Skip to content

Commit bf3a255

Browse files
committed
Cst816s: scale down SDL mouse coordinates according to MONITOR_ZOOM
The lv_drivers provided monitor driver supports a `MONITOR_ZOOM`-factor which scales the window by the set factor. This is 'useful when simulating small screens'. The zoom can be set as cmake configuration setting `-DMONITOR_ZOOM=1`. Probably even more usefull for high-dpi screens where 240 pixels is really tiny.
1 parent 84195fa commit bf3a255

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ file(GLOB_RECURSE SOURCES "lv_drivers/*.c" "${InfiniTime_DIR}/src/libs/lvgl/src
5555

5656
add_executable(infinisim main.cpp ${SOURCES} ${INCLUDES})
5757

58+
set(MONITOR_ZOOM 1 CACHE STRING "Scale simulator window by this factor")
59+
if(MONITOR_ZOOM MATCHES "^[0-9]\.?[0-9]*")
60+
target_compile_definitions(infinisim PRIVATE MONITOR_ZOOM=${MONITOR_ZOOM})
61+
else()
62+
message(FATAL_ERROR "variable MONITOR_ZOOM=${MONITOR_ZOOM} must be a positive number")
63+
endif()
64+
5865
# include the generated lv_conf.h file before anything else
5966
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
6067

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The following configuration settings can be added to the first `cmake -S . -B bu
5555
- `-DInfiniTime_DIR=InfiniTime`: a full path to an existing InfiniTime repository checked out.
5656
Inside that directory the `src/libs/lvgl` submodule must be checked out as well.
5757
The default value points to the InfiniTime submodule in this repository.
58+
- `-DMONITOR_ZOOM=1`: scale simulator window by this factor
5859

5960
## Run Simulator
6061

lv_drv_conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
# define MONITOR_VER_RES 240
100100

101101
/* Scale window by this factor (useful when simulating small screens) */
102+
#ifndef MONITOR_ZOOM
102103
# define MONITOR_ZOOM 1
104+
#endif
105+
static_assert(MONITOR_ZOOM > 0);
103106

104107
/* Used to test true double buffering with only address changing.
105108
* Set LV_draw_buf_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_draw_buf_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */

sim/drivers/Cst816s.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "drivers/Cst816s.h"
2+
#include "lv_drv_conf.h" // MONITOR_ZOOM
23
#include <SDL2/SDL.h>
34
#include <libraries/log/nrf_log.h>
45
#include <cmath>
@@ -25,6 +26,10 @@ bool Cst816S::Init() {
2526
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
2627
int x, y;
2728
uint32_t buttons = SDL_GetMouseState(&x, &y);
29+
// scale down real mouse coordinates to InfiniTime scale to make zoom work
30+
// the MONITOR_ZOOM-factor is defined in lv_drv_conf.h
31+
x /= MONITOR_ZOOM;
32+
y /= MONITOR_ZOOM;
2833

2934
Cst816S::TouchInfos info;
3035
info.x = x;

0 commit comments

Comments
 (0)