The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 BUTTON_H_INCLUDED
15 #define BUTTON_H_INCLUDED
16 
17 #include "widget.hpp"
18 
19 #include "exceptions.hpp"
20 
21 #ifdef SDL_GPU
22 #include "sdl/image.hpp"
23 #endif
24 
25 namespace gui {
26 
27 class button : public widget
28 {
29 public:
30  struct error : public game::error {
32  : game::error("GUI1 button error")
33  {}
34  };
35 
37 
39 
41  std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE,
42  const bool auto_join=true, std::string overlay_image="");
43 
44 
45  /** Default implementation, but defined out-of-line for efficiency reasons. */
46  virtual ~button();
47  void set_check(bool check);
48  void set_active(bool active);
49  bool checked() const;
50 
51  void set_label(const std::string& val);
52  void set_image(const std::string& image_file_base);
53  void set_overlay(const std::string& image_file_base);
55 
56  bool pressed();
57  bool hit(int x, int y) const;
58  virtual void enable(bool new_val=true);
59  void release();
60 
61 protected:
62  virtual void handle_event(const SDL_Event& event);
63  virtual void mouse_motion(const SDL_MouseMotionEvent& event);
64  virtual void mouse_down(const SDL_MouseButtonEvent& event);
65  virtual void mouse_up(const SDL_MouseButtonEvent& event);
66  virtual void draw_contents();
67 
69 
70 private:
71 
72  void load_images();
73 
74  void calculate_size();
75 
77 
78 #ifdef SDL_GPU
79  sdl::timage label_image_;
84 #else
89 #endif
90  SDL_Rect textRect_;
91 
94 
95  bool pressed_;
96 
98 
100 
104 
105 }; //end class button
106 
107 }
108 
109 #endif
std::string button_image_name_
Definition: button.hpp:101
void set_check(bool check)
Definition: button.cpp:352
virtual void mouse_up(const SDL_MouseButtonEvent &event)
Definition: button.cpp:689
button(CVideo &video, const std::string &label, TYPE type=TYPE_PRESS, std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE, const bool auto_join=true, std::string overlay_image="")
Definition: button.cpp:47
std::string button_image_path_suffix_
Definition: button.hpp:103
static void check(LexState *ls, int c)
Definition: lparser.cpp:109
bool pressed_
Definition: button.hpp:95
int base_height_
Definition: button.hpp:99
void set_label(const std::string &val)
Definition: button.cpp:604
surface pressedActiveImage_
Definition: button.hpp:85
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void set_image(const std::string &image_file_base)
Definition: button.cpp:582
surface pressedImage_
Definition: button.hpp:85
Definition: video.hpp:58
virtual void enable(bool new_val=true)
Definition: button.cpp:386
surface overlayPressedImage_
Definition: button.hpp:85
surface activeImage_
Definition: button.hpp:85
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
void set_image_path_suffix(const std::string &suffix)
Definition: button.hpp:54
GLuint const GLfloat * val
Definition: glew.h:2614
surface disabledImage_
Definition: button.hpp:85
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
virtual void mouse_down(const SDL_MouseButtonEvent &event)
Definition: button.cpp:661
void load_images()
Definition: button.cpp:92
virtual void draw_contents()
Definition: button.cpp:399
int base_width_
Definition: button.hpp:99
void release()
Definition: button.cpp:684
surface overlayImage_
Definition: button.hpp:85
std::string button_overlay_image_name_
Definition: button.hpp:102
void calculate_size()
Definition: button.cpp:291
SPACE_CONSUMPTION spacing_
Definition: button.hpp:97
TYPE type_
Definition: button.hpp:68
surface touchedImage_
Definition: button.hpp:85
virtual void mouse_motion(const SDL_MouseMotionEvent &event)
Definition: button.cpp:627
SPACE_CONSUMPTION
Definition: button.hpp:38
void set_overlay(const std::string &image_file_base)
Definition: button.cpp:593
bool pressed()
Definition: button.cpp:770
surface image_
Definition: button.hpp:85
Contains a wrapper class for the GPU_Image class.
virtual void handle_event(const SDL_Event &event)
Definition: button.cpp:740
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
bool hit(int x, int y) const
Definition: button.cpp:575
surface overlayPressedDisabledImage_
Definition: button.hpp:85
surface overlayActiveImage_
Definition: button.hpp:85
std::string label_text_
Definition: button.hpp:76
SDL_Rect textRect_
Definition: button.hpp:90
virtual ~button()
Default implementation, but defined out-of-line for efficiency reasons.
Definition: button.cpp:287
cl_event event
Definition: glew.h:3070
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:27
bool checked() const
Definition: button.cpp:381
surface pressedDisabledImage_
Definition: button.hpp:85
STATE state_
Definition: button.hpp:93
GLsizei const GLcharARB ** string
Definition: glew.h:4503
surface overlayDisabledImage_
Definition: button.hpp:85
void set_active(bool active)
Definition: button.cpp:370