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 accommodate 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  * Ported from dolphin system tree
32  *
33 
34     13    2002/08/26 20:14 Hashida
35     Suppressed a warning.
36 
37     12    2002/02/05 4:01p Eugene
38     Added pad data to window structure so that it may be exposed to calling
39     application.
40 
41     11    2001/05/08 10:49p Eugene
42 
43     10    2001/05/08 2:18a Eugene
44 
45     9     2001/05/08 2:06a Eugene
46 
47     8     2001/05/07 11:54p Eugene
48 
49     7     2001/05/07 11:14p Eugene
50 
51     6     2001/05/07 11:13p Eugene
52 
53     5     2001/05/07 10:01p Eugene
54 
55     4     2001/05/07 1:28p Eugene
56 
57     3     2001/05/06 11:28p Eugene
58 
59     2     2001/05/06 11:07p Eugene
60 
61     1     2001/05/06 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     2000/12/04 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