The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tristate_button.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 TRISTATE_BUTTON_H_INCLUDED
15 #define TRISTATE_BUTTON_H_INCLUDED
16 
17 #include "widgets/widget.hpp"
18 
19 #include "exceptions.hpp"
21 
22 namespace gui {
23 
24 //This button has 4 states, why it is called tristate?
25 class tristate_button : public widget
26 {
27 
28 public:
29 
30  struct error : public game::error {
32  : game::error("GUI1 tristate button error")
33  {}
34  };
35 
37 
40  std::string button_image="",
41  const bool auto_join=true);
42 
43  /** Default implementation, but defined out-of-line for efficiency reasons. */
44  virtual ~tristate_button();
45 
46  void set_pressed(PRESSED_STATE new_pressed_state);
47 
48  // void set_active(bool active);
49 
50  bool pressed();
52 
53  void set_label(const std::string& val);
54 
55  bool hit(int x, int y) const;
56  virtual void enable(bool new_val=true);
57  void release();
58 
60  const surface& image)
61  {
62  itemImage_ = image;
63  }
64 
65  void set_item_id(const std::string& id) {
66  item_id_ = id;
67  }
68 
69  void draw() {
70  widget::draw();
71  }
72 
73 protected:
74 
75  virtual void handle_event(const SDL_Event& event);
76  virtual void mouse_motion(const SDL_MouseMotionEvent& event);
77  virtual void mouse_down(const SDL_MouseButtonEvent& event);
78  virtual void mouse_up(const SDL_MouseButtonEvent& event);
79 
80  virtual void draw_contents();
81 
82 private:
83 
84  void calculate_size();
85 
87 
89  itemImage_,
90  // normalImage_, activeImage_,
94  // disabledImage_, pressedDownDisabledImage_, pressedUpDisabledImage_, pressedBothDisabledImage_;
95 
96  SDL_Rect textRect_;
97 
98  enum STATE { UNINIT,
103  };
104 
105 
107 
108  bool pressed_;
109 
111 
113 
115 
116 }; //end class button
117 
118 }
119 
120 #endif
virtual void mouse_up(const SDL_MouseButtonEvent &event)
bool hit(int x, int y) const
virtual void mouse_down(const SDL_MouseButtonEvent &event)
virtual ~tristate_button()
Default implementation, but defined out-of-line for efficiency reasons.
Definition: video.hpp:58
PRESSED_STATE pressed_state() const
void set_item_id(const std::string &id)
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:3783
virtual void enable(bool new_val=true)
GLuint const GLfloat * val
Definition: glew.h:2614
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
editor::tristate_palette * palette_
void set_pressed(PRESSED_STATE new_pressed_state)
virtual void mouse_motion(const SDL_MouseMotionEvent &event)
void set_label(const std::string &val)
virtual void handle_event(const SDL_Event &event)
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
virtual void draw()
Definition: widget.cpp:283
cl_event event
Definition: glew.h:3070
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:27
virtual void draw_contents()
this module manages the cache of images.
Definition: image.cpp:75
std::vector< Uint32 > palette(color_range cr)
Creates a reference color palette from a color range.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
tristate_button(CVideo &video, editor::tristate_palette *palette, std::string button_image="", const bool auto_join=true)
const std::string & id() const
Definition: widget.cpp:232
void set_item_image(const surface &image)