home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn 3D Graphics Programming on the PC
/
Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso
/
rwwin
/
xopmenu.c_
/
xopmenu.bin
Wrap
Text File
|
1995-11-14
|
9KB
|
271 lines
/**********************************************************************
*
* File : popmenu.c
*
* Abstract : The implementation of some functions which handle the
* pop-up right mouse button menus used by the viewer.
*
* This application had been written to be compatible with
* both the fixed and floating-point versions of the
* RenderWare library, i.e., it uses the macros CREAL,
* INT2REAL, RAdd, RDiv, RSub etc. If your application is
* intended for the floating-point version of the library
* only these macros are not necessary.
*
* Please note that this application is intended for
* demonstration purposes only. No support will be
* provided for this code and it comes with no warranty.
*
**********************************************************************
*
* This file is a product of Criterion Software Ltd.
*
* This file is provided as is with no warranties of any kind and is
* provided without any obligation on Criterion Software Ltd. or
* Canon Inc. to assist in its use or modification.
*
* Criterion Software Ltd. will not, under any
* circumstances, be liable for any lost revenue or other damages arising
* from the use of this file.
*
* Copyright (c) 1994, 1995 Criterion Software Ltd.
* All Rights Reserved.
*
* RenderWare is a trademark of Canon Inc.
*
**********************************************************************/
/**********************************************************************
*
* Header files.
*
**********************************************************************/
#include <windows.h>
#include <string.h>
#include <rwlib.h>
#include <rwwin.h>
#include "resource.h"
#include "common.h"
#include "popmenu.h"
/**********************************************************************
*
* Exported Data.
*
**********************************************************************/
HMENU LightMenu = (HMENU)0;
HMENU ClumpMenu = (HMENU)0;
HMENU BackgroundMenu = (HMENU)0;
/**********************************************************************
*
* Functions.
*
**********************************************************************/
/**********************************************************************/
BOOL
CreatePopupMenus(void)
{
BOOL status;
LightMenu = CreatePopupMenu();
if (LightMenu == (HMENU)0)
return FALSE;
status = AppendMenu(LightMenu, MF_DISABLED | MF_OWNERDRAW,
IDM_LIGHTPOPUP_LABEL, "");
status = status && AppendMenu(LightMenu, MF_ENABLED,
IDM_LIGHTPOPUP_MOVETO, "&Move To");
status = status && AppendMenu(LightMenu, MF_ENABLED,
IDM_LIGHTPOPUP_LOOKAT, "&Look At");
status = status && AppendMenu(LightMenu, MF_SEPARATOR,
0, NULL);
status = status && AppendMenu(LightMenu, MF_ENABLED,
IDM_LIGHTPOPUP_DUPLICATE, "Du&plicate");
status = status && AppendMenu(LightMenu, MF_ENABLED,
IDM_LIGHTPOPUP_DELETE, "&Delete");
status = status && AppendMenu(LightMenu, MF_SEPARATOR,
0, NULL);
status = status && AppendMenu(LightMenu, MF_ENABLED,
IDM_LIGHTPOPUP_PROPERTIES, "P&roperties...");
if (!status)
{
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
return FALSE;
}
ClumpMenu = CreatePopupMenu();
if (ClumpMenu == (HMENU)0)
{
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
return FALSE;
}
status = AppendMenu(ClumpMenu, MF_DISABLED | MF_OWNERDRAW,
IDM_CLUMPPOPUP_LABEL, "");
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_RESET, "Re&set");
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_MOVETO, "&Move To");
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_LOOKAT, "&Look At");
status = status && AppendMenu(ClumpMenu, MF_SEPARATOR,
0, NULL);
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_DUPLICATE, "Du&plicate");
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_DELETE, "&Delete");
status = status && AppendMenu(ClumpMenu, MF_SEPARATOR,
0, NULL);
status = status && AppendMenu(ClumpMenu, MF_ENABLED,
IDM_CLUMPPOPUP_PROPERTIES, "P&roperties...");
if (!status)
{
DestroyMenu(ClumpMenu);
ClumpMenu = (HMENU)0;
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
return FALSE;
}
BackgroundMenu = CreatePopupMenu();
if (BackgroundMenu == (HMENU)0)
{
DestroyMenu(ClumpMenu);
ClumpMenu = (HMENU)0;
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
return FALSE;
}
status = AppendMenu(BackgroundMenu, MF_DISABLED | MF_OWNERDRAW,
IDM_BACKGROUNDPOPUP_LABEL, "");
status = status && AppendMenu(BackgroundMenu, MF_ENABLED,
IDM_BACKGROUNDPOPUP_COLOR, "&Color");
status = status && AppendMenu(BackgroundMenu, MF_ENABLED,
IDM_BACKGROUNDPOPUP_DELETE, "&Delete");
if (!status)
{
DestroyMenu(BackgroundMenu);
BackgroundMenu = (HMENU)0;
DestroyMenu(ClumpMenu);
ClumpMenu = (HMENU)0;
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
return FALSE;
}
return TRUE;
}
/**********************************************************************/
void
DestroyPopupMenus(void)
{
if (LightMenu != (HMENU)0)
{
DestroyMenu(LightMenu);
LightMenu = (HMENU)0;
}
if (ClumpMenu != (HMENU)0)
{
DestroyMenu(ClumpMenu);
ClumpMenu = (HMENU)0;
}
if (BackgroundMenu != (HMENU)0)
{
DestroyMenu(BackgroundMenu);
BackgroundMenu = (HMENU)0;
}
}
/**********************************************************************/
void
MeasurePopupMenuLabel(HDC dc, char *label, SIZE *size)
{
int len;
/*
* Get the text of this menu item.
*/
len = strlen(label);
/*
* Get the extent of the menu item text.
*/
GetTextExtentPoint(dc, label, len, size);
/*
* Add a bit of horizontal space.
*/
size->cx += 10;
/*
* We want the height to be the same as a window caption.
*/
size->cy = GetSystemMetrics(SM_CYCAPTION);
}
/**********************************************************************/
void
DrawPopupMenuLabel(HDC dc, RECT *rect, char *label)
{
int len;
HPEN pen;
HPEN oldPen;
HBRUSH brush;
HBRUSH oldBrush;
SIZE size;
int oldMode;
COLORREF oldColor;
int x;
int y;
/*
* Get the text of this menu item.
*/
len = strlen(label);
/*
* Background of the label is the same color as an active window's
* caption.
*/
pen = GetStockObject(NULL_PEN);
oldPen = SelectObject(dc, pen);
brush = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));
oldBrush = SelectObject(dc, brush);
Rectangle(dc, rect->left, rect->top, rect->right + 1, rect->bottom + 1);
SelectObject(dc, oldBrush);
DeleteObject(brush);
SelectObject(dc, oldPen);
/*
* Center the label string in the supplied rectangle (and make it the
* same color as a window's caption text).
*/
oldMode = SetBkMode(dc, TRANSPARENT);
oldColor = SetTextColor(dc, GetSysColor(COLOR_CAPTIONTEXT));
GetTextExtentPoint(dc, label, len, &size);
x = rect->left + ((rect->right - rect->left) - size.cx) / 2;
y = rect->top + ((rect->bottom - rect->top) - size.cy) / 2;
TextOut(dc, x, y, label, len);
SetTextColor(dc, oldColor);
SetBkMode(dc, oldMode);
}
/**********************************************************************/