LCDGFX LCD display driver  1.1.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
nano_gfx_types.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2017-2019, 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 _NANO_GFX_TYPES_H_
29 #define _NANO_GFX_TYPES_H_
30 
31 #include "lcd_hal/io.h"
32 #include "canvas/canvas_types.h"
33 
34 #ifndef lcd_gfx_min
35 
36 #define lcd_gfx_min(a, b) ((a) < (b) ? (a) : (b))
37 #endif
38 
39 #ifndef lcd_gfx_max
40 
41 #define lcd_gfx_max(a, b) ((a) > (b) ? (a) : (b))
42 #endif
43 
47 typedef struct
48 {
50  uint8_t left;
52  uint8_t top;
54  uint8_t right;
56  uint8_t bottom;
57 } SSD1306_RECT;
58 
63 typedef struct SPRITE
64 {
66  uint8_t x;
68  uint8_t y;
70  uint8_t w;
72  uint8_t lx;
74  uint8_t ly;
76  const uint8_t *data;
77 
78 #ifdef __cplusplus
79 
84  void setPos(uint8_t x, uint8_t y);
85 
90  void draw();
91 
95  void eraseTrace();
96 
100  void erase();
101 
106  inline bool isNearMove() const
107  {
108  /* We emulate abs function for unsigned vars here */
109  return (((uint8_t)(x - lx) < w) || ((uint8_t)(lx - x) < w)) &&
110  (((uint8_t)(y - ly) < 8) || ((uint8_t)(ly - y) < 8));
111  };
112 
121  inline SSD1306_RECT getRect() const
122  {
123  uint8_t right = ((x + w - 1) >> 3);
124  uint8_t bottom = ((y + 7) >> 3);
125  uint8_t left = x >> 3;
126  left = left < right ? left : 0;
127  uint8_t top = y >> 3;
128  top = top < bottom ? top : 0;
129  return (SSD1306_RECT){left, top, right, bottom};
130  };
131 
139  inline SSD1306_RECT getLRect() const
140  {
141  uint8_t left = lx;
142  uint8_t top = ly;
143  uint8_t right = (uint8_t)(lx + w - 1);
144  uint8_t bottom = (uint8_t)(ly + 7);
145  left = left < right ? left : 0;
146  top = top < bottom ? top : 0;
147  return (SSD1306_RECT){left, top, right, bottom};
148  };
149 
157  {
158  uint8_t left = lcd_gfx_min(x, lx);
159  uint8_t top = lcd_gfx_min(y, ly);
160  uint8_t right = lcd_gfx_max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
161  if ( ((uint8_t)(lx + w - 1) < w) && (right > 2 * w) )
162  {
163  right = (uint8_t)(lx + w - 1);
164  }
165  uint8_t bottom = lcd_gfx_max((uint8_t)(y + 7), (uint8_t)(ly + 7));
166  if ( ((uint8_t)(ly + 7) < 8) && (bottom > 16) )
167  {
168  bottom = (uint8_t)(ly + 7);
169  }
170  if ( left > right )
171  left = 0;
172  if ( top > bottom )
173  top = 0;
174  return (SSD1306_RECT){left, top, right, bottom};
175  };
176 #endif
177 } SPRITE;
178 
179 // ----------------------------------------------------------------------------
180 #endif // _NANO_GFX_TYPES_H_
struct SPRITE SPRITE
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
void eraseTrace()
void erase()
#define lcd_gfx_max(a, b)
void draw()
void setPos(uint8_t x, uint8_t y)
uint8_t bottom
bottom
uint8_t y
draw position Y on the screen
#define lcd_gfx_min(a, b)
SSD1306_RECT getUpdateRect() const
uint8_t x
draw position X on the screen
uint8_t w
sprite width
SSD1306_RECT getRect() const
uint8_t lx
last draw position X on the screen
bool isNearMove() const
uint8_t right
right
uint8_t ly
last draw position Y on the screen
SSD1306_RECT getLRect() const
uint8_t left
left