indexing description: "[ Delegate of an EM_SLIDER. ]" date: "$Date$" revision: "$Revision$" class EM_ECLIPSE_SLIDER_DELEGATE inherit EM_SLIDER_DELEGATE redefine install, optimal_width, optimal_height, draw_body end EM_WIDGET_DRAWING export {NONE} all end feature -- Initialisation install (slider: EM_SLIDER) is -- Install style on `slider'. -- Set up all default values for background, border, font and colors. do Precursor {EM_SLIDER_DELEGATE} (slider) slider.set_transparent end feature -- Measurement optimal_width (slider: EM_SLIDER): INTEGER is -- Optimal width of `slider' do if slider.is_vertical then Result := 14 + slider.border.left + slider.border.right else Result := (slider.right_value - slider.left_value) + slider.border.left + slider.border.right + 10 end end optimal_height (slider: EM_SLIDER): INTEGER is -- Optimal height of `slider' do if slider.is_vertical then Result := 14 + slider.border.top + slider.border.bottom else Result := (slider.right_value - slider.left_value) + slider.border.top + slider.border.bottom + 10 end end feature -- Drawing draw_body (slider: EM_SLIDER) is -- Draw body of `slider'. local left, right, top, bottom: INTEGER x: INTEGER do if slider.is_vertical then left := slider.width // 2 - 3 right := left + 6 top := slider.border.top + 5 bottom := slider.height-slider.border.bottom-5 x := top + ((bottom-top) / (slider.right_value-slider.left_value) * (slider.current_value-slider.left_value)).floor draw_bevel_border_down (left, top, right, bottom, slider.surface) slider.surface.put_rectangle_filled (left-3, x-3, right+3, x+3, up_inner_top_left) draw_bevel_border_up (left-3, x-3, right+3, x+3, slider.surface) else left := slider.border.left + 5 right := slider.width-slider.border.right-5 top := slider.height // 2 - 3 bottom := top + 6 x := left + ((right-left) / (slider.right_value-slider.left_value) * (slider.current_value-slider.left_value)).floor draw_bevel_border_down (left, top, right, bottom, slider.surface) slider.surface.put_rectangle_filled (x-3, top-3, x+3, bottom+3, up_inner_top_left) draw_bevel_border_up (x-3, top-4, x+3, bottom+3, slider.surface) end end feature -- Basic operations position_to_value (slider: EM_SLIDER; a_x, a_y: INTEGER): INTEGER is -- Slider value at position `a_x' `a_y' local left, right, top, bottom: INTEGER do if slider.is_vertical then top := slider.border.top + 5 bottom := slider.height-slider.border.bottom-5 Result := ((a_y - top) * (slider.right_value - slider.left_value) / (bottom - top)).floor + slider.left_value else left := slider.border.left + 5 right := slider.width-slider.border.right-5 Result := ((a_x - left) * (slider.right_value - slider.left_value) / (right - left)).floor + slider.left_value end end end