home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
372.lha
/
PopUpMenu_3.2
/
Source
/
Select.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-06
|
5KB
|
187 lines
#include "PopUpMenu.h"
/***************************************
* SelectItem() - check mouseposition. *
* *
* Input: *
* none *
* Output: *
* none *
***************************************/
VOID SelectItem()
{
IMPORT struct WindowData MenuWindow, ItemWindow, SubWindow;
IMPORT struct MenuItem *CurrentSubItem, *CurrentItem, *TempItem;
IMPORT struct Menu *CurrentMenuPtr;
IMPORT UWORD CurrentMenuNr;
IMPORT const UWORD MenuFontSize;
IMPORT const WORD MouseY;
IMPORT struct RastPort Rp;
/********************
* Check subwindow. *
********************/
if (SubWindow.BitMapOk) {
struct MenuItem *const NewSubItem = FindMouseItem(&SubWindow);
if (NewSubItem != CurrentSubItem) {
if (CurrentSubItem)
HighLightItem(CurrentSubItem,&SubWindow,HIGHLIGHTOFF);
else
if (TempItem) {
CurrentItem = TempItem;
TempItem = NULL;
HighLightCurrItemBehind(HIGHLIGHTON);
}
if ((CurrentSubItem = NewSubItem) != NULL)
HighLightItem(NewSubItem,&SubWindow,HIGHLIGHTON);
else {
HighLightCurrItemBehind(HIGHLIGHTOFF);
TempItem = CurrentItem;
CurrentItem = NULL;
}
}
if (MouseInWindow(&SubWindow))
return;
}
/*********************
* Check itemwindow. *
*********************/
if (ItemWindow.BitMapOk) {
if (MouseInWindow(&ItemWindow)) {
struct MenuItem *const NewItem = FindMouseItem(&ItemWindow);
if (NewItem != CurrentItem) {
if (SubWindow.BitMapOk) {
CloseItemWindow(&SubWindow);
TempItem = NULL;
}
if (CurrentItem)
HighLightItem(CurrentItem,&ItemWindow,HIGHLIGHTOFF);
if ((CurrentItem = NewItem) != NULL) {
HighLightItem(NewItem,&ItemWindow,HIGHLIGHTON);
if ((NewItem->Flags & ITEMENABLED) AND
((SubWindow.Items = NewItem->SubItem) != NULL))
OpenItemWindow(&SubWindow,&ItemWindow,
(WORD)(CurrentItem->TopEdge - ItemWindow.TopValue),
SUBWINDOW);
}
}
return;
}
else /* mouse not in itemwindow */
if (CurrentItem) {
if (SubWindow.BitMapOk) {
HighLightCurrItemBehind(HIGHLIGHTOFF);
TempItem = CurrentItem;
}
else
HighLightItem(CurrentItem,&ItemWindow,HIGHLIGHTOFF);
CurrentItem = NULL;
}
}
/*********************
* Check menuwindow. *
*********************/
if (MouseInWindow(&MenuWindow)) {
const UWORD NewMenuNr = (MouseY - MenuWindow.TopEdge - BORDERSIZE)/MenuFontSize + 1;
if (NewMenuNr != CurrentMenuNr) {
if (CurrentMenuNr) {
if (ItemWindow.BitMapOk) {
CloseItemWindow(&SubWindow);
CloseItemWindow(&ItemWindow);
TempItem = NULL;
}
ToggleMenu(CurrentMenuNr,CurrentMenuPtr); /* HIGHLIGHTOFF */
}
if ((CurrentMenuPtr = FindMenuPtr(NewMenuNr)) == NULL)
CurrentMenuNr = 0;
else {
ToggleMenu(CurrentMenuNr = NewMenuNr,CurrentMenuPtr); /* HIGHLIGHTON */
if ((CurrentMenuPtr->Flags & MENUENABLED) AND
((ItemWindow.Items = CurrentMenuPtr->FirstItem) != NULL))
OpenItemWindow(&ItemWindow,&MenuWindow,
(WORD)((CurrentMenuNr - 1) * MenuFontSize + MenuWindow.TopEdge),
ITEMWINDOW);
}
}
}
return;
}
/***************************************************
* MouseInWindow(Window) - Is mouse inside window. *
* *
* Input: *
* Window - Window to check. *
* Output: *
* return - TRUE if mouse inside. *
***************************************************/
BOOL MouseInWindow(Window)
const struct WindowData *const Window;
{
IMPORT const WORD MouseX, MouseY;
return ((MouseX > Window->LeftEdge) AND
(MouseX < Window->RightEdge) AND
(MouseY > Window->TopEdge) AND
(MouseY < Window->Bottom));
}
/****************************************************************
* FindMouseItem(ItemWindow) - Check if mouse inside an item. *
* *
* Input: *
* ItemWindow - Window with items *
* Output: *
* return - Pointer to item under the mousepointer (or NULL). *
****************************************************************/
struct MenuItem *FindMouseItem(ItemWindow)
const struct WindowData *const ItemWindow;
{
IMPORT const WORD MouseX,MouseY;
const WORD MouseWinX = MouseX + ItemWindow->LeftValue;
const WORD MouseWinY = MouseY + ItemWindow->TopValue;
struct MenuItem *Item = ItemWindow->Items;
do
if ((MouseWinY >= Item->TopEdge) AND
(MouseWinY <= Item->TopEdge + Item->Height) AND
(MouseWinX >= Item->LeftEdge) AND
(MouseWinX <= Item->LeftEdge + Item->Width))
return (Item);
while ((Item = Item->NextItem) != NULL);
return (NULL);
}
/*********************************************************
* HighLightCurrItemBehind(Mode) - Highlight currentitem *
* behind subwindow. *
* Input: *
* Mode - HIGHLIGHTON or HIGHLIGHTOFF. *
* Output: *
* none *
*********************************************************/
VOID HighLightCurrItemBehind(Mode)
UWORD const Mode;
{
IMPORT struct WindowData ItemWindow,SubWindow;
IMPORT struct RastPort Rp;
IMPORT struct MenuItem *const CurrentItem;
SwapBits(&SubWindow);
HighLightItem(CurrentItem,&ItemWindow,Mode);
SwapBits(&SubWindow);
}