note
	description: "[
		Draws the circular control markers for VITP.
		]"
	author: "Jimmy J. Johnson"

class
	CONTROL_MARKER

inherit

	FONT_AND_COLOR_CONSTANTS
		undefine
			default_create
		end

	DIMABLE
		redefine
			default_create
		end

	EV_MODEL_WORLD
		redefine
			default_create,
			create_interface_objects
		end
create
	make

create {CONTROL_MARKER}
	list_make

feature {NONE} -- Initialization

	default_create
			-- Set up Current
		do
			Precursor {DIMABLE}
			Precursor {EV_MODEL_WORLD}
			build_widgets
		end

	make (a_location: LOCATION)
			-- Set up Current
		do
			location_imp := a_location
			default_create
		end

	create_interface_objects
			-- Create attributes
		local
			p1, p2: EV_COORDINATE
			s: REAL_64
			offset: REAL_64
			t: EV_MODEL_TRANSFORMATION
		do
			Precursor {EV_MODEL_WORLD}
			create circle
			create sun
			create star
			create anchor
		end

	build_widgets
			-- Construct and add widgets to Current.
		do
			build_circle
			build_sun
			build_star
			build_anchor
			star.scale (0.8)
			anchor.set_x_y (anchor.x + 90, anchor.y + 62)
			star.set_x_y (star.x + 96, star.y + 96)
			sun.set_x_y (sun.x + 20, sun.y + 30)
			paint
		end

	build_circle
			-- Create the marker
		local
			p1, p2: EV_COORDINATE
			s: REAL_64
		do
			extend (circle)
			create p1.make_precise (0, 0)
			create p2.make_precise (Initial_size, Initial_size)
			circle.set_point_a (p1)
			circle.set_point_b (p2)
		end

	build_sun
			-- Create the "Japanese" rising `sun'
		local
			p1, p2: EV_COORDINATE
			s: REAL_64
			offset: REAL_64
		do
			extend (sun)
				-- create a circle that is slightly small than `circle'
				-- and offset it a little
			s := Initial_size * 0.7
			create p1.make_precise (0, 0)
			create p2.make_precise (s, s)
			sun.set_point_a (p1)
			sun.set_point_b (p2)
			offset := Initial_size / 12
				-- offset a little
--			translate_widget (sun, offset, offset)
		end

	build_star
			-- Create the star
		do
			extend (star)
--			translate_widget (star, -Initial_size/12, -Initial_size/12)
--			scale_widget (star, 1.2)
-- fix center on ... dot is not positioned yet by `initialize'
--			star.set_x_y (dot.x, dot.y)
		end

	build_anchor
			-- Create an anchor
		do
			extend (anchor)
--			scale_widget (anchor, 2.0)
--			translate_widget (anchor, -Initial_size/12, -Initial_size/12)
-- fix center on ... dot is not positioned yet by `initialize'
		end

feature -- Access

	location: LOCATION
			-- The location (e.g. a PORT or a chart) to which
			-- this marker belongs
		require
			has_location: has_location
		do
			check attached location_imp as loc then
				Result := loc
			end
		end

	set_location (a_location: like location)
			-- Change the `location'
		do
			location_imp := a_location
		end

feature {NONE} -- Implementation

	location_imp: detachable like location
			-- Implementation for `location'

feature -- Status report

	has_location: BOOLEAN
			-- Has a location been assigned?
		do
			Result := attached location_imp
		end

	is_boarder_shown: BOOLEAN
			-- Should the outline of the flag show?

feature -- Status setting

	show_boarder
				-- Make the outline of the flag visible
		do
			is_boarder_shown := true
		end

	hide_boarder
				-- Make the outline of the flag NOT visible
		do
			is_boarder_shown := false
		end

feature -- Basic operations

	hide_anchor
			-- Make the anchor no show.
			-- Required for non-major ports.
		do
			anchor.hide
		end

	paint
			-- Set the colors of the sub-widgets
		local
			fc: EV_COLOR
		do
			circle.show
			if location.is_allied then
				circle.set_foreground_color (adjusted_color (US_unit_color))
				circle.set_background_color (adjusted_color (US_unit_color))
				sun.hide
				star.show
--				star.paint
			else
				sun.show
				star.hide
				circle.set_foreground_color (adjusted_color (White))
				circle.set_background_color (adjusted_color (White))
			end
				-- Hide or show boarder color?
			if location.nationality = {NATIONALITY_CONSTANTS}.japanese then
				fc := japanese_unit_color
			else
				fc := allied_unit_boarder_color
			end
			if is_boarder_shown then
				circle.set_foreground_color (adjusted_color (fc))
			end
			anchor.set_foreground_color (adjusted_color (Black))
			anchor.set_background_color (adjusted_color (Black))
			sun.set_foreground_color (adjusted_color (Japanese_unit_color))
			sun.set_background_color (adjusted_color (Japanese_unit_color))
		end

feature {NONE} -- Implementation

	circle: EV_MODEL_ELLIPSE
			-- The main figure

	sun: EV_MODEL_ELLIPSE
			-- The sun on Japanese markers

	star: STAR
			-- The star on US widgets

	anchor: ANCHOR
			-- The anchor on major port control markers

	internal_scale_factor_small: DOUBLE = 0.05
			-- Used to scale `internal_size'

	internal_scale_factor_medium: DOUBLE = 0.07
			-- Used to scale `internal_size'

	internal_scale_factor_large: DOUBLE = 0.09
			-- Used to scale `internal_size'

	Initial_size: REAL_64 = 200.0
			-- Used internally to build the figure

invariant


end
