listpage.c 4.48 KB
/*
 * This is the handler for the list page. It takes controller input
 * and provides Sprites as output and also a return value which says
 * what the next page should be.
 */
#include <ultra64.h>
#include "uimain.h"
#include "font.h"

/*
 * XXX Some test stuff
 */
static int xpos = 10;
static int ypos = 100;

#define NUM_BMS        (24*40)
static Bitmap textBoxBmp[NUM_BMS];
static Gfx textBoxDl[NUM_DL(NUM_BMS)];

extern Font tvfont;

static Bitmap pBmp[1];
static Gfx pDl[NUM_DL(1)];
static Sprite letterP = {0, 0, 0, 0, 1.0, 1.0, 0, 0, 
                         SP_TRANSPARENT, 0, 255, 255, 255, 255,
                         0, 0, NULL, 0, 1, 1, NUM_DL(NUM_BMS), 
                         15, 128, G_IM_FMT_I, G_IM_SIZ_4b,
                         pBmp, pDl, NULL};
static Bitmap lBmp[1];
static Gfx lDl[NUM_DL(1)];
static Sprite letterL = {0, 0, 0, 0, 1.0, 1.0, 0, 0, 
                         SP_TRANSPARENT, 0, 255, 255, 255, 255,
                         0, 0, NULL, 0, 1, 1, NUM_DL(NUM_BMS), 
                         15, 128, G_IM_FMT_I, G_IM_SIZ_4b,
                         lBmp, lDl, NULL};
static Bitmap aBmp[1];
static Gfx aDl[NUM_DL(1)];
static Sprite letterA = {0, 0, 0, 0, 1.0, 1.0, 0, 0, 
                         SP_TRANSPARENT, 0, 255, 255, 255, 255,
                         0, 0, NULL, 0, 1, 1, NUM_DL(NUM_BMS), 
                         15, 128, G_IM_FMT_I, G_IM_SIZ_4b,
                         aBmp, aDl, NULL};
static Bitmap yBmp[1];
static Gfx yDl[NUM_DL(1)];
static Sprite letterY = {0, 0, 0, 0, 1.0, 1.0, 0, 0, 
                         SP_TRANSPARENT, 0, 255, 255, 255, 255,
                         0, 0, NULL, 0, 1, 1, NUM_DL(NUM_BMS), 
                         15, 128, G_IM_FMT_I, G_IM_SIZ_4b,
                         yBmp, yDl, NULL};

static Sprite listLine0;
static Sprite listLine1;
static Sprite listLine2;
static Sprite listLine3;

static int localTimer = 0;

static Sprite textBox = {
        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 */
        NUM_BMS,                /* Number of bitmaps */
        NUM_DL(NUM_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 */
        textBoxBmp,             /* Pointer to bitmaps */
        textBoxDl,              /* Display list memory */
        NULL,                   /* HACK: dynamic_dl pointer */
};

/*
 * Called once - can be used to init sprites, so we don't have to write 
 * letters every time
 */
int listInit()
{

    drawString("p", &tvfont, 1, 1, &letterP);
    spScale(&letterP, 2.0, 2.0);
    spColor(&letterP, 255, 0, 0, 255);
    drawString("l", &tvfont, 1, 1, &letterL);
    spScale(&letterL, 2.0, 2.0);
    spColor(&letterL, 0, 0, 255, 255);
    drawString("a", &tvfont, 1, 1, &letterA);
    spScale(&letterA, 2.0, 2.0);
    spColor(&letterA, 255, 255, 0, 255);
    drawString("y", &tvfont, 1, 1, &letterY);
    spScale(&letterY, 2.0, 2.0);
    spColor(&letterY, 255, 255, 255, 255);

    drawString("(B) Back", &tvfont, 9, 1, &textBox);
    spColor(&textBox, 0, 255, 255, 255);
    spMove(&textBox, 30, 210);
    return 0;
}

/*
 * Called every frame with controller event
 */
int listPage(u16 cntrl, Sprite **sp)
{
    int shift;
    int a;
    int myTime;
    /*
     * Counts frames for time
     */
    localTimer++;
    localTimer = localTimer % 120;
    if (localTimer > 60) {
	myTime = 120 - localTimer;
    } else {
        myTime = localTimer;
    }

    shift = myTime - 30;
    a = shift / 4;

    spMove(&letterP, 100, 40);
    sp[0] = &letterP;
    spMove(&letterL, 120, 40 + a - shift);
    sp[1] = &letterL;
    spMove(&letterA, 140, 40 + a - shift);
    sp[2] = &letterA;
    spMove(&letterY, 160, 40);
    sp[3] = &letterY;

    sp[4] = &textBox;

    sp[5] = 0;

    if (cntrl & CONT_B) {
        return 0;
    } else {
        /*
         * Come back to current page
         */
        return 1;
    }

}