KolibriLib
Loading...
Searching...
No Matches
graphic.hpp
1#ifndef __GRAPHIC_H__
2#define __GRAPHIC_H__
3
4
5#include <sys/ksys.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#include <math.h>
11
12#include "base.hpp"
13#include "UI.hpp"
14#include "color.hpp"
15
16namespace KolibriLib
17{
18 // Графика
19 namespace graphic
20 {
25 inline void DrawLine(UI::Coord a, UI::Coord b, Color::Color color = OS::sys_color_table.work_graph)
26 {
27 _ksys_draw_line(a.x, a.y, b.x, b.y, color);
28 }
29
33 inline void DrawPixel(UI::Coord position, Color::Color color)
34 {
35 _ksys_draw_pixel(position.x, position.y, color);
36 }
37
43 void DrawCircle(UI::Coord coord, unsigned Radius, unsigned detalization = 36, Color::Color color = OS::sys_color_table.work_graph)
44 {
45 UI::Coord buff;
46 unsigned b = Radius;
47 unsigned c = 0;
48 for (unsigned angle = 1; angle <= detalization * 10; angle += 36 / detalization)
49 {
50 buff = {coord.x + (int)b, coord.y + (int)c};
51 b = Radius * cos(angle);
52 c = Radius * sin(angle);
53 UI::Coord n = {coord.x + (int)b, coord.y + (int)c};
54 DrawLine(buff, n);
55 }
56 }
57
62 void DrawRectangleFill(UI::Coord position, UI::Size size, Color::Color color = OS::sys_color_table.work_graph)
63 {
64 __asm__ __volatile__(
65 "int $0x40" ::"a"(13), "b"((position.x << 16) + size.x), "c"((position.y << 16) + size.y), "d"(color));
66 }
67
73 void DrawCircleFill(UI::Coord coord, unsigned Radius, unsigned detalization = 36, Color::Color color = OS::sys_color_table.work_graph)
74 {
75 DrawCircle(coord, Radius, color);
76
77 unsigned b = Radius * cos(90+45);
78 unsigned c = Radius * sin(90+45);
79 UI::Coord n = {coord.x + (int)b, coord.y + (int)c};
80
81 DrawRectangleFill(n, {(unsigned)(coord.x - n.x) * 2, (unsigned)c * 2}, color);
82
83 for (unsigned i = Radius; i > (Radius -(coord.x - n.x)); i--)//Дозакрашивание пробелов между квадратом и границами груга
84 {
85 DrawCircle(coord, i, detalization, color);
86 }
87 }
88
94 void DrawPoint(UI::Coord position, unsigned size, Color::Color color = OS::sys_color_table.work_graph, bool a = false)
95 {
96 if(size < 3)
97 {
98 a = true;
99 }
100 if (a)
101 {
102 DrawCircle(position, size, color);
103 }
104 else
105 {
106 DrawCircleFill(position, size, color);
107 }
108 }
109
110
114 void DrawRectangleLines(UI::Coord a, UI::Coord b, Color::Color color = OS::sys_color_table.work_graph)
115 {
116 DrawLine(a, {b.x, a.y}, color);
117 DrawLine(a, {a.x, b.y}, color);
118 DrawLine({b.x, a.y}, b, color);
119 DrawLine({a.x, b.y}, b, color);
120 }
121
122
123
129 inline void DrawTriangle(UI::Coord a, UI::Coord b, UI::Coord c, Color::Color color = OS::sys_color_table.work_graph)
130 {
131 DrawLine(a, b, color);
132 DrawLine(a, c, color);
133 DrawLine(b, c, color);
134 }
135 }
136} // namespace KolibriLib
137
138
139#endif // __GRAPHIC_H__
ksys_color_t Color
Цвет
Definition color.hpp:13
Color::ColorsTable sys_color_table
Таблица стандартных(системных) цветов
Definition os.hpp:15
Основное пространство имён
Definition base.hpp:18