#include <image.h>


enum LineStyle
{
    NoLine,
    SolidLine,
    DottedLine,
    DashedLine
};


enum FillStyle
{
    NoFill,
    SolidFill,
    GradientFill,
    ImageFill
};


/*
    Should I consider fractional units?

    Line could for example begin at (0.4, 0.7) and go to (2.3,4.5) and then antialiasing makes even more sense.
    If using points with integer values, then need to remember that really (0,0) marks the middle of an area
    around (0,0) which would be an area from (-0.5,-0.5) to (0.5,0.5) if it is a square point. If what we really
    want is the square area from (0,0) to (1,1), then the center of that point is really (0.5,0.5). So if we
    want pixel [0][0], this really means (0.5,0.5) in the fractional style notation. Fraction units makes it
    hard to use integers and access the half rows around the border of the screen unless trying to plot pixels
    off the screen at -1,y and x,-1 and w+1,y etc. The other way is to just treat the 2D Point coordinate as
    a pixel array indices, eg, we could subtract 0.5,0.5 to all values if we want to convert integer pixel values
    to fraction point positions (and conversely add 0.5,0.5 to convert the other direction).

    Starts to get a little complicated.

    First step is to create a basic painter that can plot pixels with integer coordinates.

    Line, circle and curve drawing perhaps should be posponed until fractional units are added.

    Text rendering with fractional units might be useful, so perhaps fractional unit blitting might be the
    first thing to add with fractional coordinates, but should optimize obviously for the integer case.
    Fractional unit blitting might not be too hard, need to consider the first two lines, always using two
    scan lines at a time, and as progressing, using 4 of the pixels, eg a 2x2 box used for calculating the
    value for the given pixel on the screen. This is done by calculating the area proportions of each part
    of the 2x2 block that the image pixel contributes to the screen pixel and scaling that to a value
    between 0-65536 for example and then multiplying each of the 4 pixel values with this value, summing
    the result, and then dividing by 65536. This should then give the correct result for sub-pixel blitting.
*/
class Point2D
{
public:
    int x;
    int y;
};


class Size2D
{
public:
    int w;
    int h;
};


class Painter
{
public:
    Painter(Image *_target) : target(_target) {}
    virtual ~Painter() {}

//    void setRotation(int angle);
//    void setTranslation(Point2D offset);

    void setLineStyle(LineStyle lineStyle);
    void setFillStyle(FillStyle fillStyle);

    void drawTriangle (Point2D a, Point2D b, Point2D c, LineStyle lineStyle, FillStyle fillStyle);
    void drawPolygon  (Point2D *points, int pointCount, LineStyle lineStyle, FillStyle fillStyle);
    void drawEllipse  (Point2D origin, Size2D size, LineStyle lineStyle, FillStyle fillStyle);
    void drawRect     (Point2D origin, Size2D size, LineStyle lineStyle, FillStyle fillStyle);
    void drawLine     (Point2D origin, Size2D size, LineStyle lineStyle);
    void drawCurve    (Point2D a, Point2D b, Point2D controlA, Point2D controlB, LineStyle lineStyle);
    void drawImage    (Point2D origin, Size2D size, Image *src, Point2D srcOrigin);
    void drawText     (Point2D origin, const char *string, LineStyle lineStyle, FillStyle fillStyle);

private:
    Image *target;
};


