2012-03-15 00:04:12 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
2012-07-07 08:08:28 +04:00
|
|
|
*
|
|
|
|
* Panel
|
|
|
|
*
|
|
|
|
* Provides a graphical panel with a clock, and
|
|
|
|
* hopefully more things in the future.
|
2012-03-15 00:04:12 +04:00
|
|
|
*/
|
2012-03-08 09:44:02 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
2012-10-10 08:02:43 +04:00
|
|
|
#include <sys/time.h>
|
2012-03-08 09:44:02 +04:00
|
|
|
|
2012-11-18 00:57:16 +04:00
|
|
|
#define PANEL_HEIGHT 28
|
|
|
|
|
2012-03-08 09:44:02 +04:00
|
|
|
#include "lib/window.h"
|
|
|
|
#include "lib/graphics.h"
|
2012-11-19 08:14:57 +04:00
|
|
|
#include "lib/shmemfonts.h"
|
2012-03-08 09:44:02 +04:00
|
|
|
|
|
|
|
sprite_t * sprites[128];
|
|
|
|
sprite_t alpha_tmp;
|
|
|
|
|
|
|
|
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 09:44:02 +04:00
|
|
|
|
2012-12-11 08:28:31 +04:00
|
|
|
DEFN_SYSCALL2(nanosleep, 46, unsigned long, unsigned long);
|
|
|
|
|
2012-03-08 09:44:02 +04:00
|
|
|
int center_x(int x) {
|
|
|
|
return (win_width - x) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int center_y(int y) {
|
|
|
|
return (win_height - y) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_sprite(int i, char * filename, char * alpha) {
|
|
|
|
sprites[i] = malloc(sizeof(sprite_t));
|
|
|
|
load_sprite(sprites[i], filename);
|
|
|
|
if (alpha) {
|
|
|
|
sprites[i]->alpha = 1;
|
|
|
|
load_sprite(&alpha_tmp, alpha);
|
|
|
|
sprites[i]->masks = alpha_tmp.bitmap;
|
|
|
|
} else {
|
2012-09-14 09:12:47 +04:00
|
|
|
sprites[i]->alpha = ALPHA_OPAQUE;
|
2012-03-08 09:44:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
void init_sprite_png(int i, char * filename) {
|
|
|
|
sprites[i] = malloc(sizeof(sprite_t));
|
|
|
|
load_sprite_png(sprites[i], filename);
|
|
|
|
}
|
|
|
|
|
2012-03-08 09:44:02 +04:00
|
|
|
#define FONT_SIZE 14
|
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
volatile int _continue = 1;
|
|
|
|
|
|
|
|
void sig_int(int sig) {
|
|
|
|
printf("Received shutdown signal in panel!\n");
|
|
|
|
_continue = 0;
|
|
|
|
}
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
void panel_check_click(w_mouse_t * evt) {
|
|
|
|
if (evt->command == WE_MOUSECLICK) {
|
|
|
|
printf("Click!\n");
|
|
|
|
if (evt->new_x >= win_width - 24 ) {
|
|
|
|
printf("Clicked log-out button. Good bye!\n");
|
|
|
|
_continue = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-08 09:44:02 +04:00
|
|
|
int main (int argc, char ** argv) {
|
|
|
|
setup_windowing();
|
|
|
|
|
|
|
|
int width = wins_globals->server_width;
|
|
|
|
int height = wins_globals->server_height;
|
|
|
|
|
|
|
|
win_width = width;
|
|
|
|
win_height = height;
|
|
|
|
|
2012-11-19 08:14:57 +04:00
|
|
|
init_shmemfonts();
|
|
|
|
set_font_size(14);
|
2012-03-08 09:44:02 +04:00
|
|
|
|
|
|
|
/* Create the panel */
|
2012-11-18 00:57:16 +04:00
|
|
|
window_t * panel = window_create(0, 0, width, PANEL_HEIGHT);
|
2012-03-08 09:44:02 +04:00
|
|
|
window_reorder (panel, 0xFFFF);
|
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(panel);
|
2012-11-18 00:57:16 +04:00
|
|
|
draw_fill(ctx, rgba(0,0,0,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
|
|
|
flip(ctx);
|
|
|
|
|
2012-11-18 00:57:16 +04:00
|
|
|
init_sprite_png(0, "/usr/share/panel.png");
|
2012-09-20 08:16:21 +04:00
|
|
|
init_sprite_png(1, "/usr/share/icons/panel-shutdown.png");
|
2012-03-08 09:44:02 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < width; i += sprites[0]->width) {
|
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
|
|
|
draw_sprite(ctx, sprites[0], i, 0);
|
2012-03-08 09:44:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t buf_size = panel->width * panel->height * sizeof(uint32_t);
|
|
|
|
char * buf = malloc(buf_size);
|
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
|
|
|
memcpy(buf, ctx->backbuffer, buf_size);
|
2012-03-08 09:44:02 +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 09:44:02 +04:00
|
|
|
|
|
|
|
struct timeval now;
|
|
|
|
int last = 0;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
char buffer[80];
|
|
|
|
|
2012-09-13 07:08:30 +04:00
|
|
|
char _uname[1024];
|
|
|
|
syscall_kernel_string_XXX(_uname);
|
|
|
|
|
|
|
|
char * os_version = strstr(_uname, " ");
|
|
|
|
os_version++;
|
|
|
|
char * tmp = strstr(os_version, " ");
|
|
|
|
tmp[0] = 0;
|
|
|
|
|
2012-09-06 07:19:52 +04:00
|
|
|
/* UTF-8 Strings FTW! */
|
2012-09-13 07:08:30 +04:00
|
|
|
uint8_t * os_name_ = "とあるOS";
|
|
|
|
uint8_t final[512];
|
|
|
|
uint32_t l = snprintf(final, 512, "%s %s", os_name_, os_version);
|
2012-09-06 07:19:52 +04:00
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
syscall_signal(2, sig_int);
|
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
/* Enable mouse */
|
|
|
|
win_use_threaded_handler();
|
|
|
|
mouse_action_callback = panel_check_click;
|
|
|
|
|
2012-09-13 11:29:29 +04:00
|
|
|
while (_continue) {
|
2012-03-08 09:44:02 +04:00
|
|
|
/* Redraw the background by memcpy (super speedy) */
|
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
|
|
|
memcpy(ctx->backbuffer, buf, buf_size);
|
2012-03-08 09:44:02 +04:00
|
|
|
syscall_gettimeofday(&now, NULL); //time(NULL);
|
|
|
|
if (now.tv_sec != last) {
|
|
|
|
last = now.tv_sec;
|
|
|
|
timeinfo = localtime((time_t *)&now.tv_sec);
|
|
|
|
strftime(buffer, 80, "%I:%M:%S %p", timeinfo);
|
|
|
|
|
2012-11-19 08:14:57 +04:00
|
|
|
draw_string(ctx, width - 120, 17, rgb(255,255,255), buffer);
|
|
|
|
draw_string(ctx, 10, 17, rgb(255,255,255), final);
|
2012-03-08 09:44:02 +04:00
|
|
|
|
2012-09-20 08:16:21 +04:00
|
|
|
draw_sprite(ctx, sprites[1], win_width - 23, 1); /* Logout button */
|
|
|
|
|
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-15 00:04:12 +04:00
|
|
|
}
|
2012-12-11 08:28:31 +04:00
|
|
|
syscall_nanosleep(0,50);
|
2012-03-08 09:44:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown_windowing();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|