#pragma once #include #include /*! \file window.h \brief Provides functionality for creating and handling windows. */ #ifdef __cplusplus extern "C" { #endif typedef struct kinc_framebuffer_options { int frequency; bool vertical_sync; int color_bits; int depth_bits; int stencil_bits; int samples_per_pixel; } kinc_framebuffer_options_t; typedef enum { KINC_WINDOW_MODE_WINDOW, KINC_WINDOW_MODE_FULLSCREEN, KINC_WINDOW_MODE_EXCLUSIVE_FULLSCREEN // Only relevant for Windows } kinc_window_mode_t; #define KINC_WINDOW_FEATURE_RESIZEABLE 1 #define KINC_WINDOW_FEATURE_MINIMIZABLE 2 #define KINC_WINDOW_FEATURE_MAXIMIZABLE 4 #define KINC_WINDOW_FEATURE_BORDERLESS 8 #define KINC_WINDOW_FEATURE_ON_TOP 16 typedef struct kinc_window_options { const char *title; int x; int y; int width; int height; int display_index; bool visible; int window_features; kinc_window_mode_t mode; } kinc_window_options_t; /// /// Creates a window. /// /// The id of the created window KINC_FUNC int kinc_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *frame); /// /// Closes and destroys a window. /// KINC_FUNC void kinc_window_destroy(int window); KINC_FUNC void kinc_window_options_set_defaults(kinc_window_options_t *win); KINC_FUNC void kinc_framebuffer_options_set_defaults(kinc_framebuffer_options_t *frame); /// /// Counts all windows the program created, including the initial window created by kinc_init. /// /// The number of windows KINC_FUNC int kinc_count_windows(void); /// /// Resizes a window. /// KINC_FUNC void kinc_window_resize(int window, int width, int height); /// /// Moves a window. /// KINC_FUNC void kinc_window_move(int window, int x, int y); /// /// Switches between window and fullscreen-modes. /// KINC_FUNC void kinc_window_change_mode(int window, kinc_window_mode_t mode); /// /// Applies an or-ed combination of KINC_WINDOW_FEATURE values. /// KINC_FUNC void kinc_window_change_features(int window, int features); /// /// Changes the framebuffer-options of a window. /// KINC_FUNC void kinc_window_change_framebuffer(int window, kinc_framebuffer_options_t *frame); /// /// Returns the x position of a window. /// /// The x-position KINC_FUNC int kinc_window_x(int window); /// /// Returns the y position of a window. /// /// The y-position KINC_FUNC int kinc_window_y(int window); /// /// Returns the width of a window. /// /// The window-width KINC_FUNC int kinc_window_width(int window); /// /// Returns the height of a window. /// /// The window-height KINC_FUNC int kinc_window_height(int window); /// /// Returns the id of the display the window currently is on. /// /// The display-id KINC_FUNC int kinc_window_display(int window); /// /// Returns the current window-mode. /// /// The window-mode KINC_FUNC kinc_window_mode_t kinc_window_get_mode(int window); /// /// Makes the window visible. /// KINC_FUNC void kinc_window_show(int window); /// /// Hides a window. /// KINC_FUNC void kinc_window_hide(int window); /// /// Sets the title of a window. /// KINC_FUNC void kinc_window_set_title(int window, const char *title); /// /// Sets a resize callback that's called whenever the window is resized. /// KINC_FUNC void kinc_window_set_resize_callback(int window, void (*callback)(int x, int y, void *data), void *data); /// /// Sets a PPI callback that's called whenever the window moves to a display that uses a different PPI-setting. /// KINC_FUNC void kinc_window_set_ppi_changed_callback(int window, void (*callback)(int ppi, void *data), void *data); /// /// Sets a close callback that's called when the window is about to close. /// Returning false from the callback tries to stop the window from closing. /// KINC_FUNC void kinc_window_set_close_callback(int window, bool (*callback)(void *data), void *data); /// /// Returns whether the window is vsynced or not. /// /// Whether the window is vsynced or not KINC_FUNC bool kinc_window_vsynced(int window); void kinc_internal_call_resize_callback(int window, int width, int height); void kinc_internal_call_ppi_changed_callback(int window, int ppi); bool kinc_internal_call_close_callback(int window); #ifdef KINC_IMPLEMENTATION_ROOT #define KINC_IMPLEMENTATION #endif #ifdef KINC_IMPLEMENTATION #ifdef KINC_IMPLEMENTATION_ROOT #undef KINC_IMPLEMENTATION #endif #include #ifdef KINC_IMPLEMENTATION_ROOT #define KINC_IMPLEMENTATION #endif #include void kinc_window_options_set_defaults(kinc_window_options_t *win) { kinc_display_init(); win->title = NULL; win->display_index = kinc_primary_display(); win->mode = KINC_WINDOW_MODE_WINDOW; win->x = -1; win->y = -1; win->width = 800; win->height = 600; win->visible = true; win->window_features = KINC_WINDOW_FEATURE_RESIZEABLE | KINC_WINDOW_FEATURE_MINIMIZABLE | KINC_WINDOW_FEATURE_MAXIMIZABLE; } void kinc_framebuffer_options_set_defaults(kinc_framebuffer_options_t *frame) { frame->frequency = 60; frame->vertical_sync = true; frame->color_bits = 32; frame->depth_bits = 16; frame->stencil_bits = 8; frame->samples_per_pixel = 1; } #endif #ifdef __cplusplus } #endif