Make the blur test app interactive
Type to change the text. Resize if you need more space. Alt+F4 to quit. (And remember, focus follows mouse, but does not go through transparent windows, so if you're in the right box, you'll be fine)
This commit is contained in:
parent
8c1a213696
commit
8b29bd7e21
@ -7,6 +7,10 @@
|
||||
gfx_context_t * ctx;
|
||||
window_t * window;
|
||||
|
||||
#define INPUT_SIZE 512
|
||||
char input_buffer[INPUT_SIZE] = {0};
|
||||
int input_collected = 0;
|
||||
|
||||
void display() {
|
||||
gfx_context_t * tmp_c, * out_c;
|
||||
sprite_t * tmp_s, * out_s;
|
||||
@ -18,11 +22,11 @@ void display() {
|
||||
out_c = init_graphics_sprite(out_s);
|
||||
|
||||
draw_fill(tmp_c, rgba(0,0,0,0));
|
||||
draw_string(tmp_c, 20, 20, rgb(0,0,0), "Hello World");
|
||||
draw_string(tmp_c, 20, 20, rgb(0,0,0), input_buffer);
|
||||
|
||||
blur_context(out_c, tmp_c, 3);
|
||||
|
||||
draw_string(out_c, 19, 19, rgb(255,255,255), "Hello World");
|
||||
draw_string(out_c, 19, 19, rgb(255,255,255), input_buffer);
|
||||
|
||||
draw_fill(ctx, rgba(0,0,0,0));
|
||||
draw_sprite(ctx, out_s, 0, 0);
|
||||
@ -42,10 +46,30 @@ void display() {
|
||||
void resize_callback(window_t * win) {
|
||||
reinit_graphics_window(ctx, window);
|
||||
|
||||
draw_fill(ctx, rgb(0,0,0));
|
||||
display();
|
||||
}
|
||||
|
||||
int buffer_put(char c) {
|
||||
if (c == 8) {
|
||||
/* Backspace */
|
||||
if (input_collected > 0) {
|
||||
input_collected--;
|
||||
input_buffer[input_collected] = '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (c < 10 || (c > 10 && c < 32) || c > 126) {
|
||||
return 0;
|
||||
}
|
||||
input_buffer[input_collected] = c;
|
||||
input_collected++;
|
||||
input_buffer[input_collected] = '\0';
|
||||
if (input_collected == INPUT_SIZE - 1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
setup_windowing();
|
||||
|
||||
@ -53,11 +77,11 @@ int main(int argc, char * argv[]) {
|
||||
window = window_create(40, 40, 200, 30);
|
||||
ctx = init_graphics_window_double_buffer(window);
|
||||
|
||||
draw_fill(ctx, rgba(0,0,0,0));
|
||||
window_enable_alpha(window);
|
||||
|
||||
init_shmemfonts();
|
||||
|
||||
buffer_put('$');
|
||||
display();
|
||||
|
||||
int playing = 1;
|
||||
@ -68,16 +92,17 @@ int main(int argc, char * argv[]) {
|
||||
do {
|
||||
kbd = poll_keyboard();
|
||||
if (kbd != NULL) {
|
||||
ch = kbd->key;
|
||||
if ((kbd->event.modifiers & KEY_MOD_LEFT_ALT) && (kbd->event.keycode == KEY_F4)) {
|
||||
playing = 0;
|
||||
break;
|
||||
}
|
||||
if (kbd->key) {
|
||||
buffer_put(kbd->key);
|
||||
display();
|
||||
}
|
||||
free(kbd);
|
||||
}
|
||||
} while (kbd != NULL);
|
||||
|
||||
switch (ch) {
|
||||
case 'q':
|
||||
playing = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
teardown_windowing();
|
||||
|
Loading…
x
Reference in New Issue
Block a user