2012-07-07 08:08:28 +04:00
|
|
|
/*
|
|
|
|
* view
|
|
|
|
*
|
|
|
|
* Displays bitmap images in windows
|
|
|
|
*/
|
2012-02-26 08:47:20 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "lib/window.h"
|
|
|
|
#include "lib/graphics.h"
|
|
|
|
|
|
|
|
sprite_t * sprites[128];
|
|
|
|
sprite_t alpha_tmp;
|
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-02-26 08:47:20 +04:00
|
|
|
|
|
|
|
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 {
|
|
|
|
sprites[i]->alpha = 0;
|
|
|
|
}
|
|
|
|
sprites[i]->blank = 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char ** argv) {
|
2012-03-08 12:50:33 +04:00
|
|
|
if (argc < 2) {
|
|
|
|
printf("usage: %s file\n", argv[0]);
|
2012-02-26 08:47:20 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-08 12:50:33 +04:00
|
|
|
int left = 30;
|
|
|
|
int top = 30;
|
2012-02-26 08:47:20 +04:00
|
|
|
|
2012-09-14 10:22:38 +04:00
|
|
|
if (strstr(argv[1], ".png")) {
|
|
|
|
sprites[0] = malloc(sizeof(sprite_t));
|
|
|
|
load_sprite_png(sprites[0], argv[1]);
|
|
|
|
} else {
|
|
|
|
init_sprite(0, argv[1], NULL);
|
|
|
|
}
|
2012-02-26 08:47:20 +04:00
|
|
|
|
|
|
|
int width = sprites[0]->width;
|
|
|
|
int height = sprites[0]->height;
|
|
|
|
|
|
|
|
setup_windowing();
|
|
|
|
|
|
|
|
/* Do something with a window */
|
|
|
|
window_t * wina = window_create(left, top, width, 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
|
|
|
ctx = init_graphics_window(wina);
|
|
|
|
draw_fill(ctx, rgb(0,0,0));
|
2012-02-26 08:47:20 +04:00
|
|
|
|
2012-09-14 10:22:38 +04:00
|
|
|
if (sprites[0]->alpha == ALPHA_EMBEDDED) {
|
|
|
|
draw_fill(ctx, rgba(0,0,0,0));
|
|
|
|
window_enable_alpha(wina);
|
|
|
|
}
|
|
|
|
|
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], 0, 0);
|
2012-02-26 08:47:20 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
w_keyboard_t * kbd = poll_keyboard();
|
|
|
|
if (kbd != NULL) {
|
|
|
|
if (kbd->key == 'q') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(kbd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_windowing();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|