178 lines
4.1 KiB
Plaintext
178 lines
4.1 KiB
Plaintext
|
note
|
||
|
description: "[
|
||
|
An arrow widget
|
||
|
]"
|
||
|
author: "Jimmy J. Johnson"
|
||
|
|
||
|
class
|
||
|
ARROW
|
||
|
|
||
|
inherit
|
||
|
|
||
|
VITP_WIDGET
|
||
|
redefine
|
||
|
default_create,
|
||
|
target_imp,
|
||
|
build_widgets,
|
||
|
paint
|
||
|
end
|
||
|
|
||
|
create
|
||
|
default_create
|
||
|
|
||
|
feature {NONE} -- Initialization
|
||
|
|
||
|
default_create
|
||
|
-- Initialize attributes
|
||
|
do
|
||
|
-- create head_dot
|
||
|
create nock
|
||
|
create shaft
|
||
|
create head
|
||
|
Precursor {VITP_WIDGET}
|
||
|
end
|
||
|
|
||
|
build_widgets
|
||
|
-- Create the widgets that make up Current
|
||
|
local
|
||
|
t: EV_MODEL_TRANSFORMATION
|
||
|
do
|
||
|
-- Use the `dot' as reference point to build the arrow (the center of the nock).
|
||
|
-- The EV_MODEL_DOT and EV_MODEL_LINE do not scale nicely, so use circle and
|
||
|
-- rectangle to build the parts of the arrow.
|
||
|
create t.make_zero
|
||
|
t.translate (width // 2, 0)
|
||
|
dot.transform (t)
|
||
|
direction := North
|
||
|
build_nock
|
||
|
build_shaft
|
||
|
build_head
|
||
|
end
|
||
|
|
||
|
build_nock
|
||
|
-- Create the end of the arrow opposite the head
|
||
|
-- A circle slightly bigger than the shaft, centered on `dot'
|
||
|
local
|
||
|
p1, p2: EV_COORDINATE
|
||
|
r: INTEGER
|
||
|
do
|
||
|
r := (width // 2) + (width // 4)
|
||
|
create p1.make_precise (dot.x - r, dot.y - r)
|
||
|
create p2.make_precise (dot.x + r, dot.y + r)
|
||
|
create nock.make_with_points (p1, p2)
|
||
|
extend (nock)
|
||
|
end
|
||
|
|
||
|
build_shaft
|
||
|
-- Create the shaft as a rectangle `width' wide with an arrow on the
|
||
|
-- end. Assume the arrow tip ends `Default_length' away from `dot'.
|
||
|
local
|
||
|
p: EV_COORDINATE
|
||
|
len, wid: INTEGER
|
||
|
do
|
||
|
io.put_string ("ARROW.build_shaft -- fix me! Add a pointed tip. %N")
|
||
|
len := length
|
||
|
wid := width // 2
|
||
|
create shaft
|
||
|
create p.make_precise (dot.x - wid, dot.y)
|
||
|
shaft.extend_point (p)
|
||
|
create p.make_precise (dot.x + wid, dot.y)
|
||
|
shaft.extend_point (p)
|
||
|
create p.make_precise (dot.x + wid, dot.y + len)
|
||
|
shaft.extend_point (p)
|
||
|
create p.make_precise (dot.x - wid, dot.y + len)
|
||
|
shaft.extend_point (p)
|
||
|
extend (shaft)
|
||
|
end
|
||
|
|
||
|
build_head
|
||
|
-- Create the point (or retical) end of the arrow
|
||
|
local
|
||
|
p: EV_COORDINATE
|
||
|
do
|
||
|
create head
|
||
|
end
|
||
|
|
||
|
feature -- Access
|
||
|
|
||
|
direction: INTEGER
|
||
|
-- The direction the arrow is pointing if not targetting a unit
|
||
|
|
||
|
width: INTEGER
|
||
|
-- The size of the `shaft'
|
||
|
do
|
||
|
Result := 100
|
||
|
end
|
||
|
|
||
|
length: INTEGER
|
||
|
-- The length of the `shaft' calculated from the distance between the
|
||
|
-- two widgets or as a percentage of the size of the `unit_widget'
|
||
|
local
|
||
|
xd, yd: INTEGER
|
||
|
do
|
||
|
Result := 500
|
||
|
end
|
||
|
|
||
|
feature -- Basic operations
|
||
|
|
||
|
fill_widgets
|
||
|
-- Nothing to do here.
|
||
|
do
|
||
|
end
|
||
|
|
||
|
paint
|
||
|
-- Set the colors of the sub-widgets
|
||
|
do
|
||
|
Precursor {VITP_WIDGET}
|
||
|
-- if attached unit_widget as uw then
|
||
|
-- if attached targetted_widget as tw then
|
||
|
-- if uw.unit.nationality = US then
|
||
|
-- nock.set_foreground_color (adjusted_color (US_retical_color))
|
||
|
-- nock.set_background_color (adjusted_color (US_retical_color))
|
||
|
-- shaft.set_foreground_color (adjusted_color (US_retical_color))
|
||
|
-- shaft.set_background_color (adjusted_color (US_retical_color))
|
||
|
-- else
|
||
|
-- nock.set_foreground_color (adjusted_color (Japanese_retical_color))
|
||
|
-- nock.set_background_color (adjusted_color (Japanese_retical_color))
|
||
|
-- shaft.set_foreground_color (adjusted_color (Japanese_retical_color))
|
||
|
-- shaft.set_background_color (adjusted_color (Japanese_retical_color))
|
||
|
-- end
|
||
|
-- else
|
||
|
-- -- there is no target
|
||
|
-- nock.set_foreground_color (adjusted_color (arrow_color))
|
||
|
-- nock.set_background_color (adjusted_color (arrow_color))
|
||
|
-- shaft.set_foreground_color (adjusted_color (arrow_color))
|
||
|
-- shaft.set_background_color (adjusted_color (arrow_color))
|
||
|
--io.put_string ("ARROW.paint -- fix me! Hide/show the retical %N")
|
||
|
-- end
|
||
|
-- end
|
||
|
end
|
||
|
|
||
|
feature {NONE} -- Implementation
|
||
|
|
||
|
target_imp: detachable ATTACK_UNIT
|
||
|
-- Anchor for `target'
|
||
|
|
||
|
nock: EV_MODEL_ELLIPSE
|
||
|
-- Shows the end opposite the head
|
||
|
|
||
|
shaft: EV_MODEL_POLYGON
|
||
|
-- The shaft of the arrow
|
||
|
|
||
|
head: EV_MODEL_POLYGON
|
||
|
-- The point of the arrow
|
||
|
|
||
|
-- head: RETICAL
|
||
|
-- Gun sight retical
|
||
|
|
||
|
North: INTEGER = 1
|
||
|
South: INTEGER = 2
|
||
|
East: INTEGER = 3
|
||
|
West: INTEGER = 4
|
||
|
North_east: INTEGER = 5
|
||
|
South_east: INTEGER = 6
|
||
|
North_west: INTEGER = 7
|
||
|
South_west: INTEGER = 8
|
||
|
|
||
|
end
|