indexing description: "[ Basic delegate of an EM_SCROLLBAR. ]" date: "$Date$" revision: "$Revision$" class EM_BASIC_SCROLLBAR_DELEGATE inherit EM_SLIDER_DELEGATE redefine install, optimal_width, optimal_height, draw_body 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 (create {EM_LINE_BORDER}.make (create {EM_COLOR}.make_black, 1)) 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 + 12 bottom := scrollbar.height-scrollbar.border.bottom - 12 x := top + ((bottom-top) / (scrollbar.right_value-scrollbar.left_value) * (scrollbar.current_value-scrollbar.left_value)).floor scrollbar.surface.put_line_segment (scrollbar.border.left, scrollbar.border.top+12, scrollbar.width-scrollbar.border.right, scrollbar.border.top+12, create {EM_COLOR}.make_black) scrollbar.surface.put_line_segment (scrollbar.border.left, scrollbar.height-scrollbar.border.bottom-12, scrollbar.width-scrollbar.border.right, scrollbar.height-scrollbar.border.bottom-12, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.border.top+6, 4, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.height-scrollbar.border.bottom-6, 4, create {EM_COLOR}.make_black) scrollbar.surface.put_rectangle_filled (scrollbar.border.left, x-2, scrollbar.width-scrollbar.border.right, x+2, create {EM_COLOR}.make_black) else left := scrollbar.border.left + 12 right := scrollbar.width-scrollbar.border.right - 12 x := left + ((right-left) / (scrollbar.right_value-scrollbar.left_value) * (scrollbar.current_value-scrollbar.left_value)).floor scrollbar.surface.put_line_segment (scrollbar.border.left+12, scrollbar.border.top, scrollbar.border.left+12, scrollbar.height-scrollbar.border.bottom, create {EM_COLOR}.make_black) scrollbar.surface.put_line_segment (scrollbar.width-scrollbar.border.right-12, scrollbar.border.top, scrollbar.width-scrollbar.border.right-12, scrollbar.height-scrollbar.border.bottom, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.border.left+6, scrollbar.border.top+6, 4, create {EM_COLOR}.make_black) scrollbar.surface.put_circle_filled (scrollbar.width-scrollbar.border.right-6, scrollbar.border.top+6, 4, create {EM_COLOR}.make_black) scrollbar.surface.put_rectangle_filled (x-2, scrollbar.border.top, x+2, scrollbar.height-scrollbar.border.bottom, create {EM_COLOR}.make_black) 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 + 12 bottom := scrollbar.height - scrollbar.border.bottom - 12 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 + 12 right := scrollbar.width-scrollbar.border.right - 12 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