SDL Window Engine  20200905
swe_object.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_OBJECT_
24 #define _SWE_OBJECT_
25 
26 #include "swe_types.h"
27 
28 #ifdef SWE_WITH_JSON
29 #include "swe_json_ext.h"
30 #endif
31 
33 namespace SWE
34 {
35  class DisplayScene;
36 
39  {
40  public:
41  virtual ~ObjectClass() {}
42 
44  virtual const char* className(void) const
45  {
46  return "SWE::ObjectClass";
47  }
48 
49 #ifdef SWE_WITH_JSON
50  virtual JsonObject toJson(void) const
52  {
53  JsonObject res;
54  res.addString("className", className());
55  return res;
56  }
57 #endif
58  };
59 
61 
79  class ObjectEvent : public ObjectClass
80  {
81  protected:
82  friend class DisplayScene;
83 
88  virtual bool userEvent(int code, void* data) { return false; }
89 
93  virtual void tickEvent(u32 ms) {}
94 
95  public:
96  virtual ~ObjectEvent() {}
97 
102  void pushEventAction(int code, ObjectEvent* dst, void* data);
103 
104  const char* className(void) const override
105  {
106  return "SWE::ObjectEvent";
107  }
108  };
109 }
110 
111 #endif
класс объектов сцены DisplayScene, с возможностью отправки/получения сообщений
Definition: swe_object.h:79
virtual bool userEvent(int code, void *data)
метод получатель, вызывается при получении сообщения, отправленного через pushEventAction.
Definition: swe_object.h:88
пространство SWE.
Definition: swe_binarybuf.cpp:30
virtual void tickEvent(u32 ms)
метод получатель, вызывается один раз за каждую итерацию главного цикла сцены DisplayScene, но перед отрисовкой всей сцены
Definition: swe_object.h:93
void pushEventAction(int code, ObjectEvent *dst, void *data)
функция отправки сообщения с данными для объектов сцены DisplayScene.
Definition: swe_object.cpp:26
Definition: swe_display_scene.h:86
virtual const char * className(void) const
идентификацинная метка класса
Definition: swe_object.h:44
родительский класс объектов сцены DisplayScene.
Definition: swe_object.h:38
const char * className(void) const override
идентификацинная метка класса
Definition: swe_object.h:104