#ifndef RENDERTYPEWIN #error Only for Windows #endif #include "compat.h" #include "build.h" #include "editor.h" #include "winlayer.h" #define WIN32_LEAN_AND_MEAN #include #include #ifndef _WIN32_IE #define _WIN32_IE 0x0300 #endif #include #include #include "startwin.editor.h" #define TAB_CONFIG 0 #define TAB_MESSAGES 1 static struct { int32_t fullscreen; int32_t xdim2d, ydim2d; int32_t xdim3d, ydim3d, bpp3d; int32_t forcesetup; } settings; static HWND startupdlg = NULL; static HWND pages[2] = { NULL, NULL}; static int32_t done = -1, mode = TAB_CONFIG; static void PopulateForm(void) { int32_t i,j; char buf[64]; int32_t mode2d, mode3d; HWND hwnd2d, hwnd3d; hwnd2d = GetDlgItem(pages[TAB_CONFIG], IDC2DVMODE); hwnd3d = GetDlgItem(pages[TAB_CONFIG], IDC3DVMODE); mode2d = checkvideomode(&settings.xdim2d, &settings.ydim2d, 8, settings.fullscreen, 1); mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1); if (mode2d < 0) mode2d = 0; if (mode3d < 0) { int32_t cd[] = { 32, 24, 16, 15, 8, 0 }; for (i=0; cd[i];) { if (cd[i] >= settings.bpp3d) i++; else break; } for (; cd[i]; i++) { mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1); if (mode3d < 0) continue; settings.bpp3d = cd[i]; break; } } Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), (settings.fullscreen ? BST_CHECKED : BST_UNCHECKED)); Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED)); (void)ComboBox_ResetContent(hwnd2d); (void)ComboBox_ResetContent(hwnd3d); for (i=0; iidFrom != WIN_STARTWIN_TABCTL) break; cur = (int32_t)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0); switch (nmhdr->code) { case TCN_SELCHANGING: { if (cur < 0 || !pages[cur]) break; ShowWindow(pages[cur],SW_HIDE); return TRUE; } case TCN_SELCHANGE: { if (cur < 0 || !pages[cur]) break; ShowWindow(pages[cur],SW_SHOW); return TRUE; } } break; } case WM_CLOSE: if (mode == TAB_CONFIG) done = 0; else quitevent++; return TRUE; case WM_DESTROY: if (hbmp) { DeleteObject(hbmp); hbmp = NULL; } if (pages[TAB_CONFIG]) { DestroyWindow(pages[TAB_CONFIG]); pages[TAB_CONFIG] = NULL; } startupdlg = NULL; return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case WIN_STARTWIN_CANCEL: if (mode == TAB_CONFIG) done = 0; else quitevent++; return TRUE; case WIN_STARTWIN_START: done = 1; return TRUE; } return FALSE; case WM_CTLCOLORSTATIC: if ((HWND)lParam == pages[TAB_MESSAGES]) return (BOOL)GetSysColorBrush(COLOR_WINDOW); break; default: break; } return FALSE; } int32_t startwin_open(void) { INITCOMMONCONTROLSEX icc; if (startupdlg) return 1; icc.dwSize = sizeof(icc); icc.dwICC = ICC_TAB_CLASSES; InitCommonControlsEx(&icc); startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc); if (startupdlg) { SetPage(TAB_MESSAGES); EnableConfig(0); return 0; } return -1; } int32_t startwin_close(void) { if (!startupdlg) return 1; DestroyWindow(startupdlg); startupdlg = NULL; return 0; } int32_t startwin_puts(const char *buf) { const char *p = NULL, *q = NULL; static char workbuf[1024]; static int32_t newline = 0; int32_t curlen, linesbefore, linesafter; HWND edctl; int32_t vis; static HWND dactrl = NULL; if (!startupdlg) return 1; edctl = pages[TAB_MESSAGES]; if (!edctl) return -1; if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL); vis = ((int32_t)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES); if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0); curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0); SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen); linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0); p = buf; while (*p) { if (newline) { SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n"); newline = 0; } q = p; while (*q && *q != '\n') q++; Bmemcpy(workbuf, p, q-p); if (*q == '\n') { if (!q[1]) { newline = 1; workbuf[q-p] = 0; } else { workbuf[q-p] = '\r'; workbuf[q-p+1] = '\n'; workbuf[q-p+2] = 0; } p = q+1; } else { workbuf[q-p] = 0; p = q; } SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf); } linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0); SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore); if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0); return 0; } int32_t startwin_settitle(const char *str) { if (!startupdlg) return 1; SetWindowText(startupdlg, str); return 0; } int32_t startwin_idle(void *v) { if (!startupdlg || !IsWindow(startupdlg)) return 0; if (IsDialogMessage(startupdlg, (MSG*)v)) return 1; return 0; } int32_t startwin_run(void) { MSG msg; if (!startupdlg) return 1; done = -1; SetPage(TAB_CONFIG); EnableConfig(1); settings.fullscreen = fullscreen; settings.xdim2d = xdim2d; settings.ydim2d = ydim2d; settings.xdim3d = xdimgame; settings.ydim3d = ydimgame; settings.bpp3d = bppgame; settings.forcesetup = forcesetup; PopulateForm(); while (done < 0) { switch (GetMessage(&msg, NULL, 0,0)) { case 0: done = 1; break; case -1: return -1; default: if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break; TranslateMessage(&msg); DispatchMessage(&msg); break; } } SetPage(TAB_MESSAGES); EnableConfig(0); if (done) { fullscreen = settings.fullscreen; xdim2d = settings.xdim2d; ydim2d = settings.ydim2d; xdimgame = settings.xdim3d; ydimgame = settings.ydim3d; bppgame = settings.bpp3d; forcesetup = settings.forcesetup; } return done; }