TouchCPLib  1.0.0
A touch-enabled GUI interface based on SDL and libTS. It provides a simple desktop-free UI for your embedded Raspberry projects.
Button.h
Go to the documentation of this file.
1 #pragma once
2 
12 #include <SDL2/SDL.h>
13 #include <SDL2/SDL_ttf.h>
14 
15 #include "Application.h"
16 #include "TTFFontException.h"
18 #include "Color.h"
19 #include "Font.h"
20 #include "Rect.h"
21 
26 {
27 public:
28  Button();
29  ~Button();
34  void setText(const std::string &text);
39  void setGeometry(Rect r);
44  void setFillColor(const Color fillColor);
49  void setTextColor(const Color textColor);
54  void setFontPath(const std::string &fontPath);
59  void setFontSize(int fontSize);
60  void draw(uint32_t time) override;
61  int getX() const override;
62  int getY() const override;
63  int getWidth() const override;
64  int getHeight() const override;
65 
66 private:
67  void build();
68  SDL_Renderer *renderer = nullptr;
69  std::string text;
70  Rect geometry = {0, 0, 0, 0};
71  SDL_Rect rectangle, textPosition;
72  Color fillColor = {0, 0, 0, 0xFF};
73  Color textColor = {0, 0, 0, 0xFF};
74  std::string fontPath;
75  int fontSize = 12;
76  SDL_Surface *textSurface = nullptr;
77  SDL_Texture *textTexture = nullptr;
78  std::unique_ptr<Font> font = nullptr;
79 };
void setFontSize(int fontSize)
Set the button font size.
Definition: Button.cpp:47
int getWidth() const override
Definition: Button.cpp:75
A font wrapper.
The main application class header.
A simple text button.
Definition: Button.h:25
void setFontPath(const std::string &fontPath)
Set the button text font.
Definition: Button.cpp:40
Definition: Color.h:16
void setTextColor(const Color textColor)
Sete the text color.
Definition: Button.cpp:34
int getY() const override
Definition: Button.cpp:70
An abstract class implementing both the GraphicsObject and the TouchEnabledObject, which gives an interactive graphic object as result.
Definition: InteractiveGraphicsObject.h:20
Button()
Definition: Button.cpp:3
int getHeight() const override
Definition: Button.cpp:80
void draw(uint32_t time) override
The draw method. It will be called once per frame for each object in a scene.
Definition: Button.cpp:54
~Button()
Definition: Button.cpp:8
A color wrapper.
void setText(const std::string &text)
Sets the button text.
Definition: Button.cpp:17
Definition: Rect.h:17
void setGeometry(Rect r)
Sets the button geometry (position and size)
Definition: Button.cpp:23
void setFillColor(const Color fillColor)
Set the fill color.
Definition: Button.cpp:29
int getX() const override
Definition: Button.cpp:65