SSD1306 OLED display driver  1.3.3
This library is developed to control SSD1306 i2c/spi 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 */
23 #ifndef _NANO_GFX_TYPES_H_
24 #define _NANO_GFX_TYPES_H_
25 
26 #include <stdint.h>
27 #include <Arduino.h>
28 
30 typedef void (*InitFunction)();
31 
33 typedef enum
34 {
35  STYLE_NORMAL,
36  STYLE_BOLD,
37  STYLE_ITALIC,
38 } EFontStyle;
39 
43 typedef struct
44 {
46  uint8_t left;
48  uint8_t top;
50  uint8_t right;
52  uint8_t bottom;
53 } SSD1306_RECT;
54 
55 
59 typedef struct SPRITE
60 {
62  uint8_t x;
64  uint8_t y;
66  uint8_t w;
68  uint8_t lx;
70  uint8_t ly;
72  const uint8_t * data;
74  const uint8_t * transparentMask;
75 
81  void setPos(uint8_t x, uint8_t y);
82 
87  void draw();
88 
92  void eraseTrace();
93 
97  void erase();
98 
103  inline bool isNearMove() const
104  {
105  /* We emulate abs function for unsigned vars here */
106  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
107  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
108  };
109 
118  inline SSD1306_RECT getRect() const
119  {
120  uint8_t right = ((x + w - 1)>>3);
121  uint8_t bottom = ((y + 7)>>3);
122  uint8_t left = x>>3; left = left < right ? left: 0;
123  uint8_t top = y>>3; top = top < bottom ? top: 0;
124  return (SSD1306_RECT){ left, top, right, bottom };
125  };
126 
134  inline SSD1306_RECT getLRect() const
135  {
136  uint8_t left = lx;
137  uint8_t top = ly;
138  uint8_t right = (uint8_t)(lx + w - 1);
139  uint8_t bottom = (uint8_t)(ly + 7);
140  left = left < right ? left: 0;
141  top = top < bottom ? top: 0;
142  return (SSD1306_RECT){ left, top, right, bottom };
143  };
144 
152  {
153  uint8_t left = min(x,lx);
154  uint8_t top = min(y,ly);
155  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
156  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
157  if ( left >= right ) left = 0;
158  if ( top >= bottom ) top = 0;
159  return (SSD1306_RECT){ left, top, right, bottom };
160  };
161 } SPRITE;
162 
163 // ----------------------------------------------------------------------------
164 #endif // _NANO_GFX_TYPES_H_
struct SPRITE SPRITE
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
const uint8_t * transparentMask
Pointer to PROGMEM data, representing sprite transparencyMask (can be nullptr)
void eraseTrace()
void erase()
void draw()
void setPos(uint8_t x, uint8_t y)
uint8_t bottom
bottom
void(* InitFunction)()
uint8_t y
draw position Y on the screen
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
EFontStyle
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