forked from apps-cs/apps-lcd-opencv-simul
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_class.hpp
More file actions
112 lines (84 loc) · 2.73 KB
/
Copy pathgraph_class.hpp
File metadata and controls
112 lines (84 loc) · 2.73 KB
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
// **************************************************************************
//
// Demo program for labs
//
// Subject: Computer Architectures and Parallel systems
// Author: Petr Olivka, petr.olivka@vsb.cz, 09/2019
// Organization: Department of Computer Science, FEECS,
// VSB-Technical University of Ostrava, CZ
//
// File: OpenCV simulator of LCD
//
// **************************************************************************
#include "lcd_lib.h"
// Simple graphic interface
struct Point2D
{
int32_t x, y;
};
struct RGB
{
uint8_t r, g, b;
};
class GraphElement
{
public:
// foreground and background color
RGB m_fg_color, m_bg_color;
// constructor
GraphElement( RGB t_fg_color, RGB t_bg_color ) :
m_fg_color( t_fg_color ), m_bg_color( t_bg_color ) {}
// ONLY ONE INTERFACE WITH LCD HARDWARE!!!
void drawPixel( int32_t t_x, int32_t t_y ) { lcd_put_pixel( t_x, t_y, convert_RGB888_to_RGB565( m_fg_color ) ); }
// Draw graphics element
virtual void draw() = 0;
// Hide graphics element
virtual void hide() { swap_fg_bg_color(); draw(); swap_fg_bg_color(); }
private:
// swap foreground and backgroud colors
void swap_fg_bg_color() { RGB l_tmp = m_fg_color; m_fg_color = m_bg_color; m_bg_color = l_tmp; }
// IMPLEMENT!!!
// conversion of 24-bit RGB color into 16-bit color format
uint16_t convert_RGB888_to_RGB565( RGB t_color ) { return 0x07E0; /* green color */ }
};
class Pixel : public GraphElement
{
public:
// constructor
Pixel( Point2D t_pos, RGB t_fg_color, RGB t_bg_color ) : GraphElement( t_fg_color, t_bg_color ), m_pos( t_pos ) {}
// Draw method implementation
virtual void draw() { drawPixel( m_pos.x, m_pos.y ); }
// Position of Pixel
Point2D m_pos;
};
class Circle : public GraphElement
{
public:
// Center of circle
Point2D m_center;
// Radius of circle
int32_t m_radius;
Circle( Point2D t_center, int32_t t_radius, RGB t_fg, RGB t_bg ) :
GraphElement( t_fg, t_bg ), m_center( t_center ), m_radius( t_radius ) {}
void draw() { } // IMPLEMENT!!!
};
class Character : public GraphElement
{
public:
// position of character
Point2D m_pos;
// character
char m_character;
Character( Point2D t_pos, char t_char, RGB t_fg, RGB t_bg ) :
GraphElement( t_fg, t_bg ), m_pos( t_pos ), m_character( t_char ) {};
void draw() { }; // IMPLEMENT!!!
};
class Line : public GraphElement
{
public:
// the first and the last point of line
Point2D m_pos1, m_pos2;
Line( Point2D t_pos1, Point2D t_pos2, RGB t_fg, RGB t_bg ) :
GraphElement( t_fg, t_bg ), m_pos1( t_pos1 ), m_pos2( t_pos2 ) {}
void draw() { }; // IMPLEMENT!!!
};