Skip to content

Commit

Permalink
Hooked up splash loading code.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 24, 2007
1 parent 65f189e commit b7f033a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
27 changes: 24 additions & 3 deletions gui.h
Expand Up @@ -55,11 +55,31 @@ struct MojoGuiSetupOptions
};


typedef enum
{
MOJOGUI_SPLASH_NONE,
MOJOGUI_SPLASH_TOP,
MOJOGUI_SPLASH_LEFT,
MOJOGUI_SPLASH_RIGHT,
MOJOGUI_SPLASH_BOTTOM,
MOJOGUI_SPLASH_BACKGROUND,
} MojoGuiSplashPos;

typedef struct MojoGuiSplash MojoGuiSplash;
struct MojoGuiSplash
{
const uint8 *rgba; // framebuffer.
uint32 w; // width in pixels.
uint32 h; // height in pixels.
MojoGuiSplashPos position; // where to put the splash.
};


#define MOJOGUI_ENTRY_POINT MojoSetup_Gui_GetInterface
#define MOJOGUI_ENTRY_POINT_STR DEFINE_TO_STR(MOJOGUI_ENTRY_POINT)

// Increment this value when MojoGui's structure changes.
#define MOJOGUI_INTERFACE_REVISION 2
#define MOJOGUI_INTERFACE_REVISION 3

typedef struct MojoGui MojoGui;
struct MojoGui
Expand All @@ -71,7 +91,7 @@ struct MojoGui
void (*msgbox)(const char *title, const char *text);
boolean (*promptyn)(const char *title, const char *text, boolean def);
MojoGuiYNAN (*promptynan)(const char *title, const char *text, boolean def);
boolean (*start)(const char *title, const char *splash);
boolean (*start)(const char *title, const MojoGuiSplash *splash);
void (*stop)(void);
int (*readme)(const char *name, const uint8 *data, size_t len,
boolean can_back, boolean can_fwd);
Expand Down Expand Up @@ -113,7 +133,8 @@ static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2, \
boolean d); \
static MojoGuiYNAN MojoGui_##module##_promptynan(const char *t1, \
const char *t2, boolean d); \
static boolean MojoGui_##module##_start(const char *t, const char *s); \
static boolean MojoGui_##module##_start(const char *t, \
const MojoGuiSplash *splash); \
static void MojoGui_##module##_stop(void); \
static int MojoGui_##module##_readme(const char *name, const uint8 *data, \
size_t len, boolean can_back, \
Expand Down
3 changes: 2 additions & 1 deletion gui_gtkplus2.c
Expand Up @@ -459,7 +459,8 @@ GtkWidget *create_gtkwindow(const char *title)
} // create_gtkwindow


static boolean MojoGui_gtkplus2_start(const char *title, const char *splash)
static boolean MojoGui_gtkplus2_start(const char *title,
const MojoGuiSplash *splash)
{
gtkwindow = create_gtkwindow(title);
return (gtkwindow != NULL);
Expand Down
3 changes: 2 additions & 1 deletion gui_macosx.c
Expand Up @@ -146,7 +146,8 @@ static MojoGuiYNAN MojoGui_macosx_promptynan(const char *title,
} // MojoGui_macosx_promptynan


static boolean MojoGui_macosx_start(const char *title, const char *splash)
static boolean MojoGui_macosx_start(const char *title,
const MojoGuiSplash *splash)
{
return true; // !!! FIXME
} // MojoGui_macosx_start
Expand Down
3 changes: 2 additions & 1 deletion gui_ncurses.c
Expand Up @@ -699,7 +699,8 @@ static MojoGuiYNAN MojoGui_ncurses_promptynan(const char *title,
} // MojoGui_ncurses_promptynan


static boolean MojoGui_ncurses_start(const char *_title, const char *splash)
static boolean MojoGui_ncurses_start(const char *_title,
const MojoGuiSplash *splash)
{
free(title);
title = entry->xstrdup(_title);
Expand Down
3 changes: 2 additions & 1 deletion gui_stdio.c
Expand Up @@ -192,7 +192,8 @@ static MojoGuiYNAN MojoGui_stdio_promptynan(const char *title, const char *txt,
} // MojoGui_stdio_promptynan


static boolean MojoGui_stdio_start(const char *title, const char *splash)
static boolean MojoGui_stdio_start(const char *title,
const MojoGuiSplash *splash)
{
printf("%s\n", title);
return true;
Expand Down
3 changes: 2 additions & 1 deletion gui_www.c
Expand Up @@ -793,7 +793,8 @@ static MojoGuiYNAN MojoGui_www_promptynan(const char *title, const char *text,
} // MojoGui_www_promptynan


static boolean MojoGui_www_start(const char *title, const char *splash)
static boolean MojoGui_www_start(const char *title,
const MojoGuiSplash *splash)
{
return true;
} // MojoGui_www_start
Expand Down
44 changes: 42 additions & 2 deletions lua_glue.c
Expand Up @@ -947,11 +947,51 @@ static int luahook_movefile(lua_State *L)
} // luahook_movefile


static void prepareSplash(MojoGuiSplash *splash, const char *fname)
{
MojoInput *io = NULL;
int64 len = 0;

memset(splash, '\0', sizeof (*splash));

if (fname == NULL)
return;

io = MojoInput_newFromArchivePath(GBaseArchive, fname);
if (io == NULL)
return;

len = io->length(io);
if ((len > 0) && (len < 0xFFFFFFFF))
{
const uint32 size = (uint32) len;
uint8 *data = (uint8 *) xmalloc(size);
if (io->read(io, data, size) == len)
{
splash->rgba = decodeImage(data, size, &splash->w, &splash->h);
if (splash->rgba != NULL)
splash->position = MOJOGUI_SPLASH_TOP; // !!! FIXME: others?
} // if
free(data);
} // if

io->close(io);
} // prepareSplash


static int luahook_gui_start(lua_State *L)
{
const char *title = luaL_checkstring(L, 1);
const char *splash = lua_tostring(L, 2);
return retvalBoolean(L, GGui->start(title, splash));
const char *splashfname = lua_tostring(L, 2);
boolean rc = false;
MojoGuiSplash splash;

prepareSplash(&splash, splashfname);
rc = GGui->start(title, &splash);
if (splash.rgba != NULL)
free((void *) splash.rgba);

return retvalBoolean(L, rc);
} // luahook_gui_start


Expand Down

0 comments on commit b7f033a

Please sign in to comment.