Start here
Your first window
How do you open a window and paint it? Fill in one structure, give it a function that writes pixels, and run it.
What does the smallest window look like?
This is a whole program. Windows asks for the picture, and paint writes it. Each pixel is 0x00RRGGBB, top row first.
#include <impossible/window.h>
static void paint(im_window *window, im_canvas *canvas) {
(void)window;
for (int i = 0; i < canvas->width * canvas->height; i++)
canvas->pixels[i] = 0x00102040;
}
int im_main(void) {
im_window window = {.title = L"First window", .width = 640, .height = 400, .paint = paint};
return im_window_run(&window, false) ? 0 : 1;
}Note A window needs
WINDOW TIER 1inCMakeLists.txt. At tier 0 the build stops and names the functions that are too many.
How does it answer the pointer?
Add an event function. Return true and the window is painted again. This is the one of the window sample, which keeps the pointer's place in its own structure:
static bool event(im_window *window, const im_event *event) {
if (event->kind != IM_POINTER_MOVE) return false;
*(state *)window->user = (state){event->x, event->y};
return true;
}The kinds of event are pointer move, down and up, and a key going down. window.h lists them.
What happens on a screen at 150 percent?
The width and height you give are for 100 percent. The canvas you get is already in real pixels, and canvas->scale is 1.5, so multiply your own sizes by it. Moving the window to a screen with another scale paints it again at that scale.
How do you draw more than a colour?
Impossible UI draws rounded shapes and buttons into the same pixels. Drawing shows how.
include/impossible/window.h, samples/window/main.cEdit this pagePublished from dfbf2d3