LCDGFX LCD display driver  1.0.2
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 min
35 
36 #define min(a,b) ((a)<(b)?(a):(b))
37 #endif
38 
39 #ifndef max
40 
41 #define 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 
59 
64 typedef struct SPRITE
65 {
67  uint8_t x;
69  uint8_t y;
71  uint8_t w;
73  uint8_t lx;
75  uint8_t ly;
77  const uint8_t * data;
78 
79 #ifdef __cplusplus
80 
85  void setPos(uint8_t x, uint8_t y);
86 
91  void draw();
92 
96  void eraseTrace();
97 
101  void erase();
102 
107  inline bool isNearMove() const
108  {
109  /* We emulate abs function for unsigned vars here */
110  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
111  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
112  };
113 
122  inline SSD1306_RECT getRect() const
123  {
124  uint8_t right = ((x + w - 1)>>3);
125  uint8_t bottom = ((y + 7)>>3);
126  uint8_t left = x>>3; left = left < right ? left: 0;
127  uint8_t top = y>>3; top = top < bottom ? top: 0;
128  return (SSD1306_RECT){ left, top, right, bottom };
129  };
130 
138  inline SSD1306_RECT getLRect() const
139  {
140  uint8_t left = lx;
141  uint8_t top = ly;
142  uint8_t right = (uint8_t)(lx + w - 1);
143  uint8_t bottom = (uint8_t)(ly + 7);
144  left = left < right ? left: 0;
145  top = top < bottom ? top: 0;
146  return (SSD1306_RECT){ left, top, right, bottom };
147  };
148 
156  {
157  uint8_t left = min(x,lx);
158  uint8_t top = min(y,ly);
159  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
160  if (((uint8_t)(lx + w - 1) < w) && (right > 2*w))
161  {
162  right = (uint8_t)(lx + w - 1);
163  }
164  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
165  if (((uint8_t)(ly + 7) < 8) && (bottom > 16))
166  {
167  bottom = (uint8_t)(ly + 7);
168  }
169  if ( left > right ) left = 0;
170  if ( top > bottom ) top = 0;
171  return (SSD1306_RECT){ left, top, right, bottom };
172  };
173 #endif
174 } SPRITE;
175 
176 // ----------------------------------------------------------------------------
177 #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()
void draw()
void setPos(uint8_t x, uint8_t y)
uint8_t bottom
bottom
#define max(a, b)
uint8_t y
draw position Y on the screen
#define 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