Skip to content

Commit

Permalink
Happy September. Allow installers to specify a splash position in the…
Browse files Browse the repository at this point in the history
… GUI.
  • Loading branch information
icculus committed Sep 22, 2009
1 parent 54fa56d commit 5d4a04d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs.txt
Expand Up @@ -165,6 +165,8 @@ Here are the elements, and the attributes they can possess.
mustBeUrl: Error if isn't a string that matches the regexp "^.+://.-/.*".
mustBePerms: Error if isn't a valid permissions string for the platform.
mustBeStringOrTableOfStrings: Error if isn't a string or an array of strings.
mustBeSplashPosition: Error if isn't a string in the set of "top",
"left", "bottom", "right", or "background".

Attributes that aren't explicitly specified take on their default value. In
cases without a default, they are effectively set to Lua's "nil" value.
Expand Down Expand Up @@ -326,6 +328,14 @@ Here are the elements, and the attributes they can possess.
used for the file.


splashpos (no default, mustBeSplashPosition)

This is the location of the splash image that will be used in the GUI.
Please note that not all GUIs can show graphics, or handle the position
requested, but this makes a best effort. If you specify a splash and no
position, the GUI is free to place it wherever it thinks is best.


url (no default, mustBeString, cantBeEmpty)

(!!! FIXME) This attribute is for future expansion.
Expand Down
31 changes: 27 additions & 4 deletions lua_glue.c
Expand Up @@ -1129,7 +1129,8 @@ static int luahook_movefile(lua_State *L)
} // luahook_movefile


static void prepareSplash(MojoGuiSplash *splash, const char *fname)
static void prepareSplash(MojoGuiSplash *splash, const char *fname,
const char *splashpos)
{
MojoInput *io = NULL;
int64 len = 0;
Expand All @@ -1152,8 +1153,29 @@ static void prepareSplash(MojoGuiSplash *splash, const char *fname)
{
splash->rgba = decodeImage(data, size, &splash->w, &splash->h);
if (splash->rgba != NULL)
splash->position = (splash->w >= splash->h) ?
MOJOGUI_SPLASH_TOP : MOJOGUI_SPLASH_LEFT; // !!! FIXME: others?
{
const uint32 w = splash->w;
const uint32 h = splash->h;
const MojoGuiSplashPos defpos =
((w >= h) ? MOJOGUI_SPLASH_TOP : MOJOGUI_SPLASH_LEFT);

if (splashpos == NULL)
splash->position = defpos;
else if ((splashpos == NULL) && (splash->w < splash->h))
splash->position = MOJOGUI_SPLASH_LEFT;
else if (strcmp(splashpos, "top") == 0)
splash->position = MOJOGUI_SPLASH_TOP;
else if (strcmp(splashpos, "left") == 0)
splash->position = MOJOGUI_SPLASH_LEFT;
else if (strcmp(splashpos, "bottom") == 0)
splash->position = MOJOGUI_SPLASH_BOTTOM;
else if (strcmp(splashpos, "right") == 0)
splash->position = MOJOGUI_SPLASH_RIGHT;
else if (strcmp(splashpos, "background") == 0)
splash->position = MOJOGUI_SPLASH_BACKGROUND;
else
splash->position = defpos; // oh well.
} // if
} // if
free(data);
} // if
Expand All @@ -1166,10 +1188,11 @@ static int luahook_gui_start(lua_State *L)
{
const char *title = luaL_checkstring(L, 1);
const char *splashfname = lua_tostring(L, 2);
const char *splashpos = lua_tostring(L, 3);
boolean rc = false;
MojoGuiSplash splash;

prepareSplash(&splash, splashfname);
prepareSplash(&splash, splashfname, splashpos);
rc = GGui->start(title, &splash);
if (splash.rgba != NULL)
free((void *) splash.rgba);
Expand Down
8 changes: 8 additions & 0 deletions scripts/mojosetup_init.lua
Expand Up @@ -191,6 +191,13 @@ local function mustBeUrl(fnname, elem, val)
end
end

local function mustBeSplashPosition(fnname, elem, val)
mustBeString(fnname, elem, val)
local valid = (val == nil) or (val == "right") or (val == "bottom") or
(val == "left") or (val == "top") or (val == "background");
schema_assert(valid, fnname, elem, _("Splash position is invalid"))
end

local function mustBePerms(fnname, elem, val)
mustBeString(fnname, elem, val)
local valid = MojoSetup.isvalidperms(val)
Expand Down Expand Up @@ -298,6 +305,7 @@ function Setup.Package(tab)
{ "preinstall", nil, mustBeFunction },
{ "postinstall", nil, mustBeFunction },
{ "splash", nil, mustBeString, cantBeEmpty },
{ "splashpos", nil, mustBeSplashPosition },
{ "url", nil, mustBeString, cantBeEmpty },
{ "once", true, mustBeBool },
{ "category", "Games", mustBeString, cantBeEmpty },
Expand Down
9 changes: 5 additions & 4 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -1062,6 +1062,7 @@ local function install_manifests(desc, key)
version = MojoSetup.install.version,
manifest = MojoSetup.manifest,
splash = MojoSetup.install.splash,
splashpos = MojoSetup.install.splashpos,
desktopmenuitems = MojoSetup.install.desktopmenuitems,
preuninstall = MojoSetup.install.preuninstall,
postuninstall = MojoSetup.install.postuninstall
Expand Down Expand Up @@ -1227,12 +1228,12 @@ local function get_productkey(thisstage, maxstage, desc, fmt, verify, dest, mani
end


local function start_gui(desc, splashfname)
local function start_gui(desc, splashfname, splashpos)
if splashfname ~= nil then
splashfname = 'meta/' .. splashfname
end

if not MojoSetup.gui.start(desc, splashfname) then
if not MojoSetup.gui.start(desc, splashfname, splashpos) then
MojoSetup.fatal(_("GUI failed to start"))
end

Expand Down Expand Up @@ -1781,7 +1782,7 @@ local function do_install(install)
end

-- Now make all this happen.
start_gui(install.description, install.splash)
start_gui(install.description, install.splash, install.splashpos)

-- Make the stages available elsewhere.
MojoSetup.stages = stages
Expand Down Expand Up @@ -2017,7 +2018,7 @@ local function uninstaller()
end

if uninstall_permitted then
start_gui(package.description, package.splash)
start_gui(package.description, package.splash, package.splashpos)
run_config_defined_hook(package.preuninstall, package)

uninstall_desktop_menu_items(package)
Expand Down

0 comments on commit 5d4a04d

Please sign in to comment.