Add flexible about dialogs

This commit is contained in:
K. Lange 2018-06-04 12:35:46 +09:00
parent 39a1cc73d3
commit e68dfe20b6
4 changed files with 89 additions and 21 deletions

View File

@ -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();

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <unistd.h>
#include <toaru/yutani.h>
#include <toaru/graphics.h>
@ -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[]) {

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <unistd.h>
#include <toaru/yutani.h>
#include <toaru/graphics.h>
@ -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[]) {

View File

@ -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);