From 997297d163d9f1426d31151bf221ac4040e52a25 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Tue, 13 May 2025 18:12:35 +0200 Subject: [PATCH] Run clang-format --- .github/workflows/format.yml | 2 +- miniwin/minimfc/include/minimfc.h | 1 - miniwin/minimfc/src/minimfc.cpp | 73 ++++++------- miniwin/miniwin/include/miniwin.h | 8 +- miniwin/miniwin/include/miniwin_d3drm.h | 7 +- miniwin/miniwin/include/miniwin_ddraw.h | 8 +- miniwin/miniwin/src/miniwin.cpp | 44 ++++---- miniwin/miniwin/src/miniwin_ddraw.cpp | 131 +++++++++++------------- 8 files changed, 140 insertions(+), 134 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index c13becba..e5f2d4de 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -12,7 +12,7 @@ jobs: - name: Run clang-format run: | - find CONFIG LEGO1 ISLE -iname '*.h' -o -iname '*.cpp' | xargs \ + find CONFIG LEGO1 ISLE miniwin -iname '*.h' -o -iname '*.cpp' | xargs \ pipx run "clang-format>=17,<18" \ --style=file \ -i diff --git a/miniwin/minimfc/include/minimfc.h b/miniwin/minimfc/include/minimfc.h index 826c9a41..46cd739f 100644 --- a/miniwin/minimfc/include/minimfc.h +++ b/miniwin/minimfc/include/minimfc.h @@ -60,7 +60,6 @@ struct CCommandLineInfo { virtual void ParseParam(LPCSTR pszParam, BOOL bFlag, BOOL bLast) {} }; - inline BOOL IsDlgButtonChecked(int nIDButton) { return 0; diff --git a/miniwin/minimfc/src/minimfc.cpp b/miniwin/minimfc/src/minimfc.cpp index 34f3e353..2c6e1af0 100644 --- a/miniwin/minimfc/src/minimfc.cpp +++ b/miniwin/minimfc/src/minimfc.cpp @@ -1,9 +1,9 @@ #include "minimfc.h" + #include "miniwin.h" #include #include - #include char* afxCurrentAppName; @@ -13,12 +13,13 @@ CWinApp* wndTop; SDL_Window* window; const char* title = "Configure LEGO Island"; -CWinApp::CWinApp() { - if (wndTop != NULL) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "There can only be one CWinApp!"); - abort(); - } - wndTop = this; +CWinApp::CWinApp() +{ + if (wndTop != NULL) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "There can only be one CWinApp!"); + abort(); + } + wndTop = this; } CWinApp::~CWinApp() = default; @@ -41,39 +42,41 @@ int CWinApp::ExitInstance() return 0; } -static char *get_base_filename(const char *path) { - for (;;) { - const char *next = SDL_strpbrk(path, "/\\"); - if (next == NULL) { - break; - } - path = next + 1; - } - const char *end = SDL_strchr(path, '.'); - size_t len; - if (end == NULL) { - len = SDL_strlen(path); - } else { - len = end - path; - } - char *filename = new char[len + 1]; - SDL_memcpy(filename, path, len); - filename[len] = '\0'; - return filename; +static char* get_base_filename(const char* path) +{ + for (;;) { + const char* next = SDL_strpbrk(path, "/\\"); + if (next == NULL) { + break; + } + path = next + 1; + } + const char* end = SDL_strchr(path, '.'); + size_t len; + if (end == NULL) { + len = SDL_strlen(path); + } + else { + len = end - path; + } + char* filename = new char[len + 1]; + SDL_memcpy(filename, path, len); + filename[len] = '\0'; + return filename; } int main(int argc, char* argv[]) { - afxCurrentAppName = get_base_filename(argv[0]); - if (wndTop == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No CWinApp created"); - abort(); - } + afxCurrentAppName = get_base_filename(argv[0]); + if (wndTop == NULL) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No CWinApp created"); + abort(); + } if (!wndTop->InitInstance()) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CWinApp::InitInstance failed"); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "CWinApp::InitInstance failed"); } - SDL_Event event; + SDL_Event event; bool running = true; while (running) { while (SDL_PollEvent(&event)) { @@ -86,8 +89,8 @@ int main(int argc, char* argv[]) } int result = wndTop->ExitInstance(); - free(afxCurrentAppName); - return result; + free(afxCurrentAppName); + return result; } void AfxMessageBox(const char* message) diff --git a/miniwin/miniwin/include/miniwin.h b/miniwin/miniwin/include/miniwin.h index 68548d9d..cee400ca 100644 --- a/miniwin/miniwin/include/miniwin.h +++ b/miniwin/miniwin/include/miniwin.h @@ -37,8 +37,8 @@ #define FAILED(hr) (((HRESULT) (hr)) < 0) #define InterlockedIncrement(x) __sync_add_and_fetch(x, 1) -#define INVALID_HANDLE ((HANDLE) - 1) -#define INVALID_HANDLE_VALUE ((HANDLE) - 1) +#define INVALID_HANDLE ((HANDLE) -1) +#define INVALID_HANDLE_VALUE ((HANDLE) -1) #define HKEY_LOCAL_MACHINE ((HKEY) 0x80000002) #define GWL_STYLE (-16) #define HWND_NOTOPMOST (HWND) - 2 @@ -129,7 +129,7 @@ typedef UINT_PTR WPARAM; typedef LONG_PTR LPARAM, LRESULT; typedef void* HANDLE; typedef HANDLE HMENU, HICON, HFONT; -typedef struct HINSTANCE__ * HINSTANCE; +typedef struct HINSTANCE__* HINSTANCE; typedef HANDLE HWND, HMODULE, HDC, HPALETTE, HFILE, HCURSOR; typedef LONG HRESULT, LSTATUS, HKEY, REGSAM; typedef HKEY* PHKEY; @@ -262,7 +262,7 @@ inline BOOL SetWindowPos(HWND hWndInsertAfter, int X, int Y, int cx, int cy, UIN return TRUE; } -BOOL GetWindowRect(HWND hDlg, struct tagRECT *Rect); +BOOL GetWindowRect(HWND hDlg, struct tagRECT* Rect); inline BOOL GetClientRect(LPRECT lpRect) { diff --git a/miniwin/miniwin/include/miniwin_d3drm.h b/miniwin/miniwin/include/miniwin_d3drm.h index b9fc09ed..0236c40d 100644 --- a/miniwin/miniwin/include/miniwin_d3drm.h +++ b/miniwin/miniwin/include/miniwin_d3drm.h @@ -244,7 +244,12 @@ struct D3DRMPICKDESC { struct IDirect3DRMPickedArray : public IUnknown { virtual DWORD GetSize() = 0; - virtual HRESULT GetPick(DWORD index, IDirect3DRMVisual** visual, IDirect3DRMFrameArray** frameArray, D3DRMPICKDESC* desc) = 0; + virtual HRESULT GetPick( + DWORD index, + IDirect3DRMVisual** visual, + IDirect3DRMFrameArray** frameArray, + D3DRMPICKDESC* desc + ) = 0; }; typedef IDirect3DRMPickedArray* LPDIRECT3DRMPICKEDARRAY; diff --git a/miniwin/miniwin/include/miniwin_ddraw.h b/miniwin/miniwin/include/miniwin_ddraw.h index f2f57f35..e114fb54 100644 --- a/miniwin/miniwin/include/miniwin_ddraw.h +++ b/miniwin/miniwin/include/miniwin_ddraw.h @@ -236,7 +236,13 @@ struct IDirectDrawSurface : public IUnknown { DWORD dwFlags, LPDDBLTFX lpDDBltFx ) = 0; - virtual HRESULT BltFast(DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwTrans) = 0; + virtual HRESULT BltFast( + DWORD dwX, + DWORD dwY, + LPDIRECTDRAWSURFACE lpDDSrcSurface, + LPRECT lpSrcRect, + DWORD dwTrans + ) = 0; virtual HRESULT DeleteAttachedSurface(DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSAttachedSurface) = 0; virtual HRESULT Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags) = 0; virtual HRESULT GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTDRAWSURFACE* lplpDDAttachedSurface) = 0; diff --git a/miniwin/miniwin/src/miniwin.cpp b/miniwin/miniwin/src/miniwin.cpp index 3474c862..ac336289 100644 --- a/miniwin/miniwin/src/miniwin.cpp +++ b/miniwin/miniwin/src/miniwin.cpp @@ -4,16 +4,16 @@ #include #include -static std::vector> sdl_hwnd_mapping; +static std::vector> sdl_hwnd_mapping; -SDL_Window *miniwin_GetSdlWindow(HWND hWnd) +SDL_Window* miniwin_GetSdlWindow(HWND hWnd) { - for (size_t i = 0; i < sdl_hwnd_mapping.size(); i++) { - if (sdl_hwnd_mapping[i].second == hWnd) { - return sdl_hwnd_mapping[i].first; - } - } - return NULL; + for (size_t i = 0; i < sdl_hwnd_mapping.size(); i++) { + if (sdl_hwnd_mapping[i].second == hWnd) { + return sdl_hwnd_mapping[i].first; + } + } + return NULL; } void OutputDebugString(const char* lpOutputString) @@ -29,18 +29,18 @@ VOID WINAPI Sleep(DWORD dwMilliseconds) BOOL GetWindowRect(HWND hWnd, tagRECT* Rect) { int x, y, w, h; - if (!Rect) { - return FALSE; - } - SDL_Window *window = miniwin_GetSdlWindow(hWnd); - if (window == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unregistered HWND %p", hWnd); - Rect->left = 0; - Rect->top = 0; - Rect->right = 640; - Rect->bottom = 480; - return FALSE; - } + if (!Rect) { + return FALSE; + } + SDL_Window* window = miniwin_GetSdlWindow(hWnd); + if (window == NULL) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unregistered HWND %p", hWnd); + Rect->left = 0; + Rect->top = 0; + Rect->right = 640; + Rect->bottom = 480; + return FALSE; + } SDL_GetWindowPosition(window, &x, &y); SDL_GetWindowSize(window, &w, &h); @@ -59,6 +59,6 @@ int _stricmp(const char* str1, const char* str2) void GlobalMemoryStatus(MEMORYSTATUS* memory_status) { - memory_status->dwLength = sizeof(*memory_status); - memory_status->dwTotalPhys = 1024 * SDL_GetSystemRAM(); + memory_status->dwLength = sizeof(*memory_status); + memory_status->dwTotalPhys = 1024 * SDL_GetSystemRAM(); } diff --git a/miniwin/miniwin/src/miniwin_ddraw.cpp b/miniwin/miniwin/src/miniwin_ddraw.cpp index 4572216f..3d4fabd8 100644 --- a/miniwin/miniwin/src/miniwin_ddraw.cpp +++ b/miniwin/miniwin/src/miniwin_ddraw.cpp @@ -1,57 +1,59 @@ #include "miniwin_ddraw.h" + #include "miniwin_d3d.h" #include struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 { - DirectDrawImpl() - : m_refCount(1) { - } - // IUnknown interface - ULONG AddRef() override { - m_refCount += 1; - return m_refCount; - }; - ULONG Release() override { - m_refCount -= 1; - if (m_refCount == 0) { - delete this; - } - return m_refCount; - } - HRESULT QueryInterface(const GUID& riid, void** ppvObject) override { - if (SDL_memcmp(&riid, &IID_IDirectDraw2, sizeof(GUID)) == 0) { - AddRef(); - *ppvObject = static_cast(this); - return S_OK; - } - if (SDL_memcmp(&riid, &IID_IDirect3D2, sizeof(GUID)) == 0) { - AddRef(); - *ppvObject = static_cast(this); - return S_OK; - } - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "DirectDrawImpl does not implement guid"); - return E_NOINTERFACE; - } - // IDirecdtDraw interface - HRESULT CreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER* lplpDDClipper, IUnknown* pUnkOuter) override { - return DDERR_GENERIC; - } + DirectDrawImpl() : m_refCount(1) {} + // IUnknown interface + ULONG AddRef() override + { + m_refCount += 1; + return m_refCount; + } + ULONG Release() override + { + m_refCount -= 1; + if (m_refCount == 0) { + delete this; + } + return m_refCount; + } + HRESULT QueryInterface(const GUID& riid, void** ppvObject) override + { + if (SDL_memcmp(&riid, &IID_IDirectDraw2, sizeof(GUID)) == 0) { + AddRef(); + *ppvObject = static_cast(this); + return S_OK; + } + if (SDL_memcmp(&riid, &IID_IDirect3D2, sizeof(GUID)) == 0) { + AddRef(); + *ppvObject = static_cast(this); + return S_OK; + } + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "DirectDrawImpl does not implement guid"); + return E_NOINTERFACE; + } + // IDirecdtDraw interface + HRESULT CreateClipper(DWORD dwFlags, LPDIRECTDRAWCLIPPER* lplpDDClipper, IUnknown* pUnkOuter) override + { + return DDERR_GENERIC; + } HRESULT CreatePalette( DWORD dwFlags, LPPALETTEENTRY lpColorTable, LPDIRECTDRAWPALETTE* lplpDDPalette, IUnknown* pUnkOuter - ) override { - return DDERR_GENERIC; - } - HRESULT CreateSurface( - LPDDSURFACEDESC lpDDSurfaceDesc, - LPDIRECTDRAWSURFACE* lplpDDSurface, - IUnknown* pUnkOuter - ) override { - return DDERR_GENERIC; - } + ) override + { + return DDERR_GENERIC; + } + HRESULT CreateSurface(LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE* lplpDDSurface, IUnknown* pUnkOuter) + override + { + return DDERR_GENERIC; + } HRESULT EnumDisplayModes( DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, @@ -63,35 +65,26 @@ struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 { LPDDSURFACEDESC lpDDSD, LPVOID lpContext, LPDDENUMSURFACESCALLBACK lpEnumSurfacesCallback - ) override { - return DD_OK; - } - HRESULT FlipToGDISurface() override { - return DD_OK; - } + ) override + { + return DD_OK; + } + HRESULT FlipToGDISurface() override { return DD_OK; } HRESULT GetCaps(LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps) override; - HRESULT GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc) override { - return DD_OK; - } - HRESULT Initialize(GUID* lpGUID) override { - return DD_OK; - } - HRESULT RestoreDisplayMode() override { - return DD_OK; - } - HRESULT SetCooperativeLevel(HWND hWnd, DWORD dwFlags) override { - return DD_OK; - } - HRESULT SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP) override { - return DD_OK; - } - // IDirect3D2 interface - HRESULT CreateDevice(const GUID& guid, void* pBackBuffer, IDirect3DDevice2** ppDirect3DDevice) override { - return DDERR_GENERIC; - } + HRESULT GetDisplayMode(LPDDSURFACEDESC lpDDSurfaceDesc) override { return DD_OK; } + HRESULT Initialize(GUID* lpGUID) override { return DD_OK; } + HRESULT RestoreDisplayMode() override { return DD_OK; } + HRESULT SetCooperativeLevel(HWND hWnd, DWORD dwFlags) override { return DD_OK; } + HRESULT SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBPP) override { return DD_OK; } + // IDirect3D2 interface + HRESULT CreateDevice(const GUID& guid, void* pBackBuffer, IDirect3DDevice2** ppDirect3DDevice) override + { + return DDERR_GENERIC; + } HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx) override; + private: - int m_refCount; + int m_refCount; }; HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)