indexing description: "[ Represents a panel for the current status of all axes ]" date: "$Date$" revision: "$Revision$" class JOYSTICK_AXIS_PANEL inherit 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'. local label: EM_LABEL 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) -- container for sotring the actual axis position create axis_values.make (0, 15) -- default values create drawing_color.make_with_rgb (255,0,0) create black_color.make_black -- create x/y axis label create label.make_from_text ("X Axis / Y Axis") label.set_position (5, 15) label.set_dimension (131, label.optimal_height) label.align_center add_widget (label) -- create cobobox and add it to the panel create combobox.make_empty combobox.set_position (140, 15) add_widget (combobox) -- add to the `current' and handle axis events joystick_focus.add_focus (current) joystick_axis_event.subscribe (agent handle_joystick_axis_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_axis_count (a_count: INTEGER) is -- setup the number of axis for this event require enough_axis: a_count >= 2 or a_count = 0 -- there is no joystick with 1 axis -- 0 axis defined no joystick found (or not seleceted yet) local i: INTEGER do -- create axis_values and wipe out the combobox create axis_values.make (0, a_count -1) combobox.wipe_out -- fill combobox with all avaiable axis from i := 2 until i = a_count or a_count = 0 loop combobox.put ("Axis #" + i.out) i := i + 1 end -- set dimension combobox.set_dimension (75, combobox.optimal_height) if combobox.count > 0 then combobox.set_selected_index (1) combobox.enable else -- select optimal height if empty combobox.put ("No Axis") 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, pos: 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_ORTHOGONAL_RECTANGLE}.make_from_coordinates (4, 34, 135,165)) if axis_values.count >= 2 then pos_x := 70 + (axis_values.item (0) // 512) pos_y := 100 + (axis_values.item (1) // 512) surface.set_drawing_color (drawing_color) -- standard X/Y-Axis surface.draw_rectangle (create {EM_ORTHOGONAL_RECTANGLE}.make_from_coordinates (70, 95, pos_x, 105)) surface.draw_rectangle (create {EM_ORTHOGONAL_RECTANGLE}.make_from_coordinates (65, 100, 75, pos_y)) -- draw selected axis from the combobox pos := 100 + (axis_values.item (combobox.selected_index + 1) // 512) surface.draw_rectangle (create {EM_ORTHOGONAL_RECTANGLE}.make_from_coordinates (175, 100, 185, pos)) -- crosshair surface.set_drawing_color (black_color) surface.draw_line_segment (create {EM_VECTOR_2D}.make (pos_x -5, pos_y), create {EM_VECTOR_2D}.make (pos_x +5, pos_y)) surface.draw_line_segment (create {EM_VECTOR_2D}.make (pos_x, pos_y -5), create {EM_VECTOR_2D}.make (pos_x, pos_y +5)) end end end feature {JOYSTICK_SCENE} -- Joystick Management handle_joystick_axis_event (event: EM_JOYSTICK_AXIS_EVENT) is -- Handle joystick axis event do axis_values.put (event.value, event.is_axis) set_changed end feature {NONE} -- Implementation axis_values: ARRAY [INTEGER] -- container for all axis values combobox: EM_COMBOBOX [STRING] -- Selector for axis 3..axis_values.count drawing_color: EM_COLOR -- color to draw black_color: EM_COLOR -- black color for drawing end