indexing description: "[ Represents a panel for the current status of all balls ]" date: "$Date$" revision: "$Revision$" class JOYSTICK_BALL_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 and setup all necessary labels create status_label.make_from_text ("Ball events are represented as relative position movements since the last event.%N%NRelative Movement in x-direction: 0%NRelative Movement in y-direction: 0") status_label.set_multilined (true) status_label.align_top status_label.set_position (5, 35) status_label.set_dimension (width -10, height -15) add_widget (status_label) -- 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 ball events joystick_focus.add_focus (current) joystick_ball_event.subscribe (agent handle_joystick_ball_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_balls_count (a_count: INTEGER) is -- setup the number of axis for this event local i: INTEGER do -- wipe out the combobox combobox.wipe_out -- fill combobox with all avaiable balls from i := 0 until i = a_count loop combobox.put ("Ball #" + 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 Balls") 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. do -- draw the background surface.blit_surface (image, 0, 0) end feature {JOYSTICK_SCENE} -- Joystick Management handle_joystick_ball_event (event: EM_JOYSTICK_BALL_EVENT) is -- Handle joystick ball event do if event.is_ball = (combobox.selected_index - 1) then status_label.set_text ("Ball events are represented as relative position movements since the last event.%N%NRelative Movement in x-direction: " + event.x_relative_motion.out + "%NRelative Movement in y-direction: " + event.y_relative_motion.out) end set_changed end feature {NONE} -- Implementation combobox: EM_COMBOBOX [STRING] -- selector for hat 0..ball_values.count drawing_color: EM_COLOR -- color to draw status_label: EM_LABEL -- represents the status of the selected ball end