touchgfx-多页面

注意基类不能在修改,否则下次design执行的时候手写的代码会被清空
所谓基类也就是Screen1ViewBase.hpp这样的文件
其实可以看到Screen1ViewBase.hpp他们的属性是只读的
我需要修改的是Screen1View.hpp这样的文件
你可以看到它是继承的class Screen1View : public Screen1ViewBase
这样基类的虚函数可以在子类里面完成

页面1:
#Screen1View.hpp

//他们在基类中是虚函数 在子类中也需要申明
	void buttonHourUpClicked();
	void buttonHourDownClicked();
	void buttonMinuteUpClicked();
	void buttonMinuteDownClicked();
	void buttonHourSaveClicked();
	void buttonMinSaveClicked();
protected:
	int16_t hour;
	int16_t minute;
	
#Screen1View.cpp

void Screen1View::buttonHourUpClicked()
{
	hour = (hour + 1) % 24; // Keep new value in range 0..23
	Unicode::snprintf(textAreaHourBuffer, TEXTAREAHOUR_SIZE, "%02d", hour);
	textAreaHour.invalidate();
}

void Screen1View::buttonHourDownClicked()
{
	hour = (hour + 24 - 1) % 24; // Keep new value in range 0..23
	Unicode::snprintf(textAreaHourBuffer, TEXTAREAHOUR_SIZE, "%02d", hour);
	textAreaHour.invalidate();
}

void Screen1View::buttonMinuteUpClicked()
{
	minute = (minute + 1) % 60; // Keep new value in range 0..59
	Unicode::snprintf(textAreaMinuteBuffer, TEXTAREAMINUTE_SIZE, "%02d", minute);
	textAreaMinute.invalidate();
}

void Screen1View::buttonMinuteDownClicked()
{
	minute = (minute + 60 - 1) % 60; // Keep new value in range 0..59
	Unicode::snprintf(textAreaMinuteBuffer, TEXTAREAMINUTE_SIZE, "%02d", minute);
	textAreaMinute.invalidate();
}


void Screen1View::buttonHourSaveClicked()
{

}
void Screen1View::buttonMinSaveClicked()
{

}





页面2:
#Screen2View.hpp
	virtual void handleTickEvent() ;
protected:
	int16_t hour;
	int16_t minute;
	int16_t tickCount;
	int16_t addStart;
	int16_t addEnd;
	
	
#Screen2View.cpp
void Screen2View::handleTickEvent()
{
	if (tickCount == 60)
	{
		minute++;
		hour = (hour + (minute / 60)) % 24;
		minute %= 60;

		Unicode::snprintf(textClockBuffer1, TEXTCLOCKBUFFER1_SIZE, "%02d", hour);
		Unicode::snprintf(textClockBuffer2, TEXTCLOCKBUFFER2_SIZE, "%02d", minute);

		textClock.invalidate();

		tickCount = 0;
	}

	if (!textClock.isMoveAnimationRunning())
	{
		tickCount++;
		if (circle.getArcStart() + 340 == circle.getArcEnd())
		{
			addStart = 2;
			addEnd = 1;
		}
		else if (circle.getArcStart() + 20 == circle.getArcEnd())
		{
			addStart = 1;
			addEnd = 2;
		}
		circle.invalidate();
		circle.setArc(circle.getArcStart() + addStart, circle.getArcEnd() + addEnd);
		circle.invalidate();
	}
}

页面联系:
#他们的调整是不需要手写代码的 也就是基类已经完成了 所以不需要考虑这个
#model.hpp
public:
    void saveHour(int16_t saveHour)
    {
        hour = saveHour;
    }

    void saveMinute(int16_t saveMinute)
    {
        minute = saveMinute;
    }

    int16_t getHour()
    {
        return hour;
    }

    int16_t getMinute()
    {
        return minute;
    }

protected:
    int16_t hour;
    int16_t minute;
	
#model.cpp	
	Model::Model() : modelListener(0), hour(0), minute(0)
{
}


#Screen1Presenter.hpp
#Screen2Presenter.hpp
public:
    void saveHour(int16_t hour)
    {
        model->saveHour(hour);
    }

    void saveMinute(int16_t minute)
    {
        model->saveMinute(minute);
    }

    int16_t getHour()
    {
        return model->getHour();
    }

    int16_t getMinute()
    {
        return model->getMinute();
    }
	
	
#Screen1View.cpp

void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();

    hour = presenter->getHour();
    minute = presenter->getMinute();

    Unicode::snprintf(textAreaHourBuffer, TEXTAREAHOUR_SIZE, "%02d", hour);
    Unicode::snprintf(textAreaMinuteBuffer, TEXTAREAMINUTE_SIZE, "%02d", minute);
}	


#Screen1View.cpp

void Screen1View::buttonHourSaveClicked()
{
	presenter->saveHour(hour);
}
void Screen1View::buttonMinSaveClicked()
{
	presenter->saveMinute(minute);
}
	
	
	
	
#Screen2View.cpp

void Screen2View::setupScreen()
{
    Screen2ViewBase::setupScreen();

    hour = presenter->getHour();
    minute = presenter->getMinute();

    Unicode::snprintf(textClockBuffer1, TEXTCLOCKBUFFER1_SIZE, "%02d", hour);
    Unicode::snprintf(textClockBuffer2, TEXTCLOCKBUFFER2_SIZE, "%02d", minute);
}


void Screen2View::tearDownScreen()
{
    presenter->saveHour(hour);
    presenter->saveMinute(minute);

    Screen2ViewBase::tearDownScreen();
}

 

你可能感兴趣的:(touchgfx-多页面)