2020-05-31 01:19:16 -05:00
|
|
|
#include <sparrow3d.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "../lib/font.h"
|
|
|
|
#include "../lib/sound.h"
|
|
|
|
#include "../lib/menu.h"
|
|
|
|
#include "test-menu.h"
|
|
|
|
|
|
|
|
SDL_Surface* screen = NULL;
|
|
|
|
SDL_Surface* menuSurface = NULL;
|
|
|
|
|
|
|
|
struct eMenu* testMenu;
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
int
|
|
|
|
main ( int argc, char **argv )
|
|
|
|
{
|
|
|
|
testMenu = malloc(sizeof(struct eMenu));
|
|
|
|
|
|
|
|
init();
|
|
|
|
int ret_code = spLoop( draw_test, calc_test, 10, resize, NULL );
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
if ( ret_code != -1 ) {
|
|
|
|
ret_code--;
|
|
|
|
struct eMenuElement* targetElement = testMenu->elements[ret_code];
|
|
|
|
printf("Here's the menu item you selected:\n");
|
|
|
|
printf("Index: %i\tText: %s\n", ret_code, targetElement->text);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// TEST
|
|
|
|
// ============================================================================
|
|
|
|
// draw this whole menu test (aka, simple background, text, and the testMenu.
|
|
|
|
void
|
|
|
|
draw_test ( void )
|
|
|
|
{
|
|
|
|
spClearTarget( spGetRGB(64,64,64) );
|
|
|
|
spSelectRenderTarget(spGetWindowSurface());
|
|
|
|
|
2020-06-07 21:58:36 -05:00
|
|
|
drawMenu ( testMenu );
|
2020-05-31 01:19:16 -05:00
|
|
|
spBlitSurface( spGetWindowSurface()->w/2, spGetWindowSurface()->h/2, 0,
|
|
|
|
testMenu->surface );
|
|
|
|
|
|
|
|
spFontDrawMiddle( spGetWindowSurface()->w/2,
|
2020-05-31 02:49:08 -05:00
|
|
|
spGetWindowSurface()->h
|
|
|
|
- fonts[FN_COZETTE]->maxheight * 2.5, 0,
|
|
|
|
"Press [S] to select", fonts[FN_COZETTE] );
|
2020-05-31 01:19:16 -05:00
|
|
|
spFontDrawMiddle( spGetWindowSurface()->w/2,
|
2020-06-02 22:56:43 -05:00
|
|
|
spGetWindowSurface()->h
|
2020-05-31 02:49:08 -05:00
|
|
|
- fonts[FN_COZETTE]->maxheight -2, 0,
|
|
|
|
"Press [E] to exit", fonts[FN_COZETTE] );
|
2020-05-31 01:19:16 -05:00
|
|
|
spFlip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// input for the menu test
|
2020-06-02 22:56:43 -05:00
|
|
|
// if non-zero return int, it's the index of the selected menu item + 1.
|
2020-05-31 01:19:16 -05:00
|
|
|
int
|
|
|
|
calc_test ( Uint32 steps )
|
|
|
|
{
|
2020-06-02 22:56:43 -05:00
|
|
|
int menucode = calcMenu( testMenu, SP_BUTTON_START, steps );
|
2020-05-31 02:49:08 -05:00
|
|
|
// no input? interpret keypress as our own
|
2020-06-02 22:56:43 -05:00
|
|
|
if ( menucode == CALCMENU_NOINPUT ) {
|
2020-05-31 01:19:16 -05:00
|
|
|
if ( spGetInput()->button[SP_BUTTON_SELECT] )
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2020-06-02 22:56:43 -05:00
|
|
|
}
|
|
|
|
// greater than _MOVED means it returned the inc'd menu selection index
|
2020-05-31 02:49:08 -05:00
|
|
|
if ( menucode > CALCMENU_MOVED )
|
2020-05-31 02:31:32 -05:00
|
|
|
spSleep(700000);
|
|
|
|
// sleep long enough after selection to play selection sound lol
|
2020-05-31 01:19:16 -05:00
|
|
|
return menucode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
resize ( Uint16 w, Uint16 h )
|
|
|
|
{
|
2020-06-02 22:56:43 -05:00
|
|
|
spSelectRenderTarget( spGetWindowSurface());
|
|
|
|
resizeFonts();
|
|
|
|
resizeMenu( testMenu );
|
2020-05-31 01:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// INIT
|
|
|
|
// ============================================================================
|
|
|
|
int
|
|
|
|
init ( void )
|
|
|
|
{
|
|
|
|
init_sparrow3d();
|
|
|
|
init_sounds();
|
|
|
|
init_fonts();
|
|
|
|
init_test_menu(testMenu);
|
|
|
|
resize( spGetWindowSurface()->w, spGetWindowSurface()->h );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_test_menu ( struct eMenu* menu )
|
|
|
|
{
|
2020-06-02 22:56:43 -05:00
|
|
|
initMenu( menu, "what do you do? <3",
|
|
|
|
&fonts[FN_LOVEMECHAIN], &fonts[FN_COZETTE],
|
|
|
|
spGetRGB(80,80,80), spGetRGB(35,71,107) );
|
2020-05-31 01:19:16 -05:00
|
|
|
menu->titleCentered = 0;
|
|
|
|
menu->textCentered = 0;
|
2020-05-31 02:49:08 -05:00
|
|
|
menu->moveSound = sounds[SF_TAMBORINE];
|
|
|
|
menu->selectSound = sounds[SF_EEUH];
|
2020-06-02 22:56:43 -05:00
|
|
|
addMenuElement(menu, "give up");
|
|
|
|
addMenuElement(menu, "run away");
|
|
|
|
addMenuElement(menu, "eat a baby");
|
|
|
|
addMenuElement(menu, "wave hello");
|
|
|
|
addMenuElement(menu, "hug a stranger until they blush");
|
|
|
|
addMenuElement(menu, "oh well");
|
2020-05-31 01:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_fonts ( void )
|
|
|
|
{
|
2020-06-02 22:56:43 -05:00
|
|
|
addFont("data/font/cozette-vector.ttf");
|
|
|
|
addFont("data/font/love_me_chain.ttf");
|
2020-05-31 01:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_sparrow3d ( void )
|
|
|
|
{
|
|
|
|
spSetDefaultWindowSize( 320, 240 );
|
|
|
|
spInitCore();
|
|
|
|
spCreateDefaultWindow();
|
|
|
|
spSetZSet(0);
|
|
|
|
spSetZTest(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
init_sounds ( void )
|
|
|
|
{
|
|
|
|
spSoundInit();
|
2020-06-02 22:56:43 -05:00
|
|
|
addSound("data/sound/tamborine.ogg");
|
|
|
|
addSound("data/sound/eeuh.ogg");
|
2020-05-31 01:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// CLEANUP
|
|
|
|
// ============================================================================
|
|
|
|
int
|
|
|
|
cleanup ( void )
|
|
|
|
{
|
2020-06-02 22:56:43 -05:00
|
|
|
cleanupFonts();
|
|
|
|
cleanupSounds();
|
2020-05-31 01:19:16 -05:00
|
|
|
spDeleteSurface( menuSurface );
|
|
|
|
spQuitCore();
|
|
|
|
}
|