tcMenu
TcDrawableButton.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
12 #ifndef TCMENU_TCDRAWABLEBUTTON_H
13 #define TCMENU_TCDRAWABLEBUTTON_H
14 
15 #include <PlatformDetermination.h>
16 #include "DrawingPrimitives.h"
17 #include "GraphicsDeviceRenderer.h"
18 #include "DeviceDrawableHelper.h"
19 
20 #define DRAW_BUTTON_FLAG_ICON_BOOL 0
21 #define DRAW_BUTTON_FLAG_IS_DIRTY 1
22 #define DRAW_BUTTON_MONO 2
23 
24 namespace tcgfx {
25 
32  public:
33  enum ButtonDrawingMode {
34  NORMAL, SELECTED, PRESSED, NOT_SELECTABLE
35  };
36  private:
37  Coord where;
38  Coord size;
39  color_t bgColor;
40  color_t fgColor;
41  color_t selectedColor;
42  union {
43  const char *text;
44  const tcgfx::DrawableIcon *icon;
45  };
46  DeviceFontDrawingMode fontMode;
47  ButtonDrawingMode drawingMode = NORMAL;
48  uint8_t flags;
49  public:
58  TcDrawableButton(const Coord &where, const Coord &size, color_t bgCol, color_t fgCol, color_t selCol,
59  const char *text, const DeviceFontDrawingMode& font);
60 
69  TcDrawableButton(const Coord &where, const Coord &size, color_t bgCol, color_t fgCol, color_t selCol,
70  const tcgfx::DrawableIcon *icon);
71 
76  explicit TcDrawableButton(const tcgfx::DrawableIcon *icon);
77 
83  TcDrawableButton(const char *text, const DeviceFontDrawingMode& font);
84 
90  bool touchInBounds(const Coord &location) const;
91 
97  void setButtonOnMonoDisplay(bool mono) { bitWrite(flags, DRAW_BUTTON_MONO, mono); }
98 
102  bool isButtonOnMonoDisplay() { return bitRead(flags, DRAW_BUTTON_MONO); }
103 
108  void setButtonDrawingMode(ButtonDrawingMode mode) {
109  if(drawingMode != mode) setDirty(true);
110  drawingMode = mode;
111  }
112 
117  void setDirty(bool d) {
118  bitWrite(flags, DRAW_BUTTON_FLAG_IS_DIRTY, d);
119  }
120 
125  bool isDirty() const { return bitRead(flags, DRAW_BUTTON_FLAG_IS_DIRTY); }
126 
131  bool isIconDrawn() const { return bitRead(flags, DRAW_BUTTON_FLAG_ICON_BOOL); }
132 
136  ButtonDrawingMode getButtonDrawingMode() { return drawingMode; }
137 
142  void paintButton(DeviceDrawable *drawable);
143 
148  void setPosition(const Coord& position);
149 
155  void setPositionAndSize(const Coord& position, const Coord& newSize);
156 
163  void setColors(color_t bgCol, color_t fgCol, color_t selCol);
164 
165  void setText(const char* newText);
166  };
167 
168 }
169 
170 #endif //TCMENU_TCDRAWABLEBUTTON_H
A few helper classes that provides useful functions on top of a tcMenu device drawable.
contains a series of core components needed by all graphical renderers
uint32_t color_t
Definition: DrawingPrimitives.h:29
the interface that all graphics devices should implement to do the actual graphics rendering.
Definition: DeviceDrawable.h:34
Definition: DeviceDrawableHelper.h:48
Definition: DrawingPrimitives.h:152
Definition: TcDrawableButton.h:31
TcDrawableButton(const Coord &where, const Coord &size, color_t bgCol, color_t fgCol, color_t selCol, const char *text, const DeviceFontDrawingMode &font)
Definition: TcDrawableButton.cpp:12
bool isButtonOnMonoDisplay()
Definition: TcDrawableButton.h:102
void setDirty(bool d)
Definition: TcDrawableButton.h:117
void setButtonOnMonoDisplay(bool mono)
Definition: TcDrawableButton.h:97
void paintButton(DeviceDrawable *drawable)
Definition: TcDrawableButton.cpp:51
void setButtonDrawingMode(ButtonDrawingMode mode)
Definition: TcDrawableButton.h:108
void setPosition(const Coord &position)
Definition: TcDrawableButton.cpp:119
bool isIconDrawn() const
Definition: TcDrawableButton.h:131
void setColors(color_t bgCol, color_t fgCol, color_t selCol)
Definition: TcDrawableButton.cpp:106
bool isDirty() const
Definition: TcDrawableButton.h:125
void setPositionAndSize(const Coord &position, const Coord &newSize)
Definition: TcDrawableButton.cpp:113
ButtonDrawingMode getButtonDrawingMode()
Definition: TcDrawableButton.h:136
bool touchInBounds(const Coord &location) const
Definition: TcDrawableButton.cpp:44
Definition: DrawingPrimitives.h:123