Skip to content

Commit

Permalink
Add lv_windows_interop.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Jan 12, 2024
1 parent b5b483d commit 24cc50e
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 55 deletions.
2 changes: 2 additions & 0 deletions LvglWindowsSimulator/LvglWindowsSimulator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\win\lv_win.h" />
<ClInclude Include="lv_conf.h" />
<ClInclude Include="lv_windows_context.h" />
<ClInclude Include="lv_windows_interop.h" />
<ClInclude Include="win32drv.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -960,6 +961,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\win\lv_win.c" />
<ClCompile Include="LvglWindowsSimulator.cpp" />
<ClCompile Include="lv_windows_context.c" />
<ClCompile Include="lv_windows_interop.c" />
<ClCompile Include="win32drv.c" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions LvglWindowsSimulator/LvglWindowsSimulator.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@
<ClInclude Include="lv_conf.h" />
<ClInclude Include="win32drv.h" />
<ClInclude Include="lv_windows_context.h" />
<ClInclude Include="lv_windows_interop.h" />
</ItemGroup>
<ItemGroup>
<Manifest Include="LvglWindowsSimulator.manifest" />
Expand Down Expand Up @@ -2745,6 +2746,7 @@
<ClCompile Include="LvglWindowsSimulator.cpp" />
<ClCompile Include="win32drv.c" />
<ClCompile Include="lv_windows_context.c" />
<ClCompile Include="lv_windows_interop.c" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\LvglPlatform\freetype\.clang-format">
Expand Down
12 changes: 0 additions & 12 deletions LvglWindowsSimulator/lv_windows_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@
* GLOBAL FUNCTIONS
**********************/

EXTERN_C HWND lv_windows_get_display_window_handle(
lv_display_t* display)
{
return (HWND)lv_display_get_driver_data(display);
}

EXTERN_C HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev)
{
return lv_windows_get_display_window_handle(lv_indev_get_display(indev));
}

lv_windows_window_context_t* lv_windows_get_window_context(
HWND window_handle)
{
Expand Down
6 changes: 0 additions & 6 deletions LvglWindowsSimulator/lv_windows_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/

HWND lv_windows_get_display_window_handle(
lv_display_t* display);

HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev);

/**
* @brief Get the window context from specific LVGL display window.
* @param window_handle The window handle of specific LVGL display window.
Expand Down
73 changes: 73 additions & 0 deletions LvglWindowsSimulator/lv_windows_interop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @file lv_windows_interop.c
*
*/

/*********************
* INCLUDES
*********************/

#include "lv_windows_interop.h"
#ifdef LV_USE_WINDOWS

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

/**********************
* STATIC PROTOTYPES
**********************/

/**********************
* STATIC VARIABLES
**********************/

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/

EXTERN_C HWND lv_windows_get_display_window_handle(
lv_display_t* display)
{
return (HWND)lv_display_get_driver_data(display);
}

EXTERN_C HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev)
{
return lv_windows_get_display_window_handle(lv_indev_get_display(indev));
}

int32_t lv_windows_zoom_to_logical(int32_t physical, int32_t zoom_level)
{
return MulDiv(physical, LV_WINDOWS_ZOOM_BASE_LEVEL, zoom_level);
}

int32_t lv_windows_zoom_to_physical(int32_t logical, int32_t zoom_level)
{
return MulDiv(logical, zoom_level, LV_WINDOWS_ZOOM_BASE_LEVEL);
}

int32_t lv_windows_dpi_to_logical(int32_t physical, int32_t dpi)
{
return MulDiv(physical, USER_DEFAULT_SCREEN_DPI, dpi);
}

int32_t lv_windows_dpi_to_physical(int32_t logical, int32_t dpi)
{
return MulDiv(logical, dpi, USER_DEFAULT_SCREEN_DPI);
}

/**********************
* STATIC FUNCTIONS
**********************/

#endif // LV_USE_WINDOWS
119 changes: 119 additions & 0 deletions LvglWindowsSimulator/lv_windows_interop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* @file lv_windows_interop.h
*
*/

#ifndef LV_WINDOWS_INTEROP_H
#define LV_WINDOWS_INTEROP_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/

#include "lvgl.h"
#define LV_USE_WINDOWS

//#include "../../display/lv_display.h"
//#include "../../indev/lv_indev.h"

#ifdef LV_USE_WINDOWS

#include <windows.h>

/*********************
* DEFINES
*********************/

#define LV_WINDOWS_ZOOM_BASE_LEVEL 100

#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif

/**********************
* TYPEDEFS
**********************/

/**********************
* GLOBAL PROTOTYPES
**********************/

