1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: GuiButton.cpp
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 #include "GuiButton.h"
17
18 namespace scene
19 {
20
21 // Constructor.
Button(u32 id,s32 x,s32 y,u32 width,u32 height,const wchar_t * pText,void * pExtraData,f32 fontScale)22 Button::Button(u32 id, s32 x, s32 y, u32 width, u32 height, const wchar_t* pText, void* pExtraData, f32 fontScale)
23 : ControlBase(CONTROL_TYPE_BUTTON, id, x, y, width, height, pText, pExtraData, fontScale)
24 {
25 m_textAlign = TEXT_ALIGN_CENTER;
26 m_borderWidth = 2.0f;
27 m_state = CONTROL_STATE_DEFAULT;
28
29 // Border color
30 m_borderColors[CONTROL_STATE_DEFAULT] = nn::util::Color8(192, 192, 192, 255);
31 m_borderColors[CONTROL_STATE_DISABLED] = nn::util::Color8( 32, 32, 32, 255);
32 m_borderColors[CONTROL_STATE_SELECTING] = nn::util::Color8( 45, 116, 174, 255);
33
34 // Font color
35 m_textColors[CONTROL_STATE_DEFAULT] = nn::util::Color8(192, 192, 192, 255);
36 m_textColors[CONTROL_STATE_DISABLED] = nn::util::Color8( 32, 32, 32, 255);
37 m_textColors[CONTROL_STATE_SELECTING] = nn::util::Color8( 45, 116, 174, 255);
38 }
39
40 // Destructor.
~Button()41 Button::~Button()
42 {
43 }
44
45 // Processing when pressed with the stylus
OnPenDown()46 void Button::OnPenDown()
47 {
48 m_state = CONTROL_STATE_SELECTING;
49 }
50
51 // Processing when the stylus is lifted
OnPenUp(bool isIn)52 void Button::OnPenUp(bool isIn)
53 {
54 (void)isIn;
55
56 m_state = CONTROL_STATE_DEFAULT;
57 }
58
59 // Processing when sliding with the stylus
OnPenSlide(bool isIn)60 void Button::OnPenSlide(bool isIn)
61 {
62 m_state = (isIn ? CONTROL_STATE_SELECTING : CONTROL_STATE_DEFAULT);
63 }
64
65 // Processing when tapped with the stylus
OnPenTouch()66 void Button::OnPenTouch()
67 {
68 }
69
70 // Processing during rendering
OnDraw()71 void Button::OnDraw()
72 {
73 // Renderer
74 demo::RenderSystemDrawing* pRenderSystem = GetRenderSystem();
75 // Text writer
76 TextWriter* pTextWriter = GetTextWriter();
77
78 // Border
79 if (m_borderWidth >= 0.0f)
80 {
81 nn::util::FloatColor color = m_borderColors[m_state];
82
83 // Render the box
84 pRenderSystem->SetColor(color.r, color.g, color.b, color.a);
85 scene::util::DrawBox(m_x, m_y, m_width, m_height, m_borderWidth);
86 }
87
88 // Text
89 if (m_textLength > 0)
90 {
91 nn::util::Color8 color = m_textColors[m_state];
92 // Scale settings
93 pTextWriter->SetFontScale(m_TextScale);
94
95 // Text render position
96 s32 tx = CalculateTextX(2, 0);
97 s32 ty = CalculateTextY(0);
98
99 // Render text
100 pTextWriter->SetTextColor(color.r, color.g, color.b);
101 pTextWriter->PutString(tx, ty, m_pText);
102 }
103 }
104
105 }
106