From 47b5b3e2cc31f7bba9b865bd264df5dbd10368ab Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 31 Mar 2024 13:08:01 +0200 Subject: [PATCH] Add examples --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index fe349d4..15f6563 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,64 @@ To build programs using libwind, include `wind.h` and link with libwind: `-lwind As the wind client protocol is still in the early stages of development, it is subject to change at any time. This library should be updated as soon as possible whenever that happens, so make sure to always have both the latest version of the [Luna](https://git.cloudapio.eu/apio/Luna) repository as well as this one. +## Examples + +Connecting to the `wind` server: + +``` +wind_client_t client; +wind_connect(&client, WIND_SOCKET_PATH, 0); +``` + +Creating a new window: +``` +wind_window_t window; +struct wind_rect rect = { + .pos = {0, 0}, + .width = 640, + .height = 320 +}; + +wind_create_window(&client, &window, rect); +``` + +Drawing to a window: +``` +memset(window.canvas, 0xff, window.rect.width*window.rect.height*4); +wind_invalidate(&client, &window); +``` + +Handling events: +``` +int event_handler(wind_client_t*, uint8_t event, void* arg) +{ + switch (event) + { + case wind_MouseEvent: { + struct wind_mouse_event_request event_data; + wind_read_response(&client, event, &event_data, sizeof event_data); + // Do something + break; + } + case wind_MouseLeave: { + struct wind_mouse_leave_request event_data; + wind_read_response(&client, event, &event_data, sizeof event_data); + // Do something + break; + } + case wind_KeyEvent: { + struct wind_key_event_request event_data; + wind_read_response(&client, event, &event_data, sizeof event_data); + // Do something + break; + } + } +} + +wind_set_handler(&client, event_handler, NULL); +wind_check_for_messages(&client); +``` + ## License libwind is free and open-source software under the [BSD-2-Clause License](LICENSE). \ No newline at end of file