SSD1306 I2C Display Driver  1.1.0
This library is developed to control SSD1306 I2C OLED Display
nano_gfx_types.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 Alexey Dynda
3 
4  This file is part of SSD1306 library.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
24 #ifndef _NANO_GFX_TYPES_H_
25 #define _NANO_GFX_TYPES_H_
26 
27 #include <stdint.h>
28 #include <Arduino.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
35 typedef enum
36 {
37  STYLE_NORMAL,
38  STYLE_BOLD,
39  STYLE_ITALIC,
40 } EFontStyle;
41 
45 typedef struct
46 {
48  uint8_t left;
50  uint8_t top;
52  uint8_t right;
54  uint8_t bottom;
55 } SSD1306_RECT;
56 
57 
61 typedef struct
62 {
64  uint8_t x;
66  uint8_t y;
68  uint8_t w;
70  uint8_t lx;
72  uint8_t ly;
74  const uint8_t * data;
76  const uint8_t * transparentMask;
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()
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 
122  {
123  uint8_t right = ((x + w - 1)>>3);
124  uint8_t bottom = ((y + 7)>>3);
125  uint8_t left = x>>3; left = left < right ? left: 0;
126  uint8_t top = y>>3; top = top < bottom ? top: 0;
127  return (SSD1306_RECT){ left, top, right, bottom };
128  };
129 
138  {
139  uint8_t left = lx;
140  uint8_t top = ly;
141  uint8_t right = (uint8_t)(lx + w - 1);
142  uint8_t bottom = (uint8_t)(ly + 7);
143  left = left < right ? left: 0;
144  top = top < bottom ? top: 0;
145  return (SSD1306_RECT){ left, top, right, bottom };
146  };
147 
155  {
156  uint8_t left = min(x,lx);
157  uint8_t top = min(y,ly);
158  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
159  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
160  if ( left >= right ) left = 0;
161  if ( top >= bottom ) top = 0;
162  return (SSD1306_RECT){ left, top, right, bottom };
163  };
164 
165 #endif
166 
167 } SPRITE;
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 // ----------------------------------------------------------------------------
174 #endif // _NANO_GFX_TYPES_H_
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
SSD1306_RECT getLRect()
const uint8_t * transparentMask
Pointer to PROGMEM data, representing sprite transparencyMask (can be nullptr)
SSD1306_RECT getRect()
uint8_t bottom
bottom
SSD1306_RECT getUpdateRect()
uint8_t y
draw position Y on the screen
uint8_t x
draw position X on the screen
uint8_t w
sprite width
uint8_t lx
last draw position X on the screen
EFontStyle
uint8_t right
right
bool isNearMove()
uint8_t ly
last draw position Y on the screen
uint8_t left
left