1 /*---------------------------------------------------------------------------*
2 Project: TWLSDK - demos - FS - overlay-staticinit
3 File: mode_2.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 /* Variables */
29
30 // Stylus press state
31 static BOOL is_tp_on;
32 static struct Point { int x, y; } bak_pos, cur_pos;
33
34
35 /*---------------------------------------------------------------------------*/
36 /* functions */
37
38 /*---------------------------------------------------------------------------*
39 Name: MyUpdateFrame
40
41 Description: Updates the internal state by one frame in the current mode.
42
43 Arguments: frame_count: Frame count of the current operation
44 input: Array of input data
45 player_count: Current number of total players (the number of valid input elements)
46 own_player_id: Local player number
47
48 Returns: Returns FALSE if the current mode ends this frame and TRUE otherwise.
49
50 *---------------------------------------------------------------------------*/
MyUpdateFrame(int frame_count,const InputData * input,int player_count,int own_player_id)51 static BOOL MyUpdateFrame(int frame_count,
52 const InputData * input, int player_count, int own_player_id)
53 {
54 (void)frame_count;
55 (void)player_count;
56
57 // Update the input state of the stylus
58 bak_pos = cur_pos;
59 is_tp_on = IS_INPUT_(input[own_player_id], PAD_BUTTON_TP, push);
60 if (is_tp_on)
61 {
62 cur_pos.x = input[own_player_id].tp.x;
63 cur_pos.y = input[own_player_id].tp.y;
64 }
65 // End if anything is pressed other than the stylus
66 return !IS_INPUT_(input[own_player_id], PAD_ALL_MASK, push);
67 }
68
69 /*---------------------------------------------------------------------------*
70 Name: MyDrawFrame
71
72 Description: Performs a rendering update based on the internal state in the current mode.
73
74 Arguments: frame_count: Frame count of the current operation
75
76 Returns: None.
77 *---------------------------------------------------------------------------*/
MyDrawFrame(int frame_count)78 static void MyDrawFrame(int frame_count)
79 {
80 // The first frame clears the screen
81 if (frame_count == 0)
82 {
83 DEMOFillRect(0, 0, GX_LCD_SIZE_X, GX_LCD_SIZE_Y, DEMO_RGB_CLEAR);
84 DEMOSetBitmapTextColor(GX_RGBA(31, 31, 31, 1));
85 DEMODrawText(0, 10, "%s", __FILE__);
86 DEMODrawText(30, 40, "touch screen : draw line");
87 DEMODrawText(30, 50, "press any key to return");
88 }
89 // Render the current position and trajectory
90 DEMOFillRect(cur_pos.x - 2, cur_pos.y - 2, 4, 4, GX_RGBA(0, 31, 0, 1));
91 if (is_tp_on)
92 {
93 DEMODrawLine(bak_pos.x, bak_pos.y, cur_pos.x, cur_pos.y, GX_RGBA(16, 16, 31, 1));
94 }
95 }
96
97 /*---------------------------------------------------------------------------*
98 Name: MyEndFrame
99
100 Description: Ends current mode.
101
102 Arguments: p_next_mode: The ID indicated by this pointer is overwritten when the next mode is specified explicitly.
103 If no mode is specified, the mode that called the current mode will be selected.
104
105
106
107 Returns: None.
108 *---------------------------------------------------------------------------*/
MyEndFrame(FSOverlayID * p_next_mode)109 static void MyEndFrame(FSOverlayID *p_next_mode)
110 {
111 (void)p_next_mode;
112 }
113
114 /*---------------------------------------------------------------------------*
115 Name: NitroStaticInit
116
117 Description: Function for auto-initialization as static initializer.
118
119 Arguments: None.
120
121 Returns: None.
122 *---------------------------------------------------------------------------*/
NitroStaticInit(void)123 static void NitroStaticInit(void)
124 {
125 UpdateFrame = MyUpdateFrame;
126 DrawFrame = MyDrawFrame;
127 EndFrame = MyEndFrame;
128
129 /* Perform the necessary initialization processes for each mode here */
130
131 is_tp_on = FALSE;
132 cur_pos.x = HW_LCD_WIDTH / 2;
133 cur_pos.y = HW_LCD_HEIGHT / 2;
134 bak_pos = cur_pos;
135 }
136