1 /*---------------------------------------------------------------------------* 2 * N I N T E N D O C O N F I D E N T I A L P R O P R I E T A R Y 3 *---------------------------------------------------------------------------* 4 * 5 * Project : Dolphin OS - DEMOWin 6 * File: DEMOWin.h 7 * 8 * Copyright 2001 Nintendo. All rights reserved. 9 * 10 * These coded instructions, statements, and computer programs contain 11 * proprietary information of Nintendo of America Inc. and/or Nintendo 12 * Company Ltd., and are protected by Federal copyright law. They may 13 * not be disclosed to third parties or copied or duplicated in any form, 14 * in whole or in part, without the prior written consent of Nintendo. 15 * 16 * $Log: DEMOWin.h,v $ 17 * Revision 1.4 2006/05/21 15:02:25 ekwon 18 * Revised to accomodate MEM library usage if DEMO_USE_MEMLIB is #define'd before DEMOWIN.h is included. 19 * 20 * Also supports using MEM2 via #define of DEMOWIN_USE_MEM2. However, this has not been tested yet. 21 * 22 * Note that these changes are backwards compatible with older demos. 23 * 24 * Revision 1.3 2006/03/20 11:22:56 hiratsu 25 * Fixed unsafe macro. 26 * 27 * Revision 1.2 2006/02/04 13:05:45 hashida 28 * (none) 29 * 30 * Revision 1.1.1.1 2005/05/12 02:41:06 yasuh-to 31 * dolphin�V�[�X�c���[����ڐA 32 * 33 34 13 02/08/26 20:14 Hashida 35 Suppressed a warning. 36 37 12 2/05/02 4:01p Eugene 38 Added pad data to window structure so that it may be exposed to calling 39 application. 40 41 11 5/08/01 10:49p Eugene 42 43 10 5/08/01 2:18a Eugene 44 45 9 5/08/01 2:06a Eugene 46 47 8 5/07/01 11:54p Eugene 48 49 7 5/07/01 11:14p Eugene 50 51 6 5/07/01 11:13p Eugene 52 53 5 5/07/01 10:01p Eugene 54 55 4 5/07/01 1:28p Eugene 56 57 3 5/06/01 11:28p Eugene 58 59 2 5/06/01 11:07p Eugene 60 61 1 5/06/01 8:30p Eugene 62 For unsupported, undocumented windowing system. This file must be 63 explicitly included before the DEMOWin library can be used. 64 65 1 12/04/00 7:28p Eugene 66 * 67 * 68 * $NoKeywords: $ 69 * 70 *---------------------------------------------------------------------------* 71 * 72 * Description 73 * ----------- 74 * 75 * 76 * 77 * 78 *---------------------------------------------------------------------------*/ 79 80 81 #ifndef __DEMOWIN_H__ 82 #define __DEMOWIN_H__ 83 84 #ifdef __cplusplus 85 extern "C" { 86 #endif 87 88 /*---------------------------------------------------------------------------* 89 * Includes 90 *---------------------------------------------------------------------------*/ 91 92 #include <revolution/types.h> 93 94 /*---------------------------------------------------------------------------* 95 * Definitions 96 *---------------------------------------------------------------------------*/ 97 98 // font-size calibrations 99 #define DEMOWIN_MAX_STRING_SIZE 128 100 #define FONT_CHAR_WIDTH 8 101 #define FONT_CHAR_HEIGHT 8 102 #define DEMOWIN_X_CHAR_PAD 7 103 #define DEMOWIN_Y_CHAR_PAD 2 104 105 // calculating minimum window dimensions 106 // takes number of characters as parameters; returns size in pixels 107 #define DEMOWIN_CALC_MENU_WIDTH_PIXELS(w) ((((w)+DEMOWIN_X_CHAR_PAD)*FONT_CHAR_WIDTH)+4) 108 #define DEMOWIN_CALC_MENU_HEIGHT_PIXELS(h) (((DEMOWIN_Y_CHAR_PAD+(h))*FONT_CHAR_HEIGHT)+4) 109 110 // window flags 111 #define DEMOWIN_FLAG_ATTACHED 0x00000001 112 #define DEMOWIN_FLAG_VISIBLE 0x00000002 113 114 // window priority (Z value) - note that DEMO lib looks down the positive Z axis 115 #define DEMOWIN_PRIORITY_FORE 0x0000 116 #define DEMOWIN_PRIORITY_BACK 0x0001 117 118 // window color attributes 119 #define DEMOWIN_COLOR_CAPTION 0 120 #define DEMOWIN_COLOR_BKGND 1 121 #define DEMOWIN_COLOR_BORDER 2 122 #define DEMOWIN_COLOR_RESET 3 123 124 // for window scrolling function 125 #define DEMOWIN_SCROLL_HOME 0 // set curr_view_line to curr_output_line 126 #define DEMOWIN_SCROLL_UP 1 // text moves down 127 #define DEMOWIN_SCROLL_DOWN 2 // text moves up 128 129 #define DEMOWIN_LIST_HOME 0 130 #define DEMOWIN_LIST_UP 1 131 #define DEMOWIN_LIST_DOWN 2 132 133 // ****************************************** 134 // DEMOWIN PAD structure 135 // ****************************************** 136 137 typedef struct 138 { 139 PADStatus pads [PAD_MAX_CONTROLLERS]; 140 u32 button [PAD_MAX_CONTROLLERS]; 141 u32 old_button [PAD_MAX_CONTROLLERS]; 142 u32 changed_button [PAD_MAX_CONTROLLERS]; 143 u32 repeat_button [PAD_MAX_CONTROLLERS]; 144 u32 repeat_ctr [PAD_MAX_CONTROLLERS]; 145 } DEMOWinPadInfo; 146 147 #define PAD_THRESHOLD 64 148 #define TRIGGER_THRESHOLD 128 149 150 // ***************************************** 151 // For PopUp menu system 152 // ***************************************** 153 154 // item flags 155 #define DEMOWIN_ITM_NONE 0x00000000 // 156 #define DEMOWIN_ITM_DISABLED 0x00000001 // 157 #define DEMOWIN_ITM_CHECK 0x00000002 // 158 #define DEMOWIN_ITM_CHK_STATE 0x00000004 // 159 #define DEMOWIN_ITM_SEPARATOR 0x00000008 // 160 #define DEMOWIN_ITM_EOF 0x00000010 // menu should exit after invoking this function 161 #define DEMOWIN_ITM_TERMINATOR 0x80000000 162 163 // window flag 164 #define DEMOWIN_MNU_NONE 0x00000000 // 165 #define DEMOWIN_MNU_EOM 0x00000001 // parent should exit after invoking this menu 166 167 168 // menu navigation 169 #define DEMOWIN_MNU_UP 0x0001 170 #define DEMOWIN_MNU_DOWN 0x0002 171 #define DEMOWIN_MNU_LEFT 0x0003 172 #define DEMOWIN_MNU_RIGHT 0x0004 173 #define DEMOWIN_MNU_SELECT 0x0005 174 #define DEMOWIN_MNU_CANCEL 0x0006 175 176 // ***************************************** 177 // For PAD system 178 // ***************************************** 179 #define DEMOWIN_PAD_REPEAT_THRESH_DEF 15 // in video frames 180 #define DEMOWIN_PAD_REPEAT_RATE_DEF 2 // in video frames 181 182 183 #define DEMOWIN_STICK_U 0x00010000 // analog value exceed specified threshold 184 #define DEMOWIN_STICK_D 0x00020000 185 #define DEMOWIN_STICK_R 0x00040000 186 #define DEMOWIN_STICK_L 0x00080000 187 #define DEMOWIN_SUBSTICK_U 0x00100000 188 #define DEMOWIN_SUBSTICK_D 0x00200000 189 #define DEMOWIN_SUBSTICK_R 0x00400000 190 #define DEMOWIN_SUBSTICK_L 0x00800000 191 #define DEMOWIN_TRIGGER_R 0x01000000 192 #define DEMOWIN_TRIGGER_L 0x02000000 193 194 /*---------------------------------------------------------------------------* 195 * Types 196 *---------------------------------------------------------------------------*/ 197 198 199 typedef struct STRUCT_DEMOWIN 200 { 201 // user defined window properties 202 s32 x1; 203 s32 y1; 204 205 s32 x2; 206 s32 y2; 207 208 u32 priority; 209 210 u32 flags; 211 212 u16 x_cal; // corrective offset, for centering window contents horizontally 213 u16 y_cal; // corrective offset, for centering window contents vertically 214 215 u16 pixel_width; // width of window, in pixels 216 u16 pixel_height; // height of window, in pixels 217 218 u16 char_width; // width of window, in characters 219 u16 char_height; // height of window, in characters 220 221 u16 num_scroll_lines; // number of scrollback lines 222 u16 total_lines; // total number of buffer lines (including visible) 223 224 u16 curr_output_line; // current row in buffer at which "log printf" will output text 225 u16 curr_output_col; // current col in a line at which "log printf" will output text 226 u16 curr_view_line; // for scrolling through the buffer 227 s16 cursor_line; // if <0, no highlight; otherwise, draw highlight 228 229 char *caption; 230 u8 *buffer; // private; dynamically allocated 231 232 GXColor bkgnd; 233 GXColor cap; 234 GXColor border; 235 236 void (*refresh)(struct STRUCT_DEMOWIN *handle); 237 struct STRUCT_DEMOWIN *next; 238 struct STRUCT_DEMOWIN *prev; 239 void *parent; // pointer to a 'superstructure' which includes this window handle 240 241 DEMOWinPadInfo pad; // pad data for given window 242 243 244 } DEMOWinInfo; 245 246 247 248 /*--------------------------------------------------------------------- 249 * "Modal" menu system 250 *---------------------------------------------------------------------*/ 251 252 253 // ****************************************** 254 // Menu item 255 // ****************************************** 256 257 struct STRUCT_MENU; 258 typedef struct STRUCT_MENU_ITEM 259 { 260 char *name; // NULL terminated string; name of menu item 261 u32 flags; // menu item attributes 262 263 void (*function)(struct STRUCT_MENU *menu, u32 item, u32 *result); 264 struct STRUCT_MENU *link; // child menu, if any 265 266 } DEMOWinMenuItem; 267 268 // The "function" member is the callback to invoke if this item is selected. The 269 // function may return a value in "result". If this item has the "DEMOWIN_ITM_EOF" 270 // flag asserted, the menu will exit after calling this function and return the 271 // value of "result". Kludgy, yes, I know. 272 273 274 // ****************************************** 275 // Menu information 276 // ****************************************** 277 typedef struct STRUCT_MENU 278 { 279 char *title; // menu title 280 DEMOWinInfo *handle; // window associated with this menu 281 DEMOWinMenuItem *items; // list of menu items 282 s32 max_display_items; // max number of items to display at once 283 u32 flags; // menu attributes 284 285 void (*cb_open) (struct STRUCT_MENU *menu, u32 item); 286 void (*cb_move) (struct STRUCT_MENU *menu, u32 item); 287 void (*cb_select)(struct STRUCT_MENU *menu, u32 item); 288 void (*cb_cancel)(struct STRUCT_MENU *menu, u32 item); 289 290 // private menu state information 291 s32 num_display_items; // actual number of items to display 292 s32 num_items; // actual number of items in list 293 u32 max_str_len; // max item/caption string length 294 s32 curr_pos; // curr position in list 295 s32 display_pos; // curr 'home' row displayed in list 296 297 } DEMOWinMenuInfo; 298 299 300 /*--------------------------------------------------------------------- 301 * List box stuff 302 *---------------------------------------------------------------------*/ 303 304 // ****************************************** 305 // Listbox item 306 // ****************************************** 307 typedef struct STRUCT_LISTBOX_ITEM 308 { 309 310 char *name; // name of item 311 u32 flags; // item attributes, if any 312 313 } DEMOWinListItem; 314 315 316 // ****************************************** 317 // Listbox information 318 // ****************************************** 319 typedef struct STRUCT_LISTBOX 320 { 321 322 char *title; // listbox title/caption 323 DEMOWinInfo *handle; // Window handle 324 DEMOWinListItem *items; // pointer to array of items 325 326 s32 max_display_items; // maximum number of items to display 327 u32 flags; // listbox attributes, if any 328 329 // private menu state information 330 s32 num_display_items; // actual number of items to display 331 s32 num_items; // actual number of items in list 332 u32 max_str_len; // max item/caption string length 333 s32 curr_pos; // curr position in list 334 s32 display_pos; // curr 'home' row displayed in list 335 BOOL cursor_state; // ON or OFF 336 337 338 } DEMOWinListInfo; 339 340 341 /*---------------------------------------------------------------------------* 342 * Globals 343 *---------------------------------------------------------------------------*/ 344 345 /*---------------------------------------------------------------------------* 346 * Function Prototypes 347 *---------------------------------------------------------------------------*/ 348 349 // initialization 350 void DEMOWinInit_Real (BOOL mem_lib_flag, BOOL mem2_flag); 351 352 353 #ifdef DEMO_USE_MEMLIB 354 355 #ifdef DEMOWIN_USE_MEM2 356 357 #define DEMOWinInit() DEMOWinInit_Real(TRUE,TRUE) 358 359 #else 360 361 #define DEMOWinInit() DEMOWinInit_Real(TRUE,FALSE) 362 363 #endif 364 365 #else 366 367 #define DEMOWinInit() DEMOWinInit_Real(FALSE, FALSE) 368 369 #endif 370 371 372 // instantiation 373 DEMOWinInfo *DEMOWinCreateWindow (s32 x1, s32 y1, s32 x2, s32 y2, char *caption, u16 scroll, void *func); 374 void DEMOWinOpenWindow (DEMOWinInfo *handle); 375 void DEMOWinCloseWindow (DEMOWinInfo *handle); 376 void DEMOWinDestroyWindow (DEMOWinInfo *handle); 377 378 // attribute control 379 void DEMOWinScrollWindow (DEMOWinInfo *handle, u32 dir); 380 void DEMOWinSetWindowColor (DEMOWinInfo *handle, u32 item, u8 r, u8 g, u8 b, u8 a); 381 void DEMOWinBringToFront (DEMOWinInfo *handle); 382 void DEMOWinSendToBack (DEMOWinInfo *handle); 383 384 void DEMOWinSetCursorLine (DEMOWinInfo *handle, s16 n); 385 s32 DEMOWinGetCursorLine (DEMOWinInfo *handle); 386 387 // I/O 388 void DEMOWinLogPrintf (DEMOWinInfo *handle, char *fmt, ...); 389 void DEMOWinPrintfXY (DEMOWinInfo *handle, u16 col, u16 row, char *fmt, ...); 390 void DEMOWinClearRow (DEMOWinInfo *handle, u16 row); 391 void DEMOWinClearWindow (DEMOWinInfo *handle); 392 void DEMOWinClearBuffer (DEMOWinInfo *handle); 393 394 void DEMOWinPadInit (DEMOWinPadInfo *p); 395 void DEMOWinPadRead (DEMOWinPadInfo *p); 396 void DEMOWinResetRepeat (void); 397 void DEMOWinSetRepeat (u32 threshold, u32 rate); 398 399 // infrastructure 400 void DEMOWinRefresh (void); 401 402 // menu system 403 DEMOWinMenuInfo *DEMOWinCreateMenuWindow (DEMOWinMenuInfo *menu, u16 x, u16 y); 404 u32 DEMOWinMenuChild (DEMOWinMenuInfo *items, BOOL child_flag); 405 void DEMOWinDestroyMenuWindow(DEMOWinMenuInfo *menu); 406 407 // List box 408 DEMOWinListInfo *DEMOWinCreateListWindow (DEMOWinListInfo *list, u16 x, u16 y); 409 void DEMOWinDestroyListWindow(DEMOWinListInfo *list); 410 void DEMOWinListSetCursor (DEMOWinListInfo *list, BOOL x); 411 s32 DEMOWinListScrollList (DEMOWinListInfo *list, u32 dir); 412 s32 DEMOWinListMoveCursor (DEMOWinListInfo *list, u32 dir); 413 414 // aliased functions 415 #define DEMOWinGetNumRows(h) ((h)->char_width) 416 #define DEMOWinGetNumCols(h) ((h)->char_height) 417 #define DEMOWinMenu(ptr) DEMOWinMenuChild((ptr),FALSE) 418 419 #define DEMOWinListGetCurPos(l) ((l)->curr_pos) 420 #define DEMOWinListSetCurPos(l,x) ((l)->curr_pos = (s32)(x)) 421 422 423 #ifdef __cplusplus 424 } 425 #endif 426 427 #endif // __DEMOWIN_H__ 428