19928/jj_vitp/Interface/widgets/other_widgets/border.e

237 lines
5.7 KiB
Plaintext
Raw Permalink Normal View History

2024-06-17 07:09:33 +00:00
note
description: "[
Builds a raised border for placement on an {ATTACK_UNIT_WIDGET}
]"
author: "Jimmy J. Johnson"
class
BORDER
inherit
EV_MODEL_WORLD
redefine
create_interface_objects
end
create
make
create {BORDER}
list_make
feature {NONE} -- Initialization
create_interface_objects
-- Initialize attributes
do
Precursor {EV_MODEL_WORLD}
create color
create borders.make_filled (create {LINKED_LIST [EV_MODEL_POLYGON]}.make, 1, 4)
end
-- make (a_size: REAL_64)
make (a_width, a_height, a_edge_size: REAL_64)
-- Create Current setting the `width' and `height'
-- If `a_width' and `a_height' is the size of the widget on
-- which to place the border, then the border steps will be
-- placed over the edge of the widget, not surrounding the
-- widget. (This seems preferred, so that the size of the
-- bordered widget is not bigger than planned.)
require
width_big_enough: a_width >= 30 -- arbitrary
height_big_enough: a_height >= 30
edge_size_big_enough: a_edge_size >= 10
local
i: INTEGER
do
default_create
create borders.make_filled (create {LINKED_LIST [EV_MODEL_POLYGON]}.make, 1, 4)
from i := Left
until i > Bottom
loop
borders [i] := create {LINKED_LIST [EV_MODEL_POLYGON]}.make
i := i + 1
end
-- size := a_size
width := a_width
height := a_height
edge_size := a_edge_size
build_edges
end
feature -- Access
color: EV_COLOR
-- The color from which to `paint' Current.
width: REAL_64
-- The width from which to build Current.
height: REAL_64
-- The height from which to build Current.
-- size: REAL_64
-- The width [and length] from which to build Current.
feature -- Element change
set_color (a_color: EV_COLOR)
-- Change the `color'.
do
color := a_color
paint
end
feature -- Basic operations
paint
-- Set the colors for the boarder polygons based on the
-- color of the background color of the `tile'
local
i: INTEGER
do
-- Color each edge in order: Left, Top, Right, Bottom
from i := Left
until i > Bottom
loop
paint_edge (i)
i := i + 1
end
end
feature {NONE} -- Implementation
paint_edge (a_index: INTEGER)
-- Paint the `a_index'th edge
require
index_big_enough: a_index >= 1
index_small_enough: a_index <= 4
local
fad: COLOR_FADER
polys: LINKED_LIST [EV_MODEL_POLYGON]
p: EV_MODEL_POLYGON
c: EV_COLOR
i: INTEGER
do
polys := borders [a_index]
create fad.make_with_color_and_count (color, polys.count)
from polys.start
until polys.exhausted
loop
p := polys.item
i := polys.count - polys.index + 1
if a_index <= 2 then
c := fad.i_th_lighter (i)
else
c := fad.i_th_darker (i)
end
p.set_background_color (c)
p.set_foreground_color (c)
polys.forth
end
end
build_edges
-- Create the polygons that simulate a raised boarder
local
-- Short variable names to make equations shorter
p, p2, p3, p4: EV_COORDINATE
poly: EV_MODEL_POLYGON
w, h: REAL_64
ss: REAL_64
c: INTEGER
i: INTEGER
do
-- Each boarder is one-tenth the width of the `box'. We then determine
-- the number of times 2 will go into this width and use that as the
-- number of color steps to make on each boarder.
-- The right and bottom boarders should fade-to-black; the top and left
-- boarders should fade-to-white then fade-to-grey.
-- This should give the appearance of a light source up and left.
ss := step_size
w := width
h := height
c := step_count
from i := 1
until i > c
loop
-- right
create p.make_precise (w - i * ss, i * ss)
create p2.make_precise ((w - (i - 1) * ss), (i - 1) * ss)
create p3.make_precise (w - (i - 1) * ss, h - (i - 1) * ss)
create p4.make_precise (w - i * ss, h - i * ss)
create poly
poly.extend_point (p)
poly.extend_point (p2)
poly.extend_point (p3)
poly.extend_point (p4)
borders [Right].extend (poly)
extend (poly)
-- left
create p.make_precise (i * ss, i * ss)
create p2.make_precise (i * ss, h - i * ss)
create p3.make_precise ((i - 1) * ss, h - (i - 1) * ss)
create p4.make_precise ((i - 1) * ss, (i - 1) * ss)
create poly
poly.extend_point (p)
poly.extend_point (p2)
poly.extend_point (p3)
poly.extend_point (p4)
borders [Left].extend (poly)
extend (poly)
-- bottom
create p.make_precise (i * ss, h - i * ss)
create p2.make_precise ((w - i * ss), h - i * ss)
create p3.make_precise (w - (i - 1) * ss, h - (i - 1) * ss)
create p4.make_precise ((i - 1) * ss, h - (i - 1) * ss)
create poly
poly.extend_point (p)
poly.extend_point (p2)
poly.extend_point (p3)
poly.extend_point (p4)
borders [Bottom].extend (poly)
extend (poly)
-- top
create p.make_precise ((i - 1) * ss, (i - 1) * ss)
create p2.make_precise (w - (i - 1) * ss, (i - 1) * ss)
create p3.make_precise (w - i * ss, i * ss)
create p4.make_precise (i * ss, i * ss)
create poly
poly.extend_point (p)
poly.extend_point (p2)
poly.extend_point (p3)
poly.extend_point (p4)
borders [Top].extend (poly)
extend (poly)
i := i + 1
end
end
borders: ARRAY [LINKED_LIST [EV_MODEL_POLYGON]]
-- Contains the four edges
edge_size: REAL_64
-- The size of each edge calculated from the smaller of
-- the `width' or `height'
-- do
---- Result := size / 10
-- Result := width.min (height) / 10
-- end
step_count: INTEGER
-- The number of incremental colors into which each edge is broken
do
Result := (edge_size / step_size).rounded
end
step_size: REAL_64 = 2.0
-- The logical width of each polygon in the edges
Left: INTEGER = 1
Top: INTEGER = 2
Right: INTEGER = 3
Bottom: INTEGER = 4
end