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
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
SPRITE structure represents logical graphics object.
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
void eraseTrace()
Clears some sprite parts in old position on the display.
SSD1306 HAL IO communication functions.
void erase()
Clears sprite from the display leaving black rectangle.
#define lcd_gfx_max(a, b)
Macros returning maximum of 2 numbers.
SPRITE structure represents logical graphics object.
Basic structures of canvas gfx library.
void draw()
Draws sprite on the display.
void setPos(uint8_t x, uint8_t y)
Updates active position of the sprite (doesn&#39;t redraw it)
uint8_t bottom
bottom
uint8_t y
draw position Y on the screen
#define lcd_gfx_min(a, b)
Macros returning minimum of 2 numbers.
SSD1306_RECT getUpdateRect() const
Returns area in 8-pixel blocks, which includes old and new position For example, if sprite pixels coo...
uint8_t x
draw position X on the screen
uint8_t w
sprite width
SSD1306_RECT getRect() const
Returns area in 8-pixel blocks, which is used by the sprite.
uint8_t lx
last draw position X on the screen
Rectangle region.
bool isNearMove() const
Returns true if sprite is moved not far from previous position, and old and new rects have intersecti...
uint8_t right
right
uint8_t ly
last draw position Y on the screen
SSD1306_RECT getLRect() const
Returns area in 8-pixel blocks, which was used by the sprite last time For example, if sprite pixels coordinates are 10,18 and size is 8x8, the rect will be (left:1,top:2,right:2,bottom:3).
uint8_t left
left