mirror of
https://github.com/Alvin-Zilverstand/bob16.git
synced 2026-11-25 21:43:00 +01:00
;l
This commit is contained in:
1 parent
6dc841f956
commit
3d06f94e48
46 files changed
+5830
-543
No files matched your search
@@ -0,0 +1,48 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
static char file_buffer[BOB64_SYSCALL_MAX_BUFFER];
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
if(!text)return 0;
|
||||
while(text[length])length++;
|
||||
return length;
|
||||
}
|
||||
|
||||
static void write_text(const char *text) {
|
||||
(void)bob64_app_write(text,text_length(text));
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
const char *name;
|
||||
usize name_length;
|
||||
s64 handle,result=0;
|
||||
u8 last_character=0;
|
||||
int read_any=0;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if(startup->ArgumentCount!=2||!startup->Arguments||
|
||||
!(name=startup->Arguments[1])||!(name_length=text_length(name))) {
|
||||
write_text("usage: cat FILE\n");
|
||||
return 1;
|
||||
}
|
||||
handle=bob64_app_file_open(name,name_length,BOB64_FILE_OPEN_READ);
|
||||
if(handle<0) {
|
||||
write_text("cannot read file\n");
|
||||
return -2;
|
||||
}
|
||||
for(;;) {
|
||||
s64 count=bob64_app_file_read(handle,file_buffer,sizeof(file_buffer));
|
||||
if(count<0) {result=-3;break;}
|
||||
if(!count)break;
|
||||
if(bob64_app_write(file_buffer,(usize)count)!=count) {
|
||||
result=-4;break;
|
||||
}
|
||||
last_character=(u8)file_buffer[(usize)count-1];
|
||||
read_any=1;
|
||||
}
|
||||
if(bob64_app_file_close(handle)&&!result)result=-5;
|
||||
if(!result&&read_any&&last_character!='\n'&&
|
||||
bob64_app_write_char('\n')<0)result=-6;
|
||||
return result;
|
||||
}
|
||||
+97
-3
@@ -1,4 +1,98 @@
|
||||
int main(void) {
|
||||
bob64_app_write("bob!", 4);
|
||||
return 0;
|
||||
typedef int count_t;
|
||||
typedef char byte_t;
|
||||
typedef int *int_ptr;
|
||||
|
||||
int sum_values(int values[], int count) {
|
||||
count_t sum = 0;
|
||||
for (int i = 0; i < count; i = i + 1)
|
||||
sum = sum + values[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
count_t text_length(byte_t text[]) {
|
||||
count_t length = 0;
|
||||
while (text[length] != '\0')
|
||||
length = length + 1;
|
||||
return length;
|
||||
}
|
||||
|
||||
int_ptr first_value(int_ptr values) {
|
||||
return values;
|
||||
}
|
||||
|
||||
usize wide_division(usize value) {
|
||||
return value / 10 + value % 10;
|
||||
}
|
||||
|
||||
int sum_sixteen(int a, int b, int c, int d, int e, int f, int g, int h,
|
||||
int i, int j, int k, int l, int m, int n, int o, int p) {
|
||||
return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p;
|
||||
}
|
||||
|
||||
int stack_argument_test(void) {
|
||||
return sum_sixteen(1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
count_t values[64];
|
||||
byte_t message[5] = "bob!";
|
||||
int_ptr value_pointer = first_value(values);
|
||||
int v0 = 0;
|
||||
int v1 = 1;
|
||||
int v2 = 2;
|
||||
int v3 = 3;
|
||||
int v4 = 4;
|
||||
int v5 = 5;
|
||||
int v6 = 6;
|
||||
int v7 = 7;
|
||||
int v8 = 8;
|
||||
int v9 = 9;
|
||||
int v10 = 10;
|
||||
int v11 = 11;
|
||||
int v12 = 12;
|
||||
int v13 = 13;
|
||||
int v14 = 14;
|
||||
int v15 = 15;
|
||||
int v16 = 16;
|
||||
int v17 = 17;
|
||||
int v18 = 18;
|
||||
int v19 = 19;
|
||||
int v20 = 20;
|
||||
int v21 = 21;
|
||||
int v22 = 22;
|
||||
int v23 = 23;
|
||||
int v24 = 24;
|
||||
int v25 = 25;
|
||||
int v26 = 26;
|
||||
int v27 = 27;
|
||||
int v28 = 28;
|
||||
int v29 = 29;
|
||||
int v30 = 30;
|
||||
int v31 = 31;
|
||||
int v32 = 32;
|
||||
int v33 = 33;
|
||||
int v34 = 34;
|
||||
int v35 = 35;
|
||||
int v36 = 36;
|
||||
int v37 = 37;
|
||||
int v38 = 38;
|
||||
int v39 = 39;
|
||||
values[0] = 12;
|
||||
values[1] = 13;
|
||||
values[2] = 17;
|
||||
values[63] = 42;
|
||||
if (sum_values(values, 3) == 42 && text_length(message) == 4 &&
|
||||
stack_argument_test() == 136 && values[63] == 42 &&
|
||||
value_pointer[63] == 42 && v0 + v39 == 39 &&
|
||||
20 / 3 == 6 && 20 % 3 == 2 &&
|
||||
-20 / 3 == -6 && -20 % 3 == -2 &&
|
||||
wide_division(0x100000001ULL) == 429496736 &&
|
||||
(0x100000001ULL >> 32) == 1 &&
|
||||
((0x5a ^ 0x3c) & 0xff) == 0x66 &&
|
||||
(1 | 2 ^ 3 & 1) == 3 && (-8 >> 2) == -2) {
|
||||
bob64_app_write(message, text_length(message));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
+64
-17
@@ -1,28 +1,75 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
|
||||
#define DISPLAY_LIMIT_WIDTH 1024u
|
||||
#define DISPLAY_LIMIT_HEIGHT 768u
|
||||
#define DEMO_WIDTH 640u
|
||||
#define DEMO_HEIGHT 400u
|
||||
|
||||
static u32 pixels[DISPLAY_LIMIT_WIDTH*DISPLAY_LIMIT_HEIGHT];
|
||||
static u32 pixels[DEMO_WIDTH*DEMO_HEIGHT];
|
||||
|
||||
static void draw_demo(BOB64_GFX *graphics) {
|
||||
u32 width=graphics->Width,height=graphics->Height;
|
||||
s32 margin=(s32)(width/40u);
|
||||
s32 header_height=(s32)(height/7u);
|
||||
s32 panel_y=(s32)(height/3u);
|
||||
u32 panel_width=(width-(u32)(margin*5))/4u;
|
||||
u32 panel_height=height/4u;
|
||||
bob64_gfx_fill_rect(graphics,0,0,width,height,0x101a2au);
|
||||
bob64_gfx_fill_rect(graphics,margin,margin,width-(u32)(margin*2),
|
||||
height-(u32)(margin*2),0x1b2b40u);
|
||||
bob64_gfx_fill_rect(graphics,margin,margin,width-(u32)(margin*2),
|
||||
(u32)header_height,0x345d89u);
|
||||
bob64_gfx_text(graphics,margin*2,margin*2,"BOB32 GRAPHICS DEMO",
|
||||
0x00ffffffu,3);
|
||||
bob64_gfx_line(graphics,margin,header_height+margin*2,
|
||||
(s32)width-margin,header_height+margin*2,0x00f0c879u);
|
||||
bob64_gfx_text(graphics,margin*2,panel_y-margin*2,
|
||||
"LINES RECTANGLES AND COLORS",0x00d7e5f5u,2);
|
||||
const u32 colors[]={0x00e85d75u,0x00edaa42u,0x004fc3a1u,0x005e8ee8u};
|
||||
for(u32 i=0;i<4;i++) {
|
||||
s32 x=margin+(s32)(i*(panel_width+(u32)margin));
|
||||
s32 y=panel_y;
|
||||
bob64_gfx_fill_rect(graphics,x,y,panel_width,panel_height,colors[i]);
|
||||
bob64_gfx_fill_rect(graphics,x+8,y+8,panel_width-16,
|
||||
panel_height-16,0x00223248u);
|
||||
bob64_gfx_line(graphics,x+14,y+panel_height-18,
|
||||
x+(s32)panel_width-14,y+18,colors[i]);
|
||||
bob64_gfx_line(graphics,x+14,y+18,
|
||||
x+(s32)panel_width-14,y+panel_height-18,colors[i]);
|
||||
}
|
||||
bob64_gfx_fill_rect(graphics,margin,panel_y+(s32)panel_height+margin,
|
||||
width-(u32)(margin*2),3,0x006d849fu);
|
||||
bob64_gfx_text(graphics,margin*2,
|
||||
(s32)height-margin*6,"PRESS X OR ESCAPE TO RETURN",0x00ffffffu,2);
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
u32 width,height;
|
||||
BOB64_GFX graphics;
|
||||
BOB64_EVENT event;
|
||||
u32 screen_width,screen_height;
|
||||
u64 window=0;
|
||||
s64 result=-1;
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION||
|
||||
bob64_app_get_display(&width,&height))return -1;
|
||||
if(!width||!height||width>DISPLAY_LIMIT_WIDTH||height>DISPLAY_LIMIT_HEIGHT)
|
||||
return -2;
|
||||
for(u32 y=0;y<height;y++)for(u32 x=0;x<width;x++) {
|
||||
u32 red=(x*180u)/width;
|
||||
u32 green=(y*120u)/height;
|
||||
pixels[(usize)y*width+x]=(red<<16)|(green<<8)|32u;
|
||||
}
|
||||
if(bob64_app_present(pixels,width,height)!=(s64)((u64)width*height))return -3;
|
||||
if(bob64_app_write("bob!",4)!=4)return -4;
|
||||
bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<DEMO_WIDTH||screen_height<DEMO_HEIGHT)return -1;
|
||||
graphics.Pixels=pixels;graphics.Width=DEMO_WIDTH;graphics.Height=DEMO_HEIGHT;
|
||||
graphics.Capacity=DEMO_WIDTH*DEMO_HEIGHT;
|
||||
draw_demo(&graphics);
|
||||
window=bob64_app_window_create((s32)((screen_width-DEMO_WIDTH)/2u),
|
||||
(s32)((screen_height-DEMO_HEIGHT)/2u),DEMO_WIDTH,DEMO_HEIGHT);
|
||||
if(!window||(s64)window<0)return -2;
|
||||
if(bob64_app_window_focus(window)) {result=-3;goto cleanup;}
|
||||
result=bob64_app_window_present(window,pixels,DEMO_WIDTH,DEMO_HEIGHT);
|
||||
if(result!=(s64)(DEMO_WIDTH*DEMO_HEIGHT))goto cleanup;
|
||||
if(bob64_app_write("bob!",4)!=4) {result=-4;goto cleanup;}
|
||||
for(;;) {
|
||||
if(bob64_app_wait_event(&event))return -5;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b)break;
|
||||
if(bob64_app_wait_event(&event)) {result=-5;break;}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&
|
||||
(event.Character=='x'||event.Character=='X'||event.Character==0x1b)) {
|
||||
result=0;break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
cleanup:
|
||||
if(bob64_app_window_destroy(window)&&result==0)result=-6;
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
if(!text)return 0;
|
||||
while(text[length])length++;
|
||||
return length;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
(startup->ArgumentCount&&!startup->Arguments))return -1;
|
||||
for(u64 i=1;i<startup->ArgumentCount;i++) {
|
||||
const char *argument=startup->Arguments[i];
|
||||
if(i>1&&bob64_app_write_char(' ')<0)return -2;
|
||||
if(!argument||bob64_app_write(argument,text_length(argument))<0)return -3;
|
||||
}
|
||||
if(bob64_app_write_char('\n')<0)return -4;
|
||||
return 0;
|
||||
}
|
||||
+572
-50
@@ -1,13 +1,17 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/editor.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
#include "../bob64/window.h"
|
||||
|
||||
#define BOB64_GUI_MAX_WIDTH 1280u
|
||||
#define BOB64_GUI_MAX_HEIGHT 800u
|
||||
#define BOB64_GUI_MAX_WINDOWS 4u
|
||||
#define BOB64_GUI_FILENAME_CAPACITY 64u
|
||||
#define BOB64_GUI_SURFACE_PIXEL_CAPACITY 1048576u
|
||||
#define BOB64_GUI_PREVIEW_CAPACITY 384u
|
||||
#define BOB64_GUI_PREVIEW_COLUMNS 64u
|
||||
#define BOB64_GUI_PREVIEW_ROWS 8u
|
||||
#define BOB64_GUI_SURFACE_PIXEL_CAPACITY 1114112u
|
||||
|
||||
static u32 pixels[BOB64_GUI_SURFACE_PIXEL_CAPACITY];
|
||||
static BOB64_GFX graphics[BOB64_GUI_MAX_WINDOWS];
|
||||
@@ -17,17 +21,47 @@ static BOB64_WINDOW windows[BOB64_GUI_MAX_WINDOWS];
|
||||
static BOB64_WINDOW_HANDLE order[BOB64_GUI_MAX_WINDOWS];
|
||||
static char titles[BOB64_GUI_MAX_WINDOWS][16]={"Files","Editor","Window 3","Window 4"};
|
||||
static char filename[BOB64_GUI_FILENAME_CAPACITY];
|
||||
static char file_preview[BOB64_GUI_PREVIEW_CAPACITY];
|
||||
static char file_preview_status[28];
|
||||
static usize file_preview_length;
|
||||
static int file_preview_truncated;
|
||||
static char editor_status[32];
|
||||
static char gui_file_buffer[BOB64_EDITOR_CAPACITY+1];
|
||||
static const char applications_title[]="Applications";
|
||||
static const char delete_title[]="Delete file?";
|
||||
static const char help_title[]="Desktop help";
|
||||
static BOB64_EDITOR editor;
|
||||
static BOB64_WINDOW_HANDLE editor_window;
|
||||
static BOB64_WINDOW_HANDLE files_window;
|
||||
static BOB64_WINDOW_HANDLE applications_window;
|
||||
static BOB64_WINDOW_HANDLE delete_window;
|
||||
static BOB64_WINDOW_HANDLE help_window;
|
||||
static u32 screen_width,screen_height;
|
||||
static BOB64_FILE_INFO file_entries[BOB64_SYSCALL_MAX_FILES];
|
||||
static const BOB64_RECT file_run_button={8,38,68,16};
|
||||
static const BOB64_RECT file_apps_button={82,38,64,16};
|
||||
static const BOB64_RECT file_delete_button={152,38,76,16};
|
||||
static const BOB64_RECT file_help_button={234,38,64,16};
|
||||
static const BOB64_RECT delete_yes_button={20,82,88,18};
|
||||
static const BOB64_RECT delete_cancel_button={120,82,88,18};
|
||||
static const BOB64_RECT help_close_button={156,132,68,18};
|
||||
static const BOB64_RECT applications_run_button={8,38,68,16};
|
||||
static const BOB64_RECT applications_close_button={82,38,64,16};
|
||||
static BOB64_BUTTON_STATE file_run_state,file_apps_state;
|
||||
static BOB64_BUTTON_STATE file_delete_state;
|
||||
static BOB64_BUTTON_STATE file_help_state;
|
||||
static BOB64_BUTTON_STATE applications_run_state,applications_close_state;
|
||||
static BOB64_BUTTON_STATE delete_yes_state,delete_cancel_state;
|
||||
static BOB64_BUTTON_STATE help_close_state;
|
||||
static BOB64_TEXT_FIELD filename_field;
|
||||
static u32 file_count,selected_file,file_scroll;
|
||||
static u32 selected_application,application_scroll;
|
||||
static int editor_save_allowed;
|
||||
static int editor_exit_armed;
|
||||
static int editor_open_armed;
|
||||
static int file_delete_armed;
|
||||
static char delete_filename[BOB64_GUI_FILENAME_CAPACITY];
|
||||
|
||||
static void gui_refresh_files(void);
|
||||
|
||||
static usize gui_length(const char *text,usize limit) {
|
||||
usize length=0;
|
||||
@@ -41,6 +75,12 @@ static void gui_copy(char *destination,const char *source,usize length) {
|
||||
destination[length]=0;
|
||||
}
|
||||
|
||||
static BOB64_RECT gui_filename_rect(void) {
|
||||
BOB64_WINDOW *window=bob64_wm_find(&manager,editor_window);
|
||||
BOB64_RECT rect={40,28,window&&window->Width>48?window->Width-48:12,16};
|
||||
return rect;
|
||||
}
|
||||
|
||||
static BOB64_GFX *gui_graphics_for_handle(BOB64_WINDOW_HANDLE handle) {
|
||||
for(u32 i=0;i<BOB64_GUI_MAX_WINDOWS;i++)
|
||||
if(windows[i].Handle==handle)return &graphics[i];
|
||||
@@ -114,6 +154,8 @@ static int gui_destroy_window(BOB64_WINDOW_HANDLE handle) {
|
||||
if(bob64_app_window_destroy(handle))return -1;
|
||||
if(bob64_wm_destroy(&manager,handle))return -1;
|
||||
gui_surface_release(slot);
|
||||
if(handle==applications_window)applications_window=0;
|
||||
if(handle==help_window)help_window=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -122,6 +164,138 @@ static void gui_focus_window(BOB64_WINDOW_HANDLE handle) {
|
||||
gui_copy(editor_status,"FOCUS FAILED",sizeof("FOCUS FAILED"));
|
||||
}
|
||||
|
||||
static int gui_is_application(const char *name) {
|
||||
usize length=gui_length(name,BOB64_GUI_FILENAME_CAPACITY);
|
||||
return length>5&&name[length-5]=='.'&&name[length-4]=='b'&&
|
||||
name[length-3]=='6'&&name[length-2]=='4'&&name[length-1]=='e';
|
||||
}
|
||||
|
||||
static int gui_filename_valid(void) {
|
||||
if(!filename_field.Length||filename_field.Length>=BOB64_GUI_FILENAME_CAPACITY||
|
||||
gui_is_application(filename))return 0;
|
||||
for(usize i=0;i<filename_field.Length;i++) {
|
||||
char value=filename[i];
|
||||
if(!((value>='a'&&value<='z')||(value>='A'&&value<='Z')||
|
||||
(value>='0'&&value<='9')||value=='.'||value=='_'||value=='-'))return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static u32 gui_application_count(void) {
|
||||
u32 count=0;
|
||||
for(u32 i=0;i<file_count;i++)if(gui_is_application(file_entries[i].Name))count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
static int gui_application_file(u32 application,u32 *file_index) {
|
||||
u32 found=0;
|
||||
if(!file_index)return -1;
|
||||
for(u32 i=0;i<file_count;i++)if(gui_is_application(file_entries[i].Name)) {
|
||||
if(found++==application){*file_index=i;return 0;}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void gui_open_applications(void) {
|
||||
if(applications_window&&bob64_wm_find(&manager,applications_window)) {
|
||||
gui_focus_window(applications_window);return;
|
||||
}
|
||||
if(manager.Count>=BOB64_GUI_MAX_WINDOWS) {
|
||||
gui_copy(editor_status,"NO WINDOW SPACE",sizeof("NO WINDOW SPACE"));return;
|
||||
}
|
||||
applications_window=gui_create_window((s32)(screen_width-316),32,300,260,
|
||||
applications_title);
|
||||
if(!applications_window) {
|
||||
gui_copy(editor_status,"LAUNCHER OPEN FAILED",
|
||||
sizeof("LAUNCHER OPEN FAILED"));return;
|
||||
}
|
||||
selected_application=0;application_scroll=0;
|
||||
gui_refresh_files();
|
||||
}
|
||||
|
||||
static void gui_open_help(void) {
|
||||
if(help_window&&bob64_wm_find(&manager,help_window)) {
|
||||
gui_focus_window(help_window);return;
|
||||
}
|
||||
if(manager.Count>=BOB64_GUI_MAX_WINDOWS) {
|
||||
gui_copy(editor_status,"NO WINDOW SPACE",sizeof("NO WINDOW SPACE"));return;
|
||||
}
|
||||
help_window=gui_create_window((s32)(screen_width/2)-120,
|
||||
(s32)(screen_height/2)-82,240,164,help_title);
|
||||
if(!help_window) {
|
||||
gui_copy(editor_status,"HELP WINDOW FAILED",
|
||||
sizeof("HELP WINDOW FAILED"));return;
|
||||
}
|
||||
gui_focus_window(help_window);
|
||||
}
|
||||
|
||||
static void gui_reveal_selected_application(void) {
|
||||
BOB64_WINDOW *window=bob64_wm_find(&manager,applications_window);
|
||||
u32 rows=window&&window->Height>84?(window->Height-84)/14:1;
|
||||
if(!rows)rows=1;
|
||||
if(selected_application<application_scroll)
|
||||
application_scroll=selected_application;
|
||||
else if(selected_application>=application_scroll+rows)
|
||||
application_scroll=selected_application-rows+1;
|
||||
}
|
||||
|
||||
static void gui_refresh_file_preview(void) {
|
||||
s64 result;
|
||||
file_preview_length=0;file_preview_truncated=0;
|
||||
if(selected_file>=file_count) {
|
||||
gui_copy(file_preview_status,"SELECT A FILE",
|
||||
sizeof("SELECT A FILE"));return;
|
||||
}
|
||||
if(gui_is_application(file_entries[selected_file].Name)) {
|
||||
gui_copy(file_preview_status,"APP - PRESS A TO RUN",
|
||||
sizeof("APP - PRESS A TO RUN"));return;
|
||||
}
|
||||
result=bob64_app_file_read_all(file_entries[selected_file].Name,
|
||||
gui_length(file_entries[selected_file].Name,
|
||||
BOB64_GUI_FILENAME_CAPACITY),file_preview,
|
||||
sizeof(file_preview));
|
||||
if(result==-28) {
|
||||
file_preview_length=sizeof(file_preview);file_preview_truncated=1;
|
||||
} else if(result<0) {
|
||||
gui_copy(file_preview_status,"PREVIEW UNAVAILABLE",
|
||||
sizeof("PREVIEW UNAVAILABLE"));return;
|
||||
} else file_preview_length=(usize)result;
|
||||
if(bob64_editor_is_binary_text(file_preview,file_preview_length)) {
|
||||
file_preview_length=0;
|
||||
gui_copy(file_preview_status,"BINARY FILE",
|
||||
sizeof("BINARY FILE"));return;
|
||||
}
|
||||
gui_copy(file_preview_status,file_preview_length?"TEXT FILE":"EMPTY FILE",
|
||||
file_preview_length?sizeof("TEXT FILE"):sizeof("EMPTY FILE"));
|
||||
}
|
||||
|
||||
static void gui_draw_file_preview(BOB64_GFX *graphics,
|
||||
const BOB64_WINDOW *window) {
|
||||
usize position=0;
|
||||
s32 y=window->Y+(s32)window->Height-124;
|
||||
if(!file_preview_length) {
|
||||
bob64_gfx_text(graphics,window->X+10,y,file_preview_status,
|
||||
0x009eb3c7u,1);return;
|
||||
}
|
||||
for(u32 row=0;row<BOB64_GUI_PREVIEW_ROWS&&position<file_preview_length;
|
||||
row++) {
|
||||
char line[BOB64_GUI_PREVIEW_COLUMNS+1];
|
||||
u32 column=0;
|
||||
while(position<file_preview_length&&column<BOB64_GUI_PREVIEW_COLUMNS) {
|
||||
char value=file_preview[position++];
|
||||
if(value=='\n')break;
|
||||
if(value=='\r')continue;
|
||||
line[column++]=value=='\t'?' ':value;
|
||||
}
|
||||
line[column]=0;
|
||||
bob64_gfx_text(graphics,window->X+10,y+(s32)(row*10),line,
|
||||
0x00dbe8f4u,1);
|
||||
}
|
||||
if(file_preview_truncated||position<file_preview_length)
|
||||
bob64_gfx_text(graphics,window->X+10,
|
||||
window->Y+(s32)window->Height-34,"...",0x009eb3c7u,1);
|
||||
}
|
||||
|
||||
static int gui_load_file(const BOB64_APP_STARTUP *startup) {
|
||||
const char *requested="notes.txt";
|
||||
usize length=sizeof("notes.txt")-1;
|
||||
@@ -137,7 +311,15 @@ static int gui_load_file(const BOB64_APP_STARTUP *startup) {
|
||||
(value>='0'&&value<='9')||value=='.'||value=='_'||value=='-'))return -1;
|
||||
}
|
||||
gui_copy(filename,requested,length);
|
||||
result=bob64_app_read_file(filename,length,editor.Text,BOB64_EDITOR_CAPACITY);
|
||||
if(bob64_text_field_init(&filename_field,filename,sizeof(filename)))return -1;
|
||||
if(gui_is_application(filename)) {
|
||||
bob64_editor_init(&editor,0,0);
|
||||
gui_copy(editor_status,"USE RUN APP",sizeof("USE RUN APP"));
|
||||
editor_save_allowed=0;
|
||||
return 0;
|
||||
}
|
||||
result=bob64_app_file_read_all(filename,length,gui_file_buffer,
|
||||
BOB64_EDITOR_CAPACITY);
|
||||
if(result==-2) {
|
||||
bob64_editor_init(&editor,0,0);
|
||||
gui_copy(editor_status,"NEW FILE",sizeof("NEW FILE"));
|
||||
@@ -149,9 +331,15 @@ static int gui_load_file(const BOB64_APP_STARTUP *startup) {
|
||||
} else if(result<0) {
|
||||
return -1;
|
||||
} else {
|
||||
bob64_editor_init(&editor,editor.Text,(u32)result);
|
||||
gui_copy(editor_status,"LOADED",sizeof("LOADED"));
|
||||
editor_save_allowed=1;
|
||||
if(bob64_editor_is_binary_text(gui_file_buffer,(usize)result)) {
|
||||
bob64_editor_init(&editor,0,0);
|
||||
gui_copy(editor_status,"BINARY FILE",sizeof("BINARY FILE"));
|
||||
editor_save_allowed=0;
|
||||
} else {
|
||||
bob64_editor_init(&editor,gui_file_buffer,(u32)result);
|
||||
gui_copy(editor_status,"LOADED",sizeof("LOADED"));
|
||||
editor_save_allowed=1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -162,21 +350,37 @@ static void gui_refresh_files(void) {
|
||||
file_count=0;
|
||||
gui_copy(editor_status,result==-28?"TOO MANY FILES":"LIST FAILED",
|
||||
result==-28?sizeof("TOO MANY FILES"):sizeof("LIST FAILED"));
|
||||
gui_refresh_file_preview();
|
||||
return;
|
||||
}
|
||||
file_count=(u32)result;
|
||||
if(selected_file>=file_count)selected_file=file_count?file_count-1:0;
|
||||
if(file_scroll>=file_count)file_scroll=file_count?file_count-1:0;
|
||||
gui_refresh_file_preview();
|
||||
}
|
||||
|
||||
static void gui_reveal_selected_file(void) {
|
||||
BOB64_WINDOW *window=bob64_wm_find(&manager,files_window);
|
||||
u32 rows=window&&window->Height>58?(window->Height-58)/14:1;
|
||||
u32 rows=window&&window->Height>70?(window->Height-70)/14:1;
|
||||
if(!rows)rows=1;
|
||||
if(selected_file<file_scroll)file_scroll=selected_file;
|
||||
else if(selected_file>=file_scroll+rows)file_scroll=selected_file-rows+1;
|
||||
}
|
||||
|
||||
static void gui_scroll_file_selection(s32 wheel) {
|
||||
if(wheel>0&&selected_file)selected_file--;
|
||||
else if(wheel<0&&selected_file+1<file_count)selected_file++;
|
||||
gui_reveal_selected_file();
|
||||
gui_refresh_file_preview();
|
||||
}
|
||||
|
||||
static void gui_scroll_application_selection(s32 wheel) {
|
||||
if(wheel>0&&selected_application)selected_application--;
|
||||
else if(wheel<0&&selected_application+1<gui_application_count())
|
||||
selected_application++;
|
||||
gui_reveal_selected_application();
|
||||
}
|
||||
|
||||
static int gui_name_equal(const char *left,const char *right) {
|
||||
while(*left&&*right&&*left==*right){left++;right++;}
|
||||
return !*left&&!*right;
|
||||
@@ -188,7 +392,11 @@ static void gui_open_selected_file(void) {
|
||||
gui_copy(editor_status,"NO FILE SELECTED",sizeof("NO FILE SELECTED"));return;
|
||||
}
|
||||
const char *name=file_entries[selected_file].Name;
|
||||
if(editor.Dirty&&!editor_open_armed) {
|
||||
if(gui_is_application(name)) {
|
||||
gui_copy(editor_status,"USE RUN APP",sizeof("USE RUN APP"));
|
||||
editor_open_armed=0;return;
|
||||
}
|
||||
if((editor.Dirty||filename_field.Dirty)&&!editor_open_armed) {
|
||||
gui_copy(editor_status,"OPEN AGAIN TO DISCARD",sizeof("OPEN AGAIN TO DISCARD"));
|
||||
editor_open_armed=1;return;
|
||||
}
|
||||
@@ -197,43 +405,122 @@ static void gui_open_selected_file(void) {
|
||||
gui_copy(editor_status,"CURRENT FILE",sizeof("CURRENT FILE"));
|
||||
editor_open_armed=0;return;
|
||||
}
|
||||
result=bob64_app_read_file(name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY),
|
||||
editor.Text,BOB64_EDITOR_CAPACITY);
|
||||
result=bob64_app_file_read_all(name,
|
||||
gui_length(name,BOB64_GUI_FILENAME_CAPACITY),gui_file_buffer,
|
||||
BOB64_EDITOR_CAPACITY);
|
||||
if(result==-28) {
|
||||
gui_copy(editor_status,"FILE TOO LARGE",sizeof("FILE TOO LARGE"));
|
||||
editor_save_allowed=0;return;
|
||||
editor_open_armed=0;return;
|
||||
}
|
||||
if(result<0) {
|
||||
gui_copy(editor_status,"OPEN FAILED",sizeof("OPEN FAILED"));return;
|
||||
}
|
||||
if(bob64_editor_is_binary_text(gui_file_buffer,(usize)result)) {
|
||||
gui_copy(editor_status,"BINARY FILE",sizeof("BINARY FILE"));
|
||||
editor_open_armed=0;return;
|
||||
}
|
||||
gui_copy(filename,name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY));
|
||||
bob64_editor_init(&editor,editor.Text,(u32)result);
|
||||
bob64_text_field_sync(&filename_field);
|
||||
bob64_editor_init(&editor,gui_file_buffer,(u32)result);
|
||||
editor_save_allowed=1;editor_open_armed=0;
|
||||
gui_copy(editor_status,"LOADED",sizeof("LOADED"));
|
||||
gui_focus_window(editor_window);
|
||||
}
|
||||
|
||||
static void gui_delete_selected_file(void) {
|
||||
const char *name;
|
||||
s64 result;
|
||||
BOB64_WINDOW_HANDLE handle;
|
||||
if(selected_file>=file_count) {
|
||||
gui_copy(editor_status,"NO FILE SELECTED",sizeof("NO FILE SELECTED"));return;
|
||||
}
|
||||
name=file_entries[selected_file].Name;
|
||||
if(gui_name_equal(name,filename)) {
|
||||
file_delete_armed=0;
|
||||
if(gui_name_equal(file_entries[selected_file].Name,filename)) {
|
||||
gui_copy(editor_status,"SAVE OR OPEN OTHER FILE",sizeof("SAVE OR OPEN OTHER FILE"));
|
||||
return;
|
||||
}
|
||||
if(!file_delete_armed) {
|
||||
file_delete_armed=1;
|
||||
gui_copy(editor_status,"D AGAIN TO DELETE",sizeof("D AGAIN TO DELETE"));
|
||||
if(delete_window&&bob64_wm_find(&manager,delete_window)) {
|
||||
gui_focus_window(delete_window);return;
|
||||
}
|
||||
gui_copy(delete_filename,file_entries[selected_file].Name,
|
||||
gui_length(file_entries[selected_file].Name,
|
||||
BOB64_GUI_FILENAME_CAPACITY));
|
||||
handle=gui_create_window((s32)(screen_width/2)-120,
|
||||
(s32)(screen_height/2)-60,240,124,delete_title);
|
||||
if(!handle) {
|
||||
delete_filename[0]=0;
|
||||
gui_copy(editor_status,"DELETE DIALOG FAILED",
|
||||
sizeof("DELETE DIALOG FAILED"));return;
|
||||
}
|
||||
delete_window=handle;
|
||||
gui_focus_window(delete_window);
|
||||
}
|
||||
|
||||
static void gui_finish_delete(int confirm) {
|
||||
if(!delete_window)return;
|
||||
if(confirm) {
|
||||
s64 result=bob64_app_delete_file(delete_filename,
|
||||
gui_length(delete_filename,BOB64_GUI_FILENAME_CAPACITY));
|
||||
if(result)gui_copy(editor_status,"DELETE FAILED",sizeof("DELETE FAILED"));
|
||||
else {gui_refresh_files();gui_copy(editor_status,"DELETED",sizeof("DELETED"));}
|
||||
} else gui_copy(editor_status,"DELETE CANCELLED",sizeof("DELETE CANCELLED"));
|
||||
gui_destroy_window(delete_window);
|
||||
delete_window=0;delete_filename[0]=0;
|
||||
delete_yes_state.Pressed=delete_cancel_state.Pressed=0;
|
||||
}
|
||||
|
||||
static void gui_set_app_exit_status(s64 status) {
|
||||
char digits[20];
|
||||
u64 magnitude;
|
||||
usize length=0,offset=0;
|
||||
if(status<0) {
|
||||
gui_copy(editor_status,"APP EXIT -",10);offset=10;
|
||||
magnitude=(u64)(-(status+1))+1;
|
||||
} else {
|
||||
gui_copy(editor_status,"APP EXIT ",9);offset=9;
|
||||
magnitude=(u64)status;
|
||||
}
|
||||
do {digits[length++]=(char)('0'+magnitude%10);magnitude/=10;}
|
||||
while(magnitude&&length<sizeof(digits));
|
||||
while(length)editor_status[offset++]=digits[--length];
|
||||
editor_status[offset]=0;
|
||||
}
|
||||
|
||||
static void gui_run_application_file(u32 file_index) {
|
||||
const char *name;
|
||||
usize length;
|
||||
s64 exit_status=-1;
|
||||
s64 result;
|
||||
if(file_index>=file_count) {
|
||||
gui_copy(editor_status,"NO FILE SELECTED",sizeof("NO FILE SELECTED"));return;
|
||||
}
|
||||
name=file_entries[file_index].Name;
|
||||
length=gui_length(name,BOB64_GUI_FILENAME_CAPACITY);
|
||||
if(length>=BOB64_GUI_FILENAME_CAPACITY||!gui_is_application(name)) {
|
||||
gui_copy(editor_status,"SELECT A .B64E APP",sizeof("SELECT A .B64E APP"));
|
||||
return;
|
||||
}
|
||||
result=bob64_app_delete_file(name,gui_length(name,BOB64_GUI_FILENAME_CAPACITY));
|
||||
file_delete_armed=0;
|
||||
if(result)gui_copy(editor_status,"DELETE FAILED",sizeof("DELETE FAILED"));
|
||||
else {gui_refresh_files();gui_copy(editor_status,"DELETED",sizeof("DELETED"));}
|
||||
const char *arguments[1]={name};
|
||||
result=bob64_app_run(name,length,1,arguments,&exit_status);
|
||||
if(result) {
|
||||
gui_copy(editor_status,"APP LAUNCH FAILED",sizeof("APP LAUNCH FAILED"));
|
||||
return;
|
||||
}
|
||||
gui_refresh_files();
|
||||
u32 application_count=gui_application_count();
|
||||
if(selected_application>=application_count)
|
||||
selected_application=application_count?application_count-1:0;
|
||||
gui_reveal_selected_application();
|
||||
gui_set_app_exit_status(exit_status);
|
||||
}
|
||||
|
||||
static void gui_run_selected_app(void) {
|
||||
gui_run_application_file(selected_file);
|
||||
}
|
||||
|
||||
static void gui_run_selected_application(void) {
|
||||
u32 file_index;
|
||||
if(gui_application_file(selected_application,&file_index)) {
|
||||
gui_copy(editor_status,"NO APP SELECTED",sizeof("NO APP SELECTED"));return;
|
||||
}
|
||||
gui_run_application_file(file_index);
|
||||
}
|
||||
|
||||
static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
@@ -275,8 +562,10 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
if(cursor_row<editor.ScrollRow)editor.ScrollRow=cursor_row;
|
||||
else if(rows&&cursor_row>=editor.ScrollRow+rows)
|
||||
editor.ScrollRow=cursor_row-rows+1;
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+30,filename,
|
||||
BOB64_RECT filename_rect={40,28,window->Width-48,16};
|
||||
bob64_gfx_text(graphics,window->X+8,window->Y+32,"NAME",
|
||||
0x009eb3c7u,1);
|
||||
bob64_text_field_draw(graphics,&filename_rect,&filename_field);
|
||||
for(u32 i=0;i<=editor.Length;i++) {
|
||||
if(column>=columns&&(i==editor.Length||editor.Text[i]!='\n')) {
|
||||
row++;column=0;
|
||||
@@ -316,16 +605,25 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
bob64_gfx_text(graphics,window->X+(s32)window->Width/2,
|
||||
window->Y+(s32)window->Height-16,"CTRL S SAVE",0x009eb3c7u,1);
|
||||
} else if(window->Handle==files_window) {
|
||||
u32 rows=window->Height>58?(window->Height-58)/14:0;
|
||||
u32 list_bottom=window->Height>156?window->Height-156:70;
|
||||
u32 rows=list_bottom>70?(list_bottom-70)/14:0;
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+31,
|
||||
"UP DOWN OPEN R REFRESH",0x009eb3c7u,1);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+41,
|
||||
"D TWICE DELETE",0x009eb3c7u,1);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+49,editor_status,
|
||||
"UP DOWN / WHEEL MOVE",0x009eb3c7u,1);
|
||||
bob64_button_draw(graphics,&file_run_button,"RUN APP",&file_run_state);
|
||||
bob64_button_draw(graphics,&file_apps_button,"APPS",&file_apps_state);
|
||||
bob64_button_draw(graphics,&file_delete_button,"DELETE",&file_delete_state);
|
||||
bob64_button_draw(graphics,&file_help_button,"HELP",&file_help_state);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+52,
|
||||
"O OPEN R REFRESH D DELETE",0x009eb3c7u,1);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+61,editor_status,
|
||||
0x008fc8ffu,1);
|
||||
bob64_gfx_text(graphics,window->X+10,
|
||||
window->Y+(s32)window->Height-144,"PREVIEW (ON DISK)",
|
||||
0x009eb3c7u,1);
|
||||
gui_draw_file_preview(graphics,window);
|
||||
for(u32 row=0;row<rows&&file_scroll+row<file_count;row++) {
|
||||
u32 index=file_scroll+row;
|
||||
s32 y=window->Y+56+(s32)(row*14);
|
||||
s32 y=window->Y+70+(s32)(row*14);
|
||||
if(index==selected_file)
|
||||
bob64_gfx_fill_rect(graphics,window->X+6,y-2,
|
||||
window->Width-12,12,0x00335d8cu);
|
||||
@@ -333,8 +631,54 @@ static void gui_draw_window(const BOB64_WINDOW *window,int focused) {
|
||||
file_entries[index].Name,index==selected_file?
|
||||
0x00ffffffu:0x00dbe8f4u,1);
|
||||
}
|
||||
if(!file_count)bob64_gfx_text(graphics,window->X+10,window->Y+60,
|
||||
if(!file_count)bob64_gfx_text(graphics,window->X+10,window->Y+72,
|
||||
"NO FILES",0x008fc8ffu,1);
|
||||
} else if(window->Handle==delete_window) {
|
||||
bob64_gfx_text(graphics,window->X+16,window->Y+40,
|
||||
"DELETE THIS FILE?",0x00ffffffu,1);
|
||||
bob64_gfx_text(graphics,window->X+16,window->Y+58,
|
||||
delete_filename,0x009eb3c7u,1);
|
||||
bob64_button_draw(graphics,&delete_yes_button,"YES, DELETE",
|
||||
&delete_yes_state);
|
||||
bob64_button_draw(graphics,&delete_cancel_button,"CANCEL",
|
||||
&delete_cancel_state);
|
||||
} else if(window->Handle==help_window) {
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+38,
|
||||
"FILES: ARROWS/WHEEL SELECT",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+54,
|
||||
"O OPENS; A RUNS AN APP",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+70,
|
||||
"D OR DELETE ASKS FIRST",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+86,
|
||||
"P OPENS THE APP LAUNCHER",0x00e2ebf5u,1);
|
||||
bob64_gfx_text(graphics,window->X+12,window->Y+102,
|
||||
"CTRL S SAVES; TAB SWITCHES",0x00e2ebf5u,1);
|
||||
bob64_button_draw(graphics,&help_close_button,"CLOSE",
|
||||
&help_close_state);
|
||||
} else if(window->Handle==applications_window) {
|
||||
u32 rows=window->Height>80?(window->Height-80)/14:0;
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+31,
|
||||
"UP DOWN WHEEL ENTER RUN",0x009eb3c7u,1);
|
||||
bob64_button_draw(graphics,&applications_run_button,"RUN APP",
|
||||
&applications_run_state);
|
||||
bob64_button_draw(graphics,&applications_close_button,"X CLOSE",
|
||||
&applications_close_state);
|
||||
bob64_gfx_text(graphics,window->X+10,window->Y+58,editor_status,
|
||||
0x008fc8ffu,1);
|
||||
for(u32 row=0;row<rows;row++) {
|
||||
u32 app_index=application_scroll+row,file_index;
|
||||
if(app_index>=gui_application_count())break;
|
||||
if(gui_application_file(app_index,&file_index))break;
|
||||
s32 y=window->Y+76+(s32)(row*14);
|
||||
if(app_index==selected_application)
|
||||
bob64_gfx_fill_rect(graphics,window->X+6,y-2,
|
||||
window->Width-12,12,0x00335d8cu);
|
||||
bob64_gfx_text(graphics,window->X+10,y,
|
||||
file_entries[file_index].Name,app_index==selected_application?
|
||||
0x00ffffffu:0x00dbe8f4u,1);
|
||||
}
|
||||
if(!gui_application_count())bob64_gfx_text(graphics,window->X+10,
|
||||
window->Y+80,"NO APPS",0x008fc8ffu,1);
|
||||
} else if(window->Handle==manager.Focused) {
|
||||
bob64_gfx_text(graphics,window->X+14,window->Y+46,
|
||||
"BOB64 DESKTOP",0x007ed6ffu,1);
|
||||
@@ -381,15 +725,50 @@ static int gui_draw(s32 cursor_x,s32 cursor_y) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gui_update_button_hover(BOB64_WINDOW_HANDLE handle,s32 screen_x,
|
||||
s32 screen_y) {
|
||||
BOB64_WINDOW *window=bob64_wm_find(&manager,handle);
|
||||
BOB64_EVENT event={0};
|
||||
if(!window)return;
|
||||
event.Type=BOB64_EVENT_MOUSE_MOVE;
|
||||
event.X=screen_x-window->X;event.Y=screen_y-window->Y;
|
||||
if(handle==files_window) {
|
||||
bob64_button_event(&file_run_button,&file_run_state,&event);
|
||||
bob64_button_event(&file_apps_button,&file_apps_state,&event);
|
||||
bob64_button_event(&file_delete_button,&file_delete_state,&event);
|
||||
bob64_button_event(&file_help_button,&file_help_state,&event);
|
||||
} else if(handle==applications_window) {
|
||||
bob64_button_event(&applications_run_button,&applications_run_state,&event);
|
||||
bob64_button_event(&applications_close_button,&applications_close_state,&event);
|
||||
} else if(handle==delete_window) {
|
||||
bob64_button_event(&delete_yes_button,&delete_yes_state,&event);
|
||||
bob64_button_event(&delete_cancel_button,&delete_cancel_state,&event);
|
||||
} else if(handle==help_window) {
|
||||
bob64_button_event(&help_close_button,&help_close_state,&event);
|
||||
}
|
||||
}
|
||||
|
||||
static void gui_cancel_button_presses(void) {
|
||||
file_run_state.Pressed=0;file_apps_state.Pressed=0;
|
||||
applications_run_state.Pressed=0;applications_close_state.Pressed=0;
|
||||
file_delete_state.Pressed=0;
|
||||
file_help_state.Pressed=0;
|
||||
delete_yes_state.Pressed=delete_cancel_state.Pressed=0;
|
||||
help_close_state.Pressed=0;
|
||||
}
|
||||
|
||||
static void gui_save_editor(void) {
|
||||
if(!editor_save_allowed) {
|
||||
gui_copy(editor_status,"FILE TOO LARGE",sizeof("FILE TOO LARGE"));
|
||||
if(!editor_save_allowed)return;
|
||||
if(!gui_filename_valid()) {
|
||||
gui_copy(editor_status,"INVALID FILE NAME",sizeof("INVALID FILE NAME"));
|
||||
return;
|
||||
}
|
||||
s64 result=bob64_app_write_file(filename,gui_length(filename,
|
||||
s64 result=bob64_app_file_write_all(filename,gui_length(filename,
|
||||
BOB64_GUI_FILENAME_CAPACITY),editor.Text,editor.Length);
|
||||
if(result==(s64)editor.Length) {
|
||||
editor.Dirty=0;gui_copy(editor_status,"SAVED",sizeof("SAVED"));
|
||||
editor.Dirty=0;filename_field.Dirty=0;
|
||||
gui_copy(editor_status,"SAVED",sizeof("SAVED"));
|
||||
gui_refresh_files();
|
||||
} else gui_copy(editor_status,"SAVE FAILED",sizeof("SAVE FAILED"));
|
||||
}
|
||||
|
||||
@@ -431,22 +810,66 @@ static void gui_focus_next(void) {
|
||||
|
||||
static void gui_key(const BOB64_EVENT *event) {
|
||||
if(event->Type!=BOB64_EVENT_KEY_DOWN)return;
|
||||
if(event->Character=='\t')gui_focus_next();
|
||||
if(manager.Focused==delete_window) {
|
||||
if(event->Character=='y'||event->Character=='Y'||event->Character=='\n')
|
||||
gui_finish_delete(1);
|
||||
else if(event->Character=='n'||event->Character=='N'||
|
||||
event->Character==0x1b)gui_finish_delete(0);
|
||||
}
|
||||
else if(manager.Focused==help_window) {
|
||||
if(event->Character==0x1b||event->Character=='x'||
|
||||
event->Character=='X'||event->Character=='h'||
|
||||
event->Character=='H')gui_destroy_window(help_window);
|
||||
}
|
||||
else if(event->Character=='\t') {
|
||||
if(manager.Focused==editor_window&&filename_field.Focused)
|
||||
filename_field.Focused=0;
|
||||
else gui_focus_next();
|
||||
}
|
||||
else if(manager.Focused==editor_window&&filename_field.Focused) {
|
||||
if((event->Modifiers&BOB64_EVENT_MOD_CONTROL)&&
|
||||
(event->Character=='s'||event->Character=='S'))gui_save_editor();
|
||||
else if(event->Character=='\n')filename_field.Focused=0;
|
||||
else {
|
||||
BOB64_RECT filename_rect=gui_filename_rect();
|
||||
bob64_text_field_event(&filename_field,&filename_rect,event);
|
||||
}
|
||||
}
|
||||
else if(event->Character=='p'||event->Character=='P')gui_open_applications();
|
||||
else if(manager.Focused==applications_window) {
|
||||
if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
if(selected_application)selected_application--;
|
||||
gui_reveal_selected_application();
|
||||
} else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x50)) {
|
||||
if(selected_application+1<gui_application_count())selected_application++;
|
||||
gui_reveal_selected_application();
|
||||
} else if(event->Character=='\n'||event->Character=='a'||
|
||||
event->Character=='A')gui_run_selected_application();
|
||||
else if((event->Character=='x'||event->Character=='X')&&
|
||||
gui_destroy_window(applications_window))
|
||||
gui_copy(editor_status,"WINDOW CLOSE FAILED",sizeof("WINDOW CLOSE FAILED"));
|
||||
}
|
||||
else if(manager.Focused==files_window) {
|
||||
if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
if(selected_file)selected_file--;
|
||||
gui_reveal_selected_file();
|
||||
file_delete_armed=editor_open_armed=0;
|
||||
gui_refresh_file_preview();
|
||||
editor_open_armed=0;
|
||||
} else if(event->Key==(BOB64_EVENT_KEY_EXTENDED|0x50)) {
|
||||
if(selected_file+1<file_count)selected_file++;
|
||||
gui_reveal_selected_file();
|
||||
file_delete_armed=editor_open_armed=0;
|
||||
gui_refresh_file_preview();
|
||||
editor_open_armed=0;
|
||||
} else if(event->Character=='r'||event->Character=='R') {
|
||||
gui_refresh_files();file_delete_armed=editor_open_armed=0;
|
||||
gui_refresh_files();editor_open_armed=0;
|
||||
} else if(event->Character=='a'||event->Character=='A') {
|
||||
gui_run_selected_app();editor_open_armed=0;
|
||||
} else if(event->Character=='o'||event->Character=='O'||
|
||||
event->Character=='\n')gui_open_selected_file();
|
||||
else if(event->Character=='d'||event->Character=='D')gui_delete_selected_file();
|
||||
else file_delete_armed=editor_open_armed=0;
|
||||
else if(event->Character=='h'||event->Character=='H'||
|
||||
event->Character=='?')gui_open_help();
|
||||
else editor_open_armed=0;
|
||||
}
|
||||
else if(event->Character=='n'&&manager.Count<BOB64_GUI_MAX_WINDOWS) {
|
||||
u32 index=manager.Count;
|
||||
@@ -470,6 +893,8 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_EVENT event;
|
||||
BOB64_EVENT routed;
|
||||
BOB64_EVENT screen_event;
|
||||
BOB64_EVENT local_event;
|
||||
s64 event_target;
|
||||
s32 cursor_x,cursor_y;
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -1;
|
||||
@@ -490,8 +915,20 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
for(;;) {
|
||||
if(gui_draw(cursor_x,cursor_y))return -4;
|
||||
if(bob64_app_wait_event(&event))return -5;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b&&
|
||||
manager.Focused==delete_window) {
|
||||
gui_finish_delete(0);continue;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b&&
|
||||
manager.Focused==help_window) {
|
||||
gui_destroy_window(help_window);continue;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b&&
|
||||
manager.Focused==applications_window) {
|
||||
gui_destroy_window(applications_window);continue;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b) {
|
||||
if(editor.Dirty&&!editor_exit_armed) {
|
||||
if((editor.Dirty||filename_field.Dirty)&&!editor_exit_armed) {
|
||||
gui_copy(editor_status,"ESC AGAIN TO QUIT",sizeof("ESC AGAIN TO QUIT"));
|
||||
editor_exit_armed=1;continue;
|
||||
}
|
||||
@@ -502,20 +939,105 @@ s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
event.Type==BOB64_EVENT_MOUSE_WHEEL)
|
||||
cursor_x=event.ScreenX,cursor_y=event.ScreenY;
|
||||
screen_event=event;screen_event.X=event.ScreenX;screen_event.Y=event.ScreenY;
|
||||
bob64_wm_dispatch(&manager,&screen_event,&routed);
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&(event.Buttons&1u)&&
|
||||
manager.Focused==files_window&&routed.X>=8&&routed.Y>=56) {
|
||||
u32 row=(u32)(routed.Y-56)/14;
|
||||
if(file_scroll+row<file_count)selected_file=file_scroll+row;
|
||||
event_target=bob64_wm_dispatch(&manager,&screen_event,&routed);
|
||||
if(manager.Focused!=editor_window)filename_field.Focused=0;
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE) {
|
||||
gui_update_button_hover(files_window,event.ScreenX,event.ScreenY);
|
||||
gui_update_button_hover(applications_window,event.ScreenX,event.ScreenY);
|
||||
gui_update_button_hover(delete_window,event.ScreenX,event.ScreenY);
|
||||
gui_update_button_hover(help_window,event.ScreenX,event.ScreenY);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&(event.Buttons&1u)&&
|
||||
manager.Focused==editor_window&&routed.X>=12&&routed.Y>=46) {
|
||||
if(event.Type==BOB64_EVENT_MOUSE_WHEEL) {
|
||||
if(manager.Focused==files_window&&routed.Y>=70)
|
||||
gui_scroll_file_selection(event.Wheel);
|
||||
else if(manager.Focused==applications_window&&routed.Y>=72)
|
||||
gui_scroll_application_selection(event.Wheel);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
event_target==(s64)files_window) {
|
||||
local_event=event;local_event.X=routed.X;local_event.Y=routed.Y;
|
||||
int run_clicked=bob64_button_event(&file_run_button,&file_run_state,
|
||||
&local_event);
|
||||
int apps_clicked=bob64_button_event(&file_apps_button,&file_apps_state,
|
||||
&local_event);
|
||||
int delete_clicked=bob64_button_event(&file_delete_button,
|
||||
&file_delete_state,&local_event);
|
||||
int help_clicked=bob64_button_event(&file_help_button,
|
||||
&file_help_state,&local_event);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&run_clicked)
|
||||
gui_run_selected_app();
|
||||
else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&apps_clicked)
|
||||
gui_open_applications();
|
||||
else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&delete_clicked)
|
||||
gui_delete_selected_file();
|
||||
else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&help_clicked)
|
||||
gui_open_help();
|
||||
else if((event.Buttons&BOB64_BUTTON_LEFT)&&routed.Y>=70&&routed.X>=8) {
|
||||
u32 row=(u32)(routed.Y-70)/14;
|
||||
if(file_scroll+row<file_count) {
|
||||
selected_file=file_scroll+row;
|
||||
gui_refresh_file_preview();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
event_target==(s64)applications_window) {
|
||||
local_event=event;local_event.X=routed.X;local_event.Y=routed.Y;
|
||||
int run_clicked=bob64_button_event(&applications_run_button,
|
||||
&applications_run_state,&local_event);
|
||||
int close_clicked=bob64_button_event(&applications_close_button,
|
||||
&applications_close_state,&local_event);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&close_clicked)
|
||||
gui_destroy_window(applications_window);
|
||||
else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&run_clicked)
|
||||
gui_run_selected_application();
|
||||
else if((event.Buttons&BOB64_BUTTON_LEFT)&&routed.Y>=72) {
|
||||
u32 row=(u32)(routed.Y-72)/14;
|
||||
u32 app_index=application_scroll+row;
|
||||
if(app_index<gui_application_count())
|
||||
selected_application=app_index;
|
||||
}
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
event_target==(s64)delete_window) {
|
||||
local_event=event;local_event.X=routed.X;local_event.Y=routed.Y;
|
||||
int yes_clicked=bob64_button_event(&delete_yes_button,
|
||||
&delete_yes_state,&local_event);
|
||||
int cancel_clicked=bob64_button_event(&delete_cancel_button,
|
||||
&delete_cancel_state,&local_event);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&yes_clicked)
|
||||
gui_finish_delete(1);
|
||||
else if(!(event.Buttons&BOB64_BUTTON_LEFT)&&cancel_clicked)
|
||||
gui_finish_delete(0);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
event_target==(s64)help_window) {
|
||||
local_event=event;local_event.X=routed.X;local_event.Y=routed.Y;
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&
|
||||
bob64_button_event(&help_close_button,&help_close_state,
|
||||
&local_event))gui_destroy_window(help_window);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
!(event.Buttons&BOB64_BUTTON_LEFT)&&
|
||||
event_target!=(s64)files_window&&
|
||||
event_target!=(s64)applications_window&&
|
||||
event_target!=(s64)delete_window&&
|
||||
event_target!=(s64)help_window)gui_cancel_button_presses();
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&
|
||||
event_target==(s64)editor_window) {
|
||||
local_event=event;local_event.X=routed.X;local_event.Y=routed.Y;
|
||||
BOB64_RECT filename_rect=gui_filename_rect();
|
||||
bob64_text_field_event(&filename_field,&filename_rect,&local_event);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&(event.Buttons&BOB64_BUTTON_LEFT)&&
|
||||
event_target==(s64)editor_window&&routed.X>=12&&routed.Y>=46) {
|
||||
BOB64_WINDOW *window=bob64_wm_find(&manager,editor_window);
|
||||
if(window)gui_editor_place_cursor((u32)(routed.Y-46)/10,
|
||||
(u32)(routed.X-12)/6,(window->Width-24)/6);
|
||||
}
|
||||
gui_key(&event);
|
||||
if(editor.Dirty)gui_copy(editor_status,"UNSAVED",sizeof("UNSAVED"));
|
||||
if(editor.Dirty||filename_field.Dirty)
|
||||
gui_copy(editor_status,"UNSAVED",sizeof("UNSAVED"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
static void write_text(const char *text) {
|
||||
usize length=0;
|
||||
while(text[length])length++;
|
||||
(void)bob64_app_write(text,length);
|
||||
}
|
||||
|
||||
static void write_number(u64 value) {
|
||||
char digits[20];
|
||||
usize count=0;
|
||||
do {
|
||||
digits[count++]=(char)('0'+value%10);
|
||||
value/=10;
|
||||
} while(value&&count<sizeof(digits));
|
||||
while(count)(void)bob64_app_write_char((u8)digits[--count]);
|
||||
}
|
||||
|
||||
static void write_labeled_number(const char *label,u64 value) {
|
||||
write_text(label);
|
||||
write_number(value);
|
||||
write_text("\n");
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_FILE_INFO files[BOB64_SYSCALL_MAX_FILES];
|
||||
u32 width=0,height=0;
|
||||
s64 file_count,display_status;
|
||||
u64 total_bytes=0;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||startup->ArgumentCount!=0)
|
||||
return -1;
|
||||
if(bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -2;
|
||||
display_status=bob64_app_get_display(&width,&height);
|
||||
file_count=bob64_app_list_files(files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(file_count<0||(u64)file_count>BOB64_SYSCALL_MAX_FILES)return -4;
|
||||
for(s64 i=0;i<file_count;i++)total_bytes+=files[i].Size;
|
||||
write_text("bob64 system information\n");
|
||||
write_labeled_number("System call ABI: ",BOB64_SYSCALL_ABI_VERSION);
|
||||
if(display_status)write_text("Display: unavailable\n");
|
||||
else {
|
||||
write_text("Display: ");write_number(width);write_text(" x ");
|
||||
write_number(height);write_text(" pixels\n");
|
||||
}
|
||||
write_labeled_number("Uptime: ",bob64_app_ticks()/100);
|
||||
write_labeled_number("RAM files: ",(u64)file_count);
|
||||
write_labeled_number("RAM file data: ",total_bytes);
|
||||
write_text("Uptime unit: seconds\n");
|
||||
write_text("bob!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/gfx.h"
|
||||
#include "../bob64/widgets.h"
|
||||
#include "../bob64/window.h"
|
||||
|
||||
#define LAUNCHER_WIDTH 360u
|
||||
#define LAUNCHER_HEIGHT 280u
|
||||
#define LAUNCHER_ROWS 9u
|
||||
|
||||
static u32 pixels[LAUNCHER_WIDTH*LAUNCHER_HEIGHT];
|
||||
static BOB64_GFX graphics;
|
||||
static BOB64_WINDOW_MANAGER manager;
|
||||
static BOB64_WINDOW window;
|
||||
static BOB64_WINDOW_HANDLE order[1];
|
||||
static BOB64_FILE_INFO files[BOB64_SYSCALL_MAX_FILES];
|
||||
static u32 application_files[BOB64_SYSCALL_MAX_FILES];
|
||||
static u32 application_count,selected_application,scroll;
|
||||
static BOB64_RECT run_button={12,36,72,18};
|
||||
static BOB64_RECT close_button={92,36,72,18};
|
||||
static BOB64_BUTTON_STATE run_state,close_state;
|
||||
static char status[32];
|
||||
|
||||
static usize length(const char *text) {
|
||||
usize result=0;
|
||||
if(text)while(text[result])result++;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void copy(char *to,const char *from,usize limit) {
|
||||
usize i=0;
|
||||
while(i+1<limit&&from[i]){to[i]=from[i];i++;}
|
||||
to[i]=0;
|
||||
}
|
||||
|
||||
static int app_name(const char *name) {
|
||||
usize size=length(name);
|
||||
return size>5&&name[size-5]=='.'&&name[size-4]=='b'&&
|
||||
name[size-3]=='6'&&name[size-2]=='4'&&name[size-1]=='e';
|
||||
}
|
||||
|
||||
static int self_name(const char *name) {
|
||||
static const char self[]="launcher.b64e";
|
||||
usize size=length(name);
|
||||
if(size!=sizeof(self)-1)return 0;
|
||||
for(usize i=0;i<size;i++) {
|
||||
char a=name[i],b=self[i];
|
||||
if(a>='A'&&a<='Z')a=(char)(a-'A'+'a');
|
||||
if(a!=b)return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void refresh(void) {
|
||||
s64 count=bob64_app_list_files(files,BOB64_SYSCALL_MAX_FILES);
|
||||
application_count=0;
|
||||
if(count<0) {
|
||||
copy(status,"FILE LIST FAILED",sizeof(status));return;
|
||||
}
|
||||
for(u32 i=0;i<(u32)count;i++)
|
||||
if(app_name(files[i].Name)&&!self_name(files[i].Name))
|
||||
application_files[application_count++]=i;
|
||||
if(selected_application>=application_count)
|
||||
selected_application=application_count?application_count-1:0;
|
||||
if(scroll>selected_application)scroll=selected_application;
|
||||
copy(status,application_count?"SELECT AN APP":"NO APPS INSTALLED",
|
||||
sizeof(status));
|
||||
}
|
||||
|
||||
static void reveal_selection(void) {
|
||||
if(selected_application<scroll)scroll=selected_application;
|
||||
else if(selected_application>=scroll+LAUNCHER_ROWS)
|
||||
scroll=selected_application-LAUNCHER_ROWS+1;
|
||||
}
|
||||
|
||||
static void draw(void) {
|
||||
bob64_gfx_fill_rect(&graphics,0,0,LAUNCHER_WIDTH,LAUNCHER_HEIGHT,
|
||||
0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(&graphics,0,0,LAUNCHER_WIDTH,
|
||||
BOB64_WINDOW_TITLE_BAR_HEIGHT,0x00335d8cu);
|
||||
bob64_gfx_text(&graphics,12,8,"APPLICATION LAUNCHER",0x00ffffffu,1);
|
||||
bob64_gfx_text(&graphics,12,28,"SELECT AN APP TO RUN",0x009eb3c7u,1);
|
||||
bob64_button_draw(&graphics,&run_button,"RUN APP",&run_state);
|
||||
bob64_button_draw(&graphics,&close_button,"CLOSE",&close_state);
|
||||
bob64_gfx_text(&graphics,180,42,status,0x008fc8ffu,1);
|
||||
for(u32 row=0;row<LAUNCHER_ROWS;row++) {
|
||||
u32 index=scroll+row;
|
||||
if(index>=application_count)break;
|
||||
s32 y=68+(s32)(row*20);
|
||||
if(index==selected_application)
|
||||
bob64_gfx_fill_rect(&graphics,8,y-3,344,17,0x00335d8cu);
|
||||
bob64_gfx_text(&graphics,14,y,
|
||||
files[application_files[index]].Name,
|
||||
index==selected_application?0x00ffffffu:0x00dbe8f4u,1);
|
||||
}
|
||||
if(bob64_app_window_present(window.Handle,graphics.Pixels,
|
||||
graphics.Width,graphics.Height)!=(s64)(LAUNCHER_WIDTH*LAUNCHER_HEIGHT))
|
||||
bob64_app_exit(-2);
|
||||
}
|
||||
|
||||
static void launch_selected(void) {
|
||||
s64 child_status=-1,result;
|
||||
if(selected_application>=application_count) {
|
||||
copy(status,"NO APP SELECTED",sizeof(status));return;
|
||||
}
|
||||
const char *name=files[application_files[selected_application]].Name;
|
||||
const char *arguments[1]={name};
|
||||
result=bob64_app_run(name,length(name),1,arguments,&child_status);
|
||||
refresh();
|
||||
if(result||child_status)copy(status,"APP FAILED",sizeof(status));
|
||||
else copy(status,"APP EXITED OK",sizeof(status));
|
||||
(void)bob64_app_window_focus(window.Handle);
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_EVENT event,screen_event,routed;
|
||||
s64 target;
|
||||
BOB64_WINDOW_HANDLE kernel_handle,app_handle;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
bob64_app_query_abi()!=BOB64_SYSCALL_ABI_VERSION)return -1;
|
||||
if(bob64_app_write("bob!",4)!=4)return -2;
|
||||
if(startup->ArgumentCount>1) {
|
||||
s64 child_status=-1,result;
|
||||
if(!startup->Arguments||!startup->Arguments[1])return -3;
|
||||
const char *name=startup->Arguments[1];
|
||||
result=bob64_app_run(name,length(name),
|
||||
(usize)(startup->ArgumentCount-1),startup->Arguments+1,
|
||||
&child_status);
|
||||
return result?result:child_status;
|
||||
}
|
||||
u32 screen_width,screen_height;
|
||||
if(bob64_app_get_display(&screen_width,&screen_height)||
|
||||
screen_width<LAUNCHER_WIDTH||screen_height<LAUNCHER_HEIGHT)return -3;
|
||||
if(bob64_wm_init(&manager,&window,1,order,screen_width,screen_height))return -4;
|
||||
kernel_handle=bob64_app_window_create(
|
||||
(s32)(screen_width-LAUNCHER_WIDTH)/2,
|
||||
(s32)(screen_height-LAUNCHER_HEIGHT)/2,
|
||||
LAUNCHER_WIDTH,LAUNCHER_HEIGHT);
|
||||
if(!kernel_handle||(s64)kernel_handle<0)return -5;
|
||||
manager.NextHandle=kernel_handle;
|
||||
app_handle=bob64_wm_create(&manager,
|
||||
(s32)(screen_width-LAUNCHER_WIDTH)/2,
|
||||
(s32)(screen_height-LAUNCHER_HEIGHT)/2,
|
||||
LAUNCHER_WIDTH,LAUNCHER_HEIGHT,(void *)"Application launcher");
|
||||
if(app_handle!=kernel_handle) {
|
||||
if(app_handle)bob64_wm_destroy(&manager,app_handle);
|
||||
bob64_app_window_destroy(kernel_handle);return -6;
|
||||
}
|
||||
graphics.Pixels=pixels;graphics.Width=LAUNCHER_WIDTH;
|
||||
graphics.Height=LAUNCHER_HEIGHT;
|
||||
graphics.Capacity=LAUNCHER_WIDTH*LAUNCHER_HEIGHT;
|
||||
refresh();
|
||||
for(;;) {
|
||||
draw();
|
||||
if(bob64_app_wait_event(&event))return -7;
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN&&event.Character==0x1b)break;
|
||||
screen_event=event;screen_event.X=event.ScreenX;
|
||||
screen_event.Y=event.ScreenY;
|
||||
target=bob64_wm_dispatch(&manager,&screen_event,&routed);
|
||||
if(event.Type==BOB64_EVENT_MOUSE_MOVE) {
|
||||
BOB64_EVENT local=event;
|
||||
local.X=event.ScreenX-window.X;local.Y=event.ScreenY-window.Y;
|
||||
bob64_button_event(&run_button,&run_state,&local);
|
||||
bob64_button_event(&close_button,&close_state,&local);
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_WHEEL&&
|
||||
bob64_rect_contains(&(BOB64_RECT){window.X,window.Y+64,
|
||||
window.Width,window.Height-64},event.ScreenX,event.ScreenY)) {
|
||||
if(event.Wheel>0&&selected_application)selected_application--;
|
||||
else if(event.Wheel<0&&selected_application+1<application_count)
|
||||
selected_application++;
|
||||
reveal_selection();
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_KEY_DOWN) {
|
||||
if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x48)) {
|
||||
if(selected_application)selected_application--;
|
||||
reveal_selection();
|
||||
} else if(event.Key==(BOB64_EVENT_KEY_EXTENDED|0x50)) {
|
||||
if(selected_application+1<application_count)selected_application++;
|
||||
reveal_selection();
|
||||
} else if(event.Character=='\n'||event.Character=='a'||
|
||||
event.Character=='A'||event.Character=='r'||
|
||||
event.Character=='R')launch_selected();
|
||||
else if(event.Character=='x'||event.Character=='X')break;
|
||||
}
|
||||
if(event.Type==BOB64_EVENT_MOUSE_BUTTON&&target==(s64)window.Handle) {
|
||||
BOB64_EVENT local=event;local.X=routed.X;local.Y=routed.Y;
|
||||
int run=bob64_button_event(&run_button,&run_state,&local);
|
||||
int close=bob64_button_event(&close_button,&close_state,&local);
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&close)break;
|
||||
if(!(event.Buttons&BOB64_BUTTON_LEFT)&&run)launch_selected();
|
||||
else if((event.Buttons&BOB64_BUTTON_LEFT)&&routed.Y>=64) {
|
||||
u32 row=(u32)(routed.Y-68)/20;
|
||||
if(routed.Y>=68&&scroll+row<application_count)
|
||||
selected_application=scroll+row;
|
||||
}
|
||||
}
|
||||
}
|
||||
bob64_app_window_destroy(window.Handle);
|
||||
bob64_wm_destroy(&manager,window.Handle);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
static void write_text(const char *text) {
|
||||
usize length=0;
|
||||
while(text[length])length++;
|
||||
(void)bob64_app_write(text,length);
|
||||
}
|
||||
|
||||
static void write_size(u64 value) {
|
||||
char digits[20];
|
||||
usize count=0;
|
||||
do {
|
||||
digits[count++]=(char)('0'+value%10);
|
||||
value/=10;
|
||||
} while(value&&count<sizeof(digits));
|
||||
while(count)bob64_app_write_char((u8)digits[--count]);
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_FILE_INFO files[BOB64_SYSCALL_MAX_FILES];
|
||||
s64 count;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
count=bob64_app_list_files(files,BOB64_SYSCALL_MAX_FILES);
|
||||
if(count<0) {
|
||||
write_text("cannot list files\n");
|
||||
return count;
|
||||
}
|
||||
for(s64 i=0;i<count;i++) {
|
||||
write_text(files[i].Name);
|
||||
write_text(" ");
|
||||
write_size(files[i].Size);
|
||||
write_text(" bytes\n");
|
||||
}
|
||||
if(!count)write_text("no files\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
/* The QEMU runtime test injects a mouse move through the emulated PS/2 device. */
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
BOB64_EVENT event;
|
||||
static const char passed[]="bob64 live mouse event passed\n";
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION)return -1;
|
||||
if(bob64_app_wait_event(&event))return -2;
|
||||
if(event.Type!=BOB64_EVENT_MOUSE_MOVE||
|
||||
(!event.DeltaX&&!event.DeltaY))
|
||||
return -3;
|
||||
if(bob64_app_write(passed,sizeof(passed)-1)!=(s64)(sizeof(passed)-1))
|
||||
return -4;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "../bob64/app.h"
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
s64 child_status=-1;
|
||||
if(!startup||startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
bob64_app_run("bob.b64e",8,1,(const char *const[]){"bob.b64e"},
|
||||
&child_status)||child_status)return -1;
|
||||
if(bob64_app_write("bob!",4)!=4)return -2;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
#include "../bob64/app.h"
|
||||
#include "../bob64/editor.h"
|
||||
#include "../bob64/gfx.h"
|
||||
|
||||
static char note_buffer[BOB64_EDITOR_CAPACITY+1];
|
||||
static u32 note_pixels[640u*420u];
|
||||
static BOB64_EDITOR note_editor;
|
||||
static BOB64_GFX note_graphics;
|
||||
static char note_status[32]="CTRL S SAVE ESC CLOSE";
|
||||
static const char note_filename[]="notes.txt";
|
||||
|
||||
static usize text_length(const char *text) {
|
||||
usize length=0;
|
||||
if(!text)return 0;
|
||||
while(text[length])length++;
|
||||
return length;
|
||||
}
|
||||
|
||||
static int same_text(const char *left,const char *right) {
|
||||
usize i=0;
|
||||
if(!left||!right)return 0;
|
||||
while(left[i]&&left[i]==right[i])i++;
|
||||
return left[i]==right[i];
|
||||
}
|
||||
|
||||
static void write_text(const char *text) {
|
||||
(void)bob64_app_write(text,text_length(text));
|
||||
}
|
||||
|
||||
static void note_copy(char *destination,const char *source,usize capacity) {
|
||||
usize i=0;
|
||||
if(!destination||!capacity)return;
|
||||
if(source)while(i+1<capacity&&source[i]) {
|
||||
destination[i]=source[i];i++;
|
||||
}
|
||||
destination[i]=0;
|
||||
}
|
||||
|
||||
static s64 read_note(const char *name,usize name_length,usize *length) {
|
||||
s64 result=bob64_app_file_read_all(name,name_length,note_buffer,
|
||||
BOB64_EDITOR_CAPACITY);
|
||||
if(result<0)return result;
|
||||
if(bob64_editor_is_binary_text(note_buffer,(usize)result))return -84;
|
||||
*length=(usize)result;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int append_arguments(const BOB64_APP_STARTUP *startup,u64 first,
|
||||
usize *length) {
|
||||
for(u64 i=first;i<startup->ArgumentCount;i++) {
|
||||
const char *argument=startup->Arguments[i];
|
||||
usize argument_length=text_length(argument);
|
||||
usize separator=i>first?1:0;
|
||||
if(!argument||argument_length>BOB64_EDITOR_CAPACITY-*length||
|
||||
separator>BOB64_EDITOR_CAPACITY-*length-argument_length)
|
||||
return -1;
|
||||
if(separator)note_buffer[(*length)++]=' ';
|
||||
for(usize j=0;j<argument_length;j++)
|
||||
note_buffer[(*length)++]=argument[j];
|
||||
}
|
||||
note_buffer[*length]=0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int save_note(const char *name,usize name_length,usize length) {
|
||||
s64 result=bob64_app_file_write_all(name,name_length,note_buffer,length);
|
||||
if(result!=(s64)length) {
|
||||
write_text("cannot save note\n");
|
||||
return -1;
|
||||
}
|
||||
write_text("saved\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void note_gui_draw(void) {
|
||||
const u32 width=640,height=420;
|
||||
const u32 columns=96,visible_rows=29;
|
||||
u32 row=0,column=0,cursor_row,cursor_column;
|
||||
bob64_gfx_fill_rect(¬e_graphics,0,0,width,height,0x0009111bu);
|
||||
bob64_gfx_fill_rect(¬e_graphics,2,2,width-4,height-4,0x001a2a3cu);
|
||||
bob64_gfx_fill_rect(¬e_graphics,0,0,width,26,0x00335d8cu);
|
||||
bob64_gfx_line(¬e_graphics,0,0,width-1,0,0x00a4c8ffu);
|
||||
bob64_gfx_line(¬e_graphics,0,height-1,width-1,height-1,0x00a4c8ffu);
|
||||
bob64_gfx_line(¬e_graphics,0,0,0,height-1,0x00a4c8ffu);
|
||||
bob64_gfx_line(¬e_graphics,width-1,0,width-1,height-1,0x00a4c8ffu);
|
||||
bob64_gfx_text(¬e_graphics,12,8,"NOTES",0x00ffffffu,1);
|
||||
bob64_gfx_text(¬e_graphics,14,36,note_filename,0x009eb3c7u,1);
|
||||
bob64_editor_visual_position(¬e_editor,columns,&cursor_row,&cursor_column);
|
||||
if(cursor_row<note_editor.ScrollRow)note_editor.ScrollRow=cursor_row;
|
||||
else if(cursor_row>=note_editor.ScrollRow+visible_rows)
|
||||
note_editor.ScrollRow=cursor_row-visible_rows+1;
|
||||
for(u32 i=0;i<=note_editor.Length;i++) {
|
||||
if(column>=columns&&(i==note_editor.Length||note_editor.Text[i]!='\n')) {
|
||||
row++;column=0;
|
||||
}
|
||||
if(i==note_editor.Cursor) {
|
||||
if(row>=note_editor.ScrollRow&&row<note_editor.ScrollRow+visible_rows) {
|
||||
s32 x=14+(s32)(column*6),y=54+(s32)((row-note_editor.ScrollRow)*10);
|
||||
bob64_gfx_line(¬e_graphics,x,y,x,y+7,0x00ffffffu);
|
||||
}
|
||||
}
|
||||
if(i==note_editor.Length)break;
|
||||
if(note_editor.Text[i]=='\n') {row++;column=0;continue;}
|
||||
if(row>=note_editor.ScrollRow&&row<note_editor.ScrollRow+visible_rows) {
|
||||
char character[2]={note_editor.Text[i],0};
|
||||
bob64_gfx_text(¬e_graphics,14+(s32)(column*6),
|
||||
54+(s32)((row-note_editor.ScrollRow)*10),character,
|
||||
0x00e2ebf5u,1);
|
||||
}
|
||||
column++;
|
||||
}
|
||||
(void)cursor_column;
|
||||
bob64_gfx_line(¬e_graphics,8,390,width-8,390,0x0044576au);
|
||||
bob64_gfx_text(¬e_graphics,12,398,note_status,0x008fc8ffu,1);
|
||||
}
|
||||
|
||||
static s64 note_gui_run(void) {
|
||||
const u32 width=640,height=420;
|
||||
u32 display_width,display_height;
|
||||
u64 handle;
|
||||
usize length=0;
|
||||
s64 result;
|
||||
if(bob64_app_get_display(&display_width,&display_height)||
|
||||
display_width<width||display_height<height) {
|
||||
write_text("display is too small for notes\n");
|
||||
return -1;
|
||||
}
|
||||
result=read_note(note_filename,sizeof(note_filename)-1,&length);
|
||||
if(result<0&&result!=-2) {
|
||||
write_text(result==-84?"notes.txt is not a text file\n":
|
||||
"cannot open notes.txt\n");
|
||||
return -1;
|
||||
}
|
||||
bob64_editor_init(¬e_editor,result>=0?note_buffer:0,(u32)length);
|
||||
note_graphics.Pixels=note_pixels;
|
||||
note_graphics.Width=width;note_graphics.Height=height;
|
||||
note_graphics.Capacity=sizeof(note_pixels)/sizeof(note_pixels[0]);
|
||||
handle=bob64_app_window_create((s32)((display_width-width)/2),
|
||||
(s32)((display_height-height)/2),width,height);
|
||||
if(!handle) {
|
||||
write_text("cannot open notes window\n");
|
||||
return -1;
|
||||
}
|
||||
for(;;) {
|
||||
BOB64_EVENT event;
|
||||
note_gui_draw();
|
||||
if(bob64_app_window_present(handle,note_pixels,width,height)<0) {
|
||||
bob64_app_window_destroy(handle);
|
||||
return -2;
|
||||
}
|
||||
if(bob64_app_wait_event(&event)) {
|
||||
bob64_app_window_destroy(handle);
|
||||
return -3;
|
||||
}
|
||||
if(event.Type!=BOB64_EVENT_KEY_DOWN)continue;
|
||||
if(event.Key==0x01)break;
|
||||
if((event.Modifiers&BOB64_EVENT_MOD_CONTROL)&&
|
||||
(event.Character=='s'||event.Character=='S')) {
|
||||
usize saved_length=note_editor.Length;
|
||||
for(usize i=0;i<saved_length;i++)note_buffer[i]=note_editor.Text[i];
|
||||
if(bob64_app_file_write_all(note_filename,sizeof(note_filename)-1,
|
||||
note_buffer,saved_length)==(s64)saved_length)
|
||||
note_copy(note_status,"SAVED",sizeof(note_status));
|
||||
else note_copy(note_status,"SAVE FAILED",sizeof(note_status));
|
||||
continue;
|
||||
}
|
||||
bob64_editor_handle_key(¬e_editor,&event);
|
||||
note_copy(note_status,"CTRL S SAVE ESC CLOSE",sizeof(note_status));
|
||||
}
|
||||
if(bob64_app_window_destroy(handle))return -4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
s64 bob64_app_main(const BOB64_APP_STARTUP *startup) {
|
||||
const char *command,*name;
|
||||
usize name_length,length=0;
|
||||
s64 result;
|
||||
if(!startup||startup->StructSize!=sizeof(*startup)||
|
||||
startup->AbiVersion!=BOB64_APP_ABI_VERSION||
|
||||
(startup->ArgumentCount&&!startup->Arguments))return -1;
|
||||
if(!startup->ArgumentCount)return note_gui_run();
|
||||
if(startup->ArgumentCount<2||!startup->Arguments[1]) {
|
||||
write_text("usage: notes show NAME | copy SOURCE DEST | put NAME TEXT | add NAME TEXT | delete NAME\n");
|
||||
return 1;
|
||||
}
|
||||
command=startup->Arguments[1];
|
||||
if(startup->ArgumentCount<3||!startup->Arguments[2]) {
|
||||
write_text("usage: notes show NAME | copy SOURCE DEST | put NAME TEXT | add NAME TEXT | delete NAME\n");
|
||||
return 1;
|
||||
}
|
||||
name=startup->Arguments[2];
|
||||
name_length=text_length(name);
|
||||
if(!name_length||name_length>BOB64_SYSCALL_MAX_FILENAME) {
|
||||
write_text("invalid note name\n");
|
||||
return 1;
|
||||
}
|
||||
if(same_text(command,"show")&&startup->ArgumentCount==3) {
|
||||
result=read_note(name,name_length,&length);
|
||||
if(result<0) {
|
||||
write_text(result==-84?"not a text note\n":"note not found or too large\n");
|
||||
return 1;
|
||||
}
|
||||
for(usize offset=0;offset<length;) {
|
||||
usize chunk=length-offset;
|
||||
if(chunk>BOB64_SYSCALL_MAX_BUFFER)chunk=BOB64_SYSCALL_MAX_BUFFER;
|
||||
if(bob64_app_write(note_buffer+offset,chunk)!=(s64)chunk)return -2;
|
||||
offset+=chunk;
|
||||
}
|
||||
if(bob64_app_write_char('\n')<0)return -2;
|
||||
return 0;
|
||||
}
|
||||
if(same_text(command,"copy")&&startup->ArgumentCount==4&&
|
||||
startup->Arguments[3]) {
|
||||
const char *destination=startup->Arguments[3];
|
||||
usize destination_length=text_length(destination);
|
||||
if(!destination_length||destination_length>BOB64_SYSCALL_MAX_FILENAME||
|
||||
same_text(name,destination)) {
|
||||
write_text("invalid copy destination\n");
|
||||
return 1;
|
||||
}
|
||||
if(destination_length>=5&&destination[destination_length-5]=='.'&&
|
||||
destination[destination_length-4]=='b'&&
|
||||
destination[destination_length-3]=='6'&&
|
||||
destination[destination_length-2]=='4'&&
|
||||
destination[destination_length-1]=='e') {
|
||||
write_text("refusing to overwrite an app\n");
|
||||
return 1;
|
||||
}
|
||||
result=read_note(destination,destination_length,&length);
|
||||
if(result<0&&result!=-2) {
|
||||
write_text("destination is not a text note\n");
|
||||
return 1;
|
||||
}
|
||||
result=read_note(name,name_length,&length);
|
||||
if(result<0) {
|
||||
write_text(result==-84?"source is not a text note\n":
|
||||
"source note not found or too large\n");
|
||||
return 1;
|
||||
}
|
||||
result=bob64_app_file_write_all(destination,destination_length,
|
||||
note_buffer,length);
|
||||
if(result!=(s64)length) {
|
||||
write_text("cannot copy note\n");
|
||||
return 1;
|
||||
}
|
||||
write_text("Copied.\n");
|
||||
return 0;
|
||||
}
|
||||
if((same_text(command,"put")||same_text(command,"edit"))&&
|
||||
startup->ArgumentCount>=4) {
|
||||
result=read_note(name,name_length,&length);
|
||||
if(result<0&&result!=-2) {
|
||||
write_text(result==-84?"not a text note\n":"cannot read note\n");
|
||||
return 1;
|
||||
}
|
||||
length=0;
|
||||
if(append_arguments(startup,3,&length)) {
|
||||
write_text("note is too large\n");
|
||||
return 1;
|
||||
}
|
||||
return save_note(name,name_length,length);
|
||||
}
|
||||
if(same_text(command,"add")&&startup->ArgumentCount>=4) {
|
||||
result=read_note(name,name_length,&length);
|
||||
if(result<0&&result!=-2) {
|
||||
write_text(result==-84?"not a text note\n":"cannot read note\n");
|
||||
return 1;
|
||||
}
|
||||
if(length&¬e_buffer[length-1]!='\n') {
|
||||
if(length>=BOB64_EDITOR_CAPACITY) {
|
||||
write_text("note is too large\n");
|
||||
return 1;
|
||||
}
|
||||
note_buffer[length++]='\n';
|
||||
}
|
||||
if(append_arguments(startup,3,&length)) {
|
||||
write_text("note is too large\n");
|
||||
return 1;
|
||||
}
|
||||
return save_note(name,name_length,length);
|
||||
}
|
||||
if(same_text(command,"delete")&&startup->ArgumentCount==3) {
|
||||
result=read_note(name,name_length,&length);
|
||||
if(result<0) {
|
||||
write_text(result==-84?"not a text note\n":"note not found\n");
|
||||
return 1;
|
||||
}
|
||||
if(bob64_app_delete_file(name,name_length)) {
|
||||
write_text("cannot delete note\n");
|
||||
return 1;
|
||||
}
|
||||
write_text("deleted\n");
|
||||
return 0;
|
||||
}
|
||||
write_text("usage: notes show NAME | copy SOURCE DEST | put NAME TEXT | add NAME TEXT | delete NAME\n");
|
||||
return 1;
|
||||
}
|
||||
Reference in new issue
Block a user