1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
$Id: scrollbar_default.cpp,v 1.40 2002/01/17 14:38:44 sphair Exp $
ClanGUI, copyrights by various people. Have a look in the CREDITS file.
This sourcecode is distributed using the Library GNU Public Licence,
version 2 or (at your option) any later version. Please read LICENSE
for details.
*/
#include "precomp.h"
#include "scrollbar_default.h"
#include "button_default.h"
#include "API/Display/Display/surface.h"
#include "API/Core/Resources/resource_manager.h"
CL_ScrollBar_Default::CL_ScrollBar_Default(
CL_ScrollBar *_scrollbar,
CL_StyleManager_Default *style)
:
CL_ComponentStyle(_scrollbar),
timer_scroll(250),
scrollbar(_scrollbar)
{
this->style = style;
resources = style->get_resources();
CL_Rect rect_decrease;
CL_Rect rect_increase;
CL_Component *client_area = scrollbar->get_client_area();
if (scrollbar->is_vertical())
{
int button_size = scrollbar->get_width();
rect_decrease = CL_Rect(0, 0, button_size, button_size);
rect_increase = CL_Rect(0, scrollbar->get_height() - button_size, button_size, scrollbar->get_height());
}
else
{
int button_size = scrollbar->get_height();
rect_decrease = CL_Rect(0, 0, button_size, button_size);
rect_increase = CL_Rect(scrollbar->get_width() - button_size, 0, scrollbar->get_width(), button_size);
}
button_increase = new CL_Button(rect_increase, "", scrollbar, style);
button_decrease = new CL_Button(rect_decrease, "", scrollbar, style);
layout.add_resize_position(button_decrease, CL_LayoutManager::x2, scrollbar, CL_LayoutManager::x2);
layout.add_resize_position(button_increase, CL_LayoutManager::x2, scrollbar, CL_LayoutManager::x2);
layout.add_resize_position(button_increase, CL_LayoutManager::y1, scrollbar, CL_LayoutManager::y2);
layout.add_resize_position(button_increase, CL_LayoutManager::y2, scrollbar, CL_LayoutManager::y2);
slot_paint = client_area->sig_paint().connect(
this, &CL_ScrollBar_Default::on_paint);
slot_increase_pressed = button_increase->sig_pressed().connect(
this, &CL_ScrollBar_Default::start_scroll, 1);
slot_decrease_pressed = button_decrease->sig_pressed().connect(
this, &CL_ScrollBar_Default::start_scroll, -1);
slot_increase_released = button_increase->sig_released().connect(
this, &CL_ScrollBar_Default::stop_scroll);
slot_decrease_released = button_decrease->sig_released().connect(
this, &CL_ScrollBar_Default::stop_scroll);
slot_timer = timer_scroll.sig_timer.connect(
this, &CL_ScrollBar_Default::on_timer_scroll);
}
CL_ScrollBar_Default::~CL_ScrollBar_Default()
{
delete button_increase;
delete button_decrease;
}
void CL_ScrollBar_Default::start_scroll(int delta)
{
scroll_delta = delta;
timer_scroll.enable();
on_timer_scroll();
}
void CL_ScrollBar_Default::stop_scroll()
{
timer_scroll.disable();
}
void CL_ScrollBar_Default::on_timer_scroll()
{
scrollbar->set_value(scrollbar->get_value() + scroll_delta);
}
void CL_ScrollBar_Default::on_paint()
{
int width = scrollbar->get_client_area()->get_width();
int height = scrollbar->get_client_area()->get_height();
CL_Rect rect = scrollbar->get_slider_rect();
// Background
// TODO: Split this into two parts (at the sides of the slider)
style->fill_rect(
0, 0,
width, height,
GUICOLOR_SCROLLBAR);
if(scrollbar->has_focus())
style->draw_rect(
0, 0,
width, height,
GUICOLOR_FOCUS);
// Slider
if(scrollbar->is_dragging_slider())
{
style->fill_rect(
rect.x1 + 2,
rect.y1 + 2,
rect.x2 - 2,
rect.y2 - 2,
GUICOLOR_DARKER_SHADE);
}
else
{
style->fill_rect(
rect.x1 + 2,
rect.y1 + 2,
rect.x2 - 2,
rect.y2 - 2,
GUICOLOR_WHITE);
}
style->draw_rect(
rect.x1 + 1,
rect.y1 + 1,
rect.x2 - 1,
rect.y2 - 1,
GUICOLOR_DARK_OUTLINE);
}
|