/**
* @brief Get the window handle from specific LVGL display object.
* @param display The specific LVGL display object.
* @return The window handle from specific LVGL display object.
*/
HWND lv_windows_get_display_window_handle(
lv_display_t* display);

/**
* @brief Get the window handle from specific LVGL input device object.
* @param indev The specific LVGL input device object.
* @return The window handle from specific LVGL input device object.
*/
HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev);

/**
* @brief Get logical pixel value from physical pixel value taken account
* with zoom level.
* @param physical The physical pixel value taken account with zoom level.
* @param zoom_level The zoom level value. Base value is 100 a.k.a 100%.
* @return The logical pixel value.
* @remark It uses the same calculation style as Windows OS implementation.
* It will be useful for integrate LVGL Windows backend to other
* Windows applications.
*/
int32_t lv_windows_zoom_to_logical(int32_t physical, int32_t zoom_level);

/**
* @brief Get physical pixel value taken account with zoom level from
* logical pixel value.
* @param logical The logical pixel value.
* @param zoom_level The zoom level value. Base value is 100 a.k.a 100%.
* @return The physical pixel value taken account with zoom level.
* @remark It uses the same calculation style as Windows OS implementation.
* It will be useful for integrate LVGL Windows backend to other
* Windows applications.
*/
int32_t lv_windows_zoom_to_physical(int32_t logical, int32_t zoom_level);

/**
* @brief Get logical pixel value from physical pixel value taken account
* with DPI scaling.
* @param physical The physical pixel value taken account with DPI scaling.
* @param dpi The DPI scaling value. Base value is USER_DEFAULT_SCREEN_DPI.
* @return The logical pixel value.
* @remark It uses the same calculation style as Windows OS implementation.
* It will be useful for integrate LVGL Windows backend to other
* Windows applications.
*/
int32_t lv_windows_dpi_to_logical(int32_t physical, int32_t dpi);

/**
* @brief Get physical pixel value taken account with DPI scaling from
* logical pixel value.
* @param logical The logical pixel value.
* @param dpi The DPI scaling value. Base value is USER_DEFAULT_SCREEN_DPI.
* @return The physical pixel value taken account with DPI scaling.
* @remark It uses the same calculation style as Windows OS implementation.
* It will be useful for integrate LVGL Windows backend to other
* Windows applications.
*/
int32_t lv_windows_dpi_to_physical(int32_t logical, int32_t dpi);

/**********************
* MACROS
**********************/

#endif // LV_USE_WINDOWS

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_WINDOWS_INTEROP_H*/
38 changes: 2 additions & 36 deletions LvglWindowsSimulator/win32drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "win32drv.h"

#include "lv_windows_context.h"

#include <windowsx.h>
#include <malloc.h>
#include <process.h>
Expand All @@ -21,26 +23,10 @@
* DEFINES
*********************/

#define LV_WINDOWS_ZOOM_BASE_LEVEL 100

#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif

/**********************
* TYPEDEFS
**********************/

typedef struct _WINDOW_THREAD_PARAMETER
{
HANDLE window_mutex;
HINSTANCE instance_handle;
HICON icon_handle;
int32_t hor_res;
int32_t ver_res;
int show_window_mode;
} WINDOW_THREAD_PARAMETER, * PWINDOW_THREAD_PARAMETER;

typedef struct _lv_windows_create_display_data_t
{
const wchar_t* title;
Expand Down Expand Up @@ -844,26 +830,6 @@ static UINT lv_windows_get_dpi_for_window(
return Result;
}

static int32_t lv_windows_zoom_to_logical(int32_t physical, int32_t zoom_level)
{
return MulDiv(physical, LV_WINDOWS_ZOOM_BASE_LEVEL, zoom_level);
}

static int32_t lv_windows_zoom_to_physical(int32_t logical, int32_t zoom_level)
{
return MulDiv(logical, zoom_level, LV_WINDOWS_ZOOM_BASE_LEVEL);
}

static int32_t lv_windows_dpi_to_logical(int32_t physical, int32_t dpi)
{
return MulDiv(physical, USER_DEFAULT_SCREEN_DPI, dpi);
}

static int32_t lv_windows_dpi_to_physical(int32_t logical, int32_t dpi)
{
return MulDiv(logical, dpi, USER_DEFAULT_SCREEN_DPI);
}

static void lv_windows_display_driver_flush_callback(
lv_disp_t* display,
const lv_area_t* area,
Expand Down
2 changes: 1 addition & 1 deletion LvglWindowsSimulator/win32drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "lvgl/lvgl.h"

#include "lv_windows_context.h"
#include "lv_windows_interop.h"

#include <windows.h>

Expand Down

0 comments on commit 24cc50e

Please sign in to comment.