ToyColourableSprite.h
4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// ToyColourableSprite.h
// SteveMaggieCpp
//
// Created by Katarzyna Kalinowska-Górska on 17.05.2017.
//
//
#ifndef ToyColourableSprite_h
#define ToyColourableSprite_h
#include "ToyPlainNode.h"
#include "ToyDraggableBrushSprite.h"
#include "2d/CCRenderTexture.h"
#include <cstdint>
class ToyColourableSprite : public ToyPlainNode
{
public:
struct AutofillRect {
cocos2d::Rect rect;
bool visited;
AutofillRect(cocos2d::Rect pRect, bool pVisited){
rect = pRect;
visited = pVisited;
}
};
const float defaultBrushThickness = 30;
// creating / destroying
static ToyColourableSprite* createWithSpritePaths(std::string whiteSpritePath, std::string revealedSpritePath);
virtual bool initWithSpritePaths(std::string whiteSpritePath, std::string revealedSpritePath);
virtual ~ToyColourableSprite();
// ToyLayoutObject overrides
virtual void loadPropertiesFromJSON(const rapidjson::Value& jsonValue, ToyLayoutViewInterface* scene = NULL, const std::string resFolder = "", const std::string altResFolder = "") override;
virtual void prepareSize(const rapidjson::Value& jsonValue, float& width, float& height) override;
// other overrides
virtual void onEnter() override;
virtual void setOpacity(uint8_t op) override;
// others
virtual void startUsingBrush(ToyDraggableBrushSprite* brush);
virtual void endUsingBrush();
virtual void clear();
virtual void flashOnce(float delaySecs);
virtual void flash(float time, int times);
virtual void stopFlashing();
virtual void autofill();
virtual void startAutofillAnimation();
virtual void startDemoAnimation(ToyDraggableBrushSprite* brush);
virtual void update(float delta) override;
friend class ToyBlockingActionParser; //temp
// Scenario Object
virtual void setProperty(std::string propertyName, const rapidjson::Value& newValue, ActionParseDelegate* parseDelegate) override;
virtual void callFunctionByName(std::string methodName, const rapidjson::Value* arguments, ActionParseDelegate* parseDelegate, std::function<void()> callback = [](){}) override;
virtual std::string getPropertyAsString(std::string propertyName = "") override;
protected:
const float _autofillVelocity = 600;
bool _flashable;
bool _whiteSpriteDisappears;
bool _colouringEnabled;
bool _autofilled;
bool _drawingWithFinger;
cocos2d::Point _previousTouchPoint;
cocos2d::Point _currentTouchPoint;
bool _deferringRepaint;
bool _playingDemoAnimation;
bool _autofilling;
float _sumDy;
int _currentRoutePointIndex;
float _brushThickness;
std::string _whiteSpriteFilePath;
std::string _revealedSpriteFilePath;
cocos2d::Sprite* _whiteSprite;
cocos2d::Sprite* _revealedSprite;
cocos2d::Sprite* _flashingSprite;
cocos2d::RenderTexture* _renderTextureWhite;
cocos2d::RenderTexture* _renderTextureRevealed;
cocos2d::DrawNode* _drawNodeWhite;
cocos2d::DrawNode* _drawNodeRevealed;
std::vector<AutofillRect> _autofillRects;
std::function<void()> _autofillCallback;
std::vector<cocos2d::Point> _rememberedTouchLocations;
cocos2d::Rect _lastBrushIntersection;
ToyDraggableBrushSprite* _brush;
virtual void configureTouchListeners();
virtual bool drawLinesOnTouch(cocos2d::Touch* touch);
virtual void paintWithBrush(ToyDraggableBrushSprite* brush, bool usePreviousBrushLocation);
virtual void repaintTextures(bool clear);
virtual void drawOnTextures(std::function<void(cocos2d::DrawNode*)> drawNodeDrawBlock, bool clearTextures);
virtual void drawLine(cocos2d::Point location1, cocos2d::Point location2, float brushThickness);
virtual void markAutofillRectangles(cocos2d::Point point1, cocos2d::Point point2);
virtual void markAutofillRectanglesByPoint(cocos2d::Point point);
virtual void markAutofillRectanglesByRect(cocos2d::Rect rect);
virtual bool checkAutofillRectangles();
virtual void tempClear();
virtual void tempRefill();
};
#endif /* ToyColourableSprite_h */