1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     GuiControlBase.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  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   $Rev: 46365 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_COMMON_SCENE_GUICONTROLBASE_H_
17 #define NN_COMMON_SCENE_GUICONTROLBASE_H_
18 
19 #include "GuiUtil.h"
20 #include "GuiTypes.h"
21 #include <nn/util/util_SizedEnum.h>
22 
23 namespace scene
24 {
25     class ControlManager;
26 
27     /* Please see man pages for details
28 
29     */
30     class ControlBase
31     {
32     public:
33         friend class ControlManager;
34 
35     public:
36         /* Please see man pages for details
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47         */
48         ControlBase(ControlType type, u32 id, s32 x, s32 y, u32 width, u32 height, const wchar_t* pText, void* pExtraData, f32 fontScale);
49 
50         /* Please see man pages for details
51 
52         */
53         virtual ~ControlBase();
54 
55         /* Please see man pages for details
56 
57         */
GetType()58         ControlType GetType() const
59         {
60             return m_type;
61         }
62 
63         /* Please see man pages for details
64 
65         */
GetId()66         u32 GetId() const
67         {
68             return m_id;
69         }
70 
71         /* Please see man pages for details
72 
73         */
GetX()74         s32 GetX() const
75         {
76             return m_x;
77         }
78 
79         /* Please see man pages for details
80 
81         */
GetY()82         s32 GetY() const
83         {
84             return m_y;
85         }
86 
87         /* Please see man pages for details
88 
89         */
GetWidth()90         u32 GetWidth() const
91         {
92             return m_width;
93         }
94 
95         /* Please see man pages for details
96 
97         */
GetHeight()98         u32 GetHeight() const
99         {
100             return m_height;
101         }
102 
103         /* Please see man pages for details
104 
105         */
GetText()106         const wchar_t* GetText() const
107         {
108             return m_pText;
109         }
110 
111         /* Please see man pages for details
112 
113         */
GetTextLength()114         s32 GetTextLength() const
115         {
116             return m_textLength;
117         }
118 
119         /* Please see man pages for details
120 
121         */
GetBorderColor(ControlState state)122         nn::util::Color8 GetBorderColor(ControlState state) const
123         {
124             if (state < CONTROL_STATE_MAX)
125             {
126                 return m_borderColors[state];
127             }
128 
129             return nn::util::Color8();
130         }
131 
132         /* Please see man pages for details
133 
134         */
GetTextColor(ControlState state)135         nn::util::Color8 GetTextColor(ControlState state) const
136         {
137             if (state < CONTROL_STATE_MAX)
138             {
139                 return m_textColors[state];
140             }
141 
142             return nn::util::Color8();
143         }
144 
145         /* Please see man pages for details
146 
147         */
GetTextAlign()148         TextAlign GetTextAlign() const
149         {
150             return m_textAlign;
151         }
152 
153         /* Please see man pages for details
154 
155         */
GetBorderWidth()156         f32 GetBorderWidth() const
157         {
158             return m_borderWidth;
159         }
160 
161         /* Please see man pages for details
162 
163         */
GetState()164         ControlState GetState() const
165         {
166             return m_state;
167         }
168 
169         /* Please see man pages for details
170 
171         */
GetExtraData()172         void* GetExtraData() const
173         {
174             return m_pExtraData;
175         }
176 
177         /* Please see man pages for details
178 
179         */
GetControlManager()180         ControlManager* GetControlManager() const
181         {
182             return m_pManager;
183         }
184 
185         /* Please see man pages for details
186 
187         */
SetX(s32 x)188         void SetX(s32 x)
189         {
190             m_x = x;
191         }
192 
193         /* Please see man pages for details
194 
195         */
SetY(s32 y)196         void SetY(s32 y)
197         {
198             m_y = y;
199         }
200 
201         /* Please see man pages for details
202 
203         */
SetWidth(u32 width)204         void SetWidth(u32 width)
205         {
206             if (width > 0)
207             {
208                 m_width = width;
209             }
210         }
211 
212         /* Please see man pages for details
213 
214         */
SetHeight(u32 height)215         void SetHeight(u32 height)
216         {
217             if (height > 0)
218             {
219                 m_height = height;
220             }
221         }
222 
223         /* Please see man pages for details
224 
225         */
226         void SetText(const wchar_t* pText);
227 
228         /* Please see man pages for details
229 
230         */
231         void SetFormattedText(const wchar_t* pFormat, ...);
232 
233         /* Please see man pages for details
234 
235         */
SetBorderColor(ControlState state,nn::util::Color8 color)236         void SetBorderColor(ControlState state, nn::util::Color8 color)
237         {
238             if (state < CONTROL_STATE_MAX)
239             {
240                 m_borderColors[state] = color;
241             }
242         }
243 
244         /* Please see man pages for details
245 
246         */
SetTextColor(ControlState state,nn::util::Color8 color)247         void SetTextColor(ControlState state, nn::util::Color8 color)
248         {
249             if (state < CONTROL_STATE_MAX)
250             {
251                 m_textColors[state] = color;
252             }
253         }
254 
255         /* Please see man pages for details
256 
257         */
SetTextAlign(TextAlign textAlign)258         void SetTextAlign(TextAlign textAlign)
259         {
260             m_textAlign = textAlign;
261         }
262 
263         /* Please see man pages for details
264 
265         */
SetBorderWidth(f32 borderWidth)266         void SetBorderWidth(f32 borderWidth)
267         {
268             m_borderWidth = borderWidth;
269         }
270 
271         /* Please see man pages for details
272 
273         */
SetState(ControlState state)274         void SetState(ControlState state)
275         {
276             if (state < CONTROL_STATE_MAX)
277             {
278                 m_state = state;
279             }
280         }
281 
282         /* Please see man pages for details
283 
284         */
SetExtraData(void * pExtraData)285         void SetExtraData(void* pExtraData)
286         {
287             m_pExtraData = pExtraData;
288         }
289 
290         /* Please see man pages for details
291 
292         */
SetControlManager(ControlManager * pManager)293         void SetControlManager(ControlManager* pManager)
294         {
295             m_pManager = pManager;
296         }
297 
298     protected:
299         // Calculate the start position for text rendering.
300         s32 CalculateTextX(s32 offsetL, s32 offsetR);
301         // Calculate the start position for text rendering.
302         s32 CalculateTextY(s32 offset);
303 
304         // Processing when pressed with the stylus
305         virtual void OnPenDown() = 0;
306         // Processing when the stylus is lifted
307         virtual void OnPenUp(bool isIn) = 0;
308         // Processing when sliding with the stylus
309         virtual void OnPenSlide(bool isIn) = 0;
310         // Processing when tapped with the stylus
311         virtual void OnPenTouch() = 0;
312         // Processing during rendering
313         virtual void OnDraw() = 0;
314 
315     protected:
316         // Control type
317         nn::util::SizedEnum4<ControlType> m_type;
318         // Control ID
319         u32 m_id;
320         // Coordinates
321         s32 m_x;
322         s32 m_y;
323         // Size
324         u32 m_width;
325         u32 m_height;
326         // Text
327         wchar_t* m_pText;
328         // Text length
329         s32 m_textLength;
330         s32 m_textBufferLength;
331         // Text scale
332         f32 m_TextScale;
333         // Text size
334         f32 m_textWidth;
335         f32 m_textHeight;
336         // Border color
337         nn::util::Color8 m_borderColors[CONTROL_STATE_MAX];
338         // Font color
339         nn::util::Color8 m_textColors[CONTROL_STATE_MAX];
340         // Text placement
341         nn::util::SizedEnum4<TextAlign> m_textAlign;
342         // Border size
343         f32 m_borderWidth;
344         // Control state
345         nn::util::SizedEnum4<ControlState> m_state;
346         // Expanded data
347         void* m_pExtraData;
348         // Control manager
349         ControlManager* m_pManager;
350     };
351 }
352 
353 #endif // NN_COMMON_SCENE_GUICONTROLBASE_H_
354