indexing description: "[ Delegate of an EM_SCROLLBAR. ]" date: "$Date$" revision: "$Revision$" class EM_ECLIPSE_SCROLLBAR_DELEGATE inherit EM_SLIDER_DELEGATE redefine install, optimal_width, optimal_height, draw_body end EM_WIDGET_DRAWING export {NONE} all end feature -- Initialisation install (scrollbar: EM_SCROLLBAR) is -- Install style on `scrollbar'. -- Set up all default values for background, border, font and colors. do Precursor {EM_SLIDER_DELEGATE} (scrollbar) scrollbar.set_border (Void) scrollbar.set_background_color (theme_colors.standard_background) end feature -- Measurement optimal_width (scrollbar: EM_SCROLLBAR): INTEGER is -- Optimal width of `scrollbar' do Result := 12 + scrollbar.border.left + scrollbar.border.right end optimal_height (scrollbar: EM_SCROLLBAR): INTEGER is -- Optimal height of `scrollbar' do Result := 12 + scrollbar.border.bottom + scrollbar.border.top end feature -- Drawing draw_body (scrollbar: EM_SCROLLBAR) is -- Draw body of `scrollbar'. local left, right, top, bottom: INTEGER x: INTEGER do if scrollbar.is_vertical then top := scrollbar.border.top + 17 bottom := scrollbar.height-scrollbar.border.bottom - 17 x := top + ((bottom-top) / (scrollbar.right_value-scrollbar.left_value) * (scrollbar.current_value-scrollbar.left_value)).floor draw_bevel_border_up (scrollbar.border.left, scrollbar.border.top, scrollbar.width-scrollbar.border.right, scrollbar.border.top+12, scrollbar.surface) draw_bevel_border_up (scrollbar.border.left, scrollbar.height-scrollbar.border.bottom-12, scrollbar.width-scrollbar.border.right, scrollbar.height-scrollbar.border.top, scrollbar.surface) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.border.top+6, 2, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.height-scrollbar.border.bottom-6, 2, create {EM_COLOR}.make_black) draw_bevel_border_up (scrollbar.border.left, x-5, scrollbar.width-scrollbar.border.right, x+5, scrollbar.surface) else left := scrollbar.border.left + 17 right := scrollbar.width-scrollbar.border.right - 17 x := left + ((right-left) / (scrollbar.right_value-scrollbar.left_value) * (scrollbar.current_value-scrollbar.left_value)).floor draw_bevel_border_up (scrollbar.border.left, scrollbar.border.top, scrollbar.border.left+12, scrollbar.height-scrollbar.border.bottom, scrollbar.surface) draw_bevel_border_up (scrollbar.width-scrollbar.border.right-12, scrollbar.border.top, scrollbar.width-scrollbar.border.right, scrollbar.height-scrollbar.border.bottom, scrollbar.surface) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.border.top+6, 2, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.width-scrollbar.border.right-6, scrollbar.border.top+6, 2, create {EM_COLOR}.make_black) draw_bevel_border_up (x-5, scrollbar.border.top, x+5, scrollbar.height-scrollbar.border.bottom, scrollbar.surface) end end feature -- Basic operations position_to_value (scrollbar: EM_SCROLLBAR; a_x, a_y: INTEGER): INTEGER is -- Scrollbar value at position `a_x' `a_y' local left, right: INTEGER top, bottom: INTEGER do if scrollbar.is_vertical then top := scrollbar.border.top + 17 bottom := scrollbar.height - scrollbar.border.bottom - 17 if a_y < top then Result := scrollbar.left_value.max (scrollbar.current_value - 10) elseif a_y > bottom then Result := scrollbar.right_value.min (scrollbar.current_value + 10) else Result := ((a_y - top) * (scrollbar.right_value - scrollbar.left_value) / (bottom - top)).floor + scrollbar.left_value end else left := scrollbar.border.left + 17 right := scrollbar.width-scrollbar.border.right - 17 if a_x < left then Result := scrollbar.left_value.max (scrollbar.current_value - 10) elseif a_x > right then Result := scrollbar.right_value.min (scrollbar.current_value + 10) else Result := ((a_x - left) * (scrollbar.right_value - scrollbar.left_value) / (right - left)).floor + scrollbar.left_value end end end end