-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWndMainWindow.cpp
More file actions
2040 lines (1691 loc) · 63.1 KB
/
WndMainWindow.cpp
File metadata and controls
2040 lines (1691 loc) · 63.1 KB
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
// NOTE: Apologies for the quality of this code, this is really from pre-opensource Dolphin - that is, 2003.
// It's improving slowly, though. :)
#include "Common/CommonWindows.h"
#include "Common/KeyMap.h"
#include <map>
#include <string>
#include "base/NativeApp.h"
#include "Globals.h"
#include "shellapi.h"
#include "commctrl.h"
#include "i18n/i18n.h"
#include "input/input_state.h"
#include "input/keycodes.h"
#include "thread/threadutil.h"
#include "util/text/utf8.h"
#include "Core/Debugger/SymbolMap.h"
#include "Windows/InputBox.h"
#include "Windows/OpenGLBase.h"
#include "Windows/Debugger/Debugger_Disasm.h"
#include "Windows/Debugger/Debugger_MemoryDlg.h"
#include "Windows/GEDebugger/GEDebugger.h"
#include "main.h"
#include "Core/Core.h"
#include "Core/MemMap.h"
#include "Core/SaveState.h"
#include "Core/System.h"
#include "Core/Config.h"
#include "Core/MIPS/JitCommon/NativeJit.h"
#include "Core/MIPS/JitCommon/JitBlockCache.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "Windows/EmuThread.h"
#include "resource.h"
#include "Windows/WndMainWindow.h"
#include "Windows/WindowsHost.h"
#include "Common/LogManager.h"
#include "Common/ConsoleListener.h"
#include "Windows/W32Util/DialogManager.h"
#include "Windows/W32Util/ShellUtil.h"
#include "Windows/W32Util/Misc.h"
#include "Windows/RawInput.h"
#include "Windows/TouchInputHandler.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUState.h"
#include "gfx_es2/gpu_features.h"
#include "GPU/GLES/TextureScaler.h"
#include "GPU/GLES/TextureCache.h"
#include "GPU/GLES/Framebuffer.h"
#include "ControlMapping.h"
#include "UI/OnScreenDisplay.h"
#include "GPU/Common/PostShader.h"
#include "Core/HLE/sceUmd.h"
#ifdef THEMES
#include "XPTheme.h"
#endif
#define MOUSEEVENTF_FROMTOUCH_NOPEN 0xFF515780 //http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx
#define MOUSEEVENTF_MASK_PLUS_PENTOUCH 0xFFFFFF80
static const int numCPUs = 1;
int verysleepy__useSendMessage = 1;
const UINT WM_VERYSLEEPY_MSG = WM_APP + 0x3117;
// Respond TRUE to a message with this param value to indicate support.
const WPARAM VERYSLEEPY_WPARAM_SUPPORTED = 0;
// Respond TRUE to a message wit this param value after filling in the addr name.
const WPARAM VERYSLEEPY_WPARAM_GETADDRINFO = 1;
struct VerySleepy_AddrInfo
{
// Always zero for now.
int flags;
// This is the pointer (always passed as 64 bits.)
unsigned long long addr;
// Write the name here.
wchar_t name[256];
};
extern std::map<int, int> windowsTransTable;
static RECT g_normalRC = {0};
static std::wstring windowTitle;
extern bool g_TakeScreenshot;
extern InputState input_state;
#define TIMER_CURSORUPDATE 1
#define TIMER_CURSORMOVEUPDATE 2
#define CURSORUPDATE_INTERVAL_MS 1000
#define CURSORUPDATE_MOVE_TIMESPAN_MS 500
namespace MainWindow
{
HWND hwndMain;
HWND hwndDisplay;
HWND hwndGameList;
TouchInputHandler touchHandler;
static HMENU menu;
static HINSTANCE hInst;
static int cursorCounter = 0;
static int prevCursorX = -1;
static int prevCursorY = -1;
static bool mouseButtonDown = false;
static bool hideCursor = false;
static std::map<int, std::string> initialMenuKeys;
static std::vector<std::string> countryCodes;
static std::vector<std::string> availableShaders;
static W32Util::AsyncBrowseDialog *browseDialog;
static bool browsePauseAfter;
static bool g_inModeSwitch; // when true, don't react to WM_SIZE
static int g_WindowState;
#define MAX_LOADSTRING 100
const TCHAR *szTitle = TEXT("PPSSPP");
const TCHAR *szWindowClass = TEXT("PPSSPPWnd");
const TCHAR *szDisplayClass = TEXT("PPSSPPDisplay");
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DisplayProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
HWND GetHWND() {
return hwndMain;
}
HWND GetDisplayHWND() {
return hwndDisplay;
}
void Init(HINSTANCE hInstance) {
#ifdef THEMES
WTL::CTheme::IsThemingSupported();
#endif
//Register classes
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_PARENTDC;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_PPSSPP);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = (LPCWSTR)IDR_MENU1;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = (HICON)LoadImage(hInstance, (LPCTSTR)IDI_PPSSPP, IMAGE_ICON, 16, 16, LR_SHARED);
RegisterClassEx(&wcex);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)DisplayProc;
wcex.hIcon = 0;
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = 0;
wcex.lpszClassName = szDisplayClass;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
}
void SavePosition() {
if (g_Config.bFullScreen)
return;
WINDOWPLACEMENT placement;
GetWindowPlacement(hwndMain, &placement);
if (placement.showCmd == SW_SHOWNORMAL) {
RECT rc;
GetWindowRect(hwndMain, &rc);
g_Config.iWindowX = rc.left;
g_Config.iWindowY = rc.top;
g_Config.iWindowWidth = rc.right - rc.left;
g_Config.iWindowHeight = rc.bottom - rc.top;
}
}
static void GetWindowRectAtResolution(int xres, int yres, RECT &rcInner, RECT &rcOuter) {
rcInner.left = 0;
rcInner.top = 0;
rcInner.right = xres;
rcInner.bottom = yres;
rcOuter = rcInner;
AdjustWindowRect(&rcOuter, WS_OVERLAPPEDWINDOW, TRUE);
rcOuter.right += g_Config.iWindowX - rcOuter.left;
rcOuter.bottom += g_Config.iWindowY - rcOuter.top;
rcOuter.left = g_Config.iWindowX;
rcOuter.top = g_Config.iWindowY;
}
static void ShowScreenResolution() {
I18NCategory *g = GetI18NCategory("Graphics");
std::ostringstream messageStream;
messageStream << g->T("Internal Resolution") << ": ";
messageStream << PSP_CoreParameter().renderWidth << "x" << PSP_CoreParameter().renderHeight << " ";
messageStream << g->T("Window Size") << ": ";
messageStream << PSP_CoreParameter().pixelWidth << "x" << PSP_CoreParameter().pixelHeight;
osm.Show(messageStream.str(), 2.0f);
}
static void UpdateRenderResolution() {
RECT rc;
GetClientRect(hwndMain, &rc);
// Round up to a zoom factor for the render size.
int zoom = g_Config.iInternalResolution;
if (zoom == 0) // auto mode
zoom = (rc.right - rc.left + 479) / 480;
if (zoom <= 1)
zoom = 1;
// Actually, auto mode should be more granular...
PSP_CoreParameter().renderWidth = 480 * zoom;
PSP_CoreParameter().renderHeight = 272 * zoom;
}
static void ResizeDisplay(bool noWindowMovement = false) {
AssertCurrentThreadName("Main");
int width = 0, height = 0;
RECT rc;
GetClientRect(hwndMain, &rc);
if (!noWindowMovement) {
width = rc.right - rc.left;
height = rc.bottom - rc.top;
// Moves the internal window, not the frame. TODO: Get rid of the internal window.
MoveWindow(hwndDisplay, 0, 0, width, height, TRUE);
// This is taken care of anyway later, but makes sure that ShowScreenResolution gets the right numbers.
// Need to clean all of this up...
PSP_CoreParameter().pixelWidth = width;
PSP_CoreParameter().pixelHeight = height;
}
UpdateRenderResolution();
if (!noWindowMovement) {
if (UpdateScreenScale(width, height)) {
NativeMessageReceived("gpu resized", "");
}
}
}
void SetWindowSize(int zoom) {
AssertCurrentThreadName("Main");
RECT rc, rcOuter;
GetWindowRectAtResolution(480 * (int)zoom, 272 * (int)zoom, rc, rcOuter);
MoveWindow(hwndMain, rcOuter.left, rcOuter.top, rcOuter.right - rcOuter.left, rcOuter.bottom - rcOuter.top, TRUE);
ResizeDisplay(false);
ShowScreenResolution();
}
void SetInternalResolution(int res = -1) {
if (res >= 0 && res <= RESOLUTION_MAX)
g_Config.iInternalResolution = res;
else {
if (++g_Config.iInternalResolution > RESOLUTION_MAX)
g_Config.iInternalResolution = 0;
}
// Taking auto-texture scaling into account
if (g_Config.iTexScalingLevel == TEXSCALING_AUTO)
setTexScalingMultiplier(0);
if (gpu)
gpu->Resized();
UpdateRenderResolution();
ShowScreenResolution();
}
void CorrectCursor() {
bool autoHide = g_Config.bFullScreen && !mouseButtonDown && GetUIState() == UISTATE_INGAME;
if (autoHide && hideCursor) {
while (cursorCounter >= 0) {
cursorCounter = ShowCursor(FALSE);
}
} else {
hideCursor = !autoHide;
if (cursorCounter < 0) {
cursorCounter = ShowCursor(TRUE);
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
}
}
void ToggleFullscreen(HWND hWnd, bool goingFullscreen) {
// Make sure no rendering is happening during the switch.
Core_NotifyWindowHidden(true);
g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)...
DWORD dwOldStyle;
DWORD dwNewStyle;
if (!goingFullscreen) {
// Put caption and border styles back.
dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
dwOldStyle &= ~WS_POPUP;
dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU;
// Put back the menu bar.
::SetMenu(hWnd, menu);
} else {
// If the window was maximized before going fullscreen, make sure to restore first
// in order not to have the taskbar show up on top of PPSSPP.
if (g_WindowState == SIZE_MAXIMIZED) {
ShowWindow(hwndMain, SW_RESTORE);
}
// Remember the normal window rectangle.
::GetWindowRect(hWnd, &g_normalRC);
// Remove caption and border styles.
dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE);
dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU);
// Add WS_POPUP
dwNewStyle |= WS_POPUP;
}
::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle);
// Remove the menu bar.
::SetMenu(hWnd, goingFullscreen ? NULL : menu);
// Resize to the appropriate view.
// If we're returning to window mode, re-apply the appropriate size setting.
if (goingFullscreen) {
ShowWindow(hwndMain, SW_MAXIMIZE);
} else {
ShowWindow(hwndMain, g_WindowState == SIZE_MAXIMIZED ? SW_MAXIMIZE : SW_RESTORE);
}
g_Config.bFullScreen = goingFullscreen;
CorrectCursor();
bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO);
ResizeDisplay(false);
if (showOSM) {
ShowScreenResolution();
}
ShowOwnedPopups(hwndMain, goingFullscreen ? FALSE : TRUE);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
g_inModeSwitch = false;
Core_NotifyWindowHidden(false);
WindowsRawInput::NotifyMenu();
}
RECT DetermineWindowRectangle() {
RECT rc;
const int screenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
const int screenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
const int screenX = GetSystemMetrics(SM_XVIRTUALSCREEN);
const int screenY = GetSystemMetrics(SM_YVIRTUALSCREEN);
if (!g_Config.bFullScreen) {
bool visibleHorizontally = ((g_Config.iWindowX + g_Config.iWindowWidth) >= screenX) &&
((g_Config.iWindowX + g_Config.iWindowWidth) < (screenWidth + g_Config.iWindowWidth));
bool visibleVertically = ((g_Config.iWindowY + g_Config.iWindowHeight) >= screenY) &&
((g_Config.iWindowY + g_Config.iWindowHeight) < (screenHeight + g_Config.iWindowHeight));
if (!visibleHorizontally)
g_Config.iWindowX = -1;
if (!visibleVertically)
g_Config.iWindowY = -1;
}
rc.left = g_Config.iWindowX;
rc.top = g_Config.iWindowY;
// First, get the w/h right.
if (g_Config.iWindowWidth <= 0 || g_Config.iWindowHeight <= 0) {
RECT rcInner = rc, rcOuter;
GetWindowRectAtResolution(2 * 480, 2 * 272, rcInner, rcOuter);
rc.right = rc.left + (rcOuter.right - rcOuter.left);
rc.bottom = rc.top + (rcOuter.bottom - rcOuter.top);
g_Config.iWindowWidth = rc.right - rc.left;
g_Config.iWindowHeight = rc.bottom - rc.top;
} else {
rc.right = rc.left + g_Config.iWindowWidth;
rc.bottom = rc.top + g_Config.iWindowHeight;
}
// Then center if necessary.
if (g_Config.iWindowX == -1 && g_Config.iWindowY == -1) {
// Center the window.
const int primaryScreenWidth = GetSystemMetrics(SM_CXSCREEN);
const int primaryScreenHeight = GetSystemMetrics(SM_CYSCREEN);
g_Config.iWindowX = (primaryScreenWidth - g_Config.iWindowWidth) / 2;
g_Config.iWindowY = (primaryScreenHeight - g_Config.iWindowHeight) / 2;
rc.left = g_Config.iWindowX;
rc.top = g_Config.iWindowY;
rc.right = rc.left + g_Config.iWindowWidth;
rc.bottom = rc.top + g_Config.iWindowHeight;
}
return rc;
}
void SetIngameMenuItemStates(const GlobalUIState state) {
UINT menuEnable = state == UISTATE_INGAME ? MF_ENABLED : MF_GRAYED;
UINT umdSwitchEnable = state == UISTATE_INGAME && getUMDReplacePermit()? MF_ENABLED : MF_GRAYED;
EnableMenuItem(menu, ID_FILE_SAVESTATEFILE, menuEnable);
EnableMenuItem(menu, ID_FILE_LOADSTATEFILE, menuEnable);
EnableMenuItem(menu, ID_FILE_QUICKSAVESTATE, menuEnable);
EnableMenuItem(menu, ID_FILE_QUICKLOADSTATE, menuEnable);
EnableMenuItem(menu, ID_TOGGLE_PAUSE, menuEnable);
EnableMenuItem(menu, ID_EMULATION_STOP, menuEnable);
EnableMenuItem(menu, ID_EMULATION_RESET, menuEnable);
EnableMenuItem(menu, ID_EMULATION_SWITCH_UMD, umdSwitchEnable);
EnableMenuItem(menu, ID_DEBUG_LOADMAPFILE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_SAVEMAPFILE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_LOADSYMFILE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_SAVESYMFILE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_RESETSYMBOLTABLE, menuEnable);
EnableMenuItem(menu, ID_DEBUG_EXTRACTFILE, menuEnable);
}
// These are used as an offset
// to determine which menu item to change.
// Make sure to count(from 0) the separators too, when dealing with submenus!!
enum MenuItemPosition {
// Main menus
MENU_FILE = 0,
MENU_EMULATION = 1,
MENU_DEBUG = 2,
MENU_OPTIONS = 3,
MENU_HELP = 4,
// File submenus
SUBMENU_FILE_SAVESTATE_SLOT = 6,
// Game Settings submenus
SUBMENU_CUSTOM_SHADERS = 10,
SUBMENU_RENDERING_RESOLUTION = 11,
SUBMENU_WINDOW_SIZE = 12,
SUBMENU_RENDERING_BACKEND = 13,
SUBMENU_RENDERING_MODE = 14,
SUBMENU_FRAME_SKIPPING = 15,
SUBMENU_TEXTURE_FILTERING = 16,
SUBMENU_BUFFER_FILTER = 17,
SUBMENU_TEXTURE_SCALING = 18,
};
std::string GetMenuItemText(int menuID) {
MENUITEMINFO menuInfo;
memset(&menuInfo, 0, sizeof(menuInfo));
menuInfo.cbSize = sizeof(MENUITEMINFO);
menuInfo.fMask = MIIM_STRING;
menuInfo.dwTypeData = 0;
std::string retVal;
if (GetMenuItemInfo(menu, menuID, MF_BYCOMMAND, &menuInfo) != FALSE) {
wchar_t *buffer = new wchar_t[++menuInfo.cch];
menuInfo.dwTypeData = buffer;
GetMenuItemInfo(menu, menuID, MF_BYCOMMAND, &menuInfo);
retVal = ConvertWStringToUTF8(menuInfo.dwTypeData);
delete [] buffer;
}
return retVal;
}
const std::string &GetMenuItemInitialText(const int menuID) {
if (initialMenuKeys.find(menuID) == initialMenuKeys.end()) {
initialMenuKeys[menuID] = GetMenuItemText(menuID);
}
return initialMenuKeys[menuID];
}
void CreateHelpMenu() {
I18NCategory *des = GetI18NCategory("DesktopUI");
const std::wstring help = ConvertUTF8ToWString(des->T("Help"));
const std::wstring visitMainWebsite = ConvertUTF8ToWString(des->T("www.ppsspp.org"));
const std::wstring visitForum = ConvertUTF8ToWString(des->T("PPSSPP Forums"));
const std::wstring buyGold = ConvertUTF8ToWString(des->T("Buy Gold"));
const std::wstring aboutPPSSPP = ConvertUTF8ToWString(des->T("About PPSSPP..."));
// Simply remove the old help menu and create a new one.
RemoveMenu(menu, MENU_HELP, MF_BYPOSITION);
HMENU helpMenu = CreatePopupMenu();
InsertMenu(menu, MENU_HELP, MF_POPUP | MF_STRING | MF_BYPOSITION, (UINT_PTR)helpMenu, help.c_str());
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENWEBSITE, visitMainWebsite.c_str());
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_OPENFORUM, visitForum.c_str());
// Repeat the process for other languages, if necessary.
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_BUYGOLD, buyGold.c_str());
AppendMenu(helpMenu, MF_SEPARATOR, 0, 0);
AppendMenu(helpMenu, MF_STRING | MF_BYCOMMAND, ID_HELP_ABOUT, aboutPPSSPP.c_str());
}
void UpdateDynamicMenuCheckmarks() {
int item = ID_SHADERS_BASE + 1;
for (size_t i = 0; i < availableShaders.size(); i++)
CheckMenuItem(menu, item++, ((g_Config.sPostShaderName == availableShaders[i]) ? MF_CHECKED : MF_UNCHECKED));
}
void CreateShadersSubmenu() {
I18NCategory *des = GetI18NCategory("DesktopUI");
I18NCategory *ps = GetI18NCategory("PostShaders");
const std::wstring key = ConvertUTF8ToWString(des->T("Postprocessing Shader"));
HMENU optionsMenu = GetSubMenu(menu, MENU_OPTIONS);
HMENU shaderMenu = CreatePopupMenu();
RemoveMenu(optionsMenu, SUBMENU_CUSTOM_SHADERS, MF_BYPOSITION);
InsertMenu(optionsMenu, SUBMENU_CUSTOM_SHADERS, MF_POPUP | MF_STRING | MF_BYPOSITION, (UINT_PTR)shaderMenu, key.c_str());
std::vector<ShaderInfo> info = GetAllPostShaderInfo();
availableShaders.clear();
int item = ID_SHADERS_BASE + 1;
int checkedStatus = -1;
const char *translatedShaderName = nullptr;
for (auto i = info.begin(); i != info.end(); ++i) {
checkedStatus = MF_UNCHECKED;
availableShaders.push_back(i->section);
if (g_Config.sPostShaderName == i->section) {
checkedStatus = MF_CHECKED;
}
translatedShaderName = ps->T(i->section.c_str());
AppendMenu(shaderMenu, MF_STRING | MF_BYPOSITION | checkedStatus, item++, ConvertUTF8ToWString(translatedShaderName).c_str());
}
}
void _TranslateMenuItem(const int menuIDOrPosition, const char *key, bool byCommand = false, const std::wstring& accelerator = L"", const HMENU hMenu = menu) {
I18NCategory *des = GetI18NCategory("DesktopUI");
std::wstring translated = ConvertUTF8ToWString(des->T(key));
translated.append(accelerator);
u32 flags = MF_STRING | (byCommand ? MF_BYCOMMAND : MF_BYPOSITION);
ModifyMenu(hMenu, menuIDOrPosition, flags, menuIDOrPosition, translated.c_str());
}
void TranslateMenuItem(const int menuID, const std::wstring& accelerator = L"", const char *key = "", const HMENU hMenu = menu) {
if(key == nullptr || !strcmp(key, ""))
_TranslateMenuItem(menuID, GetMenuItemInitialText(menuID).c_str(), true, accelerator, hMenu);
else
_TranslateMenuItem(menuID, key, true, accelerator, hMenu);
}
void TranslateMenu(const char *key, const MenuItemPosition mainMenuPosition, const std::wstring& accelerator = L"") {
_TranslateMenuItem(mainMenuPosition, key, false, accelerator);
}
void TranslateSubMenu(const char *key, const MenuItemPosition mainMenuItem, const MenuItemPosition subMenuItem, const std::wstring& accelerator = L"") {
_TranslateMenuItem(subMenuItem, key, false, accelerator, GetSubMenu(menu, mainMenuItem));
}
void TranslateMenus() {
// Menu headers and submenu headers don't have resource IDs,
// So we have to hardcode strings here, unfortunately.
TranslateMenu("File", MENU_FILE);
TranslateMenu("Emulation", MENU_EMULATION);
TranslateMenu("Debugging", MENU_DEBUG);
TranslateMenu("Game Settings", MENU_OPTIONS);
TranslateMenu("Help", MENU_HELP);
CreateShadersSubmenu();
// File menu
TranslateMenuItem(ID_FILE_LOAD);
TranslateMenuItem(ID_FILE_LOAD_DIR);
TranslateMenuItem(ID_FILE_LOAD_MEMSTICK);
TranslateMenuItem(ID_FILE_MEMSTICK);
TranslateSubMenu("Savestate Slot", MENU_FILE, SUBMENU_FILE_SAVESTATE_SLOT, L"\tF3");
TranslateMenuItem(ID_FILE_QUICKLOADSTATE, L"\tF4");
TranslateMenuItem(ID_FILE_QUICKSAVESTATE, L"\tF2");
TranslateMenuItem(ID_FILE_LOADSTATEFILE);
TranslateMenuItem(ID_FILE_SAVESTATEFILE);
TranslateMenuItem(ID_FILE_EXIT, L"\tAlt+F4");
// Emulation menu
TranslateMenuItem(ID_TOGGLE_PAUSE, L"\tF8", "Pause");
TranslateMenuItem(ID_EMULATION_STOP, L"\tCtrl+W");
TranslateMenuItem(ID_EMULATION_RESET, L"\tCtrl+B");
TranslateMenuItem(ID_EMULATION_SWITCH_UMD, L"\tCtrl+U", "Switch UMD");
// Debug menu
TranslateMenuItem(ID_DEBUG_LOADMAPFILE);
TranslateMenuItem(ID_DEBUG_SAVEMAPFILE);
TranslateMenuItem(ID_DEBUG_LOADSYMFILE);
TranslateMenuItem(ID_DEBUG_SAVESYMFILE);
TranslateMenuItem(ID_DEBUG_RESETSYMBOLTABLE);
TranslateMenuItem(ID_DEBUG_DUMPNEXTFRAME);
TranslateMenuItem(ID_DEBUG_TAKESCREENSHOT, L"\tF12");
TranslateMenuItem(ID_DEBUG_SHOWDEBUGSTATISTICS);
TranslateMenuItem(ID_DEBUG_IGNOREILLEGALREADS);
TranslateMenuItem(ID_DEBUG_RUNONLOAD);
TranslateMenuItem(ID_DEBUG_DISASSEMBLY, L"\tCtrl+D");
TranslateMenuItem(ID_DEBUG_GEDEBUGGER,L"\tCtrl+G");
TranslateMenuItem(ID_DEBUG_EXTRACTFILE);
TranslateMenuItem(ID_DEBUG_LOG, L"\tCtrl+L");
TranslateMenuItem(ID_DEBUG_MEMORYVIEW, L"\tCtrl+M");
// Options menu
TranslateMenuItem(ID_OPTIONS_LANGUAGE);
TranslateMenuItem(ID_OPTIONS_TOPMOST);
TranslateMenuItem(ID_OPTIONS_PAUSE_FOCUS);
TranslateMenuItem(ID_OPTIONS_IGNOREWINKEY);
TranslateMenuItem(ID_OPTIONS_MORE_SETTINGS);
TranslateMenuItem(ID_OPTIONS_CONTROLS);
TranslateMenuItem(ID_OPTIONS_STRETCHDISPLAY);
TranslateMenuItem(ID_OPTIONS_FULLSCREEN, L"\tAlt+Return, F11");
TranslateMenuItem(ID_OPTIONS_VSYNC);
TranslateSubMenu("Postprocessing Shader", MENU_OPTIONS, SUBMENU_CUSTOM_SHADERS);
TranslateSubMenu("Rendering Resolution", MENU_OPTIONS, SUBMENU_RENDERING_RESOLUTION, L"\tCtrl+1");
TranslateMenuItem(ID_OPTIONS_SCREENAUTO);
// Skip rendering resolution 2x-5x..
TranslateSubMenu("Window Size", MENU_OPTIONS, SUBMENU_WINDOW_SIZE);
// Skip window size 1x-4x..
TranslateSubMenu("Backend", MENU_OPTIONS, SUBMENU_RENDERING_BACKEND);
TranslateMenuItem(ID_OPTIONS_DIRECTX);
TranslateMenuItem(ID_OPTIONS_OPENGL);
TranslateSubMenu("Rendering Mode", MENU_OPTIONS, SUBMENU_RENDERING_MODE, L"\tF5");
TranslateMenuItem(ID_OPTIONS_NONBUFFEREDRENDERING);
TranslateMenuItem(ID_OPTIONS_BUFFEREDRENDERING);
TranslateMenuItem(ID_OPTIONS_READFBOTOMEMORYCPU);
TranslateMenuItem(ID_OPTIONS_READFBOTOMEMORYGPU);
TranslateSubMenu("Frame Skipping", MENU_OPTIONS, SUBMENU_FRAME_SKIPPING, L"\tF7");
TranslateMenuItem(ID_OPTIONS_FRAMESKIP_AUTO);
TranslateMenuItem(ID_OPTIONS_FRAMESKIP_0);
// Skip frameskipping 1-8..
TranslateSubMenu("Texture Filtering", MENU_OPTIONS, SUBMENU_TEXTURE_FILTERING);
TranslateMenuItem(ID_OPTIONS_TEXTUREFILTERING_AUTO);
TranslateMenuItem(ID_OPTIONS_NEARESTFILTERING);
TranslateMenuItem(ID_OPTIONS_LINEARFILTERING);
TranslateMenuItem(ID_OPTIONS_LINEARFILTERING_CG);
TranslateSubMenu("Screen Scaling Filter", MENU_OPTIONS, SUBMENU_BUFFER_FILTER);
TranslateMenuItem(ID_OPTIONS_BUFLINEARFILTER);
TranslateMenuItem(ID_OPTIONS_BUFNEARESTFILTER);
TranslateSubMenu("Texture Scaling", MENU_OPTIONS, SUBMENU_TEXTURE_SCALING);
TranslateMenuItem(ID_TEXTURESCALING_OFF);
// Skip texture scaling 2x-5x...
TranslateMenuItem(ID_TEXTURESCALING_XBRZ);
TranslateMenuItem(ID_TEXTURESCALING_HYBRID);
TranslateMenuItem(ID_TEXTURESCALING_BICUBIC);
TranslateMenuItem(ID_TEXTURESCALING_HYBRID_BICUBIC);
TranslateMenuItem(ID_TEXTURESCALING_DEPOSTERIZE);
TranslateMenuItem(ID_OPTIONS_HARDWARETRANSFORM, L"\tF6");
TranslateMenuItem(ID_OPTIONS_VERTEXCACHE);
TranslateMenuItem(ID_OPTIONS_SHOWFPS);
TranslateMenuItem(ID_EMULATION_SOUND);
TranslateMenuItem(ID_EMULATION_CHEATS, L"\tCtrl+T");
// Help menu: it's translated in CreateHelpMenu.
CreateHelpMenu();
// TODO: Urgh! Why do we need this here?
// The menu is supposed to enable/disable this stuff directly afterward.
SetIngameMenuItemStates(GetUIState());
DrawMenuBar(hwndMain);
UpdateMenus();
}
void setTexScalingMultiplier(int level) {
g_Config.iTexScalingLevel = level;
NativeMessageReceived("gpu clear cache", "");
}
void setTexFiltering(int type) {
g_Config.iTexFiltering = type;
}
void setBufFilter(int type) {
g_Config.iBufFilter = type;
}
void setTexScalingType(int type) {
g_Config.iTexScalingType = type;
NativeMessageReceived("gpu clear cache", "");
}
void setRenderingMode(int mode = -1) {
if (mode >= FB_NON_BUFFERED_MODE)
g_Config.iRenderingMode = mode;
else {
if (++g_Config.iRenderingMode > FB_READFBOMEMORY_GPU)
g_Config.iRenderingMode = FB_NON_BUFFERED_MODE;
}
I18NCategory *g = GetI18NCategory("Graphics");
switch(g_Config.iRenderingMode) {
case FB_NON_BUFFERED_MODE:
osm.Show(g->T("Non-Buffered Rendering"));
g_Config.bAutoFrameSkip = false;
break;
case FB_BUFFERED_MODE:
osm.Show(g->T("Buffered Rendering"));
break;
case FB_READFBOMEMORY_CPU:
osm.Show(g->T("Read Framebuffers To Memory (CPU)"));
break;
case FB_READFBOMEMORY_GPU:
osm.Show(g->T("Read Framebuffers To Memory (GPU)"));
break;
}
NativeMessageReceived("gpu resized", "");
}
void setFpsLimit(int fps) {
g_Config.iFpsLimit = fps;
}
void setFrameSkipping(int framesToSkip = -1) {
if (framesToSkip >= FRAMESKIP_OFF)
g_Config.iFrameSkip = framesToSkip;
else {
if (++g_Config.iFrameSkip > FRAMESKIP_MAX)
g_Config.iFrameSkip = FRAMESKIP_OFF;
}
I18NCategory *g = GetI18NCategory("Graphics");
std::ostringstream messageStream;
messageStream << g->T("Frame Skipping") << ":" << " ";
if (g_Config.iFrameSkip == FRAMESKIP_OFF)
messageStream << g->T("Off");
else
messageStream << g_Config.iFrameSkip;
osm.Show(messageStream.str());
}
void enableCheats(bool cheats) {
g_Config.bEnableCheats = cheats;
}
void UpdateWindowTitle() {
// Seems to be fine to call now since we use a UNICODE build...
SetWindowText(hwndMain, windowTitle.c_str());
}
void SetWindowTitle(const wchar_t *title) {
windowTitle = title;
}
BOOL Show(HINSTANCE hInstance) {
hInst = hInstance; // Store instance handle in our global variable.
RECT rc = DetermineWindowRectangle();
u32 style = WS_OVERLAPPEDWINDOW;
hwndMain = CreateWindowEx(0,szWindowClass, L"", style,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
if (!hwndMain)
return FALSE;
RECT rcClient;
GetClientRect(hwndMain, &rcClient);
hwndDisplay = CreateWindowEx(0, szDisplayClass, L"", WS_CHILD | WS_VISIBLE,
0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hwndMain, 0, hInstance, 0);
if (!hwndDisplay)
return FALSE;
menu = GetMenu(hwndMain);
#ifdef FINAL
RemoveMenu(menu,2,MF_BYPOSITION);
RemoveMenu(menu,2,MF_BYPOSITION);
#endif
MENUINFO info;
ZeroMemory(&info,sizeof(MENUINFO));
info.cbSize = sizeof(MENUINFO);
info.cyMax = 0;
info.dwStyle = MNS_CHECKORBMP;
info.fMask = MIM_STYLE;
for (int i = 0; i < GetMenuItemCount(menu); i++) {
SetMenuInfo(GetSubMenu(menu,i),&info);
}
UpdateMenus();
// Accept dragged files.
DragAcceptFiles(hwndMain, TRUE);
hideCursor = true;
SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);
ToggleFullscreen(hwndMain, g_Config.bFullScreen);
W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);
touchHandler.registerTouchWindow(hwndDisplay);
WindowsRawInput::Init();
SetFocus(hwndMain);
return TRUE;
}
void CreateDebugWindows() {
disasmWindow[0] = new CDisasm(MainWindow::GetHInstance(), MainWindow::GetHWND(), currentDebugMIPS);
DialogManager::AddDlg(disasmWindow[0]);
disasmWindow[0]->Show(g_Config.bShowDebuggerOnLoad);
geDebuggerWindow = new CGEDebugger(MainWindow::GetHInstance(), MainWindow::GetHWND());
DialogManager::AddDlg(geDebuggerWindow);
memoryWindow[0] = new CMemoryDlg(MainWindow::GetHInstance(), MainWindow::GetHWND(), currentDebugMIPS);
DialogManager::AddDlg(memoryWindow[0]);
}
void DestroyDebugWindows() {
DialogManager::RemoveDlg(disasmWindow[0]);
if (disasmWindow[0])
delete disasmWindow[0];
disasmWindow[0] = 0;
DialogManager::RemoveDlg(geDebuggerWindow);
if (geDebuggerWindow)
delete geDebuggerWindow;
geDebuggerWindow = 0;
DialogManager::RemoveDlg(memoryWindow[0]);
if (memoryWindow[0])
delete memoryWindow[0];
memoryWindow[0] = 0;
}
void BrowseAndBoot(std::string defaultPath, bool browseDirectory) {
static std::wstring filter = L"All supported file types (*.iso *.cso *.pbp *.elf *.prx *.zip)|*.pbp;*.elf;*.iso;*.cso;*.prx;*.zip|PSP ROMs (*.iso *.cso *.pbp *.elf *.prx)|*.pbp;*.elf;*.iso;*.cso;*.prx|Homebrew/Demos installers (*.zip)|*.zip|All files (*.*)|*.*||";
for (int i = 0; i < (int)filter.length(); i++) {
if (filter[i] == '|')
filter[i] = '\0';
}
browsePauseAfter = false;
if (GetUIState() == UISTATE_INGAME) {
browsePauseAfter = Core_IsStepping();
if (!browsePauseAfter)
Core_EnableStepping(true);
}
W32Util::MakeTopMost(GetHWND(), false);
if (browseDirectory) {
browseDialog = new W32Util::AsyncBrowseDialog(GetHWND(), WM_USER_BROWSE_BOOT_DONE, L"Choose directory");
} else {
browseDialog = new W32Util::AsyncBrowseDialog(W32Util::AsyncBrowseDialog::OPEN, GetHWND(), WM_USER_BROWSE_BOOT_DONE, L"LoadFile", ConvertUTF8ToWString(defaultPath), filter, L"*.pbp;*.elf;*.iso;*.cso;");
}
}
void BrowseAndBootDone() {
std::string filename;
if (!browseDialog->GetResult(filename)) {
if (!browsePauseAfter) {
Core_EnableStepping(false);
}
} else {
if (GetUIState() == UISTATE_INGAME || GetUIState() == UISTATE_PAUSEMENU) {
Core_EnableStepping(false);
}
// TODO: What is this for / what does it fix?
if (browseDialog->GetType() != W32Util::AsyncBrowseDialog::DIR) {
// Decode the filename with fullpath.
char drive[MAX_PATH];
char dir[MAX_PATH];
char fname[MAX_PATH];
char ext[MAX_PATH];
_splitpath(filename.c_str(), drive, dir, fname, ext);
filename = std::string(drive) + std::string(dir) + std::string(fname) + std::string(ext);
}
filename = ReplaceAll(filename, "\\", "/");
NativeMessageReceived("boot", filename.c_str());
}
W32Util::MakeTopMost(GetHWND(), g_Config.bTopMost);
delete browseDialog;
browseDialog = 0;
}
void UmdSwitchAction() {
std::string fn;
std::string filter = "PSP ROMs (*.iso *.cso *.pbp *.elf)|*.pbp;*.elf;*.iso;*.cso;*.prx|All files (*.*)|*.*||";
for (int i=0; i<(int)filter.length(); i++) {
if (filter[i] == '|')
filter[i] = '\0';
}
if (W32Util::BrowseForFileName(true, GetHWND(), L"Switch Umd", 0, ConvertUTF8ToWString(filter).c_str(), L"*.pbp;*.elf;*.iso;*.cso;",fn)) {
fn = ReplaceAll(fn, "\\", "/");
__UmdReplace(fn);
}
}
LRESULT CALLBACK DisplayProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
// Only apply a factor > 1 in windowed mode.
int factor = !IsZoomed(GetHWND()) && !g_Config.bFullScreen && g_Config.iWindowWidth < (480 + 80) ? 2 : 1;
static bool firstErase = true;
switch (message) {
case WM_ACTIVATE:
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
g_activeWindow = WINDOW_MAINWINDOW;
}
break;
case WM_SETFOCUS:
break;
case WM_ERASEBKGND:
if (firstErase) {
firstErase = false;
// Paint black on first erase while OpenGL stuff is loading
return DefWindowProc(hWnd, message, wParam, lParam);
}
// Then never erase, let the OpenGL drawing take care of everything.
return 1;
// Poor man's touch - mouse input. We send the data both as an input_state pointer,
// and as asynchronous touch events for minimal latency.
case WM_LBUTTONDOWN:
if (!touchHandler.hasTouch() ||
(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
{
// Hack: Take the opportunity to show the cursor.
mouseButtonDown = true;
{
lock_guard guard(input_state.lock);
input_state.mouse_valid = true;
input_state.pointer_down[0] = true;
input_state.pointer_x[0] = GET_X_LPARAM(lParam) * factor;
input_state.pointer_y[0] = GET_Y_LPARAM(lParam) * factor;
}
TouchInput touch;
touch.id = 0;
touch.flags = TOUCH_DOWN;
touch.x = input_state.pointer_x[0];
touch.y = input_state.pointer_y[0];
NativeTouch(touch);
SetCapture(hWnd);
}
break;
case WM_MOUSEMOVE:
if (!touchHandler.hasTouch() ||
(GetMessageExtraInfo() & MOUSEEVENTF_MASK_PLUS_PENTOUCH) != MOUSEEVENTF_FROMTOUCH_NOPEN)
{
// Hack: Take the opportunity to show the cursor.
mouseButtonDown = (wParam & MK_LBUTTON) != 0;