-
-//
-// Initialize TTF data
-//
-void CreateNewDoc(void)
-{
-}
-
-//
-// Save changes to document before quitting
-//
-bool SaveChanges(void)
-{
- return true;
-}
-
-
-
-//
-// ABOUT Dialog WndProc
-//
-BOOL CALLBACK AboutProc(HWND hDlg, UINT msgID, WPARAM wParam, LPARAM lParam)
-{
- switch (msgID)
- {
- case WM_INITDIALOG:
-
- MiscCenterWnd(hDlg, hMainWnd);
- break;
-
- case WM_COMMAND:
-
- if (wParam == IDOK || wParam == IDCANCEL)
- EndDialog(hDlg, TRUE);
-
- break;
-
- default:
- return FALSE;
- }
-
- return TRUE;
-}
-
-//
-// Character Window WndProc
-//
-WndProcCW PROC STDCALL, hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
-
- mov eax, uMsg // pickup our message
- .IF (eax == WM_PAINT)
- mov eax, 0 // Non-sense... (placeholder!)
-// Scan conversion etc. goes here...
- .ELSEIF (eax == WM_LBUTTONDOWN)
- invoke SetCapture, hCharWnd
- .ELSEIF (eax == WM_LBUTTONUP)
- invoke ReleaseCapture
- invoke SetFocus, hMainWnd // Make sure the main wnd keeps focus!
- .ELSEIF (eax == WM_NCLBUTTONDOWN)
- invoke DefWindowProc, hWnd, uMsg, wParam, lParam // Let it do its thing
- invoke SetFocus, hMainWnd // Make sure the main wnd keeps focus!
- .ELSE
-DefProc: invoke DefWindowProc, hWnd, uMsg, wParam, lParam
- .ENDIF
- ret
-
-WndProcCW ENDP
-
-//
-// Character Window WndProc
-//
-LRESULT CALLBACK WndProcCW(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)
-{
- switch (msgID)
- {
- default:
- return DefWindowProc(hWnd, msgID, wParam, lParam);
- }
-
- return 0;
-}
-
-
-// Function prototypes
-
-int32 FindSelectedTool(void);
-
-//
-// Tool Palette WndProc
-//
-LRESULT CALLBACK WndProcTP(HWND hWnd, UINT msgID, WPARAM wParam, LPARAM lParam)
-{
- PAINTSTRUCT ps;
- HDC hdc;
- POINT pt;
- static uint32 prevTool = -1;
-
- switch (msgID)
- {
- case WM_PAINT:
- {
- hdc = BeginPaint(hWnd, &ps);
- HDC newDC = CreateCompatibleDC(NULL);
- SelectObject(newDC, hBMToolPal1);
- BitBlt(hdc, 0, 0, sizeTPBM.x, sizeTPBM.y, newDC, 0, 0, SRCCOPY);
- DeleteDC(newDC);
-
-// This is crappy. Find some way to tighten this up!
- int32 tool = FindSelectedTool();
-
- if (tool != -1)
- {
- newDC = CreateCompatibleDC(NULL);
- SelectObject(newDC, hBMToolPal1);
- //need ul corner of bitmap, ul corner of dest, width/height
- pt.x = sizeStamp.x * (tool & 0x03), pt.y = sizeStamp.y * (tool >> 2);
- BitBlt(hdc, pt.x, pt.y, sizeStamp.x, sizeStamp.y, newDC, pt.x, pt.y, NOTSRCCOPY);
- DeleteDC(newDC);
- }
-
- EndPaint(hWnd, &ps);
- break;
- }
- case WM_MOUSEMOVE:
- {
- int32 tool = FindSelectedTool();
-
- if (tool != prevTool)
- {
- prevTool = tool;
- InvalidateRect(hWnd, NULL, FALSE);
- }
-
- break;
- }
- case WM_RBUTTONUP:
- {
- int32 tool = FindSelectedTool(), oldTool = currentTool;
-
- if (tool != -1)
- currentTool = tool;
-
- if (currentTool != TOOLSelect && currentTool != TOOLDelPt && currentTool != TOOLAddPt
- && currentTool != TOOLPolySelect)
- ptHighlight = -1;
-
- if (currentTool != oldTool)
- InvalidateRect(hMainWnd, NULL, TRUE);
-
- if (currentTool == TOOLAddPoly)
-#ifdef DEBUGFOO
-{
-#endif
- polyFirstPoint = true;
-#ifdef DEBUGFOO
-wsprintf(strBuf, "--> Selected poly tool, polyFirstPoint is %s\n", polyFirstPoint ? "true" : "false");
-WriteLogMsg(strBuf);
-}
-#endif
-
- ReleaseCapture();
- ShowWindow(hToolPalWnd, SW_HIDE);
- SetFocus(hMainWnd); // Make sure the main wnd keeps focus!
-
- break;
- }
- default:
- return DefWindowProc(hWnd, msgID, wParam, lParam);
- }
-
- return 0;
-}
-
-//
-// Find which tool we're pointing at
-// Use: xcoord = mouse.x / (bmsize.x/4), ycoord = mouse.y / (bmsize.y/2)
-//
-int32 FindSelectedTool(void)
-{
- POINT pt;
-
- GetCursorPos(&pt);
- ScreenToClient(hToolPalWnd, &pt);
-
- uint32 x = (uint32)pt.x / sizeStamp.x, y = (uint32)pt.y / sizeStamp.y, tool = -1;
-
- if (x < 4 && y < 2)
-// {
- tool = (y * 4) + x;
-
-// if (tool == 7)
-// tool = -1; // 7 has no tool...
-// }
-
- return tool;
-}
-
-
-//
-// Misc center window
-//
-void MiscCenterWnd(HWND hChild, HWND hParent)
-{
- RECT parent, child;
-
- if (!GetWindowRect(hParent, &parent) || !GetWindowRect(hChild, &child))
- return;
-
- int32 x = parent.left + (((parent.right - parent.left) - (child.right - child.left)) / 2),
- y = parent.top + (((parent.bottom - parent.top) - (child.bottom - child.top)) / 2);
-
- if (x < 0)
- x = 0;
- else if (x > GetSystemMetrics(SM_CXFULLSCREEN) - (child.right - child.left))
- x = GetSystemMetrics(SM_CXFULLSCREEN) - (child.right - child.left);
-
- if (y < 0)
- y = 0;
- else if (y > GetSystemMetrics(SM_CYFULLSCREEN) - (child.bottom - child.top))
- y = GetSystemMetrics(SM_CYFULLSCREEN) - (child.bottom - child.top);
-
- SetWindowPos(hChild, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-}
-
-//
-// Allow only one instance
-//
-bool OnlyOneInstance(void)
-{
- HWND window = FindWindow(className, NULL);
-
- if (window == NULL)
- return true;
-
- ShowWindow(window, SW_SHOWNORMAL);
- SetWindowPos(window, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
-
- return false;
-}
-
-//
-// Load/Allocate all resources
-//
-bool LoadResources(void)
-{
- hCur[0] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR1));
- hCur[1] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR2));
- hCur[2] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR3));
- hCur[3] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR4));
- hCur[4] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR5));
- hCur[5] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR6));
- hCur[6] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR7));
- hCur[7] = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR8));
-
- BITMAP bm;
-
- hBMToolPal1 = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TOOLPAL1));
- GetObject(hBMToolPal1, sizeof(bm), &bm);
-
- // Set up sizes
-
- sizeTPBM.x = bm.bmWidth, sizeTPBM.y = bm.bmHeight;
- sizeStamp.x = bm.bmWidth / 4, sizeStamp.y = bm.bmHeight / 2;
-
- hBluePen1 = CreatePen(PS_DOT, 1, 0x00FF0000);
- hRedPen1 = CreatePen(PS_SOLID, 1, 0x000000FF);
- hGreenPen1 = CreatePen(PS_SOLID, 1, 0x0000AF00);
- hBlackPen1 = CreatePen(PS_SOLID, 1, 0x00000000);
-
- LOGBRUSH lb = { BS_NULL, 0, 0 };
-
- hNullBrush = CreateBrushIndirect(&lb);
-
- return true;
-}
-
-//
-// Deallocate all resources
-//
-void DeallocateResources(void)
-{
- DeleteObject(hBMToolPal1);
- DeleteObject(hBluePen1);
- DeleteObject(hRedPen1);
- DeleteObject(hGreenPen1);
- DeleteObject(hBlackPen1);
- DeleteObject(hNullBrush);
-}
-
-//
-// Save all application specific data, so we can pick up where we last left off...
-//
-void SaveAppState(void)
-{
- SetINIInt("Main", "flags", wpM.flags);
- SetINIInt("Main", "showCmd", wpM.showCmd);
- SetINIInt("Main", "x1", wpM.rcNormalPosition.left);
- SetINIInt("Main", "y1", wpM.rcNormalPosition.top);
- SetINIInt("Main", "x2", wpM.rcNormalPosition.right);
- SetINIInt("Main", "y2", wpM.rcNormalPosition.bottom);
-
- SetINIInt("Main", "vpx", ptVPM.x);
- SetINIInt("Main", "vpy", ptVPM.y);
-
- SetINIInt("Char", "flags", wpC.flags);
- SetINIInt("Char", "showCmd", wpC.showCmd);
- SetINIInt("Char", "x1", wpC.rcNormalPosition.left);
- SetINIInt("Char", "y1", wpC.rcNormalPosition.top);
- SetINIInt("Char", "x2", wpC.rcNormalPosition.right);
- SetINIInt("Char", "y2", wpC.rcNormalPosition.bottom);
-
- // Need to write out currently opened font, character looking at, other misc. crap
-// SetINIString("Main", "currentFile", pDoc->GetPathName());
-// SetINIInt("Main", "currentChar", pDoc->character_num);
-}
-
-//
-// Restore all application specific data previously saved
-//
-bool RestoreAppState(void)
-{
- InitINIFile();
-
- WINDOWPLACEMENT wp;
- wp.length = sizeof(WINDOWPLACEMENT);
- GetWindowPlacement(hMainWnd, &wp);
-
- wp.flags = GetINIInt("Main", "flags", wp.flags);
- wp.showCmd = GetINIInt("Main", "showCmd", wp.showCmd);
- wp.rcNormalPosition.left = GetINIInt("Main", "x1", wp.rcNormalPosition.left);
- wp.rcNormalPosition.top = GetINIInt("Main", "y1", wp.rcNormalPosition.top);
- wp.rcNormalPosition.right = GetINIInt("Main", "x2", wp.rcNormalPosition.right);
- wp.rcNormalPosition.bottom = GetINIInt("Main", "y2", wp.rcNormalPosition.bottom);
-
- SetWindowPlacement(hMainWnd, &wp);
-
- HDC hdc;
- POINT pt;
- hdc = GetDC(hMainWnd);
- GetViewportOrgEx(hdc, &pt);
-
- pt.x = GetINIInt("Main", "vpx", pt.x);
- pt.y = GetINIInt("Main", "vpy", pt.y);
-
- SetViewportOrgEx(hdc, pt.x, pt.y, NULL);
- ReleaseDC(hMainWnd, hdc);
-
- GetWindowPlacement(hCharWnd, &wp);
-
- wp.flags = GetINIInt("Char", "flags", wp.flags);
- wp.showCmd = GetINIInt("Char", "showCmd", wp.showCmd);
- wp.rcNormalPosition.left = GetINIInt("Char", "x1", wp.rcNormalPosition.left);
- wp.rcNormalPosition.top = GetINIInt("Char", "y1", wp.rcNormalPosition.top);
- wp.rcNormalPosition.right = GetINIInt("Char", "x2", wp.rcNormalPosition.right);
- wp.rcNormalPosition.bottom = GetINIInt("Char", "y2", wp.rcNormalPosition.bottom);
-
- SetWindowPlacement(hCharWnd, &wp);
-
- if (wp.showCmd == SW_HIDE)
- SendMessage(hToolBar, TB_SETSTATE, ID_TBCHARWIN, MAKELONG(TBSTATE_ENABLED, 0));
-
-// CString lastFile = theApplicationObject.GetProfileString(version, "currentFile", "");
-// int lastChar = theApplicationObject.GetProfileInt(version, "currentChar", 0);
-// if (lastFile.GetLength())
-// {
-// // Attempt to restore the last session by open the last file used, etc...
-// if (!pDoc->m_myFont.Load(lastFile))
-// {
-// // Err, make sure you can support any allegations you make below, buddy!
-// AfxMessageBox("The last file opened with TTF Edit\n\rseems to have been moved or deleted.");
-// }
-// else
-// {
-// pDoc->m_myFont.SetGlyph(lastChar); // Set TTF object to last used char
-// pDoc->character_num = lastChar;
-// pDoc->SetPathName(lastFile);
-//
-// BYTE name[512];
-// pDoc->m_myFont.GetCharName(lastChar, name);
-// m_wndOwned.SetWindowText((char *)name);
-// }
-// }
-
- return true;
-}
-
-//
-// Initialization
-//
-bool Initialization(void)
-{
- WNDCLASSEX wcex;
-
- if (!LoadResources())
- return false;
-
- RtlFillMemory(&wcex, sizeof(WNDCLASSEX), 0);
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wcex.lpfnWndProc = WndProc;
- wcex.hInstance = hInst;
- wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON));
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wcex.lpszMenuName = MAKEINTRESOURCE(IDM_MENU);
- wcex.lpszClassName = className;
- wcex.hIconSm = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, NULL);
-
- if (!RegisterClassEx(&wcex))
- return false;
-
- hMainWnd = CreateWindowEx(NULL, className, className, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
- 0, 0, 0x1A0, 0x180, NULL, NULL, hInst, NULL);
-
- if (!hMainWnd)
- return false;
-
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd);
-
- // Character window creation
-
- wcex.lpfnWndProc = WndProcCW;
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = CNCharWin;
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // Owned windows have "regular" cursors
-
- if (!RegisterClassEx(&wcex))
- return false;
-
- hCharWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW, CNCharWin,
- curCharName, WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_THICKFRAME,
- 100, 100, 120, 120, hMainWnd, NULL, hInst, NULL);
-
- if (!hCharWnd)
- return false;
-
- ShowWindow(hCharWnd, SW_SHOWNORMAL);
- UpdateWindow(hCharWnd);
- SetFocus(hMainWnd); // Make sure main wnd has focus!
-
- // Tool palette window creation
-
- wcex.lpfnWndProc = WndProcTP;
- wcex.lpszClassName = CNToolPal;
-
- if (!RegisterClassEx(&wcex))
- return false;
-
- hToolPalWnd = CreateWindowEx(WS_EX_WINDOWEDGE, CNToolPal, NULL, WS_POPUP,
- 0, 0, sizeTPBM.x, sizeTPBM.y, hMainWnd, NULL, hInst, NULL);
-
- if (!hToolPalWnd)
- return false;
-
-// Note: A better way to handle this would be to have a sub that registers ALL
-// classes beforehand and passes a TRUE/FALSE back depending on whether or not
-// all the classes were able to be registered or not, THEN create the windows
-// and controls...
-
- RestoreAppState(); // Restore app related stuff
-
- return true;
-}
-
-#endif