/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include <gui_generated/driverview_screen/DriverViewViewBase.hpp>
#include <touchgfx/canvas_widget_renderer/CanvasWidgetRenderer.hpp>
#include <touchgfx/Color.hpp>
#include <texts/TextKeysAndLanguages.hpp>
#include <images/BitmapDatabase.hpp>

DriverViewViewBase::DriverViewViewBase() :
    updateItemCallback(this, &DriverViewViewBase::updateItemCallbackHandler)
{
    touchgfx::CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);
    
    __background.setPosition(0, 0, 480, 320);
    __background.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
    add(__background);

    motorTempLabel.setPosition(315, 187, 150, 25);
    motorTempLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    motorTempLabel.setLinespacing(0);
    motorTempLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_JN2J));
    add(motorTempLabel);

    motorTempL.setXY(329, 212);
    add(motorTempL);

    motorTempR.setXY(392, 212);
    add(motorTempR);

    motorTempDiv.setPosition(389, 212, 3, 60);
    motorTempDivPainter.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    motorTempDiv.setPainter(motorTempDivPainter);
    motorTempDiv.setStart(0, 0);
    motorTempDiv.setEnd(0, 320);
    motorTempDiv.setLineWidth(10);
    motorTempDiv.setLineEndingStyle(touchgfx::Line::ROUND_CAP_ENDING);
    add(motorTempDiv);

    invTempDiv.setPosition(389, 122, 3, 60);
    invTempDivPainter.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    invTempDiv.setPainter(invTempDivPainter);
    invTempDiv.setStart(0, 0);
    invTempDiv.setEnd(0, 320);
    invTempDiv.setLineWidth(10);
    invTempDiv.setLineEndingStyle(touchgfx::Line::ROUND_CAP_ENDING);
    add(invTempDiv);

    invTempR.setXY(392, 122);
    add(invTempR);

    invTempL.setXY(329, 122);
    add(invTempL);

    invTempLabel.setPosition(315, 97, 150, 25);
    invTempLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    invTempLabel.setLinespacing(0);
    invTempLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_ZP7N));
    add(invTempLabel);

    ttDivVert.setPosition(239, 122, 3, 123);
    ttDivVertPainter.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    ttDivVert.setPainter(ttDivVertPainter);
    ttDivVert.setStart(0, 0);
    ttDivVert.setEnd(0, 320);
    ttDivVert.setLineWidth(10);
    ttDivVert.setLineEndingStyle(touchgfx::Line::ROUND_CAP_ENDING);
    add(ttDivVert);

    ttDivHoriz.setPosition(179, 182, 123, 3);
    ttDivHorizPainter.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    ttDivHoriz.setPainter(ttDivHorizPainter);
    ttDivHoriz.setStart(0, 0);
    ttDivHoriz.setEnd(480, 0);
    ttDivHoriz.setLineWidth(10);
    ttDivHoriz.setLineEndingStyle(touchgfx::Line::ROUND_CAP_ENDING);
    add(ttDivHoriz);

    tireTempRR.setXY(242, 185);
    add(tireTempRR);

    tireTempFR.setXY(242, 122);
    add(tireTempFR);

    tireTempRL.setXY(179, 185);
    add(tireTempRL);

    tireTempFL.setXY(179, 122);
    add(tireTempFL);

    tsSoC.setXY(15, 122);
    tsSoC.setProgressIndicatorPosition(0, 0, 40, 150);
    tsSoC.setRange(0, 100);
    tsSoC.setBackground(touchgfx::Bitmap(BITMAP_BAT_BAR_BG_ID));
    tsSoCPainter.setColor(touchgfx::Color::getColorFromRGB(136, 255, 0));
    tsSoC.setPainter(tsSoCPainter);
    tsSoC.setStart(9, 150);
    tsSoC.setEnd(9, 0);
    tsSoC.setLineWidth(100);
    tsSoC.setLineEndingStyle(touchgfx::Line::BUTT_CAP_ENDING);
    tsSoC.setValue(60);
    add(tsSoC);

    lvSoC.setXY(110, 122);
    lvSoC.setProgressIndicatorPosition(0, 0, 40, 150);
    lvSoC.setRange(0, 100);
    lvSoC.setBackground(touchgfx::Bitmap(BITMAP_BAT_BAR_BG_ID));
    lvSoCPainter.setColor(touchgfx::Color::getColorFromRGB(136, 255, 0));
    lvSoC.setPainter(lvSoCPainter);
    lvSoC.setStart(9, 150);
    lvSoC.setEnd(9, 0);
    lvSoC.setLineWidth(100);
    lvSoC.setLineEndingStyle(touchgfx::Line::BUTT_CAP_ENDING);
    lvSoC.setValue(80);
    add(lvSoC);

    tireLabel.setPosition(165, 97, 150, 25);
    tireLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    tireLabel.setLinespacing(0);
    tireLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_H6UX));
    add(tireLabel);

    tsSoCLabel.setPosition(15, 97, 40, 25);
    tsSoCLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    tsSoCLabel.setLinespacing(0);
    tsSoCLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_PHFD));
    add(tsSoCLabel);

    lvSoCLabel.setPosition(110, 97, 40, 25);
    lvSoCLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    lvSoCLabel.setLinespacing(0);
    lvSoCLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_4OBM));
    add(lvSoCLabel);

    field1.setXY(15, 15);
    add(field1);

    field2.setXY(165, 15);
    add(field2);

    field3.setXY(315, 15);
    add(field3);

    fieldTypeSelection.setPosition(15, 95, 150, 225);
    fieldTypeSelection.setHorizontal(false);
    fieldTypeSelection.setCircular(true);
    fieldTypeSelection.setEasingEquation(touchgfx::EasingEquations::linearEaseOut);
    fieldTypeSelection.setSwipeAcceleration(10);
    fieldTypeSelection.setDragAcceleration(10);
    fieldTypeSelection.setNumberOfItems(1);
    fieldTypeSelection.setSelectedItemOffset(94);
    fieldTypeSelection.setDrawableSize(26, 0);
    fieldTypeSelection.setDrawables(fieldTypeSelectionListItems, updateItemCallback);
    fieldTypeSelection.animateToItem(0, 0);
    fieldTypeSelection.setVisible(false);
    add(fieldTypeSelection);

    progressBar.setXY(15, 280);
    progressBar.setProgressIndicatorPosition(0, 0, 480, 55);
    progressBar.setRange(0, 100);
    progressBar.setDirection(touchgfx::AbstractDirectionProgress::RIGHT);
    progressBar.setBackground(touchgfx::Bitmap(BITMAP_PRECHARGE_BG_ID));
    progressBar.setColor(touchgfx::Color::getColorFromRGB(99, 186, 0));
    progressBar.setValue(0);
    progressBar.setVisible(false);
    add(progressBar);

    prechargeLabel.setXY(105, 275);
    prechargeLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    prechargeLabel.setLinespacing(0);
    prechargeLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_HMH2));
    prechargeLabel.setVisible(false);
    add(prechargeLabel);

    r2dLabel.setPosition(82, 275, 317, 37);
    r2dLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    r2dLabel.setLinespacing(0);
    r2dLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_NGUK));
    r2dLabel.setVisible(false);
    add(r2dLabel);

    r2dProgressLabel.setPosition(180, 275, 219, 37);
    r2dProgressLabel.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
    r2dProgressLabel.setLinespacing(0);
    r2dProgressLabel.setTypedText(touchgfx::TypedText(T___SINGLEUSE_J5UH));
    r2dProgressLabel.setVisible(false);
    add(r2dProgressLabel);

    errorPopup.setXY(15, 122);
    errorPopup.setVisible(false);
    add(errorPopup);
}

