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