|
/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#ifndef MAINVIEWBASE_HPP
#define MAINVIEWBASE_HPP
#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/main_screen/MainPresenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/Image.hpp>
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
#include <touchgfx/widgets/Button.hpp>
class MainViewBase : public touchgfx::View<MainPresenter>
{
public:
MainViewBase();
virtual ~MainViewBase();
virtual void setupScreen();
/*
* Virtual Action Handlers
*/
virtual void increaseValue()
{
// Override and implement this function in Main
}
virtual void decreaseValue()
{
// Override and implement this function in Main
}
protected:
FrontendApplication& application() {
return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
}
/*
* Member Declarations
*/
touchgfx::Box __background;
touchgfx::Image backgroundImage;
touchgfx::Image counterBackgroundImage;
touchgfx::TextAreaWithOneWildcard countTxt;
touchgfx::Button buttonUp;
touchgfx::Button buttonDown;
/*
* Wildcard Buffers
*/
static const uint16_t COUNTTXT_SIZE = 5;
touchgfx::Unicode::UnicodeChar countTxtBuffer[COUNTTXT_SIZE];
private:
/*
* Callback Declarations
*/
touchgfx::Callback<MainViewBase, const touchgfx::AbstractButton&> buttonCallback;
/*
* Callback Handler Declarations
*/
void buttonCallbackHandler(const touchgfx::AbstractButton& src);
};
#endif // MAINVIEWBASE_HPP
MainViewBase.cpp
/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#include <gui_generated/main_screen/MainViewBase.hpp>
#include <touchgfx/Color.hpp>
#include <images/BitmapDatabase.hpp>
#include <texts/TextKeysAndLanguages.hpp>
MainViewBase::MainViewBase() :
buttonCallback(this, &MainViewBase::buttonCallbackHandler)
{
__background.setPosition(0, 0, 800, 480);
__background.setColor(touchgfx::Color::getColorFromRGB(0, 0, 0));
add(__background);
backgroundImage.setXY(150, 120);
backgroundImage.setBitmap(touchgfx::Bitmap(BITMAP_BG_ID));
add(backgroundImage);
counterBackgroundImage.setXY(400, 152);
counterBackgroundImage.setBitmap(touchgfx::Bitmap(BITMAP_COUNTER_BOX_ID));
add(counterBackgroundImage);
countTxt.setPosition(316, 189, 302, 104);
countTxt.setColor(touchgfx::Color::getColorFromRGB(255, 255, 255));
countTxt.setLinespacing(4);
Unicode::snprintf(countTxtBuffer, COUNTTXT_SIZE, "%s", touchgfx::TypedText(T___SINGLEUSE_XERM).getText());
countTxt.setWildcard(countTxtBuffer);
countTxt.setTypedText(touchgfx::TypedText(T_TEXTID1));
add(countTxt);
buttonUp.setXY(169, 173);
buttonUp.setBitmaps(touchgfx::Bitmap(BITMAP_UP_BTN_ID), touchgfx::Bitmap(BITMAP_UP_BTN_PRESSED_ID));
buttonUp.setAction(buttonCallback);
add(buttonUp);
buttonDown.setXY(169, 265);
buttonDown.setBitmaps(touchgfx::Bitmap(BITMAP_DOWN_BTN_ID), touchgfx::Bitmap(BITMAP_DOWN_BTN_PRESSED_ID));
buttonDown.setAction(buttonCallback);
add(buttonDown);
}
MainViewBase::~MainViewBase()
{
}
void MainViewBase::setupScreen()
{
}
void MainViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
if (&src == &buttonUp)
{
//IncreaseValue
//When buttonUp clicked call virtual function
//Call increaseValue
increaseValue();
}
if (&src == &buttonDown)
{
//DecreaseValue
//When buttonDown clicked call virtual function
//Call decreaseValue
decreaseValue();
}
}
#ifndef MAIN_VIEW_HPP
#define MAIN_VIEW_HPP
#include <gui_generated/main_screen/MainViewBase.hpp>
#include <gui/main_screen/MainPresenter.hpp>
class MainView : public MainViewBase
{
public:
MainView();
~MainView() {};
virtual void setupScreen();
virtual void increaseValue();
virtual void decreaseValue();
void updateGFXElements();
protected:
private:
uint32_t count;
};
#endif // MAIN_VIEW_HPP
MainView.cpp:
#include <gui/main_screen/MainView.hpp>
#include "BitmapDatabase.hpp"
const uint32_t UPPER_LIMIT = 9999;
const uint32_t LOWER_LIMIT = 0;
MainView::MainView() : count(0) {}
void MainView::setupScreen()
{
updateGFXElements();
}
void MainView::increaseValue()
{
count = (count++ > UPPER_LIMIT) ? UPPER_LIMIT : count;
updateGFXElements();
}
void MainView::decreaseValue()
{
count = (count-- <= LOWER_LIMIT) ? LOWER_LIMIT : count;
updateGFXElements();
}
void MainView::updateGFXElements()
{
//Counter text area GFX uptade.
Unicode::snprintf(countTxtBuffer, 5, "%d", count);
//Button GFX update and touchable.
if (count < UPPER_LIMIT)
{
buttonUp.setBitmaps(Bitmap(BITMAP_UP_BTN_ID), Bitmap(BITMAP_UP_BTN_PRESSED_ID));
buttonUp.setTouchable(true);
}
else
{
buttonUp.setBitmaps(Bitmap(BITMAP_UP_BTN_DISABLED_ID), Bitmap(BITMAP_UP_BTN_DISABLED_ID));
buttonUp.setTouchable(false);
}
if (count > LOWER_LIMIT)
{
buttonDown.setBitmaps(Bitmap(BITMAP_DOWN_BTN_ID), Bitmap(BITMAP_DOWN_BTN_PRESSED_ID));
buttonDown.setTouchable(true);
}
else
{
buttonDown.setBitmaps(Bitmap(BITMAP_DOWN_BTN_DISABLED_ID), Bitmap(BITMAP_DOWN_BTN_DISABLED_ID));
buttonDown.setTouchable(false);
}
// Invalidate all GFX area, which will result in it being redrawn in next tick.
countTxt.invalidate();
buttonUp.invalidate();
buttonDown.invalidate();
}