DriverViewViewBase::~DriverViewViewBase()
{
    touchgfx::CanvasWidgetRenderer::resetBuffer();
}

void DriverViewViewBase::setupScreen()
{
    motorTempL.initialize();
    motorTempR.initialize();
    invTempR.initialize();
    invTempL.initialize();
    tireTempRR.initialize();
    tireTempFR.initialize();
    tireTempRL.initialize();
    tireTempFL.initialize();
    field1.initialize();
    field2.initialize();
    field3.initialize();
    fieldTypeSelection.initialize();
    for (int i = 0; i < fieldTypeSelectionListItems.getNumberOfDrawables(); i++)
    {
        fieldTypeSelectionListItems[i].initialize();
    }
    errorPopup.initialize();
}

void DriverViewViewBase::handleKeyEvent(uint8_t key)
{
    if(22 == key)
    {
        //SelectPreviousField
        //When hardware button 22 clicked call virtual function
        //Call selectPrevField
        selectPrevField();
    
    }

    if(21 == key)
    {
        //SelectNextField
        //When hardware button 21 clicked call virtual function
        //Call selectNextField
        selectNextField();
    
    }

    if(24 == key)
    {
        //SelectPreviousFieldType
        //When hardware button 24 clicked call virtual function
        //Call selectPrevFieldType
        selectPrevFieldType();
    
    }

    if(23 == key)
    {
        //SelectNextFieldType
        //When hardware button 23 clicked call virtual function
        //Call selectNextFieldType
        selectNextFieldType();
    
    }

    if(6 == key)
    {
        //ConfirmFieldType
        //When hardware button 6 clicked call virtual function
        //Call confirmFieldType
        confirmFieldType();
    
    }
}

void DriverViewViewBase::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex)
{
    if (items == &fieldTypeSelectionListItems)
    {
        touchgfx::Drawable* d = items->getDrawable(containerIndex);
        DriverViewFieldSelection* cc = (DriverViewFieldSelection*)d;
        fieldTypeSelectionUpdateItem(*cc, itemIndex);
    }
}