2019-06-08 18:11:02 +00:00
|
|
|
#ifndef _MINIFB_H_
|
|
|
|
#define _MINIFB_H_
|
|
|
|
|
|
|
|
#include "MiniFB_enums.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-11-14 15:18:42 +00:00
|
|
|
#define MFB_RGB(r, g, b) (((uint32_t) r) << 16) | (((uint32_t) g) << 8) | ((uint32_t) b)
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Create a window that is used to display the buffer sent into the mfb_update function, returns 0 if fails
|
2020-03-06 06:06:54 +00:00
|
|
|
struct mfb_window * mfb_open(const char *title, unsigned width, unsigned height);
|
|
|
|
struct mfb_window * mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags);
|
2019-06-08 18:11:02 +00:00
|
|
|
|
2019-12-14 10:20:59 +00:00
|
|
|
// Update the display
|
|
|
|
// Input buffer is assumed to be a 32-bit buffer of the size given in the open call
|
|
|
|
// Will return a negative status if something went wrong or the user want to exit
|
|
|
|
// Also updates the window events
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_update_state mfb_update(struct mfb_window *window, void *buffer);
|
2019-06-08 18:11:02 +00:00
|
|
|
|
2020-09-15 09:35:11 +00:00
|
|
|
mfb_update_state mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height);
|
|
|
|
|
2019-12-14 10:20:59 +00:00
|
|
|
// Only updates the window events
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_update_state mfb_update_events(struct mfb_window *window);
|
2019-12-14 10:20:59 +00:00
|
|
|
|
2019-06-08 18:11:02 +00:00
|
|
|
// Close the window
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_close(struct mfb_window *window);
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
// Set user data
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_user_data(struct mfb_window *window, void *user_data);
|
|
|
|
void * mfb_get_user_data(struct mfb_window *window);
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
// Set viewport (useful when resize)
|
2020-03-06 06:06:54 +00:00
|
|
|
bool mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
|
|
|
|
2020-09-21 10:27:22 +00:00
|
|
|
// DPI
|
2021-02-19 09:51:58 +00:00
|
|
|
// [Deprecated]: Probably a better name will be mfb_get_monitor_scale
|
2020-09-21 10:27:22 +00:00
|
|
|
void mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y);
|
2021-02-19 09:51:58 +00:00
|
|
|
// Use this instead
|
|
|
|
void mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y);
|
2020-09-21 10:27:22 +00:00
|
|
|
|
|
|
|
// Callbacks
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback);
|
|
|
|
void mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback);
|
|
|
|
void mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback);
|
|
|
|
void mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callback);
|
|
|
|
void mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func callback);
|
|
|
|
void mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callback);
|
|
|
|
void mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func callback);
|
|
|
|
|
2020-09-21 10:27:22 +00:00
|
|
|
// Getters
|
2020-03-06 06:06:54 +00:00
|
|
|
const char * mfb_get_key_name(mfb_key key);
|
|
|
|
|
|
|
|
bool mfb_is_window_active(struct mfb_window *window);
|
|
|
|
unsigned mfb_get_window_width(struct mfb_window *window);
|
|
|
|
unsigned mfb_get_window_height(struct mfb_window *window);
|
|
|
|
int mfb_get_mouse_x(struct mfb_window *window); // Last mouse pos X
|
|
|
|
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
|
|
|
|
float mfb_get_mouse_scroll_x(struct mfb_window *window); // Mouse wheel X as a sum. When you call this function it resets.
|
|
|
|
float mfb_get_mouse_scroll_y(struct mfb_window *window); // Mouse wheel Y as a sum. When you call this function it resets.
|
|
|
|
const uint8_t * mfb_get_mouse_button_buffer(struct mfb_window *window); // One byte for every button. Press (1), Release 0. (up to 8 buttons)
|
|
|
|
const uint8_t * mfb_get_key_buffer(struct mfb_window *window); // One byte for every key. Press (1), Release 0.
|
2019-06-08 18:11:02 +00:00
|
|
|
|
2020-09-21 10:27:22 +00:00
|
|
|
// FPS
|
2020-04-22 11:00:15 +00:00
|
|
|
void mfb_set_target_fps(uint32_t fps);
|
|
|
|
bool mfb_wait_sync(struct mfb_window *window);
|
|
|
|
|
2020-09-21 10:27:22 +00:00
|
|
|
// Timer
|
2020-04-26 12:10:18 +00:00
|
|
|
struct mfb_timer * mfb_timer_create(void);
|
2020-04-22 11:00:15 +00:00
|
|
|
void mfb_timer_destroy(struct mfb_timer *tmr);
|
|
|
|
void mfb_timer_reset(struct mfb_timer *tmr);
|
|
|
|
double mfb_timer_now(struct mfb_timer *tmr);
|
|
|
|
double mfb_timer_delta(struct mfb_timer *tmr);
|
2020-04-26 12:10:18 +00:00
|
|
|
double mfb_timer_get_frequency(void);
|
|
|
|
double mfb_timer_get_resolution(void);
|
2020-04-22 11:00:15 +00:00
|
|
|
|
2019-06-08 18:11:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "MiniFB_cpp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|