AddressWindow.h
Go to the documentation of this file.
1 /****
2  * AddressWindow.h
3  *
4  * Copyright 2021 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming-Graphics Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: May 2021 - mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "Types.h"
25 
26 namespace Graphics
27 {
37 struct AddressWindow {
38  // Last access mode for window
39  enum class Mode {
40  none,
41  write,
42  read,
43  };
44 
46  uint16_t column{0};
49 
51  {
52  }
53 
54  AddressWindow(const Rect& rect) : bounds(rect), initial(rect)
55  {
56  }
57 
58  void reset()
59  {
60  column = 0;
61  bounds = initial;
62  }
63 
65  {
66  if(this->mode == mode) {
67  return false;
68  }
69  this->mode = mode;
70  reset();
71  return true;
72  }
73 
75  {
76  initial = rect;
77  mode = Mode::none;
78  reset();
79  return *this;
80  }
81 
85  size_t getPixelCount() const
86  {
87  return bounds.w * bounds.h - column;
88  }
89 
90  uint16_t seek(uint16_t count)
91  {
92  if(bounds.h == 0) {
93  return 0;
94  }
95  auto pos = column;
96  uint16_t res{0};
97  column += count;
98  while(column >= bounds.w && bounds.h != 0) {
99  column -= bounds.w;
100  ++bounds.y;
101  --bounds.h;
102  res += bounds.w;
103  }
104  return res + column - pos;
105  }
106 
107  Point pos() const
108  {
109  return Point(left(), top());
110  }
111 
112  uint16_t left() const
113  {
114  return bounds.left() + column;
115  }
116 
117  uint16_t top() const
118  {
119  return bounds.top();
120  }
121 
122  uint16_t right() const
123  {
124  return bounds.right();
125  }
126 
127  uint16_t bottom() const
128  {
129  return bounds.bottom();
130  }
131 };
132 
133 } // namespace Graphics
Definition: Virtual.h:31
TPoint< int16_t > Point
Definition: Libraries/Graphics/src/include/Graphics/Types.h:280
Manages a rectangular area of display memory with position information.
Definition: AddressWindow.h:37
uint16_t left() const
Definition: AddressWindow.h:112
uint16_t bottom() const
Definition: AddressWindow.h:127
void reset()
Definition: AddressWindow.h:58
Rect bounds
y and h are updated by seek()
Definition: AddressWindow.h:45
uint16_t top() const
Definition: AddressWindow.h:117
AddressWindow & operator=(const Rect &rect)
Definition: AddressWindow.h:74
uint16_t column
Relative x position within window.
Definition: AddressWindow.h:46
Mode
Definition: AddressWindow.h:39
AddressWindow()
Definition: AddressWindow.h:50
bool setMode(Mode mode)
Definition: AddressWindow.h:64
AddressWindow(const Rect &rect)
Definition: AddressWindow.h:54
uint16_t right() const
Definition: AddressWindow.h:122
Point pos() const
Definition: AddressWindow.h:107
uint16_t seek(uint16_t count)
Definition: AddressWindow.h:90
size_t getPixelCount() const
Get remaining pixels in window from current position.
Definition: AddressWindow.h:85
Mode mode
Definition: AddressWindow.h:48
Rect initial
Definition: AddressWindow.h:47
Location and size of rectangular area (x, y, w, h)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:287
int16_t y
Definition: Libraries/Graphics/src/include/Graphics/Types.h:289
uint16_t h
Definition: Libraries/Graphics/src/include/Graphics/Types.h:291
int16_t bottom() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:412
int16_t left() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:397
uint16_t w
Definition: Libraries/Graphics/src/include/Graphics/Types.h:290
int16_t right() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:402
int16_t top() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:407