From 38f9178831aba84c4af98fdc5fba98b14b9db27a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 11 Jan 2025 18:15:51 +0100 Subject: [PATCH] fix framebuffer resize and impl. ctrl+v --- gpuapi/opengl/OpenglUtils.h | 5 ++++ gpuapi/opengl/OpenglWin32.h | 4 ++++ input/Input.h | 22 +++++++++++++----- platform/linux/UtilsLinux.h | 46 ++++++++++++++++++++++++++++++++++++- platform/win32/Clipboard.h | 37 +++++++++++++++++++++++++++++ platform/win32/UtilsWin32.h | 1 + 6 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 platform/win32/Clipboard.h diff --git a/gpuapi/opengl/OpenglUtils.h b/gpuapi/opengl/OpenglUtils.h index d3c41ba..20eb4ff 100644 --- a/gpuapi/opengl/OpenglUtils.h +++ b/gpuapi/opengl/OpenglUtils.h @@ -165,6 +165,11 @@ void texture_use(const Texture* texture) glBindTexture(texture_data_type, (GLuint) texture->id); } +inline +void texture_delete(Texture* texture) { + glDeleteTextures(1, &texture->id); +} + inline void draw_triangles_3d(VertexRef* vertices, GLuint buffer, int32 count) { glBindBuffer(GL_ARRAY_BUFFER, buffer); diff --git a/gpuapi/opengl/OpenglWin32.h b/gpuapi/opengl/OpenglWin32.h index d8521f7..dae220b 100644 --- a/gpuapi/opengl/OpenglWin32.h +++ b/gpuapi/opengl/OpenglWin32.h @@ -551,6 +551,9 @@ static type_glDeleteShader* glDeleteShader; typedef void WINAPI type_glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers); static type_glDeleteFramebuffers* glDeleteFramebuffers; +typedef void WINAPI type_glDeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers); +static type_glDeleteRenderbuffers* glDeleteRenderbuffers; + typedef void WINAPI type_glDrawBuffers(GLsizei n, const GLenum *bufs); static type_glDrawBuffers* glDrawBuffers; @@ -824,6 +827,7 @@ void opengl_init_gl() glDeleteVertexArrays = (type_glDeleteVertexArrays *) wglGetProcAddress("glDeleteVertexArrays"); glDeleteShader = (type_glDeleteShader *) wglGetProcAddress("glDeleteShader"); glDeleteFramebuffers = (type_glDeleteFramebuffers *) wglGetProcAddress("glDeleteFramebuffers"); + glDeleteRenderbuffers = (type_glDeleteRenderbuffers *) wglGetProcAddress("glDeleteRenderbuffers"); glDrawBuffers = (type_glDrawBuffers *) wglGetProcAddress("glDrawBuffers"); glTexImage3D = (type_glTexImage3D *) wglGetProcAddress("glTexImage3D"); glTexSubImage3D = (type_glTexSubImage3D *) wglGetProcAddress("glTexSubImage3D"); diff --git a/input/Input.h b/input/Input.h index b35d9c5..d4482c1 100644 --- a/input/Input.h +++ b/input/Input.h @@ -11,6 +11,7 @@ #include "../stdlib/Types.h" #include "../utils/BitUtils.h" +#include "../utils/StringUtils.h" #include "../memory/BufferMemory.h" #include "ControllerInput.h" #include "InputConnectionType.h" @@ -163,7 +164,7 @@ struct Input { // @todo this should probably be somewhere else // @todo don't we need multiple deadzones? triggers, sticks uint32 deadzone = 10; - uint32 characters[10]; + char text[512]; // This data is passed to the hotkey callback void* callback_data; @@ -518,9 +519,9 @@ void input_hotkey_state(Input* input) // Check typing mode if (input->general_states & INPUT_STATE_GENERAL_TYPING_MODE) { - // @todo If this function becomes threaded we must maintain the input characters as a persistent state + *input->text = '\0'; int32 input_characters = 0; - memset(input->characters, 0, sizeof(uint32) * ARRAY_COUNT(input->characters)); + uint32 characters[10]; // Create keyboard state array byte keyboard_state[256] = {}; @@ -541,7 +542,7 @@ void input_hotkey_state(Input* input) && (state->active_keys[key_state].scan_code & INPUT_KEYBOARD_PREFIX) && state->active_keys[key_state].key_state != KEY_PRESS_TYPE_RELEASED ) { - if (input_characters >= ARRAY_COUNT(input->characters)) { + if (input_characters >= ARRAY_COUNT(characters)) { break; } @@ -554,22 +555,31 @@ void input_hotkey_state(Input* input) // Is the pressed key a keyboard input if (!code) { // Is not text -> we have to reset characters - memset(input->characters, 0, sizeof(uint32) * input_characters); + memset(characters, 0, sizeof(uint32) * input_characters); input_characters = 0; break; } - input->characters[input_characters++] = code; + characters[input_characters++] = code; } } if (input_characters) { + // Mark keys for (int32 key_state = 0; key_state < MAX_KEY_PRESS_TYPES; ++key_state) { state->active_keys[key_state].is_processed = true; state->active_keys[key_state].time = 0; // @todo fix } + // Create text from input + char* pos = input->text; + for (int32 i = 0; i < ARRAY_COUNT(characters); ++i) { + pos += utf8_decode(characters[i], pos); + } + + *pos = '\0'; + input_clean_state(state->active_keys); return; } diff --git a/platform/linux/UtilsLinux.h b/platform/linux/UtilsLinux.h index 1c7fa0c..c5b52d6 100644 --- a/platform/linux/UtilsLinux.h +++ b/platform/linux/UtilsLinux.h @@ -9,11 +9,13 @@ #ifndef TOS_UTILS_LINUX_H #define TOS_UTILS_LINUX_H +#include "../../stdlib/Types.h" #include #include #include +#include +#include -#include "../../stdlib/Types.h" int32 sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...) { int32 result; @@ -36,4 +38,46 @@ int32 sprintf_s(char *buffer, size_t sizeOfBuffer, const char *format, ...) { return result; } +void clipboard_get(char* text, int32 max_length) +{ + *text = '\0'; + + Display *display = XOpenDisplay(NULL); + if (display == NULL) { + return; + } + + Atom clipboard = XInternAtom(display, "CLIPBOARD", false); + Atom utf8_string = XInternAtom(display, "UTF8_STRING", false); + Atom xa_string = XInternAtom(display, "STRING", false); + Window window = XDefaultRootWindow(display); + + XConvertSelection(display, clipboard, utf8_string, xa_string, window, CurrentTime); + XEvent event; + XNextEvent(display, &event); + + if (event.type == SelectionNotify) { + if (event.xselection.property) { + Atom type; + int32 format; + unsigned long nitems, bytes_after; + byte* data = NULL; + + XGetWindowProperty( + display, event.xselection.requestor, + event.xselection.property, 0, (~0L), false, + AnyPropertyType, &type, &format, &nitems, + &bytes_after, &data + ); + + if (data) { + str_copy_short(text, clipboard_text, max_length); + XFree(data); + } + } + } + + XCloseDisplay(display); +} + #endif \ No newline at end of file diff --git a/platform/win32/Clipboard.h b/platform/win32/Clipboard.h new file mode 100644 index 0000000..525af67 --- /dev/null +++ b/platform/win32/Clipboard.h @@ -0,0 +1,37 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef TOS_PLATFORM_WIN32_CLIPBOARD_H +#define TOS_PLATFORM_WIN32_CLIPBOARD_H + +#include "../../stdlib/Types.h" +#include "../../utils/StringUtils.h" +#include +#include +#include + +#define strtok_r strtok_s + +void clipboard_get(char* text, int32 max_length) +{ + *text = '\0'; + if (OpenClipboard(NULL)) { + HANDLE clipboard_data = GetClipboardData(CF_TEXT); + if (clipboard_data) { + const char* clipboard_text = (const char*) GlobalLock(clipboard_data); + if (clipboard_text) { + str_copy_short(text, clipboard_text, max_length); + GlobalUnlock(clipboard_data); + } + } + + CloseClipboard(); + } +} + +#endif \ No newline at end of file diff --git a/platform/win32/UtilsWin32.h b/platform/win32/UtilsWin32.h index e2da56c..ba8ea86 100644 --- a/platform/win32/UtilsWin32.h +++ b/platform/win32/UtilsWin32.h @@ -10,6 +10,7 @@ #define TOS_PLATFORM_WIN32_UTILS_H #include "../../stdlib/Types.h" +#include "../../utils/StringUtils.h" #include #include #include