
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.
60 lines
1.3 KiB
C
60 lines
1.3 KiB
C
#include <stdlib.h>
|
|
#include <assert.h>
|
|
|
|
#include "lib/window.h"
|
|
#include "lib/graphics.h"
|
|
|
|
|
|
int32_t min(int32_t a, int32_t b) {
|
|
return (a < b) ? a : b;
|
|
}
|
|
|
|
int32_t max(int32_t a, int32_t b) {
|
|
return (a > b) ? a : b;
|
|
}
|
|
|
|
int main (int argc, char ** argv) {
|
|
if (argc < 5) {
|
|
printf("usage: %s left top width height\n", argv[0]);
|
|
return -1;
|
|
}
|
|
|
|
int left = atoi(argv[1]);
|
|
int top = atoi(argv[2]);
|
|
int width = atoi(argv[3]);
|
|
int height = atoi(argv[4]);
|
|
|
|
setup_windowing();
|
|
|
|
printf("[drawlines] Windowing ready for client[%d,%d,%d,%d]\n", left, top, width, height);
|
|
|
|
/* Do something with a window */
|
|
window_t * wina = window_create(left, top, width, height);
|
|
assert(wina);
|
|
|
|
gfx_context_t * ctx = init_graphics_window(wina);
|
|
draw_fill(ctx, rgb(0,0,0));
|
|
|
|
|
|
printf("[drawlines] Window drawn for client[%d,%d,%d,%d]\n", left, top, width, height);
|
|
|
|
int exit = 0;
|
|
while (!exit) {
|
|
w_keyboard_t * kbd = poll_keyboard();
|
|
if (kbd != NULL) {
|
|
printf("[drawlines] kbd=0x%x\n", kbd);
|
|
printf("[drawlines] got key '%c'\n", (char)kbd->key);
|
|
if (kbd->key == 'q')
|
|
exit = 1;
|
|
free(kbd);
|
|
}
|
|
|
|
draw_line(ctx, rand() % width, rand() % width, rand() % height, rand() % height, rgb(rand() % 255,rand() % 255,rand() % 255));
|
|
}
|
|
|
|
//window_destroy(wina); // (will close on exit)
|
|
teardown_windowing();
|
|
|
|
return 0;
|
|
}
|