1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <stdio.h>
#include <saffron.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h>
#include <SDL3/SDL_render.h>
/* PLEASE don't do this in production!
* when wrappers are implemented,
* THEY will make draw functions for you
* THIS IS A BAD IDEA */
void my_test_draw(SaffronWidget* self, SDL_Renderer* renderer) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_FRect rect = {self->x, self->y, self->w, self->h};
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderRect(renderer, &rect);
}
/* YET AGAIN DONT DO THIS IN PROD PLEASE
* this is very lunatic */
void my_test_onclick(SaffronWidget* self) {
printf("clicked!\n");
}
int main(void) {
saffron_init();
SaffronWindow* window = saffron_window_new("saffron test", 800, 600);
/* i guess IM THE LUNATIC NOW
* DEAL WITH IT */
SaffronWidget* test = saffron_widget_new();
test->x = 100;
test->y = 100;
test->w = 200;
test->h = 150;
test->draw = my_test_draw;
test->on_click = my_test_onclick;
/* lunatic method 2 */
SaffronWidget* test2 = saffron_widget_new();
test2->x = 150;
test2->y = 500;
test2->w = 300;
test2->h = 170;
test2->draw = my_test_draw;
saffron_widget_add_child(window->root, test);
saffron_widget_add_child(window->root, test2);
saffron_window_main(window);
saffron_window_free(window);
saffron_quit();
return 0;
}
|