comparison src/adventure/main.c @ 115:3bd0d3a39e30

core: implement checkbox, closes #2486
author David Demelier <markand@malikania.fr>
date Sun, 12 Jul 2020 09:44:27 +0200
parents 4ac71ac10c9f
children
comparison
equal deleted inserted replaced
114:bf7500aea454 115:3bd0d3a39e30
21 #include <stdlib.h> 21 #include <stdlib.h>
22 #include <stdnoreturn.h> 22 #include <stdnoreturn.h>
23 #include <string.h> 23 #include <string.h>
24 24
25 #include "button.h" 25 #include "button.h"
26 #include "checkbox.h"
26 #include "clock.h" 27 #include "clock.h"
27 #include "debug.h" 28 #include "debug.h"
28 #include "error.h" 29 #include "error.h"
29 #include "event.h" 30 #include "event.h"
30 #include "font.h" 31 #include "font.h"
81 82
82 static void 83 static void
83 run(void) 84 run(void)
84 { 85 {
85 struct clock clock = { 0 }; 86 struct clock clock = { 0 };
86 struct button button = { 87 struct frame mainmenu = {
87 .text = "click me",
88 .x = 10, 88 .x = 10,
89 .y = 40, 89 .y = 10,
90 .w = 100, 90 .w = 200,
91 .h = 30 91 .h = 64
92 };
93 struct checkbox cb = {
94 .label = "Play hard mode",
95 .x = 20,
96 .y = 20,
97 .w = 200,
98 .h = 16
92 }; 99 };
93 100
94 for (;;) { 101 for (;;) {
95 unsigned int elapsed = clock_elapsed(&clock); 102 unsigned int elapsed = clock_elapsed(&clock);
96 103
99 for (union event ev; event_poll(&ev); ) { 106 for (union event ev; event_poll(&ev); ) {
100 switch (ev.type) { 107 switch (ev.type) {
101 case EVENT_QUIT: 108 case EVENT_QUIT:
102 return; 109 return;
103 default: 110 default:
104 button_handle(&button, &ev); 111 checkbox_handle(&cb, &ev);
105
106 if (button.state == BUTTON_STATE_ACTIVATED) {
107 puts("CLICKED!!!");
108 button_reset(&button);
109 }
110
111 break; 112 break;
112 } 113 }
113 } 114 }
114 115
115 printf("%d\n", button.state);
116
117 painter_set_color(0xffffffff); 116 painter_set_color(0xffffffff);
118 painter_clear(); 117 painter_clear();
119 118
120 theme_draw_frame(NULL, &(const struct frame){ .x=10, .y=10, .w=500, .h=500 }); 119 theme_draw_frame(NULL, &(const struct frame){ .x=10, .y=10, .w=500, .h=500 });
121 label_draw(&(const struct label){ .text = "Hello for this quest.", .x=20, .y=20, .w=100, .h=100 }); 120 checkbox_draw(&cb);
122 button_draw(&button);
123 121
124 painter_present(); 122 painter_present();
125 123
126 if ((elapsed = clock_elapsed(&clock)) < 20) 124 if ((elapsed = clock_elapsed(&clock)) < 20)
127 delay(20 - elapsed); 125 delay(20 - elapsed);