1 /*---------------------------------------------------------------------------*
2 
3   Copyright (C) Nintendo.  All rights reserved.
4 
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law.  They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 #ifndef __DEMOWIN_ASSETS_H_
14 #define __DEMOWIN_ASSETS_H_
15 
16 ////////////////////////////////////////////////////
17 //
18 // Assets data, types and interface for demos
19 //
20 ////////////////////////////////////////////////////
21 
22 
23 struct CVec2
24 {
CVec2CVec225     CVec2() {}
CVec2CVec226     CVec2(float _x, float _y)
27         : x(_x), y(_y) {}
28 
29     union
30     {
31         struct
32         {
33             float x;
34             float y;
35         };
36         struct
37         {
38             float u;
39             float v;
40         };
41     };
42 };
43 
44 struct CVec3
45 {
CVec3CVec346     CVec3() {}
CVec3CVec347     CVec3(float _x, float _y, float _z)
48         : x(_x), y(_y), z(_z) {}
49 
50     union
51     {
52         struct
53         {
54             float x;
55             float y;
56             float z;
57         };
58         struct
59         {
60             float r;
61             float g;
62             float b;
63         };
64     };
65 };
66 
67 struct CVec4
68 {
CVec4CVec469     CVec4() {}
70     CVec4(float _x, float _y, float _z, float _w = 1.0)
xCVec471         : x(_x), y(_y), z(_z), w(_w) {}
72 
73     union
74     {
75         struct
76         {
77             float x;
78             float y;
79             float z;
80             float w;
81         };
82         struct
83         {
84             float r;
85             float g;
86             float b;
87             float a;
88         };
89     };
90 };
91 
92 const float CURSOR_SPEED = 0.02;
93 
94 struct Window;
95 struct TabObject;
96 
97 const int MAX_WINDOWS = 100;
98 const int MAX_NAME_LENGTH = 256;
99 const int MAX_LINE_LENGTH = 80;
100 const int MAX_TEXT_LENGTH = 1000;
101 const float WINDOW_HANDLE_HEIGHT = 0.1;
102 
103 enum CWTextures
104 {
105     CW_TEXTURE_CURSOR = 0,
106     CW_TEXTURE_SLIDERLEFT,
107     CW_TEXTURE_SLIDERRIGHT,
108     CW_TEXTURE_COMBODOWNARROW,
109     CW_NUM_TEXTURES,
110 };
111 
112 typedef CVec4 (*ColorFunc)(int);
113 typedef void (*VoidFuncP)(void*);
114 
115 ///////////////////////////////////////////////////////////////////////////////////////////////////
116     // Since there is no std::string
117 template <int SIZE>
118 struct String
119 {
StringString120     String() {}
StringString121     String(const char* txt) {strcpy_s(text, txt);}
122 
123     String& operator=(const char* txt) {strcpy_s(text, txt); return *this;}
124 
125     operator char*() {return text;}
126 
127     char text[SIZE];
128 };
129 
130 #define DEMOWinStringList(...) AutoList<const char*>(__VA_ARGS__)
131 #define DEMOWinStringListList(...) AutoList<AutoList<const char*> >(__VA_ARGS__)
132 #define DEMOWinIntList(...) AutoList<int>(__VA_ARGS__)
133 
134     // Holds any positive number of <insert variable here>
135     // Supports any number for POD types, and up to 10 for non-POD types
136 template <typename T>
137 struct AutoList
138 {
AutoListAutoList139     AutoList()
140     {
141         count = 0;
142     }
143 
AutoListAutoList144     AutoList(const T& arg0)
145     {Init(1, &arg0);}
AutoListAutoList146     AutoList(const T& arg0, const T& arg1)
147     {Init(2, &arg0, &arg1);}
AutoListAutoList148     AutoList(const T& arg0, const T& arg1, const T& arg2)
149     {Init(3, &arg0, &arg1, &arg2);}
AutoListAutoList150     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3)
151     {Init(4, &arg0, &arg1, &arg2, &arg3);}
AutoListAutoList152     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4)
153     {Init(5, &arg0, &arg1, &arg2, &arg3, &arg4);}
AutoListAutoList154     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5)
155     {Init(6, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5);}
AutoListAutoList156     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5, const T& arg6)
157     {Init(7, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6);}
AutoListAutoList158     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5, const T& arg6, const T& arg7)
159     {Init(8, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7);}
AutoListAutoList160     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5, const T& arg6, const T& arg7, const T& arg8)
161     {Init(9, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8);}
AutoListAutoList162     AutoList(const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5, const T& arg6, const T& arg7, const T& arg8, const T& arg9)
163     {Init(10, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9);}
164 
AutoListAutoList165     AutoList(int _count, const T& arg0, const T& arg1, const T& arg2, const T& arg3, const T& arg4, const T& arg5, const T& arg6, const T& arg7, const T& arg8, const T& arg9, ...)
166     {
167         count = _count;
168         data.resize(count);
169 
170         va_list list;
171         va_start(list, _count);
172 
173             // Figure out where the first element is!
174         for (int i = 0; i < count; ++i)
175             data[i] = va_arg(list, T);
176 
177         va_end(list);
178     }
179 
InitAutoList180     void Init(int _count, ...)
181     {
182         count = _count;
183 
184         data.resize(count);
185 
186         va_list list;
187         va_start(list, _count);
188 
189             // Figure out where the first element is!
190         for (int i = 0; i < count; ++i)
191             data[i] = *va_arg(list, T*);
192 
193         va_end(list);
194 
195         args = &data[0];
196     }
197 
198     const AutoList& operator=(const AutoList& list)
199     {
200         count = list.count;
201 
202         data.resize(list.data.size());
203         for (int i = 0; i < list.data.size(); ++i)
204             data = list.data;
205 
206         args = &data[0];
207 
208         return *this;
209     }
210 
211     T* args;
212     std::vector<T> data;
213     int count;
214 };
215 
216 ///////////////////////////////////////////////////////////////////////////////////////////////////
217 
218 struct MenuItem;
219 
220     // The structure used for tabbing
221 struct TabObject
222 {
TabObjectTabObject223     TabObject()
224     : active(false), next(this), prev(this) {}
225 
TabObjectTabObject226     TabObject(Window* window) : active(false), next(this), prev(this)
227     {this->window = window;}
228 
229     void Add(Window* window, MenuItem* object, bool active = true);
230     void Remove();
231 
232     Window* window;
233     MenuItem* object;
234 
235     bool active;
236 
237     TabObject* next;
238     TabObject* prev;
239 };
240 
241     // The base structure that must be used for the combo box
242 struct SubCombo
243 {
244     virtual const char* GetName() = 0;
245     virtual SubCombo** GetPointers() = 0;
246     virtual int GetCount() = 0;
247 };
248 
249     // A simple example that has a list of names
250 template <int MAX_NAME_LENGTH_T>
251 struct SubComboBasic : public SubCombo
252 {
SubComboBasicSubComboBasic253     SubComboBasic(const char* _name)
254         : name(_name) {}
SubComboBasicSubComboBasic255     SubComboBasic() {}
256 
257     SubComboBasic& operator=(const char* txt) {name = txt; return *this;}
258 
GetNameSubComboBasic259     virtual const char* GetName() {return name.text;}
GetPointersSubComboBasic260     virtual SubCombo** GetPointers() {return NULL;}
GetCountSubComboBasic261     virtual int GetCount() {return 0;}
262 
263     String<MAX_NAME_LENGTH_T> name;
264 };
265 
266     // A simple example that has a double list of names
267 template <int MAX_NAME_LENGTH_T, int NUM_POINTERS>
268 struct SubDoubleComboBasic : public SubCombo
269 {
SubDoubleComboBasicSubDoubleComboBasic270     SubDoubleComboBasic(const char* _name)
271         : name(_name), count(0) {}
SubDoubleComboBasicSubDoubleComboBasic272     SubDoubleComboBasic() {}
273 
SetNameSubDoubleComboBasic274     void SetName(const char* txt) {name = txt;}
AddNameSubDoubleComboBasic275     void AddName(const char* txt) {list[count] = txt; pointers[count] = &list[count]; ++count;}
276 
GetNameSubDoubleComboBasic277     virtual const char* GetName() {return name.text;}
GetPointersSubDoubleComboBasic278     virtual SubCombo** GetPointers() {return pointers;}
GetCountSubDoubleComboBasic279     virtual int GetCount() {return count;}
280 
281     String<MAX_NAME_LENGTH_T> name;
282 
283     SubCombo* pointers[NUM_POINTERS];
284     SubComboBasic<MAX_NAME_LENGTH_T> list[NUM_POINTERS];
285     int count;
286 };
287 
288 #endif
289