plusui-native-core 0.1.30 → 0.1.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,6 @@ add_library(plusui STATIC
24
24
  Features/Bindings/CustomBindings/custom_bindings.cpp
25
25
  Features/App/app.cpp
26
26
  Features/Window/window.cpp
27
- Features/Window/window_manager.cpp
28
27
  Features/Window/webview.cpp
29
28
  Features/Browser/browser.cpp
30
29
  Features/Display/display.cpp
@@ -6,8 +6,6 @@
6
6
  #include <plusui/app.hpp>
7
7
  #include <plusui/tray.hpp>
8
8
  #include <plusui/window.hpp>
9
- #include <plusui/window.hpp>
10
- #include <plusui/window_manager.hpp>
11
9
 
12
10
  namespace plusui {
13
11
 
@@ -1,11 +1,10 @@
1
1
  #include <fstream>
2
+ #include <functional>
2
3
  #include <iostream>
3
4
  #include <map>
4
5
  #include <plusui/tray.hpp>
5
6
  #include <plusui/webgpu.hpp>
6
7
  #include <plusui/window.hpp>
7
- #include <plusui/window.hpp>
8
- #include <plusui/window_manager.hpp>
9
8
  #include <regex>
10
9
  #include <sstream>
11
10
 
@@ -44,7 +43,6 @@ struct Window::Impl {
44
43
  std::map<std::string, JSCallback> bindings;
45
44
 
46
45
  std::unique_ptr<TrayManager> trayManager;
47
- std::unique_ptr<WindowManager> windowManager;
48
46
  std::map<std::string, std::function<void(const std::string &)>> events;
49
47
  WebGPU webgpu; // WebGPU support
50
48
 
@@ -242,39 +240,43 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
242
240
  if (method.find("window.") == 0) {
243
241
  std::string winMethod = method.substr(7);
244
242
  if (winMethod == "minimize") {
245
- pImpl->windowManager->minimize();
243
+ if (pImpl->window) pImpl->window->minimize();
246
244
  success = true;
247
245
  } else if (winMethod == "maximize") {
248
- pImpl->windowManager->maximize();
246
+ if (pImpl->window) pImpl->window->maximize();
249
247
  success = true;
250
248
  } else if (winMethod == "restore") {
251
- pImpl->windowManager->restore();
249
+ if (pImpl->window) pImpl->window->restore();
252
250
  success = true;
253
251
  } else if (winMethod == "close") {
254
- pImpl->windowManager->close();
252
+ if (pImpl->window) pImpl->window->close();
255
253
  success = true;
256
254
  } else if (winMethod == "show") {
257
- pImpl->windowManager->show();
255
+ if (pImpl->window) pImpl->window->show();
258
256
  success = true;
259
257
  } else if (winMethod == "hide") {
260
- pImpl->windowManager->hide();
258
+ if (pImpl->window) pImpl->window->hide();
261
259
  success = true;
262
260
  } else if (winMethod == "getSize") {
263
- auto size =
264
- pImpl->windowManager->getSize();
265
- result = "{\"width\":" +
266
- std::to_string(size.width) +
267
- ",\"height\":" +
268
- std::to_string(size.height) +
269
- "}";
261
+ if (pImpl->window) {
262
+ int w, h;
263
+ pImpl->window->getSize(w, h);
264
+ result = "{\"width\":" +
265
+ std::to_string(w) +
266
+ ",\"height\":" +
267
+ std::to_string(h) +
268
+ "}";
269
+ }
270
270
  success = true;
271
271
  } else if (winMethod == "getPosition") {
272
- auto pos =
273
- pImpl->windowManager->getPosition();
274
- result =
275
- "{\"x\":" + std::to_string(pos.x) +
276
- ",\"y\":" + std::to_string(pos.y) +
277
- "}";
272
+ if (pImpl->window) {
273
+ int x, y;
274
+ pImpl->window->getPosition(x, y);
275
+ result =
276
+ "{\"x\":" + std::to_string(x) +
277
+ ",\"y\":" + std::to_string(y) +
278
+ "}";
279
+ }
278
280
  success = true;
279
281
  } else if (winMethod == "setSize") {
280
282
  // Parse params [width, height]
@@ -287,7 +289,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
287
289
  int w = 0, h = 0;
288
290
  sscanf(params.c_str(), "%d, %d", &w,
289
291
  &h);
290
- pImpl->windowManager->setSize(w, h);
292
+ if (pImpl->window) pImpl->window->setSize(w, h);
291
293
  }
292
294
  success = true;
293
295
  } else if (winMethod == "setPosition") {
@@ -300,7 +302,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
300
302
  int x = 0, y = 0;
301
303
  sscanf(params.c_str(), "%d, %d", &x,
302
304
  &y);
303
- pImpl->windowManager->setPosition(x, y);
305
+ if (pImpl->window) pImpl->window->setPosition(x, y);
304
306
  }
305
307
  success = true;
306
308
  } else if (winMethod == "setTitle") {
@@ -310,7 +312,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
310
312
  p2 != std::string::npos) {
311
313
  std::string title =
312
314
  msg.substr(p1 + 2, p2 - p1 - 2);
313
- pImpl->windowManager->setTitle(title);
315
+ if (pImpl->window) pImpl->window->setTitle(title);
314
316
  }
315
317
  success = true;
316
318
  } else if (winMethod == "setFullscreen") {
@@ -320,7 +322,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
320
322
  p2 != std::string::npos) {
321
323
  std::string params =
322
324
  msg.substr(p1 + 1, p2 - p1 - 1);
323
- pImpl->windowManager->setFullscreen(
325
+ if (pImpl->window) pImpl->window->setFullscreen(
324
326
  params.find("true") !=
325
327
  std::string::npos);
326
328
  }
@@ -332,7 +334,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
332
334
  p2 != std::string::npos) {
333
335
  std::string params =
334
336
  msg.substr(p1 + 1, p2 - p1 - 1);
335
- pImpl->windowManager->setAlwaysOnTop(
337
+ if (pImpl->window) pImpl->window->setAlwaysOnTop(
336
338
  params.find("true") !=
337
339
  std::string::npos);
338
340
  }
@@ -344,30 +346,30 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
344
346
  p2 != std::string::npos) {
345
347
  std::string params =
346
348
  msg.substr(p1 + 1, p2 - p1 - 1);
347
- pImpl->windowManager->setResizable(
349
+ if (pImpl->window) pImpl->window->setResizable(
348
350
  params.find("true") !=
349
351
  std::string::npos);
350
352
  }
351
353
  success = true;
352
354
  } else if (winMethod == "isMaximized") {
353
355
  result =
354
- pImpl->windowManager->isMaximized()
356
+ (pImpl->window && pImpl->window->isMaximized())
355
357
  ? "true"
356
358
  : "false";
357
359
  success = true;
358
360
  } else if (winMethod == "isMinimized") {
359
361
  result =
360
- pImpl->windowManager->isMinimized()
362
+ (pImpl->window && pImpl->window->isMinimized())
361
363
  ? "true"
362
364
  : "false";
363
365
  success = true;
364
366
  } else if (winMethod == "isVisible") {
365
- result = pImpl->windowManager->isVisible()
367
+ result = (pImpl->window && pImpl->window->isVisible())
366
368
  ? "true"
367
369
  : "false";
368
370
  success = true;
369
371
  } else if (winMethod == "center") {
370
- pImpl->windowManager->setCenter();
372
+ if (pImpl->window) pImpl->window->center();
371
373
  success = true;
372
374
  }
373
375
  } else if (method.find("tray.") == 0) {
@@ -432,7 +434,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
432
434
  } else if (method.find("app.") == 0) {
433
435
  std::string appMethod = method.substr(4);
434
436
  if (appMethod == "quit") {
435
- pImpl->windowManager->close();
437
+ if (pImpl->window) pImpl->window->close();
436
438
  PostQuitMessage(0);
437
439
  success = true;
438
440
  }
@@ -725,7 +727,6 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
725
727
 
726
728
  #endif
727
729
 
728
- win.pImpl->windowManager = std::make_unique<WindowManager>(windowHandle);
729
730
  win.pImpl->trayManager = std::make_unique<TrayManager>();
730
731
  win.pImpl->trayManager->setWindowHandle(windowHandle);
731
732
 
@@ -733,7 +734,6 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
733
734
  }
