Oxygine  1
2g game engine
initActor.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "Actor.h"
4 #include "Sprite.h"
5 #include "Button.h"
6 #include "TextField.h"
7 namespace oxygine
8 {
9 
10  namespace args
11  {
12  template<typename value, typename valueRef, typename C, void (C::*SetF)(valueRef)>
13  class argT
14  {
15  bool _init;
16  value _v;
17 
18  public:
19  argT(): _init(false) {}
20 
21  argT& operator = (valueRef v)
22  {
23  _init = true;
24  _v = v;
25  return *this;
26  }
27 
28  argT& operator = (intrusive_ptr<C> v)
29  {
30  _init = true;
31  _v = v.get();
32  return *this;
33  }
34 
35  void apply(C* c) const
36  {
37  if (!_init)
38  return;
39  return (c->*SetF)(_v);
40  }
41  };
42 
65 
74 
75 
76  class animFrame
77  {
78  const ResAnim* _resAnim;
79  int _col;
80  int _row;
81  bool _managed;
82  AnimationFrame _frame;
83  bool _useResAnim;
84 
85  public:
86  animFrame(bool managed, int col, int row): _col(col), _row(row), _resAnim(0), _useResAnim(true), _managed(managed) {}
87 
88  animFrame& operator = (const ResAnim* r)
89  {
90  _useResAnim = true;
91  _resAnim = r;
92  return *this;
93  }
94 
95  animFrame& operator = (const AnimationFrame& frame)
96  {
97  _useResAnim = false;
98  _frame = frame;
99  return *this;
100  }
101 
102  void apply(Sprite* s) const
103  {
104  if (_managed)
105  s->setManageResAnim(_managed);
106  if (_useResAnim)
107  return s->setAnimFrame(_resAnim, _col, _row);
108  return s->setAnimFrame(_frame);
109  }
110 
111  void apply(Button* b) const
112  {
113  OX_ASSERT(_useResAnim);
114  b->setResAnim(_resAnim);
115  }
116  };
117 
118 
119 #define arg_position args::position()
120 #define arg_pos arg_position
121 #define arg_x args::x()
122 #define arg_y args::y()
123 
124 #define arg_anchor args::anchor()
125 
126 #define arg_rotation args::rotation()
127 #define arg_rot arg_rotation
128 
129 #define arg_visible args::visible()
130 #define arg_vis args::visible()
131 
132 #define arg_width args::width()
133 #define arg_w arg_width
134 #define arg_height args::height()
135 #define arg_h arg_height
136 #define arg_size args::size()
137 
138 #define arg_scale args::scale()
139 #define arg_scale2 args::scale2()
140 #define arg_scaleX args::scaleX()
141 #define arg_scaleY args::scaleY()
142 
143 #define arg_name args::name()
144 
145 #define arg_alpha args::alpha()
146 #define arg_color args::color()
147 #define arg_blend args::blend()
148 
149 #define arg_input args::input()
150 #define arg_attachTo args::attachTo()
151 #define arg_priority args::priority()
152 #define arg_userData args::userData()
153 
154 #define arg_extendedClickArea args::extendedClickArea()
155 
156 
157 
158 //sprite or button
159 #define arg_animFrame args::animFrame(false, 0, 0)
160 #define arg_resAnim args::animFrame(false, 0, 0)
161 #define arg_managedResAnim args::animFrame(true, 0, 0)
162 
163 //TextField
164 #define arg_style args::style()
165 #define arg_text args::text()
166 #define arg_htmlText args::htmlText()
167 #define arg_hAlign args::hAlign()
168 #define arg_vAlign args::vAlign()
169 #define arg_fontSize args::fontSize()
170 #define arg_font args::font()
171 #define arg_multiline args::multiline()
172 #define arg_tcolor args::color()
173 //Button
174 #define arg_onClick args::onClick()
175 
176 
177  }
178 
179  template<class T>
180  T initActor(T actor)
181  {
182  return actor;
183  }
184 
185  template<class T, class A1>
186  T initActor(T actor, const A1& arg1)
187  {
188  initActor(actor);
189  arg1.apply(actor);
190 
191  return actor;
192  }
193 
194  template<class T, class A1, class A2>
195  T initActor(T actor, const A1& arg1, const A2& arg2)
196  {
197  initActor(actor, arg1);
198  arg2.apply(actor);
199  return actor;
200  }
201 
202  template<class T, class A1, class A2, class A3>
203  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3)
204  {
205  initActor(actor, arg1, arg2);
206  arg3.apply(actor);
207  return actor;
208  }
209 
210  template<class T, class A1, class A2, class A3, class A4>
211  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4)
212  {
213  initActor(actor, arg1, arg2, arg3);
214  arg4.apply(actor);
215  return actor;
216  }
217 
218  template<class T, class A1, class A2, class A3, class A4, class A5>
219  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4, const A5& arg5)
220  {
221  initActor(actor, arg1, arg2, arg3, arg4);
222  arg5.apply(actor);
223  return actor;
224  }
225 
226  template<class T, class A1, class A2, class A3, class A4, class A5, class A6>
227  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4, const A5& arg5, const A6& arg6)
228  {
229  initActor(actor, arg1, arg2, arg3, arg4, arg5);
230  arg6.apply(actor);
231  return actor;
232  }
233 
234  template<class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
235  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4, const A5& arg5, const A6& arg6, const A7& arg7)
236  {
237  initActor(actor, arg1, arg2, arg3, arg4, arg5, arg6);
238  arg7.apply(actor);
239  return actor;
240  }
241 
242  template<class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
243  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4, const A5& arg5, const A6& arg6, const A7& arg7, const A8& arg8)
244  {
245  initActor(actor, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
246  arg8.apply(actor);
247  return actor;
248  }
249 
250  template<class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
251  T initActor(T actor, const A1& arg1, const A2& arg2, const A3& arg3, const A4& arg4, const A5& arg5, const A6& arg6, const A7& arg7, const A8& arg8, const A9& arg9)
252  {
253  initActor(actor, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
254  arg9.apply(actor);
255  return actor;
256  }
257 }
Definition: Sprite.h:14
Definition: initActor.h:13
Definition: intrusive_ptr.h:12
Definition: AnimationFrame.h:28
–oxgl-end–!
Definition: Actor.h:14
void setAnimFrame(const AnimationFrame &f)
Definition: Button.h:8
Definition: ResAnim.h:13
Definition: initActor.h:76
void setManageResAnim(bool manage)