Add examples
This commit is contained in:
parent
65d4da1d1f
commit
47b5b3e2cc
58
README.md
58
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).
|
Loading…
Reference in New Issue
Block a user