JugiMap Framework
jmNCine.h
1 
2 //===================================================================================================
3 // JugiMap API extension for nCIne.
4 //===================================================================================================
5 
6 #ifndef JUGIMAP_NCINE_H
7 #define JUGIMAP_NCINE_H
8 
9 #include <ncine/imgui.h>
10 #include <ncine/Texture.h>
11 #include <ncine/Sprite.h>
12 #include <ncine/DrawableNode.h>
13 #include <ncine/SceneNode.h>
14 #include <ncine/TextNode.h>
15 #include <ncine/Font.h>
16 #include <ncine/IFile.h>
17 #include "../jugimap/jugimap.h"
18 
19 #if defined(__ANDROID__)
20 #include <ncine/AssetFile.h>
21 #endif
22 
23 
24 
25 
26 
27 namespace jugimap {
28 
29 
30 
31 #if defined(__ANDROID__)
32 
33 
34 class AndroidBinaryFileStreamReaderNC : public BinaryStreamReader
35 {
36 public:
37 
38  AndroidBinaryFileStreamReaderNC(const std::string &fileName)
39  {
40  ncIFile = new ncine::AssetFile(fileName.c_str());
41  ncIFile->open(ncine::IFile::OpenMode::READ | ncine::IFile::OpenMode::BINARY);
42  }
43 
44  ~AndroidBinaryFileStreamReaderNC(){ if(ncIFile) delete ncIFile; }
45 
46 
47  bool IsOpen() override {return ncIFile->isOpened();}
48  int Pos() override {return ncIFile->tell();}
49  void Seek(int _pos) override {ncIFile->seek(_pos, SEEK_SET);}
50  int Size() override {return ncIFile->size();}
51 
52 
53  unsigned char ReadByte() override
54  {
55  unsigned char value;
56  ncIFile->read(reinterpret_cast<char*>(&value), 1);
57  return value;
58  }
59 
60  int ReadInt() override
61  {
62  int value;
63  ncIFile->read(reinterpret_cast<char*>(&value), 4);
64  return value;
65  }
66 
67  float ReadFloat() override
68  {
69  float value;
70  ncIFile->read(reinterpret_cast<char*>(&value), 4);
71  return value;
72  }
73 
74 
75  std::string ReadString() override
76  {
77  int length = ReadInt();
78  char *buf = new char[length];
79  ncIFile->read(buf, length);
80  std::string value(buf, length);
81  delete[] buf;
82  return value;
83  }
84 
85 
86 private:
87  ncine::IFile *ncIFile = nullptr; // OWNED
88 };
89 
90 #endif
91 
92 
93 
96 class GraphicFileNC : public GraphicFile
97 {
98 public:
99 
100  GraphicFileNC(){}
101  virtual ~GraphicFileNC() override;
102 
103  virtual void Init() override;
104 
106  ncine::Texture *GetNCTexture() {return ncTexture;}
107 
108 private:
109  ncine::Texture *ncTexture = nullptr; // OWNED
110 };
111 
112 
113 //===================================================================================================
114 
115 
119 {
120 public:
121 
122  StandardSpriteNC(){}
123  //StandardSpriteNC(SourceSprite *_sourceSprite, Vec2f _position, SpriteLayer *_spriteLayer);
124 
125  virtual void InitEngineObjects() override;
126  virtual void UpdateEngineObjects() override;
127  virtual void SetActiveImage(GraphicItem *_image) override;
128  //virtual void SetVisible(bool _visible) override;
129  virtual bool IsEngineSpriteInitialized() override {return (ncSprite!=nullptr);}
130 
132  ncine::Sprite * GetNCSprite() {return ncSprite;}
133 
134 private:
135 
136  ncine::Sprite *ncSprite = nullptr; // LINK
137 
138  void ManageShaders_OverlayColor();
139 
140 };
141 
142 
143 //===================================================================================================
144 
145 
148 class TextSpriteNC : public TextSprite
149 {
150 public:
151 
152  TextSpriteNC(){}
153  //TextSpriteNC(const std::string &_textString, Font* _font, ColorRGBA _color, Vec2f _position, TextHandleVariant _textHandle, SpriteLayer *_spriteLayer);
154 
155  virtual void InitEngineObjects() override;
156  virtual void UpdateEngineObjects() override;
157  virtual bool IsEngineSpriteInitialized() override { return (ncTextNode!=nullptr); }
158 
159  //---
161  ncine::TextNode* GetNCTextNode(){ return ncTextNode;}
162 
163 
164 private:
165  ncine::TextNode* ncTextNode = nullptr; // LINK
166  bool emptyString = false;
167 
168 };
169 
170 
171 //===================================================================================================
172 
173 
177 {
178 public:
179 
180  virtual void RemoveAndDeleteSprite(Sprite* _sprite) override;
181 
182 };
183 
184 
185 
186 //===================================================================================================
187 
190 class FontNC : public Font
191 {
192 public:
193 
194  FontNC(const std::string &_relativeFilePath, int _size, FontKind _kind);
195  virtual ~FontNC();
196 
198  ncine::Font* GetNCFont(){ return ncFont;}
199 
200  virtual int GetPixelWidth(const std::string &s) override;
201  virtual int GetPixelHeight(const std::string &s) override;
202  virtual Vec2f GetPixelSize(const std::string &s) override;
203 
204 private:
205  ncine::Font* ncFont = nullptr; // OWNED
206  ncine::TextNode* ncTextNode = nullptr; // OWNED
207 
208  ncine::SceneNode *dummySceneNode = nullptr;
209  std::string text;
210 };
211 
212 
213 /*
216 class TextNC : public Text
217 {
218 public:
219 
220  TextNC(TextLayer* _textLayer, Font *_font, const std::string &_textString, Vec2f _position, ColorRGBA _color);
221 
222 
223  virtual void UpdateEngineText();
224  virtual bool IsEngineTextInitialized(){ return (ncTextNode!=nullptr); }
225 
227  ncine::TextNode* GetNCTextNode(){ return ncTextNode;}
228 
229 
230 private:
231  ncine::TextNode* ncTextNode = nullptr; // LINK
232  bool emptyString = false;
233 };
234 
235 
236 //===================================================================================================
237 
238 
241 class TextLayerNC : public TextLayer
242 {
243 public:
244 
245  TextLayerNC(const std::string &_name) : TextLayer(_name) {}
246 
247  virtual void RemoveAndDeleteText(Text* _text) override;
248 
249 };
250 */
251 
252 //===================================================================================================
253 
254 
257 class DrawerNC : public Drawer
258 {
259 public:
260 
261  virtual void InitEngineDrawer() override;
262  virtual void UpdateEngineDrawer() override;
263 
264  virtual void Clear() override;
265 
266  virtual void SetOutlineColor(ColorRGBA _outlineColor) override;
267  virtual void Line(Vec2f p1, Vec2f p2) override;
268  virtual void RectangleOutline(const Rectf &rect) override;
269  virtual void EllipseOutline(Vec2f c, Vec2f r) override;
270  virtual void Dot(Vec2f p) override;
271 
272 
273 private:
274  //cocos2d::Color4F outlineColor;
275  //cocos2d::DrawNode * drawNode = nullptr; // LINK ( Cocos2d handles ownership of engine objects. )
276 
277  ImDrawList* drawList = nullptr;
278  ImColor outlineColor;
279 };
280 
281 
282 //===================================================================================================
283 
284 
285 class MapNC;
286 
289 class MapNCNode : public ncine::SceneNode
290 {
291 public:
292  explicit MapNCNode(MapNC * _map) : SceneNode() { map = _map;}
293 
294  virtual void visit(ncine::RenderQueue &renderQueue) override;
295 
296 private:
297  MapNC * map = nullptr; // LINK
298 };
299 
300 
301 
302 //===================================================================================================
303 
304 
307 class MapNC : public Map
308 {
309 public:
310 
311  MapNC(int _zOrderStart) : Map(_zOrderStart){}
312  virtual void InitEngineObjects(MapType _mapType) override;
313  virtual void UpdateEngineObjects() override;
314  virtual void SetVisible(bool _visible) override;
315 
317  MapNCNode * GetMapNCNode(){return mMapNCNode;}
318 
319 private:
320  MapNCNode * mMapNCNode = nullptr; // LINK
321 };
322 
323 
324 
325 //===================================================================================================
326 
327 
328 class EngineSceneCC;
329 
330 
331 class EngineSceneNC : public EngineScene
332 {
333 public:
334 
335  EngineSceneNC(Scene *_scene);
336  void PostInit() override;
337  // void SetSystemMouseCursorVisible(bool _visible) override;
338  //SceneCCNode* GetSceneNode(){ return ccSceneNode; }
339  ncine::SceneNode* GetEngineNode(){ return ncNode; }
340 
341 private:
342  ncine::SceneNode *ncNode = nullptr; // LINK
343 };
344 
345 
346 /*
347 class EngineAppCC;
348 
349 
352 class AppNCNode : public ncine::SceneNode
353 {
354 public:
355  friend class EngineAppCC;
356 
357 
361  AppNCNode(jugimap::App* _jmApp) : SceneNode() { jmApp = _jmApp;}
362 
364  virtual ~AppNCNode();
365 
369  //virtual bool init() override;
370 
372  virtual void update(float delta) override;
373 
374  virtual void visit(ncine::RenderQueue &renderQueue) override;
375 
377  jugimap::App * GetJMApp(){ return jmApp; }
378 
379 
380 private:
381  jugimap::App *jmApp = nullptr; // LINK
382  ncine::TextNode *errorMessageLabel = nullptr;
383 };
384 
385 */
386 
387 
388 class EngineAppNC : public EngineApp
389 {
390 public:
391 
392  EngineAppNC(App *_app);
393  void PostInit() override;
394  void SetSystemMouseCursorVisible(bool _visible) override;
395  ncine::SceneNode * GetAppNode(){ return appNCNode; }
396 
397 
398 private:
399  ncine::SceneNode * appNCNode = nullptr; // LINK
400  ncine::TextNode *errorMessageLabel = nullptr; // LINK
401 };
402 
403 //===================================================================================================
404 
405 
406 /*
407 class CommandsNC : public Commands
408 {
409 public:
410 
411  virtual void PreAppUpdate() override;
412  virtual void PostAppUpdate() override;
413  virtual void SetSystemMouseCursorVisible(bool _visible) override;
414 
415 };
416 */
417 
418 
419 //===================================================================================================
420 
421 
425 {
426 public:
427 
428 
429 #if defined(__ANDROID__)
430  virtual BinaryStreamReader* NewBinaryFileStreamReader(const std::string &fileName) override
431  {
432  return new AndroidBinaryFileStreamReaderNC(fileName);
433  }
434 #endif
435 
436  virtual EngineApp* NewEngineApp(App* _app) override { return new EngineAppNC(_app); }
437  virtual EngineScene* NewEngineScene(Scene *_scene) override { return new EngineSceneNC(_scene); }
438  virtual GraphicFile* NewFile() override { return new GraphicFileNC(); }
439  virtual Map* NewMap(int _zOrderStart) override { return new MapNC(_zOrderStart); }
440  virtual SpriteLayer *NewSpriteLayer() override { return new SpriteLayerNC(); }
441  virtual StandardSprite *NewStandardSprite() override { return new StandardSpriteNC (); }
442  //virtual StandardSprite *NewStandardSprite(SourceSprite *_sourceSprite, Vec2f _position, SpriteLayer *_spriteLayer) override
443  //{
444  // return new StandardSpriteNC(_sourceSprite, _position, _spriteLayer);
445  //}
446  virtual TextSprite *NewTextSprite() override { return new TextSpriteNC(); }
447  //virtual TextSprite *NewTextSprite(const std::string &_textString, Font* _font, ColorRGBA _color, Vec2f _position, TextHandleVariant _textHandle, SpriteLayer *_spriteLayer) override
448  //{
449  // return new TextSpriteNC (_textString, _font, _color, _position, _textHandle, _spriteLayer);
450  //}
451  virtual Font* NewFont(const std::string &_relativeFilePath, int _size=-1, FontKind _fontKind = FontKind::NOT_DEFINED) override
452  {
453  return new FontNC(_relativeFilePath, _size, _fontKind);
454  }
455  virtual Drawer* NewDrawer() override { return new DrawerNC(); }
456 
457 
458  //virtual TextLayer* NewTextLayer(const std::string &_name) override { return new TextLayerNC(_name); }
459 
460 };
461 
462 
463 //===================================================================================================
464 
465 
466 //void DeleteNCNode(ncine::SceneNode* _node);
467 //extern bool deleteNCNodesSpecial; // Use different way for deleting nodes with children nodes as 'delete node' causes crash in QCreator in debug mode (at least on my comp).
468 
469 extern ncine::TextNode * errorMessageLabel; // LINK
470 
471 
472 }
473 
474 
475 
476 
477 #endif
jugimap::TextSpriteNC::GetNCTextNode
ncine::TextNode * GetNCTextNode()
Returns the nCine text node.
Definition: jmNCine.h:161
jugimap::StandardSpriteNC
Extended StandardSprite class for nCine.
Definition: jmNCine.h:118
jugimap::DrawerNC::InitEngineDrawer
virtual void InitEngineDrawer() override
Initialize engine objects related to this drawer.
Definition: jmNCine.cpp:668
jugimap::Rect< float >
jugimap::StandardSpriteNC::SetActiveImage
virtual void SetActiveImage(GraphicItem *_image) override
Set the active image to the given *_image*.
Definition: jmNCine.cpp:99
jugimap::MapNC::SetVisible
virtual void SetVisible(bool _visible) override
Set the visibility of this map.
Definition: jmNCine.cpp:797
jugimap::StandardSpriteNC::InitEngineObjects
virtual void InitEngineObjects() override
Initialize the engine sprite.
Definition: jmNCine.cpp:63
jugimap::DrawerNC::Line
virtual void Line(Vec2f p1, Vec2f p2) override
Draw a line from the given position p1 to p2.
Definition: jmNCine.cpp:707
jugimap::ObjectFactoryNC::NewEngineApp
virtual EngineApp * NewEngineApp(App *_app) override
Returns a new map object.
Definition: jmNCine.h:436
jugimap::SpriteLayerNC
Extended SpriteLayer class for nCine.
Definition: jmNCine.h:176
jugimap::FontNC
Extended Font class for nCine.
Definition: jmNCine.h:190
jugimap::ColorRGBA
Color in RGBA color space - integer variant.
Definition: jmColor.h:15
jugimap::EngineScene
The EngineScene class defines engine specific scene properties.
Definition: jmScene.h:109
jugimap::App
The App is the base class of the application.
Definition: jmApp.h:22
jugimap::ObjectFactoryNC::NewStandardSprite
virtual StandardSprite * NewStandardSprite() override
Returns a new standard sprite object.
Definition: jmNCine.h:441
jugimap::ObjectFactoryNC::NewMap
virtual Map * NewMap(int _zOrderStart) override
Returns a new map object.
Definition: jmNCine.h:439
jugimap::Scene
The Scene class is the base class for the application scenes.
Definition: jmScene.h:23
jugimap::DrawerNC::RectangleOutline
virtual void RectangleOutline(const Rectf &rect) override
Draw the outline of the given rectangle rect.
Definition: jmNCine.cpp:720
jugimap::ObjectFactoryNC::NewFont
virtual Font * NewFont(const std::string &_relativeFilePath, int _size=-1, FontKind _fontKind=FontKind::NOT_DEFINED) override
Returns a new text object.
Definition: jmNCine.h:451
jugimap::GraphicItem
The GraphicItem class defines the equivalent object from JugiMap Editor.
Definition: jmSourceGraphics.h:34
jugimap::EngineApp
The EngineApp class defines engine specific application properties.
Definition: jmApp.h:115
jugimap::GraphicFileNC
Extended GraphicFile class for nCine.
Definition: jmNCine.h:96
jugimap::StandardSpriteNC::UpdateEngineObjects
virtual void UpdateEngineObjects() override
Update the engine sprite.
Definition: jmNCine.cpp:131
jugimap::DrawerNC
Extended Drawer class for Cocos2d-x.
Definition: jmNCine.h:257
jugimap::BinaryStreamReader
The base abstract class for reading binary streams.
Definition: jmStreams.h:33
jugimap::ObjectFactoryNC::NewFile
virtual GraphicFile * NewFile() override
Returns a new graphic file object.
Definition: jmNCine.h:438
jugimap::Map::Map
Map()
Constructor.
Definition: jmMap.h:34
jugimap::StandardSprite
The StandardSprite class defines the sprite from JugiMap Editor.
Definition: jmSprites.h:787
jugimap::TextSpriteNC::IsEngineSpriteInitialized
virtual bool IsEngineSpriteInitialized() override
Returns true if the engine sprite of this sprite has been initialized; otherwise returns false.
Definition: jmNCine.h:157
jugimap::MapNC::InitEngineObjects
virtual void InitEngineObjects(MapType _mapType) override
Initialize the engine map objects.
Definition: jmNCine.cpp:775
jugimap::DrawerNC::Clear
virtual void Clear() override
Clear this drawer (required by some engines).
Definition: jmNCine.cpp:694
jugimap::MapNCNode
Extended ncine::SceneNode class for use with MapNC objects.
Definition: jmNCine.h:289
jugimap::DrawerNC::EllipseOutline
virtual void EllipseOutline(Vec2f c, Vec2f r) override
Draw the outline of an ellipse defined by the given center point c and radius r.
Definition: jmNCine.cpp:731
jugimap::Sprite
The Sprite is the base sprite class.
Definition: jmSprites.h:32
jugimap::ObjectFactoryNC::NewSpriteLayer
virtual SpriteLayer * NewSpriteLayer() override
Returns a new sprite layer object.
Definition: jmNCine.h:440
jugimap::FontKind
FontKind
The kinds of font.
Definition: jmGlobal.h:124
jugimap::MapNC::GetMapNCNode
MapNCNode * GetMapNCNode()
Returns the MapNCNode object.
Definition: jmNCine.h:317
jugimap::DrawerNC::UpdateEngineDrawer
virtual void UpdateEngineDrawer() override
Update engine objects related to this drawer.
Definition: jmNCine.cpp:675
jugimap::GraphicFile
The GraphicFile class defines the equivalent object from JugiMap Editor.
Definition: jmSourceGraphics.h:148
jugimap::MapNC
Extended Map class for nCine.
Definition: jmNCine.h:307
jugimap::Drawer
The Drawer is the base drawer class.
Definition: jmDrawing.h:20
jugimap::ObjectFactoryNC
Extended ObjectFactory class for nCine.
Definition: jmNCine.h:424
jugimap::ObjectFactoryNC::NewDrawer
virtual Drawer * NewDrawer() override
Returns a new drawer object.
Definition: jmNCine.h:455
jugimap::MapType
MapType
The types of map.
Definition: jmGlobal.h:42
jugimap::GraphicFileNC::GetNCTexture
ncine::Texture * GetNCTexture()
Returns the nCine texture object.
Definition: jmNCine.h:106
jugimap::GraphicFileNC::Init
virtual void Init() override
Initialize this GraphicFile.
Definition: jmNCine.cpp:26
jugimap::ObjectFactoryNC::NewTextSprite
virtual TextSprite * NewTextSprite() override
Returns a new standard sprite object.
Definition: jmNCine.h:446
jugimap::ObjectFactoryNC::NewEngineScene
virtual EngineScene * NewEngineScene(Scene *_scene) override
Returns a new map object.
Definition: jmNCine.h:437
jugimap::DrawerNC::Dot
virtual void Dot(Vec2f p) override
Draw a dot at the given position p.
Definition: jmNCine.cpp:753
jugimap::Font
The Font class defines fonts used in TextSprite objects.
Definition: jmFont.h:16
jugimap::SpriteLayerNC::RemoveAndDeleteSprite
virtual void RemoveAndDeleteSprite(Sprite *_sprite) override
Remove and delete the given sprite *_sprite* from this sprite layer.
Definition: jmNCine.cpp:497
jugimap::ObjectFactory
The ObjectFactory is the base class for engine specific object factories.
Definition: jmObjectFactory.h:48
jugimap::TextSpriteNC::InitEngineObjects
virtual void InitEngineObjects() override
Initialize the engine sprite.
Definition: jmNCine.cpp:310
jugimap::Vec2
2d vector.
Definition: jmCommon.h:23
jugimap::StandardSpriteNC::GetNCSprite
ncine::Sprite * GetNCSprite()
Returns the nCine sprite object.
Definition: jmNCine.h:132
jugimap::TextSpriteNC
Extended TextSprite class for Cocos2d-x.
Definition: jmNCine.h:148
jugimap::FontNC::GetNCFont
ncine::Font * GetNCFont()
Returns the nCine font object.
Definition: jmNCine.h:198
jugimap::DrawerNC::SetOutlineColor
virtual void SetOutlineColor(ColorRGBA _outlineColor) override
Set outline color to the given *_outlineColor*.
Definition: jmNCine.cpp:701
jugimap::TextSprite
The TextSprite class defines the text sprite from JugiMap Editor.
Definition: jmSprites.h:889
jugimap::TextSpriteNC::UpdateEngineObjects
virtual void UpdateEngineObjects() override
Update the engine sprite.
Definition: jmNCine.cpp:397
jugimap::Map
The Map class defines the map element from JugiMap Editor.
Definition: jmMap.h:26
jugimap::MapNC::UpdateEngineObjects
virtual void UpdateEngineObjects() override
Update the engine map objects.
Definition: jmNCine.cpp:785
jugimap::StandardSpriteNC::IsEngineSpriteInitialized
virtual bool IsEngineSpriteInitialized() override
Returns true if the engine sprite of this sprite has been initialized; otherwise returns false.
Definition: jmNCine.h:129
jugimap::SpriteLayer
The SpriteLayer class defines the sprite and tile layers from JugiMap Editor.
Definition: jmLayers.h:303
jugimap::FontKind::NOT_DEFINED
The font kind not defined.