home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 7 Games / 07-Games.zip / 32PMCHES.ZIP / COLOR.C < prev    next >
Text File  |  1990-12-17  |  11KB  |  323 lines

  1. //
  2. //  Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  3. //  Copyright (c) 1988, 1989, 1990  John Stanback
  4. //
  5. //  Project:    OS/2 PM Port of GNU CHESS 3.1 (PmChess)
  6. //
  7. //  Version:    1.02  1990-12-17
  8. //
  9. //   Module:    Color Support Logic (Color.c)
  10. //
  11. //   Porter:    Ported to Windows 3.0 by Darly Baker
  12. //
  13. //   Porter:    Ported to OS/2 1.2+ by Kent Cedola
  14. //
  15. //   System:    OS2 1.2 using Microsoft C 6.0
  16. //
  17. //  Remarks:    This code converted from Windows to PM using a straight port
  18. //              method with some editing improvements.  Based on ideas and
  19. //              code segments of Charles Petzold from artices in Microsoft
  20. //              Systems Journal.
  21. //
  22. //  License:
  23. //
  24. //    CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  25. //    WARRANTY.  No author or distributor accepts responsibility to anyone for
  26. //    the consequences of using it or for whether it serves any particular
  27. //    purpose or works at all, unless he says so in writing.  Refer to the
  28. //    CHESS General Public License for full details.
  29. //
  30. //    Everyone is granted permission to copy, modify and redistribute CHESS,
  31. //    but only under the conditions described in the CHESS General Public
  32. //    License.  A copy of this license is supposed to have been given to you
  33. //    along with CHESS so you can know your rights and responsibilities.  It
  34. //    should be in a file named COPYING.  Among other things, the copyright
  35. //    notice and this notice must be preserved on all copies.
  36. //
  37.  
  38. #define INCL_DOS
  39. #define INCL_GPI
  40. #define INCL_PM
  41. #include <os2.h>
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include "PmChess.h"
  45. #include "Resource.h"
  46.  
  47.  
  48. extern ULONG clrBackGround;
  49. extern ULONG clrBlackSquare;
  50. extern ULONG clrWhiteSquare;
  51. extern ULONG clrBlackPiece;
  52. extern ULONG clrWhitePiece;
  53. extern ULONG clrText;
  54.  
  55. extern HWND hComputerColor;
  56. extern HWND hComputerMove;
  57. extern HWND hWhosTurn;
  58. extern HWND hClockComputer;
  59. extern HWND hClockHuman;
  60. extern HWND hMsgComputer;
  61. extern HWND hMsgHuman;
  62.  
  63. //
  64. //  Define dialog procedure's prototypes.
  65. //
  66. MRESULT EXPENTRY ColorProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  67.  
  68.  
  69.  
  70. static char lpChessini[]    = "pmchess.ini";   /* Ormson 12/13/90    */
  71. static char lpBackGround[]  = "BackGround";
  72. static char lpBlackSquare[] = "BlackSquare";
  73. static char lpWhiteSquare[] = "WhiteSquare";
  74. static char lpBlackPiece[]  = "BlackPiece";
  75. static char lpWhitePiece[]  = "WhitePiece";
  76. static char lpDefault[]     = "Default";
  77. static char lpText[]        = "Text";
  78.  
  79. static char np08lX[] = "%08lX";
  80.  
  81.  
  82. void UpdateChilds()
  83.   {
  84.   WinSetPresParam(hComputerColor, PP_BACKGROUNDCOLORINDEX,
  85.                   sizeof(LONG), &clrBackGround);
  86.   WinSetPresParam(hWhosTurn,      PP_BACKGROUNDCOLORINDEX,
  87.                   sizeof(LONG), &clrBackGround);
  88.   WinSetPresParam(hComputerMove,  PP_BACKGROUNDCOLORINDEX,
  89.                   sizeof(LONG), &clrBackGround);
  90.   WinSetPresParam(hClockComputer,  PP_BACKGROUNDCOLORINDEX,
  91.                   sizeof(LONG), &clrBackGround);
  92.   WinSetPresParam(hClockHuman,  PP_BACKGROUNDCOLORINDEX,
  93.                   sizeof(LONG), &clrBackGround);
  94.   WinSetPresParam(hMsgComputer,  PP_BACKGROUNDCOLORINDEX,
  95.                   sizeof(LONG), &clrBackGround);
  96.   WinSetPresParam(hMsgHuman, PP_BACKGROUNDCOLORINDEX,
  97.                   sizeof(LONG), &clrBackGround);
  98.   }
  99.  
  100.  
  101. void SetStandardColors ( VOID )
  102.   {
  103.   clrBackGround  = CLR_CYAN;
  104.   clrBlackSquare = CLR_DARKGREEN;
  105.   clrWhiteSquare = CLR_PALEGRAY;
  106.   clrBlackPiece  = CLR_RED;
  107.   clrWhitePiece  = CLR_WHITE;
  108.   clrText        = CLR_BLACK;
  109.  
  110.   UpdateChilds();
  111.   }
  112.  
  113.  
  114. void SaveColors(PSZ appname )
  115.   {
  116.   HINI hIni;
  117.   char ostring[30];
  118.  
  119.  
  120.   hIni = PrfOpenProfile(hab, lpChessini);
  121.  
  122.    sprintf ( ostring, np08lX, clrBackGround);
  123.    PrfWriteProfileString (hIni, appname, lpBackGround,ostring);
  124.  
  125.    sprintf ( ostring, np08lX, clrBlackSquare);
  126.    PrfWriteProfileString (hIni, appname, lpBlackSquare,ostring);
  127.  
  128.    sprintf ( ostring, np08lX, clrWhiteSquare);
  129.    PrfWriteProfileString (hIni, appname, lpWhiteSquare,ostring);
  130.  
  131.    sprintf ( ostring, np08lX, clrBlackPiece);
  132.    PrfWriteProfileString (hIni, appname, lpBlackPiece,ostring);
  133.  
  134.    sprintf ( ostring, np08lX, clrWhitePiece);
  135.    PrfWriteProfileString (hIni, appname, lpWhitePiece,ostring);
  136.  
  137.    sprintf ( ostring, np08lX, clrText);
  138.    PrfWriteProfileString (hIni, appname, lpText,ostring);
  139.  
  140.   PrfCloseProfile(hIni);
  141.   }
  142.  
  143. void GetStartupColors ( PSZ appname )
  144. {
  145.   HINI hIni;
  146.   char istring[30];
  147.  
  148.  
  149.   hIni = PrfOpenProfile(hab, lpChessini);
  150.  
  151.    SetStandardColors ();
  152.  
  153.    PrfQueryProfileString (hIni, appname, lpBackGround,lpDefault,istring,
  154.                              sizeof(istring));
  155.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrBackGround);
  156.  
  157.    PrfQueryProfileString (hIni, appname, lpBlackSquare,lpDefault,istring,
  158.                              sizeof(istring));
  159.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrBlackSquare);
  160.  
  161.    PrfQueryProfileString (hIni, appname, lpWhiteSquare,lpDefault,istring,
  162.                              sizeof(istring));
  163.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrWhiteSquare);
  164.  
  165.    PrfQueryProfileString (hIni, appname, lpBlackPiece,lpDefault,istring,
  166.                              sizeof(istring));
  167.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrBlackPiece);
  168.  
  169.    PrfQueryProfileString (hIni, appname, lpWhitePiece,lpDefault,istring,
  170.                              sizeof(istring));
  171.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrWhitePiece);
  172.  
  173.    PrfQueryProfileString (hIni, appname, lpText,lpDefault,istring,
  174.                              sizeof(istring));
  175.    if (strcmp ( istring, lpDefault) != 0)  sscanf ( istring, np08lX, &clrText);
  176.  
  177.   PrfCloseProfile(hIni);
  178.  
  179.  
  180.   UpdateChilds();
  181. }
  182.  
  183.  
  184. int ColorDialog(HWND hWnd, ULONG Param )
  185.   {
  186.   int status;
  187.  
  188.   status = (int)(LONG)WinDlgBox(HWND_DESKTOP, hWnd, ColorProc, 0, IDD_COLORS,
  189.                            (PVOID)Param);
  190.   if (status)
  191.     UpdateChilds();
  192.  
  193.   return (status);
  194.   }
  195.  
  196.  
  197. static int ColorToIndex ( ULONG color)
  198. {
  199.    if (color == CLR_BLACK ) return IDC_COLORS_BLACK;
  200.    else if ( color == CLR_BLUE) return IDC_COLORS_BLUE;
  201.    else if ( color == CLR_GREEN) return IDC_COLORS_GREEN;
  202.    else if ( color == CLR_CYAN) return IDC_COLORS_CYAN;
  203.    else if ( color == CLR_RED) return IDC_COLORS_RED;
  204.    else if ( color == CLR_PINK) return IDC_COLORS_PINK;
  205.    else if ( color == CLR_YELLOW) return IDC_COLORS_YELLOW;
  206.    else if ( color == CLR_PALEGRAY) return IDC_COLORS_PALEGRAY;
  207.    else if ( color == CLR_DARKGRAY) return IDC_COLORS_DARKGRAY;
  208.    else if ( color == CLR_DARKBLUE) return IDC_COLORS_DARKBLUE;
  209.    else if ( color == CLR_DARKGREEN) return IDC_COLORS_DARKGREEN;
  210.    else if ( color == CLR_DARKCYAN) return IDC_COLORS_DARKCYAN;
  211.    else if ( color == CLR_DARKRED) return IDC_COLORS_DARKRED;
  212.    else if ( color == CLR_DARKPINK) return IDC_COLORS_DARKPINK;
  213.    else if ( color == CLR_BROWN) return IDC_COLORS_BROWN;
  214.    else if ( color == CLR_WHITE) return IDC_COLORS_WHITE;
  215.    return IDC_COLORS_WHITE;
  216. }
  217.  
  218. static ULONG IndexToColor ( int color)
  219. {
  220.    if (color == IDC_COLORS_BLACK ) return  CLR_BLACK;
  221.    else if ( color == IDC_COLORS_BLUE) return  CLR_BLUE;
  222.    else if ( color == IDC_COLORS_GREEN) return  CLR_GREEN;
  223.    else if ( color == IDC_COLORS_CYAN) return  CLR_CYAN;
  224.    else if ( color == IDC_COLORS_RED) return  CLR_RED;
  225.    else if ( color == IDC_COLORS_PINK) return  CLR_PINK;
  226.    else if ( color == IDC_COLORS_YELLOW) return  CLR_YELLOW;
  227.    else if ( color == IDC_COLORS_PALEGRAY) return  CLR_PALEGRAY;
  228.    else if ( color == IDC_COLORS_DARKGRAY) return  CLR_DARKGRAY;
  229.    else if ( color == IDC_COLORS_DARKBLUE) return  CLR_DARKBLUE;
  230.    else if ( color == IDC_COLORS_DARKGREEN) return  CLR_DARKGREEN;
  231.    else if ( color == IDC_COLORS_DARKCYAN) return  CLR_DARKCYAN;
  232.    else if ( color == IDC_COLORS_DARKRED) return  CLR_DARKRED;
  233.    else if ( color == IDC_COLORS_DARKPINK) return  CLR_DARKPINK;
  234.    else if ( color == IDC_COLORS_BROWN) return  CLR_BROWN;
  235.    else if ( color == IDC_COLORS_WHITE) return  CLR_WHITE;
  236.    return CLR_RED;
  237. }
  238.  
  239. static char lpWBGC[] ="Window background color";
  240. static char lpBS[]   ="Black square color";
  241. static char lpWS[]   ="White square color";
  242. static char lpBP[]   ="Black piece color";
  243. static char lpWP[]   ="White piece color";
  244. static char lpTX[]   ="Text color";
  245.  
  246. static ULONG *pclr;
  247. static int index;
  248.  
  249. MRESULT EXPENTRY ColorProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)
  250.   {
  251.   char *pchHeading;
  252.  
  253.  
  254.   switch (msg)
  255.     {
  256.     case WM_INITDLG:
  257.       switch (LONGFROMMP(mp2))
  258.         {
  259.         case IDM_COLORS_BSQUARES:
  260.           pchHeading = (char *)lpBS;
  261.           pclr       = &clrBlackSquare;
  262.           break;
  263.  
  264.         case IDM_COLORS_WSQUARES:
  265.           pchHeading = (char *)lpWS;
  266.           pclr       = &clrWhiteSquare;
  267.           break;
  268.  
  269.         case IDM_COLORS_BPIECES:
  270.           pchHeading = (char *) lpBP;
  271.           pclr       = &clrBlackPiece;
  272.           break;
  273.  
  274.         case IDM_COLORS_WPIECES:
  275.           pchHeading = (char *) lpWP;
  276.           pclr       = &clrWhitePiece;
  277.           break;
  278.  
  279.         case IDM_COLORS_TEXT:
  280.           pchHeading = (char *) lpTX;
  281.           pclr       = &clrText;
  282.           break;
  283.  
  284.         default:
  285.           pchHeading = (char *) lpWBGC;
  286.           pclr       = &clrBackGround;
  287.           break;
  288.  
  289.          }
  290.  
  291.       WinSetDlgItemText(hDlg, IDC_COLORS_HEADER, pchHeading);
  292.       index = ColorToIndex( *pclr);
  293.  
  294.       WinSendDlgItemMsg(hDlg, index, BM_SETCHECK, MPFROMSHORT(TRUE), NULL);
  295.  
  296.       WinSetFocus (HWND_DESKTOP, WinWindowFromID(hDlg, index));
  297.  
  298.       return ((MRESULT)TRUE);
  299.  
  300.     case WM_COMMAND:
  301.       switch (SHORT1FROMMP(mp1))
  302.         {
  303.         case IDC_OK:
  304.           *pclr = IndexToColor (index);
  305.           WinDismissDlg(hDlg, TRUE);
  306.           break;
  307.  
  308.         case IDC_CANCEL:
  309.           WinDismissDlg(hDlg, FALSE);
  310.           break;
  311.         }
  312.       return (0);
  313.  
  314.     case WM_CONTROL:
  315.       WinSendDlgItemMsg(hDlg, index, BM_SETCHECK, MPFROMSHORT(FALSE), NULL);
  316.       index = SHORT1FROMMP(mp1);
  317.       WinSendDlgItemMsg(hDlg, index, BM_SETCHECK, MPFROMSHORT(TRUE), NULL);
  318.       return 0 ;
  319.     }
  320.  
  321.   return (WinDefDlgProc(hDlg, msg, mp1, mp2));
  322.   }
  323.