The Battle for Wesnoth  1.13.10+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 - 2017 by David White <dave@whitevine.net>
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 
15 #pragma once
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) override;
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() override {
70  widget::draw();
71  }
72 
73 protected:
74 
75  virtual void handle_event(const SDL_Event& event) override;
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() override;
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 }
virtual void mouse_up(const SDL_MouseButtonEvent &event)
bool hit(int x, int y) const
std::vector< char_t > string
virtual void mouse_down(const SDL_MouseButtonEvent &event)
std::vector< color_t > palette(const color_range &cr)
Creates a reference color palette from a color range.
Definition: color_range.cpp:85
virtual ~tristate_button()
Default implementation, but defined out-of-line for efficiency reasons.
Definition: video.hpp:29
PRESSED_STATE pressed_state() const
void set_item_id(const std::string &id)
CVideo & video() const
Definition: widget.hpp:84
General purpose widgets.
editor::tristate_palette * palette_
void set_pressed(PRESSED_STATE new_pressed_state)
virtual void handle_event(const SDL_Event &event) override
virtual void mouse_motion(const SDL_MouseMotionEvent &event)
void set_label(const std::string &val)
virtual void draw_contents() override
virtual void draw()
Definition: widget.cpp:277
void draw() override
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
this module manages the cache of images.
Definition: image.cpp:109
virtual void enable(bool new_val=true) override
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:230
void set_item_image(const surface &image)