How to open a window ?¶
To create a windowed-application, haiku provides the hk_window_t*
object to manage a canvas and keyboard/mouse inputs.
Window creation/cleanup¶
hk_window_t*
is the second “owning” pointer returned by haiku.
It means that the user has to manage its lifetime through the application.
/* Creating a window object */
hk_window_t* window = hkapp_window_create( &(hk_app_window_desc)
{
// Title of the application (on-top of window)
.name = "MyWindow",
// requested frame width
.width = app_frame_width,
// requested frame height
.height = app_frame_height,
// allows to resize canvas
.resizable = true,
});
This call has a respective destroy function named hkapp_window_destroy
to call at the end of your program.
Application mainloop¶
Here is a snippet of a simple main loop for a windowed-application using haiku:
/* Main loop */
while(hkapp_window_is_running(window))
{
/* Checking/Updating application events */
hkapp_window_poll(window);
/* If user press ESCAPE key, leave the application */
if(hkapp_is_key_just_pressed(window,HK_KEY_ESCAPE)) {
hkapp_window_close(window);
}
/* User code */
}