Skip to content

Commit

Permalink
Work on explorer rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Aug 10, 2024
1 parent c94f714 commit 96f6562
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 49 deletions.
28 changes: 17 additions & 11 deletions src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,19 +63,19 @@ 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);
gfx_SetTextBGColor(WINDOW_BUTTON_BG_COLOR);
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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/data/adrive/src/fs/bin/explorer-rewrite/src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
95 changes: 62 additions & 33 deletions src/data/adrive/src/fs/bin/explorer-rewrite/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -43,7 +45,7 @@ window_t MainWindow = {
NULL,
NULL,
NULL,
&MainWindowItems,
MainWindowItems,
};


Expand Down Expand Up @@ -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);
Expand All @@ -116,47 +118,74 @@ int main(int argc, char **argv) {
th_HandleNextThread();
for (char i=0; i<KEY_SCAN_ITERATIONS; i++) {
if (kb_AnyKey()) {
key_pressed = true;
break;
}
Delay10ms();
}
kb_Scan();

if (kb_AnyKey()) {
gfx_BlitRectangle(1, cursor_x, cursor_y, cursor->width, 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;
if (cursor_speed < MAX_CURSOR_SPEED) {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/installer8xp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 96f6562

Please sign in to comment.