1 /*---------------------------------------------------------------------------*
2 Project: TWLSDK - demos - FS - overlay-staticinit
3 File: top_menu.c
4
5 Copyright 2007 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2007-11-06 #$
14 $Rev: 2135 $
15 $Author: yosizaki $
16 *---------------------------------------------------------------------------*/
17
18 #include <nitro.h>
19 #include "mode.h"
20 #include "DEMO.h"
21
22 // Include this header when NitroStaticInit() is specified as a static initializer.
23 //
24 #include <nitro/sinit.h>
25
26
27 /*---------------------------------------------------------------------------*/
28 /* Constants */
29
30 // The overlay ID of each mode to be selected from the top menu
31 FS_EXTERN_OVERLAY(mode_1);
32 FS_EXTERN_OVERLAY(mode_2);
33 FS_EXTERN_OVERLAY(mode_3);
34
35 enum
36 {
37 MENU_MODE_1,
38 MENU_MODE_2,
39 MENU_MODE_3,
40 MENU_BEGIN = 0,
41 MENU_END = MENU_MODE_3,
42 MENU_MAX = MENU_END + 1
43 };
44
45
46 /*---------------------------------------------------------------------------*/
47 /* Variables */
48
49 // menu cursor
50 static int menu_cursor;
51
52
53 /*---------------------------------------------------------------------------*/
54 /* functions */
55
56 /*---------------------------------------------------------------------------*
57 Name: MyUpdateFrame
58
59 Description: Updates the internal state by one frame in the current mode.
60
61 Arguments: frame_count: Frame count of the current operation
62 input: Array of input data
63 player_count: Current number of total players (the number of valid input elements)
64 own_player_id: Local player number
65
66 Returns: Returns FALSE if the current mode ends this frame and TRUE otherwise.
67
68 *---------------------------------------------------------------------------*/
MyUpdateFrame(int frame_count,const InputData * input,int player_count,int own_player_id)69 static BOOL MyUpdateFrame(int frame_count,
70 const InputData * input, int player_count, int own_player_id)
71 {
72 (void)frame_count;
73 (void)player_count;
74
75 // Select menu with Up and Down keys
76 if (IS_INPUT_(input[own_player_id], PAD_KEY_UP, push))
77 {
78 if (--menu_cursor < MENU_BEGIN)
79 {
80 menu_cursor = MENU_END;
81 }
82 }
83 if (IS_INPUT_(input[own_player_id], PAD_KEY_DOWN, push))
84 {
85 if (++menu_cursor > MENU_END)
86 {
87 menu_cursor = MENU_BEGIN;
88 }
89 }
90 // Confirm with the A Button
91 return !IS_INPUT_(input[own_player_id], PAD_BUTTON_A, push);
92 }
93
94 /*---------------------------------------------------------------------------*
95 Name: MyDrawFrame
96
97 Description: Performs a rendering update based on the internal state in the current mode.
98
99 Arguments: frame_count: Frame count of the current operation
100
101 Returns: None.
102 *---------------------------------------------------------------------------*/
MyDrawFrame(int frame_count)103 static void MyDrawFrame(int frame_count)
104 {
105 int i;
106
107 (void)frame_count;
108
109 DEMOFillRect(0, 0, GX_LCD_SIZE_X, GX_LCD_SIZE_Y, DEMO_RGB_CLEAR);
110 // Display file name and a simple description of operations
111 DEMOSetBitmapTextColor(GX_RGBA(31, 31, 31, 1));
112 DEMODrawText(0, 10, "%s", __FILE__);
113 DEMODrawText(30, 40, "up/down: select menu");
114 DEMODrawText(30, 50, " A : run selected mode");
115 // Menu and cursor display
116 DEMOSetBitmapTextColor(GX_RGBA(31, 31, 16, 1));
117 for (i = MENU_BEGIN; i <= MENU_END; ++i)
118 {
119 DEMODrawText(40, 80 + i * 10, "%c mode %d", ((i == menu_cursor) ? '>' : ' '), i + 1);
120 }
121 }
122
123 /*---------------------------------------------------------------------------*
124 Name: MyEndFrame
125
126 Description: Ends the current mode.
127
128 Arguments: p_next_mode: The ID indicated by this pointer is overwritten when the next mode is specified explicitly.
129 In the absence of a particular specification, the mode that called the current mode is selected.
130
131
132
133 Returns: None.
134 *---------------------------------------------------------------------------*/
MyEndFrame(FSOverlayID * p_next_mode)135 static void MyEndFrame(FSOverlayID *p_next_mode)
136 {
137 // Expressly configure and return the selected mode
138 switch (menu_cursor)
139 {
140 case MENU_MODE_1:
141 *p_next_mode = FS_OVERLAY_ID(mode_1);
142 break;
143 case MENU_MODE_2:
144 *p_next_mode = FS_OVERLAY_ID(mode_2);
145 break;
146 case MENU_MODE_3:
147 *p_next_mode = FS_OVERLAY_ID(mode_3);
148 break;
149 }
150 }
151
152 /*---------------------------------------------------------------------------*
153 Name: NitroStaticInit
154
155 Description: This is an automatic initialization function as a static initializer.
156
157 Arguments: None.
158
159 Returns: None.
160 *---------------------------------------------------------------------------*/
NitroStaticInit(void)161 static void NitroStaticInit(void)
162 {
163 UpdateFrame = MyUpdateFrame;
164 DrawFrame = MyDrawFrame;
165 EndFrame = MyEndFrame;
166
167 // Perform the necessary initialization processes for each mode here
168
169 menu_cursor = 0;
170 }
171