Registers.h
Go to the documentation of this file.
1 /****
2  * Registers.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 {
28 namespace Drawing
29 {
30 // name, type, default
31 #define GRAPHICS_DRAWING_REGISTER_LIST(XX) \
32  XX(x1, int16_t, 0) \
33  XX(y1, int16_t, 0) \
34  XX(x2, int16_t, 0) \
35  XX(y2, int16_t, 0) \
36  XX(penColor, Color, Color::White) \
37  XX(brushColor, Color, Color::Black) \
38  XX(penWidth, uint16_t, 1) \
39  XX(radius, uint16_t, 0) \
40  XX(startAngle, uint16_t, 0) \
41  XX(angle, int16_t, 0) \
42  XX(brushId, AssetID, 0) \
43  XX(penId, AssetID, 0) \
44  XX(textId, AssetID, 0) \
45  XX(id, AssetID, 0) \
46  XX(length, uint16_t, 0xffff) \
47  XX(offset, uint16_t, 0) \
48  XX(style, FontStyles, 0) \
49  XX(fontId, AssetID, 0)
50 
51 enum class OpCode : uint8_t {
52  store,
53  add,
54  sub,
55  execute,
56 };
57 
58 String toString(OpCode opcode);
59 
60 struct Registers {
61 #define XX(name, type, def) type name{def};
63 #undef XX
64 
65  Point pt1() const
66  {
67  return Point{x1, y1};
68  }
69 
70  Point pt2() const
71  {
72  return Point{x2, y2};
73  }
74 
75  Rect rect() const
76  {
77  return Rect{pt1(), pt2()};
78  }
79 
80  uint16_t endAngle() const
81  {
82  return startAngle + angle;
83  }
84 
85  template <typename T> void update(uint8_t index, OpCode opcode, T value)
86  {
87  assert(index * sizeof(T) < sizeof(Registers));
88  auto& reg = reinterpret_cast<T*>(this)[index];
89  switch(opcode) {
90  case OpCode::store:
91  reg = value;
92  break;
93  case OpCode::add:
94  reg += value;
95  break;
96  case OpCode::sub:
97  reg -= value;
98  break;
100  assert(false);
101  break;
102  }
103  }
104 
105  static String nameAt(uint8_t offset);
106 };
107 
108 } // namespace Drawing
109 } // namespace Graphics
void update(uint8_t index, OpCode opcode, T value)
Definition: Registers.h:123
static String nameAt(uint8_t offset)
The String class.
Definition: WString.h:136
OpCode
Definition: Registers.h:89
Definition: Virtual.h:30
TPoint< int16_t > Point
Definition: Libraries/Graphics/src/include/Graphics/Types.h:299
Point pt2() const
Definition: Registers.h:108
#define GRAPHICS_DRAWING_REGISTER_LIST(XX)
Definition: Registers.h:69
Rect rect() const
Definition: Registers.h:113
String toString(OpCode opcode)
uint16_t endAngle() const
Definition: Registers.h:118
Point pt1() const
Definition: Registers.h:103