LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
display_base.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018-2020, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
28 #ifndef _DISPLAY_BASE_H_
29 #define _DISPLAY_BASE_H_
30 
31 #include "lcd_hal/io.h"
32 #include "nano_gfx_types.h"
33 #include "canvas/point.h"
34 #include "canvas/rect.h"
35 #include "canvas/font.h"
36 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46  extern uint8_t s_ssd1306_invertByte;
47 #ifdef __cplusplus
48 }
49 #endif
50 
55 template <class I> class NanoDisplayBase
56 {
57 public:
63  explicit NanoDisplayBase(I &intf)
64  : m_intf(intf)
65  {
66  }
67 
68 #ifndef DOXYGEN_SHOULD_SKIP_THIS
69 
74  void setOffset(lcdint_t ox, lcdint_t oy){};
75 #endif
76 
81  const NanoPoint offsetEnd() const
82  {
83  return (NanoPoint){(lcdint_t)(m_w - 1), (lcdint_t)(m_h - 1)};
84  }
85 
90  const NanoRect rect() const
91  {
92  return {(NanoPoint){0, 0}, offsetEnd()};
93  }
94 
99  {
100  return m_w;
101  }
102 
107  {
108  return m_h;
109  }
110 
115  {
116  lcduint_t t = m_w;
117  m_w = m_h;
118  m_h = t;
119  }
120 
125  void setColor(uint16_t color)
126  {
127  m_color = color;
128  };
129 
133  uint16_t getColor()
134  {
135  return m_color;
136  };
137 
142  void setBackground(uint16_t color)
143  {
144  m_bgColor = color;
145  }
146 
151  {
152  uint16_t color = m_color;
153  m_color = m_bgColor;
154  m_bgColor = color;
155  }
156 
163  {
164  return m_intf;
165  }
166 
175  void setFont(NanoFont &font)
176  {
177  m_font = &font;
178  }
179 
186  void setFontSpacing(uint8_t spacing)
187  {
188  if ( m_font )
189  m_font->setSpacing(spacing);
190  }
191 
196  {
197  return *m_font;
198  }
199 
209  void setFixedFont(const uint8_t *progmemFont)
210  {
211  g_canvas_font.loadFixedFont(progmemFont);
212  setFont(g_canvas_font);
213  }
214 
215 #ifndef DOXYGEN_SHOULD_SKIP_THIS
216  void setFixedFont_oldStyle(const uint8_t *progmemFont)
217  {
218  g_canvas_font.loadFixedFont_oldStyle(progmemFont);
219  setFont(g_canvas_font);
220  }
221 #endif
222 
233  void setFixedFont(const uint8_t *progmemFont, const uint8_t *secondaryFont)
234  {
235  g_canvas_font.loadFixedFont(progmemFont);
236  if ( secondaryFont )
237  {
238  g_canvas_font.loadSecondaryFont(secondaryFont);
239  }
240  setFont(g_canvas_font);
241  }
242 
253  void setFreeFont(const uint8_t *progmemFont, const uint8_t *secondaryFont = nullptr)
254  {
255  g_canvas_font.loadFreeFont(progmemFont);
256  if ( secondaryFont )
257  {
258  g_canvas_font.loadSecondaryFont(secondaryFont);
259  }
260  setFont(g_canvas_font);
261  }
262 
270  {
271  m_cursorX = x;
272  m_cursorY = y;
273  }
274 
275 protected:
281  uint8_t m_textMode = 0;
282  EFontStyle m_fontStyle = STYLE_NORMAL;
283  uint16_t m_color = 0xFFFF;
284  uint16_t m_bgColor = 0x0000;
285  NanoFont *m_font = nullptr;
286 
287  I &m_intf;
288 };
289 
294 #endif
EFontStyle m_fontStyle
currently active font style
Definition: display_base.h:282
void invertColors()
Changes foreground and background colors.
Definition: display_base.h:150
lcdint_t m_cursorY
current Y cursor position for text output
Definition: display_base.h:280
uint8_t lcduint_t
internal int type, used by the library.
Definition: canvas_types.h:79
struct _NanoPoint NanoPoint
Describes point.
Describes point.
Definition: point.h:39
NanoRect structure describes rectangle area.
Definition: rect.h:42
const NanoPoint offsetEnd() const
Returns right-bottom point of the canvas in offset terms.
Definition: display_base.h:81
void swapDimensions()
Swaps width and height dimensions.
Definition: display_base.h:114
NanoFont * m_font
currently set font
Definition: display_base.h:285
lcduint_t m_w
width of NanoCanvas area in pixels
Definition: display_base.h:276
Point class.
lcduint_t width()
Returns width of the display in pixels.
Definition: display_base.h:98
int8_t lcdint_t
internal int type, used by the library.
Definition: canvas_types.h:77
I & getInterface()
Returns reference to interface communicator.
Definition: display_base.h:162
lcduint_t height()
Returns height of the display in pixels.
Definition: display_base.h:106
uint16_t getColor()
Returns currently set color.
Definition: display_base.h:133
SSD1306 HAL IO communication functions.
void setFixedFont(const uint8_t *progmemFont, const uint8_t *secondaryFont)
Sets new font to use with print functions.
Definition: display_base.h:233
void setFont(NanoFont &font)
Sets new font to use with print functions.
Definition: display_base.h:175
void setColor(uint16_t color)
Sets color.
Definition: display_base.h:125
Rectangle class.
uint16_t m_color
current foreground color
Definition: display_base.h:283
NanoFont class implements work with fonts provided by the library: loading fonts, providing their par...
Definition: font.h:45
void setFixedFont(const uint8_t *progmemFont)
Sets new font to use with print functions.
Definition: display_base.h:209
void setSpacing(uint8_t spacing)
Sets spacing in pixels between 2 nearest characters.
Definition: font.h:152
uint16_t m_bgColor
current background color
Definition: display_base.h:284
NanoDisplayBase(I &intf)
Creates new empty base display object.
Definition: display_base.h:63
const NanoRect rect() const
Returns rectangle area, covered by canvas in offset terms.
Definition: display_base.h:90
lcduint_t m_h
height of NanoCanvas area in pixels
Definition: display_base.h:277
Basic structures of nano gfx library.
void setFontSpacing(uint8_t spacing)
Sets spacing for currently active font.
Definition: display_base.h:186
uint8_t m_textMode
Flags for current NanoCanvas mode.
Definition: display_base.h:281
NanoFont & getFont()
Returns reference to NanoFont object, currently used by Display.
Definition: display_base.h:195
void setTextCursor(lcdint_t x, lcdint_t y)
Function sets text cursor position for write() functions.
Definition: display_base.h:269
void loadFixedFont(const uint8_t *progmemFont)
Function allows to set another fixed font for the library.
lcdint_t m_cursorX
current X cursor position for text output
Definition: display_base.h:279
EFontStyle
Supported font styles.
Definition: canvas_types.h:88
Class implements basic display operations for the library: It stores reference to communication inter...
Definition: display_base.h:55
void loadSecondaryFont(const uint8_t *progmemUnicode)
Function allows sets secondary font for specific language.
void setFreeFont(const uint8_t *progmemFont, const uint8_t *secondaryFont=nullptr)
Sets new font to use with print functions.
Definition: display_base.h:253
void setBackground(uint16_t color)
Sets background color.
Definition: display_base.h:142
I & m_intf
communication interface with the display
Definition: display_base.h:287
void loadFreeFont(const uint8_t *progmemFont)
Function allows to set another free font for the library.
lcduint_t m_p
number of bits, used by width value: 3 equals to 8 pixels width
Definition: display_base.h:278
Font class.