| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program 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.
- **
- ** This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: WinMain.cpp //////////////////////////////////////////////////////////
- //-----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //-----------------------------------------------------------------------------
- //
- // Project: RTS3
- //
- // File name: GUIEdit.cpp
- //
- // Created: Colin Day, July 2001
- //
- // Desc: GUI Edit and window layout entry point
- //
- //-----------------------------------------------------------------------------
- ///////////////////////////////////////////////////////////////////////////////
- // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
- #include <stdlib.h>
- #include <windows.h>
- #include <commctrl.h>
- // USER INCLUDES //////////////////////////////////////////////////////////////
- #include "Common/Debug.h"
- #include "Common/GameMemory.h"
- #include "Common/GameEngine.h"
- #include "GameClient/GameWindowManager.h"
- #include "Win32Device/GameClient/Win32Mouse.h"
- #include "Resource.h"
- #include "Lib/BaseType.h"
- #include "GUIEdit.h"
- #include "EditWindow.h"
- #include "DialogProc.h"
- #include "LayoutScheme.h"
- // DEFINES ////////////////////////////////////////////////////////////////////
- // PRIVATE TYPES //////////////////////////////////////////////////////////////
- // PRIVATE DATA ///////////////////////////////////////////////////////////////
- static char *szWindowClass = "GUIEdit";
- // PUBLIC DATA ////////////////////////////////////////////////////////////////
- HINSTANCE ApplicationHInstance; ///< main application instance
- HWND ApplicationHWnd; ///< main application HWnd
- Win32Mouse *TheWin32Mouse = NULL; ///< for Win32 mouse
- char *gAppPrefix = "ge_"; /// So GuiEdit can have a different debug log file name if we need it
- const Char *g_strFile = "data\\Generals.str";
- const Char *g_csfFile = "data\\%s\\Generals.csf";
- ///////////////////////////////////////////////////////////////////////////////
- // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK AboutCallback(HWND, UINT, WPARAM, LPARAM);
- ///////////////////////////////////////////////////////////////////////////////
- // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- // initInstance ===============================================================
- //
- // FUNCTION: initInstance(HANDLE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- //=============================================================================
- static BOOL initInstance( HINSTANCE hInstance, int nCmdShow )
- {
- // store application instance
- ApplicationHInstance = hInstance;
- // create app window and keep handle
- ApplicationHWnd = CreateWindowEx( 0, // extended style
- szWindowClass, // window class name
- "GUIEdit", // window name
- WS_OVERLAPPEDWINDOW, // window styles
- 0, // x position
- 0, // y position
- GetSystemMetrics( SM_CXSCREEN ), // width
- GetSystemMetrics( SM_CYSCREEN ), // height
- NULL, // parent
- NULL, // menu
- ApplicationHInstance, // instance
- NULL ); // creation data
- if( ApplicationHWnd == NULL )
- return FALSE;
- // display the window
- ShowWindow( ApplicationHWnd, SW_MAXIMIZE );
- UpdateWindow( ApplicationHWnd );
- return TRUE;
- } // end initInstance
- // registerClass ==============================================================
- //
- // FUNCTION: registerClass()
- //
- // PURPOSE: Registers the window class.
- //
- // COMMENTS:
- //
- // This function and its usage is only necessary if you want this code
- // to be compatible with Win32 systems prior to the 'RegisterClassEx'
- // function that was added to Windows 95. It is important to call this function
- // so that the application will get 'well formed' small icons associated
- // with it.
- //
- //=============================================================================
- static ATOM registerClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
- wcex.cbSize = sizeof( WNDCLASSEX );
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = (WNDPROC)WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)GUIEDIT_LARGE_ICON);
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
- wcex.lpszMenuName = (LPCSTR)GUIEDIT_MENU;
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)GUIEDIT_SMALL_ICON);
- return RegisterClassEx( &wcex );
- } // registerClass
- ///////////////////////////////////////////////////////////////////////////////
- // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- // WinMain ====================================================================
- /** Entry point for application */
- //=============================================================================
- Int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- MSG msg;
- Int returnValue;
- HACCEL hAccelTable;
- Bool quit = FALSE;
- /// @todo remove this force set of working directory later
- Char buffer[ _MAX_PATH ];
- GetModuleFileName( NULL, buffer, sizeof( buffer ) );
- Char *pEnd = buffer + strlen( buffer );
- while( pEnd != buffer )
- {
- if( *pEnd == '\\' )
- {
- *pEnd = 0;
- break;
- }
- pEnd--;
- }
- ::SetCurrentDirectory(buffer);
- // start the log
- DEBUG_INIT(DEBUG_FLAGS_DEFAULT);
- initMemoryManager();
- // register a class for our window with the OS
- registerClass( hInstance );
- // Perform application initialization:
- if( !initInstance( hInstance, nCmdShow ) )
- return FALSE;
- // load accellerator table
- hAccelTable = LoadAccelerators( hInstance, (LPCTSTR)GUIEDIT_ACCELERATORS );
- // initialize the common controls
- INITCOMMONCONTROLSEX controls;
- controls.dwSize = sizeof( controls );
- controls.dwICC = ICC_BAR_CLASSES;
- InitCommonControlsEx( &controls );
- // initialize GUIEdit data
- TheEditor = new GUIEdit;
- if( TheEditor == NULL )
- return FALSE;
- TheEditor->init();
- //
- // see if we have any messages to process, a NULL window handle tells the
- // OS to look at the main window associated with the calling thread, us!
- //
- while( quit == FALSE )
- {
- // is there is message ready for us?
- if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- // process ALL messages waiting
- while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
- {
- // get the message
- returnValue = GetMessage( &msg, NULL, 0, 0 );
- // check for quitting
- if( returnValue == 0 )
- quit = TRUE;
- // translate accelerator messages
- if( !TranslateAccelerator( msg.hwnd, hAccelTable, &msg ) )
- {
- // translate and dispatch the message
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- } // end if
- } // end while
- } // end if
- else
- {
- // udpate our universe
- TheEditor->update();
- Sleep(1);
- } // end else
-
- } // end while
- // shutdown GUIEdit data
- delete TheEditor;
- TheEditor = NULL;
- // close the log
- shutdownMemoryManager();
- DEBUG_SHUTDOWN();
- return msg.wParam;
- } // end WinMain
- // WndProc ====================================================================
- //
- // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //=============================================================================
- LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam )
- {
- switch( message )
- {
- // ------------------------------------------------------------------------
- case WM_MOUSEMOVE:
- {
- // keep focus in our app
- if( GetFocus() != hWnd )
- SetFocus( hWnd );
- return 0;
- } // end move mouse
- // ------------------------------------------------------------------------
- case WM_COMMAND:
- {
- Int controlID = LOWORD( wParam );
- // Int nofifyCode = HIWORD( wParam );
- // HWND hWndControl = (HWND)lParam;
- switch( controlID )
- {
- // --------------------------------------------------------------------
- case MENU_EXIT:
- TheEditor->menuExit();
- break;
- //---------------------------------------------------------------------
- case MENU_NEW:
- TheEditor->menuNew();
- break;
- // --------------------------------------------------------------------
- case MENU_OPEN:
- TheEditor->menuOpen();
- break;
- // --------------------------------------------------------------------
- case MENU_SAVE:
- TheEditor->menuSave();
- break;
- // --------------------------------------------------------------------
- case MENU_SAVEAS:
- TheEditor->menuSaveAs();
- break;
- // --------------------------------------------------------------------
- case MENU_COPY:
- TheEditor->menuCopy();
- break;
- // --------------------------------------------------------------------
- case MENU_CUT:
- TheEditor->menuCut();
- break;
- // --------------------------------------------------------------------
- case MENU_PASTE:
- TheEditor->menuPaste();
- break;
- // --------------------------------------------------------------------
- case MENU_CALLBACKS:
- DialogBox( TheEditor->getInstance(), (LPCTSTR)CALLBACK_EDITOR_DIALOG,
- TheEditor->getWindowHandle(), CallbackEditorDialogProc );
- break;
- // --------------------------------------------------------------------
- case MENU_GRID_SETTINGS:
- DialogBox( TheEditor->getInstance(), (LPCTSTR)GRID_SETTINGS_DIALOG,
- TheEditor->getWindowHandle(), GridSettingsDialogProc );
- break;
- // --------------------------------------------------------------------
- case MENU_SHOW_HIDDEN_OUTLINES:
- TheEditor->setShowHiddenOutlines( !TheEditor->getShowHiddenOutlines() );
- break;
- // --------------------------------------------------------------------
- case MENU_SHOW_SEE_THRU_OUTLINES:
- TheEditor->setShowSeeThruOutlines( !TheEditor->getShowSeeThruOutlines() );
- break;
-
- // --------------------------------------------------------------------
- case MENU_TEST_MODE:
- // switch to test mode or edit mode
- if( TheEditor)
- {
- EditMode mode = TheEditor->getMode();
- if( mode != MODE_TEST_RUN )
- TheEditor->setMode( MODE_TEST_RUN );
- else
- TheEditor->setMode( MODE_EDIT );
- } // end if
- break;
-
- // --------------------------------------------------------------------
- case MENU_BACKGROUND_COLOR:
-
- if( TheEditWindow )
- {
- RGBColorReal color = TheEditWindow->getBackgroundColor();
- RGBColorInt *newColor;
- POINT mouse;
- // get mouse point
- GetCursorPos( &mouse );
- // select a new color
- newColor = SelectColor( (Int)(255.0f * color.red),
- (Int)(255.0f * color.green),
- (Int)(255.0f * color.blue),
- (Int)(255.0f * color.alpha),
- mouse.x, mouse.y );
- if( newColor )
- {
-
- color.red = (Real)newColor->red / 255.0f;
- color.green = (Real)newColor->green / 255.0f;
- color.blue = (Real)newColor->blue / 255.0f;
- color.alpha = (Real)newColor->alpha / 255.0f;
- TheEditWindow->setBackgroundColor( color );
- } // end if
- } // end if
- break;
- // --------------------------------------------------------------------
- case MENU_SCHEME:
- {
- // open the default scheme information
- if( TheDefaultScheme )
- TheDefaultScheme->openDialog();
- break;
- } // end scheme
- // --------------------------------------------------------------------
- case MENU_ABOUT:
- {
- DialogBox( ApplicationHInstance, (LPCTSTR)ABOUT_DIALOG,
- hWnd, (DLGPROC)AboutCallback );
- break;
- } // end about
- // --------------------------------------------------------------------
- default:
- {
- return DefWindowProc( hWnd, message, wParam, lParam );
- } // end default
- } // end switch( controlID )
- return 0;
- } // end command
- // ------------------------------------------------------------------------
- case WM_CLOSE:
- {
- // close gets initiated from the 'x' in the top right of the window
- TheEditor->menuExit();
- return 0;
- } // end close
- // ------------------------------------------------------------------------
- case WM_KEYDOWN:
- {
- Int virtualKey = wParam;
- // Int keyData = lParam;
- Bool controlDown = BitTest( GetKeyState( VK_CONTROL ), 0x1000 );
- switch( virtualKey )
- {
- // --------------------------------------------------------------------
- case VK_ESCAPE:
- {
- // unselect all windows
- if( TheEditor )
- if(TheEditor->getMode() == MODE_KEYBOARD_MOVE)
- TheEditor->setMode( MODE_EDIT );
- else
- TheEditor->clearSelections();
- break;
- } // end escape
- // --------------------------------------------------------------------
- case VK_DELETE:
- {
- // delete all selected windows
- if( TheEditor )
- TheEditor->deleteSelected();
- break;
- } // end delete
- // --------------------------------------------------------------------
- case VK_LEFT:
- {
- // delete all selected windows
- if( TheEditor && TheEditWindow)
- {
- if(TheEditor->getMode() == MODE_EDIT)
- {
-
- if(TheEditor->selectionCount() <= 0 )
- break;
- ICoord2D zero;
- zero.x = zero.y = 0;
- TheEditWindow->setDragMoveOrigin(&zero);
- TheEditWindow->setDragMoveDest(&zero);
-
- TheEditor->setMode(MODE_KEYBOARD_MOVE);
- }
- if(TheEditor->getMode() == MODE_KEYBOARD_MOVE)
- {
- ICoord2D temp;
- temp = TheEditWindow->getDragMoveDest();
- if(!controlDown && TheEditor->isGridSnapOn())
- {
- temp.x -= TheEditor->getGridResolution();
- TheEditor->gridSnapLocation(&temp,&temp);
- }
- else
- {
- temp.x--;
- }
- TheEditWindow->setDragMoveDest(&temp);
- }
- }
- break;
- } // end Left
- // --------------------------------------------------------------------
- case VK_RIGHT:
- {
- // delete all selected windows
- if( TheEditor && TheEditWindow)
- {
- if(TheEditor->getMode() == MODE_EDIT)
- {
-
- if(TheEditor->selectionCount() <= 0 )
- break;
- ICoord2D zero;
- zero.x = zero.y = 0;
- TheEditWindow->setDragMoveOrigin(&zero);
- TheEditWindow->setDragMoveDest(&zero);
-
- TheEditor->setMode(MODE_KEYBOARD_MOVE);
- }
- if(TheEditor->getMode() == MODE_KEYBOARD_MOVE)
- {
- ICoord2D temp;
-
- temp = TheEditWindow->getDragMoveDest();
- if(!controlDown && TheEditor->isGridSnapOn())
- {
- temp.x += TheEditor->getGridResolution();
- TheEditor->gridSnapLocation(&temp,&temp);
- }
- else
- {
- temp.x++;
- }
- TheEditWindow->setDragMoveDest(&temp);
- }
- }
- break;
- } // end RIGHT
- // --------------------------------------------------------------------
- case VK_UP:
- {
- // delete all selected windows
- if( TheEditor && TheEditWindow)
- {
- if(TheEditor->getMode() == MODE_EDIT)
- {
-
- if(TheEditor->selectionCount() <= 0 )
- break;
- ICoord2D zero;
- zero.x = zero.y = 0;
- TheEditWindow->setDragMoveOrigin(&zero);
- TheEditWindow->setDragMoveDest(&zero);
-
- TheEditor->setMode(MODE_KEYBOARD_MOVE);
- }
- if(TheEditor->getMode() == MODE_KEYBOARD_MOVE)
- {
- ICoord2D temp;
- temp = TheEditWindow->getDragMoveDest();
-
- if(!controlDown && TheEditor->isGridSnapOn())
- {
- temp.y -= TheEditor->getGridResolution();
- TheEditor->gridSnapLocation(&temp,&temp);
- }
- else
- {
- temp.y--;
- }
- TheEditWindow->setDragMoveDest(&temp);
- }
- }
- break;
- } // end Up
- // --------------------------------------------------------------------
- case VK_DOWN:
- {
- // delete all selected windows
- if( TheEditor && TheEditWindow)
- {
- if(TheEditor->getMode() == MODE_EDIT)
- {
-
- if(TheEditor->selectionCount() <= 0 )
- break;
- ICoord2D zero;
- zero.x = zero.y = 0;
- TheEditWindow->setDragMoveOrigin(&zero);
- TheEditWindow->setDragMoveDest(&zero);
-
- TheEditor->setMode(MODE_KEYBOARD_MOVE);
- }
- if(TheEditor->getMode() == MODE_KEYBOARD_MOVE)
- {
- ICoord2D temp;
- temp = TheEditWindow->getDragMoveDest();
- if(!controlDown && TheEditor->isGridSnapOn())
- {
- temp.y += TheEditor->getGridResolution();
- TheEditor->gridSnapLocation(&temp,&temp);
- }
- else
- {
- temp.y++;
- }
- TheEditWindow->setDragMoveDest(&temp);
- }
- }
- break;
- } // end Down
-
- // --------------------------------------------------------------------
- case VK_RETURN:
- {
- if( TheEditor && TheEditWindow && TheEditor->getMode() == MODE_KEYBOARD_MOVE )
- {
- ICoord2D tempOrigin, tempDest;
- tempDest = TheEditWindow->getDragMoveDest();
- tempOrigin = TheEditWindow->getDragMoveOrigin();
- // move the windows
- TheEditor->dragMoveSelectedWindows( &tempOrigin, &tempDest );
- // go back to normal mode
- TheEditor->setMode( MODE_EDIT );
- }
- break;
- }// end Enter
- } // end switch( virtualKey )
- return 0;
- } // end key down
- // ------------------------------------------------------------------------
- case WM_SIZE:
- {
- Int width = LOWORD( lParam );
- Int height = HIWORD( lParam );
- // resize status bar
- if( TheEditor )
- {
- HWND statusBar = TheEditor->getStatusBarWindowHandle();
- if( statusBar )
- {
- RECT rect;
- Int barX, barY;
- Int barWidth, barHeight;
- // keep status window height the same
- GetWindowRect( statusBar, &rect );
- barWidth = width;
- barHeight = rect.bottom - rect.top;
- barX = 0;
- barY = height - barHeight;
- MoveWindow( statusBar, barX, barY, barWidth, barHeight, TRUE );
- } // end if
- } // end if
- return 0;
- } // end size
- // ------------------------------------------------------------------------
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc;
- hdc = BeginPaint(hWnd, &ps);
- EndPaint(hWnd, &ps);
- break;
- } // end paint
- // ------------------------------------------------------------------------
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- break;
- } // end destroy
- // ------------------------------------------------------------------------
- default:
- {
- return DefWindowProc(hWnd, message, wParam, lParam);
- } // end default
- } // end switch( message )
- return DefWindowProc( hWnd, message, wParam, lParam );
- } // end WndProc
- // AboutCallback ==============================================================
- /** Mesage handler for about box. */
- //=============================================================================
- LRESULT CALLBACK AboutCallback( HWND hDlg, UINT message,
- WPARAM wParam, LPARAM lParam )
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return TRUE;
- }
- break;
- }
- return FALSE;
- } // end AboutCallback
|