SDL Window Engine  20200905
swe_window.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_WINDOW_
24 #define _SWE_WINDOW_
25 
26 #include "swe_types.h"
27 #include "swe_tools.h"
28 #include "swe_rect.h"
29 #include "swe_surface.h"
30 #include "swe_fontset.h"
31 #include "swe_events.h"
32 #include "swe_display.h"
33 
35 namespace SWE
36 {
37 
38  typedef std::uintptr_t WindowId;
39  struct KeySym;
40 
41  enum { // Window 0xxxxx0000
42  FlagVisible = 0x80000000, FlagModality = 0x40000000, FlagFocused = 0x20000000, FlagBroken = 0x10000000,
43 
44  FlagKeyHandle = 0x04000000, FlagMouseTracking = 0x02000000, FlagSystemTickSkip = 0x01000000,
45  FlagLayoutHidden = 0x00800000, FlagLayoutBackground = 0x00200000, FlagLayoutForeground = 0x00100000,
46 
47  // GUI 0x0000xxxx
48  FlagPressed = 0x00080000, FlagInformed = 0x00040000, FlagSelected = 0x00020000, FlagDisabled = 0x00010000,
49  FlagWrap = 0x00008000, FlagVertical = 0x00004000,
50  FlagFreeMask = 0x00000FFF
51  };
52 
53  // MouseButtonHandle, SystemTickHandle
54  class Window;
55 
57  class Window : public SignalMember
58  {
59  friend class DisplayScene;
60 
61  //
62  void focusHandle(bool gain);
63  bool scrollHandle(bool isup);
64  bool mouseMotionHandle(const Point &, u32);
65  bool mouseButtonHandle(const ButtonEvent & st, bool press);
66  bool mouseClickHandle(const ButtonsEvent & st);
67  bool keyHandle(const KeySym & key, bool press);
68 
69  protected:
70  Rect gfxpos;
71  Window* prnt;
72  BitFlags state;
73  int result;
74 
75  void destroy(void);
76  void redraw(void);
77  void setSize(int, int);
78  void setPosition(int, int);
79 
80  // SignalMember:
81  // virtual void signalReceive(int, const SignalMember*) override {}
82  //
83  // ObjectEvent:
84  // virtual bool userEvent(int, void*) override { return false; }
85  // virtual void tickEvent(u32 ms) override {}
86 
87  // target
88  virtual Texture & targetTexture(void);
89 
90  // Window
91  virtual void textureInvalidEvent(void) {}
92  virtual void windowMoveEvent(const Point &) {}
93  virtual void windowResizeEvent(const Size &) {}
94  virtual void windowVisibleEvent(bool) {}
95  virtual void windowCreateEvent(void) {}
96  virtual bool keyPressEvent(const KeySym &) { return false; }
97  virtual bool keyReleaseEvent(const KeySym &) { return false; }
98  virtual bool textInputEvent(const std::string &) { return false; }
99  virtual bool mousePressEvent(const ButtonEvent &) { return false; }
100  virtual bool mouseReleaseEvent(const ButtonEvent &) { return false; }
101  virtual bool mouseClickEvent(const ButtonsEvent &) { return false; }
102  virtual void mouseFocusEvent(void) {}
103  virtual void mouseLeaveEvent(void) {}
104  virtual void mouseTrackingEvent(const Point &, u32 buttons) {}
105  virtual bool mouseMotionEvent(const Point &, u32 buttons) { return false; }
106  virtual bool scrollUpEvent(void) { return false; }
107  virtual bool scrollDownEvent(void) { return false; }
108  virtual void renderPresentEvent(u32 ms) {}
109  virtual void displayResizeEvent(const Size &) {}
110  virtual void displayFocusEvent(bool gain) {}
111 
112  protected:
113  bool checkState(size_t) const;
114  void setState(size_t);
115  void resetState(size_t);
116  void switchedState(size_t);
117 
118  virtual void renderBackground(void) {}
119  virtual void renderForeground(void) {}
120 
121  public:
122  Window(Window*);
123  Window(const Size &, Window*);
124  Window(const Point &, const Size &, Window*);
125  virtual ~Window();
126 
127  Window(Window &&) noexcept;
128  Window & operator= (Window &&) noexcept;
129 
130  Window(const Window &);
131  Window & operator= (const Window &);
132 
133  // Signal Member:
134  // void signalSubscribe(const SignalMember & sender, int sig);
135  // void signalUnsubscribe(const SignalMember &);
136  // void signalEmit(int);
137  //
138  // ObjectEvent:
139  // void pushEventAction(int code, const ObjectEvent* dst, void* data);
140 
141  bool isID(const WindowId &) const;
142  bool isVisible(void) const;
143  bool isHidden(void) const;
144  bool isFocused(void) const;
145  bool isModality(void) const;
146  bool isKeyHandle(void) const;
147  bool isMouseTrack(void) const;
148  virtual bool isAreaPoint(const Point &) const;
149  WindowId id(void) const;
150  const Point & position(void) const;
151  const Size & size(void) const;
152  const Rect & area(void) const;
153  const Window* parent(void) const;
154  Window* parent(void);
155  int width(void) const;
156  int height(void) const;
157  int resultCode(void) const;
158  Rect rect(void) const;
159 
160  void setState(size_t, bool f);
161  void setDirty(bool);
162  void setParent(Window*);
163  void setVisible(bool);
164  void setHidden(bool);
165  void setModality(bool);
166  void setKeyHandle(bool);
167  void setMouseTrack(bool);
168  void setResultCode(int);
169  virtual void setSize(const Size &);
170  virtual void setPosition(const Point &);
171 
172  int exec(void);
173 
175  void disableTickEvent(bool);
176 
177 
178  void renderSurface(const Surface &, const Point &, int flip = FlipNone);
179  void renderSurface(const Surface &, const Rect &, const Point &, int flip = FlipNone);
180  void renderTexture(const Texture &, const Point &, int flip = FlipNone);
181  void renderTexture(const Texture &, const Rect &, const Point &, int flip = FlipNone);
182  void renderTexture(const TexturePos &);
183 
184  Rect renderText(const FontRender &, const UnicodeString &, const Color &, const Point &,
185  const AlignType & hAlign = AlignLeft, const AlignType & vAlign = AlignTop, bool isHorizontal = true,
186  const CharRender & render = RenderDefault, int style = StyleDefault, const CharHinting & hinting = HintingDefault);
187 
188  virtual void renderClear(const Color &);
189  void renderColor(const Color &, const Rect &);
190  void renderRect(const Color &, const Rect &);
191  void renderLine(const Color &, const Point &, const Point &);
192  void renderPoint(const Color &, const Point &);
193 
194  virtual void renderWindow(void) = 0;
195 
196  const char* className(void) const override { return "SWE::Window"; }
197 #ifdef SWE_WITH_JSON
198  JsonObject toJson(void) const override;
199 #endif
200  void dumpState(void) const;
201  virtual std::string toString(void) const;
202  };
203 
204  class DisplayWindow : public Window
205  {
206  Color backcolor;
207 
208  public:
209  DisplayWindow(const Color & back = Color(Color::Black));
210 
211  void renderBackground(void) override;
212  void renderWindow(void) override {}
213 
214  const char* className(void) const override { return "SWE::DisplayWindow"; }
215 #ifdef SWE_WITH_JSON
216  JsonObject toJson(void) const override;
217 #endif
218  };
219 
220  class CenteredWindow : public Window
221  {
222  public:
223  CenteredWindow(const Size &, Window*);
224  const char* className(void) const override { return "SWE::CenteredWindow"; }
225  };
226 
227  class TargetWindow : public Window, public Texture
228  {
229  protected:
230  Texture & targetTexture(void) { return *this; }
231 
232  public:
233  TargetWindow(const Size &);
234  };
235 } // SWE
236 #endif
Definition: swe_surface.h:154
класс объектов сцены DisplayScene, с возможностью отправки/получения сигналов
Definition: swe_events.h:56
Definition: swe_types.h:216
const char * className(void) const override
идентификацинная метка класса
Definition: swe_window.h:224
const char * className(void) const override
идентификацинная метка класса
Definition: swe_window.h:214
пространство SWE.
Definition: swe_binarybuf.cpp:30
класс прямоугольника
Definition: swe_rect.h:144
по умолчанию (используется значение заданное при инициализации)
Definition: swe_fontset.h:82
event класс кнопки мыши (с состояниями press, release)
Definition: swe_events.h:159
const char * className(void) const override
идентификацинная метка класса
Definition: swe_window.h:196
класс точки с двумя координатами
Definition: swe_rect.h:72
Definition: swe_inputs_keys.h:245
void disableTickEvent(bool)
функция запрета обработки tickEvent.
Definition: swe_window.cpp:206
класс цвета
Definition: swe_colors.h:65
базовый класс шрифта
Definition: swe_fontset.h:151
по левому краю
Definition: swe_fontset.h:39
Definition: swe_surface.h:210
Definition: swe_display_scene.h:86
по верхнему краю
Definition: swe_fontset.h:41
AlignType
перечисление типа выравнивания
Definition: swe_fontset.h:37
event класс кнопки мыши
Definition: swe_events.h:145
класс двухмерной размерности
Definition: swe_rect.h:36
по умолчанию (используется значение заданное при инициализации)
Definition: swe_fontset.h:94
CharRender
перечисление типа рендера
Definition: swe_fontset.h:70
Definition: swe_window.h:204
Definition: swe_surface.h:58
Definition: swe_window.h:220
по умолчанию (используется значение заданное при инициализации)
Definition: swe_fontset.h:72
CharHinting
перечисление типа сглаживания контура
Definition: swe_fontset.h:92
базовый класс графических объектов сцены DisplayScene.
Definition: swe_window.h:57
Definition: swe_window.h:227
класс unicode строки
Definition: swe_cunicode.h:41