//
//  PolygonNode.h
//  Meteor
//
//  Created by Cesar Parent on 10/08/2015.
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#ifndef __Meteor__PolygonNode__
#define __Meteor__PolygonNode__

#include "Node.h"
#include "../Graphics.h"


NS_BEGIN

/*!
 * @class           PolygonNode
 * @ingroup         GameObjects
 * @brief           A node that can draw arbitrary polygon outlines.
 */
class PolygonNode : public Node {
    
public:
    
    /*!
     * @name        Creating Polygon Nodes.
     * @{
     */
    
    /*!
     * @brief       Creates a new Polygon Node from an Polygon object.
     * @param       shape       Polygon object to create the node from.
     */
    PolygonNode(const Polygon& shape);
    
    /*!
     * @}
     */
    
    virtual ~PolygonNode();
    
    // MARK: -
    // MARK: Getters
    
    /*!
     * @name        Inspecting the Polygon's properties
     * @{
     */
    
    /*!
     * @brief       Returns the color used to draw the polygon's outline.
     * @details     By default, the color is <code>Color::whiteColor</code>.
     * @return      The color used to draw the polygon's outline.
     * @see         setStrokeColor(const Color&)
     */
    Color
    strokeColor() const { return _strokeColor; }
    
    /*!
     * @brief       Returns the color used to fill the polygon.
     * @details     By default, the color is <code>Color::clearColor</code>, which means the
     *              shape is not filled
     * @return      The color used to fill the polygon.
     * @see         setFillColor(const Color&)
     */
    Color
    fillColor() const { return _fillColor; }
    
    /*!
     * @brief       Returns a reference to the node's polygon.
     * @return      A reference to the underlying polygon object.
     */
    Polygon&
    shape() { return _shape; _frameDirty = true; }
    
    /*!
     * @brief       Return the polygon's bounding box.
     * @return      The polygon's bounding box.
     */
    Rect
    frame() const;
    
    /**
     * @}
     */
    
    
    // MARK: -
    // MARK: Setters
    
    /*!
     * @name        Changing the Polygon's properties
     * @{
     */
    
    /*!
     * @brief       Sets the color used to draw the polygon's outline.
     * @details     By default, the color is <code>Color::whiteColor</code>.
     * @param       color       The color used to draw the polygon's outline.
     * @see         strokeColor()
     */
    void
    setStrokeColor(const Color& color) { _strokeColor = color; }
    
    /*!
     * @brief       Sets the color used to fill the polygon.
     * @details     By default, the color is <code>Color::clearColor</code>, which means the
     *              shape is not filled
     * @param       color       The color used to fill the polygon.
     * @see         fillColor()
     */
    void
    setFillColor(const Color& color) { _fillColor = color; }
    
    /*!
     * @}
     */
    
    /*!
     * @internal
     */
    virtual void
    draw(RendererProtocol& renderer) override;
    
    
private:
    
    virtual void
    invalidateCachedTransform() const override;
    
    Polygon         _shape;
    
    Color           _strokeColor;
    
    Color           _fillColor;
    
    mutable Rect    _frame;
    
    mutable bool    _frameDirty;
};

NS_END

#endif /* defined(__Meteor__PolygonNode__) */
