aboutsummaryrefslogtreecommitdiff
path: root/apps/view/main.c
blob: fc7e3bc81355c995a5ca9acfd282bc691d5d65fd (plain) (blame)
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
// MIT License, Copyright (c) 2021 Marvin Borner

#include <def.h>
#include <libgui/gui.h>

#define SCALING_FACTOR 0.1

static vec2 size = { 800, 800 };
static const char *path;

static void mousemove(struct gui_event_mouse *event)
{
	if (event->scroll) {
		size = vec2_mul(size, event->scroll < 0 ? SCALING_FACTOR + 1 : 1 - SCALING_FACTOR);
		gui_fill(event->win, event->widget, GUI_LAYER_FG, COLOR_WHITE);
		gui_draw_image(event->win, event->widget, GUI_LAYER_FG, vec2(0, 0), size, path);
		gui_redraw_widget(event->win, event->widget);
	}
}

int main(int argc, char *argv[])
{
	UNUSED(argc);
	UNUSED(argv);

	path = "/res/test.png";

	u32 win = gui_custom_window(APPNAME, vec2(0, 0), size);
	u32 canvas = gui_widget(win, gui_main_widget(win), vec2(0, 0), size);
	gui_fill(win, canvas, GUI_LAYER_BG, COLOR_WHITE);
	gui_widget_listen(win, canvas, GUI_LISTEN_MOUSEMOVE, (u32)mousemove);

	gui_redraw_window(win);
	gui_loop();

	return 0;
}