The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
slider.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 #ifndef SLIDER_HPP_INCLUDED
15 #define SLIDER_HPP_INCLUDED
16 
17 #include <SDL.h>
18 
19 #include "sdl/utils.hpp"
20 
21 #include "widget.hpp"
22 
23 #include <vector>
24 
25 namespace gui {
26 
27 class slider : public widget
28 {
29 public:
30  slider(CVideo &video, const std::string& image = "buttons/sliders/slider", bool black = false);
31 
32  void set_min(int value);
33  void set_max(int value);
34  void set_value(int value);
35  void set_increment(int increment);
36 
37  int value() const;
38  int max_value() const;
39  int min_value() const { return min_; }
40 
41  bool value_change();
42 
43  virtual void enable(bool new_val=true);
44 
45  //VC++ doesn't like a 'using scrollarea::set_location' directive here, so we declare
46  //an inline forwarding function instead
47  void set_location(int x, int y) { widget::set_location(x,y); }
48  virtual void set_location(SDL_Rect const &rect);
49 
50 protected:
51  bool requires_event_focus(const SDL_Event *event=nullptr) const;
52  virtual void handle_event(const SDL_Event& event);
53  virtual void draw_contents();
54  virtual bool allow_key_events() { return true; }
55 
56 private:
57  void mouse_motion(const SDL_MouseMotionEvent& event);
58  void mouse_down(const SDL_MouseButtonEvent& event);
59  void mouse_wheel(const SDL_MouseWheelEvent& event);
60  void set_slider_position(int x);
61  SDL_Rect slider_area() const;
63  SDL_Color line_color_;
64 
65  int min_;
66  int max_;
67  int value_;
69 
71 
74 };
75 
76 
77 template<typename T>
78 class list_slider : public slider
79 {
80  public:
82  list_slider(CVideo &video, const std::vector<T> &items);
83  void set_items(const std::vector<T> &items);
84  bool select_item(const T& item); //use select_item() instead of set_value()
85  const T& item_selected() const; //use item_selected() instead of value()
86  private:
87  std::vector<T> items_;
88 };
89 
90 // This is a different style of slider, which doesn't implement key left/right responses
91 class zoom_slider : public slider
92 {
93 public:
94  zoom_slider(CVideo &video, const std::string& image = "buttons/sliders/slider", bool black = false);
95  virtual bool allow_key_events() { return false; }
96 };
97 
98 }
99 
100 #endif
bool value_change_
Definition: slider.hpp:70
int value_
Definition: slider.hpp:67
void mouse_down(const SDL_MouseButtonEvent &event)
Definition: slider.cpp:214
void set_value(int value)
Definition: slider.cpp:87
int value() const
Definition: slider.cpp:112
void set_max(int value)
Definition: slider.cpp:77
Definition: video.hpp:58
slider(CVideo &video, const std::string &image="buttons/sliders/slider", bool black=false)
Definition: slider.cpp:40
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
void set_increment(int increment)
Definition: slider.cpp:107
surface disabledImage_
Definition: slider.hpp:62
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
const std::vector< std::string > items
surface activeImage_
Definition: slider.hpp:62
bool requires_event_focus(const SDL_Event *event=nullptr) const
Definition: slider.cpp:270
void set_location(int x, int y)
Definition: slider.hpp:47
STATE state_
Definition: slider.hpp:73
virtual bool allow_key_events()
Definition: slider.hpp:54
surface pressedImage_
Definition: slider.hpp:62
int max_value() const
Definition: slider.cpp:117
int max_
Definition: slider.hpp:66
void mouse_wheel(const SDL_MouseWheelEvent &event)
Definition: slider.cpp:240
GLsizei const GLfloat * value
Definition: glew.h:1817
std::vector< T > items_
Definition: slider.hpp:87
list_slider(CVideo &video)
Definition: slider.cpp:343
void set_items(const std::vector< T > &items)
Definition: slider.cpp:386
virtual void enable(bool new_val=true)
Definition: slider.cpp:51
bool select_item(const T &item)
Definition: slider.cpp:372
virtual void handle_event(const SDL_Event &event)
Definition: slider.cpp:294
zoom_slider(CVideo &video, const std::string &image="buttons/sliders/slider", bool black=false)
Definition: slider.cpp:407
int min_
Definition: slider.hpp:65
const T & item_selected() const
Definition: slider.cpp:366
void mouse_motion(const SDL_MouseMotionEvent &event)
Definition: slider.cpp:196
virtual void draw_contents()
Definition: slider.cpp:142
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
int increment_
Definition: slider.hpp:68
bool value_change()
Definition: slider.cpp:122
surface image_
Definition: slider.hpp:62
cl_event event
Definition: glew.h:3070
this module manages the cache of images.
Definition: image.cpp:75
void set_min(int value)
Definition: slider.cpp:67
virtual void set_location(SDL_Rect const &rect)
Definition: widget.cpp:85
void set_slider_position(int x)
Definition: slider.cpp:184
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual bool allow_key_events()
Definition: slider.hpp:95
SDL_Color line_color_
Definition: slider.hpp:63
SDL_Rect slider_area() const
Definition: slider.cpp:131
int min_value() const
Definition: slider.hpp:39