SSD1306 OLED display driver  1.7.1
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
rect.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018, 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_RECT_H_
29 #define _NANO_RECT_H_
30 
31 #include "point.h"
32 #include "ssd1306_hal/io.h"
33 
37 typedef struct _NanoRect
38 {
41 
44 
50  void move(lcdint_t dx, lcdint_t dy)
51  {
52  p1.x += dx; p2.x += dx;
53  p1.y += dy; p2.y += dy;
54  }
55 
60  void addH(lcdint_t dx)
61  {
62  p1.x += dx; p2.x += dx;
63  };
64 
69  void addV(lcdint_t dy)
70  {
71  p1.y += dy;
72  p2.y += dy;
73  };
74 
82  void setRect(lcdint_t l, lcdint_t t, lcdint_t r, lcdint_t b)
83  {
84  p1.x = l; p1.y = t;
85  p2.x = r; p2.y = b;
86  };
87 
92  bool collisionX(lcdint_t x) const { return (x >= p1.x) && (x <= p2.x); };
93 
98  bool collisionY(lcdint_t y) const { return (y >= p1.y) && (y <= p2.y); };
99 
104  bool collision(const NanoPoint &p) const { return collisionX(p.x) && collisionY(p.y); };
105 
110  bool above(const NanoPoint &p) const { return (p.y < p1.y); };
111 
116  bool below(const NanoPoint &p) const { return (p.y > p2.y); };
117 
123  {
124  return { {static_cast<lcdint_t>(p1.x - p.x), static_cast<lcdint_t>(p1.y - p.y) },
125  {static_cast<lcdint_t>(p2.x - p.x), static_cast<lcdint_t>(p2.y - p.y) } };
126  };
127 
133  {
134  return { {static_cast<lcdint_t>(p1.x + p.x), static_cast<lcdint_t>(p1.y + p.y) },
135  {static_cast<lcdint_t>(p2.x + p.x), static_cast<lcdint_t>(p2.y + p.y) } };
136  };
137 
143  {
144  p1.x += p.x;
145  p1.y += p.y;
146  p2.x += p.x;
147  p2.y += p.y;
148  return *this;
149  };
150 
151 } NanoRect;
152 
153 #endif
154 
bool below(const NanoPoint &p) const
Definition: rect.h:116
bool collisionX(lcdint_t x) const
Definition: rect.h:92
_NanoRect operator-(const _NanoPoint &p)
Definition: rect.h:122
_NanoRect operator+(const _NanoPoint &p)
Definition: rect.h:132
Definition: rect.h:37
void addV(lcdint_t dy)
Definition: rect.h:69
NanoPoint p2
Definition: rect.h:43
lcdint_t y
Definition: point.h:40
bool collisionY(lcdint_t y) const
Definition: rect.h:98
void setRect(lcdint_t l, lcdint_t t, lcdint_t r, lcdint_t b)
Definition: rect.h:82
_NanoRect & operator+=(const _NanoPoint &p)
Definition: rect.h:142
void addH(lcdint_t dx)
Definition: rect.h:60
void move(lcdint_t dx, lcdint_t dy)
Definition: rect.h:50
bool collision(const NanoPoint &p) const
Definition: rect.h:104
bool above(const NanoPoint &p) const
Definition: rect.h:110
struct _NanoRect NanoRect
NanoPoint p1
Definition: rect.h:40
lcdint_t x
Definition: point.h:38