From e68dfe20b6e4e7ced08bb6552f9e26856a098b7e Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Mon, 4 Jun 2018 12:35:46 +0900 Subject: [PATCH] Add flexible about dialogs --- apps/about.c | 83 ++++++++++++++++++++++++++++++++++----------- apps/file-browser.c | 7 ++++ apps/help-browser.c | 4 +++ apps/terminal.c | 16 +++++++-- 4 files changed, 89 insertions(+), 21 deletions(-) diff --git a/apps/about.c b/apps/about.c index 51b403dd..501b0dd0 100644 --- a/apps/about.c +++ b/apps/about.c @@ -15,7 +15,10 @@ static int32_t width = 350; static int32_t height = 250; static char * version_str; -#define TITLE "About ToaruOS-NIH" +static char * icon_path; +static char * title_str; +static char * version_str; +static char * copyright_str[20] = {NULL}; static int center_x(int x) { return (width - x) / 2; @@ -30,42 +33,84 @@ static void redraw(void) { draw_fill(ctx, rgb(204,204,204)); draw_sprite(ctx, &logo, decor_left_width + center_x(logo.width), decor_top_height + 10); - char version[100]; - sprintf(version, "ToaruOS-NIH %s", version_str); - draw_string(0, version, SDF_FONT_BOLD, rgb(0,0,0)); - draw_string(20, "(C) 2011-2018 K. Lange, et al.", SDF_FONT_THIN, rgb(0,0,0)); - draw_string(50, "ToaruOS is free software released under the", SDF_FONT_THIN, rgb(0,0,0)); - draw_string(70, "NCSA/University of Illinois license.", SDF_FONT_THIN, rgb(0,0,0)); - draw_string(100, "http://toaruos.org", SDF_FONT_THIN, rgb(0,0,255)); - draw_string(120, "https://github.com/klange/toaru-nih", SDF_FONT_THIN, rgb(0,0,255)); + draw_string(0, version_str, SDF_FONT_BOLD, rgb(0,0,0)); + + int offset = 20; + + for (char ** copy_str = copyright_str; *copy_str; ++copy_str) { + if (**copy_str == '-') { + offset += 10; + } else if (**copy_str == '%') { + draw_string(offset, *copy_str+1, SDF_FONT_THIN, rgb(0,0,255)); + offset += 20; + } else { + draw_string(offset, *copy_str, SDF_FONT_THIN, rgb(0,0,0)); + offset += 20; + } + } window->decorator_flags |= DECOR_FLAG_NO_MAXIMIZE; - render_decorations(window, ctx, TITLE); + render_decorations(window, ctx, title_str); flip(ctx); yutani_flip(yctx, window); } -int main(int argc, char * argv[]) { - struct utsname u; - uname(&u); +static void init_default(void) { + title_str = "About ToaruOS-NIH"; + icon_path = "/usr/share/logo_login.bmp"; - version_str = strdup(u.release); - char * tmp = strstr(version_str, "-"); - if (tmp) { - *tmp = '\0'; + { + version_str = malloc(100); + struct utsname u; + uname(&u); + sprintf(version_str, "ToaruOS-NIH %s", u.release); } + copyright_str[0] = "(C) 2011-2018 K. Lange, et al."; + copyright_str[1] = "-"; + copyright_str[2] = "ToaruOS is free software released under the"; + copyright_str[3] = "NCSA/University of Illinois license."; + copyright_str[4] = "-"; + copyright_str[5] = "%https://toaruos.org"; + copyright_str[6] = "%https://github.com/klange/toaru-nih"; + +} + +int main(int argc, char * argv[]) { yctx = yutani_init(); init_decorations(); window = yutani_window_create(yctx, width + decor_width(), height + decor_height()); yutani_window_move(yctx, window, yctx->display_width / 2 - window->width / 2, yctx->display_height / 2 - window->height / 2); - yutani_window_advertise_icon(yctx, window, TITLE, "star"); + if (argc < 2) { + init_default(); + } else if (argc < 5) { + fprintf(stderr, "Invalid arguments.\n"); + return 1; + } else { + title_str = argv[1]; + icon_path = argv[2]; + version_str = argv[3]; + + int i = 0; + char * me = argv[4], * end; + do { + copyright_str[i] = me; + i++; + end = strchr(me,'\n'); + if (end) { + *end = '\0'; + me = end+1; + } + } while (end); + } + + yutani_window_advertise_icon(yctx, window, title_str, "star"); ctx = init_graphics_yutani_double_buffer(window); - load_sprite(&logo, "/usr/share/logo_login.bmp"); + load_sprite(&logo, icon_path); logo.alpha = ALPHA_EMBEDDED; redraw(); diff --git a/apps/file-browser.c b/apps/file-browser.c index c1f4e5e3..4e0e4b4d 100644 --- a/apps/file-browser.c +++ b/apps/file-browser.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -64,10 +65,16 @@ static void _menu_action_up(struct MenuEntry * entry) { static void _menu_action_help(struct MenuEntry * entry) { /* show help documentation */ + if (!fork()) { + system("help-browser file-browser.trt"); + } } static void _menu_action_about(struct MenuEntry * entry) { /* Show About dialog */ + if (!fork()) { + system("about \"About File Browser\" /usr/share/icons/48/folder.bmp \"ToaruOS File Browser\" \"(C) 2018 K. Lange\n-\nPart of ToaruOS, which is free software\nreleased under the NCSA/University of Illinois\nlicense.\n-\n%https://toaruos.org\n%https://github.com/klange/toaru-nih\""); + } } int main(int argc, char * argv[]) { diff --git a/apps/help-browser.c b/apps/help-browser.c index c8e657eb..c7943a2c 100644 --- a/apps/help-browser.c +++ b/apps/help-browser.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -64,6 +65,9 @@ static void _menu_action_forward(struct MenuEntry * entry) { static void _menu_action_about(struct MenuEntry * entry) { /* Show About dialog */ + if (!fork()) { + system("about \"About Help Browser\" /usr/share/icons/48/help.bmp \"ToaruOS Help Browser\" \"(C) 2018 K. Lange\n-\nPart of ToaruOS, which is free software\nreleased under the NCSA/University of Illinois\nlicense.\n-\n%https://toaruos.org\n%https://github.com/klange/toaru-nih\""); + } } int main(int argc, char * argv[]) { diff --git a/apps/terminal.c b/apps/terminal.c index 6de7c5c6..9d02392c 100644 --- a/apps/terminal.c +++ b/apps/terminal.c @@ -1792,6 +1792,18 @@ void _menu_action_hide_borders(struct MenuEntry * self) { reinit(1); } +void _menu_action_show_about(struct MenuEntry * self) { + if (!fork()) { + system("about \"About Terminal\" /usr/share/icons/48/utilities-terminal.bmp \"ToaruOS Terminal\" \"(C) 2013-2018 K. Lange\n-\nPart of ToaruOS, which is free software\nreleased under the NCSA/University of Illinois\nlicense.\n-\n%https://toaruos.org\n%https://github.com/klange/toaru-nih\""); + } +} + +void _menu_action_show_help(struct MenuEntry * self) { + if (!fork()) { + system("help-browser terminal.trt"); + } +} + void _menu_action_copy(struct MenuEntry * self) { copy_selection(); } @@ -1943,9 +1955,9 @@ int main(int argc, char ** argv) { menu_set_insert(terminal_menu_bar.set, "view", m); m = menu_create(); - menu_insert(m, menu_create_normal("help","help","Contents", NULL)); + menu_insert(m, menu_create_normal("help","help","Contents", _menu_action_show_help)); menu_insert(m, menu_create_separator()); - menu_insert(m, menu_create_normal("star","star","About Terminal", NULL)); + menu_insert(m, menu_create_normal("star","star","About Terminal", _menu_action_show_about)); menu_set_insert(terminal_menu_bar.set, "help", m);