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.
ImageButton.h
Go to the documentation of this file.
1 #pragma once
2 
13 #include <SDL2/SDL.h>
14 #include <SDL2/SDL_image.h>
15 
16 #include "Application.h"
18 #include "IMGException.h"
19 #include "Rect.h"
20 #include "Color.h"
21 
26 {
27 public:
28  ImageButton();
29  ~ImageButton();
34  void setGeometry(Rect geom);
39  void setFillColor(Color color);
44  void setImageFile(const std::string &imgFile);
50  void setImageSize(int width, int height);
51  void draw(uint32_t time) override;
52  int getX() const override;
53  int getY() const override;
54  int getWidth() const override;
55  int getHeight() const override;
56 
57 private:
58  void build();
59  SDL_Renderer *renderer = nullptr;
60  Rect geometry = {0, 0, 0, 0}, imgPosition;
61  Color fillColor = {0, 0, 0, 0xFF};
62  SDL_Texture *imgTexture = nullptr;
63  std::string imageFile;
64  int imgW = -1, imgH = -1;
65 };
void setGeometry(Rect geom)
Set the button geometry (position and size)
Definition: ImageButton.cpp:13
The main application class header.
int getX() const override
Definition: ImageButton.cpp:46
ImageButton()
Definition: ImageButton.cpp:2
int getY() const override
Definition: ImageButton.cpp:51
void setImageFile(const std::string &imgFile)
Set the image file.
Definition: ImageButton.cpp:24
Definition: Color.h:16
void setImageSize(int width, int height)
Set the image size. The image is automatically centered.
Definition: ImageButton.cpp:30
A simple image button.
Definition: ImageButton.h:25
An abstract class implementing both the GraphicsObject and the TouchEnabledObject, which gives an interactive graphic object as result.
Definition: InteractiveGraphicsObject.h:20
~ImageButton()
Definition: ImageButton.cpp:7
int getHeight() const override
Definition: ImageButton.cpp:61
int getWidth() const override
Definition: ImageButton.cpp:56
A color wrapper.
void setFillColor(Color color)
Set the fill color.
Definition: ImageButton.cpp:19
void draw(uint32_t time) override
The draw method. It will be called once per frame for each object in a scene.
Definition: ImageButton.cpp:37
Definition: Rect.h:17