Archived
1
0
Disbranĉigi 0
Ĉi tiu deponejo arĥiviĝis je 2024-01-29. Vi povas vidi kaj elŝuti dosierojn, sed ne povas puŝi nek raporti problemojn nek tirpeti.
efemmera/tests/test-menu.c

155 lines
3.7 KiB
C
Raw Normal View History

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,
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
// 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 )
{
int menucode = calcMenu( testMenu, SP_BUTTON_START, steps );
2020-05-31 02:49:08 -05:00
// no input? interpret keypress as our own
if ( menucode == CALCMENU_NOINPUT ) {
2020-05-31 01:19:16 -05:00
if ( spGetInput()->button[SP_BUTTON_SELECT] )
return -1;
return 0;
}
// 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 )
{
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 )
{
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];
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 )
{
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();
addSound("data/sound/tamborine.ogg");
addSound("data/sound/eeuh.ogg");
2020-05-31 01:19:16 -05:00
}
// ============================================================================
// CLEANUP
// ============================================================================
int
cleanup ( void )
{
cleanupFonts();
cleanupSounds();
2020-05-31 01:19:16 -05:00
spDeleteSurface( menuSurface );
spQuitCore();
}