Skip to main content
JReed.1856
Associate II
Solved

How do I get the active screen from the model

I'd like to only update variables, which are shown on the current screen. How do I get the current screen in a switch case structure, in the model::tick() function. I tried to alter the tick function to get the currentScreen parameter from the FrontendApplication.hpp as a variable, but this did not work

This topic has been closed for replies.
Martin KJELDSEN
Martin KJELDSENBest answer
Principal III

I'd simply store the active screen in the model when you activate a screens presenter.

class MyView;
 
class MyPresenter : public Presenter, public ModelListener
{
public:
 MyPresenter(MyView& v);
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate()
 {
 model->setActiveScreen(MYSCREEN); 
 }
...

3 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III

I'd simply store the active screen in the model when you activate a screens presenter.

class MyView;
 
class MyPresenter : public Presenter, public ModelListener
{
public:
 MyPresenter(MyView& v);
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate()
 {
 model->setActiveScreen(MYSCREEN); 
 }
...

JReed.1856
Associate II

Ah thank you, that is actually an easy still elegant solution.=)

Martin KJELDSEN
Principal III

I think so too. You could do some type-checking magic, but this is a lot simpler and more readable.

/Martin