SayoriOS  0.3.3
texplorer.c
См. документацию.
1 
11 #include <kernel.h>
12 #include <io/ports.h>
13 #include <io/status_loggers.h>
14 #include <lib/stdio.h>
15 #include <lib/tui.h>
16 #include <drv/input/keymap.h>
17 
18 #define TE_COLOR_BODY 0x00
19 #define TE_COLOR_TEXT 0x01
20 #define TE_COLOR_START_BODY 0x02
21 #define TE_COLOR_START_TEXT 0x03
22 #define TE_COLOR_BORDER 0x04
23 #define TE_COLOR_BACKGROUND 0x05
24 #define TE_COLOR_TITLE_BODY 0x06
25 #define TE_COLOR_TITLE_TEXT 0x07
26 #define TE_COLOR_BTN_BODY 0x08
27 #define TE_COLOR_BTN_TEXT 0x09
28 #define TE_COLOR_BTN_BORD 0x10
29 #define TE_COLOR_PGB_BORD 0x11
30 #define TE_COLOR_PGB_BODY 0x12
31 #define TE_COLOR_PGB_TEXT 0x13
32 
33 //DukeHeader_t* TE_Icons[32];
34 
35 int TE_getColor(int item){
36  if (item == TE_COLOR_BODY) return 0xFFFFFF;
37  if (item == TE_COLOR_TEXT) return 0x000000;
38  if (item == TE_COLOR_START_BODY) return 0xFFFFFF;
39  if (item == TE_COLOR_START_TEXT) return 0x000000;
40  if (item == TE_COLOR_BORDER) return 0x000000;
41  if (item == TE_COLOR_BACKGROUND) return 0x000000;
42  if (item == TE_COLOR_TITLE_BODY) return 0xFFFFFF;
43  if (item == TE_COLOR_TITLE_TEXT) return 0x000000;
44  if (item == TE_COLOR_BTN_BODY) return 0xFFFFFF;
45  if (item == TE_COLOR_BTN_TEXT) return 0x000000;
46  if (item == TE_COLOR_BTN_BORD) return 0x000000;
47  if (item == TE_COLOR_PGB_BORD) return 0x000000;
48  if (item == TE_COLOR_PGB_BODY) return 0xFFFFFF;
49  if (item == TE_COLOR_PGB_TEXT) return 0x43ACE8;
50  return 0x000000;
51 }
52 
53 void TE_DrawTime(){
54  setPosY(getScreenHeight() - 20);
55 
56 // sayori_time_t time = get_time();
57  setPosX(getScreenWidth() - 68);
58 
59  tty_puts_color("22:22:22",TE_getColor(TE_COLOR_START_TEXT),TE_getColor(TE_COLOR_START_BODY));
60 
61  setPosX(getScreenWidth() - 88);
62 
63  tty_puts_color("EN",TE_getColor(TE_COLOR_START_TEXT),TE_getColor(TE_COLOR_START_BODY));
64 
65  //tty_printf("%s%d:%s%d:%s%d", (time.hours>10?"":"0"), time.hours, (time.minutes>10?"":"0"),time.minutes, (time.seconds>10?"":"0"),time.seconds);
66 }
67 
68 void TE_DrawMessageBox(char* title, char* msg, int mode, int x, int y, int close, int data, int data2){
69  //qemu_log("[TE] Title: %s\n Message: %s\n Mode:%x\n Close:%x\n Data1:%d\n Data2:%d",title,msg,mode,close,(int) data,(int) data2);
70 
71  int w = 320;
72  int h = 64;
73 
75  drawRect(x,y,w,h,TE_getColor(TE_COLOR_BODY));
77  drawRect(x+1,y+1,w-3,h-3,TE_getColor(TE_COLOR_TITLE_BODY));
78  drawRectBorder(x+1,y+1,w-3,h-3,TE_getColor(TE_COLOR_BORDER));
79  setPosX(x+6);
80  setPosY(y+4);
81  _tty_puts_color(title,TE_getColor(TE_COLOR_TITLE_TEXT),TE_getColor(TE_COLOR_TITLE_BODY));
82  drawRectBorder(x+1,y+1,w-3,18,TE_getColor(TE_COLOR_BORDER));
84  setPosX(x+6);
85  setPosY(y+22);
86  _tty_puts_color(msg,TE_getColor(TE_COLOR_TEXT),TE_getColor(TE_COLOR_BODY));
88  if (close){
89  setPosX(x+w-12);
90  setPosY(y+4);
91  _tty_puts_color("X",TE_getColor(TE_COLOR_TITLE_TEXT),TE_getColor(TE_COLOR_TITLE_BODY));
92  drawRectBorder(x+w-16,y+1,14,18,TE_getColor(TE_COLOR_BORDER));
93  }
94  if (mode == 0) return;
95  if (mode == 1){
96  drawRect(x+16,y+h-22,w-32,16,TE_getColor(TE_COLOR_BTN_BODY));
97  drawRectBorder(x+17,y+h-21,w-35,15,TE_getColor(TE_COLOR_BTN_BORD));
98  setPosX(x+((w-32)/2));
99  setPosY(y+h-20);
100  _tty_puts_color("OK",TE_getColor(TE_COLOR_BTN_TEXT),TE_getColor(TE_COLOR_BTN_BODY));
101  }
102  if (mode == 2){
103  // ProgreesBar
104 
105  drawRect(x+16,y+h-22,w-32,16,TE_getColor(TE_COLOR_PGB_BODY));
106  drawRectBorder(x+17,y+h-21,w-35,15,TE_getColor(TE_COLOR_PGB_BORD));
107  int wb = w-32-8;
108  int hb = 10;
109  int pc = (((int) data * wb)/(int) data2);
110  drawRect(x+20,y+h-18,(pc == 0?((int) data) + (wb) :pc),hb,TE_getColor(TE_COLOR_PGB_TEXT));
111  //tty_puts_color("OK",TE_getColor(TE_COLOR_BTN_TEXT),TE_getColor(TE_COLOR_BTN_BODY));
112  }
113 
114  setPosX(0);
115  setPosY(0);
116 }
117 
118 void TE_IconsLoader(){
119  // If you want to place icons here, use TGA.
120 }
121 
123  // TODO: If you want to support TExplorer further, replace duke with TGA!
124 // DukeHeader_t* imdata = kmalloc(sizeof(DukeHeader_t));
125 // char* rpath = "/Sayori/Wallpaper/wallpaper.png.duke";
126 
128  // Да всё Никита, успокойся, я пофиксил.
130 
131  // TODO: If you want to support TExplorer further, replace duke with TGA!
132 // FILE* fp = fopen(rpath, "r");
133 
134 // if(!fp) {
135 // qemu_log("[TE] [DBG] Произошла ошибка при открытии файла %s\n", rpath);
136 // kfree(imdata);
137 // return;
138 // }
139 
140 // fread(fp, 1, sizeof(DukeHeader_t), imdata);
141 // fclose(fp);
142 //
143 // uint32_t w = getScreenWidth() - imdata->width;
144 // uint32_t h = getScreenHeight() - imdata->height;
145 //
146 
147  // TODO: If you want to support TExplorer further, replace duke with TGA!
148 // bool error = duke_draw_from_file(rpath, w / 2, h / 2);
149 
150 // if(error) {
151 // qemu_log("[TE] [DBG] Во время рендера картинки произошла ошибка.\n");
152 // }
153 //
154 // kfree(rpath);
155 // kfree(imdata);
156 //
157  TE_IconsLoader();
158  punch();
159 }
160 
161 void TE_Desktop(){
162  qemu_log("[TE] Desktop Draw..");
163 
165  drawRect(0, 0, getScreenWidth(), getScreenHeight(), TE_getColor(TE_COLOR_BACKGROUND));
166 
167  TE_DesktopBG();
168 
170  drawRect(0, getScreenHeight() - 24, getScreenWidth(), 24, TE_getColor(TE_COLOR_START_BODY));
171  drawRectBorder(2, getScreenHeight() - 21, 38, 18, TE_getColor(TE_COLOR_BORDER));
172 
173  setPosX(6);
174  setPosY(getScreenHeight() - 20);
175  tty_puts_color("Пуск",TE_getColor(TE_COLOR_START_TEXT),TE_getColor(TE_COLOR_START_BODY));
176 
177  TE_DrawTime();
178 
179 
180  setPosX(0);
181  setPosY(0);
182 }
183 
184 void TExplorer(){
185  qemu_log("[TE] Loader..");
186 
187  TE_Desktop();
188 
189  TE_DrawMessageBox("Заголовок", "А я точно попаду в MessageBox?", 1, getScreenWidth() / 4, getScreenHeight() / 3, 1, 0, 0);
190  TE_DrawMessageBox("Инициализация...", "Ожидание ответа NatSuki...", 2, getScreenWidth() / 4, 100, 0, 3, 10);
191 
192  setPosX(0);
193  setPosY(0);
194 
195  int zx = 0;
196  while(1){
197  if (zx == 0) TE_DrawMessageBox("[1/10] Инициализация...", "Проверка...", 2, getScreenWidth() / 4, 100, 0, 1, 10);
198  if (zx == 2) TE_DrawMessageBox("[2/10] Инициализация...", "Инициализация системы...", 2, getScreenWidth() / 4, 100, 0, 2, 10);
199  if (zx == 3) TE_DrawMessageBox("[3/10] Инициализация...", "Сбор информации...", 2, getScreenWidth() / 4, 100, 0, 3, 10);
200  if (zx == 4) TE_DrawMessageBox("[4/10] Инициализация...", "Подключение к NatSuki...", 2, getScreenWidth() / 4, 100, 0, 4, 10);
201  if (zx == 5) TE_DrawMessageBox("[5/10] Инициализация...", "Синхронизация...", 2, getScreenWidth() / 4, 100, 0, 5, 10);
202  if (zx == 6) TE_DrawMessageBox("[6/10] Инициализация...", "Загрузка темы оформления...", 2, getScreenWidth() / 4, 100, 0, 6, 10);
203  if (zx == 7) TE_DrawMessageBox("[7/10] Инициализация...", "Загрузка меню пуск...", 2, getScreenWidth() / 4, 100, 0, 7, 10);
204  if (zx == 8) TE_DrawMessageBox("[8/10] Инициализация...", "Поиск доступных программ...", 2, getScreenWidth() / 4, 100, 0, 8, 10);
205  if (zx == 9) TE_DrawMessageBox("[9/10] Инициализация...", "Активация курсора...", 2, getScreenWidth() / 4, 100, 0, 9, 10);
206  if (zx == 9) mouse_set_state(CURSOR_NORMAL);
207  if (zx == 10)TE_DrawMessageBox("[10/10] Инициализация...", "С возращением, oem!", 2, getScreenWidth() / 4, 100, 0, 10, 10);
208  if (zx == 11) break;
209  zx++;
210  punch();
211  sleep_ms(1000);
212  }
213  shellForceClose();
214 }
uint32_t mode
Режим работы (0 - Обычный | 1 - Режим логирования)
Definition: bootscreen.c:23
void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Рисуем залитый прямоугольник
Definition: pixel.c:25
void drawRectBorder(int x, int y, int w, int h, int color)
Рисует линию вокруг прямоугольника
Definition: pixel.c:66
void sleep_ms(uint32_t milliseconds)
Ожидание по миллисекундам
Definition: timer.c:68
void TE_DrawMessageBox(char *title, char *msg, int mode, int x, int y, int close, int data, int data2)
Definition: texplorer.c:68
void TE_Desktop()
Definition: texplorer.c:161
void TE_DesktopBG()
Definition: texplorer.c:122
void setPosX(uint32_t x)
Изменяем позицию курсора по X.
Definition: tty.c:154
void setPosY(uint32_t y)
Изменяем позицию курсора по Y.
Definition: tty.c:164