From 4f99c4289fb46e06c0ff305d12276cfc9fb5cf9c Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Tue, 30 May 2023 17:23:06 +0200 Subject: Add test folder --- test/test1.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 test/test1.c (limited to 'test/test1.c') diff --git a/test/test1.c b/test/test1.c new file mode 100644 index 0000000..c2bbfac --- /dev/null +++ b/test/test1.c @@ -0,0 +1,99 @@ +/* See LICENSE file for copyright and license details. */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +static void +app_deactivated(CherryApplication *app, void *data) +{ + printf("Deactivated\n"); +} + +int +listener1(CherryWindow *w, CherryEvent evt) +{ + char hello[] = "Example 1"; + char hi[] = "Hi!"; + + KeySym mykey; + char text[10]; + int i; + + switch (evt.event_id) { + case WINDOW_DELETED: + printf("Listener1\n"); + cherry_window_dispose_on_exit(w); + break; + case WINDOW_EXPOSED: + XDrawImageString(evt.display, + evt.window, + w->gc, + 50, 50, + hello, strlen(hello)); + break; + case MOUSE_BUTTON_PRESSED: + XDrawImageString(evt.display, + evt.window, + w->gc, + evt.mouse.x, evt.mouse.y, + hi, strlen(hi)); + break; + case KEY_PRESSED: + i = XLookupString(&evt.key.xkey, text, 10, &mykey, 0); + if (i == 1 && text[0] == 'q') cherry_window_dispose_on_exit(w); + break; + } + + return 0; +} + + int +listener2(CherryWindow *w, CherryEvent evt) +{ + switch (evt.event_id) { + case WINDOW_DELETED: + printf("Listener2\n"); + break; + } + + return 0; +} + +static void +app_activated(CherryApplication *app, void *data) +{ + CherryWindow *w = cherry_window_new(); + cherry_window_set_title(w, "Hello from another World!"); + cherry_window_set_dimension(w, 350, 250); + cherry_window_set_position(w, 200, 300); + cherry_window_set_listener(w, listener1); + + CherryWindow *w2 = cherry_window_new(); + cherry_window_set_title(w2, "The second window"); + cherry_window_set_dimension(w2, 350, 250); + cherry_window_set_position(w2, 500, 300); + cherry_window_set_listener(w2, listener2); + + /* show up window */ + cherry_window_set_visible(w, 1); + cherry_window_set_visible(w2, 1); +} + +int +test1(int argc, char **argv) +{ + puts("Running test1..."); + + CherryApplication *app = cherry_application_new("Just a test!"); + cherry_application_set_activated_listener(app, app_activated, NULL); + cherry_application_set_deactivated_listener(app, app_deactivated, NULL); + + return cherry_application_run(app, argc, argv); +} -- cgit v1.2.3