channelUI.c 6.4 KB
/*====================================================================
 * channelUI.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

/*========================*/

#include <ultra64.h>
#include <ultralog.h>
#include <os.h>

#include <assert.h>

#include "audio.h"
#include "channelUI.h"
#include "sequence.h"
#include "UIpane.h"
#include "font_ext.h"



static Channel      sChannel;

static void __ChlItemInit (UIItem *pItem, int id);

static void __ChlPaneDrawProc (UIPane *pPane, Gfx **ppGfx);
static void __ChlDrawValueBox (UIItem *pItem, Gfx **ppGfx);
static char __ChlHandleEventProc (UIPane *pPane, UIEvent *pEvent);

static char __ChlHandleMouseDown (UIPane *pPane, Point *pPt);
static char __ChlHandleMouseUp (UIPane *pPane, Point *pPt);
static char __ChlHandleButtonDown (UIPane *pPane, int button);


#define kNumValueBoxStr_bms		9

static Bitmap sValueBoxStrBM[kNumValueBoxStr_bms];

static Gfx sValueBoxStrDL[kNumValueBox][NUM_DL(kNumValueBoxStr_bms)];

static Sprite sValueBoxStrSprite =
{
        0,0,                		/* Position: x,y */
        0,0,                 		/* Sprite size in texels (x,y) */
        1.0,1.0,             		/* Sprite Scale: x,y */
        0,0,                 		/* Explosion (x,y) */
        SP_TRANSPARENT,      		/* Sprite Attributes */
        0x1234,              		/* Sprite Depth: Z */
        255,255,255,255,     		/* Sprite Coloration: RGBA */
        0,0,NULL,            		/* Color LookUp Table: start_index, length, address */
        0,1,                 		/* Sprite Bitmap index: start index, step increment */
        kNumValueBoxStr_bms,		/* Number of bitmaps */
        NUM_DL(kNumValueBoxStr_bms),	/* Number of display list locations allocated */
        15, 128,             		/* Sprite Bitmap Height: Used_height, physical height */
        G_IM_FMT_I,          		/* Sprite Bitmap Format */
        G_IM_SIZ_4b,         		/* Sprite Bitmap Texel Size */
        sValueBoxStrBM,      		/* Pointer to bitmaps */
        &sValueBoxStrDL[0][0],      	/* Display list memory */
        &sValueBoxStrDL[0][0],      	/* HACK: dynamic_dl pointer */
};


void
Chl_Init (UIPane **ppPane)
{
    UIItem      *pItem;
    int         i;
    
    /* Initialize the Channel object's pane. */
    sChannel.fPane.numItems = kNumChlItems;
    sChannel.fPane.itemList = sChannel.fItemList;
    sChannel.fPane.pData = &sChannel;
    sChannel.fPane.DrawProc = __ChlPaneDrawProc;
    sChannel.fPane.HandleEventProc = __ChlHandleEventProc;    
    SetRect (&sChannel.fPane.bounds, kChl_l, kChl_t, kChl_l + kChl_w, kChl_t + kChl_h);
    

    /* Initialize each of the channel's pane's items. */
    for (i=0; i<sChannel.fPane.numItems; i++)
    {
        pItem = &sChannel.fPane.itemList[i];

        __ChlItemInit (pItem, i);
    }

    
    /* Return the pane's address to the caller. */
    *ppPane = &sChannel.fPane;
}


static void
__ChlItemInit (UIItem *pItem, int id)
{
    Item_Init (pItem, id);
    
    pItem->pPane = &sChannel.fPane; 

    switch (id)
    {
      case kMasterVolItemID:
	  pItem->DrawProc = __ChlDrawValueBox;
	  SetRect (&pItem->bounds,
		   kMasterVolItem_l,
		   kMasterVolItem_t,
		   kMasterVolItem_l + kMasterVolItem_w,
		   kMasterVolItem_t + kMasterVolItem_h);
          break;
    }
}



/*

  Channel UI Procs

*/


static void
__ChlPaneDrawProc (UIPane *pPane, Gfx **ppGfx)
{
    UIItem *    pItem;
    int         i;
    
    /* Draw the Channel window. */
    DrawBeveledRect (&pPane->bounds, FALSE, FALSE, ppGfx);
    
    
    /* Draw the Channel pane's UI items. */
    for (i=0; i<pPane->numItems; i++)
    {
        pItem = &pPane->itemList[i];

        pItem->DrawProc (pItem, ppGfx);
    }
}



static void
__ChlDrawValueBox (UIItem *pItem, Gfx **ppGfx)
{
    Rect        boundsRect;
    s32		value;
    char	str[10];

    if (pItem->id == kMasterVolItemID)
    {
       value = Seq_GetVolume ();
       value >>= 8;
    }
    
    sprintf (str, "%d", value);

    /* Get the bounds for the value box. */
    Item_GetScreenBounds (pItem, &boundsRect);
    
    /* Assign unique storage for this item's sprite display list. */
    sValueBoxStrSprite.rsp_dl_next = &sValueBoxStrDL[pItem->id - kMasterVolItemID][0];
    
    /* Draw the value box. */
    font_set_font (kDigit6Font);		/* Use small digits to save space. */
    DrawValueStrBox (&boundsRect, str, Item_IsSelected (pItem), &sValueBoxStrSprite, ppGfx);
}


static char
__ChlHandleEventProc (UIPane *pPane, UIEvent *pEvent)
{
    char	isHandled = FALSE;

    switch (pEvent->type)
    {
      case kMouseDown:
          isHandled = __ChlHandleMouseDown (pPane, &pEvent->where);
          break;

      case kMouseUp:
          isHandled = __ChlHandleMouseUp (pPane, &pEvent->where);
          break;

      case kButtonDown:
          isHandled = __ChlHandleButtonDown (pPane, pEvent->what);
          break;
    }
}


static char
__ChlHandleMouseDown (UIPane *pPane, Point *pPt)
{
    UIItem *    pItem;
    char	isHandled = FALSE;
    
    Pane_DeselectAllItems (pPane);

    if (Pane_ItemClicked (pPane, pPt, &pItem))
    {
        assert(pItem != NULL);
        
	Item_SetSelected (pItem, TRUE);
	isHandled = TRUE;
    }

    isHandled = FALSE;
}


static char
__ChlHandleMouseUp (UIPane *pPane, Point *pPt)
{
    UIItem *    pItem;
    char	isHandled = FALSE;

    if (Pane_ItemClicked (pPane, pPt, &pItem))
    {
        assert(pItem != NULL);
	
	isHandled = TRUE;
    }
    
    return isHandled;
}


static char
__ChlHandleButtonDown (UIPane *pPane, int button)
{
    UIItem *	pItem;

    if ((button & CONT_UP) || (button & CONT_DOWN))
    {
	if (Pane_GetSelectedItem (pPane, &pItem))
	{
	    switch (pItem->id)
	    {
	    case kMasterVolItemID:
		Seq_AdjustVolume (button & CONT_UP);
		break;
	    }
	}
    }
    return TRUE;
}