mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-23 03:49:26 +01:00
Fixed the menu (although it's untested). Allow assigning to B
This commit is contained in:
parent
6b627c2d68
commit
2e1a340675
4
Makefile
4
Makefile
@ -58,10 +58,10 @@ export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
#---------------------------------------------------------------------------------
|
||||
# automatically build a list of object files for our project
|
||||
#---------------------------------------------------------------------------------
|
||||
CFILES := menu.c char_to_kc.c
|
||||
CFILES := char_to_kc.c
|
||||
CPPFILES := Display.cpp main.cpp Prefs.cpp SID.cpp REU.cpp IEC.cpp 1541fs.cpp \
|
||||
1541d64.cpp 1541t64.cpp 1541job.o SAM.cpp C64.cpp CPUC64.cpp VIC.cpp \
|
||||
CIA.cpp CPU1541.cpp
|
||||
CIA.cpp CPU1541.cpp menu.cpp bitmap-font.cpp
|
||||
sFILES :=
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
#if defined(HAVE_SDL)
|
||||
/* SDL menu */
|
||||
#include "bitmap-font.h"
|
||||
#include "menu.h"
|
||||
#include <SDL_ttf.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BEOS__
|
||||
@ -146,7 +146,7 @@ private:
|
||||
|
||||
#ifdef GEKKO
|
||||
double speed_index;
|
||||
int joystick_key_binding[4]; /* A, Plus, Minus, 1 */
|
||||
int joystick_key_binding[5]; /* A, B, Plus, Minus, 1 */
|
||||
#endif
|
||||
|
||||
#ifdef __unix
|
||||
@ -156,7 +156,7 @@ public:
|
||||
#endif
|
||||
#ifdef HAVE_SDL
|
||||
menu_t main_menu;
|
||||
TTF_Font *menu_font;
|
||||
Font *menu_font;
|
||||
const char *base_dir;
|
||||
|
||||
bool fake_key_sequence;
|
||||
@ -166,6 +166,9 @@ public:
|
||||
|
||||
void select_disc();
|
||||
void bind_key();
|
||||
void display_options();
|
||||
|
||||
int display_type;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "bitmap-font.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@ -16,11 +17,11 @@
|
||||
|
||||
static struct timeval tv_start;
|
||||
static char *main_menu_messages[] = {
|
||||
"Insert disc/tape", /* 0 */
|
||||
"Load disc/tape", /* 1 */
|
||||
"Insert disc or tape", /* 0 */
|
||||
"Load disc or tape", /* 1 */
|
||||
"Reset C64", /* 2 */
|
||||
"Bind key to joystick",/* 3 */
|
||||
"Joystick port (kbd)", /* 4 */
|
||||
"Display options", /* 4 */
|
||||
"^|1|2",
|
||||
"Swap joysticks", /* 6 */
|
||||
" ",
|
||||
@ -28,18 +29,22 @@ static char *main_menu_messages[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
static char *bind_key_messages[] = {
|
||||
"Bind to A", /* 0 */
|
||||
"Bind to Plus", /* 1 */
|
||||
"Bind to Minus", /* 2 */
|
||||
"Bind to 1", /* 3 */
|
||||
static char *display_option_messages[] = {
|
||||
"1-1 resolution", /* 0 */
|
||||
"double resolution, centered", /* 1 */
|
||||
"full-screen stretched", /* 2 */
|
||||
NULL,
|
||||
};
|
||||
|
||||
static char *bind_key_messages[] = {
|
||||
"Bind to A", /* 0 */
|
||||
"Bind to B", /* 1 */
|
||||
"Bind to Plus", /* 2 */
|
||||
"Bind to Minus", /* 3 */
|
||||
"Bind to 1", /* 4 */
|
||||
NULL,
|
||||
};
|
||||
|
||||
#define FONT_PATH "FreeMono.ttf"
|
||||
#if defined(GEKKO)
|
||||
#define FONT_PATH "/apps/frodo/FreeMono.ttf"
|
||||
#endif
|
||||
/*
|
||||
* Constructor, system-dependent things
|
||||
*/
|
||||
@ -63,22 +68,7 @@ void C64::c64_ctor1(void)
|
||||
this->fake_key_keytime = 5;
|
||||
this->fake_key_type = 0;
|
||||
|
||||
FILE *f = fopen(FONT_PATH, "r");
|
||||
if (!f)
|
||||
fprintf(stderr, "Cannot open %s\n", FONT_PATH);
|
||||
else {
|
||||
fprintf(stderr, "Could open %s!!!\n", FONT_PATH);
|
||||
fclose(f);
|
||||
}
|
||||
f = fopen("/FreeMono.ttf", "r");
|
||||
if (!f)
|
||||
fprintf(stderr, "Cannot open %s\n", "/Free...");
|
||||
else {
|
||||
fprintf(stderr, "Could open %s!!!\n", "/Free...");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
this->menu_font = TTF_OpenFont(FONT_PATH, 20);
|
||||
this->menu_font = new Font("/apps/frodo/fonts.png");
|
||||
if (!this->menu_font)
|
||||
{
|
||||
fprintf(stderr, "Unable to open font: %s\n", TTF_GetError() );
|
||||
@ -215,6 +205,18 @@ void C64::bind_key()
|
||||
menu_fini(&key_menu);
|
||||
}
|
||||
|
||||
void C64::display_options()
|
||||
{
|
||||
menu_t display_menu;
|
||||
|
||||
menu_init(&display_menu, this->menu_font, display_option_messages,
|
||||
0, 0, DISPLAY_X, DISPLAY_Y);
|
||||
int opt = menu_select(screen, &display_menu, ~0, NULL);
|
||||
if (opt >= 0)
|
||||
this->display_type = opt;
|
||||
menu_fini(&display_menu);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start main emulation thread
|
||||
*/
|
||||
@ -372,31 +374,22 @@ uint8 C64::poll_joystick(int port)
|
||||
if (held & WPAD_BUTTON_2)
|
||||
j &= 0xef; // Button
|
||||
if (held & WPAD_BUTTON_HOME)
|
||||
exit(1);
|
||||
//this->enter_menu();
|
||||
this->enter_menu();
|
||||
|
||||
if (held & WPAD_BUTTON_A) {
|
||||
Prefs *np = Frodo::reload_prefs();
|
||||
strncpy(np->DrivePath[0], "/apps/frodo/images/spy_vs_spy.d64", 255);
|
||||
np->DriveType[0] = DRVTYPE_D64;
|
||||
np->LimitSpeed = true;
|
||||
NewPrefs(np);
|
||||
ThePrefs = *np;
|
||||
|
||||
this->fake_key_sequence = true;
|
||||
}
|
||||
//this->enter_menu();
|
||||
if ( (held & WPAD_BUTTON_A) && this->joystick_key_binding[0])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[0],
|
||||
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
|
||||
if ( (held & WPAD_BUTTON_PLUS) && this->joystick_key_binding[1])
|
||||
if ( (held & WPAD_BUTTON_B) && this->joystick_key_binding[1])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[1],
|
||||
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
|
||||
if ( (held & WPAD_BUTTON_MINUS) && this->joystick_key_binding[2])
|
||||
if ( (held & WPAD_BUTTON_PLUS) && this->joystick_key_binding[2])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[2],
|
||||
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
|
||||
if ( (held & WPAD_BUTTON_1) && this->joystick_key_binding[1])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[1],
|
||||
if ( (held & WPAD_BUTTON_MINUS) && this->joystick_key_binding[3])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[3],
|
||||
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
|
||||
if ( (held & WPAD_BUTTON_1) && this->joystick_key_binding[4])
|
||||
TheDisplay->FakeKeyPress(this->joystick_key_binding[4],
|
||||
false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL);
|
||||
|
||||
|
||||
@ -516,7 +509,8 @@ void C64::thread_func(void)
|
||||
case 3: /* Bind keys to joystick */
|
||||
this->bind_key();
|
||||
break;
|
||||
case 4: /* Joystick port */
|
||||
case 4: /* Display options */
|
||||
this->display_options();
|
||||
break;
|
||||
case 6: /* Swap joysticks */
|
||||
{
|
||||
|
658
Src/bitmap-font.cpp
Normal file
658
Src/bitmap-font.cpp
Normal file
@ -0,0 +1,658 @@
|
||||
#include <SDL_image.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include "bitmap-font.h"
|
||||
|
||||
Font::Font(std::string src_file)
|
||||
{
|
||||
m_pFontList = SDL_DisplayFormatAlpha(IMG_Load(src_file.c_str()));
|
||||
}
|
||||
|
||||
Font::~Font(void)
|
||||
{
|
||||
}
|
||||
|
||||
int Font::ShowText(std::string text, int type, int pos_x, int pos_y, SDL_Surface* pScreen)
|
||||
{
|
||||
/* TODO: We need to calculate the fonts height into the pos_y thing. */
|
||||
// Also, id like to see this stuff gathered from an ini file.
|
||||
// That way we can alter fonts without the need for recompilcation
|
||||
|
||||
if(!pScreen) return 1;
|
||||
|
||||
SDL_Rect rect, src_rect; // src_rect is the location of the character we need to fetch. rect will be the destenation
|
||||
rect.x = pos_x;
|
||||
rect.y = pos_y;
|
||||
SDL_Rect tmp_rect;
|
||||
|
||||
for(int i=0; i < text.size(); i++) {
|
||||
|
||||
tmp_rect.y = 39*type; // set right y axe
|
||||
|
||||
switch(text[i]) {
|
||||
case 0x20:
|
||||
rect.x += 10;
|
||||
break;
|
||||
case 0x21: // !
|
||||
tmp_rect.x = 4;
|
||||
tmp_rect.w = 6;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x2D: // -
|
||||
tmp_rect.x = 184;
|
||||
tmp_rect.w = 8;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x30: // 0
|
||||
tmp_rect.x = 226;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x31: // 1
|
||||
tmp_rect.x = 244;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x32: // 2
|
||||
tmp_rect.x = 256;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x33: // 3
|
||||
tmp_rect.x = 272;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x34: // 4
|
||||
tmp_rect.x = 286;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x35: // 5
|
||||
tmp_rect.x = 302;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x36: // 6
|
||||
tmp_rect.x = 317;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x37: // 7
|
||||
tmp_rect.x = 332;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x38: // 8
|
||||
tmp_rect.x = 347;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x39: // 9
|
||||
tmp_rect.x = 362;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3A: // :
|
||||
tmp_rect.x = 379;
|
||||
tmp_rect.w = 6;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3B: // ;
|
||||
tmp_rect.x = 394;
|
||||
tmp_rect.w = 5;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3C: // <
|
||||
tmp_rect.x = 407;
|
||||
tmp_rect.w = 8;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3D: // =
|
||||
tmp_rect.x = 424;
|
||||
tmp_rect.w = 8;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3E: // >
|
||||
tmp_rect.x = 440;
|
||||
tmp_rect.w = 8;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x3F: // ?
|
||||
tmp_rect.x = 454;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x40: // ?
|
||||
tmp_rect.x = 465;
|
||||
tmp_rect.w = 16;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x41: // A
|
||||
tmp_rect.x = 482;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x42: // B
|
||||
tmp_rect.x = 498;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x43: // C
|
||||
tmp_rect.x = 511;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x44: // D
|
||||
tmp_rect.x = 527;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x45: // E
|
||||
tmp_rect.x = 542;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x46: // F
|
||||
tmp_rect.x = 558;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x47: // G
|
||||
tmp_rect.x = 571;
|
||||
tmp_rect.w = 14;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x48: // H
|
||||
tmp_rect.x = 586;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x49: // I
|
||||
tmp_rect.x = 602;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4A: // J
|
||||
tmp_rect.x = 616;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4B: // K
|
||||
tmp_rect.x = 631;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4C: // L
|
||||
tmp_rect.x = 647;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4D: // M
|
||||
tmp_rect.x = 659;
|
||||
tmp_rect.w = 16;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4E: // N
|
||||
tmp_rect.x = 406;
|
||||
tmp_rect.w = 14;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x4F: // O
|
||||
tmp_rect.x = 675;
|
||||
tmp_rect.w = 15;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type; // <-- Here we fix that mistake :)
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x50: // P
|
||||
tmp_rect.x = 692;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x51: // Q
|
||||
tmp_rect.x = 705;
|
||||
tmp_rect.w = 14;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x52: // R
|
||||
tmp_rect.x = 722;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x53: // S
|
||||
tmp_rect.x = 736;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x54: // T
|
||||
tmp_rect.x = 751;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x55: // U
|
||||
tmp_rect.x = 766;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x56: // V
|
||||
tmp_rect.x = 782;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x57: // W
|
||||
tmp_rect.x = 795;
|
||||
tmp_rect.w = 15;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x58: // X
|
||||
tmp_rect.x = 811;
|
||||
tmp_rect.w = 13;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x59: // Y
|
||||
tmp_rect.x = 827;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5A: // Z
|
||||
tmp_rect.x = 841;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5B: // [
|
||||
tmp_rect.x = 858;
|
||||
tmp_rect.w = 8;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5C: // /
|
||||
tmp_rect.x = 873;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5D: // ]
|
||||
tmp_rect.x = 888;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5E: // ]
|
||||
tmp_rect.x = 903;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x5F: // _
|
||||
tmp_rect.x = 915;
|
||||
tmp_rect.w = 15;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x60: // `
|
||||
tmp_rect.x = 936;
|
||||
tmp_rect.w = 7;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x61: // a
|
||||
tmp_rect.x = 946;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x62: // b
|
||||
tmp_rect.x = 962;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x63: // c
|
||||
tmp_rect.x = 976;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x64: // d
|
||||
tmp_rect.x = 1;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x65: // e
|
||||
tmp_rect.x = 16;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x66: // f
|
||||
tmp_rect.x = 34;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x67: // g
|
||||
tmp_rect.x = 48;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x68: // h
|
||||
tmp_rect.x = 62;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x69: // i
|
||||
tmp_rect.x = 80;
|
||||
tmp_rect.w = 6;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6A: // j
|
||||
tmp_rect.x = 91;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6B: // k
|
||||
tmp_rect.x = 108;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6C: // l
|
||||
tmp_rect.x = 123;
|
||||
tmp_rect.w = 6;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6D: // m
|
||||
tmp_rect.x = 136;
|
||||
tmp_rect.w = 14;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6E: // n
|
||||
tmp_rect.x = 152;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x6F: // o
|
||||
tmp_rect.x = 167;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x70: // p
|
||||
tmp_rect.x = 182;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x71: // q
|
||||
tmp_rect.x = 197;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x72: // r
|
||||
tmp_rect.x = 212;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x73: // s
|
||||
tmp_rect.x = 229;
|
||||
tmp_rect.w = 9;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x74: // t
|
||||
tmp_rect.x = 242;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x75: // u
|
||||
tmp_rect.x = 258;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x76: // v
|
||||
tmp_rect.x = 272;
|
||||
tmp_rect.w = 10;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x77: // w
|
||||
tmp_rect.x = 285;
|
||||
tmp_rect.w = 14;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x78: // x
|
||||
tmp_rect.x = 301;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x79: // y
|
||||
tmp_rect.x = 318;
|
||||
tmp_rect.w = 12;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
case 0x7A: // z
|
||||
tmp_rect.x = 332;
|
||||
tmp_rect.w = 11;
|
||||
tmp_rect.h = 19;
|
||||
tmp_rect.y = 19 + 39*type;
|
||||
SDL_BlitSurface( m_pFontList, &tmp_rect, pScreen, &rect);
|
||||
rect.x += tmp_rect.w;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
28
Src/bitmap-font.h
Normal file
28
Src/bitmap-font.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef __FONT_H
|
||||
#define __FONT_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <SDL.h>
|
||||
|
||||
|
||||
class Font
|
||||
{
|
||||
SDL_Surface* m_pFontList;
|
||||
public:
|
||||
Font(std::string src_file);
|
||||
virtual ~Font(void);
|
||||
int ShowText(std::string text, int type, int pos_x, int pos_y, SDL_Surface* pScreen);
|
||||
|
||||
int GetHeight()
|
||||
{
|
||||
return 18;
|
||||
}
|
||||
|
||||
int GetWidth()
|
||||
{
|
||||
return 14;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -12,6 +12,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bitmap-font.h"
|
||||
|
||||
#if defined(GEKKO)
|
||||
# include <wiiuse/wpad.h>
|
||||
#endif
|
||||
@ -42,14 +44,11 @@ static submenu_t *find_submenu(menu_t *p_menu, int index)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
|
||||
static void print_font(SDL_Surface *screen, Font *font, int type,
|
||||
int x, int y, char *msg)
|
||||
{
|
||||
SDL_Surface *font_surf;
|
||||
SDL_Rect dst = {x, y, 0, 0};
|
||||
SDL_Color color = {r, g, b};
|
||||
char buf[255];
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, msg, 254);
|
||||
@ -61,17 +60,7 @@ static void print_font(SDL_Surface *screen, TTF_Font *font, int r, int g, int b,
|
||||
buf[i] = ' ';
|
||||
}
|
||||
|
||||
font_surf = TTF_RenderText_Solid(font, buf,
|
||||
color);
|
||||
if (!font_surf)
|
||||
{
|
||||
fprintf(stderr, "%s\n", TTF_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_BlitSurface(font_surf, NULL, screen, &dst);
|
||||
|
||||
SDL_FreeSurface(font_surf);
|
||||
font->ShowText(buf, type, x, y, screen);
|
||||
}
|
||||
|
||||
|
||||
@ -79,7 +68,7 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu)
|
||||
{
|
||||
int x_start = p_menu->x1 + (p_menu->x2 - p_menu->x1) / 2 - p_menu->text_w / 2;
|
||||
int y_start = p_menu->y1 + (p_menu->y2 - p_menu->y1) / 2 - p_menu->text_h / 2;
|
||||
int font_height = TTF_FontHeight(p_menu->p_font);
|
||||
int font_height = p_menu->p_font->GetHeight();
|
||||
int line_height = (font_height + font_height / 4);
|
||||
int cur_y = p_menu->cur_sel * line_height;
|
||||
int entries_visible = p_menu->y2 / line_height;
|
||||
@ -98,13 +87,13 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu)
|
||||
int y = (i - p_menu->start_entry_visible) * line_height;
|
||||
|
||||
if ((p_menu->available_options & (1<<i)) == 0) /* Gray (not available) */
|
||||
print_font(screen, p_menu->p_font, 128,128,128, x_start,
|
||||
print_font(screen, p_menu->p_font, 2, x_start,
|
||||
y_start + y, msg);
|
||||
else if (p_menu->cur_sel == i) /* Selected - color */
|
||||
print_font(screen, p_menu->p_font, 255,255,0, x_start,
|
||||
print_font(screen, p_menu->p_font, 3, x_start,
|
||||
y_start + y, msg);
|
||||
else /* Otherwise white */
|
||||
print_font(screen, p_menu->p_font, 255,255,255, x_start,
|
||||
print_font(screen, p_menu->p_font, 0, x_start,
|
||||
y_start + y, msg);
|
||||
if (IS_SUBMENU(msg))
|
||||
{
|
||||
@ -125,14 +114,8 @@ static void menu_draw(SDL_Surface *screen, menu_t *p_menu)
|
||||
if (p_submenu->sel == n_pipe-1)
|
||||
{
|
||||
SDL_Rect r;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
if (TTF_SizeText(p_menu->p_font, "X", &w, &h) < 0)
|
||||
{
|
||||
fprintf(stderr, "%s\n", TTF_GetError());
|
||||
exit(1);
|
||||
}
|
||||
int w = p_menu->p_font->GetWidth();
|
||||
int h = p_menu->p_font->GetHeight();
|
||||
|
||||
r = (SDL_Rect) { x_start + (n+1) * w-1,
|
||||
y_start + (i+1 - p_menu->start_entry_visible) * ((h + h/4)-1),
|
||||
@ -180,7 +163,7 @@ static int is_submenu_title(menu_t *p_menu, int n)
|
||||
}
|
||||
|
||||
|
||||
void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs,
|
||||
void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs,
|
||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||
{
|
||||
int i;
|
||||
@ -209,15 +192,11 @@ void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs,
|
||||
continue; /* Length of submenus is unimportant */
|
||||
}
|
||||
|
||||
if (TTF_SizeText(p_font, p_menu->pp_msgs[p_menu->n_entries], &text_w_font, NULL) != 0)
|
||||
{
|
||||
fprintf(stderr, "%s\n", TTF_GetError());
|
||||
exit(1);
|
||||
}
|
||||
text_w_font = p_menu->p_font->GetWidth();
|
||||
if (text_w_font > p_menu->text_w)
|
||||
p_menu->text_w = text_w_font;
|
||||
}
|
||||
if ( !(p_menu->p_submenus = malloc(sizeof(submenu_t) * p_menu->n_submenus)) )
|
||||
if ( !(p_menu->p_submenus = (submenu_t*)malloc(sizeof(submenu_t) * p_menu->n_submenus)) )
|
||||
{
|
||||
perror("malloc failed!\n");
|
||||
exit(1);
|
||||
@ -244,7 +223,7 @@ void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs,
|
||||
}
|
||||
}
|
||||
}
|
||||
p_menu->text_h = p_menu->n_entries * (TTF_FontHeight(p_font) + TTF_FontHeight(p_font) / 4);
|
||||
p_menu->text_h = p_menu->n_entries * (p_font->GetHeight() + p_font->GetHeight() / 4);
|
||||
}
|
||||
|
||||
void menu_fini(menu_t *p_menu)
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "bitmap-font.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@ -31,7 +32,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
char **pp_msgs;
|
||||
TTF_Font *p_font;
|
||||
Font *p_font;
|
||||
int x1,y1;
|
||||
int x2,y2;
|
||||
int text_w;
|
||||
@ -46,7 +47,7 @@ typedef struct
|
||||
int n_entries;
|
||||
} menu_t;
|
||||
|
||||
void menu_init(menu_t *p_menu, TTF_Font *p_font, char **pp_msgs,
|
||||
void menu_init(menu_t *p_menu, Font *p_font, char **pp_msgs,
|
||||
int16_t x1, int16_t y1, int16_t x2, int16_t y2);
|
||||
void menu_fini(menu_t *p_menu);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user