Subversion Repositories Kolibri OS

Rev

Rev 4481 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "kosSyst.h"
  2. #include "KosFile.h"
  3. #include "gfxdef.h"
  4. #include "mainWnd.h"
  5. #include "lang.h"
  6.  
  7.  
  8. //
  9. RGB bmPMButton[] = {
  10.         0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
  11.         0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
  12.         0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  13.         0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
  14.         0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
  15.         0xCCCCCC, 0xCCCCCC, 0x000000, 0x000000, 0xCCCCCC, 0xCCCCCC,
  16. };
  17.  
  18.  
  19. //
  20. #if LANG == RUS
  21. char mainWndTitle[] = "PHARAON's CRYPT\0";
  22. char mainWndCopyright[] = "(C) MMVI by Rabid Rabbit";
  23. char mainWndMenuStart[] = "Enter - ç âì ¨£àã";
  24. char mainWndMenuLevel[] = " ç «ì­ë© ã஢¥­ì - %U";
  25. #else
  26. char mainWndTitle[] = "PHARAOH's CRYPT\0";
  27. char mainWndCopyright[] = "(C) MMVI by Rabid Rabbit";
  28. char mainWndMenuStart[] = "Enter - Start game";
  29. char mainWndMenuLevel[] = "Starting level - %U";
  30. #endif
  31. //
  32. CKosBitmap mainWndFace;
  33. //
  34. Word mcx, mcy;
  35.  
  36. #define BT_SIZE_X_MINUS         4
  37. #define BT_SIZE_X_PLUS          5
  38.  
  39. //
  40. int MainWndLoop()
  41. {
  42.         Byte keyCode;
  43.         Dword buttonID;
  44.         int result;
  45.         static bool firstTime = true;
  46.  
  47.         //
  48.         startGameLevel = maxGameLevel;
  49.         //
  50.         if ( firstTime )
  51.         {
  52.                 //
  53.                 mainWndFace.GetSize( mcx, mcy );
  54.                 //
  55.                 firstTime = false;
  56.                 //
  57.                 DrawMainWindow();
  58.         }
  59.         //
  60.         kos_ChangeWindow( -1, -1, mcx + 1, mcy + 21 );
  61.         //
  62.         for ( result = MW_NONE; result == MW_NONE; )
  63.         {
  64.                 switch( kos_WaitForEvent() )
  65.                 {
  66.                 case 1:
  67.                         DrawMainWindow();
  68.                         break;
  69.  
  70.                 case 2:
  71.                         if ( kos_GetKey( keyCode ) )
  72.                         {
  73.                                 //
  74.                                 switch ( keyCode )
  75.                                 {
  76.                                 case 13:                                        // enter
  77.                                         result = MW_START_GAME;
  78.                                         break;
  79.  
  80.                                 case 27:                                        // escape
  81.                                         result = MW_EXIT_APP;
  82.                                         break;
  83.  
  84.                                 default:
  85.                                         break;
  86.                                 }
  87.                         }
  88.                         break;
  89.  
  90.                 case 3:
  91.                         if ( kos_GetButtonID( buttonID ) )
  92.                         {
  93.                                 //
  94.                                 switch ( buttonID )
  95.                                 {
  96.                                 //
  97.                                 case 1:
  98.                                         result = MW_EXIT_APP;
  99.                                         break;
  100.                                 case BT_SIZE_X_MINUS:
  101.                                         if ( --startGameLevel < 1 )
  102.                                                 startGameLevel = 1;
  103.                                         else
  104.                                                 DrawMainWindow();
  105.                                         break;
  106.  
  107.                                 //
  108.                                 case BT_SIZE_X_PLUS:
  109.                                         if ( ++startGameLevel > maxGameLevel )
  110.                                                 startGameLevel = maxGameLevel;
  111.                                         else
  112.                                                 DrawMainWindow();
  113.                                         break;
  114.  
  115.                                 //
  116.                                 default:
  117.                                         break;
  118.                                 }
  119.                         }
  120.  
  121.                 default:
  122.                         break;
  123.                 }
  124.         }
  125.         // êíîïêè
  126.         kos_DefineButton(
  127.                 0, 0,
  128.                 0, 0,
  129.                 BT_SIZE_X_MINUS + 0x80000000,
  130.                 0
  131.                 );
  132.         //
  133.         kos_DefineButton(
  134.                 0, 0,
  135.                 0, 0,
  136.                 BT_SIZE_X_PLUS + 0x80000000,
  137.                 0
  138.                 );
  139.         //
  140.         return result;
  141. }
  142.  
  143.  
  144. // ïîëíàÿ îòðèñîâêà ãëàâíîãî îêíà ïðîãðàììû (1)
  145. void DrawMainWindow()
  146. {
  147.         char line[64];
  148.  
  149.         //
  150.         kos_WindowRedrawStatus( WRS_BEGIN );
  151.         // îêíî
  152.         kos_DefineAndDrawWindow(
  153.                 WNDLEFT, WNDTOP,
  154.                 mcx + 1, mcy + 21,
  155.                 0x54, 0x0,                              // Skinned fixed size window, dont fill working area, window has caption
  156.                 0, WNDHEADCOLOUR,
  157.                 mainWndTitle
  158.                 );
  159.         // çàãîëîâîê îêíà
  160.           kos_ChangeWindowCaption(mainWndTitle);
  161.         mainWndFace.Draw( 1, 21 );
  162.         // ïåðâàÿ ñòðîêà
  163.         kos_WriteTextToWindow(
  164.                 8, 32,
  165.                 0, 0x0,
  166.                 mainWndMenuStart, sizeof(mainWndMenuStart)-1
  167.                 );
  168.         // òðåòüÿ ñòðîêà
  169.         sprintf( line, mainWndMenuLevel, startGameLevel);
  170.         kos_WriteTextToWindow(
  171.                 8, 64,
  172.                 0, 0x0,
  173.                 line, strlen( line )
  174.                 );
  175.         // êíîïêè
  176.         kos_DefineButton(
  177.                 mcx - 29, 64,
  178.                 12, 12,
  179.                 BT_SIZE_X_MINUS,
  180.                 0xCCCCCC
  181.                 );
  182.         //
  183.         kos_PutImage( bmPMButton + 12, 6, 2, mcx - 29 + 3, 69 );
  184.         //
  185.         kos_DefineButton(
  186.                 mcx - 16, 64,
  187.                 12, 12,
  188.                 BT_SIZE_X_PLUS,
  189.                 0xCCCCCC
  190.                 );
  191.         //
  192.         kos_PutImage( bmPMButton, 6, 6, mcx - 16 + 3, 67 );
  193.         // êîïèðàéò
  194.         kos_WriteTextToWindow(
  195.                 8, mcy - 16 + 21,
  196.                 0, 0x000066,
  197.                 mainWndCopyright, sizeof(mainWndCopyright)-1
  198.                 );
  199.         //
  200.         kos_WindowRedrawStatus( WRS_END );
  201. }
  202.