734
735
 
735
736
  TrayManager &Window::tray() { return *pImpl->trayManager; }
736
- WindowManager &Window::windowManager() { return *pImpl->windowManager; }
737
737
 
738
738
  void Window::setWindow(std::shared_ptr<Window> win) {
739
739
  pImpl->window = win;
@@ -3,7 +3,6 @@
3
3
 
4
4
  #include "tray.hpp"
5
5
  #include "window.hpp"
6
- #include "window_manager.hpp"
7
6
  #include <functional>
8
7
  #include <future>
9
8
  #include <memory>
@@ -36,4 +36,3 @@
36
36
  #include <plusui/tray.hpp>
37
37
  #include <plusui/webgpu.hpp>
38
38
  #include <plusui/window.hpp>
39
- #include <plusui/window_manager.hpp>
@@ -10,7 +10,6 @@
10
10
  namespace plusui {
11
11
 
12
12
  class TrayManager;
13
- class WindowManager;
14
13
 
15
14
  struct WindowConfig {
16
15
  // Window properties
@@ -207,7 +206,6 @@ public:
207
206
 
208
207
  // Features
209
208
  TrayManager &tray();
210
- WindowManager &windowManager();
211
209
 
212
210
  private:
213
211
  struct Impl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,428 +0,0 @@
1
- #include <plusui/window_manager.hpp>
2
- #include <stb_image.h>
3
-
4
- #ifdef _WIN32
5
- #include <windows.h>
6
- #elif defined(__APPLE__)
7
- #include <Cocoa/Cocoa.h>
8
- #else
9
- #include <gtk/gtk.h>
10
- #endif
11
-
12
- namespace plusui {
13
-
14
- struct WindowManager::Impl {
15
- void *nativeWindow = nullptr;
16
- bool visible = true;
17
- bool maximized = false;
18
- bool minimized = false;
19
-
20
- #ifdef _WIN32
21
- HWND hwnd() const { return (HWND)nativeWindow; }
22
- #endif
23
- };
24
-
25
- WindowManager::WindowManager() : pImpl(std::make_unique<Impl>()) {}
26
-
27
- WindowManager::WindowManager(void *nativeWindow)
28
- : pImpl(std::make_unique<Impl>()) {
29
- pImpl->nativeWindow = nativeWindow;
30
- }
31
-
32
- WindowManager::~WindowManager() = default;
33
-
34
- void WindowManager::setTitle(const std::string &title) {
35
- #ifdef _WIN32
36
- if (pImpl->nativeWindow) {
37
- std::wstring wideTitle(title.begin(), title.end());
38
- SetWindowTextW(pImpl->hwnd(), wideTitle.c_str());
39
- }
40
- #elif defined(__APPLE__)
41
- // macOS implementation
42
- #else
43
- if (pImpl->nativeWindow) {
44
- gtk_window_set_title(GTK_WINDOW(pImpl->nativeWindow), title.c_str());
45
- }
46
- #endif
47
- }
48
-
49
- void WindowManager::setSize(int width, int height) {
50
- #ifdef _WIN32
51
- if (pImpl->nativeWindow) {
52
- SetWindowPos(pImpl->hwnd(), nullptr, 0, 0, width, height,
53
- SWP_NOMOVE | SWP_NOZORDER);
54
- }
55
- #elif defined(__APPLE__)
56
- // macOS implementation
57
- #else
58
- if (pImpl->nativeWindow) {
59
- gtk_window_resize(GTK_WINDOW(pImpl->nativeWindow), width, height);
60
- }
61
- #endif
62
- }
63
-
64
- WindowSize WindowManager::getSize() const {
65
- WindowSize size;
66
- #ifdef _WIN32
67
- if (pImpl->nativeWindow) {
68
- RECT rc;
69
- GetWindowRect(pImpl->hwnd(), &rc);
70
- size.width = rc.right - rc.left;
71
- size.height = rc.bottom - rc.top;
72
- }
73
- #elif defined(__APPLE__)
74
- // macOS implementation
75
- #else
76
- if (pImpl->nativeWindow) {
77
- gint w, h;
78
- gtk_window_get_size(GTK_WINDOW(pImpl->nativeWindow), &w, &h);
79
- size.width = w;
80
- size.height = h;
81
- }
82
- #endif
83
- return size;
84
- }
85
-
86
- void WindowManager::setPosition(int x, int y) {
87
- #ifdef _WIN32
88
- if (pImpl->nativeWindow) {
89
- SetWindowPos(pImpl->hwnd(), nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
90
- }
91
- #elif defined(__APPLE__)
92
- // macOS implementation
93
- #else
94
- if (pImpl->nativeWindow) {
95
- gtk_window_move(GTK_WINDOW(pImpl->nativeWindow), x, y);
96
- }
97
- #endif
98
- }
99
-
100
- WindowPosition WindowManager::getPosition() const {
101
- WindowPosition pos;
102
- #ifdef _WIN32
103
- if (pImpl->nativeWindow) {
104
- RECT rc;
105
- GetWindowRect(pImpl->hwnd(), &rc);
106
- pos.x = rc.left;
107
- pos.y = rc.top;
108
- }
109
- #elif defined(__APPLE__)
110
- // macOS implementation
111
- #else
112
- if (pImpl->nativeWindow) {
113
- gint x, y;
114
- gtk_window_get_position(GTK_WINDOW(pImpl->nativeWindow), &x, &y);
115
- pos.x = x;
116
- pos.y = y;
117
- }
118
- #endif
119
- return pos;
120
- }
121
-
122
- void WindowManager::setCenter() {
123
- #ifdef _WIN32
124
- if (pImpl->nativeWindow) {
125
- RECT rc, screen;
126
- GetWindowRect(pImpl->hwnd(), &rc);
127
- SystemParametersInfo(SPI_GETWORKAREA, 0, &screen, 0);
128
- int x = (screen.right - (rc.right - rc.left)) / 2;
129
- int y = (screen.bottom - (rc.bottom - rc.top)) / 2;
130
- SetWindowPos(pImpl->hwnd(), nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
131
- }
132
- #elif defined(__APPLE__)
133
- // macOS implementation
134
- #else
135
- if (pImpl->nativeWindow) {
136
- gtk_window_set_position(GTK_WINDOW(pImpl->nativeWindow),
137
- GTK_WIN_POS_CENTER);
138
- }
139
- #endif
140
- }
141
-
142
- void WindowManager::setFullscreen(bool enabled) {
143
- #ifdef _WIN32
144
- if (pImpl->nativeWindow) {
145
- if (enabled) {
146
- ShowWindow(pImpl->hwnd(), SW_MAXIMIZE);
147
- } else {
148
- ShowWindow(pImpl->hwnd(), SW_RESTORE);
149
- }
150
- }
151
- #elif defined(__APPLE__)
152
- // macOS implementation
153
- #else
154
- if (pImpl->nativeWindow) {
155
- if (enabled) {
156
- gtk_window_fullscreen(GTK_WINDOW(pImpl->nativeWindow));
157
- } else {
158
- gtk_window_unfullscreen(GTK_WINDOW(pImpl->nativeWindow));
159
- }
160
- }
161
- #endif
162
- }
163
-
164
- void WindowManager::setAlwaysOnTop(bool enabled) {
165
- #ifdef _WIN32
166
- if (pImpl->nativeWindow) {
167
- SetWindowPos(pImpl->hwnd(), enabled ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0,
168
- 0, 0, SWP_NOMOVE | SWP_NOSIZE);
169
- }
170
- #elif defined(__APPLE__)
171
- // macOS implementation
172
- #else
173
- if (pImpl->nativeWindow) {
174
- gtk_window_set_keep_above(GTK_WINDOW(pImpl->nativeWindow), enabled);
175
- }
176
- #endif
177
- }
178
-
179
- void WindowManager::setResizable(bool enabled) {
180
- #ifdef _WIN32
181
- if (pImpl->nativeWindow) {
182
- LONG style = GetWindowLong(pImpl->hwnd(), GWL_STYLE);
183
- if (enabled) {
184
- style |= WS_THICKFRAME;
185
- } else {
186
- style &= ~WS_THICKFRAME;
187
- }
188
- SetWindowLong(pImpl->hwnd(), GWL_STYLE, style);
189
- }
190
- #elif defined(__APPLE__)
191
- // macOS implementation
192
- #else
193
- if (pImpl->nativeWindow) {
194
- gtk_window_set_resizable(GTK_WINDOW(pImpl->nativeWindow), enabled);
195
- }
196
- #endif
197
- }
198
-
199
- void WindowManager::setDecorations(bool enabled) {
200
- #ifdef _WIN32
201
- if (pImpl->nativeWindow) {
202
- LONG style = GetWindowLong(pImpl->hwnd(), GWL_STYLE);
203
- if (enabled) {
204
- style |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
205
- } else {
206
- style &= ~(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
207
- }
208
- SetWindowLong(pImpl->hwnd(), GWL_STYLE, style);
209
- }
210
- #elif defined(__APPLE__)
211
- // macOS implementation
212
- #else
213
- if (pImpl->nativeWindow) {
214
- gtk_window_set_decorated(GTK_WINDOW(pImpl->nativeWindow), enabled);
215
- }
216
- #endif
217
- }
218
-
219
- void WindowManager::setSkipTaskbar(bool enabled) {
220
- #ifdef _WIN32
221
- if (pImpl->nativeWindow) {
222
- LONG exStyle = GetWindowLong(pImpl->hwnd(), GWL_EXSTYLE);
223
- if (enabled) {
224
- exStyle |= WS_EX_TOOLWINDOW;
225
- } else {
226
- exStyle &= ~WS_EX_TOOLWINDOW;
227
- }
228
- SetWindowLong(pImpl->hwnd(), GWL_EXSTYLE, exStyle);
229
- }
230
- #endif
231
- }
232
-
233
- void WindowManager::setTransparency(double alpha) {
234
- #ifdef _WIN32
235
- if (pImpl->nativeWindow) {
236
- LONG exStyle = GetWindowLong(pImpl->hwnd(), GWL_EXSTYLE);
237
- SetWindowLong(pImpl->hwnd(), GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
238
- SetLayeredWindowAttributes(pImpl->hwnd(), 0, (BYTE)(alpha * 255),
239
- LWA_ALPHA);
240
- }
241
- #elif defined(__APPLE__)
242
- // macOS implementation
243
- #else
244
- if (pImpl->nativeWindow) {
245
- gtk_widget_set_opacity(GTK_WIDGET(pImpl->nativeWindow), alpha);
246
- }
247
- #endif
248
- }
249
-
250
- void WindowManager::minimize() {
251
- #ifdef _WIN32
252
- if (pImpl->nativeWindow) {
253
- ShowWindow(pImpl->hwnd(), SW_MINIMIZE);
254
- }
255
- #elif defined(__APPLE__)
256
- // macOS implementation
257
- #else
258
- if (pImpl->nativeWindow) {
259
- gtk_window_iconify(GTK_WINDOW(pImpl->nativeWindow));
260
- }
261
- #endif
262
- }
263
-
264
- void WindowManager::maximize() {
265
- #ifdef _WIN32
266
- if (pImpl->nativeWindow) {
267
- ShowWindow(pImpl->hwnd(), SW_MAXIMIZE);
268
- }
269
- #elif defined(__APPLE__)
270
- // macOS implementation
271
- #else
272
- if (pImpl->nativeWindow) {
273
- gtk_window_maximize(GTK_WINDOW(pImpl->nativeWindow));
274
- }
275
- #endif
276
- }
277
-
278
- void WindowManager::restore() {
279
- #ifdef _WIN32
280
- if (pImpl->nativeWindow) {
281
- ShowWindow(pImpl->hwnd(), SW_RESTORE);
282
- }
283
- #elif defined(__APPLE__)
284
- // macOS implementation
285
- #else
286
- if (pImpl->nativeWindow) {
287
- gtk_window_unmaximize(GTK_WINDOW(pImpl->nativeWindow));
288
- }
289
- #endif
290
- }
291
-
292
- void WindowManager::show() {
293
- pImpl->visible = true;
294
- #ifdef _WIN32
295
- if (pImpl->nativeWindow) {
296
- ShowWindow(pImpl->hwnd(), SW_SHOW);
297
- }
298
- #elif defined(__APPLE__)
299
- // macOS implementation
300
- #else
301
- if (pImpl->nativeWindow) {
302
- gtk_widget_show(GTK_WIDGET(pImpl->nativeWindow));
303
- }
304
- #endif
305
- }
306
-
307
- void WindowManager::hide() {
308
- pImpl->visible = false;
309
- #ifdef _WIN32
310
- if (pImpl->nativeWindow) {
311
- ShowWindow(pImpl->hwnd(), SW_HIDE);
312
- }
313
- #elif defined(__APPLE__)
314
- // macOS implementation
315
- #else
316
- if (pImpl->nativeWindow) {
317
- gtk_widget_hide(GTK_WIDGET(pImpl->nativeWindow));
318
- }
319
- #endif
320
- }
321
-
322
- void WindowManager::close() {
323
- #ifdef _WIN32
324
- if (pImpl->nativeWindow) {
325
- PostMessage(pImpl->hwnd(), WM_CLOSE, 0, 0);
326
- }
327
- #elif defined(__APPLE__)
328
- // macOS implementation
329
- #else
330
- if (pImpl->nativeWindow) {
331
- gtk_window_close(GTK_WINDOW(pImpl->nativeWindow));
332
- }
333
- #endif
334
- }
335
-
336
- bool WindowManager::isMaximized() const { return pImpl->maximized; }
337
-
338
- bool WindowManager::isMinimized() const { return pImpl->minimized; }
339
-
340
- bool WindowManager::isVisible() const { return pImpl->visible; }
341
-
342
- void WindowManager::setIcon(const std::string& iconPath) {
343
- #ifdef _WIN32
344
- if (pImpl->nativeWindow && !iconPath.empty()) {
345
- std::wstring wpath(iconPath.begin(), iconPath.end());
346
- HICON hIcon = (HICON)LoadImageW(nullptr, wpath.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
347
- if (hIcon) {
348
- SendMessage(pImpl->hwnd(), WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
349
- SendMessage(pImpl->hwnd(), WM_SETICON, ICON_BIG, (LPARAM)hIcon);
350
- }
351
- }
352
- #elif defined(__APPLE__)
353
- // macOS implementation
354
- #else
355
- if (pImpl->nativeWindow && !iconPath.empty()) {
356
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(iconPath.c_str(), nullptr);
357
- if (pixbuf) {
358
- gtk_window_set_icon(GTK_WINDOW(pImpl->nativeWindow), pixbuf);
359
- g_object_unref(pixbuf);
360
- }
361
- }
362
- #endif
363
- }
364
-
365
- void WindowManager::setIconFromMemory(const unsigned char *data, size_t size) {
366
- #ifdef _WIN32
367
- if (pImpl->nativeWindow && data && size > 0) {
368
- int width, height, channels;
369
- unsigned char *pixels = stbi_load_from_memory(data, (int)size, &width, &height, &channels, 4);
370
- if (pixels) {
371
- // Convert RGBA to BGRA for Windows
372
- for (int i = 0; i < width * height; ++i) {
373
- unsigned char r = pixels[i * 4 + 0];
374
- unsigned char b = pixels[i * 4 + 2];
375
- pixels[i * 4 + 0] = b;
376
- pixels[i * 4 + 2] = r;
377
- }
378
-
379
- BITMAPINFO bmi = {};
380
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
381
- bmi.bmiHeader.biWidth = width;
382
- bmi.bmiHeader.biHeight = -height;
383
- bmi.bmiHeader.biPlanes = 1;
384
- bmi.bmiHeader.biBitCount = 32;
385
- bmi.bmiHeader.biCompression = BI_RGB;
386
-
387
- void *bits = nullptr;
388
- HBITMAP hbm = CreateDIBSection(nullptr, &bmi, DIB_RGB_COLORS, &bits, nullptr, 0);
389
- if (hbm && bits) {
390
- memcpy(bits, pixels, width * height * 4);
391
-
392
- ICONINFO ii = {};
393
- ii.fIcon = TRUE;
394
- ii.hbmColor = hbm;
395
- ii.hbmMask = CreateCompatibleBitmap(GetDC(nullptr), width, height);
396
-
397
- HICON hIcon = CreateIconIndirect(&ii);
398
- if (hIcon) {
399
- SendMessage(pImpl->hwnd(), WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
400
- SendMessage(pImpl->hwnd(), WM_SETICON, ICON_BIG, (LPARAM)hIcon);
401
- }
402
-
403
- DeleteObject(ii.hbmMask);
404
- DeleteObject(hbm);
405
- }
406
-
407
- stbi_image_free(pixels);
408
- }
409
- }
410
- #elif defined(__APPLE__)
411
- // macOS implementation
412
- #else
413
- if (pImpl->nativeWindow && data && size > 0) {
414
- int width, height, channels;
415
- unsigned char *pixels = stbi_load_from_memory(data, (int)size, &width, &height, &channels, 4);
416
- if (pixels) {
417
- GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, TRUE, 8, width, height, width * 4, nullptr, nullptr);
418
- if (pixbuf) {
419
- gtk_window_set_icon(GTK_WINDOW(pImpl->nativeWindow), pixbuf);
420
- g_object_unref(pixbuf);
421
- }
422
- stbi_image_free(pixels);
423
- }
424
- }
425
- #endif
426
- }
427
-
428
- } // namespace plusui
@@ -1,59 +0,0 @@
1
- #ifndef PLUSUI_WINDOW_MANAGER_H
2
- #define PLUSUI_WINDOW_MANAGER_H
3
-
4
- #include <string>
5
- #include <memory>
6
-
7
- namespace plusui {
8
-
9
- struct WindowSize {
10
- int width = 0;
11
- int height = 0;
12
- };
13
-
14
- struct WindowPosition {
15
- int x = 0;
16
- int y = 0;
17
- };
18
-
19
- class WindowManager {
20
- public:
21
- WindowManager();
22
- explicit WindowManager(void* nativeWindow);
23
- ~WindowManager();
24
-
25
- // Window operations
26
- void setTitle(const std::string& title);
27
- void setSize(int width, int height);
28
- WindowSize getSize() const;
29
- void setPosition(int x, int y);
30
- WindowPosition getPosition() const;
31
- void setCenter();
32
- void setFullscreen(bool enabled);
33
- void setAlwaysOnTop(bool enabled);
34
- void setResizable(bool enabled);
35
- void setDecorations(bool enabled);
36
- void setSkipTaskbar(bool enabled);
37
- void setTransparency(double alpha);
38
- void setIcon(const std::string& iconPath);
39
- void setIconFromMemory(const unsigned char *data, size_t size);
40
-
41
- void minimize();
42
- void maximize();
43
- void restore();
44
- void show();
45
- void hide();
46
- void close();
47
-
48
- bool isMaximized() const;
49
- bool isMinimized() const;
50
- bool isVisible() const;
51
-
52
- private:
53
- struct Impl;
54
- std::unique_ptr<Impl> pImpl;
55
- };
56
-
57
- } // namespace plusui
58
-
59
- #endif