home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / imagedit / globals.c < prev    next >
C/C++ Source or Header  |  1996-06-12  |  16KB  |  348 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                 Copyright (C) 1987-1996 Microsoft Corp.                */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /****************************************************************************/
  7. /****************************** Module Header *******************************
  8. * Module Name: globals.c
  9. *
  10. * Global data for the image editor.
  11. *
  12. * History:
  13. *
  14. ****************************************************************************/
  15.  
  16. #include "imagedit.h"
  17. #include "dialogs.h"
  18. #include "iehelp.h"
  19. #include "ids.h"
  20.  
  21.  
  22. /*
  23.  * Initialized data and structures -----------------------------------------
  24.  */
  25.  
  26. /*
  27.  * Initialization data structure.  This describes each profile entry
  28.  * that is contained in the initialization file.
  29.  */
  30. INIENTRY gaie[] = {
  31.     { "fGrid",          &gfGrid,            FALSE,              0 },
  32.     { "fShowColor",     &gfShowColor,       TRUE,               0 },
  33.     { "fShowView",      &gfShowView,        TRUE,               0 },
  34.     { "fShowToolbox",   &gfShowToolbox,     TRUE,               0 },
  35.     { "nBrushSize",     &gnBrushSize,       3,                  0 },
  36.     { NULL,             NULL,               0,                  0 }
  37. };
  38.  
  39. BOOL gfGrid;                        // TRUE if the grid is on.
  40. BOOL gfShowColor;                   // TRUE if Color palette is to be shown.
  41. BOOL gfShowView;                    // TRUE if View window is to be shown.
  42. BOOL gfShowToolbox;                 // TRUE if Toolbox is to be shown.
  43. INT gnBrushSize;                    // Current brush size.
  44.  
  45. CHAR szAppPos[] = "AppPos";         // App window's position keyname.
  46. CHAR szTBPos[] = "TBPos";           // Toolbox window's position keyname.
  47. CHAR szViewPos[] = "ViewPos";       // View window's position keyname.
  48. CHAR szColorPos[] = "ColorPos";     // Color palette window's position keyname.
  49. CHAR szrgbScreen[] = "rgbScreen";   // Screen color keyname.
  50.  
  51.  
  52. /*
  53.  * Instance handles, window handles and class strings ----------------------
  54.  */
  55.  
  56. HANDLE ghInst;                      // App instance handle.
  57. HANDLE haccelTbl;                   // Accelerator table handle.
  58. HCURSOR hcurWait;                   // Standard hourglass cursor.
  59.  
  60. HWND ghwndMain;                     // Main app window handle.
  61. HWND ghwndWork;                     // Workspace window handle.
  62. HWND ghwndPropBar;                  // Properties Bar window handle.
  63. HWND ghwndToolbox;                  // Toolbox window handle.
  64. HWND ghwndView;                     // View window handle.
  65. HWND ghwndColor;                    // Color palette window handle.
  66.  
  67. CHAR szMainClass[] = "ImagEdit";    // Main window class.
  68. CHAR szWorkClass[] = "Work";        // Work window class.
  69. CHAR szToolboxClass[] = "Toolbox";  // Toolbox window class.
  70. CHAR szToolBtnClass[] = "ToolBtn";  // Toolbox button window class.
  71. CHAR szViewClass[] = "View";        // View window class.
  72. CHAR szColorBoxClass[] = "ColorBox";// Color box window class.
  73. CHAR szColorLRClass[] = "ColorLR";  // Color Left-Right sample class.
  74.  
  75.  
  76. /*
  77.  * Device list globals -----------------------------------------------------
  78.  */
  79.  
  80. PDEVICE gpIconDeviceHead = NULL;    // Head of icon device list.
  81. INT gnIconDevices = 0;              // Number of icon devices.
  82. PDEVICE gpCursorDeviceHead = NULL;  // Head of cursor device list.
  83. INT gnCursorDevices = 0;            // Number of cursor devices.
  84.  
  85.  
  86. /*
  87.  * Globals that describe the current file and image being edited -----------
  88.  */
  89.  
  90. CHAR gszFullFileName[CCHMAXPATH];   // Full path name of current file.
  91. PSTR gpszFileName = NULL;           // Current file name (or NULL).
  92. INT giType = FT_BITMAP;             // Type of object being edited currently.
  93. PIMAGEINFO gpImageHead = NULL;      // Head of image linked list.
  94. INT gnImages = 0;                   // Number of images in the file.
  95. BOOL fFileDirty;                    // TRUE if the file is dirty.
  96.  
  97. PIMAGEINFO gpImageCur = NULL;       // Pointer to current image.
  98. INT gcxImage;                       // Width of the image.
  99. INT gcyImage;                       // Height of the image.
  100. INT gnColors = 16;                  // Number of colors of current image.
  101. BOOL fImageDirty;                   // TRUE if the image is dirty.
  102.  
  103.  
  104. /*
  105.  * Drawing DC's and bitmaps ------------------------------------------------
  106.  */
  107.  
  108. HDC ghdcImage = NULL;               // Image XOR DC.
  109. HBITMAP ghbmImage = NULL;           // Image XOR bitmap.
  110.  
  111. HDC ghdcANDMask = NULL;             // Image AND mask DC.
  112. HBITMAP ghbmANDMask = NULL;         // Image AND mask bitmap.
  113.  
  114. HBITMAP ghbmUndo = NULL;            // Backup of XOR bitmap for undo.
  115. HBITMAP ghbmUndoMask = NULL;        // Backup of AND mask bitmap for undo.
  116.  
  117.  
  118. /*
  119.  * Globals for the color palette and drawing -------------------------------
  120.  */
  121.  
  122. INT giColorLeft;                    // Index to the left color in gargbCurrent.
  123. INT giColorRight;                   // Index to the right color in gargbCurrent.
  124. INT gfModeLeft;                     // Mode of the left color brush.
  125. INT gfModeRight;                    // Mode of the right color brush.
  126. HBRUSH ghbrLeft = NULL;             // Brush with left mouse button color.
  127. HBRUSH ghbrLeftSolid = NULL;        // Brush with solid left button color.
  128. HBRUSH ghbrRight = NULL;            // Brush with right mouse button color.
  129. HBRUSH ghbrRightSolid = NULL;       // Brush with solid right button color.
  130. HBRUSH ghbrScreen = NULL;           // Brush with screen color.
  131. HBRUSH ghbrInverse = NULL;          // Brush with inverse screen color.
  132. HPEN ghpenLeft = NULL;              // Left color pen.
  133. HPEN ghpenRight = NULL;             // Right color pen.
  134. DWORD grgbScreenDefault;            // Default screen color.
  135. DWORD grgbScreen;                   // RGB of screen color.
  136. DWORD grgbInverse;                  // RGB of inverse screen color.
  137. DWORD *gargbCurrent;                // Points to the current color table.
  138. DWORD gargbColor[COLORSMAX];        // Current color color table.
  139. DWORD gargbMono[COLORSMAX];         // Current monochrome color table.
  140. HPEN hpenDarkGray = NULL;           // A dark gray pen.
  141.  
  142. DRAWPROC gpfnDrawProc;              // Current drawing functions.
  143. INT gCurTool = -1;                  // Current tool (TOOL_* define).
  144. HBRUSH ghbrDraw = NULL;             // Current drawing brush.
  145. HBRUSH ghbrDrawSolid = NULL;        // Current solid drawing brush.
  146. HPEN ghpenDraw = NULL;              // Current drawing pen.
  147. INT gfDrawMode;                     // Mode of current drawing brush.
  148.  
  149. /*
  150.  * The default color palette.
  151.  */
  152. DWORD gargbDefaultColor[] = {
  153.     RGB(255, 255, 255), RGB(0, 0, 0),
  154.     RGB(192, 192, 192), RGB(128, 128, 128),
  155.     RGB(255, 0, 0),     RGB(128, 0, 0),
  156.     RGB(255, 255, 0),   RGB(128, 128, 0),
  157.     RGB(0, 255, 0),     RGB(0, 128, 0),
  158.     RGB(0, 255, 255),   RGB(0, 128, 128),
  159.     RGB(0, 0, 255),     RGB(0, 0, 128),
  160.     RGB(255, 0, 255),   RGB(128, 0, 128),
  161.     RGB(255, 255, 128), RGB(128, 128, 64),
  162.     RGB(0, 255, 128),   RGB(0, 64, 64),
  163.     RGB(128, 255, 255), RGB(0, 128, 255),
  164.     RGB(128, 128, 255), RGB(0, 64, 128),
  165.     RGB(255, 0, 128),   RGB(64, 0, 128),
  166.     RGB(255, 128, 64),  RGB(128, 64, 0)
  167. };
  168.  
  169. /*
  170.  * The default monochrome palette.
  171.  */
  172. DWORD gargbDefaultMono[] =   {
  173.     RGB(255, 255, 255), RGB(0, 0, 0),
  174.     RGB(128, 128, 128), RGB(9, 9, 9),
  175.     RGB(137, 137, 137), RGB(18, 18, 18),
  176.     RGB(146, 146, 146), RGB(27, 27, 27),
  177.     RGB(155, 155, 155), RGB(37, 37, 37),
  178.     RGB(164, 164, 164), RGB(46, 46, 46),
  179.     RGB(173, 173, 173), RGB(55, 55, 55),
  180.     RGB(182, 182, 182), RGB(63, 63, 63),
  181.     RGB(191, 191, 191), RGB(73, 73, 73),
  182.     RGB(201, 201, 201), RGB(82, 82, 82),
  183.     RGB(212, 212, 212), RGB(92, 92, 92),
  184.     RGB(222, 222, 222), RGB(101, 101, 101),
  185.     RGB(231, 231, 231), RGB(110, 110, 110),
  186.     RGB(245, 245, 245), RGB(119, 119, 119)
  187. };
  188.  
  189. /*
  190.  * Color table for monochrome DIB's.
  191.  */
  192. DWORD gargbColorTable2[] = {
  193.     RGB(0, 0, 0),
  194.     RGB(255, 255, 255)
  195. };
  196.  
  197. /*
  198.  * Array that describes each tool used in the editor.  This table
  199.  * is indexed by the TOOL_* defines.
  200.  */
  201. TOOLS gaTools[] = {
  202.     { PencilDP,     NULL,   IDBM_TUPENCIL,  NULL,   IDBM_TDPENCIL,  NULL,
  203.         TRUE, FALSE },
  204.     { BrushDP,      NULL,   IDBM_TUBRUSH,   NULL,   IDBM_TDBRUSH,   NULL,
  205.         TRUE, FALSE },
  206.     { PickDP,       NULL,   IDBM_TUSELECT,  NULL,   IDBM_TDSELECT,  NULL,
  207.         FALSE, FALSE },
  208.     { LineDP,       NULL,   IDBM_TULINE,    NULL,   IDBM_TDLINE,    NULL,
  209.         FALSE, TRUE },
  210.     { RectDP,       NULL,   IDBM_TURECT,    NULL,   IDBM_TDRECT,    NULL,
  211.         FALSE, TRUE },
  212.     { RectDP,       NULL,   IDBM_TUSRECT,   NULL,   IDBM_TDSRECT,   NULL,
  213.         FALSE, TRUE },
  214.     { CircleDP,     NULL,   IDBM_TUCIRCLE,  NULL,   IDBM_TDCIRCLE,  NULL,
  215.         FALSE, TRUE },
  216.     { CircleDP,     NULL,   IDBM_TUSCIRCL,  NULL,   IDBM_TDSCIRCL,  NULL,
  217.         FALSE, TRUE },
  218.     { FloodDP,      NULL,   IDBM_TUFLOOD,   NULL,   IDBM_TDFLOOD,   NULL,
  219.         TRUE, FALSE },
  220.     { HotSpotDP,    NULL,   IDBM_TUHOTSPT,  NULL,   IDBM_TDHOTSPT,  NULL,
  221.         FALSE, FALSE }
  222. };
  223.  
  224.  
  225. /*
  226.  * Globals and tables for messages and help --------------------------------
  227.  */
  228.  
  229. /*
  230.  * Message box messages, for the Message() function.
  231.  */
  232. MESSAGEDATA gamdMessages[] = {
  233.     { IDS_OUTOFMEMORY,          MB_OK | MB_ICONHAND                 },
  234.     { IDS_MEMERROR,             MB_OK | MB_ICONHAND                 },
  235.     { IDS_BADBMPFILE,           MB_OK | MB_ICONEXCLAMATION          },
  236.     { IDS_BADICOCURFILE,        MB_OK | MB_ICONEXCLAMATION          },
  237.     { IDS_BADPALFILE,           MB_OK | MB_ICONEXCLAMATION          },
  238.     { IDS_CANTOPEN,             MB_OK | MB_ICONEXCLAMATION          },
  239.     { IDS_READERROR,            MB_OK | MB_ICONEXCLAMATION          },
  240.     { IDS_WRITEERROR,           MB_OK | MB_ICONEXCLAMATION          },
  241.     { IDS_CANTCREATE,           MB_OK | MB_ICONEXCLAMATION          },
  242.     { IDS_NOCLIPBOARDFORMAT,    MB_OK | MB_ICONEXCLAMATION          },
  243.     { IDS_NOCLIPBOARD,          MB_OK | MB_ICONEXCLAMATION          },
  244.     { IDS_CANTEDITIMAGE,        MB_OK | MB_ICONEXCLAMATION          },
  245.     { IDS_SAVEFILE,             MB_YESNOCANCEL | MB_ICONEXCLAMATION },
  246.     { IDS_ENTERANUMBER,         MB_OK | MB_ICONEXCLAMATION          },
  247.     { IDS_BADDEVICESIZE,        MB_OK | MB_ICONEXCLAMATION          },
  248.     { IDS_BADDEVICECOLORS,      MB_OK | MB_ICONEXCLAMATION          },
  249.     { IDS_NOTSUPPORT,           MB_OK | MB_ICONEXCLAMATION          },
  250.     { IDS_NOIMAGES,             MB_OK | MB_ICONEXCLAMATION          },
  251.     { IDS_BADBMPSIZE,           MB_OK | MB_ICONEXCLAMATION          }
  252. };
  253.  
  254. INT gidCurrentDlg = 0;              // Current dialog id (null if none).
  255. INT gMenuSelected = 0;              // Currently selected menu item.
  256. CHAR gszHelpFile[CCHMAXPATH];       // Path to the help file.
  257. HHOOK ghhkMsgFilter;                // Hook handle for message filter func.
  258. FARPROC lpfnMsgFilterHookFunc;      // The message filter proc instance.
  259.  
  260. /*
  261.  * Table that maps menu items to help context id's for them.
  262.  */
  263. HELPMAP gahmapMenu[] = {
  264.     {MENU_FILE_NEW,             HELPID_FILE_NEW                 },
  265.     {MENU_FILE_OPEN,            HELPID_FILE_OPEN                },
  266.     {MENU_FILE_SAVE,            HELPID_FILE_SAVE                },
  267.     {MENU_FILE_SAVEAS,          HELPID_FILE_SAVEAS              },
  268.     {MENU_FILE_LOADCOLORS,      HELPID_FILE_LOADCOLORS          },
  269.     {MENU_FILE_SAVECOLORS,      HELPID_FILE_SAVECOLORS          },
  270.     {MENU_FILE_DEFAULTCOLORS,   HELPID_FILE_DEFAULTCOLORS       },
  271.     {MENU_FILE_EXIT,            HELPID_FILE_EXIT                },
  272.  
  273.     {MENU_EDIT_UNDO,            HELPID_EDIT_UNDO                },
  274.     {MENU_EDIT_RESTORE,         HELPID_EDIT_RESTORE             },
  275.     {MENU_EDIT_COPY,            HELPID_EDIT_COPY                },
  276.     {MENU_EDIT_PASTE,           HELPID_EDIT_PASTE               },
  277.     {MENU_EDIT_CLEAR,           HELPID_EDIT_CLEAR               },
  278.     {MENU_EDIT_NEWIMAGE,        HELPID_EDIT_NEWIMAGE            },
  279.     {MENU_EDIT_SELECTIMAGE,     HELPID_EDIT_SELECTIMAGE         },
  280.     {MENU_EDIT_DELETEIMAGE,     HELPID_EDIT_DELETEIMAGE         },
  281.  
  282.     {MENU_OPTIONS_GRID,         HELPID_OPTIONS_GRID             },
  283.     {MENU_OPTIONS_BRUSH2,       HELPID_OPTIONS_BRUSH2           },
  284.     {MENU_OPTIONS_BRUSH3,       HELPID_OPTIONS_BRUSH3           },
  285.     {MENU_OPTIONS_BRUSH4,       HELPID_OPTIONS_BRUSH4           },
  286.     {MENU_OPTIONS_BRUSH5,       HELPID_OPTIONS_BRUSH5           },
  287.     {MENU_OPTIONS_SHOWCOLOR,    HELPID_OPTIONS_SHOWCOLOR        },
  288.     {MENU_OPTIONS_SHOWVIEW,     HELPID_OPTIONS_SHOWVIEW         },
  289.     {MENU_OPTIONS_SHOWTOOLBOX,  HELPID_OPTIONS_SHOWTOOLBOX      },
  290.  
  291.     {MENU_HELP_CONTENTS,        HELPID_HELP_CONTENTS            },
  292.     {MENU_HELP_SEARCH,          HELPID_HELP_SEARCH              },
  293.     // No help for the About menu command.
  294.  
  295.     {0,                         0                               }
  296. };
  297.  
  298. /*
  299.  * Table that maps dialog ids to help context id's for them.
  300.  */
  301. HELPMAP gahmapDialog[] = {
  302.     // No help for the About dialog.
  303.     {DID_BITMAPSIZE,            HELPID_BITMAPSIZE               },
  304.     {DID_PASTEOPTIONS,          HELPID_PASTEOPTIONS             },
  305.     {DID_NEWCURSORIMAGE,        HELPID_NEWCURSORIMAGE           },
  306.     {DID_NEWICONIMAGE,          HELPID_NEWICONIMAGE             },
  307.     {DID_SELECTCURSORIMAGE,     HELPID_SELECTCURSORIMAGE        },
  308.     {DID_SELECTICONIMAGE,       HELPID_SELECTICONIMAGE          },
  309.     {DID_RESOURCETYPE,          HELPID_RESOURCETYPE             },
  310.  
  311.     {DID_COMMONFILEOPEN,        HELPID_COMMONFILEOPEN           },
  312.     {DID_COMMONFILESAVE,        HELPID_COMMONFILESAVE           },
  313.     {DID_COMMONFILEOPENPAL,     HELPID_COMMONFILEOPENPAL        },
  314.     {DID_COMMONFILESAVEPAL,     HELPID_COMMONFILESAVEPAL        },
  315.     {DID_COMMONFILECHOOSECOLOR, HELPID_COMMONFILECHOOSECOLOR    },
  316.  
  317.     {DID_TOOLBOX,               HELPID_TOOLBOX                  },
  318.     {DID_PROPBAR,               HELPID_PROPERTIESBAR            },
  319.     {DID_COLOR,                 HELPID_COLORPALETTE             },
  320.     {DID_VIEW,                  HELPID_VIEW                     },
  321.  
  322.     {0,                         0                               }
  323. };
  324.  
  325.  
  326. /*
  327.  * Misc. globals -----------------------------------------------------------
  328.  */
  329.  
  330. INT gcxWorkSpace;                   // Width of workspace window.
  331. INT gcyWorkSpace;                   // Height of workspace window.
  332. INT gZoomFactor;                    // Magnification factor of image.
  333.  
  334. RECT grcPick;                       // The current picking rectangle.
  335. INT gcxPick;                        // Width of picking rectangle.
  336. INT gcyPick;                        // Height of picking rectangle.
  337.  
  338. UINT ClipboardFormat;               // ID of private clipboard format.
  339. BOOL fStretchClipboardData = TRUE;  // TRUE to default to stretch on paste.
  340.  
  341. INT iNewFileType;                   // New file type the user selected.
  342.  
  343. INT gcyBorder;                      // System border height.
  344. INT gcyPropBar;                     // Height of PropBar window.
  345.  
  346. WNDPROC lpfnPropBarDlgProc = NULL;  // Proc inst. of PropBar dialog proc.
  347. WNDPROC lpfnColorDlgProc = NULL;    // Proc inst. of Color palette dlg proc.
  348.