SSD1306 OLED display driver  1.3.1
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 enum
31 {
32  STYLE_NORMAL,
33  STYLE_BOLD,
34  STYLE_ITALIC,
35 } EFontStyle;
36 
40 typedef struct
41 {
43  uint8_t left;
45  uint8_t top;
47  uint8_t right;
49  uint8_t bottom;
50 } SSD1306_RECT;
51 
52 
56 typedef struct SPRITE
57 {
59  uint8_t x;
61  uint8_t y;
63  uint8_t w;
65  uint8_t lx;
67  uint8_t ly;
69  const uint8_t * data;
71  const uint8_t * transparentMask;
72 
78  void setPos(uint8_t x, uint8_t y);
79 
84  void draw();
85 
89  void eraseTrace();
90 
94  void erase();
95 
100  inline bool isNearMove() const
101  {
102  /* We emulate abs function for unsigned vars here */
103  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
104  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
105  };
106 
115  inline SSD1306_RECT getRect() const
116  {
117  uint8_t right = ((x + w - 1)>>3);
118  uint8_t bottom = ((y + 7)>>3);
119  uint8_t left = x>>3; left = left < right ? left: 0;
120  uint8_t top = y>>3; top = top < bottom ? top: 0;
121  return (SSD1306_RECT){ left, top, right, bottom };
122  };
123 
131  inline SSD1306_RECT getLRect() const
132  {
133  uint8_t left = lx;
134  uint8_t top = ly;
135  uint8_t right = (uint8_t)(lx + w - 1);
136  uint8_t bottom = (uint8_t)(ly + 7);
137  left = left < right ? left: 0;
138  top = top < bottom ? top: 0;
139  return (SSD1306_RECT){ left, top, right, bottom };
140  };
141 
149  {
150  uint8_t left = min(x,lx);
151  uint8_t top = min(y,ly);
152  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
153  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
154  if ( left >= right ) left = 0;
155  if ( top >= bottom ) top = 0;
156  return (SSD1306_RECT){ left, top, right, bottom };
157  };
158 } SPRITE;
159 
160 // ----------------------------------------------------------------------------
161 #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
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