Fixed on click logic to identify ui elements

main
noah metz 2024-10-30 16:48:44 -06:00
parent 857655e926
commit 40d31430c2
1 changed files with 15 additions and 12 deletions

@ -13,6 +13,9 @@ typedef struct ClientContextStruct {
GLFWwindow* window; GLFWwindow* window;
RenderContext render; RenderContext render;
UIContext ui; UIContext ui;
uint32_t clicked_container;
uint32_t clicked_element;
} ClientContext; } ClientContext;
void* network_thread(void* data) { void* network_thread(void* data) {
@ -97,22 +100,18 @@ VkResult main_thread(ClientContext* context) {
// //
uint32_t* mapped_codes = context->ui.containers[0].layers[0].codes_buffer; uint32_t* mapped_codes = context->ui.containers[0].layers[0].codes_buffer;
GPUString* mapped_string = context->ui.containers[0].layers[0].strings_buffer; GPUString* mapped_string = context->ui.containers[0].layers[0].strings_buffer;
char str[21] = "1234567890"; char str[21];
uint32_t last_id = 0;
uint32_t last_last_id = -1;
int test = 0;
// //
while(glfwWindowShouldClose(context->window) == 0) { while(glfwWindowShouldClose(context->window) == 0) {
context->clicked_element = 0x00000000;
context->clicked_container = 0x00000000;
glfwPollEvents(); glfwPollEvents();
double frame_time = glfwGetTime(); double frame_time = glfwGetTime();
if(last_id != last_last_id) { if(context->clicked_container != 0) {
last_last_id = last_id; snprintf(str, 21, "Clicked: %d.%d", context->clicked_container, context->clicked_element);
test = (test + 1) % 7;
snprintf(str, 21, "Last ID: %d", last_id);
map_string(str, mapped_codes, 0, 0, &context->ui); map_string(str, mapped_codes, 0, 0, &context->ui);
VK_RESULT(add_transfers( VK_RESULT(add_transfers(
context->ui.containers[0].layers[0].codes_buffer, context->ui.containers[0].layers[0].codes_buffer,
@ -179,15 +178,19 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
break; break;
case GLFW_MOUSE_BUTTON_LEFT: case GLFW_MOUSE_BUTTON_LEFT:
if(action == GLFW_PRESS) { if(action == GLFW_PRESS) {
for(uint32_t c = context->ui.max_containers - 1; c >= 0; c--) { for(int32_t c = context->ui.max_containers - 1; c >= 0; c--) {
if(context->ui.containers[c].id == 0x00000000) { if(context->ui.containers[c].id == 0x00000000) {
continue; continue;
} }
for(uint32_t l = 0; l < context->ui.containers[c].layer_count; l++) { for(uint32_t l = 0; l < context->ui.containers[c].layer_count; l++) {
for(uint32_t d = 0; d < context->ui.containers[c].layers[l].data.num_drawables; d++) { for(uint32_t d = 0; d < context->ui.containers[c].layers[l].data.num_drawables; d++) {
if(context->ui.containers[c].layers[l].drawables_buffer[d].id == 0x00000000) {
continue;
}
if(contains(cursor, &context->ui.containers[c].data, &context->ui.containers[c].layers[l].drawables_buffer[d])) { if(contains(cursor, &context->ui.containers[c].data, &context->ui.containers[c].layers[l].drawables_buffer[d])) {
fprintf(stderr, "hit\n"); context->clicked_container = context->ui.containers[c].id;
context->clicked_element = context->ui.containers[c].layers[l].drawables_buffer[d].id;
} }
} }
} }