vaseboot/VasEBoot-core/gfxmenu/gfxmenu.c

151 lines
4.2 KiB
C

/* gfxmenu.c - Graphical menu interface controller. */
/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2008 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/types.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/mm.h>
#include <VasEBoot/err.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/command.h>
#include <VasEBoot/video.h>
#include <VasEBoot/gfxterm.h>
#include <VasEBoot/bitmap.h>
#include <VasEBoot/bitmap_scale.h>
#include <VasEBoot/term.h>
#include <VasEBoot/env.h>
#include <VasEBoot/normal.h>
#include <VasEBoot/gfxwidgets.h>
#include <VasEBoot/menu.h>
#include <VasEBoot/menu_viewer.h>
#include <VasEBoot/gfxmenu_model.h>
#include <VasEBoot/gfxmenu_view.h>
#include <VasEBoot/time.h>
#include <VasEBoot/i18n.h>
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
static VasEBoot_gfxmenu_view_t cached_view;
static void
VasEBoot_gfxmenu_viewer_fini (void *data __attribute__ ((unused)))
{
}
/* FIXME: Previously 't' changed to text menu is it necessary? */
static VasEBoot_err_t
VasEBoot_gfxmenu_try (int entry, VasEBoot_menu_t menu, int nested)
{
VasEBoot_gfxmenu_view_t view = NULL;
const char *theme_path;
char *full_theme_path = 0;
struct VasEBoot_menu_viewer *instance;
VasEBoot_err_t err;
struct VasEBoot_video_mode_info mode_info;
theme_path = VasEBoot_env_get ("theme");
if (! theme_path)
return VasEBoot_error (VAS_EBOOT_ERR_FILE_NOT_FOUND, N_("variable `%s' isn't set"),
"theme");
err = VasEBoot_video_get_info (&mode_info);
if (err)
return err;
instance = VasEBoot_zalloc (sizeof (*instance));
if (!instance)
return VasEBoot_errno;
if (theme_path[0] != '/' && theme_path[0] != '(')
{
const char *prefix;
prefix = VasEBoot_env_get ("prefix");
full_theme_path = VasEBoot_xasprintf ("%s/themes/%s",
prefix,
theme_path);
}
if (!cached_view || VasEBoot_strcmp (cached_view->theme_path,
full_theme_path ? : theme_path) != 0
|| cached_view->screen.width != mode_info.width
|| cached_view->screen.height != mode_info.height)
{
VasEBoot_gfxmenu_view_destroy (cached_view);
/* Create the view. */
cached_view = VasEBoot_gfxmenu_view_new (full_theme_path ? : theme_path,
mode_info.width,
mode_info.height);
}
VasEBoot_free (full_theme_path);
if (! cached_view)
{
VasEBoot_free (instance);
return VasEBoot_errno;
}
view = cached_view;
view->double_repaint = (mode_info.mode_type
& VAS_EBOOT_VIDEO_MODE_TYPE_DOUBLE_BUFFERED)
&& !(mode_info.mode_type & VAS_EBOOT_VIDEO_MODE_TYPE_UPDATING_SWAP);
view->selected = entry;
view->menu = menu;
view->nested = nested;
view->first_timeout = -1;
VasEBoot_video_set_viewport (0, 0, mode_info.width, mode_info.height);
if (view->double_repaint)
{
VasEBoot_video_swap_buffers ();
VasEBoot_video_set_viewport (0, 0, mode_info.width, mode_info.height);
}
VasEBoot_gfxmenu_view_draw (view);
instance->data = view;
instance->set_chosen_entry = VasEBoot_gfxmenu_set_chosen_entry;
instance->fini = VasEBoot_gfxmenu_viewer_fini;
instance->print_timeout = VasEBoot_gfxmenu_print_timeout;
instance->clear_timeout = VasEBoot_gfxmenu_clear_timeout;
VasEBoot_menu_register_viewer (instance);
return VAS_EBOOT_ERR_NONE;
}
VAS_EBOOT_MOD_INIT (gfxmenu)
{
struct VasEBoot_term_output *term;
FOR_ACTIVE_TERM_OUTPUTS(term)
if (VasEBoot_gfxmenu_try_hook && term->fullscreen)
{
term->fullscreen ();
break;
}
VasEBoot_gfxmenu_try_hook = VasEBoot_gfxmenu_try;
}
VAS_EBOOT_MOD_FINI (gfxmenu)
{
VasEBoot_gfxmenu_view_destroy (cached_view);
VasEBoot_gfxmenu_try_hook = NULL;
}