Skip to content

Commit a9ccb7d

Browse files
committed
backends: add initial GDI backend for windows
1 parent 51e8c79 commit a9ccb7d

9 files changed

Lines changed: 650 additions & 15 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ lvtk.includes
3131

3232
doxy.log
3333

34-
.meson-subproject-wrap-hash.txt
34+
.meson-subproject-wrap-hash.txt.cache/
35+
.cache/

demo/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ endif()
105105
if(WIN32)
106106
lui_add_demo(lui-demo-d2d)
107107
target_compile_definitions(lui-demo-d2d PRIVATE LUI_DEMO_D2D=1)
108+
lui_add_demo(lui-demo-gdi)
109+
target_compile_definitions(lui-demo-gdi PRIVATE LUI_DEMO_GDI=1)
108110
endif()

demo/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#elif LUI_DEMO_D2D
1919
# include <lui/direct2d.hpp>
2020
# define LUI_DEMO_TITLE "LUI Direct2D Demo"
21+
#elif LUI_DEMO_GDI
22+
# include <lui/gdi.hpp>
23+
# define LUI_DEMO_TITLE "LUI GDI Demo"
2124
#endif
2225

2326
#include "demo.hpp"
@@ -78,6 +81,8 @@ int WinMain (HINSTANCE hInstance,
7881
lui::Main context (lui::Mode::PROGRAM, std::make_unique<lui::Vulkan>());
7982
# elif LUI_DEMO_D2D
8083
lui::Main context (lui::Mode::PROGRAM, std::make_unique<lui::Direct2D>());
84+
# elif LUI_DEMO_GDI
85+
lui::Main context (lui::Mode::PROGRAM, std::make_unique<lui::GDI>());
8186
# else
8287
lui::Main context (lui::Mode::PROGRAM, std::make_unique<lui::OpenGL>());
8388
# endif

include/lui/gdi.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2026 Kushview, LLC
2+
// SPDX-License-Identifier: ISC
3+
4+
#pragma once
5+
6+
#include <lui/lui.h>
7+
#include <lui/main.hpp>
8+
9+
namespace lui {
10+
11+
class Main;
12+
class Widget;
13+
14+
/** The Windows GDI graphics backend.
15+
Using this backend requires Windows and links to GDI.
16+
17+
@ingroup widgets
18+
@ingroup graphics
19+
@headerfile lui/gdi.hpp
20+
*/
21+
struct LUI_API GDI : public Backend {
22+
GDI() : Backend ("GDI") {}
23+
std::unique_ptr<View> create_view (Main& c, Widget& w) override;
24+
};
25+
26+
} // namespace lui

include/lui/point.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace lui {
1616
*/
1717
template <typename Val>
1818
struct Point {
19-
static_assert(std::is_integral_v<Val> || std::is_floating_point_v<Val>,
20-
"Point value type must be integral or floating point");
19+
static_assert (std::is_integral_v<Val> || std::is_floating_point_v<Val>,
20+
"Point value type must be integral or floating point");
2121

2222
/** X coordinate */
2323
Val x {};
@@ -26,13 +26,12 @@ struct Point {
2626

2727
Point() = default;
2828

29-
template<typename TX, typename TY,
30-
typename = std::enable_if_t<
31-
(std::is_integral_v<TX> || std::is_floating_point_v<TX>) &&
32-
(std::is_integral_v<TY> || std::is_floating_point_v<TY>)>>
33-
Point(TX x_val, TY y_val) noexcept
34-
: x(static_cast<Val>(x_val)),
35-
y(static_cast<Val>(y_val)) {}
29+
template <typename TX, typename TY,
30+
typename = std::enable_if_t<
31+
(std::is_integral_v<TX> || std::is_floating_point_v<TX>) && (std::is_integral_v<TY> || std::is_floating_point_v<TY>)>>
32+
Point (TX x_val, TY y_val) noexcept
33+
: x (static_cast<Val> (x_val)),
34+
y (static_cast<Val> (y_val)) {}
3635

3736
/** Convert this point to another value type.
3837
i.e. int to float

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ elseif(UNIX AND NOT APPLE)
5656
pugl/src/x11.c)
5757
elseif(WIN32)
5858
list(APPEND LIBLUI_SOURCES
59-
direct2d.cpp
6059
embed_win32.cpp
60+
direct2d.cpp
6161
win_direct2d.cpp
62+
gdi.cpp
63+
win_gdi.c
6264
pugl/src/win.c)
6365
endif()
6466

0 commit comments

Comments
 (0)