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.
Text.h
Go to the documentation of this file.
1 #pragma once
2 
13 #include <SDL2/SDL.h>
14 #include <SDL2/SDL_ttf.h>
15 
16 #include "Application.h"
18 #include "Rect.h"
19 #include "Color.h"
20 #include "Font.h"
21 
26 {
27 public:
28  Text();
29  ~Text();
34  void setText(const char *text);
39  void setGeometry(Rect geom);
44  void setColor(Color c);
49  void setFontPath(const std::string &fontPath);
54  void setFontSize(int fontSize);
55  void draw(uint32_t time) override;
56  int getX() const override;
57  int getY() const override;
58  int getWidth() const override;
59  int getHeight() const override;
60 
61 private:
62  void build();
63  std::string text;
64  SDL_Renderer *renderer;
65  Rect geometry;
66  Color textColor;
67  std::unique_ptr<Font> font;
68  Rect textPosition;
69  SDL_Surface *textSurface = nullptr;
70  SDL_Texture *textTexture = nullptr;
71  std::string fontPath;
72  int fontSize = 12;
73 };
A font wrapper.
int getWidth() const override
Definition: Text.cpp:69
The main application class header.
void setFontSize(int fontSize)
Set the font size.
Definition: Text.cpp:42
void setColor(Color c)
Set the text color.
Definition: Text.cpp:29
Definition: Color.h:16
int getY() const override
Definition: Text.cpp:64
void draw(uint32_t time) override
The draw method. It will be called once per frame for each object in a scene.
Definition: Text.cpp:49
Text()
Definition: Text.cpp:3
An abstract class implementing both the GraphicsObject and the TouchEnabledObject, which gives an interactive graphic object as result.
Definition: InteractiveGraphicsObject.h:20
void setText(const char *text)
Set the text message.
Definition: Text.cpp:17
void setGeometry(Rect geom)
Set the text geometry (position and size). If width and height are set to -1 the text natural size wi...
Definition: Text.cpp:23
A color wrapper.
void setFontPath(const std::string &fontPath)
Set the text font.
Definition: Text.cpp:35
~Text()
Definition: Text.cpp:8
int getX() const override
Definition: Text.cpp:59
Definition: Rect.h:17
int getHeight() const override
Definition: Text.cpp:74
A simple text object.
Definition: Text.h:25