fbee

view test.c @ 1:2471e9b63432

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 07 Feb 2013 16:03:32 +0200
parents
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "fbee.h"
6 void draw(void *cls);
7 void keyb(int key, int state, void *cls);
8 void mouse_button(int bn, int state, void *cls);
9 void mouse_motion(int x, int y, void *cls);
11 int width = 640, height = 480, bpp = 32;
12 int mouse_x, mouse_y;
13 int bnstate[8];
15 int main(void)
16 {
17 if(fbee_init() == -1) {
18 return 1;
19 }
21 fbee_set_video_mode(width, height, bpp, 0);
22 fbee_get_video_mode(&width, &height, &bpp);
24 printf("got video mode: %dx%d-%dbpp\n", width, height, bpp);
26 fbee_event_func(FBEE_EV_DRAW, draw, 0);
27 fbee_event_func(FBEE_EV_KEY, keyb, 0);
28 fbee_event_func(FBEE_EV_BUTTON, mouse_button, 0);
29 fbee_event_func(FBEE_EV_MOTION, mouse_motion, 0);
31 {
32 unsigned char *fb = fbee_framebuffer();
33 memset(fb, 0x80, width * height * bpp / 8);
34 }
36 fbee_evloop();
37 return 0;
38 }
40 void draw(void *cls)
41 {
42 unsigned char *fb = fbee_framebuffer();
43 if(bnstate[0]) {
44 fb[(mouse_y * width + mouse_x) * 4 + 1] = 255;
45 }
47 fbee_update(0);
48 }
50 void keyb(int key, int state, void *cls)
51 {
52 if(key == 27) {
53 exit(0);
54 }
55 }
57 void mouse_button(int bn, int state, void *cls)
58 {
59 bnstate[bn] = state;
60 fbee_redisplay();
61 }
63 void mouse_motion(int x, int y, void *cls)
64 {
65 mouse_x = x;
66 mouse_y = y;
67 fbee_redisplay();
68 }