Skip to content

Creating the Screen class.

StackZ edited this page May 27, 2020 · 1 revision

How to create a properly working screen?

1.) Put the following things in the Makefile:

  • -std=gnu++17 inside the CXXFLAGS.
  • -D_GNU_SOURCE=1 inside the CFLAGS.

2.) Create a file called <ScreenName>.cpp and <ScreenName>.hpp. (<ScreenName> is the Name of your screen.)

3.) Put this inside the Header of <ScreenName>.hpp:

#include "screenCommon.hpp" // Or "common.hpp" in case you have screenCommon included there.

class <ScreenName> : public Screen {
public:
    void Draw(void) const override;
    void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
    <ScreenName>(); // Only needed if you need a constructor.
private:
   // All your private functions & variables for this class here. They get destroyed when it goes out of scope.
};

4.) Put this inside the <ScreenName>.cpp file:

#include "<ScreenName>.hpp"

<ScreenName>::<ScreenName>() {
    // Only needed if you need a constructor.
}

void <ScreenName>::Draw(void) const {
    // All your drawing stuff here.
}

void <ScreenName>::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
   // Your Logic stuff here.
}

5.) And that's all! For using the screens please look at the [gui.hpp] - screen functions page.

Information! The Constructor will ALWAYS be called when calling std::make_unique<ScreenName>().