/* =========================================================================== IceTech GPL Source Code Copyright (C) 2026 Justin Marshall This file is part of the IceTech GPL Source Code (?IceTech Source Code?). IceTech Source Code 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, either version 3 of the License, or (at your option) any later version. IceTech Source Code 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 for more details. You should have received a copy of the GNU General Public License along with IceTech Source Code. If not, see . In addition, the IceTech Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the IceTech Source Code. If not, please request a copy in writing from id Software at the address below. If you have questions concerning this license or the applicable additional terms, you may contact in writing Justin Marshall, justinmarshall20@gmail.com =========================================================================== */ #include "precompiled.h" #pragma hdrstop #include "qe3.h" #include "Radiant.h" #include "PatchDialog.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // -------------------------------------------------------------------------- // IceTech dark MFC/common-control helper // -------------------------------------------------------------------------- #ifndef BS_TYPEMASK #define BS_TYPEMASK 0x0000000F #endif static const COLORREF ICE_DARK_BG = RGB(17, 19, 23); static const COLORREF ICE_DARK_PANEL = RGB(24, 27, 32); static const COLORREF ICE_DARK_PANEL_ALT = RGB(29, 33, 39); static const COLORREF ICE_DARK_FIELD = RGB(14, 16, 20); static const COLORREF ICE_DARK_BORDER = RGB(55, 62, 72); static const COLORREF ICE_DARK_BORDER_HOT = RGB(87, 166, 255); static const COLORREF ICE_DARK_TEXT = RGB(226, 232, 240); static const COLORREF ICE_DARK_TEXT_MUTED = RGB(151, 163, 184); static const COLORREF ICE_DARK_TEXT_DISABLED = RGB(103, 112, 128); static const COLORREF ICE_DARK_ACCENT = RGB(87, 166, 255); static const char* ICE_DARK_PARENT_OLDPROC = "IceTech.Dark.ParentOldProc"; static const char* ICE_DARK_CONTROL_OLDPROC = "IceTech.Dark.ControlOldProc"; static int IceDark_MaxInt(int a, int b) { return (a > b) ? a : b; } static HBRUSH IceDark_BgBrush() { static HBRUSH hBrush = ::CreateSolidBrush(ICE_DARK_BG); return hBrush; } static HBRUSH IceDark_PanelBrush() { static HBRUSH hBrush = ::CreateSolidBrush(ICE_DARK_PANEL); return hBrush; } static HBRUSH IceDark_FieldBrush() { static HBRUSH hBrush = ::CreateSolidBrush(ICE_DARK_FIELD); return hBrush; } static void IceDark_FillRect(HDC hDC, const RECT& rc, COLORREF color) { HBRUSH brush = ::CreateSolidBrush(color); ::FillRect(hDC, &rc, brush); ::DeleteObject(brush); } static void IceDark_FrameRect(HDC hDC, const RECT& rc, COLORREF color) { HBRUSH brush = ::CreateSolidBrush(color); ::FrameRect(hDC, &rc, brush); ::DeleteObject(brush); } static void IceDark_ApplyNativeTheme(HWND hWnd) { if (!hWnd) { return; } typedef HRESULT (WINAPI *SetWindowThemeProc)(HWND, LPCWSTR, LPCWSTR); typedef BOOL (WINAPI *AllowDarkModeForWindowProc)(HWND, BOOL); static HMODULE hUxTheme = ::LoadLibraryA("uxtheme.dll"); static SetWindowThemeProc pSetWindowTheme = hUxTheme ? (SetWindowThemeProc)::GetProcAddress(hUxTheme, "SetWindowTheme") : NULL; static AllowDarkModeForWindowProc pAllowDarkModeForWindow = hUxTheme ? (AllowDarkModeForWindowProc)::GetProcAddress(hUxTheme, MAKEINTRESOURCEA(133)) : NULL; if (pAllowDarkModeForWindow) { pAllowDarkModeForWindow(hWnd, TRUE); } if (pSetWindowTheme) { pSetWindowTheme(hWnd, L"DarkMode_Explorer", NULL); } ::SendMessage(hWnd, WM_THEMECHANGED, 0, 0); } static void IceDark_RemoveClientEdge(HWND hWnd) { if (!hWnd) { return; } LONG exStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE); if (exStyle & WS_EX_CLIENTEDGE) { ::SetWindowLong(hWnd, GWL_EXSTYLE, exStyle & ~WS_EX_CLIENTEDGE); ::SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); } } static void IceDark_DrawFrame(HWND hWnd, COLORREF color) { HDC hDC = ::GetWindowDC(hWnd); if (!hDC) { return; } RECT rc; ::GetWindowRect(hWnd, &rc); ::OffsetRect(&rc, -rc.left, -rc.top); IceDark_FrameRect(hDC, rc, color); ::ReleaseDC(hWnd, hDC); } static void IceDark_DrawButton(HWND hWnd, HDC hDC) { RECT rc; ::GetClientRect(hWnd, &rc); const UINT style = (UINT)::GetWindowLong(hWnd, GWL_STYLE); const UINT type = style & BS_TYPEMASK; const bool enabled = ::IsWindowEnabled(hWnd) ? true : false; const bool pushed = (::SendMessage(hWnd, BM_GETSTATE, 0, 0) & BST_PUSHED) != 0; const bool checked = (::SendMessage(hWnd, BM_GETCHECK, 0, 0) == BST_CHECKED); const bool isCheck = (type == BS_CHECKBOX || type == BS_AUTOCHECKBOX || type == BS_3STATE || type == BS_AUTO3STATE); const bool isRadio = (type == BS_RADIOBUTTON || type == BS_AUTORADIOBUTTON); const bool isGroup = (type == BS_GROUPBOX); char text[512]; text[0] = '\0'; ::GetWindowTextA(hWnd, text, sizeof(text)); HFONT font = (HFONT)::SendMessage(hWnd, WM_GETFONT, 0, 0); HFONT oldFont = font ? (HFONT)::SelectObject(hDC, font) : NULL; ::SetBkMode(hDC, TRANSPARENT); ::SetTextColor(hDC, enabled ? ICE_DARK_TEXT : ICE_DARK_TEXT_DISABLED); if (isGroup) { IceDark_FillRect(hDC, rc, ICE_DARK_BG); RECT textRect = rc; textRect.left += 10; textRect.right -= 8; textRect.bottom = textRect.top + 18; SIZE textSize; textSize.cx = textSize.cy = 0; ::GetTextExtentPoint32A(hDC, text, (int)strlen(text), &textSize); RECT frame = rc; frame.top += 8; HPEN pen = ::CreatePen(PS_SOLID, 1, ICE_DARK_BORDER); HPEN oldPen = (HPEN)::SelectObject(hDC, pen); HBRUSH oldBrush = (HBRUSH)::SelectObject(hDC, ::GetStockObject(NULL_BRUSH)); ::RoundRect(hDC, frame.left, frame.top, frame.right, frame.bottom, 8, 8); ::SelectObject(hDC, oldBrush); ::SelectObject(hDC, oldPen); ::DeleteObject(pen); RECT fillLabel = textRect; fillLabel.right = fillLabel.left + textSize.cx + 8; IceDark_FillRect(hDC, fillLabel, ICE_DARK_BG); ::SetTextColor(hDC, ICE_DARK_TEXT_MUTED); ::DrawTextA(hDC, text, -1, &textRect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS); } else if (isCheck || isRadio) { IceDark_FillRect(hDC, rc, ICE_DARK_BG); RECT box = rc; box.left += 3; box.right = box.left + 15; box.top += IceDark_MaxInt(0, (rc.bottom - rc.top - 15) / 2); box.bottom = box.top + 15; if (isRadio) { HPEN pen = ::CreatePen(PS_SOLID, 1, checked ? ICE_DARK_ACCENT : ICE_DARK_BORDER); HPEN oldPen = (HPEN)::SelectObject(hDC, pen); HBRUSH brush = ::CreateSolidBrush(enabled ? ICE_DARK_FIELD : RGB(20, 22, 26)); HBRUSH oldBrush = (HBRUSH)::SelectObject(hDC, brush); ::Ellipse(hDC, box.left, box.top, box.right, box.bottom); ::SelectObject(hDC, oldBrush); ::DeleteObject(brush); ::SelectObject(hDC, oldPen); ::DeleteObject(pen); if (checked) { RECT dot = box; ::InflateRect(&dot, -4, -4); HBRUSH dotBrush = ::CreateSolidBrush(enabled ? ICE_DARK_ACCENT : ICE_DARK_TEXT_DISABLED); HBRUSH oldDotBrush = (HBRUSH)::SelectObject(hDC, dotBrush); HPEN dotPen = ::CreatePen(PS_SOLID, 1, enabled ? ICE_DARK_ACCENT : ICE_DARK_TEXT_DISABLED); HPEN oldDotPen = (HPEN)::SelectObject(hDC, dotPen); ::Ellipse(hDC, dot.left, dot.top, dot.right, dot.bottom); ::SelectObject(hDC, oldDotPen); ::DeleteObject(dotPen); ::SelectObject(hDC, oldDotBrush); ::DeleteObject(dotBrush); } } else { IceDark_FillRect(hDC, box, enabled ? ICE_DARK_FIELD : RGB(20, 22, 26)); IceDark_FrameRect(hDC, box, checked ? ICE_DARK_ACCENT : ICE_DARK_BORDER); if (checked) { HPEN pen = ::CreatePen(PS_SOLID, 2, enabled ? ICE_DARK_ACCENT : ICE_DARK_TEXT_DISABLED); HPEN oldPen = (HPEN)::SelectObject(hDC, pen); ::MoveToEx(hDC, box.left + 3, box.top + 7, NULL); ::LineTo(hDC, box.left + 6, box.top + 10); ::LineTo(hDC, box.right - 3, box.top + 3); ::SelectObject(hDC, oldPen); ::DeleteObject(pen); } } RECT textRect = rc; textRect.left = box.right + 7; textRect.right -= 2; ::DrawTextA(hDC, text, -1, &textRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS); } else { COLORREF face = pushed ? RGB(22, 25, 30) : ICE_DARK_PANEL_ALT; IceDark_FillRect(hDC, rc, face); IceDark_FrameRect(hDC, rc, enabled ? ICE_DARK_BORDER : RGB(39, 44, 52)); RECT inner = rc; ::InflateRect(&inner, -1, -1); if (!pushed) { IceDark_FrameRect(hDC, inner, RGB(35, 40, 47)); } RECT textRect = rc; if (pushed) { ::OffsetRect(&textRect, 1, 1); } ::DrawTextA(hDC, text, -1, &textRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS); } if (oldFont) { ::SelectObject(hDC, oldFont); } } static LRESULT CALLBACK IceDark_ButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldProc = (WNDPROC)::GetPropA(hWnd, ICE_DARK_CONTROL_OLDPROC); if (!oldProc) { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_ERASEBKGND: return 1; case WM_PAINT: { UINT style = (UINT)::GetWindowLong(hWnd, GWL_STYLE); if (style & (BS_BITMAP | BS_ICON)) { LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); IceDark_DrawFrame(hWnd, ICE_DARK_BORDER); return result; } PAINTSTRUCT ps; HDC hDC = ::BeginPaint(hWnd, &ps); IceDark_DrawButton(hWnd, hDC); ::EndPaint(hWnd, &ps); return 0; } case WM_PRINTCLIENT: IceDark_DrawButton(hWnd, (HDC)wParam); return 0; case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_ENABLE: case WM_SETTEXT: case BM_SETCHECK: case BM_SETSTATE: { LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); ::InvalidateRect(hWnd, NULL, FALSE); return result; } case WM_NCDESTROY: { ::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldProc); ::RemovePropA(hWnd, ICE_DARK_CONTROL_OLDPROC); return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } } return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } static void IceDark_DrawCombo(HWND hWnd, HDC hDC) { RECT rc; ::GetClientRect(hWnd, &rc); const bool enabled = ::IsWindowEnabled(hWnd) ? true : false; const bool focused = (::GetFocus() == hWnd || ::IsChild(hWnd, ::GetFocus())) ? true : false; IceDark_FillRect(hDC, rc, enabled ? ICE_DARK_FIELD : RGB(20, 22, 26)); IceDark_FrameRect(hDC, rc, focused ? ICE_DARK_BORDER_HOT : ICE_DARK_BORDER); RECT arrow = rc; arrow.left = arrow.right - 22; IceDark_FillRect(hDC, arrow, ICE_DARK_PANEL_ALT); IceDark_FrameRect(hDC, arrow, ICE_DARK_BORDER); POINT pts[3]; int cx = arrow.left + (arrow.right - arrow.left) / 2; int cy = arrow.top + (arrow.bottom - arrow.top) / 2 + 1; pts[0].x = cx - 4; pts[0].y = cy - 2; pts[1].x = cx + 4; pts[1].y = cy - 2; pts[2].x = cx; pts[2].y = cy + 3; HBRUSH arrowBrush = ::CreateSolidBrush(enabled ? ICE_DARK_TEXT : ICE_DARK_TEXT_DISABLED); HBRUSH oldBrush = (HBRUSH)::SelectObject(hDC, arrowBrush); HPEN arrowPen = ::CreatePen(PS_SOLID, 1, enabled ? ICE_DARK_TEXT : ICE_DARK_TEXT_DISABLED); HPEN oldPen = (HPEN)::SelectObject(hDC, arrowPen); ::Polygon(hDC, pts, 3); ::SelectObject(hDC, oldPen); ::DeleteObject(arrowPen); ::SelectObject(hDC, oldBrush); ::DeleteObject(arrowBrush); char text[512]; text[0] = '\0'; int sel = (int)::SendMessage(hWnd, CB_GETCURSEL, 0, 0); if (sel >= 0) { ::SendMessageA(hWnd, CB_GETLBTEXT, (WPARAM)sel, (LPARAM)text); } else { ::GetWindowTextA(hWnd, text, sizeof(text)); } HFONT font = (HFONT)::SendMessage(hWnd, WM_GETFONT, 0, 0); HFONT oldFont = font ? (HFONT)::SelectObject(hDC, font) : NULL; ::SetBkMode(hDC, TRANSPARENT); ::SetTextColor(hDC, enabled ? ICE_DARK_TEXT : ICE_DARK_TEXT_DISABLED); RECT textRect = rc; textRect.left += 7; textRect.right = arrow.left - 3; ::DrawTextA(hDC, text, -1, &textRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS); if (oldFont) { ::SelectObject(hDC, oldFont); } } static LRESULT CALLBACK IceDark_ComboProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldProc = (WNDPROC)::GetPropA(hWnd, ICE_DARK_CONTROL_OLDPROC); if (!oldProc) { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_ERASEBKGND: return 1; case WM_PAINT: { UINT comboType = (UINT)::GetWindowLong(hWnd, GWL_STYLE) & 0x00000003; if (comboType == CBS_DROPDOWNLIST) { PAINTSTRUCT ps; HDC hDC = ::BeginPaint(hWnd, &ps); IceDark_DrawCombo(hWnd, hDC); ::EndPaint(hWnd, &ps); return 0; } LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); IceDark_DrawFrame(hWnd, (::GetFocus() == hWnd || ::IsChild(hWnd, ::GetFocus())) ? ICE_DARK_BORDER_HOT : ICE_DARK_BORDER); return result; } case WM_SETFOCUS: case WM_KILLFOCUS: case WM_ENABLE: case WM_SETTEXT: case CB_SETCURSEL: case CB_ADDSTRING: case CB_DELETESTRING: case CB_RESETCONTENT: { LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); ::InvalidateRect(hWnd, NULL, FALSE); return result; } case WM_NCDESTROY: { ::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldProc); ::RemovePropA(hWnd, ICE_DARK_CONTROL_OLDPROC); return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } } return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } static LRESULT CALLBACK IceDark_FieldProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldProc = (WNDPROC)::GetPropA(hWnd, ICE_DARK_CONTROL_OLDPROC); if (!oldProc) { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_NCPAINT: case WM_PAINT: { LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); IceDark_DrawFrame(hWnd, (::GetFocus() == hWnd) ? ICE_DARK_BORDER_HOT : ICE_DARK_BORDER); return result; } case WM_SETFOCUS: case WM_KILLFOCUS: case WM_ENABLE: { LRESULT result = ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); ::RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW); return result; } case WM_NCDESTROY: { ::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldProc); ::RemovePropA(hWnd, ICE_DARK_CONTROL_OLDPROC); return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } } return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } static LRESULT CALLBACK IceDark_ParentProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldProc = (WNDPROC)::GetPropA(hWnd, ICE_DARK_PARENT_OLDPROC); if (!oldProc) { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } switch (uMsg) { case WM_ERASEBKGND: { RECT rc; ::GetClientRect(hWnd, &rc); IceDark_FillRect((HDC)wParam, rc, ICE_DARK_BG); return 1; } case WM_CTLCOLORDLG: return (LRESULT)IceDark_BgBrush(); case WM_CTLCOLORSTATIC: { HDC hDC = (HDC)wParam; ::SetTextColor(hDC, ICE_DARK_TEXT_MUTED); ::SetBkMode(hDC, TRANSPARENT); return (LRESULT)IceDark_BgBrush(); } case WM_CTLCOLOREDIT: case WM_CTLCOLORLISTBOX: { HDC hDC = (HDC)wParam; ::SetTextColor(hDC, ICE_DARK_TEXT); ::SetBkColor(hDC, ICE_DARK_FIELD); return (LRESULT)IceDark_FieldBrush(); } case WM_CTLCOLORBTN: { HDC hDC = (HDC)wParam; ::SetTextColor(hDC, ICE_DARK_TEXT); ::SetBkColor(hDC, ICE_DARK_BG); return (LRESULT)IceDark_BgBrush(); } case WM_NCDESTROY: { ::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)oldProc); ::RemovePropA(hWnd, ICE_DARK_PARENT_OLDPROC); return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } } return ::CallWindowProc(oldProc, hWnd, uMsg, wParam, lParam); } static void IceDark_Subclass(HWND hWnd, WNDPROC proc, const char* propName) { if (!hWnd || ::GetPropA(hWnd, propName)) { return; } WNDPROC oldProc = (WNDPROC)::GetWindowLongPtr(hWnd, GWLP_WNDPROC); ::SetPropA(hWnd, propName, (HANDLE)oldProc); ::SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)proc); } static bool IceDark_IsClass(HWND hWnd, const char* className) { char actual[128]; actual[0] = '\0'; ::GetClassNameA(hWnd, actual, sizeof(actual)); return ::lstrcmpiA(actual, className) == 0; } static bool IceDark_IsKnownControl(HWND hWnd) { return IceDark_IsClass(hWnd, "Button") || IceDark_IsClass(hWnd, "Edit") || IceDark_IsClass(hWnd, "ComboBox") || IceDark_IsClass(hWnd, "ListBox") || IceDark_IsClass(hWnd, "SysTreeView32") || IceDark_IsClass(hWnd, "SysListView32") || IceDark_IsClass(hWnd, "msctls_trackbar32") || IceDark_IsClass(hWnd, "msctls_updown32") || IceDark_IsClass(hWnd, "ScrollBar") || IceDark_IsClass(hWnd, "SysTabControl32"); } static void IceDark_ApplyToWindowAndChildren(HWND hWnd) { if (!hWnd) { return; } IceDark_ApplyNativeTheme(hWnd); IceDark_RemoveClientEdge(hWnd); if (IceDark_IsClass(hWnd, "Button")) { IceDark_Subclass(hWnd, IceDark_ButtonProc, ICE_DARK_CONTROL_OLDPROC); } else if (IceDark_IsClass(hWnd, "ComboBox")) { IceDark_Subclass(hWnd, IceDark_ComboProc, ICE_DARK_CONTROL_OLDPROC); } else if (IceDark_IsClass(hWnd, "Edit") || IceDark_IsClass(hWnd, "ListBox") || IceDark_IsClass(hWnd, "SysTreeView32") || IceDark_IsClass(hWnd, "SysListView32")) { IceDark_Subclass(hWnd, IceDark_FieldProc, ICE_DARK_CONTROL_OLDPROC); } else if (!IceDark_IsKnownControl(hWnd)) { IceDark_Subclass(hWnd, IceDark_ParentProc, ICE_DARK_PARENT_OLDPROC); } if (IceDark_IsClass(hWnd, "SysTreeView32")) { ::SendMessage(hWnd, TVM_SETBKCOLOR, 0, (LPARAM)ICE_DARK_FIELD); ::SendMessage(hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)ICE_DARK_TEXT); } if (IceDark_IsClass(hWnd, "SysListView32")) { ::SendMessage(hWnd, LVM_SETBKCOLOR, 0, (LPARAM)ICE_DARK_FIELD); ::SendMessage(hWnd, LVM_SETTEXTBKCOLOR, 0, (LPARAM)ICE_DARK_FIELD); ::SendMessage(hWnd, LVM_SETTEXTCOLOR, 0, (LPARAM)ICE_DARK_TEXT); } for (HWND child = ::GetWindow(hWnd, GW_CHILD); child != NULL; child = ::GetWindow(child, GW_HWNDNEXT)) { IceDark_ApplyToWindowAndChildren(child); } ::InvalidateRect(hWnd, NULL, TRUE); } static void IceDark_ApplyToDialog(CWnd* wnd) { if (wnd && wnd->GetSafeHwnd()) { IceDark_ApplyToWindowAndChildren(wnd->GetSafeHwnd()); } } ///////////////////////////////////////////////////////////////////////////// // CPatchDialog dialog CPatchDialog g_PatchDialog; CPatchDialog::CPatchDialog(CWnd* pParent /*=NULL*/) : CDialog(CPatchDialog::IDD, pParent) { //{{AFX_DATA_INIT(CPatchDialog) m_strName = _T(""); m_fS = 0.0f; m_fT = 0.0f; m_fX = 0.0f; m_fY = 0.0f; m_fZ = 0.0f; m_fHScale = 0.05f; m_fHShift = 0.05f; m_fRotate = 45; m_fVScale = 0.05f; m_fVShift = 0.05f; //}}AFX_DATA_INIT m_Patch = NULL; } void CPatchDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPatchDialog) DDX_Control(pDX, IDC_SPIN_VSHIFT, m_wndVShift); DDX_Control(pDX, IDC_SPIN_VSCALE, m_wndVScale); DDX_Control(pDX, IDC_SPIN_ROTATE, m_wndRotate); DDX_Control(pDX, IDC_SPIN_HSHIFT, m_wndHShift); DDX_Control(pDX, IDC_SPIN_HSCALE, m_wndHScale); DDX_Control(pDX, IDC_COMBO_TYPE, m_wndType); DDX_Control(pDX, IDC_COMBO_ROW, m_wndRows); DDX_Control(pDX, IDC_COMBO_COL, m_wndCols); DDX_Text(pDX, IDC_EDIT_NAME, m_strName); DDX_Text(pDX, IDC_EDIT_S, m_fS); DDX_Text(pDX, IDC_EDIT_T, m_fT); DDX_Text(pDX, IDC_EDIT_X, m_fX); DDX_Text(pDX, IDC_EDIT_Y, m_fY); DDX_Text(pDX, IDC_EDIT_Z, m_fZ); DDX_Text(pDX, IDC_HSCALE, m_fHScale); DDX_Text(pDX, IDC_HSHIFT, m_fHShift); DDX_Text(pDX, IDC_ROTATE, m_fRotate); DDX_Text(pDX, IDC_VSCALE, m_fVScale); DDX_Text(pDX, IDC_VSHIFT, m_fVShift); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPatchDialog, CDialog) //{{AFX_MSG_MAP(CPatchDialog) ON_BN_CLICKED(IDC_BTN_PATCHDETAILS, OnBtnPatchdetails) ON_BN_CLICKED(IDC_BTN_PATCHFIT, OnBtnPatchfit) ON_BN_CLICKED(IDC_BTN_PATCHNATURAL, OnBtnPatchnatural) ON_BN_CLICKED(IDC_BTN_PATCHRESET, OnBtnPatchreset) ON_CBN_SELCHANGE(IDC_COMBO_COL, OnSelchangeComboCol) ON_CBN_SELCHANGE(IDC_COMBO_ROW, OnSelchangeComboRow) ON_CBN_SELCHANGE(IDC_COMBO_TYPE, OnSelchangeComboType) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSCALE, OnDeltaposSpin) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_ROTATE, OnDeltaposSpin) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSCALE, OnDeltaposSpin) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VSHIFT, OnDeltaposSpin) ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HSHIFT, OnDeltaposSpin) ON_WM_DESTROY() ON_BN_CLICKED(IDC_APPLY, OnApply) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPatchDialog message handlers void CPatchDialog::OnBtnPatchdetails() { Patch_NaturalizeSelected(true); Sys_UpdateWindows(W_ALL); } void CPatchDialog::OnBtnPatchfit() { Patch_FitTexturing(); Sys_UpdateWindows(W_ALL); } void CPatchDialog::OnBtnPatchnatural() { Patch_NaturalizeSelected(); Sys_UpdateWindows(W_ALL); } void CPatchDialog::OnBtnPatchreset() { //CTextureLayout dlg; //if (dlg.DoModal() == IDOK) //{ // Patch_ResetTexturing(dlg.m_fX, dlg.m_fY); //} //Sys_UpdateWindows(W_ALL); } void CPatchDialog::OnSelchangeComboCol() { UpdateRowColInfo(); } void CPatchDialog::OnSelchangeComboRow() { UpdateRowColInfo(); } void CPatchDialog::OnSelchangeComboType() { // TODO: Add your control notification handler code here } void CPatchDialog::OnOK() { m_Patch = NULL; CDialog::OnOK(); } void CPatchDialog::OnDeltaposSpin(NMHDR* pNMHDR, LRESULT* pResult) { NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; UpdateSpinners((pNMUpDown->iDelta > 0), pNMUpDown->hdr.idFrom); *pResult = 0; } BOOL CPatchDialog::OnInitDialog() { CDialog::OnInitDialog(); IceDark_ApplyToDialog(this); m_wndHScale.SetRange(0, 1000); m_wndVScale.SetRange(0, 1000); m_wndHShift.SetRange(0, 1000); m_wndVShift.SetRange(0, 1000); m_wndRotate.SetRange(0, 1000); GetPatchInfo(); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPatchDialog::GetPatchInfo() { m_Patch = SinglePatchSelected(); if (m_Patch != NULL) { CString str; int i; m_wndRows.ResetContent(); for (i = 0; i < m_Patch->height; i++) { str.Format("%i", i); m_wndRows.AddString(str); } m_wndRows.SetCurSel(0); m_wndCols.ResetContent(); for (i = 0; i < m_Patch->width; i++) { str.Format("%i", i); m_wndCols.AddString(str); } m_wndCols.SetCurSel(0); } UpdateRowColInfo(); } void CPatchDialog::SetPatchInfo() { } void DoPatchInspector() { if (g_PatchDialog.GetSafeHwnd() == NULL) { g_PatchDialog.Create(IDD_DIALOG_PATCH); CRect rct; LONG lSize = sizeof(rct); if (LoadRegistryInfo("Radiant::PatchWindow", &rct, &lSize)) { g_PatchDialog.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE); } } g_PatchDialog.ShowWindow(SW_SHOW); g_PatchDialog.GetPatchInfo(); } void UpdatePatchInspector() { if (g_PatchDialog.GetSafeHwnd() != NULL) { g_PatchDialog.UpdateInfo(); } } void CPatchDialog::OnDestroy() { if (GetSafeHwnd()) { CRect rct; GetWindowRect(rct); SaveRegistryInfo("Radiant::PatchWindow", &rct, sizeof(rct)); } CDialog::OnDestroy(); } void CPatchDialog::UpdateRowColInfo() { m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0; if (m_Patch != NULL) { int r = m_wndRows.GetCurSel(); int c = m_wndCols.GetCurSel(); if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width) { m_fX = m_Patch->ctrl(c,r).xyz[0]; m_fY = m_Patch->ctrl(c,r).xyz[1]; m_fZ = m_Patch->ctrl(c,r).xyz[2]; m_fS = m_Patch->ctrl(c,r).st[0]; m_fT = m_Patch->ctrl(c,r).st[1]; } } UpdateData(FALSE); } void CPatchDialog::UpdateInfo() { GetPatchInfo(); } void CPatchDialog::OnApply() { UpdateData(TRUE); if (m_Patch != NULL) { int r = m_wndRows.GetCurSel(); int c = m_wndCols.GetCurSel(); if (r >= 0 && r < m_Patch->height && c >= 0 && c < m_Patch->width) { m_Patch->ctrl(c,r).xyz[0] = m_fX; m_Patch->ctrl(c,r).xyz[1] = m_fY; m_Patch->ctrl(c,r).xyz[2] = m_fZ; m_Patch->ctrl(c,r).st[0] = m_fS; m_Patch->ctrl(c,r).st[1] = m_fT; Patch_MakeDirty(m_Patch); Sys_UpdateWindows(W_ALL); } } } void CPatchDialog::UpdateSpinners(bool bUp, int nID) { texdef_t td; td.rotate = 0.0; td.scale[0] = td.scale[1] = 0.0; td.shift[0] = td.shift[1] = 0.0; td.value = 0; UpdateData(TRUE); if (nID == IDC_SPIN_ROTATE) { if (bUp) td.rotate = m_fRotate; else td.rotate = -m_fRotate; } else if (nID == IDC_SPIN_HSCALE) { if (bUp) td.scale[0] = 1 - m_fHScale; else td.scale[0] = 1 + m_fHScale; } else if (nID == IDC_SPIN_VSCALE) { if (bUp) td.scale[1] = 1 - m_fVScale; else td.scale[1] = 1 + m_fVScale; } else if (nID == IDC_SPIN_HSHIFT) { if (bUp) td.shift[0] = m_fHShift; else td.shift[0] = -m_fHShift; } else if (nID == IDC_SPIN_VSHIFT) { if (bUp) td.shift[1] = m_fVShift; else td.shift[1] = -m_fVShift; } Patch_SetTextureInfo(&td); Sys_UpdateWindows(W_CAMERA); }