Content

1. Examples

1.1 Example 1

#include "inc/Stk.h"

class App: public Stk::Window
{
private:

public:
    App()
    {
        init("Example",Stk::CENTERED,Stk::CENTERED,500,500);

        addScreen(new Stk::Screen());
        getScreen(0)->add(new Stk::Button("Test",40,40,240,40,Stk::FONT_MEDIUM));
        getScreen(0)->add(new Stk::CheckButton("Test2",40,100,240,40,Stk::FONT_MEDIUM));
        getScreen(0)->add(new Stk::Button3D("Test3",40,160,240,40,Stk::FONT_MEDIUM));
        getScreen(0)->add(new Stk::CheckButton3D("Test4",40,220,240,40,Stk::FONT_MEDIUM));

        joinLoop();
    }

    void action()
    {

    }

    bool end()
    {
        return getScreen(0)->get(0)->getEvent()==Stk::EVENT_CLICK;
    }
};

int main(int argc,char* argv[])
{
    App app;
    return 0;
}

2. API

2.1 Stk

How to include:

#include "inc/Stk.h" //Includes all neccessary files!

Variables and Constants(namespace Stk):

  • window: SDL_Window*

  • render: SDL_Renderer*

  • event: SDL_Event

  • mouse_x: int

  • mouse_y: int

  • mouse_timer: Uint32

  • OS_SEPERATOR: std::string

  • CENTERED: int

  • EVENT_HOVER: int

  • EVENT_CLICK: int

  • FONT_BIG: int

  • FONT_MEDIUM: int

  • FONT_SMALL: int

2.2 Window

How to apply:

The Stk::Window class is a abstract class to apply it on your class simply extend it like this:

#include "inc/Stk.h"

/*
    This is the basic structure of each Stk-based App!
*/

class App: public Stk::Window
{
public:
    App()
    {
        init("Example",Stk::CENTERED,Stk::CENTERED,500,500);
        addScreen(new Stk::Screen());
        joinLoop();
    }

    void action()
    {

    }

    bool end()
    {
        return false;
    }
}

Constructors and Methods:

  • Window(): basic constructor

  • void init(std::string title,int x_pos,int y_pos,int width,int height): inits the window

  • ~Window(): basic deconstructor

  • virtual void action(): called in each tick

  • virtual bool end(): if returns true than the app closes

  • void joinLoop(): joins main loop

  • void addScreen(Screen* s): See Screen

  • Screen* getScreen(int index): See Screen

  • int getScreenID(): Active screenID

  • void setScreenID(int id): See above.

  • int getX()

  • int getY()

  • int getWidth()

  • int getHeight()

  • std::string getTitle()

Important:

The void action() and the bool end() methode a pure virtual so YOU HAVE TO ADD THEM IN YOUR CLASS!

Even you have only one Screen, you have to ADD one with the addScreen(*)-Methode from above!

Stk allows only ONE window per APP!

2.2.1 Screen

What is the Screen-class?

Basically the Screen-class contains a container of unlimited Widget* objects and is a member of the Stk::Window-class.

Constructors and Methods:

  • Screen(): constructor

  • ~Screen(): deconstructor

  • void add(Widget* w): add a Widget* to the vector

  • void remove(int index): remove a Widget* at the index of the vector

  • std::vector<Widget*> getAll(): get the complete Widget* vector

  • Widget* get(int index): get the Widget* element at index from the vector

2.2.2 EventLoop

What does it?

The EventLoop-class handles SDLEvents and is a member of the Stk::Window-class.

Constructors and Methods:

  • EventLoop(): constructor(empty)

  • bool loop(): handles the events

Important:

Please avoid using any method of this class! For internal use only!

2.3 Style

Styles:

namespace Style
{
    /* Font styles */
    std::array<TTF_Font*,3> font;
    int big_size;
    int medium_size;
    int small_size;

    /* Colors */
    SDL_Color text_color;
    SDL_Color normal_color;
    SDL_Color hover_color;
    SDL_Color active_color;
    SDL_Color border_color;
    SDL_Color disabled_color;
    SDL_Color background_color;

    SDL_Color normal3d_color1;
    SDL_Color normal3d_color2;
    SDL_Color hover3d_color1;
    SDL_Color hover3d_color2;
    SDL_Color active3d_color1;
    SDL_Color active3d_color2;
    SDL_Color disabled3d_color1;
    SDL_Color disabled3d_color2;
}

Notice:

All of these styles can be manipulated after the call of the Stk::Window::init(*) method!

To manipulate SDL_Colors just use {r,g,b,a} as the syntax, e.g:

Stk::Style::text_color={34,34,34,255};

To manipulate the fonts use this syntax, e.g:

Stk::Style::font[Stk::FONT_SMALL]=TTF_OpenFont("file",Stk::Style::small_size);

2.4 Widgets

Constructors and Methods: