2012-04-20 05:21:19 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* Wallpaper renderer.
|
|
|
|
*
|
|
|
|
*/
|
2012-03-08 08:31:24 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2012-09-20 08:16:21 +04:00
|
|
|
#include <unistd.h>
|
2012-03-08 08:31:24 +04:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "lib/window.h"
|
|
|
|
#include "lib/graphics.h"
|
2012-10-16 06:23:47 +04:00
|
|
|
#include "lib/shmemfonts.h"
|
2012-03-08 08:31:24 +04:00
|
|
|
|
|
|
|
sprite_t * sprites[128];
|
|
|
|
sprite_t alpha_tmp;
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
#define ICON_X 24
|
|
|
|
#define ICON_TOP_Y 40
|
|
|
|
#define ICON_SPACING_Y 74
|
|
|
|
#define ICON_WIDTH 48
|
|
|
|
|
2012-03-08 08:31:24 +04:00
|
|
|
uint16_t win_width;
|
|
|
|
uint16_t win_height;
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
gfx_context_t * ctx;
|
2012-03-08 08:31:24 +04:00
|
|
|
|
|
|
|
int center_x(int x) {
|
|
|
|
return (win_width - x) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int center_y(int y) {
|
|
|
|
return (win_height - y) / 2;
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:04:18 +04:00
|
|
|
static int event_pipe;
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
typedef struct {
|
|
|
|
char * icon;
|
|
|
|
char * appname;
|
|
|
|
char * title;
|
|
|
|
} application_t;
|
|
|
|
|
|
|
|
application_t applications[] = {
|
|
|
|
{"/usr/share/icons/utilities-terminal.png", "terminal", "Terminal"},
|
2012-10-16 06:23:47 +04:00
|
|
|
{"/usr/share/icons/applications-painting.png", "draw", "Draw!"},
|
|
|
|
{"/usr/share/icons/applications-simulation.png", "game", "RPG Demo"},
|
2013-03-31 08:18:17 +04:00
|
|
|
{"/usr/share/icons/julia.png", "julia", "Julia Fractals"},
|
2012-09-20 08:16:21 +04:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
volatile int _continue = 1;
|
|
|
|
|
|
|
|
void sig_int(int sig) {
|
|
|
|
printf("Received shutdown signal in wallpaper!\n");
|
|
|
|
_continue = 0;
|
2012-12-11 09:04:18 +04:00
|
|
|
char buf = '1';
|
|
|
|
write(event_pipe, &buf, 1);
|
2012-09-13 11:29:29 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
void launch_application(char * app) {
|
|
|
|
if (!fork()) {
|
|
|
|
char name[512];
|
|
|
|
sprintf(name, "/bin/%s", app);
|
|
|
|
printf("Starting %s\n", name);
|
|
|
|
char * args[] = {name, NULL};
|
2012-10-08 11:17:50 +04:00
|
|
|
execvp(args[0], args);
|
2012-09-20 08:16:21 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char * next_run_activate = NULL;
|
|
|
|
|
|
|
|
void wallpaper_check_click(w_mouse_t * evt) {
|
|
|
|
if (evt->command == WE_MOUSECLICK) {
|
|
|
|
printf("Click!\n");
|
|
|
|
if (evt->new_x > ICON_X && evt->new_x < ICON_X + ICON_WIDTH) {
|
|
|
|
uint32_t i = 0;
|
|
|
|
while (1) {
|
|
|
|
if (!applications[i].icon) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((evt->new_y > ICON_TOP_Y + ICON_SPACING_Y * i) &&
|
|
|
|
(evt->new_y < ICON_TOP_Y + ICON_SPACING_Y + ICON_SPACING_Y * i)) {
|
|
|
|
printf("Launching application \"%s\"...\n", applications[i].title);
|
|
|
|
next_run_activate = applications[i].appname;
|
2012-12-11 09:04:18 +04:00
|
|
|
char buf = '1';
|
|
|
|
write(event_pipe, &buf, 1);
|
2012-09-20 08:16:21 +04:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
/* Within the icon range */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_sprite_png(int i, char * filename) {
|
|
|
|
sprites[i] = malloc(sizeof(sprite_t));
|
|
|
|
load_sprite_png(sprites[i], filename);
|
|
|
|
}
|
|
|
|
|
2012-03-08 08:31:24 +04:00
|
|
|
int main (int argc, char ** argv) {
|
2012-03-08 08:40:58 +04:00
|
|
|
setup_windowing();
|
2012-03-08 08:31:24 +04:00
|
|
|
|
2012-03-08 08:40:58 +04:00
|
|
|
int width = wins_globals->server_width;
|
|
|
|
int height = wins_globals->server_height;
|
2012-03-08 08:31:24 +04:00
|
|
|
|
|
|
|
win_width = width;
|
|
|
|
win_height = height;
|
|
|
|
|
2012-12-11 09:04:18 +04:00
|
|
|
event_pipe = syscall_mkpipe();
|
|
|
|
|
2012-03-08 08:31:24 +04:00
|
|
|
/* Do something with a window */
|
|
|
|
window_t * wina = window_create(0,0, width, height);
|
|
|
|
assert(wina);
|
|
|
|
window_reorder (wina, 0);
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
ctx = init_graphics_window_double_buffer(wina);
|
2012-04-18 00:34:34 +04:00
|
|
|
draw_fill(ctx, rgb(127,127,127));
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
flip(ctx);
|
2012-03-08 08:31:24 +04:00
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
syscall_signal(2, sig_int);
|
|
|
|
|
2012-10-17 07:42:48 +04:00
|
|
|
char f_name[512];
|
|
|
|
sprintf(f_name, "%s/.wallpaper.png", getenv("HOME"));
|
|
|
|
FILE * f = fopen(f_name, "r");
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
init_sprite_png(0, f_name);
|
|
|
|
} else {
|
|
|
|
init_sprite_png(0, "/usr/share/wallpaper.png");
|
|
|
|
}
|
2012-11-17 06:37:39 +04:00
|
|
|
|
|
|
|
float x = (float)width / (float)sprites[0]->width;
|
|
|
|
float y = (float)height / (float)sprites[0]->height;
|
|
|
|
|
|
|
|
int nh = (int)(x * (float)sprites[0]->height);
|
|
|
|
int nw = (int)(y * (float)sprites[0]->width);;
|
|
|
|
|
|
|
|
if (nw > width) {
|
|
|
|
draw_sprite_scaled(ctx, sprites[0], (width - nw) / 2, 0, nw, height);
|
|
|
|
} else {
|
|
|
|
draw_sprite_scaled(ctx, sprites[0], 0, (height - nh) / 2, width, nh);
|
|
|
|
}
|
2012-09-20 08:16:21 +04:00
|
|
|
flip(ctx);
|
|
|
|
|
2012-10-16 06:23:47 +04:00
|
|
|
init_shmemfonts();
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
/* Load Application Shortcuts */
|
|
|
|
uint32_t i = 0;
|
|
|
|
while (1) {
|
|
|
|
if (!applications[i].icon) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("Loading png %s\n", applications[i].icon);
|
|
|
|
init_sprite_png(i+1, applications[i].icon);
|
|
|
|
draw_sprite(ctx, sprites[i+1], ICON_X, ICON_TOP_Y + ICON_SPACING_Y * i);
|
2012-10-16 06:23:47 +04:00
|
|
|
|
|
|
|
int str_w = draw_string_width(applications[i].title) / 2;
|
|
|
|
int str_x = ICON_X + ICON_WIDTH / 2 - str_w;
|
|
|
|
int str_y = ICON_TOP_Y + ICON_SPACING_Y * i + ICON_WIDTH + 14;
|
2012-10-17 06:05:58 +04:00
|
|
|
draw_string_shadow(ctx, str_x, str_y, rgb(255,255,255), applications[i].title, rgb(0,0,0), 2, 1, 1, 3.0);
|
2012-10-16 06:23:47 +04:00
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
++i;
|
|
|
|
}
|
2012-03-08 08:31:24 +04:00
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
flip(ctx);
|
2012-03-08 08:31:24 +04:00
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
/* Enable mouse */
|
|
|
|
win_use_threaded_handler();
|
|
|
|
mouse_action_callback = wallpaper_check_click;
|
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
while (_continue) {
|
2012-12-11 09:04:18 +04:00
|
|
|
char buf;
|
|
|
|
read(event_pipe, &buf, 1);
|
2012-09-20 08:16:21 +04:00
|
|
|
if (next_run_activate) {
|
|
|
|
launch_application(next_run_activate);
|
|
|
|
next_run_activate = NULL;
|
|
|
|
}
|
2012-03-08 09:44:02 +04:00
|
|
|
}
|
|
|
|
|
2012-03-08 08:31:24 +04:00
|
|
|
teardown_windowing();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|