/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx_ColorSpace.h>

#include "TestUtility.h"


//
// Helper functions
//
template <typename ColorFX2DPainter_T>
static void dumpBufferRaw1Dot(const ColorFX2DPainter_T& painter)
{
    typename ColorFX2DPainter_T::ConstIterator it = painter.colorBufferData();

    for(typename ColorFX2DPainter_T::BufferSizeType y = 0; y < ColorFX2DPainter_T::YElementCount; ++y) {
        for(typename ColorFX2DPainter_T::BufferSizeType x = 0; x < ColorFX2DPainter_T::XElementCount; ++x) {
            printf("%s ", (*it++) ? "⬤" : "·");
        }
        printf("\n");
    }
}


//
// Test application
//
int main()
{
    const eCxx::WColor white(255);
    eCxx::ColorFX2DPainter<eCxx::WColor, 8 * 10, 8 * 4, eCxx::CBP::DefaultLayout, eCxx::CBP::RawBuffer> cfxp;
    printf("\n");

    cfxp.clear();
    cfxp.putCharXY( 0, 0, white, '0', eCxx::DefaultASCIIFont5x7  );
    cfxp.putCharXY(20, 0, white, '0', eCxx::DefaultASCIIFont10x15);
    dumpBufferRaw1Dot(cfxp);
    printf("\n");

    cfxp.clear();
    cfxp.putHTextXY( 0,  0, white,         "(A`b c)",  eCxx::DefaultASCIIFont5x7  );
    cfxp.putHTextXY(-2,  8, white, PGM_STR("(A`b c)"), eCxx::DefaultASCIIFont10x15);
    cfxp.putHTextXY(25, 24, white, PGM_STR("(A`b c)"), eCxx::DefaultASCIIFont10x15);
    dumpBufferRaw1Dot(cfxp);
    printf("\n");

    cfxp.clear();
    cfxp.putVTextXY      (-2,  0, white, PGM_STR("ABC"), eCxx::DefaultASCIIFont5x7,    1);
    cfxp.putVTextXY      (10,  0, white, PGM_STR("ABC"), eCxx::DefaultASCIIFont5x7,    1);
    cfxp.putVTextXY      (77,  0, white, PGM_STR("ABC"), eCxx::DefaultASCIIFont5x7,    1);
    cfxp.putVTextXY      (30, -1, white,         "ABC",  eCxx::DefaultASCIIFont10x15, -3);
    cfxp.putVTextXY      (45, -4, white,         "ABC",  eCxx::DefaultASCIIFont10x15, -3);
    dumpBufferRaw1Dot(cfxp);
    printf("\n");

    cfxp.clear();
    cfxp.putHTextXY   ( 0,  0, white,         "ABC",  eCxx::DefaultASCIIFont5x7, 1);
    cfxp.putRevHTextXY(79,  0, white,         "ABC",  eCxx::DefaultASCIIFont5x7, 1);
    cfxp.putVTextXY   (33,  0, white, PGM_STR("ABC"), eCxx::DefaultASCIIFont5x7, 1);
    cfxp.putRevVTextXY(42, 31, white, PGM_STR("ABC"), eCxx::DefaultASCIIFont5x7, 1);
    dumpBufferRaw1Dot(cfxp);
    printf("\n");

    _DIVIDERLINE_DASHSTR_NL2();



    cfxp.clear();

    cfxp.drawHLine( 1,  1,  9,     white);
    cfxp.drawVLine( 1,  3,  9,     white);
    cfxp.drawGLine( 3,  3,  8,  8, white);
    cfxp.drawGLine( 8,  3,  3,  8, white);
    cfxp.drawGLine( 1, 15, 11, 16, white);
    cfxp.drawGLine( 1, 18, 11, 22, white);
    cfxp.drawGLine(11, 24,  1, 28, white);
    cfxp.drawRectangle(15,  1, 25,  8, white);
    cfxp.fillRectangle(15, 11, 25, 18, white);

    cfxp.drawCircle(35,  6,  4, white); cfxp.drawCircle(35,  6, 0, white);
    cfxp.drawCircle(35, 23,  7, white); cfxp.drawCircle(35, 23, 1, white);
    cfxp.drawCircle(52, 13, 10, white); cfxp.drawCircle(52, 13, 2, white);
    cfxp.fillCircle(69,  6,  4, white);
    cfxp.fillCircle(69, 23,  7, white);

    dumpBufferRaw1Dot(cfxp);
    printf("\n");



    cfxp.clear();
    cfxp.drawEllipse(11,  8, 10,  6, white); cfxp.drawEllipse(11,  8, 2, 1, white);
    cfxp.drawEllipse(29, 11,  6, 10, white); cfxp.drawEllipse(29, 10, 1, 2, white);
    
    cfxp.fillEllipse(11, 23, 10,  6, white);
    cfxp.fillEllipse(43, 11,  6, 10, white);

    cfxp.drawEllipse(57,  5,  6,  4, white); cfxp.drawEllipse(57,  4, 0, 0, white);
    cfxp.drawEllipse(57, 15,  6,  4, white); cfxp.drawEllipse(57, 14, 0, 1, white);
    cfxp.drawEllipse(57, 25,  6,  4, white); cfxp.drawEllipse(57, 24, 1, 0, white);
    cfxp.drawEllipse(71,  5,  6,  4, white); cfxp.drawEllipse(71,  4, 0, 0, white);
    cfxp.drawEllipse(71, 15,  6,  4, white); cfxp.drawEllipse(71, 14, 0, 2, white);
    cfxp.drawEllipse(71, 25,  6,  4, white); cfxp.drawEllipse(71, 24, 2, 0, white);
    dumpBufferRaw1Dot(cfxp);
    printf("\n");



    return 0;
}
