Mercurial > repos > blastem
diff nuklear_ui/nuklear_sdl_gles2.h @ 2308:b7768c58f0da
Initial stab at DPI scaling support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 26 Mar 2023 22:39:18 -0700 |
parents | 1838b0b8f4ff |
children | 5e34369ed6be |
line wrap: on
line diff
--- a/nuklear_ui/nuklear_sdl_gles2.h Thu Mar 23 22:38:51 2023 -0700 +++ b/nuklear_ui/nuklear_sdl_gles2.h Sun Mar 26 22:39:18 2023 -0700 @@ -23,6 +23,7 @@ #include <GL/glew.h> #endif #endif +#include "../render.h" NK_API struct nk_context* nk_sdl_init(SDL_Window *win); @@ -118,7 +119,7 @@ "}\n"; struct nk_sdl_device *dev = &sdl.ogl; - + nk_buffer_init_default(&dev->cmds); dev->prog = glCreateProgram(); dev->vert_shdr = glCreateShader(GL_VERTEX_SHADER); @@ -148,7 +149,7 @@ dev->vp = offsetof(struct nk_sdl_vertex, position); dev->vt = offsetof(struct nk_sdl_vertex, uv); dev->vc = offsetof(struct nk_sdl_vertex, col); - + /* Allocate buffers */ glGenBuffers(1, &dev->vbo); glGenBuffers(1, &dev->ebo); @@ -233,7 +234,7 @@ /* Bind buffers */ glBindBuffer(GL_ARRAY_BUFFER, dev->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev->ebo); - + { /* buffer setup */ glEnableVertexAttribArray((GLuint)dev->attrib_pos); @@ -445,7 +446,7 @@ } else if (evt->type == SDL_MOUSEBUTTONDOWN || evt->type == SDL_MOUSEBUTTONUP) { /* mouse button */ int down = evt->type == SDL_MOUSEBUTTONDOWN; - const int x = evt->button.x, y = evt->button.y; + const int x = render_ui_to_pixels_x(evt->button.x), y = render_ui_to_pixels_y(evt->button.y); if (evt->button.button == SDL_BUTTON_LEFT) { if (evt->button.clicks > 1) nk_input_button(ctx, NK_BUTTON_DOUBLE, x, y, down); @@ -458,9 +459,9 @@ } else if (evt->type == SDL_MOUSEMOTION) { /* mouse motion */ if (ctx->input.mouse.grabbed) { - int x = (int)ctx->input.mouse.prev.x, y = (int)ctx->input.mouse.prev.y; - nk_input_motion(ctx, x + evt->motion.xrel, y + evt->motion.yrel); - } else nk_input_motion(ctx, evt->motion.x, evt->motion.y); + int x = render_ui_to_pixels_x((int)ctx->input.mouse.prev.x), y = render_ui_to_pixels_y((int)ctx->input.mouse.prev.y); + nk_input_motion(ctx, x + render_ui_to_pixels_x(evt->motion.xrel), y + render_ui_to_pixels_y(evt->motion.yrel)); + } else nk_input_motion(ctx, render_ui_to_pixels_x(evt->motion.x), render_ui_to_pixels_y(evt->motion.y)); return 1; } else if (evt->type == SDL_TEXTINPUT) { /* text input */