1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
/****************************************************************************
* gui.c
*
* generic GUI Engine (using GX rendering)
*
* Copyright Eke-Eke (2009-2020)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
*
* - Redistributions may not be sold, nor may they be used in a commercial
* product or activity.
*
* - Redistributions that are modified from the original source must include the
* complete source code, including the source code for all components used by a
* binary built from the modified sources. However, as a special exception, the
* source code distributed need not include anything that is normally distributed
* (in either source or binary form) with the major components (compiler, kernel,
* and so on) of the operating system on which the executable runs, unless that
* component itself accompanies the executable.
*
* - Redistributions must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************************/
#ifndef _GUI_H
#define _GUI_H
#define BG_COLOR_MAX 15
/*****************************************************************************/
/* GUI Buttons state */
/*****************************************************************************/
#define BUTTON_VISIBLE 0x01
#define BUTTON_ACTIVE 0x02
#define BUTTON_SELECTED 0x04
#define BUTTON_OVER_SFX 0x08
#define BUTTON_SELECT_SFX 0x10
#define BUTTON_FADE 0x20
#define BUTTON_SLIDE_LEFT 0x40
#define BUTTON_SLIDE_RIGHT 0x80
#define BUTTON_SLIDE_TOP 0x100
#define BUTTON_SLIDE_BOTTOM 0x200
/*****************************************************************************/
/* GUI Image state */
/*****************************************************************************/
#define IMAGE_VISIBLE 0x01
#define IMAGE_REPEAT 0x02
#define IMAGE_FADE 0x04
#define IMAGE_SLIDE_LEFT 0x08
#define IMAGE_SLIDE_RIGHT 0x10
#define IMAGE_SLIDE_TOP 0x20
#define IMAGE_SLIDE_BOTTOM 0x40
/*****************************************************************************/
/* Generic GUI structures */
/*****************************************************************************/
/* Item descriptor*/
typedef struct
{
gx_texture *texture; /* temporary texture data */
const u8 *data; /* pointer to png image data (items icon only) */
char text[64]; /* item string (items list only) */
char comment[64]; /* item comment */
u16 x; /* item image or text X position (upper left corner) */
u16 y; /* item image or text Y position (upper left corner) */
u16 w; /* item image or text width */
u16 h; /* item image or text height */
} gui_item;
/* Button Data descriptor */
typedef struct
{
gx_texture *texture[2]; /* temporary texture datas */
const u8 *image[2]; /* pointer to png image datas (default) */
} butn_data;
/* Button descriptor */
typedef struct
{
butn_data *data; /* pointer to button image/texture data */
u16 state; /* button state (ACTIVE,VISIBLE,SELECTED...) */
u8 shift[4]; /* direction offsets */
u16 x; /* button image X position (upper left corner) */
u16 y; /* button image Y position (upper left corner) */
u16 w; /* button image pixels width */
u16 h; /* button image pixels height */
} gui_butn;
/* Image descriptor */
typedef struct
{
gx_texture *texture; /* temporary texture data */
const u8 *data; /* pointer to png image data */
u8 state; /* image state (VISIBLE) */
u16 x; /* image X position (upper left corner) */
u16 y; /* image Y position (upper left corner) */
u16 w; /* image width */
u16 h; /* image height */
u8 alpha; /* alpha transparency */
} gui_image;
/* Menu descriptor */
typedef struct
{
char title[64]; /* menu title */
int selected; /* index of selected item */
int offset; /* items list offset */
int max_items; /* total number of items */
int max_buttons; /* total number of buttons */
int max_images; /* total number of background images */
u8 screenshot; /* game screen background */
gui_item *items; /* menu items */
gui_butn *buttons; /* menu buttons */
gui_image *bg_images; /* background images */
gui_item *helpers[2]; /* left & right key comments */
gui_butn *arrows[2]; /* arrows buttons */
void (*cb)(void); /* specific draw callback */
} gui_menu;
typedef struct
{
u32 progress; /* progress counter */
bool refresh; /* messagebox current state */
gui_menu *parent; /* parent menu */
char title[64]; /* box title */
char msg[64]; /* box message */
gx_texture *window; /* pointer to box texture */
gx_texture *top; /* pointer to box title texture */
gx_texture *buttonA; /* pointer to button A texture */
gx_texture *buttonB; /* pointer to button A texture */
gx_texture *throbber; /* pointer to throbber texture */
} gui_message;
/* Menu inputs */
typedef struct
{
u16 keys;
#ifdef HW_RVL
struct ir_t ir;
#endif
} gui_input;
extern gui_input m_input;
/* Optionbox callback */
typedef void (*optioncallback)(void);
/* Generic textures*/
#ifdef HW_RVL
extern gx_texture *w_pointer;
#endif
/* Generic backgrounds */
#include "Bg_layer_png.h"
#include "Bg_overlay_png.h"
#include "Banner_main_png.h"
#include "Banner_bottom_png.h"
#include "Banner_top_png.h"
#include "Main_logo_png.h"
/* Generic frames */
#include "Frame_s1_png.h"
#include "Frame_s2_png.h"
#include "Frame_s3_png.h"
#include "Frame_s1_title_png.h"
#include "Frame_s2_title_png.h"
#include "Frame_throbber_png.h"
/* Generic Buttons */
#include "Button_text_png.h"
#include "Button_text_over_png.h"
#include "Button_icon_png.h"
#include "Button_icon_over_png.h"
#include "Button_icon_sm_png.h"
#include "Button_icon_sm_over_png.h"
#include "Button_up_png.h"
#include "Button_up_over_png.h"
#include "Button_down_png.h"
#include "Button_down_over_png.h"
#include "Button_arrow_png.h"
#include "Button_arrow_over_png.h"
#include "Button_digit_png.h"
#include "Button_digit_over_png.h"
/* Generic images*/
#ifdef HW_RVL
#define Key_A_png Key_A_wii_png
#define Key_B_png Key_B_wii_png
#include "generic_point_png.h"
#include "Key_A_wii_png.h"
#include "Key_B_wii_png.h"
#else
#define Key_A_png Key_A_gcn_png
#define Key_B_png Key_B_gcn_png
#include "Key_A_gcn_png.h"
#include "Key_B_gcn_png.h"
#endif
#include "Star_full_png.h"
#include "Star_empty_png.h"
#include "Overlay_bar_png.h"
/* Generic Sounds */
#include "button_over_pcm.h"
#include "button_select_pcm.h"
#include "intro_pcm.h"
extern u8 SILENT;
extern void GUI_InitMenu(gui_menu *menu);
extern void GUI_DeleteMenu(gui_menu *menu);
extern void GUI_DrawMenu(gui_menu *menu);
extern void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out);
extern void GUI_SlideMenuTitle(gui_menu *m, int title_offset);
extern int GUI_UpdateMenu(gui_menu *menu);
extern int GUI_RunMenu(gui_menu *menu);
extern void GUI_TextWindow(gui_menu *parent, char *title, char items[][64], u8 nb_items, u8 fontsize);
extern int GUI_OptionWindow(gui_menu *parent, char *title, char *infos, char *items[], u8 nb_items);
extern void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *option, float step, float min, float max, u8 type);
extern void GUI_OptionBox2(gui_menu *parent, char *text_1, char *text_2, s16 *option_1, s16 *option_2, s16 step, s16 min, s16 max);
extern void GUI_MsgBoxOpen(char *title, char *msg, bool throbber);
extern void GUI_MsgBoxUpdate(char *title, char *msg);
extern void GUI_MsgBoxClose(void);
extern void GUI_WaitPrompt(char *title, char *msg);
extern int GUI_WaitConfirm(char *title, char *msg);
extern void GUI_FadeOut();
extern GXColor *GUI_GetBgColor(void);
extern void GUI_SetBgColor(u8 color);
#endif
|