indexing description: "[ Represents a panel for the current status of all hats ]" date: "$Date$" revision: "$Revision$" class JOYSTICK_HAT_PANEL inherit EM_CONSTANTS EM_PANEL redefine draw_body end create make feature {NONE} -- Initialization make (panel_width, panel_height: INTEGER) is -- Initialise with a drawing panel of size `panel_width' `panel_height'. do Bitmap_factory.create_empty_bitmap (panel_width, panel_height) check image_crated: Bitmap_factory.last_bitmap /= Void end image := bitmap_factory.last_bitmap image.fill (background_color) make_from_dimension (panel_width, panel_height) create drawing_color.make_with_rgb (255,0,0) create black_color.make_black -- container for sotring the actual axis position create hat_values.make (0, 15) -- default values -- create cobobox and add it to the panel create combobox.make_empty combobox.set_position (5, 15) add_widget (combobox) -- add to the `current' and handle hat events joystick_focus.add_focus (current) joystick_hat_event.subscribe (agent handle_joystick_hat_event (?)) ensure image_created: image /= Void end feature -- Access image: EM_BITMAP -- Bitmap that holds drawing background_color: EM_COLOR is -- Background color of panel once create result.make_white end set_hats_count (a_count: INTEGER) is -- setup the number of axis for this event local i: INTEGER do -- create axis_values and wipe out the combobox create hat_values.make (0, a_count -1) combobox.wipe_out -- fill combobox with all avaiable axis from i := 0 until i = a_count loop combobox.put ("Hat #" + i.out) i := i + 1 end -- set dimension combobox.set_dimension (90, combobox.optimal_height) if combobox.count > 0 then combobox.set_selected_index (1) combobox.enable else -- select optimal height if empty combobox.put ("No Hats") combobox.set_height (combobox.optimal_height) combobox.set_selected_index (1) combobox.disable end end feature -- Drawing draw_body is -- Draw the body of the widget. local pos_x, pos_y: INTEGER do -- first draw the background surface.blit_surface (image, 0, 0) -- draw only something else if needed if combobox.selected_index /= 0 then surface.set_drawing_color (black_color) surface.draw_rectangle (create {EM_RECTANGLE}.make_from_coordinates (15, 45, 85, 115)) surface.set_drawing_color (drawing_color) if hat_values.count > 0 then inspect hat_values.item (combobox.selected_index - 1) when em_joystick_hat_leftup then pos_x := 15 pos_y := 45 when em_joystick_hat_up then pos_x := 50 pos_y := 45 when em_joystick_hat_rightup then pos_x := 85 pos_y := 45 when em_joystick_hat_left then pos_x := 15 pos_y := 80 when em_joystick_hat_centered then pos_x := 50 pos_y := 80 when em_joystick_hat_right then pos_x := 85 pos_y := 80 when em_joystick_hat_leftdown then pos_x := 15 pos_y := 115 when em_joystick_hat_down then pos_x := 50 pos_y := 115 when em_joystick_hat_rightdown then pos_x := 85 pos_y := 115 else -- should not happend end -- draw a scare where the hat is surface.draw_rectangle (create {EM_RECTANGLE}.make_from_coordinates (pos_x - 5, pos_y - 5, pos_x + 5, pos_y + 5)) end end end feature {JOYSTICK_SCENE} -- Joystick Management handle_joystick_hat_event (event: EM_JOYSTICK_HAT_EVENT) is -- Handle joystick hat event do hat_values.put (event.value, event.is_hat) set_changed end feature {NONE} -- Implementation hat_values: ARRAY [INTEGER] -- container for all axis values combobox: EM_COMBOBOX [STRING] -- selector for hat 0..hat_values.count drawing_color: EM_COLOR -- color to draw black_color: EM_COLOR -- black color for drawing end