diff --git a/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.c b/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.c index 4199b08..0033847 100644 --- a/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.c +++ b/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.c @@ -30,13 +30,15 @@ void guiDrawWindow(window_t *window) { guiDrawStringXY(window->content, window->x + 2, window->y + (window->title != NULL ? LINE_HEIGHT + 3 : 2), window->width - 4, window->height - 4); } if (window->items) { + unsigned int i = 0; while (window->items[i]) { - guiDrawItem(window->items[i]); + guiDrawItem(window, window->items[i]); + i++; } } } -void guiDrawItem(gui_item_t *item) { +void guiDrawItem(window_t* window, gui_item_t* item) { int xx, yy; if (item->x < 0) { xx = window->x; @@ -61,7 +63,7 @@ void guiDrawItem(gui_item_t *item) { switch (item->type) { case GUI_ITEM_BUTTON: gfx_SetColor(WINDOW_BUTTON_BG_COLOR); - gfx_FillRectangle(xx, yy, item->width, item->height); + gfx_FillRectangle(xx+1, yy+1, item->width-2, item->height-2); gfx_SetColor(WINDOW_BUTTON_FG_COLOR); gfx_Rectangle(xx, yy, item->width, item->height); gfx_SetTextFGColor(WINDOW_BUTTON_TEXT_COLOR); @@ -69,11 +71,11 @@ void guiDrawItem(gui_item_t *item) { break; case GUI_ITEM_TEXTFIELD: gfx_SetColor(WINDOW_FIELD_BG_COLOR); - gfx_FillRectangle(xx, yy, item->width, item->height); + gfx_FillRectangle(xx+1, yy+1, item->width-2, item->height-2); gfx_SetColor(WINDOW_FIELD_FG_COLOR); gfx_Rectangle(xx, yy, item->width, item->height); gfx_SetTextFGColor(WINDOW_FIELD_TEXT_COLOR); - gfx_SetTextBGColor(WINDOW_BUTTON_BG_COLOR); + gfx_SetTextBGColor(WINDOW_FIELD_BG_COLOR); break; case GUI_ITEM_CHECKBOX: if (item->value != NULL && *(uint8_t*)item->value) { @@ -87,17 +89,18 @@ void guiDrawItem(gui_item_t *item) { gfx_SetTextFGColor(WINDOW_FIELD_TEXT_COLOR); gfx_SetTextBGColor(WINDOW_BUTTON_BG_COLOR); if (item->text != NULL) { - guiDrawStringXY(item->text, xx + 10, yy, item->width, item->height); + guiDrawStringXY(item->text, xx+11, yy, item->width, item->height); } return; case GUI_ITEM_TEXT: gfx_SetTextFGColor(WINDOW_TEXT_COLOR); gfx_SetTextBGColor(WINDOW_FILL_COLOR); + break; default: break; } if (item->text != NULL) { - guiDrawStringXY(item->text, xx, yy, item->width, item->height); + guiDrawStringXY(item->text, xx+2, yy+2, item->width-4, item->height-4); } } @@ -128,7 +131,7 @@ void guiDrawStringXY(const char *str, int minx, int miny, int w, int h) { } if (y >= maxy) break; - if (c == 0xA) + if (c < 0x20) continue; gfx_PrintChar(c); x += cw; @@ -140,20 +143,23 @@ void guiDrawStringXY(const char *str, int minx, int miny, int w, int h) { bool guiCursorOnWindow(window_t* window, int x, int y) { if ((unsigned)(y - window->y) < window->height) { if ((unsigned)(x - window->x) < window->width) { - + return true; } } + return false; } gui_item_t* guiGetItemAt(window_t* window, int x, int y) { - gui_item_t* item; if (window->items) { + gui_item_t* item; + unsigned int i = 0; while ((item = window->items[i])) { if ((unsigned)(y - item->y) < item->height) { if ((unsigned)(x - item->x) < item->width) { - + return item; } } + i++; } } return NULL; diff --git a/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.h b/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.h index 8442a4d..d404241 100644 --- a/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.h +++ b/src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.h @@ -37,8 +37,8 @@ typedef struct _gui_item_t { int x, y; unsigned int width, height; char *text; - bool (*lclickaction)(void *); - bool (*rclickaction)(void *); + bool (*lclickaction)(void*, void*); + bool (*rclickaction)(void*, void*); void *value; } gui_item_t; @@ -54,9 +54,8 @@ typedef struct _window_t { void guiDrawWindow(window_t* window); -void guiDrawItem(gui_item_t* item); +void guiDrawItem(window_t* window, gui_item_t* item); void guiDrawStringXY(const char* str, int minx, int miny, int w, int h); -void guiDrawItem(gui_item_t* item); gui_item_t* guiGetItemAt(window_t* window, int x, int y); #endif diff --git a/src/data/adrive/src/fs/bin/explorer-rewrite/src/main.c b/src/data/adrive/src/fs/bin/explorer-rewrite/src/main.c index 0e40785..42695cd 100644 --- a/src/data/adrive/src/fs/bin/explorer-rewrite/src/main.c +++ b/src/data/adrive/src/fs/bin/explorer-rewrite/src/main.c @@ -13,28 +13,30 @@ //uint8_t keypress_queue[6*8] = {0}; -#define KEY_SCAN_ITERATIONS 10 -#define CURSOR_SPEED_COOLDOWN 4 +#define KEY_SCAN_ITERATIONS 25 +#define CURSOR_SPEED_COOLDOWN 20 #define MAX_CURSOR_SPEED 4 void Delay10ms(void); -gui_item_t MainWindowItems[] = { - { - GUI_ITEM_TEXT, - 1, 1, 100, 10, - "Test Text", - NULL, NULL, - }, - { - GUI_ITEM_BUTTON, - 102, 1, 100, 10, - "Test Button", - NULL, NULL, - }, - { - GUI_ITEM_NONE, - }, + +gui_item_t MainWindowItem0 = { + GUI_ITEM_TEXT, + 64, 1, 100, 15, + "Test Text", + NULL, NULL, +}; +gui_item_t MainWindowItem1 = { + GUI_ITEM_BUTTON, + 1, 1, 62, 15, + "Butt", + NULL, NULL, +}; + +gui_item_t* MainWindowItems[] = { + &MainWindowItem0, + &MainWindowItem1, + NULL }; window_t MainWindow = { @@ -43,7 +45,7 @@ window_t MainWindow = { NULL, NULL, NULL, - &MainWindowItems, + MainWindowItems, }; @@ -98,7 +100,7 @@ int main(int argc, char **argv) { // uint8_t keythread; int cursor_x, cursor_y; char cursor_speed = 1, cursor_speed_cooldown = 0; - bool redraw = true; + bool redraw = true, cursor_moved = false, key_pressed = false; gfx_SetTransparentColor(248); gfx_SetTextTransparentColor(0); @@ -116,37 +118,52 @@ int main(int argc, char **argv) { th_HandleNextThread(); for (char i=0; iwidth, cursor->height); - } else if (cursor_speed > 1) { - cursor_speed--; + if (key_pressed) { + gfx_BlitRectangle(1, cursor_x, cursor_y, cursor_width, cursor_height); + key_pressed = false; } if (kb_IsDown(kb_KeyUp)) { - if (cursor_y > 0) + if (cursor_y > 0) { cursor_y -= cursor_speed; - goto cursor_moved; + } else { + cursor_y = 0; + } + cursor_moved = true; } if (kb_IsDown(kb_KeyDown)) { - if (cursor_y < LCD_HEIGHT - cursor->height) + if (cursor_y < LCD_HEIGHT - cursor_height) { cursor_y += cursor_speed; - goto cursor_moved; + } else { + cursor_y = LCD_HEIGHT - cursor_height; + } + cursor_moved = true; } if (kb_IsDown(kb_KeyLeft)) { - if (cursor_x > 0) + if (cursor_x > 0) { cursor_x -= cursor_speed; - goto cursor_moved; + } else { + cursor_x = 0; + } + cursor_moved = true; } if (kb_IsDown(kb_KeyRight)) { - if (cursor_x < LCD_WIDTH - cursor->width) + if (cursor_x < LCD_WIDTH - cursor_width) { cursor_x += cursor_speed; - cursor_moved:; + } else { + cursor_x = LCD_WIDTH - cursor_width; + } + cursor_moved = true; + } + + if (cursor_moved) { cursor_speed_cooldown++; if (cursor_speed_cooldown >= CURSOR_SPEED_COOLDOWN) { cursor_speed_cooldown = 0; @@ -154,9 +171,21 @@ int main(int argc, char **argv) { cursor_speed++; } } + cursor_moved = false; + } else if (cursor_speed > 1) { + cursor_speed--; } + if (kb_IsDown(kb_KeyEnter) || kb_IsDown(kb_Key2nd)) { - + gui_item_t* item = guiGetItemAt(&MainWindow, cursor_x, cursor_y); + if (item && item->lclickaction) { + item->lclickaction((void*)&MainWindow, (void*)item); + } + } else if (kb_IsDown(kb_KeyAlpha)) { + gui_item_t* item = guiGetItemAt(&MainWindow, cursor_x, cursor_y); + if (item && item->rclickaction) { + item->rclickaction((void*)&MainWindow, (void*)item); + } } } while (!kb_IsDown(kb_KeyClear)); // th_KillThread(keythread); diff --git a/src/installer8xp.asm b/src/installer8xp.asm index 6f950d8..1436dfd 100644 --- a/src/installer8xp.asm +++ b/src/installer8xp.asm @@ -97,7 +97,7 @@ backup_tios_query: missing_secondary_str: db "Missing AppVar BOSOSpt2",0 backingup_os_string: - db "Backing up TIOS &",0 + db "Backing up TIOS...",0 failed_to_backup_os_string: db "OS too large to backup",0 continue_anyways_string: