18 #define GETTEXT_DOMAIN "wesnoth-lib"
22 #include "widgets/scrollbar.hpp"
30 const std::string scrollbar_top =
"buttons/scrollbars_large/scrolltop.png";
31 const std::string scrollbar_bottom =
"buttons/scrollbars_large/scrollbottom.png";
32 const std::string scrollbar_mid =
"buttons/scrollbars_large/scrollmid.png";
34 const std::string scrollbar_top_hl =
"buttons/scrollbars_large/scrolltop-active.png";
35 const std::string scrollbar_bottom_hl =
"buttons/scrollbars_large/scrollbottom-active.png";
36 const std::string scrollbar_mid_hl =
"buttons/scrollbars_large/scrollmid-active.png";
38 const std::string scrollbar_top_pressed =
"buttons/scrollbars_large/scrolltop-pressed.png";
39 const std::string scrollbar_bottom_pressed =
"buttons/scrollbars_large/scrollbottom-pressed.png";
40 const std::string scrollbar_mid_pressed =
"buttons/scrollbars_large/scrollmid-pressed.png";
42 const std::string groove_top =
"buttons/scrollbars_large/scrollgroove-top.png";
43 const std::string groove_mid =
"buttons/scrollbars_large/scrollgroove-mid.png";
44 const std::string groove_bottom =
"buttons/scrollbars_large/scrollgroove-bottom.png";
52 , mid_scaled_(nullptr)
53 , groove_scaled_(nullptr)
54 , uparrow_(video,
"",
button::TYPE_TURBO,
"button_square/button_square_25"
55 ,
gui::
button::DEFAULT_SPACE, true,
"icons/arrows/arrows_ornate_up_25")
56 , downarrow_(video,
"",
button::TYPE_TURBO,
"button_square/button_square_25"
57 ,
gui::
button::DEFAULT_SPACE, true,
"icons/arrows/arrows_ornate_down_25")
59 , minimum_grip_height_(0)
183 if(uh + dh >= height) {
214 if(uh + dh >= loc.h) {
270 if (mid_img ==
nullptr || bottom_img ==
nullptr || top_img ==
nullptr
271 || top_grv ==
nullptr || bottom_grv ==
nullptr || mid_grv ==
nullptr) {
272 std::cerr <<
"Failure to load scrollbar image.\n";
277 int mid_height = grip.h - top_img->h - bottom_img->h;
278 if (mid_height <= 0) {
290 int groove_height = groove.h - top_grv->h - bottom_grv->h;
291 if (groove_height <= 0) {
300 std::cerr <<
"Failure during scrollbar image scale.\n";
304 if (grip.h > groove.h) {
305 std::cerr <<
"abort draw scrollbar: grip too large\n";
312 video().
blit_surface(groove.x, groove.y + top_grv->h + groove_height, bottom_grv);
334 switch (event.type) {
335 case SDL_MOUSEBUTTONUP:
337 SDL_MouseButtonEvent
const &
e =
event.button;
342 case SDL_MOUSEBUTTONDOWN:
344 SDL_MouseButtonEvent
const &
e =
event.button;
347 if (on_grip && e.button == SDL_BUTTON_LEFT) {
350 }
else if (on_groove && e.button == SDL_BUTTON_LEFT && groove.h != grip.h) {
355 }
else if (on_groove && e.button == SDL_BUTTON_MIDDLE) {
356 int y_dep = e.y - grip.y - grip.h/2;
362 case SDL_MOUSEMOTION:
364 SDL_MouseMotionEvent
const &
e =
event.motion;
377 const SDL_MouseWheelEvent&
e =
event.wheel;
379 SDL_GetMouseState(&x, &y);
381 if (on_groove && e.y < 0) {
383 }
else if (on_groove && e.y > 0) {
393 if (new_state !=
state_) {
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
std::vector< events::sdl_handler * > sdl_handler_vector
GLint GLint GLint GLint GLint GLint y
surface scale_surface(const surface &surf, int w, int h)
void blit_surface(int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
GLsizei const GLfloat * value
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
bool point_in_rect(int x, int y, const SDL_Rect &rect)
Tests whether a point is inside a rectangle.
GLfloat GLfloat GLfloat GLfloat h
GLint GLint GLint GLint GLint x
GLdouble GLdouble GLdouble r
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
Contains the SDL_Rect helper code.
void assign(const surface &o)
void update_rect(const SDL_Rect &)
GLsizei const GLcharARB ** string