cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get the active screen from the model

JReed.1856
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief 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);   
    }
...

View solution in original post

3 REPLIES 3
Martin KJELDSEN
Chief 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.=)

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

/Martin