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;
235 bool on_grip = grip.
contains(e.x, e.y);
239 case SDL_MOUSEBUTTONDOWN:
241 const SDL_MouseButtonEvent&
e =
event.button;
242 bool on_grip = grip.
contains(e.x, e.y);
243 bool on_groove = groove.
contains(e.x, e.y);
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;
263 bool on_grip = grip.
contains(e.x, e.y);
274 const SDL_MouseWheelEvent&
e =
event.wheel;
277 bool on_groove = groove.
contains(x, y);
278 if (on_groove && e.y < 0) {
280 }
else if (on_groove && e.y > 0) {
290 if (new_state !=
state_) {
Drawing functions, for drawing things on the screen.
int w() const
The draw-space width of the texture, in pixels.
int h() const
The draw-space height of the texture, in pixels.
point get_size(const locator &i_locator, bool skip_cache)
Returns the width and height of an image.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
Wrapper class to encapsulate creation and management of an SDL_Texture.
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
Contains the SDL_Rect helper code.
uint32_t get_mouse_state(int *x, int *y)
A wrapper for SDL_GetMouseState that gives coordinates in draw space.
Standard logging facilities (interface).
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
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.