17 #define GETTEXT_DOMAIN "wesnoth-lib"
21 #include "widgets/scrollbar.hpp"
30 const std::string scrollbar_top =
"buttons/scrollbars/scrolltop.png";
31 const std::string scrollbar_bottom =
"buttons/scrollbars/scrollbottom.png";
32 const std::string scrollbar_mid =
"buttons/scrollbars/scrollmid.png";
34 const std::string scrollbar_top_hl =
"buttons/scrollbars/scrolltop-active.png";
35 const std::string scrollbar_bottom_hl =
"buttons/scrollbars/scrollbottom-active.png";
36 const std::string scrollbar_mid_hl =
"buttons/scrollbars/scrollmid-active.png";
38 const std::string scrollbar_top_pressed =
"buttons/scrollbars/scrolltop-pressed.png";
39 const std::string scrollbar_bottom_pressed =
"buttons/scrollbars/scrollbottom-pressed.png";
40 const std::string scrollbar_mid_pressed =
"buttons/scrollbars/scrollmid-pressed.png";
49 , minimum_grip_height_(0)
58 if (img_size.x && img_size.y) {
153 return {loc.x, y, loc.w,
h};
189 int mid_height = grip.h - top_img.
h() - bot_img.
h();
190 if (mid_height <= 0) {
199 if (grip.h > groove.h) {
200 PLAIN_LOG <<
"abort draw scrollbar: grip too large";
205 const color_t c{0, 0, 0, uint8_t(255 * 0.35)};
209 SDL_Rect dest{grip.x, grip.y, top_img.
w(), top_img.
h()};
212 dest = {dest.x, dest.y + top_img.
h(), mid_img.
w(), mid_height};
215 dest = {dest.x, dest.y + mid_height, bot_img.
w(), bot_img.
h()};
231 switch (event.type) {
232 case SDL_MOUSEBUTTONUP:
234 const SDL_MouseButtonEvent&
e =
event.button;
239 case SDL_MOUSEBUTTONDOWN:
241 const SDL_MouseButtonEvent&
e =
event.button;
244 if (on_grip &&
e.button == SDL_BUTTON_LEFT) {
247 }
else if (on_groove &&
e.button == SDL_BUTTON_LEFT && groove.h != grip.h) {
252 }
else if (on_groove &&
e.button == SDL_BUTTON_MIDDLE && groove.h != grip.h) {
253 int y_dep =
e.y - grip.y - grip.h/2;
259 case SDL_MOUSEMOTION:
261 const SDL_MouseMotionEvent&
e =
event.motion;
274 const SDL_MouseWheelEvent&
e =
event.wheel;
276 if (on_groove &&
e.y < 0) {
278 }
else if (on_groove &&
e.y > 0) {
288 if (new_state !=
state_) {
Wrapper class to encapsulate creation and management of an SDL_Texture.
int w() const
The draw-space width of the texture, in pixels.
int h() const
The draw-space height of the texture, in pixels.
Drawing functions, for drawing things on the screen.
Standard logging facilities (interface).
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
point get_size(const locator &i_locator, bool skip_cache)
Returns the width and height of an image.
point get_mouse_location()
Returns the current mouse location in draw space.
Contains the SDL_Rect helper code.
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.