summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Systems/UI/UITextures/UIButton.h
blob: 8cf02ee3f1a5eb8af32680b10da3ec5adfd7c86e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef UIBUTTON_H
#define UIBUTTON_H
#include "Game/Systems/UI/ButtonAction/buttonaction.h"
#include "Game/Systems/UI/UITextures/uidisplay.h"
#include "Graphics/global.h"
#include <GLFW/glfw3.h>
#include <set>
#include "uitexture.h"

enum CornerPosition {
    TOPLEFT,
    TOPRIGHT,
    BOTTOMLEFT,
    BOTTOMRIGHT,
    NONE
};

class UIButton : public UITexture
{
public:
    UIButton(TextureData tex, glm::vec2 pos, glm::vec2 scale, std::set<std::string>& shownScreens,
             bool isCloseButton = false, CornerPosition corner = NONE, AspectRatio ratio = LAND_FIT);
    ~UIButton();
    void draw() override;
    GLuint getTexID() override;
    glm::vec2 getPos() override;
    glm::vec2 getScale() override;
    float getTextureRatio() override;
    AspectRatio getAspectRatio();



    void setWindowPos(int width, int height) override;
    glm::vec2 getWindowPos();

    int getHeight() override;
    int getWidth() override;
    Bounds2f getBounds() override;
    float getTextureScaleAspect() override;

    void addButtonAction(std::shared_ptr<ButtonAction> &action);
    bool onButtonPress();
    void setWindowToClose(std::string windowID);

    void setParentDisplay(std::string parent);
    std::string getParentDisplay();

    CornerPosition getCornerPos();
    bool hasCornerPos = false;
    void setToCorner(const CornerPosition corner, int width, int height);

    void setTransformationMat(glm::vec2 translation, glm::vec2 scale);
    glm::mat4 getTransformationMat();



private:
    glm::mat4 getScaleMatrix(glm::vec2 scale);
    int getScreenHeight();
    int getScreenWidth();
    void setTexID(GLuint &newTexID);


    TextureData m_tex;
    glm::vec2 m_pos;
    glm::vec2 m_scale;
    Bounds2f m_bounds;
    glm::vec2 m_windowPos; // width, height
    float m_windowHeight = 480.f;
    float m_windowWidth = 640.f;
    float m_toScreenScale = 1.f;

    int m_screenImageHeight;
    int m_screenImageWidth;
    float m_tex_aspectRatio = 1.f;
    bool m_isCloseButton = false;
    std::string m_attachedWindow;

    std::vector<std::shared_ptr<ButtonAction>> m_actions;
    std::set<std::string>& m_shownScreens;

    CornerPosition m_cornerPos;
    std::string m_parentDisplay;

    glm::mat4 m_transformationMat;
    float m_textureAspect = 1.f;

    AspectRatio m_aspectRatio;



};

#endif // UIButton_H