// // 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 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 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 _autofillRects; std::function _autofillCallback; std::vector _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 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 */