mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-26 05:24:21 +01:00
More fixes
This commit is contained in:
parent
d1315cde5a
commit
1d385c66f0
6
main.cpp
Normal file
6
main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "menu.hh"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
50
menu.cpp
50
menu.cpp
@ -752,44 +752,20 @@ const char *menu_select_file(const char *dir_path)
|
||||
32, 32, FULL_DISPLAY_X/2, FULL_DISPLAY_Y - 32);
|
||||
}
|
||||
|
||||
static TTF_Font *read_font(const char *path)
|
||||
Menu::Menu(TTF_Font *font, SDL_Color clr, int w, int h)
|
||||
{
|
||||
TTF_Font *out;
|
||||
SDL_RWops *rw;
|
||||
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
|
||||
FILE *fp = fopen(path, "r");
|
||||
this->text_color = clr;
|
||||
this->font = font;
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
if (!data) {
|
||||
fprintf(stderr, "Malloc failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Could not open font\n");
|
||||
exit(1);
|
||||
}
|
||||
fread(data, 1, 1 * 1024 * 1024, fp);
|
||||
rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
|
||||
if (!rw)
|
||||
{
|
||||
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
out = TTF_OpenFontRW(rw, 1, 20);
|
||||
if (!out)
|
||||
{
|
||||
fprintf(stderr, "Unable to open font %s\n", path);
|
||||
exit(1);
|
||||
}
|
||||
fclose(fp);
|
||||
this->pp_msgs = NULL;
|
||||
this->n_entries = 0;
|
||||
this->n_submenus = 0;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void menu_init()
|
||||
{
|
||||
Uint8 *data64 = (Uint8*)malloc(1 * 1024*1024);
|
||||
|
||||
menu_font = read_font(FONT_PATH);
|
||||
menu_font64 = read_font(FONT64_PATH);
|
||||
this->cur_sel = 0;
|
||||
this->hover_callback = NULL;
|
||||
this->selection_callback = NULL;
|
||||
this->mouse_x = -1;
|
||||
this->mouse_y = -1;
|
||||
}
|
||||
|
66
menu.hh
66
menu.hh
@ -15,48 +15,49 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <stdint.h>
|
||||
#include "sysdeps.h"
|
||||
#include "Network.h"
|
||||
|
||||
#define KEY_UP 1
|
||||
#define KEY_DOWN 2
|
||||
#define KEY_LEFT 4
|
||||
#define KEY_RIGHT 8
|
||||
#define KEY_SELECT 16
|
||||
#define KEY_ESCAPE 32
|
||||
#define KEY_PAGEDOWN 64
|
||||
#define KEY_PAGEUP 128
|
||||
#define KEY_HELP 256
|
||||
enum {
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_LEFT,
|
||||
KEY_RIGHT,
|
||||
KEY_SELECT,
|
||||
KEY_ESCAPE,
|
||||
KEY_PAGEDOWN,
|
||||
KEY_PAGEUP,
|
||||
KEY_HELP,
|
||||
};
|
||||
|
||||
class Menu
|
||||
{
|
||||
public:
|
||||
Menu(int x, int y, int w, int h);
|
||||
Menu(TTF_Font *font, SDL_Color clr, int w, int h);
|
||||
|
||||
void setTextColor(const SDL_Color clr);
|
||||
void setText(const char **messages);
|
||||
|
||||
void pushEvent(SDL_Event *ev);
|
||||
|
||||
void runLogic();
|
||||
|
||||
void draw(SDL_Surface *where);
|
||||
void draw(SDL_Surface *where,
|
||||
int x, int y);
|
||||
|
||||
~Menu();
|
||||
|
||||
private:
|
||||
const char *title;
|
||||
const char **pp_msgs;
|
||||
TTF_Font *p_font;
|
||||
TTF_Font *font;
|
||||
SDL_Color text_color;
|
||||
|
||||
int (*hover_callback)(Menu *me, int index);
|
||||
int (*selection_callback)(Menu *me, int index);
|
||||
|
||||
/* Start and end of the menu */
|
||||
int x1,y1;
|
||||
int x2,y2;
|
||||
int text_w;
|
||||
int text_h;
|
||||
/* Width and height */
|
||||
int w, h;
|
||||
|
||||
/* Relative to this menu */
|
||||
int mouse_x, mouse_y;
|
||||
|
||||
int n_submenus;
|
||||
submenu_t *p_submenus;
|
||||
@ -64,29 +65,8 @@ private:
|
||||
int cur_sel; /* Main selection */
|
||||
int start_entry_visible;
|
||||
int n_entries;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
void menu_print_font(SDL_Surface *screen, int r, int g, int b, int x, int y, const char *msg);
|
||||
void menu_print_font64(SDL_Surface *screen, int r, int g, int b, int x, int y, const char *msg);
|
||||
|
||||
/* Various option selects */
|
||||
int menu_select(const char *title, const char **pp_msgs, int *p_submenus);
|
||||
int menu_select(const char **pp_msgs, int *p_submenus);
|
||||
int menu_select_sized(char *title, const char **msgs, int *submenus,
|
||||
int x, int y, int w, int h);
|
||||
const char *menu_select_file(const char *dir_path);
|
||||
const char *menu_select_file_start(const char *dir_path, const char **d64_name);
|
||||
int menu_select_peer(NetworkUpdatePeerInfo *peers, int n_peers);
|
||||
|
||||
uint32_t menu_wait_key_press(void);
|
||||
|
||||
extern bool msgKill(SDL_Rect *rc);
|
||||
extern int msgInfo(char *text, int duration, SDL_Rect *rc);
|
||||
|
||||
extern bool msgYesNo(char *text, bool def,int x, int y);
|
||||
|
||||
|
||||
void menu_init();
|
||||
|
||||
#endif /* !__MENU_H__ */
|
||||
|
32
utils.cpp
Normal file
32
utils.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
TTF_Font *read_font(const char *path)
|
||||
{
|
||||
TTF_Font *out;
|
||||
SDL_RWops *rw;
|
||||
Uint8 *data = (Uint8*)malloc(1 * 1024*1024);
|
||||
FILE *fp = fopen(path, "r");
|
||||
|
||||
if (!data) {
|
||||
fprintf(stderr, "Malloc failed\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Could not open font\n");
|
||||
exit(1);
|
||||
}
|
||||
fread(data, 1, 1 * 1024 * 1024, fp);
|
||||
rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
|
||||
if (!rw)
|
||||
{
|
||||
fprintf(stderr, "Could not create RW: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
out = TTF_OpenFontRW(rw, 1, 20);
|
||||
if (!out)
|
||||
{
|
||||
fprintf(stderr, "Unable to open font %s\n", path);
|
||||
exit(1);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return out;
|
||||
}
|
Loading…
Reference in New Issue
Block a user