SayoriOS  0.3.3
pixel.c
См. документацию.
1 
10 #include <io/ports.h>
11 #include <io/status_loggers.h>
12 #include <lib/stdio.h>
13 #include <lib/tui.h>
14 #include <lib/pixel.h>
15 
25 void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color){
26  for (__typeof__(x) _y = y, endy = y+h; _y < endy; _y++){
27  for (__typeof__(x) _x = x, endx = x+w; _x < endx; _x++){
28  set_pixel(_x, _y, color);
29  }
30  }
31 }
32 
44 void drawRectLine(int x,int y,int w, int h,int color,int color2, int c){
55 }
56 
66 void drawRectBorder(int x, int y, int w, int h, int color){
67  for (int _x = x; _x < x+w ; _x++){
68  set_pixel(_x, y, color);
69  set_pixel(_x, y+h, color);
70  }
71  for (int _y = y; _y < y+h; _y++){
72 
73  set_pixel(x, _y, color);
74  set_pixel(x+w, _y, color);
75  }
76 }
77 
86 void drawHorizontalLine(int x1, int x2, int y, uint32_t color) {
87  for (int x = x1; x <= x2; x++) {
88  set_pixel(x, y, color);
89  }
90 }
91 
100 void drawVerticalLine(int y1, int y2, int x, uint32_t color) {
101  for (int y = y1; y <= y2; y++) {
102  set_pixel(x, y, color);
103  }
104 }
105 
117 void drawCirclePoints(int cx, int cy, int x, int y, uint32_t color) {
118  set_pixel(cx + x, cy + y, color);
119  set_pixel(cx - x, cy + y, color);
120  set_pixel(cx + x, cy - y, color);
121  set_pixel(cx - x, cy - y, color);
122  set_pixel(cx + y, cy + x, color);
123  set_pixel(cx - y, cy + x, color);
124  set_pixel(cx + y, cy - x, color);
125  set_pixel(cx - y, cy - x, color);
126 }
127 
136 void drawCircle(int cx, int cy, int radius, uint32_t color) {
137  int x = 0;
138  int y = radius;
139  int p = 3 - 2 * radius;
140  drawCirclePoints(cx, cy, x, y, color);
141 
142  while (x <= y) {
143  if (p < 0) {
144  p = p + 4 * x + 6;
145  } else {
146  p = p + 4 * (x - y) + 10;
147  y--;
148  }
149  x++;
150  drawCirclePoints(cx, cy, x, y, color);
151  }
152 }
153 
154 
163 void drawFilledCircle(int x0, int y0, int radius, uint32_t color) {
164  int x = radius;
165  int y = 0;
166  int err = 0;
167 
168  while (x >= y) {
169  drawHorizontalLine(x0 - x, x0 + x, y0 + y, color);
170  drawHorizontalLine(x0 - x, x0 + x, y0 - y, color);
171  drawHorizontalLine(x0 - y, x0 + y, y0 + x, color);
172  drawHorizontalLine(x0 - y, x0 + y, y0 - x, color);
173 
174  if (err <= 0) {
175  y += 1;
176  err += 2*y + 1;
177  }
178  if (err > 0) {
179  x -= 1;
180  err -= 2*x + 1;
181  }
182  }
183 }
184 
195 void drawFilledRectBorder(int x0, int y0, int radius, int w, int mode, uint32_t color) {
196  int x = radius;
197  int y = 0;
198  int err = 0;
199 
200  while (x >= y) {
201  drawHorizontalLine(x0 - x - (mode == 3 || mode == 4?(w/2):0), x0 + x + (mode == 1 || mode == 2?(w/2):0) , y0 - y, color);
202  drawHorizontalLine(x0 - y - (mode == 3 || mode == 4?(w/2):0), x0 + y + (mode == 1 || mode == 2?(w/2):0), y0 - x, color);
203  drawHorizontalLine(x0 - x - (mode == 3 || mode == 4?(w/2):0), x0 + x + (mode == 1 || mode == 2?(w/2):0) , y0 + y, color);
204  drawHorizontalLine(x0 - y - (mode == 3 || mode == 4?(w/2):0), x0 + y + (mode == 1 || mode == 2?(w/2):0), y0 + x, color);
205 
206  if (err <= 0) {
207  y += 1;
208  err += 2*y + 1;
209  }
210  if (err > 0) {
211  x -= 1;
212  err -= 2*x + 1;
213  }
214  }
215 }
216 
227 void drawRoundedSquare(int x, int y, int size, int radius, uint32_t fill_color, uint32_t border_color) {
228  // Отрисовываем внутренний заполненный квадрат
229  for (int i = x+1; i < x + size-1; i++) {
230  drawVerticalLine(y + radius, y + size - radius - 1, i, fill_color);
231  }
232 
233 
234  // Отрисовываем угловые закругления
235  if (radius > 0) {
236  drawFilledRectBorder(x + radius, y + radius, radius, size, 1, (border_color != -1 ? border_color : fill_color));
237  drawFilledRectBorder(x + size - radius - 1, y + radius, radius,size, 3, (border_color != -1 ? border_color : fill_color));
238  drawFilledRectBorder(x + radius, y + size - radius - 1, radius,size, 2, (border_color != -1 ? border_color : fill_color));
239  drawFilledRectBorder(x + size - radius - 1, y + size - radius - 1, radius,size, 4, (border_color != -1 ? border_color : fill_color));
240  }
241 
242  // Отрисовываем обводку квадрата
243  if (border_color != -1) {
244  drawHorizontalLine(x + radius, x + size - 1 - radius, y, border_color);
245  drawHorizontalLine(x + radius, x + size - 1 - radius, y + size - 1, border_color);
246  drawVerticalLine(y + radius, y + size - 1 - radius, x, border_color);
247  drawVerticalLine(y + radius, y + size - 1 - radius, x + size - 1, border_color);
248  }
249 }
250 
251 
263 void drawRoundedRectangle(int x, int y, int width, int height, int radius, uint32_t fill_color, uint32_t border_color) {
264  // Отрисовываем внутренний заполненный прямоугольник
265  for (int i = x + 1; i < x + width - 1; i++) {
266  for (int j = y + radius; j < y + height - radius; j++) {
267  set_pixel(i, j, fill_color);
268  }
269  }
270 
271  // Отрисовываем угловые закругления
272  if (radius > 0) {
273  drawFilledRectBorder(x + radius, y + radius, radius, width, 1, (border_color != -1 ? border_color : fill_color));
274  drawFilledRectBorder(x + width - radius - 1, y + radius, radius,width, 3, (border_color != -1 ? border_color : fill_color));
275 
276  drawFilledRectBorder(x + radius, y + height - radius - 1, radius,width, 2, (border_color != -1 ? border_color : fill_color));
277  drawFilledRectBorder(x + width - radius - 1, y + height - radius - 1, radius,width, 4, (border_color != -1 ? border_color : fill_color));
278  }
279 
280 }
uint32_t mode
Режим работы (0 - Обычный | 1 - Режим логирования)
Definition: bootscreen.c:23
void drawCircle(int cx, int cy, int radius, uint32_t color)
Рисует круг
Definition: pixel.c:136
void drawRoundedRectangle(int x, int y, int width, int height, int radius, uint32_t fill_color, uint32_t border_color)
Рисуем округленный прямоугольник, закрашиваем его и обводим
Definition: pixel.c:263
void drawFilledCircle(int x0, int y0, int radius, uint32_t color)
Закрашивает круг
Definition: pixel.c:163
void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Рисуем залитый прямоугольник
Definition: pixel.c:25
void drawFilledRectBorder(int x0, int y0, int radius, int w, int mode, uint32_t color)
Закрашивает округленный куб
Definition: pixel.c:195
void drawRectLine(int x, int y, int w, int h, int color, int color2, int c)
Рисует узор вокруг прямоугольника
Definition: pixel.c:44
void drawHorizontalLine(int x1, int x2, int y, uint32_t color)
Рисует горизонтальную линию
Definition: pixel.c:86
void drawVerticalLine(int y1, int y2, int x, uint32_t color)
Рисует вертикальную линию
Definition: pixel.c:100
void drawCirclePoints(int cx, int cy, int x, int y, uint32_t color)
Рисует окружные пиксели круга линию
Definition: pixel.c:117
void drawRectBorder(int x, int y, int w, int h, int color)
Рисует линию вокруг прямоугольника
Definition: pixel.c:66
void drawRoundedSquare(int x, int y, int size, int radius, uint32_t fill_color, uint32_t border_color)
Рисуем округленный куб закрашиваем его и обводим
Definition: pixel.c:227