1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399 |
#include "fsCHardware.h"
#include <axmol.h>
#include <base/AutoreleasePool.h>
#include <platform/FileUtils.h>
#include <platform/Application.h>
#if defined fsDesktop && AX_TARGET_PLATFORM != AX_PLATFORM_WINUWP
#ifdef AXMOL_V3
#include <platform/RenderView.h>
#else
#include <platform/RenderViewImpl.h>
#endif
#endif
#include <fsCore/fsIResourceNamePathAdjuster.h>
#include <fsCore/src/fsNRnd.h>
#include <fsCore/src/fsCAppSettings.h>
#include <fsAppCore/src/fsCAppCoreMain.h>
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS) || (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
#include "fsCHardwareImpl.h"
#endif
void fsCHardware::cursorPosSet(const fsVec2d& pPos) {
#if fsDESKTOP_PC
const auto renderView = ax::Director::getInstance()->getRenderView();
#ifdef AXMOL_V3
auto renderViewDesktop = static_cast<ax::RenderView*>(renderView);
#else
auto renderViewDesktop = static_cast<ax::RenderViewImpl*>(renderView);
#endif
auto glWindow = renderViewDesktop->getWindow();
glfwSetCursorPos(glWindow,pPos.x,pPos.y);
#else
fsCAppCoreMain::instanceGet()->cursorPosSet(pPos);
#endif
}
void fsCHardware::timeScaleSet(fsF32 pScale)
{
axmol::Director::getInstance()->getScheduler()->setTimeScale(pScale);
}
#if defined fsDesktop
void fsCHardware::appHideEnable()
{
#if defined fsDESKTOP_MAC
auto renderView = static_cast<axmol::RenderView*>(axmol::Director::getInstance()->getRenderView());
mImpl->appHideEnable(renderView);
#endif
}
fsCHardware::SCursor::~SCursor()
{
#if !defined fsUWPStore
glfwDestroyCursor(mCursor);
#endif
}
void fsCHardware::enterEvent(GLFWwindow* window, int entered)<--- Unused private function: 'fsCHardware::enterEvent'<--- Parameter 'window' can be declared as pointer to const
{
#if !defined fsUWPStore
auto hardware = static_cast<fsCHardware*>(glfwGetWindowUserPointer(window));
if (entered)
{
glfwSetCursor(glfwGetCurrentContext(), hardware->mCursor);
}
else
{
glfwSetCursor(glfwGetCurrentContext(), nullptr);
}
#endif
}
void fsCHardware::cursorApply()<--- Unused private function: 'fsCHardware::cursorApply'
{
#if !defined fsUWPStore
//glfwSetCursor(glfwGetCurrentContext(), mCursor);
#ifdef AXMOL_V3
auto glView = static_cast<axmol::RenderView*>(axmol::Director::getInstance()->getRenderView());
#else
auto glView = static_cast<axmol::RenderViewImpl*>(axmol::Director::getInstance()->getRenderView());
#endif
glfwSetCursor(glView->getWindow(), mCursor);
#endif
}
void fsCHardware::cursorClear()
{
#if !defined fsUWPStore
if (mCursor)
{
glfwDestroyCursor(mCursor);
mCursor = nullptr;
}
cursorApply();
#endif
}
void fsCHardware::cursorCreate(fsStr const& pFilename, fsBool pFlipped)
{
#if !defined fsUWPStore
cursorClear();
axmol::Image mImage;
mImage.initWithImageFile(pFilename.utf8Get());
const uint8_t* originalData = mImage.getData();
GLFWimage image;
image.width = mImage.getWidth();
image.height = mImage.getHeight();
image.pixels = mImage.getData();
uint8_t* mirrored_image = nullptr;
if (pFlipped)
{
#ifdef AXMOL_V3
mirrored_image = new uint8_t[mImage.getDataSize()];
#else
mirrored_image = new uint8_t[mImage.getDataLen()];
#endif
for (int row = 0; row < mImage.getHeight(); row++)
{
for (int col = 0; col < mImage.getWidth(); col++)
{
const int opposite_col = mImage.getWidth() - col - 1; // get the position at the opposite end of the row
for (int channel = 0; channel < 4; channel++)
{
mirrored_image[(row * mImage.getWidth() + col) * 4 + channel] =
originalData[(row * mImage.getWidth() + opposite_col) * 4 + channel];
}
}
}
image.pixels = mirrored_image;
}
mCursor = glfwCreateCursor(&image, pFlipped ? mImage.getWidth() - 1 : 0, 0);
delete[] mirrored_image;
cursorApply();
#endif
}
void fsCHardware::appMinimize()
{
#if !defined fsUWPStore
#ifdef AXMOL_V3
auto glWindow = static_cast<axmol::RenderView*>(axmol::Director::getInstance()->getRenderView())->getWindow();
#else
auto glWindow = static_cast<axmol::RenderViewImpl*>(axmol::Director::getInstance()->getRenderView())->getWindow();
#endif
if (glfwGetWindowMonitor(glWindow))
{
mWindowFullscreen = true;
GLFWvidmode const* mMode = glfwGetVideoMode(glfwGetWindowMonitor(glWindow));
mWindowWWidth = mMode->width;
mWindowHeight = mMode->height;
glfwSetWindowMonitor(glWindow, nullptr, 0, 0, 200, 200, GLFW_DONT_CARE);
}
else
{
mWindowFullscreen = false;
}
#endif
}
void fsCHardware::appMaximize()
{
#if !defined fsUWPStore
#ifdef AXMOL_V3
auto renderView = static_cast<axmol::RenderView*>(axmol::Director::getInstance()->getRenderView())->getWindow();
#else
auto renderView = static_cast<axmol::RenderViewImpl*>(axmol::Director::getInstance()->getRenderView())->getWindow();
#endif
if (mWindowFullscreen)
{
glfwSetWindowMonitor(renderView, glfwGetPrimaryMonitor(), 0, 0, mWindowWWidth, mWindowHeight, GLFW_DONT_CARE);
}
glfwFocusWindow(renderView);
#endif
}
void fsCHardware::wallpaperApplyDo(const fsCResourceName& pWallpaper)
{
#if defined fsMacStore
mImpl->wallpaperSet(pWallpaper.nameGet());
#elif defined fsPCStore
fsStr wallpaperFullPath = axmol::FileUtils::getInstance()->fullPathForFilename(pWallpaper.nameGet().utf8Get()).c_str();
int wideLen = MultiByteToWideChar(CP_UTF8, 0, wallpaperFullPath.utf8Get(), -1, nullptr, 0);
if (wideLen > 0) {
std::vector<wchar_t> widePath(wideLen);
MultiByteToWideChar(CP_UTF8, 0, wallpaperFullPath.utf8Get(), -1, widePath.data(), wideLen);
// Method 1: Try using SystemParametersInfo first
BOOL result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)widePath.data(), SPIF_UPDATEINIFILE);
if (!result) {
DWORD error = GetLastError();
// Method 2: Try using the Windows Desktop API
if (error == ERROR_ACCESS_DENIED || error == ERROR_PRIVILEGE_NOT_HELD) {
// Try to get the desktop window handle
HWND desktop = GetDesktopWindow();
if (desktop) {
// Try to set wallpaper using the desktop window
result = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)widePath.data(),
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
}
}
// If any method succeeded, set the style
// if (result) {
// SystemParametersInfo(SPI_SETDESKWALLPAPERSTYLE, 0, (void*)2, SPIF_UPDATEINIFILE);
// }
}
#endif
}
void fsCHardware::windowedDisplayModesEnumerate(fsDisplayInfo*& pAvailableModeList, fsS32& pNumModesInList)
{
// windowsSystemExtAvailableDisplayModesEnumerate(&pAvailableModeList, &pNumModesInList); // initial call to get buffer size
// pAvailableModeList = new fsDisplayInfo[pNumModesInList];
// windowsSystemExtAvailableDisplayModesEnumerate(&pAvailableModeList, &pNumModesInList);
}
void fsCHardware::hardwareCursorInit()
{
#if !defined fsUWPStore
glfwSetWindowUserPointer(glfwGetCurrentContext(), this);
glfwSetCursorEnterCallback(glfwGetCurrentContext(), &fsCHardware::enterEvent);
glfwSetCursor(glfwGetCurrentContext(), mCursor);
#endif
}
void fsCHardware::hardwareCursorUninit()
{
}
void fsCHardware::hardwareCursorChange(const fsStr& pID)
{
// winMouseExtHardwareCursorGraphicSet(pID.utf8Get());
}
#endif
void fsCHardware::engineCacheFlush() const
{
axmol::PoolManager::getInstance()->getCurrentPool()->clear();
}
void fsCHardware::rndSeedDo() const
{
// fsNRnd::seedSet(static_cast< fsU32 >(s3eTimerGetUTC()));
}
fsU64 fsCHardware::utcTimeGet() const
{
return 0;
// return s3eTimerGetUTC();
}
fsIHardware::ePlatform fsCHardware::platformGet() const
{
#if defined fsRELEASE
#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
return eWINDOWS;
#elif AX_TARGET_PLATFORM == AX_PLATFORM_MAC
return eOSX;
#elif AX_TARGET_PLATFORM == AX_PLATFORM_WINUWP
return eWINUWP;
#else
return fsIHardware::eMOBILE;
#endif
#else
return static_cast<fsIHardware::ePlatform>(fsCAppCoreMain::instanceGet()->settingsGet()->debugSettingsGet()->s32Get("platform"));
#endif
}
fsBool fsCHardware::smallDeviceGet() const
{
#if defined fsRELEASE
const int dpi = axmol::Device::getDPI();
float xInches = axmol::Director::getInstance()->getWinSize().width / dpi;
float yInches = axmol::Director::getInstance()->getWinSize().height / dpi;
float diagonalInches = sqrtf(xInches * xInches + yInches * yInches);
diagonalInches = roundf(diagonalInches * 100.0f) / 100.0f;
return (diagonalInches < 7.0f);
#else
return fsCAppCoreMain::instanceGet()->settingsGet()->debugSettingsGet()->boolGet( "smallDevice" );
#endif
}
fsStr fsCHardware::sdkVersionStringGet() const
{
return "axmol-" AX_VERSION_STR;
}
fsStr fsCHardware::appDataFolderGet() const
{
fsStr appFolder = axmol::FileUtils::getInstance()->getWritablePath().c_str();
#if AX_TARGET_PLATFORM != AX_PLATFORM_IOS
appFolder.erase(appFolder.rfind(fsIResourceNamePathAdjuster::mPathSeparator, appFolder.dataSizeGet() - 2) + 1);
#endif
return appFolder;
}
fsBool fsCHardware::processRunning(const fsStr& pProcessName) const
{
// #if defined fsPCStore
// #if defined fsDualExeBuild
// if ( S3E_OS_ID_WINDOWS == s3eDeviceGetInt( S3E_DEVICE_OS ) )
// {
// return windowsSystemExtProcessRunning( pProcessName.utf8Get() );
// }
// #endif
// #endif
return true;
}
fsBool fsCHardware::multipleAppInstances() const
{
// #if defined fsPCStore
// if ( S3E_OS_ID_WINDOWS == s3eDeviceGetInt( S3E_DEVICE_OS ) )
// {
// return windowsSystemExtMultipleAppInstances();
// }
// #endif
return false;
}
void fsCHardware::updateDo(fsS32 pDeltaMs)
{
}
void fsCHardware::hardwareCursorSet(const fsCResourceName& pFilename, fsBool pFlipped)
{
#if defined fsDesktop
auto director = ax::Director::getInstance();
if (auto renderView = director->getRenderView())
{
if (pFilename.nameGet().emptyGet())
{
cursorClear();
}
else
{
cursorCreate(pFilename.nameGet().utf8Get(), pFlipped);
}
}
#endif
}
void fsCHardware::hardwareCursorEnabledSet(fsBool pEnabled) const
{
#if defined fsDesktop
auto director = axmol::Director::getInstance();
if (auto renderView = director->getRenderView())
{
renderView->setCursorVisible(pEnabled);
}
#endif
}
void fsCHardware::browserLaunch(const fsStr& pUrl) const
{
axmol::Application::getInstance()->openURL(pUrl.utf8Get());
}
fsBool fsCHardware::windowedModePossibleGet() const
{
#if defined fsDesktop
return true;
#else
return false;
#endif
}
fsCHardware::fsCHardware()
#if defined fsPCStore
: mCursorInClientArea(true)
#endif
{
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS) || (AX_TARGET_PLATFORM == AX_PLATFORM_MAC)
mImpl = std::unique_ptr<fsCHardwareImpl>(new fsCHardwareImpl());<--- Variable 'mImpl' is assigned in constructor body. Consider performing initialization in initialization list. [+]When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'mImpl' a value by passing the value to the constructor in the initialization list.
#endif
}
fsCHardware::~fsCHardware()
{
}
|