Cleaned up Window.

This commit is contained in:
Relintai 2023-12-19 11:21:02 +01:00
parent d9485f9c3e
commit eda9c2a063
4 changed files with 317 additions and 443 deletions

View File

@ -37,7 +37,8 @@
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_vector.cpp -o sfw/pool_vector.o
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_allocator.cpp -o sfw/pool_allocator.o
# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/mutex.cpp -o sfw/mutex.o
g++ -Wall -D_REENTRANT -g -Isfw -c sfw/stime.cpp -o sfw/stime.o
#g++ -Wall -D_REENTRANT -g -Isfw -c sfw/stime.cpp -o sfw/stime.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/application.cpp -o sfw/application/application.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -o sfw/application/scene.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/window.cpp -o sfw/application/window.o

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,6 @@
#ifndef WINDOW_H
#define WINDOW_H
// -----------------------------------------------------------------------------
// window framework
// - rlyeh, public domain
@ -6,9 +9,14 @@
// @todo: if WINDOW_PORTRAIT && exist portrait monitor, use that instead of primary one
// @todo: WINDOW_TRAY
#include "color.h"
#include "int_types.h"
#include "vector2.h"
struct GLFWwindow;
struct GLFWcursor;
struct GLFWmonitor;
class Window {
public:
enum WINDOW_FLAGS {
@ -31,7 +39,6 @@ public:
bool create(float scale, unsigned flags);
bool create_from_handle(void *handle, float scale, unsigned flags);
void reload();
int frame_begin();
void frame_end();
@ -41,50 +48,47 @@ public:
void loop(void (*function)(void *loopArg), void *loopArg); // run main loop function continuously (emscripten only)
void loop_exit(); // exit from main loop function (emscripten only)
void title(const char *title);
void color(unsigned color);
Vector2 canvas();
void *handle();
char *stats();
void set_title(const char *title);
void set_color(unsigned color);
Vector2 get_canvas();
void *get_handle();
char *get_stats();
uint64_t frame();
int width();
int height();
double time();
double delta();
int get_width();
int get_height();
double get_time();
double get_delta();
// bool hook(void (*func)(), void* userdata); // deprecated
// void unhook(void (*func)()); // deprecated
void focus(); // window attribute using haz catz language for now
void set_focus(); // window attribute using haz catz language for now
int has_focus();
void fullscreen(int enabled);
void set_fullscreen(int enabled);
int has_fullscreen();
void cursor(int visible);
void set_cursor(int visible);
int has_cursor();
void pause(int paused);
void set_pause(int paused);
int has_pause();
void visible(int visible);
void set_visible(int visible);
int has_visible();
void maximize(int enabled);
void set_maximize(int enabled);
int has_maximize();
void transparent(int enabled);
void set_transparent(int enabled);
int has_transparent();
void icon(const char *file_icon);
void set_icon(const char *file_icon);
int has_icon();
double aspect();
double get_aspect();
void aspect_lock(unsigned numer, unsigned denom);
void aspect_unlock();
double fps();
double fps_target();
double get_fps();
double get_fps_target();
void fps_lock(float fps);
void fps_unlock();
void screenshot(const char *outfile_png); // , bool record_cursor
int record(const char *outfile_mp4); // , bool record_cursor
Vector2 dpi();
enum CURSOR_SHAPES {
@ -98,10 +102,10 @@ public:
CURSOR_SW_AUTO, // software cursor, ui driven. note: this is the only icon that may be recorded or snapshotted
};
void cursor_shape(unsigned shape);
void set_cursor_shape(unsigned shape);
const char *clipboard();
void setclipboard(const char *text);
const char *get_clipboard();
void set_clipboard(const char *text);
static Window *get_singleton();
@ -109,11 +113,23 @@ public:
~Window();
protected:
static void glfw_quit();
static void glfw_init();
static void glfw_error_callback(int error, const char *description);
static void drop_callback(GLFWwindow *window, int count, const char **paths);
static void window_hints(unsigned flags);
GLFWmonitor *find_monitor(int wx, int wy);
void shutdown();
void resize();
static void loop_wrapper(void *loopArg);
void glNewFrame();
Vector2 canvas();
double get_scale();
void create_default_cursors();
static Window *_singleton;
struct GLFWwindow;
GLFWwindow *window;
GLFWwindow *_window;
int w;
int h;
int xpos;
@ -131,5 +147,27 @@ protected:
double hz;
char title[128];
int locked_aspect_ratio;
Vector4 winbgcolor;
};
Color winbgcolor;
int _has_icon;
int _cursorshape = 1;
void (*render_callback)(void *loopArg);
Vector2 last_canvas_size;
int width;
int height;
bool keep_running;
unsigned int _window_flags;
bool _fullscreen;
bool _transparent;
bool _vsync;
bool _vsync_adaptive;
bool _cursors_initialized;
GLFWcursor *cursors[7];
unsigned int cursor_enums[7];
};
#endif

View File

@ -112,7 +112,7 @@ _FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2, D p3, E
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return;
#define ERR_FAIL_V(val) \
#define ERR_FAIL_V(val) \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, ""); \
return val;
@ -213,7 +213,7 @@ _FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2, D p3, E
} else \
((void)0)
#define CRASH_BAD_INDEX(index, size) \
#define CRASH_BAD_INDEX(index, size) \
if ((index < 0) || (index >= size)) { \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \
GENERATE_TRAP \
@ -234,6 +234,10 @@ _FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2, D p3, E
} else \
((void)0)
#define CRASH_MSG(msg) \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
GENERATE_TRAP
/**
* This should be a 'free' assert for program flow and should not be needed in any releases,
* only used in dev builds.