|
一、打开touchgfx designer ,加上提示文本数字时钟显示文本和模拟显示界面,这里直接使用例子里面的界面导过来。
加上时钟的时分秒设置的加减键,时钟设置的开始键,OK键其实没什么用,这里页懒得删除了。如下图所示:
二、给每个按钮设置Interactions为按下后调用虚函数。每个虚函数名字不一样 如下。
三、打开代码MainView.hpp中加入虚函数和一些时钟变量和时钟设置标记如下:
四、MainView.cpp中加入虚函数和更新按键函数的具体实现如下:
#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();
virtual ~MainView() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void handleTickEvent();
virtual void bt1_function();
virtual void bt2_function();
virtual void bt3_function();
virtual void bt4_function();
virtual void bt5_function();
virtual void bt6_function();
virtual void toggle_function();
virtual void OK_function();
protected:
int tickCounter;
int analogHours;
int analogMinutes;
int analogSeconds;
int digitalHours;
int digitalMinutes;
int digitalSeconds;
bool setflag;
};
#endif // MAIN_VIEW_HPP
MainView.cpp:
#include <gui/main_screen/MainView.hpp>
MainView::MainView() :
tickCounter(0)
{
}
void MainView::setupScreen()
{
MainViewBase::setupScreen();
digitalHours = digitalClock.getCurrentHour();
digitalMinutes = digitalClock.getCurrentMinute();
digitalSeconds = digitalClock.getCurrentSecond();
analogHours = analogClock.getCurrentHour();
analogMinutes = analogClock.getCurrentMinute();
analogSeconds = analogClock.getCurrentSecond();
}
void MainView::tearDownScreen()
{
MainViewBase::tearDownScreen();
}
void MainView::handleTickEvent()
{
if(true != setflag )
{
tickCounter++;
if (tickCounter % 60 == 0)
{
if (++digitalSeconds >= 60)
{
digitalSeconds = 0;
if (++digitalMinutes >= 60)
{
digitalMinutes = 0;
if (++digitalHours >= 24)
{
digitalHours = 0;
}
}
}
if (++analogSeconds >= 60)
{
analogSeconds = 0;
if (++analogMinutes >= 60)
{
analogMinutes = 0;
if (++analogHours >= 24)
{
analogHours = 0;
}
}
}
// Update the clocks
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
}
}
void MainView::bt1_function()
{
if(digitalHours >=23)
digitalHours =0;
else
digitalHours++;
analogHours =digitalHours;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt2_function()
{
if(digitalHours ==0)
digitalHours =23;
else
digitalHours--;
analogHours =digitalHours;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt3_function()
{
if(digitalMinutes >=59)
digitalMinutes =0;
else
digitalMinutes++;
analogMinutes =digitalMinutes;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt4_function()
{
if(digitalMinutes == 0)
digitalMinutes=59;
else
digitalMinutes--;
analogMinutes =digitalMinutes;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt5_function()
{
if(digitalSeconds >=59)
digitalSeconds=0;
else
digitalSeconds++;
analogSeconds =digitalSeconds;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt6_function()
{
if(0 ==digitalSeconds)
digitalSeconds=59;
else
digitalSeconds--;
analogSeconds =digitalSeconds;
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::toggle_function()
{
// Override and implement this function in Main
//setflag
setflag =toggleButton1.getState();
}
void MainView::OK_function()
{
digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
toggleButton1.forceState(false);
digitalClock.invalidate();
toggleButton1.invalidate();
}