From bf3a255ca40c32e9196c205f2f350d858a1644eb Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Wed, 30 Mar 2022 19:49:17 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 7 +++++++ README.md | 1 + lv_drv_conf.h | 3 +++ sim/drivers/Cst816s.cpp | 5 +++++ 4 files changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc49588..96b53d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,13 @@ file(GLOB_RECURSE SOURCES "lv_drivers/*.c" "${InfiniTime_DIR}/src/libs/lvgl/src add_executable(infinisim main.cpp ${SOURCES} ${INCLUDES}) +set(MONITOR_ZOOM 1 CACHE STRING "Scale simulator window by this factor") +if(MONITOR_ZOOM MATCHES "^[0-9]\.?[0-9]*") + target_compile_definitions(infinisim PRIVATE MONITOR_ZOOM=${MONITOR_ZOOM}) +else() + message(FATAL_ERROR "variable MONITOR_ZOOM=${MONITOR_ZOOM} must be a positive number") +endif() + # include the generated lv_conf.h file before anything else target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/README.md b/README.md index abfd7d5..9d1e469 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ The following configuration settings can be added to the first `cmake -S . -B bu - `-DInfiniTime_DIR=InfiniTime`: a full path to an existing InfiniTime repository checked out. Inside that directory the `src/libs/lvgl` submodule must be checked out as well. The default value points to the InfiniTime submodule in this repository. +- `-DMONITOR_ZOOM=1`: scale simulator window by this factor ## Run Simulator diff --git a/lv_drv_conf.h b/lv_drv_conf.h index 4a6e01f..f1e1111 100644 --- a/lv_drv_conf.h +++ b/lv_drv_conf.h @@ -99,7 +99,10 @@ # define MONITOR_VER_RES 240 /* Scale window by this factor (useful when simulating small screens) */ +#ifndef MONITOR_ZOOM # define MONITOR_ZOOM 1 +#endif +static_assert(MONITOR_ZOOM > 0); /* Used to test true double buffering with only address changing. * Set LV_draw_buf_SIZE = (LV_HOR_RES * LV_VER_RES) and LV_draw_buf_DOUBLE = 1 and LV_COLOR_DEPTH = 32" */ diff --git a/sim/drivers/Cst816s.cpp b/sim/drivers/Cst816s.cpp index 6fae3ba..659511f 100644 --- a/sim/drivers/Cst816s.cpp +++ b/sim/drivers/Cst816s.cpp @@ -1,4 +1,5 @@ #include "drivers/Cst816s.h" +#include "lv_drv_conf.h" // MONITOR_ZOOM #include #include #include @@ -25,6 +26,10 @@ bool Cst816S::Init() { Cst816S::TouchInfos Cst816S::GetTouchInfo() { int x, y; uint32_t buttons = SDL_GetMouseState(&x, &y); + // scale down real mouse coordinates to InfiniTime scale to make zoom work + // the MONITOR_ZOOM-factor is defined in lv_drv_conf.h + x /= MONITOR_ZOOM; + y /= MONITOR_ZOOM; Cst816S::TouchInfos info; info.x = x;