toaruos/userspace/drawlines.c

66 lines
1.2 KiB
C
Raw Normal View History

/*
* drawlines
*
* Test application to draw lines to a window.
*/
2012-02-12 04:54:34 +04:00
#include <stdlib.h>
#include <assert.h>
#include "lib/window.h"
#include "lib/graphics.h"
2012-02-12 04:54:34 +04:00
2012-11-16 11:33:45 +04:00
int left, top, width, height;
window_t * wina;
gfx_context_t * ctx;
2012-02-12 04:54:34 +04:00
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;
}
2012-11-16 11:33:45 +04:00
void resize_callback(window_t * window) {
width = window->width;
height = window->height;
reinit_graphics_window(ctx, wina);
draw_fill(ctx, rgb(0,0,0));
}
2012-02-12 04:54:34 +04:00
2012-11-16 11:33:45 +04:00
int main (int argc, char ** argv) {
left = 100;
top = 100;
width = 500;
height = 500;
2012-02-12 04:54:34 +04:00
2012-11-16 11:33:45 +04:00
setup_windowing();
resize_window_callback = resize_callback;
2012-02-13 03:00:21 +04:00
2012-02-12 04:54:34 +04:00
/* Do something with a window */
2012-11-16 11:33:45 +04:00
wina = window_create(left, top, width, height);
2012-02-12 04:54:34 +04:00
assert(wina);
2012-11-16 11:33:45 +04:00
ctx = init_graphics_window(wina);
draw_fill(ctx, rgb(0,0,0));
int exit = 0;
while (!exit) {
w_keyboard_t * kbd = poll_keyboard();
if (kbd != NULL) {
2012-02-17 11:28:12 +04:00
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));
2012-02-12 04:54:34 +04:00
}
teardown_windowing();
return 0;
}