TEST.CPP 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : GraphicBufferClass Test Program *
  23. * *
  24. * File Name : DRAWTEST.CPP *
  25. * *
  26. * Programmer : Steve Tall *
  27. * *
  28. * Start Date : September 25, 1995 *
  29. * *
  30. * Last Update : September 27, 1995 [ST] *
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * WinMain -- Program entry point *
  35. * WndProc -- Callback procedure for main window *
  36. * *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #define WIN32
  39. #define WIN32_LEAN_AND_MEAN
  40. #include <wwlib32.h>
  41. #include <direct.h>
  42. #include "..\mouse.h"
  43. #define NAME "KEYBOARD/MOUSE test"
  44. #define TITLE "KEYBOARD/MOUSE library test"
  45. //
  46. // Misc globals for testing
  47. //
  48. BOOL AllDone = FALSE; // Flag that we should exit
  49. #define MODE_WIDTH 640 // Width in pixels of required video mode
  50. #define MODE_HEIGHT 400 // Height in pixels of required video mode
  51. int ScreenWidth=MODE_WIDTH;
  52. GraphicBufferClass *ScreenBuffer=NULL; // Global pointer to screen GraphicBufferClass
  53. GraphicBufferClass *HidBuffer = NULL;
  54. GraphicBufferClass SysMemPage(320,200); // page in real memory
  55. WWMouseClass *Mouse=NULL; // Global pointer to mouse information
  56. WinTimerClass *WindowsTimer=NULL;
  57. PALETTEENTRY pe[256]; // DD Palette entries
  58. unsigned char Palette[256*3]; // Place to load palette to
  59. extern LPDIRECTDRAWPALETTE PalettePtr; // Pointer to direct draw palette object
  60. //
  61. // Prototypes
  62. //
  63. long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
  64. //
  65. // Externs
  66. //
  67. extern LPDIRECTDRAW DirectDrawObject;
  68. extern HWND MainWindow;
  69. VOID *ShapeFile;
  70. int CurrentShape;
  71. /***********************************************************************************************
  72. * WinMain -- Program entry point *
  73. * *
  74. * *
  75. * *
  76. * INPUT: Standard Windows startup parameters *
  77. * *
  78. * OUTPUT: msg.wParam *
  79. * *
  80. * WARNINGS: None *
  81. * *
  82. * HISTORY: *
  83. * 9/27/95 1:28PM ST : Created *
  84. *=============================================================================================*/
  85. #pragma off(unreferenced)
  86. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  87. LPSTR lpszCmdParam, int nCmdShow)
  88. {
  89. static char szAppName[] = "HelloWin" ;
  90. HWND hwnd ;
  91. MSG msg ;
  92. WNDCLASS wndclass ;
  93. char path_to_exe[132];
  94. char drive[_MAX_DRIVE];
  95. char path[_MAX_PATH];
  96. unsigned drivecount;
  97. unsigned olddrive;
  98. char oldpath[PATH_MAX];
  99. /*
  100. ** Get a path to the executable and make sure that we are pointing
  101. ** at the location our datafiles are located at.
  102. */
  103. GetModuleFileName (hInstance, &path_to_exe[0], 132);
  104. getcwd(oldpath, sizeof(oldpath));
  105. _dos_getdrive(&olddrive);
  106. _splitpath(path_to_exe, drive, path, NULL, NULL);
  107. if (!drive[0]) {
  108. drive[0] = (char)(('A' + olddrive)-1);
  109. }
  110. if (!path[0]) {
  111. strcpy(path, ".");
  112. }
  113. _dos_setdrive(toupper((drive[0])-'A')+1, &drivecount);
  114. if (path[strlen(path)-1] == '\\') {
  115. path[strlen(path)-1] = '\0';
  116. }
  117. chdir(path);
  118. //
  119. // Register the window class
  120. //
  121. if (!hPrevInstance)
  122. {
  123. wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  124. wndclass.lpfnWndProc = WndProc ;
  125. wndclass.cbClsExtra = 0 ;
  126. wndclass.cbWndExtra = 0 ;
  127. wndclass.hInstance = hInstance ;
  128. wndclass.hIcon = LoadIcon (hInstance, IDI_APPLICATION) ;
  129. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  130. wndclass.hbrBackground = NULL;
  131. wndclass.lpszMenuName = NULL;
  132. wndclass.lpszClassName = NAME;
  133. RegisterClass (&wndclass) ;
  134. }
  135. //
  136. // Create our main window
  137. //
  138. hwnd = CreateWindowEx (
  139. WS_EX_TOPMOST,
  140. NAME,
  141. TITLE,
  142. WS_POPUP | WS_MAXIMIZE,
  143. 0,
  144. 0,
  145. MODE_WIDTH,
  146. MODE_HEIGHT,
  147. NULL,
  148. NULL,
  149. hInstance,
  150. NULL );
  151. ShowWindow (hwnd, nCmdShow) ;
  152. UpdateWindow (hwnd) ;
  153. SetFocus (hwnd);
  154. MainWindow=hwnd; //Save the handle to our main window
  155. // (Dangerous if Windoze can change the handle)
  156. // Set the video mode
  157. Set_Video_Mode( MainWindow , MODE_WIDTH , MODE_HEIGHT , 8 );
  158. Set_Shape_Buffer(new unsigned char[5000], 5000);
  159. //
  160. // Create the GraphicBufferClass that will be the screen buffer
  161. //
  162. ScreenBuffer = new GraphicBufferClass ( MODE_WIDTH , MODE_HEIGHT , (GBC_Enum)(GBC_VIDEOMEM | GBC_VISIBLE));
  163. HidBuffer = new GraphicBufferClass ( MODE_WIDTH , MODE_HEIGHT , (GBC_Enum)(GBC_VIDEOMEM));
  164. ShowCursor (FALSE);
  165. Mouse = new WWMouseClass(ScreenBuffer,32,32);
  166. //
  167. // Load up the picture and display it on the scene page
  168. //
  169. Load_Picture("TITLE.CPS", SysMemPage, SysMemPage, Palette, BM_DEFAULT);
  170. FontPtr = Load_Font("font.fnt");
  171. ShapeFile = Load_Alloc_Data("MOUSE.SHP", MEM_NORMAL);
  172. CurrentShape = 0;
  173. Mouse->Set_Cursor(0,0,Extract_Shape(ShapeFile,CurrentShape));
  174. Set_Palette(Palette);
  175. SysMemPage.Scale(*HidBuffer);
  176. Mouse->Show_Mouse();
  177. WindowsTimer = new WinTimerClass(60,FALSE);
  178. //
  179. // Get rid of the windows cursor
  180. //
  181. AllDone = FALSE;
  182. //
  183. // Windows message loop
  184. //
  185. int count = 0;
  186. char temp[100];
  187. CountDownTimerClass timer(BT_SYSTEM, 0);
  188. timer.Set(60);
  189. timer.Start();
  190. while ( ! AllDone ){
  191. if (timer.Time() == 0) {
  192. sprintf(temp,"%d frames per second",count);
  193. Mouse->Erase_Mouse(HidBuffer, TRUE);
  194. HidBuffer->Print(temp,0,0,255,1);
  195. count = 0;
  196. timer.Set(60);
  197. timer.Start();
  198. } else {
  199. count++;
  200. Mouse->Erase_Mouse(HidBuffer, TRUE);
  201. }
  202. Mouse->Draw_Mouse(HidBuffer);
  203. HidBuffer->Blit(*ScreenBuffer);
  204. Mouse->Erase_Mouse(HidBuffer, FALSE);
  205. if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ){
  206. if( !GetMessage( &msg, NULL, 0, 0 ) ){
  207. break;
  208. }
  209. TranslateMessage(&msg);
  210. DispatchMessage(&msg);
  211. }
  212. }
  213. delete Mouse;
  214. return msg.wParam;
  215. }
  216. #pragma on(unreferenced)
  217. /***********************************************************************************************
  218. * WndProc -- windows message callback *
  219. * *
  220. * Pilfered from a windows example program - HELLOWIN.C *
  221. * *
  222. * *
  223. * INPUT: Standard Windoze callback parameters *
  224. * *
  225. * OUTPUT: long *
  226. * *
  227. * WARNINGS: None *
  228. * *
  229. * HISTORY: *
  230. * 9/27/95 1:39PM ST : Pilfered *
  231. *=============================================================================================*/
  232. long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam,
  233. LONG lParam)
  234. {
  235. static int condhide = 0;
  236. switch (message){
  237. // case WM_MOUSEMOVE:
  238. // if (Mouse)
  239. // Mouse->Process_Mouse();
  240. // break;
  241. case WM_LBUTTONDOWN:
  242. if (Mouse) {
  243. Mouse->Set_Cursor(0,0,Extract_Shape(ShapeFile,++CurrentShape));
  244. if (CurrentShape>160) CurrentShape = 0;
  245. }
  246. break;
  247. case WM_RBUTTONDOWN:
  248. if (condhide) {
  249. Mouse->Show_Mouse();
  250. Mouse->Conditional_Show_Mouse();
  251. Mouse->Conditional_Show_Mouse();
  252. condhide = FALSE;
  253. } else {
  254. Mouse->Hide_Mouse();
  255. Mouse->Conditional_Hide_Mouse(0,0,320,200);
  256. Mouse->Conditional_Hide_Mouse(0,0,320,200);
  257. condhide = TRUE;
  258. }
  259. break;
  260. case WM_ACTIVATEAPP:
  261. if ((BOOL)wParam) {
  262. if (ScreenBuffer) {
  263. ScreenBuffer->Get_DD_Surface()->Restore();
  264. }
  265. }
  266. break;
  267. case WM_DESTROY:
  268. //
  269. // Tidy up
  270. //
  271. delete ScreenBuffer;
  272. delete Mouse;
  273. if ( DirectDrawObject ){
  274. Reset_Video_Mode();
  275. }
  276. AllDone = TRUE;
  277. PostQuitMessage (0) ;
  278. return(0);
  279. }
  280. return DefWindowProc (hwnd, message, wParam, lParam) ;
  281. }