mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Assorted code cleanup
This commit is contained in:
@@ -544,10 +544,11 @@ void CtrlMatrixList::OnRightClick(int row, int column, const POINT &point) {
|
||||
|
||||
case ID_DISASM_COPYINSTRUCTIONDISASM:
|
||||
{
|
||||
// Not really copy instruction, more like copy a float.
|
||||
float val;
|
||||
if (GetValue(gpuDebug->GetGState(), row, column, val)) {
|
||||
wchar_t dest[512];
|
||||
swprintf(dest, 511, L"%f", val);
|
||||
char dest[128];
|
||||
snprintf(dest, sizeof(dest), "%f", val);
|
||||
W32Util::CopyTextToClipboard(GetHandle(), dest);
|
||||
}
|
||||
break;
|
||||
|
||||
+25
-73
@@ -125,9 +125,8 @@ static std::wstring g_windowTitle;
|
||||
|
||||
namespace MainWindow
|
||||
{
|
||||
HWND hwndMain;
|
||||
HWND hwndGameList;
|
||||
TouchInputHandler touchHandler;
|
||||
static HWND hwndMain;
|
||||
static TouchInputHandler touchHandler;
|
||||
|
||||
static HMENU g_hMenu;
|
||||
|
||||
@@ -151,15 +150,14 @@ namespace MainWindow
|
||||
|
||||
// gross hack
|
||||
bool noFocusPause = false; // TOGGLE_PAUSE state to override pause on lost focus
|
||||
bool trapMouse = true; // Handles some special cases(alt+tab, win menu) when game is running and mouse is confined
|
||||
static bool trapMouse = true; // Handles some special cases(alt+tab, win menu) when game is running and mouse is confined
|
||||
|
||||
static constexpr wchar_t *szWindowClass = L"PPSSPPWnd";
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
HWND GetHWND() {
|
||||
return hwndMain;
|
||||
}
|
||||
HWND GetHWND() { return hwndMain; }
|
||||
HINSTANCE GetHInstance() { return hInst; }
|
||||
|
||||
void SetKeepScreenBright(bool keepBright) {
|
||||
g_keepScreenBright = keepBright;
|
||||
@@ -167,8 +165,7 @@ namespace MainWindow
|
||||
|
||||
void Init(HINSTANCE hInstance) {
|
||||
// Register classes - Main Window
|
||||
WNDCLASSEX wcex;
|
||||
memset(&wcex, 0, sizeof(wcex));
|
||||
WNDCLASSEX wcex{};
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = 0; // Show in taskbar
|
||||
wcex.lpfnWndProc = (WNDPROC)WndProc;
|
||||
@@ -599,37 +596,6 @@ namespace MainWindow
|
||||
vfpudlg = nullptr;
|
||||
}
|
||||
|
||||
RECT MapRectFromClientToWndCoords(HWND hwnd, const RECT & r)
|
||||
{
|
||||
RECT wnd_coords = r;
|
||||
|
||||
// map to screen
|
||||
MapWindowPoints(hwnd, NULL, reinterpret_cast<POINT *>(&wnd_coords), 2);
|
||||
|
||||
RECT scr_coords;
|
||||
GetWindowRect(hwnd, &scr_coords);
|
||||
|
||||
// map to window coords by substracting the window coord origin in
|
||||
// screen coords.
|
||||
OffsetRect(&wnd_coords, -scr_coords.left, -scr_coords.top);
|
||||
|
||||
return wnd_coords;
|
||||
}
|
||||
|
||||
RECT GetNonclientMenuBorderRect(HWND hwnd)
|
||||
{
|
||||
RECT r;
|
||||
GetClientRect(hwnd, &r);
|
||||
r = MapRectFromClientToWndCoords(hwnd, r);
|
||||
int y = r.top - 1;
|
||||
return {
|
||||
r.left,
|
||||
y,
|
||||
r.right,
|
||||
y + 1
|
||||
};
|
||||
}
|
||||
|
||||
bool ConfirmAction(HWND hWnd, bool actionIsReset) {
|
||||
const GlobalUIState state = GetUIState();
|
||||
if (state == UISTATE_MENU || state == UISTATE_EXIT) {
|
||||
@@ -780,7 +746,7 @@ namespace MainWindow
|
||||
auto result = DefWindowProc(hWnd, message, wParam, lParam);
|
||||
// Paint over the line with pure black. Could also try to figure out the dark theme color.
|
||||
HDC hdc = GetWindowDC(hWnd);
|
||||
RECT r = GetNonclientMenuBorderRect(hWnd);
|
||||
RECT r = W32Util::GetNonclientMenuBorderRect(hWnd);
|
||||
HBRUSH red = CreateSolidBrush(RGB(0, 0, 0));
|
||||
FillRect(hdc, &r, red);
|
||||
DeleteObject(red);
|
||||
@@ -999,9 +965,9 @@ namespace MainWindow
|
||||
|
||||
case WM_DROPFILES:
|
||||
{
|
||||
if (!MainThread_Ready())
|
||||
if (!MainThread_Ready()) {
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
}
|
||||
const HDROP hdrop = (HDROP)wParam;
|
||||
const int count = DragQueryFile(hdrop, 0xFFFFFFFF, 0, 0);
|
||||
if (count != 1) {
|
||||
@@ -1114,16 +1080,14 @@ namespace MainWindow
|
||||
}
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
case WM_SETTINGCHANGE:
|
||||
{
|
||||
if (g_darkModeSupported && IsColorSchemeChangeMessage(lParam))
|
||||
SendMessageW(hWnd, WM_THEMECHANGED, 0, 0);
|
||||
if (g_darkModeSupported && IsColorSchemeChangeMessage(lParam)) {
|
||||
SendMessageW(hWnd, WM_THEMECHANGED, 0, 0);
|
||||
}
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_THEMECHANGED:
|
||||
{
|
||||
if (g_darkModeSupported)
|
||||
{
|
||||
if (g_darkModeSupported) {
|
||||
_AllowDarkModeForWindow(hWnd, g_darkModeEnabled);
|
||||
RefreshTitleBarThemeColor(hWnd);
|
||||
}
|
||||
@@ -1144,13 +1108,10 @@ namespace MainWindow
|
||||
case ImGuiMouseCursor_ResizeNWSE: win32_cursor = IDC_SIZENWSE; break;
|
||||
case ImGuiMouseCursor_Hand: win32_cursor = IDC_HAND; break;
|
||||
case ImGuiMouseCursor_NotAllowed: win32_cursor = IDC_NO; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (win32_cursor) {
|
||||
SetCursor(::LoadCursor(nullptr, win32_cursor));
|
||||
} else {
|
||||
SetCursor(nullptr);
|
||||
}
|
||||
SetCursor(win32_cursor ? ::LoadCursor(nullptr, win32_cursor) : nullptr);
|
||||
return TRUE;
|
||||
} else {
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
@@ -1165,8 +1126,8 @@ namespace MainWindow
|
||||
// Hack: Take the opportunity to show the cursor.
|
||||
mouseButtonDown = true;
|
||||
|
||||
float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
const float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
const float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
WindowsRawInput::SetMousePos(x, y);
|
||||
|
||||
TouchInput touch{};
|
||||
@@ -1206,6 +1167,7 @@ namespace MainWindow
|
||||
mouseButtonDown = (wParam & MK_LBUTTON) != 0;
|
||||
int cursorX = GET_X_LPARAM(lParam);
|
||||
int cursorY = GET_Y_LPARAM(lParam);
|
||||
// Require at least 2 pixels of movement to reset the hide timer.
|
||||
if (abs(cursorX - prevCursorX) > 1 || abs(cursorY - prevCursorY) > 1) {
|
||||
hideCursor = false;
|
||||
SetTimer(hwndMain, TIMER_CURSORMOVEUPDATE, CURSORUPDATE_MOVE_TIMESPAN_MS, 0);
|
||||
@@ -1213,8 +1175,8 @@ namespace MainWindow
|
||||
prevCursorX = cursorX;
|
||||
prevCursorY = cursorY;
|
||||
|
||||
float x = (float)cursorX * g_display.dpi_scale_x;
|
||||
float y = (float)cursorY * g_display.dpi_scale_y;
|
||||
const float x = (float)cursorX * g_display.dpi_scale_x;
|
||||
const float y = (float)cursorY * g_display.dpi_scale_y;
|
||||
WindowsRawInput::SetMousePos(x, y);
|
||||
|
||||
// Mouse moves now happen also when no button is pressed.
|
||||
@@ -1239,8 +1201,8 @@ namespace MainWindow
|
||||
// Hack: Take the opportunity to hide the cursor.
|
||||
mouseButtonDown = false;
|
||||
|
||||
float x = (float)GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
float y = (float)GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
const float x = (float)GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
const float y = (float)GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
WindowsRawInput::SetMousePos(x, y);
|
||||
|
||||
TouchInput touch{};
|
||||
@@ -1259,28 +1221,22 @@ namespace MainWindow
|
||||
|
||||
case WM_RBUTTONDOWN:
|
||||
{
|
||||
float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
|
||||
TouchInput touch{};
|
||||
touch.buttons = 2;
|
||||
touch.flags = TouchInputFlags::DOWN | TouchInputFlags::MOUSE;
|
||||
touch.x = x;
|
||||
touch.y = y;
|
||||
touch.x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
touch.y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
NativeTouch(touch);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_RBUTTONUP:
|
||||
{
|
||||
float x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
float y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
|
||||
TouchInput touch{};
|
||||
touch.buttons = 2;
|
||||
touch.flags = TouchInputFlags::UP | TouchInputFlags::MOUSE;
|
||||
touch.x = x;
|
||||
touch.y = y;
|
||||
touch.x = GET_X_LPARAM(lParam) * g_display.dpi_scale_x;
|
||||
touch.y = GET_Y_LPARAM(lParam) * g_display.dpi_scale_y;
|
||||
NativeTouch(touch);
|
||||
break;
|
||||
}
|
||||
@@ -1291,10 +1247,6 @@ namespace MainWindow
|
||||
return 0;
|
||||
}
|
||||
|
||||
HINSTANCE GetHInstance() {
|
||||
return hInst;
|
||||
}
|
||||
|
||||
void ToggleDebugConsoleVisibility() {
|
||||
if (!g_Config.bEnableLogging) {
|
||||
g_logManager.GetConsoleListener()->Show(false);
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
extern bool g_TakeScreenshot;
|
||||
|
||||
namespace MainWindow {
|
||||
extern HINSTANCE hInst;
|
||||
extern bool noFocusPause;
|
||||
std::vector<HMENU> g_topLevelMenus;
|
||||
HMENU g_hMenuBackend;
|
||||
@@ -842,7 +841,7 @@ namespace MainWindow {
|
||||
case ID_DEBUG_EXTRACTFILE:
|
||||
{
|
||||
std::string filename;
|
||||
if (!InputBox_GetString(hInst, hWnd, L"Disc filename", filename, filename)) {
|
||||
if (!InputBox_GetString(MainWindow::GetHInstance(), hWnd, L"Disc filename", filename, filename)) {
|
||||
break;
|
||||
}
|
||||
const char *lastSlash = strrchr(filename.c_str(), '/');
|
||||
@@ -960,7 +959,7 @@ namespace MainWindow {
|
||||
|
||||
case ID_HELP_ABOUT:
|
||||
DialogManager::EnableAll(FALSE);
|
||||
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)AboutDlgProc);
|
||||
DialogBox(MainWindow::GetHInstance(), (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)AboutDlgProc);
|
||||
DialogManager::EnableAll(TRUE);
|
||||
break;
|
||||
|
||||
|
||||
+44
-32
@@ -22,8 +22,31 @@ bool KeyDownAsync(int vkey) {
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
void CenterWindow(HWND hwnd)
|
||||
{
|
||||
static RECT MapRectFromClientToWndCoords(HWND hwnd, const RECT &r) {
|
||||
RECT wnd_coords = r;
|
||||
// map to screen
|
||||
MapWindowPoints(hwnd, NULL, reinterpret_cast<POINT *>(&wnd_coords), 2);
|
||||
RECT scr_coords;
|
||||
GetWindowRect(hwnd, &scr_coords);
|
||||
// map to window coords by substracting the window coord origin in screen coords.
|
||||
OffsetRect(&wnd_coords, -scr_coords.left, -scr_coords.top);
|
||||
return wnd_coords;
|
||||
}
|
||||
|
||||
RECT GetNonclientMenuBorderRect(HWND hwnd) {
|
||||
RECT r;
|
||||
GetClientRect(hwnd, &r);
|
||||
r = MapRectFromClientToWndCoords(hwnd, r);
|
||||
const int y = r.top - 1;
|
||||
return {
|
||||
r.left,
|
||||
y,
|
||||
r.right,
|
||||
y + 1
|
||||
};
|
||||
}
|
||||
|
||||
void CenterWindow(HWND hwnd) {
|
||||
HWND hwndParent;
|
||||
RECT rect, rectP;
|
||||
int width, height;
|
||||
@@ -57,19 +80,17 @@ namespace W32Util
|
||||
MoveWindow(hwnd, x, y, width, height, FALSE);
|
||||
}
|
||||
|
||||
BOOL CopyTextToClipboard(HWND hwnd, const char *text) {
|
||||
bool CopyTextToClipboard(HWND hWnd, std::string_view text) {
|
||||
std::wstring wtext = ConvertUTF8ToWString(text);
|
||||
return CopyTextToClipboard(hwnd, wtext);
|
||||
}
|
||||
if (!OpenClipboard(hWnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext) {
|
||||
if (!OpenClipboard(hwnd))
|
||||
return FALSE;
|
||||
EmptyClipboard();
|
||||
HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (wtext.size() + 1) * sizeof(wchar_t));
|
||||
if (hglbCopy == NULL) {
|
||||
if (!hglbCopy) {
|
||||
CloseClipboard();
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lock the handle and copy the text to the buffer.
|
||||
@@ -82,13 +103,11 @@ namespace W32Util
|
||||
SetClipboardData(CF_UNICODETEXT, hglbCopy);
|
||||
}
|
||||
CloseClipboard();
|
||||
return lptstrCopy ? TRUE : FALSE;
|
||||
return lptstrCopy != nullptr;
|
||||
}
|
||||
|
||||
void MakeTopMost(HWND hwnd, bool topMost) {
|
||||
HWND style = HWND_NOTOPMOST;
|
||||
if (topMost) style = HWND_TOPMOST;
|
||||
SetWindowPos(hwnd, style, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
SetWindowPos(hwnd, topMost ? HWND_TOPMOST : HWND_NOTOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
void GetWindowRes(HWND hWnd, int *xres, int *yres) {
|
||||
@@ -98,7 +117,7 @@ namespace W32Util
|
||||
*yres = rc.bottom - rc.top;
|
||||
}
|
||||
|
||||
void ShowFileInFolder(const std::string &path) {
|
||||
void ShowFileInFolder(std::string_view path) {
|
||||
// SHParseDisplayName can't handle relative paths, so normalize first.
|
||||
std::string resolved = ReplaceAll(File::ResolvePath(path), "/", "\\");
|
||||
|
||||
@@ -557,8 +576,7 @@ LRESULT CALLBACK GenericListControl::wndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
||||
return (LRESULT)CallWindowProc((WNDPROC)list->oldProc,hwnd,msg,wParam,lParam);
|
||||
}
|
||||
|
||||
void GenericListControl::ProcessCopy()
|
||||
{
|
||||
void GenericListControl::ProcessCopy() {
|
||||
int start = GetSelectedIndex();
|
||||
int size;
|
||||
if (start == -1)
|
||||
@@ -569,15 +587,12 @@ void GenericListControl::ProcessCopy()
|
||||
CopyRows(start, size);
|
||||
}
|
||||
|
||||
void GenericListControl::CopyRows(int start, int size)
|
||||
{
|
||||
void GenericListControl::CopyRows(int start, int size) {
|
||||
std::wstring data;
|
||||
|
||||
if (start == 0 && size == GetRowCount())
|
||||
{
|
||||
if (start == 0 && size == GetRowCount()) {
|
||||
// Let's also copy the header if everything is selected.
|
||||
for (int c = 0; c < columnCount; ++c)
|
||||
{
|
||||
for (int c = 0; c < columnCount; ++c) {
|
||||
data.append(columns[c].name);
|
||||
if (c < columnCount - 1)
|
||||
data.append(L"\t");
|
||||
@@ -586,10 +601,8 @@ void GenericListControl::CopyRows(int start, int size)
|
||||
}
|
||||
}
|
||||
|
||||
for (int r = start; r < start + size; ++r)
|
||||
{
|
||||
for (int c = 0; c < columnCount; ++c)
|
||||
{
|
||||
for (int r = start; r < start + size; ++r) {
|
||||
for (int c = 0; c < columnCount; ++c) {
|
||||
stringBuffer[0] = 0;
|
||||
GetColumnText(stringBuffer, ARRAY_SIZE(stringBuffer), r, c);
|
||||
data.append(stringBuffer);
|
||||
@@ -599,15 +612,14 @@ void GenericListControl::CopyRows(int start, int size)
|
||||
data.append(L"\r\n");
|
||||
}
|
||||
}
|
||||
W32Util::CopyTextToClipboard(handle, data);
|
||||
|
||||
W32Util::CopyTextToClipboard(handle, ConvertWStringToUTF8(data));
|
||||
}
|
||||
|
||||
void GenericListControl::SelectAll()
|
||||
{
|
||||
void GenericListControl::SelectAll() {
|
||||
ListView_SetItemState(handle, -1, LVIS_SELECTED, LVIS_SELECTED);
|
||||
}
|
||||
|
||||
int GenericListControl::GetSelectedIndex()
|
||||
{
|
||||
int GenericListControl::GetSelectedIndex() {
|
||||
return ListView_GetNextItem(handle, -1, LVNI_SELECTED);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
|
||||
#include "Common/CommonWindows.h"
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
namespace W32Util {
|
||||
void CenterWindow(HWND hwnd);
|
||||
BOOL CopyTextToClipboard(HWND hwnd, const char *text);
|
||||
BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext);
|
||||
bool CopyTextToClipboard(HWND hwnd, std::string_view text);
|
||||
void MakeTopMost(HWND hwnd, bool topMost);
|
||||
void ExitAndRestart(bool overrideArgs = false, const std::string &args = "");
|
||||
void SpawnNewInstance(bool overrideArgs = false, const std::string &args = "");
|
||||
@@ -18,7 +16,8 @@ namespace W32Util
|
||||
void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename);
|
||||
|
||||
void GetWindowRes(HWND hWnd, int *xres, int *yres);
|
||||
void ShowFileInFolder(const std::string &path);
|
||||
void ShowFileInFolder(std::string_view path);
|
||||
RECT GetNonclientMenuBorderRect(HWND hwnd);
|
||||
|
||||
struct ClipboardData {
|
||||
ClipboardData(const char *format, size_t sz);
|
||||
|
||||
+1
-2
@@ -618,8 +618,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
|
||||
}
|
||||
case SystemRequestType::COPY_TO_CLIPBOARD:
|
||||
{
|
||||
std::wstring data = ConvertUTF8ToWString(param1);
|
||||
W32Util::CopyTextToClipboard(MainWindow::GetHWND(), data);
|
||||
W32Util::CopyTextToClipboard(MainWindow::GetHWND(), param1);
|
||||
return true;
|
||||
}
|
||||
case SystemRequestType::SET_WINDOW_TITLE:
|
||||
|
||||
Reference in New Issue
Block a user