home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / popmenu.c_ / popmenu.bin
Text File  |  1995-11-14  |  9KB  |  271 lines

  1. /**********************************************************************
  2.  *
  3.  * File :     popmenu.c
  4.  *
  5.  * Abstract : The implementation of some functions which handle the
  6.  *            pop-up right mouse button menus used by the viewer.
  7.  *
  8.  *            This application had been written to be compatible with
  9.  *            both the fixed and floating-point versions of the
  10.  *            RenderWare library, i.e., it uses the macros CREAL,
  11.  *            INT2REAL, RAdd, RDiv, RSub etc. If your application is
  12.  *            intended for the floating-point version of the library
  13.  *            only these macros are not necessary.
  14.  *
  15.  *            Please note that this application is intended for
  16.  *            demonstration purposes only. No support will be
  17.  *            provided for this code and it comes with no warranty.
  18.  *
  19.  **********************************************************************
  20.  *
  21.  * This file is a product of Criterion Software Ltd.
  22.  *
  23.  * This file is provided as is with no warranties of any kind and is
  24.  * provided without any obligation on Criterion Software Ltd. or
  25.  * Canon Inc. to assist in its use or modification.
  26.  *
  27.  * Criterion Software Ltd. will not, under any
  28.  * circumstances, be liable for any lost revenue or other damages arising
  29.  * from the use of this file.
  30.  *
  31.  * Copyright (c) 1994, 1995 Criterion Software Ltd.
  32.  * All Rights Reserved.
  33.  *
  34.  * RenderWare is a trademark of Canon Inc.
  35.  *
  36.  **********************************************************************/
  37.  
  38. /**********************************************************************
  39.  *
  40.  * Header files.
  41.  *
  42.  **********************************************************************/
  43.  
  44. #include <windows.h>
  45. #include <string.h>
  46.  
  47. #include <rwlib.h>
  48. #include <rwwin.h>
  49.  
  50. #include "resource.h"
  51. #include "common.h"
  52. #include "popmenu.h"
  53.  
  54. /**********************************************************************
  55.  *
  56.  * Exported Data.
  57.  *
  58.  **********************************************************************/
  59.  
  60. HMENU LightMenu      = (HMENU)0;
  61. HMENU ClumpMenu      = (HMENU)0;
  62. HMENU BackgroundMenu = (HMENU)0;
  63.  
  64. /**********************************************************************
  65.  *
  66.  * Functions.
  67.  *
  68.  **********************************************************************/
  69.  
  70. /**********************************************************************/
  71.  
  72. BOOL
  73. CreatePopupMenus(void)
  74. {
  75.     BOOL status;
  76.     
  77.     LightMenu = CreatePopupMenu();
  78.     if (LightMenu == (HMENU)0)
  79.         return FALSE;
  80.     
  81.     status = AppendMenu(LightMenu, MF_DISABLED | MF_OWNERDRAW,
  82.                         IDM_LIGHTPOPUP_LABEL, "");
  83.     status = status && AppendMenu(LightMenu, MF_ENABLED,
  84.                                   IDM_LIGHTPOPUP_MOVETO, "&Move To");
  85.     status = status && AppendMenu(LightMenu, MF_ENABLED,
  86.                                   IDM_LIGHTPOPUP_LOOKAT, "&Look At");
  87.     status = status && AppendMenu(LightMenu, MF_SEPARATOR,
  88.                                   0, NULL);
  89.     status = status && AppendMenu(LightMenu, MF_ENABLED,
  90.                                   IDM_LIGHTPOPUP_DUPLICATE, "Du&plicate");
  91.     status = status && AppendMenu(LightMenu, MF_ENABLED,
  92.                                   IDM_LIGHTPOPUP_DELETE, "&Delete");
  93.     status = status && AppendMenu(LightMenu, MF_SEPARATOR,
  94.                                   0, NULL);
  95.     status = status && AppendMenu(LightMenu, MF_ENABLED,
  96.                                   IDM_LIGHTPOPUP_PROPERTIES, "P&roperties...");
  97.     
  98.     if (!status)
  99.     {
  100.         DestroyMenu(LightMenu);
  101.         LightMenu = (HMENU)0;
  102.         return FALSE;
  103.     }
  104.  
  105.     ClumpMenu = CreatePopupMenu();
  106.     if (ClumpMenu == (HMENU)0)
  107.     {
  108.         DestroyMenu(LightMenu);
  109.         LightMenu = (HMENU)0;
  110.         return FALSE;
  111.     }
  112.     
  113.     status = AppendMenu(ClumpMenu, MF_DISABLED | MF_OWNERDRAW,
  114.                         IDM_CLUMPPOPUP_LABEL, "");
  115.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  116.                                   IDM_CLUMPPOPUP_RESET, "Re&set");
  117.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  118.                                   IDM_CLUMPPOPUP_MOVETO, "&Move To");
  119.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  120.                                   IDM_CLUMPPOPUP_LOOKAT, "&Look At");
  121.     status = status && AppendMenu(ClumpMenu, MF_SEPARATOR,
  122.                                   0, NULL);
  123.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  124.                                   IDM_CLUMPPOPUP_DUPLICATE, "Du&plicate");
  125.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  126.                                   IDM_CLUMPPOPUP_DELETE, "&Delete");
  127.     status = status && AppendMenu(ClumpMenu, MF_SEPARATOR,
  128.                                   0, NULL);
  129.     status = status && AppendMenu(ClumpMenu, MF_ENABLED,
  130.                                   IDM_CLUMPPOPUP_PROPERTIES, "P&roperties...");
  131.  
  132.     if (!status)
  133.     {
  134.         DestroyMenu(ClumpMenu);
  135.         ClumpMenu = (HMENU)0;
  136.         DestroyMenu(LightMenu);
  137.         LightMenu = (HMENU)0;
  138.         return FALSE;
  139.     }
  140.     
  141.     BackgroundMenu = CreatePopupMenu();
  142.     if (BackgroundMenu == (HMENU)0)
  143.     {
  144.         DestroyMenu(ClumpMenu);
  145.         ClumpMenu = (HMENU)0;
  146.         DestroyMenu(LightMenu);
  147.         LightMenu = (HMENU)0;
  148.         return FALSE;
  149.     }
  150.     
  151.     status = AppendMenu(BackgroundMenu, MF_DISABLED | MF_OWNERDRAW,
  152.                         IDM_BACKGROUNDPOPUP_LABEL, "");
  153.     status = status && AppendMenu(BackgroundMenu, MF_ENABLED,
  154.                                   IDM_BACKGROUNDPOPUP_COLOR, "&Color");
  155.     status = status && AppendMenu(BackgroundMenu, MF_ENABLED,
  156.                                   IDM_BACKGROUNDPOPUP_DELETE, "&Delete");
  157.  
  158.     if (!status)
  159.     {
  160.         DestroyMenu(BackgroundMenu);
  161.         BackgroundMenu = (HMENU)0;
  162.         DestroyMenu(ClumpMenu);
  163.         ClumpMenu = (HMENU)0;
  164.         DestroyMenu(LightMenu);
  165.         LightMenu = (HMENU)0;
  166.         return FALSE;
  167.     }
  168.     
  169.     return TRUE;
  170. }
  171.  
  172. /**********************************************************************/
  173.  
  174. void
  175. DestroyPopupMenus(void)
  176. {
  177.     if (LightMenu != (HMENU)0)
  178.     {
  179.         DestroyMenu(LightMenu);
  180.         LightMenu = (HMENU)0;
  181.     }
  182.     if (ClumpMenu != (HMENU)0)
  183.     {
  184.         DestroyMenu(ClumpMenu);
  185.         ClumpMenu = (HMENU)0;
  186.     }
  187.     if (BackgroundMenu != (HMENU)0)
  188.     {
  189.         DestroyMenu(BackgroundMenu);
  190.         BackgroundMenu = (HMENU)0;
  191.     }
  192. }
  193.  
  194. /**********************************************************************/
  195.  
  196. void
  197. MeasurePopupMenuLabel(HDC dc, char *label, SIZE *size)
  198. {
  199.     int len;
  200.     
  201.     /*
  202.      * Get the text of this menu item.
  203.      */
  204.     len = strlen(label);
  205.     
  206.     /*
  207.      * Get the extent of the menu item text.
  208.      */
  209.     GetTextExtentPoint(dc, label, len, size);
  210.     
  211.     /*
  212.      * Add a bit of horizontal space.
  213.      */
  214.     size->cx += 10;
  215.     
  216.     /*
  217.      * We want the height to be the same as a window caption.
  218.      */
  219.     size->cy = GetSystemMetrics(SM_CYCAPTION);
  220. }
  221.  
  222. /**********************************************************************/
  223.  
  224. void
  225. DrawPopupMenuLabel(HDC dc, RECT *rect, char *label)
  226. {
  227.     int      len;
  228.     HPEN     pen;
  229.     HPEN     oldPen;
  230.     HBRUSH   brush;
  231.     HBRUSH   oldBrush;
  232.     SIZE     size;
  233.     int      oldMode;
  234.     COLORREF oldColor;
  235.     int      x;
  236.     int      y;
  237.     
  238.     /*
  239.      * Get the text of this menu item.
  240.      */
  241.     len = strlen(label);
  242.  
  243.     /*
  244.      * Background of the label is the same color as an active window's
  245.      * caption.
  246.      */
  247.     pen      = GetStockObject(NULL_PEN);
  248.     oldPen   = SelectObject(dc, pen);
  249.     brush    = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));
  250.     oldBrush = SelectObject(dc, brush);
  251.     Rectangle(dc, rect->left, rect->top, rect->right + 1, rect->bottom + 1);
  252.     SelectObject(dc, oldBrush);
  253.     DeleteObject(brush);
  254.     SelectObject(dc, oldPen);
  255.     
  256.     /*
  257.      * Center the label string in the supplied rectangle (and make it the
  258.      * same color as a window's caption text).
  259.      */             
  260.     oldMode  = SetBkMode(dc, TRANSPARENT);
  261.     oldColor = SetTextColor(dc, GetSysColor(COLOR_CAPTIONTEXT));
  262.     GetTextExtentPoint(dc, label, len, &size);
  263.     x = rect->left + ((rect->right  - rect->left) - size.cx) / 2;
  264.     y = rect->top  + ((rect->bottom - rect->top)  - size.cy) / 2;
  265.     TextOut(dc, x, y, label, len);
  266.     SetTextColor(dc, oldColor);
  267.     SetBkMode(dc, oldMode);
  268. }
  269.  
  270. /**********************************************************************/
  271.