Skip to content

Commit

Permalink
feat(sdl): add float zoom window support (lvgl#7089)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyKelsey123 authored and Rod Boyce committed Nov 8, 2024
1 parent 7e82fcf commit 8030bd6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/drivers/sdl/lv_sdl_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void lv_sdl_mouse_handler(SDL_Event * event)

int32_t hor_res = lv_display_get_horizontal_resolution(disp);
int32_t ver_res = lv_display_get_vertical_resolution(disp);
uint8_t zoom = lv_sdl_window_get_zoom(disp);
float zoom = lv_sdl_window_get_zoom(disp);

switch(event->type) {
case SDL_WINDOWEVENT:
Expand All @@ -163,13 +163,13 @@ void lv_sdl_mouse_handler(SDL_Event * event)
case SDL_MOUSEBUTTONDOWN:
if(event->button.button == SDL_BUTTON_LEFT) {
indev_dev->left_button_down = true;
indev_dev->last_x = event->motion.x / zoom;
indev_dev->last_y = event->motion.y / zoom;
indev_dev->last_x = (int16_t)((float)(event->motion.x) / zoom);
indev_dev->last_y = (int16_t)((float)(event->motion.y) / zoom);
}
break;
case SDL_MOUSEMOTION:
indev_dev->last_x = event->motion.x / zoom;
indev_dev->last_y = event->motion.y / zoom;
indev_dev->last_x = (int16_t)((float)(event->motion.x) / zoom);
indev_dev->last_y = (int16_t)((float)(event->motion.y) / zoom);
break;

case SDL_FINGERUP:
Expand Down
23 changes: 13 additions & 10 deletions src/drivers/sdl/lv_sdl_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct {
uint8_t * rotated_buf;
size_t rotated_buf_size;
#endif
uint8_t zoom;
float zoom;
uint8_t ignore_size_chg;
} lv_sdl_window_t;

Expand Down Expand Up @@ -144,15 +144,15 @@ void lv_sdl_window_set_resizeable(lv_display_t * disp, bool value)
SDL_SetWindowResizable(dsc->window, value);
}

void lv_sdl_window_set_zoom(lv_display_t * disp, uint8_t zoom)
void lv_sdl_window_set_zoom(lv_display_t * disp, float zoom)
{
lv_sdl_window_t * dsc = lv_display_get_driver_data(disp);
dsc->zoom = zoom;
lv_display_send_event(disp, LV_EVENT_RESOLUTION_CHANGED, NULL);
lv_refr_now(disp);
}

uint8_t lv_sdl_window_get_zoom(lv_display_t * disp)
float lv_sdl_window_get_zoom(lv_display_t * disp)
{
lv_sdl_window_t * dsc = lv_display_get_driver_data(disp);
return dsc->zoom;
Expand Down Expand Up @@ -288,7 +288,9 @@ static void sdl_event_handler(lv_timer_t * t)
break;
case SDL_WINDOWEVENT_RESIZED:
dsc->ignore_size_chg = 1;
lv_display_set_resolution(disp, event.window.data1 / dsc->zoom, event.window.data2 / dsc->zoom);
int32_t hres = (int32_t)((float)(event.window.data1) / dsc->zoom);
int32_t vres = (int32_t)((float)(event.window.data2) / dsc->zoom);
lv_display_set_resolution(disp, hres, vres);
dsc->ignore_size_chg = 0;
lv_refr_now(disp);
break;
Expand All @@ -313,18 +315,18 @@ static void sdl_event_handler(lv_timer_t * t)
static void window_create(lv_display_t * disp)
{
lv_sdl_window_t * dsc = lv_display_get_driver_data(disp);
dsc->zoom = 1;
dsc->zoom = 1.0;

int flag = SDL_WINDOW_RESIZABLE;
#if LV_SDL_FULLSCREEN
flag |= SDL_WINDOW_FULLSCREEN;
#endif

int32_t hor_res = disp->hor_res;
int32_t ver_res = disp->ver_res;
int32_t hor_res = (int32_t)((float)(disp->hor_res) * dsc->zoom);
int32_t ver_res = (int32_t)((float)(disp->ver_res) * dsc->zoom);
dsc->window = SDL_CreateWindow("LVGL Simulator",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
hor_res * dsc->zoom, ver_res * dsc->zoom, flag); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
hor_res, ver_res, flag); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/

dsc->renderer = SDL_CreateRenderer(dsc->window, -1,
LV_SDL_ACCELERATED ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE);
Expand All @@ -338,7 +340,7 @@ static void window_create(lv_display_t * disp)
#endif
#endif /*LV_USE_DRAW_SDL == 0*/
/*Some platforms (e.g. Emscripten) seem to require setting the size again */
SDL_SetWindowSize(dsc->window, hor_res * dsc->zoom, ver_res * dsc->zoom);
SDL_SetWindowSize(dsc->window, hor_res, ver_res);
#if LV_USE_DRAW_SDL == 0
texture_resize(disp);
#endif /*LV_USE_DRAW_SDL == 0*/
Expand Down Expand Up @@ -432,7 +434,8 @@ static void res_chg_event_cb(lv_event_t * e)

lv_sdl_window_t * dsc = lv_display_get_driver_data(disp);
if(dsc->ignore_size_chg == false) {
SDL_SetWindowSize(dsc->window, disp->hor_res * dsc->zoom, disp->ver_res * dsc->zoom);
SDL_SetWindowSize(dsc->window,
(int)((float)(disp->hor_res)*dsc->zoom), (int)((float)(disp->ver_res)*dsc->zoom));
}

#if LV_USE_DRAW_SDL == 0
Expand Down
5 changes: 3 additions & 2 deletions src/drivers/sdl/lv_sdl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ lv_display_t * lv_sdl_window_create(int32_t hor_res, int32_t ver_res);

void lv_sdl_window_set_resizeable(lv_display_t * disp, bool value);

void lv_sdl_window_set_zoom(lv_display_t * disp, uint8_t zoom);
void lv_sdl_window_set_zoom(lv_display_t * disp, float zoom);

uint8_t lv_sdl_window_get_zoom(lv_display_t * disp);
float lv_sdl_window_get_zoom(lv_display_t * disp);

void lv_sdl_window_set_title(lv_display_t * disp, const char * title);

Expand All @@ -53,6 +53,7 @@ void lv_sdl_quit(void);
* MACROS
**********************/


#endif /* LV_DRV_SDL */

#ifdef __cplusplus
Expand Down

0 comments on commit 8030bd6

Please sign in to comment.