fix framebuffer resize and impl. ctrl+v

This commit is contained in:
Dennis Eichhorn 2025-01-11 18:15:51 +01:00
parent a02963607d
commit 38f9178831
6 changed files with 108 additions and 7 deletions

View File

@ -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);

View File

@ -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");

View File

@ -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;
}

View File

@ -9,11 +9,13 @@
#ifndef TOS_UTILS_LINUX_H
#define TOS_UTILS_LINUX_H
#include "../../stdlib/Types.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#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

View File

@ -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 <stdio.h>
#include <windows.h>
#include <string.h>
#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

View File

@ -10,6 +10,7 @@
#define TOS_PLATFORM_WIN32_UTILS_H
#include "../../stdlib/Types.h"
#include "../../utils/StringUtils.h"
#include <stdio.h>
#include <windows.h>
#include <string.h>