SDL Window Engine  20200905
swe_wingui_button.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_GUI_BUTTON_
24 #define _SWE_GUI_BUTTON_
25 
26 #include "swe_wingui.h"
27 // WindowButton emit signals: Signal::ButtonPressed, Signal::ButtonReleased, Signal::ButtonClicked
28 
30 namespace SWE
31 {
32  struct KeySym;
33 
34  /* WindowButton */
36  {
37  int hotkey;
38 
39  protected:
40  virtual const Texture* textureFocused(void) const { return nullptr; }
41  virtual const Texture* textureDisabled(void) const { return texturePressed(); }
42  virtual const Texture* texturePressed(void) const { return textureReleased(); }
43  virtual const Texture* textureReleased(void) const { return nullptr; }
44  virtual const Texture* textureInformed(void) const { return nullptr; }
45 
46  bool mousePressEvent(const ButtonEvent &) override;
47  bool mouseReleaseEvent(const ButtonEvent &) override;
48  void mouseLeaveEvent(void) override;
49  void mouseFocusEvent(void) override;
50  bool keyPressEvent(const KeySym &) override;
51  bool keyReleaseEvent(const KeySym &) override;
52  void signalReceive(int, const SignalMember*) override;
53 
54  void setClickedComplete(void);
55  void setReleased(void);
56 
57  static u32 renderButtonComplete(u32 tick, void* ptr);
58 
59  virtual void renderFocused(void);
60  virtual void renderDisabled(void);
61  virtual void renderPressed(void);
62  virtual void renderReleased(void);
63  virtual void renderInformed(void);
64 
65  public:
67  WindowButton(const Size &, Window*);
68  WindowButton(const Point &, const Size &, Window*);
69  WindowButton(const WindowButton &);
70 
71  void renderWindow(void) override;
72 
73  void setAction(int);
74  void setDisabled(bool);
75  void setPressed(bool);
76  void setClicked(void);
77  void setInformed(bool);
78  void setHotKey(int);
79  void setHotKey(const std::string &);
80 
81  bool isAction(int) const;
82  bool isDisabled(void) const;
83  bool isPressed(void) const;
84  bool isReleased(void) const;
85  bool isHotKey(int) const;
86 
87  int action(void) const;
88  int hotKey(void) const;
89 
90  std::string toString(void) const override;
91 
92  const char* className(void) const override { return "SWE::WindowButton"; }
93 #ifdef SWE_WITH_JSON
94  JsonObject toJson(void) const override
95  {
96  JsonObject res = WindowToolTipArea::toJson();
97  res.addInteger("hotkey", hotkey);
98  return res;
99  }
100 #endif
101  };
102 
103  /* WindowCheckBox */
105  {
106  protected:
107  void mouseLeaveEvent(void) override;
108  bool mousePressEvent(const ButtonEvent &) override;
109  bool mouseReleaseEvent(const ButtonEvent &) override;
110 
111  public:
112  WindowCheckBox(Window* win) : WindowButton(win) {}
113  WindowCheckBox(const Size & sz, Window* win) : WindowButton(sz, win) {}
114  WindowCheckBox(const Point & pos, const Size & sz, Window* win) : WindowButton(pos, sz, win) {}
115 
116  void setChecked(bool f)
117  {
118  setPressed(f);
119  }
120  bool isChecked(void) const
121  {
122  return isPressed();
123  }
124 
125  const char* className(void) const override { return "SWE::WindowCheckBox"; }
126  };
127 
128  /* TextureButton */
130  {
131  protected:
132  Texture txRelease, txPress;
133 
134  const Texture* textureDisabled(void) const override;
135  const Texture* texturePressed(void) const override;
136  const Texture* textureReleased(void) const override;
137 
138 
139  public:
140  TextureButton(Window* win) : WindowButton(win) {}
141  TextureButton(const Size & sz, Window* win) : WindowButton(sz, win) {}
142  TextureButton(const Point & pos, const Size & sz, Window* win) : WindowButton(pos, sz, win) {}
143  TextureButton(const Point &, const Texture &, const Texture &, int action, Window*);
144 
145  void setSprites(const Texture & release, const Texture & press);
146 
147  const char* className(void) const override { return "SWE::TextureButton"; }
148 #ifdef SWE_WITH_JSON
149  JsonObject toJson(void) const override
150  {
151  JsonObject res = WindowButton::toJson();
152  res.addObject("press", txPress.toJson());
153  res.addObject("release", txRelease.toJson());
154  return res;
155  }
156 #endif
157  };
158 
159 } // SWE
160 #endif
Definition: swe_surface.h:154
класс объектов сцены DisplayScene, с возможностью отправки/получения сигналов
Definition: swe_events.h:56
пространство SWE.
Definition: swe_binarybuf.cpp:30
void signalReceive(int, const SignalMember *) override
метод получатель, вызывается при signalEmit со стороны отправителя
Definition: swe_wingui_button.cpp:270
Definition: swe_wingui.h:31
класс точки с двумя координатами
Definition: swe_rect.h:72
Definition: swe_inputs_keys.h:245
Definition: swe_wingui_button.h:35
Definition: swe_wingui_button.h:129
const char * className(void) const override
идентификацинная метка класса
Definition: swe_wingui_button.h:125
Definition: swe_wingui_button.h:104
const char * className(void) const override
идентификацинная метка класса
Definition: swe_wingui_button.h:147
event класс кнопки мыши
Definition: swe_events.h:145
класс двухмерной размерности
Definition: swe_rect.h:36
базовый класс графических объектов сцены DisplayScene.
Definition: swe_window.h:57
const char * className(void) const override
идентификацинная метка класса
Definition: swe_wingui_button.h:92