Rendering fix in apps

This commit is contained in:
boreddevnl
2026-02-26 21:56:50 +01:00
parent fcc290f3f9
commit 34ceff4290
57 changed files with 112 additions and 136 deletions

View File

@@ -141,19 +141,19 @@ static void flag_cell(int x, int y) {
static void minesweeper_paint(ui_window_t win) {
int win_w = 240, win_h = 340;
ui_draw_rect(win, 4, 0, win_w - 8, win_h - 34, COLOR_DARK_BG);
ui_draw_rect(win, 4, 0, win_w - 8, win_h, COLOR_DARK_BG);
if (game_over) {
ui_draw_string(win, 10, 6, "Game Over!", COLOR_TRAFFIC_RED);
ui_draw_string(win, 10, 4, "Game Over!", COLOR_TRAFFIC_RED);
} else if (game_won) {
ui_draw_string(win, 10, 6, "You Won!", 0xFF00FF00); // Bright green
ui_draw_string(win, 10, 4, "You Won!", 0xFF00FF00); // Bright green
} else {
ui_draw_string(win, 10, 6, "", COLOR_DARK_TEXT);
ui_draw_string(win, 10, 4, "", COLOR_DARK_TEXT);
}
// Draw grid
int grid_start_x = 10;
int grid_start_y = 26;
int grid_start_y = 22;
for (int y = 0; y < GRID_HEIGHT; y++) {
for (int x = 0; x < GRID_WIDTH; x++) {
@@ -191,7 +191,7 @@ static void minesweeper_paint(ui_window_t win) {
static void minesweeper_handle_click(ui_window_t win, int x, int y, int button) {
int grid_start_x = 10;
int grid_start_y = 26;
int grid_start_y = 22;
int btn_y = grid_start_y + GRID_HEIGHT * CELL_SIZE + 10;
// Check "New Game" button
@@ -211,10 +211,8 @@ static void minesweeper_handle_click(ui_window_t win, int x, int y, int button)
int cell_y = (y - grid_start_y) / CELL_SIZE;
if (button == GUI_EVENT_RIGHT_CLICK) {
debug_print("[MINESWEEPER] Flagging cell");
flag_cell(cell_x, cell_y);
} else {
debug_print("[MINESWEEPER] Revealing cell");
reveal_cell(cell_x, cell_y);
}
}
@@ -236,12 +234,10 @@ int main(int argc, char **argv) {
minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320);
} else if (ev.type == GUI_EVENT_CLICK) {
debug_print("[MINESWEEPER] LEFT CLICK");
minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type);
minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320);
} else if (ev.type == GUI_EVENT_RIGHT_CLICK) {
debug_print("[MINESWEEPER] RIGHT CLICK DETECTED");
minesweeper_handle_click(win, ev.arg1, ev.arg2, ev.type);
minesweeper_paint(win);
ui_mark_dirty(win, 0, 0, 240, 320);

Binary file not shown.

View File

@@ -13,7 +13,7 @@ static int cursor_pos = 0;
static int notepad_scroll_line = 0;
static void notepad_ensure_cursor_visible(int h) {
int visible_lines = (h - 40) / 10 + 3;
int visible_lines = (h - 10) / 10;
if (visible_lines < 1) visible_lines = 1;
int cursor_line = 0;
@@ -53,23 +53,23 @@ static void notepad_save_state() {
}
static void notepad_paint(ui_window_t win, int w, int h) {
ui_draw_rect(win, 4, 30, w - 8, h - 34, COLOR_NOTEPAD_BG);
ui_draw_rect(win, 0, 0, w, h, COLOR_NOTEPAD_BG);
int visual_line = 0;
int current_x = 8;
int current_y = 36;
int window_right = w - 16;
int current_x = 4;
int current_y = 4;
int window_right = w - 8;
for (int i = 0; i < buf_len; i++) {
if (visual_line < notepad_scroll_line) {
if (buffer[i] == '\n') {
visual_line++;
current_x = 8;
current_y = 36;
current_x = 4;
current_y = 4;
} else {
if (current_x >= window_right) {
visual_line++;
current_x = 8;
current_x = 4;
current_y += 10;
}
current_x += 8;
@@ -77,21 +77,21 @@ static void notepad_paint(ui_window_t win, int w, int h) {
continue;
}
if (visual_line >= notepad_scroll_line + (h - 40) / 10) {
if (visual_line >= notepad_scroll_line + (h - 8) / 10) {
break;
}
if (buffer[i] == '\n') {
current_x = 8;
current_x = 4;
current_y += 10;
visual_line++;
} else {
if (current_x >= window_right) {
current_x = 8;
current_x = 4;
current_y += 10;
visual_line++;
if (visual_line >= notepad_scroll_line + (h - 40) / 10) {
if (visual_line >= notepad_scroll_line + (h - 8) / 10) {
break;
}
}
@@ -103,18 +103,18 @@ static void notepad_paint(ui_window_t win, int w, int h) {
}
// Cursor
int cx = 8;
int cy = 36;
int cx = 4;
int cy = 4;
int c_visual_line = 0;
for (int i = 0; i < cursor_pos; i++) {
if (buffer[i] == '\n') {
cx = 8;
cx = 4;
cy += 10;
c_visual_line++;
} else {
if (cx >= window_right) {
cx = 8;
cx = 4;
cy += 10;
c_visual_line++;
}
@@ -123,7 +123,7 @@ static void notepad_paint(ui_window_t win, int w, int h) {
}
if (c_visual_line >= notepad_scroll_line &&
c_visual_line < notepad_scroll_line + (h - 40) / 10) {
c_visual_line < notepad_scroll_line + (h - 8) / 10) {
ui_draw_rect(win, cx, cy, 2, 8, COLOR_BLACK);
}

Binary file not shown.

View File

@@ -137,10 +137,10 @@ static uint32_t parse_rgb_separate(const char *r, const char *g, const char *b)
static void control_panel_paint_main(ui_window_t win) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
int win_w = 350;
int item_y = 15;
int item_y = 0;
int item_h = 60;
int item_spacing = 10;
@@ -180,7 +180,7 @@ static void control_panel_paint_main(ui_window_t win) {
static void control_panel_paint_wallpaper(ui_window_t win) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@@ -311,7 +311,7 @@ static void control_panel_paint_wallpaper(ui_window_t win) {
static void control_panel_paint_network(ui_window_t win) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@@ -327,7 +327,7 @@ static void control_panel_paint_network(ui_window_t win) {
static void control_panel_paint_desktop(ui_window_t win) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@@ -371,7 +371,7 @@ static void control_panel_paint_desktop(ui_window_t win) {
static void control_panel_paint_mouse(ui_window_t win) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
ui_draw_rounded_rect_filled(win, offset_x, offset_y + 5, 80, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 13, "< Back", COLOR_DARK_TEXT);
@@ -393,7 +393,7 @@ static void control_panel_paint_mouse(ui_window_t win) {
static void control_panel_paint(ui_window_t win) {
// Fill background
ui_draw_rect(win, 0, 20, 350, 480, COLOR_DARK_BG);
ui_draw_rect(win, 0, 0, 350, 500, COLOR_DARK_BG);
if (current_view == VIEW_MAIN) {
control_panel_paint_main(win);
@@ -439,11 +439,11 @@ static void control_panel_handle_click(int x, int y) {
if (current_view == VIEW_MAIN) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
int item_h = 60;
int item_spacing = 10;
int item_y = offset_y + 15;
int item_y = offset_y + 0;
if (x >= offset_x && x < win_w - 8 && y >= item_y && y < item_y + item_h) {
current_view = VIEW_WALLPAPER;
focused_field = -1;
@@ -463,7 +463,7 @@ static void control_panel_handle_click(int x, int y) {
}
} else if (current_view == VIEW_WALLPAPER) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
int button_y = offset_y + 65;
int button_x = offset_x;
@@ -541,7 +541,7 @@ static void control_panel_handle_click(int x, int y) {
}
} else if (current_view == VIEW_NETWORK) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN;
@@ -560,7 +560,7 @@ static void control_panel_handle_click(int x, int y) {
}
} else if (current_view == VIEW_DESKTOP) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN;
@@ -608,7 +608,7 @@ static void control_panel_handle_click(int x, int y) {
}
} else if (current_view == VIEW_MOUSE) {
int offset_x = 8;
int offset_y = 21;
int offset_y = 6;
if (x >= offset_x && x < offset_x + 80 && y >= offset_y + 5 && y < offset_y + 30) {
current_view = VIEW_MAIN;

Binary file not shown.

View File

@@ -52,7 +52,11 @@ static void editor_clear_all(void) {
}
static void editor_ensure_cursor_visible(void) {
int visible_lines = 22;
int header_h = 32;
int footer_h = 24;
int editor_h = win_h - header_h - footer_h;
int visible_lines = (editor_h - 10) / EDITOR_LINE_HEIGHT;
if (cursor_line < scroll_top) {
scroll_top = cursor_line;
}
@@ -196,73 +200,76 @@ static void editor_insert_char(char ch) {
}
static void editor_paint(ui_window_t win) {
int offset_x = 4;
int offset_y = 0;
int content_width = win_w - 8;
int content_height = win_h - 28;
int header_h = 32;
int footer_h = 24;
int padding = 4;
// Top content bar
ui_draw_rounded_rect_filled(win, offset_x, offset_y, content_width, 25, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, offset_y + 6, "File", COLOR_DARK_TEXT);
ui_draw_string(win, offset_x + 55, offset_y + 6, open_filename, COLOR_DARK_TEXT);
int content_width = win_w - (padding * 2);
int editor_y = header_h;
int editor_h = win_h - header_h - footer_h;
// Header bar
ui_draw_rounded_rect_filled(win, padding, 2, content_width, header_h - 4, 6, COLOR_DARK_PANEL);
ui_draw_string(win, padding + 10, 8, "File", COLOR_DARK_TEXT);
ui_draw_string(win, padding + 60, 8, open_filename, COLOR_DARK_TEXT);
// Save button
int save_btn_x = offset_x + content_width - 80;
int save_btn_y = offset_y + 3;
ui_draw_rounded_rect_filled(win, save_btn_x, save_btn_y, 70, 20, 6, COLOR_DARK_BORDER);
ui_draw_string(win, save_btn_x + 20, save_btn_y + 6, "Save", COLOR_DARK_TEXT);
int save_btn_w = 70;
int save_btn_h = 22;
int save_btn_x = padding + content_width - save_btn_w - 5;
int save_btn_y = 3;
ui_draw_rounded_rect_filled(win, save_btn_x, save_btn_y, save_btn_w, save_btn_h, 6, COLOR_DARK_BORDER);
ui_draw_string(win, save_btn_x + 18, save_btn_y + 4, "Save", COLOR_DARK_TEXT);
if (file_modified) {
ui_draw_string(win, offset_x + content_width - 200, offset_y + 5, "[Modified]", COLOR_RED);
ui_draw_string(win, padding + content_width - 180, 8, "[Modified]", COLOR_RED);
}
// Editor background
ui_draw_rect(win, 4, 54, win_w - 8, win_h - 58, COLOR_DARK_BG);
ui_draw_rect(win, padding, editor_y, content_width, editor_h, COLOR_DARK_BG);
int text_start_x = offset_x + 40;
int text_start_x = padding + 40;
int available_width = content_width - 40;
int max_chars_per_line = available_width / EDITOR_CHAR_WIDTH;
if (max_chars_per_line < 1) max_chars_per_line = 1;
int display_line = 0;
int visible_lines = (content_height - 55) / EDITOR_LINE_HEIGHT;
int visible_lines = (editor_h - 10) / EDITOR_LINE_HEIGHT;
int max_display_lines = visible_lines;
int display_line = 0;
int line_idx = scroll_top;
while (line_idx < line_count && display_line < max_display_lines) {
int display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT;
int display_y = editor_y + 5 + display_line * EDITOR_LINE_HEIGHT;
if (display_line == 0 || line_idx < line_count) {
char line_num_str[16];
int temp = line_idx + 1;
int str_len = 0;
if (temp == 0) {
line_num_str[0] = '0';
str_len = 1;
} else {
while (temp > 0) {
line_num_str[str_len++] = (temp % 10) + '0';
temp /= 10;
}
for (int j = 0; j < str_len / 2; j++) {
char t = line_num_str[j];
line_num_str[j] = line_num_str[str_len - 1 - j];
line_num_str[str_len - 1 - j] = t;
}
// Line number
char line_num_str[16];
int temp = line_idx + 1;
int str_len = 0;
if (temp == 0) {
line_num_str[0] = '0';
str_len = 1;
} else {
while (temp > 0) {
line_num_str[str_len++] = (temp % 10) + '0';
temp /= 10;
}
for (int j = 0; j < str_len / 2; j++) {
char t = line_num_str[j];
line_num_str[j] = line_num_str[str_len - 1 - j];
line_num_str[str_len - 1 - j] = t;
}
line_num_str[str_len] = 0;
ui_draw_string(win, offset_x + 4, display_y, line_num_str, COLOR_DKGRAY);
}
line_num_str[str_len] = 0;
ui_draw_string(win, padding + 4, display_y, line_num_str, COLOR_DKGRAY);
const char *text = lines[line_idx].content;
int text_len = lines[line_idx].length;
int char_idx = 0;
int local_display_line = 0;
_Bool first_pass = 1;
while ((char_idx < text_len || (text_len == 0 && first_pass)) && display_line < max_display_lines) {
first_pass = 0;
int current_display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT;
int current_display_y = editor_y + 5 + display_line * EDITOR_LINE_HEIGHT;
char segment[256];
int segment_len = 0;
@@ -273,6 +280,7 @@ static void editor_paint(ui_window_t win) {
}
segment[segment_len] = 0;
// Basic word wrap
if (char_idx < text_len && segment_len > 0) {
int last_space = -1;
for (int i = segment_len - 1; i >= 0; i--) {
@@ -285,9 +293,6 @@ static void editor_paint(ui_window_t win) {
segment_len = last_space;
segment[segment_len] = 0;
char_idx = segment_start + last_space + 1;
while (char_idx < text_len && text[char_idx] == ' ') {
char_idx++;
}
}
}
@@ -310,48 +315,38 @@ static void editor_paint(ui_window_t win) {
}
display_line++;
local_display_line++;
if (char_idx >= text_len) break;
}
line_idx++;
}
int status_y = offset_y + content_height - 20;
ui_draw_rounded_rect_filled(win, offset_x, status_y, content_width, 20, 6, COLOR_DARK_PANEL);
ui_draw_string(win, offset_x + 10, status_y + 5, "Line: ", COLOR_DARK_TEXT);
// Status bar
int status_y = win_h - footer_h;
ui_draw_rounded_rect_filled(win, padding, status_y + 2, content_width, footer_h - 4, 6, COLOR_DARK_PANEL);
char status_text[128];
// Simple manual sprintf-like functionality for BoredOS userspace
// We'll just draw parts for now as before but cleaned up
ui_draw_string(win, padding + 15, status_y + 5, "Line:", COLOR_DKGRAY);
char line_str[32];
int temp = cursor_line + 1;
int idx = 0;
while (temp > 0) {
line_str[idx++] = (temp % 10) + '0';
temp /= 10;
}
for (int j = 0; j < idx / 2; j++) {
char t = line_str[j];
line_str[j] = line_str[idx - 1 - j];
line_str[idx - 1 - j] = t;
}
while (temp > 0) { line_str[idx++] = (temp % 10) + '0'; temp /= 10; }
if (idx == 0) line_str[idx++] = '0';
for (int j = 0; j < idx / 2; j++) { char t = line_str[j]; line_str[j] = line_str[idx - 1 - j]; line_str[idx - 1 - j] = t; }
line_str[idx] = 0;
ui_draw_string(win, padding + 65, status_y + 5, line_str, COLOR_DARK_TEXT);
ui_draw_string(win, offset_x + 60, status_y + 5, line_str, COLOR_DARK_TEXT);
ui_draw_string(win, offset_x + 100, status_y + 5, " Col: ", COLOR_DARK_TEXT);
ui_draw_string(win, padding + 120, status_y + 5, "Col:", COLOR_DKGRAY);
char col_str[32];
temp = cursor_col + 1;
idx = 0;
while (temp > 0) {
col_str[idx++] = (temp % 10) + '0';
temp /= 10;
}
for (int j = 0; j < idx / 2; j++) {
char t = col_str[j];
col_str[j] = col_str[idx - 1 - j];
col_str[idx - 1 - j] = t;
}
while (temp > 0) { col_str[idx++] = (temp % 10) + '0'; temp /= 10; }
if (idx == 0) col_str[idx++] = '0';
for (int j = 0; j < idx / 2; j++) { char t = col_str[j]; col_str[j] = col_str[idx - 1 - j]; col_str[idx - 1 - j] = t; }
col_str[idx] = 0;
ui_draw_string(win, offset_x + 170, status_y + 5, col_str, COLOR_DARK_TEXT);
ui_draw_string(win, padding + 160, status_y + 5, col_str, COLOR_DARK_TEXT);
}
static void editor_handle_key(char c) {
@@ -365,8 +360,7 @@ static void editor_handle_key(char c) {
if (cursor_line < line_count - 1) {
cursor_line++;
if (cursor_col > lines[cursor_line].length) cursor_col = lines[cursor_line].length;
int visible_lines = 20;
if (cursor_line >= scroll_top + visible_lines) scroll_top = cursor_line - visible_lines + 1;
editor_ensure_cursor_visible();
}
} else if (c == 19) { // LEFT
if (cursor_col > 0) {
@@ -388,11 +382,14 @@ static void editor_handle_key(char c) {
}
static void editor_handle_click(int x, int y) {
int content_width = win_w - 8;
int button_x = 4 + content_width - 80;
int button_y = 3;
int padding = 4;
int content_width = win_w - (padding * 2);
int save_btn_w = 70;
int save_btn_x = padding + content_width - save_btn_w - 5;
int save_btn_y = 3;
int save_btn_h = 22;
if (x >= button_x && x < button_x + 70 && y >= button_y && y < button_y + 20) {
if (x >= save_btn_x && x < save_btn_x + save_btn_w && y >= save_btn_y && y < save_btn_y + save_btn_h) {
editor_save_file();
}
}
@@ -413,15 +410,15 @@ int main(int argc, char **argv) {
if (ui_get_event(win, &ev)) {
if (ev.type == GUI_EVENT_PAINT) {
editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20);
ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_CLICK) {
editor_handle_click(ev.arg1, ev.arg2);
editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20);
ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_KEY) {
editor_handle_key((char)ev.arg1);
editor_paint(win);
ui_mark_dirty(win, 0, 0, win_w, win_h - 20);
ui_mark_dirty(win, 0, 0, win_w, win_h);
} else if (ev.type == GUI_EVENT_CLOSE) {
sys_exit(0);
}

Binary file not shown.