About dialog

This commit is contained in:
K. Lange 2018-04-21 20:55:23 +09:00 committed by Kevin Lange
parent 0b2b0dc299
commit a69da36fe3
3 changed files with 142 additions and 0 deletions

141
apps/about.c Normal file
View File

@ -0,0 +1,141 @@
#include <toaru/yutani.h>
#include <toaru/graphics.h>
#include <toaru/decorations.h>
#include <toaru/sdf.h>
#include <sys/utsname.h>
static yutani_t * yctx;
static yutani_window_t * window = NULL;
static gfx_context_t * ctx = NULL;
static sprite_t logo;
static int32_t width = 350;
static int32_t height = 250;
static char * version_str;
#define TITLE "About ToaruOS-NIH"
static int center_x(int x) {
return (width - x) / 2;
}
static void draw_string(int y, const char * string, int font, uint32_t color) {
draw_sdf_string(ctx, decor_left_width + center_x(draw_sdf_string_width(string, 16, font)), decor_top_height + 10 + logo.height + 10 + y, string, 16, color, font);
}
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));
render_decorations(window, ctx, TITLE);
flip(ctx);
yutani_flip(yctx, window);
}
static void resize_finish(int w, int h) {
yutani_window_resize_accept(yctx, window, w, h);
reinit_graphics_yutani(ctx, window);
width = w - decor_left_width - decor_right_width;
height = h - decor_top_height - decor_bottom_height;
redraw();
yutani_window_resize_done(yctx, window);
yutani_flip(yctx, window);
}
int main(int argc, char * argv[]) {
struct utsname u;
uname(&u);
version_str = strdup(u.release);
char * tmp = strstr(version_str, "-");
if (tmp) {
*tmp = '\0';
}
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");
ctx = init_graphics_yutani_double_buffer(window);
load_sprite(&logo, "/usr/share/logo_login.bmp");
logo.alpha = ALPHA_EMBEDDED;
redraw();
int playing = 1;
while (playing) {
yutani_msg_t * m = yutani_poll(yctx);
if (m) {
switch (m->type) {
case YUTANI_MSG_KEY_EVENT:
{
struct yutani_msg_key_event * ke = (void*)m->data;
if (ke->event.action == KEY_ACTION_DOWN && ke->event.keycode == 'q') {
playing = 0;
}
}
break;
case YUTANI_MSG_WINDOW_FOCUS_CHANGE:
{
struct yutani_msg_window_focus_change * wf = (void*)m->data;
yutani_window_t * win = hashmap_get(yctx->windows, (void*)wf->wid);
if (win) {
win->focused = wf->focused;
redraw();
}
}
break;
#if 0
case YUTANI_MSG_RESIZE_OFFER:
{
struct yutani_msg_window_resize * wr = (void*)m->data;
resize_finish(wr->width, wr->height);
}
break;
#endif
case YUTANI_MSG_WINDOW_MOUSE_EVENT:
{
int result = decor_handle_event(yctx, m);
switch (result) {
case DECOR_CLOSE:
playing = 0;
break;
default:
/* Other actions */
break;
}
}
break;
case YUTANI_MSG_SESSION_END:
playing = 0;
break;
default:
break;
}
}
free(m);
}
yutani_close(yctx, window);
return 0;
}

View File

@ -2,3 +2,4 @@ utilities-terminal,terminal,Terminal
drawlines,drawlines,Draw Lines drawlines,drawlines,Draw Lines
julia,julia,Julia Fractals julia,julia,Julia Fractals
plasma,plasma,Plasma plasma,plasma,Plasma
star,about,About ToaruOS

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB