-
Notifications
You must be signed in to change notification settings - Fork 1
/
di_primitive.h
180 lines (145 loc) · 5.26 KB
/
di_primitive.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// primitive.h - Function declarations for base drawing primitives
//
// A drawing primitive tells how to draw a particular type of simple graphic object.
//
// Copyright (c) 2023 Curtis Whitley
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#pragma once
#include <stdint.h>
#include <stddef.h>
#include "driver/gpio.h"
#include "di_constants.h"
// Used as a hint, to potentially save RAM, when allocating bitmaps.
typedef enum ScrollMode {
NONE, // do not allow scrolling
HORIZONTAL, // allow horizontal, but not vertical
VERTICAL, // allow vertical, but not horizontal
BOTH // both horizontal and vertical
};
#pragma pack(push,4)
typedef struct {
volatile uint32_t* m_line32; // address of the DMA visible data
volatile uint8_t* m_line8; // address of the DMA visible data
int32_t m_line_index; // scan line index on the screen (0=top, 599=bottom)
int32_t m_scrolled_y; // sum of m_line_index + m_vert_scroll
int32_t m_horiz_scroll; // used to move all top-level primitives in the X direction
int32_t m_vert_scroll; // used to move all top-level primitives in the Y direction
int32_t m_screen_width; // fixed at 800
int32_t m_screen_height; // fixed at 600
} DiPaintParams;
class DiPrimitive {
public:
// An object to be drawn on the screen.
DiPrimitive();
// Destroys an allocated RAM required by the primitive.
virtual ~DiPrimitive();
// Gets the range of Y scan lines used by the primitive.
virtual void get_vertical_line_range(int32_t* min_y, int32_t* max_y);
// Draws the primitive to the DMA scan line buffer.
virtual void IRAM_ATTR paint(const DiPaintParams *params);
// Groups scan lines for optimizing paint calls.
void get_vertical_group_range(int32_t* min_group, int32_t* max_group);
protected:
// Used to type-case some pointers. (Might be removed in future.)
inline uint8_t* pixels(uint32_t* line) {
return (uint8_t*)line;
}
};
class DiPrimitiveX: public DiPrimitive {
public:
int32_t m_x;
DiPrimitiveX();
DiPrimitiveX(int32_t x);
};
class DiPrimitiveXC: public DiPrimitiveX {
public:
uint32_t m_color;
DiPrimitiveXC();
DiPrimitiveXC(int32_t x, uint8_t color);
};
class DiPrimitiveY: public DiPrimitive {
public:
int32_t m_y;
DiPrimitiveY();
DiPrimitiveY(int32_t y);
virtual void get_vertical_line_range(int32_t* min_y, int32_t* max_y);
};
class DiPrimitiveYC: public DiPrimitiveY {
public:
uint32_t m_color;
DiPrimitiveYC();
DiPrimitiveYC(int32_t y, uint8_t color);
};
class DiPrimitiveXY: public DiPrimitiveX {
public:
int32_t m_y;
DiPrimitiveXY();
DiPrimitiveXY(int32_t x, int32_t y);
virtual void get_vertical_line_range(int32_t* min_y, int32_t* max_y);
};
class DiPrimitiveXYC: public DiPrimitiveXY {
public:
uint32_t m_color;
DiPrimitiveXYC();
DiPrimitiveXYC(int32_t x, int32_t y, uint8_t color);
};
class DiPrimitiveXYW: public DiPrimitiveXY {
public:
int32_t m_width;
int32_t m_x_extent;
DiPrimitiveXYW();
DiPrimitiveXYW(int32_t x, int32_t y, int32_t width);
};
class DiPrimitiveXYWC: public DiPrimitiveXYW {
public:
uint32_t m_color;
DiPrimitiveXYWC();
DiPrimitiveXYWC(int32_t x, int32_t y, int32_t width, uint8_t color);
};
class DiPrimitiveXYH: public DiPrimitiveXY {
public:
int32_t m_height;
int32_t m_y_extent;
DiPrimitiveXYH();
DiPrimitiveXYH(int32_t x, int32_t y, int32_t height);
virtual void get_vertical_line_range(int32_t* min_y, int32_t* max_y);
};
class DiPrimitiveXYHC: public DiPrimitiveXYH {
public:
uint32_t m_color;
DiPrimitiveXYHC();
DiPrimitiveXYHC(int32_t x, int32_t y, int32_t height, uint8_t color);
};
class DiPrimitiveXYWH: public DiPrimitiveXYW {
public:
int32_t m_height;
int32_t m_y_extent;
DiPrimitiveXYWH();
DiPrimitiveXYWH(int32_t x, int32_t y, int32_t width, int32_t height);
virtual void get_vertical_line_range(int32_t* min_y, int32_t* max_y);
};
class DiPrimitiveXYWHC: public DiPrimitiveXYWH {
public:
uint32_t m_color;
DiPrimitiveXYWHC();
DiPrimitiveXYWHC(int32_t x, int32_t y, int32_t width, int32_t height, uint8_t color);
};
#pragma pack(pop)