UIpane.c 2.48 KB

#include <ultratypes.h>

#include "gfx.h"
#include "UI.h"
#include "UIpane.h"
#include "cursor.h"


void    DefPaneDrawProc (UIPane *pPane, Gfx **ppGfx);
void    DefItemDrawProc (UIItem *pPane, Gfx **ppGfx);
char    DefHandleEventProc (UIPane *pPane, UIEvent *pEvent);


void
Pane_Init (UIPane *pPane)
{
    /* Initialize the pane's fields. */
    pPane->numItems = 0;
    pPane->pData = NULL;
    
    /* Setup the pane with default procs. */
    pPane->DrawProc = DefPaneDrawProc;
    pPane->HandleEventProc = DefHandleEventProc;
}


char
Pane_ItemClicked (UIPane *pPane, Point *pPt, UIItem **ppItem)
{
    UIItem *    pItem;
    Rect        globalRect;
    int         i;
    
    for (i=0; i<pPane->numItems; i++)
    {
        pItem = &pPane->itemList[i];

	globalRect = pItem->bounds;
        OffsetRect (&globalRect, pItem->pPane->bounds.left, pItem->pPane->bounds.top);

        if (PointInRect (&globalRect, pPt))
        {
            *ppItem = pItem;
            return TRUE;
        }
    
    }

    *ppItem = NULL;
    return FALSE;
}


char
Pane_GetSelectedItem (UIPane *pPane, UIItem **ppItem)
{
    int		i;
    char	foundSelectedItem = FALSE;

    *ppItem = NULL;	/* safety's sake */

    for (i=0; i<pPane->numItems; i++)
    {
	if (pPane->itemList[i].fIsSelected)
	{
	    *ppItem = &pPane->itemList[i];
	    foundSelectedItem = TRUE;
	    break;
	}
    }

    return foundSelectedItem;
}


void
Pane_DeselectAllItems (UIPane *pPane)
{
    int		i;

    for (i=0; i<pPane->numItems; i++)
	pPane->itemList[i].fIsSelected = FALSE;

}


/*
 *
 * UI Item routines
 *
 */
void
Item_Init (UIItem *pItem, int id)
{
    pItem->id = id;
    pItem->pPane = NULL;
    pItem->fIsClicked = FALSE;
    pItem->fIsSelected = FALSE;
    pItem->pSpriteIcon = NULL;
    
    pItem->DrawProc = DefItemDrawProc;
}

void
Item_GetScreenBounds (UIItem *pItem, Rect *pRect)
{
    *pRect = pItem->bounds;
    OffsetRect (pRect, pItem->pPane->bounds.left, pItem->pPane->bounds.top);
}


void
Item_SetSelected (UIItem *pItem, char isSelected)
{
    pItem->fIsSelected = isSelected;
}


char
Item_IsSelected (UIItem *pItem)
{
    return pItem->fIsSelected;
}


/*
  
  DEFAULT UI PROCS

*/

void
DefPaneDrawProc (UIPane *pPane, Gfx **ppGfx)
{
    DrawBeveledRect (&pPane->bounds, FALSE, FALSE, ppGfx);
}


void
DefItemDrawProc (UIItem *pItem, Gfx **ppGfx)
{
    Rect boundsRect;

    Item_GetScreenBounds (pItem, &boundsRect);
    DrawBeveledRect (&boundsRect, FALSE, FALSE, ppGfx);
}


char
DefHandleEventProc (UIPane *pPane, UIEvent *pEvent)
{}