JNR
uiLabel.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // uiLabel.cpp
32 // Dependent: -
33 //
34 // UI Static text label
35 //
36 #include "stdafx.h"
37 #include "GUI.h"
38 
40 {
41  //Default attributes
42  _nAlignH = M_AC;
43  _nAlignV = M_AM;
44  _nSize = 10;
45  _bCustomColor = M_FALSE;
46 }
47 
48 uiLabel::~uiLabel(void)
49 {
50 }
51 
52 void uiLabel::create(laPoint3 pos, laPoint3 size)
53 {
54  uiWindow::create(pos,size);
55 
56  _pFont = _pSkin->parameter("FN_DEFAULT").font();
57 }
58 
59 //Load from .cui file
60 void uiLabel::load(class laFileParser *fp)
61 {
62  uiWindow::load(fp);
63  fp->readText(_strText, M_FALSE);
64 
65  //_pFont = _pSkin->parameter("FN_DEFAULT").font();
66 }
67 
69 {
71 }
72 
74 {
75  laRenderer* pr = ::laSystemIntegrator::getRenderer();
76 
77  _pFont = _pSkin->parameter("FN_DEFAULT").font();
78  ASSERT(_pFont, "Invalid font");
79 
80  //Setup align
81  laPoint3 offset;
82 
83  _pFont->ctlSize(_nSize);
84  _pFont->ctlAlignH(_nAlignH);
85  _pFont->ctlAlignV(_nAlignV);
86 
87  switch(_nAlignH)
88  {
89  case M_AR:
90  offset[0] = getSize().x();
91  break;
92  case M_AC:
93  offset[0] = getSize().x()/2.0;
94  break;
95  }
96 
97  //Adjust for vertical align
98  switch(_nAlignV)
99  {
100  case M_AB:
101  offset[1] = getSize().y();
102  break;
103  case M_AM:
104  offset[1] = getSize().y()/2.0;
105  break;
106  }
107  offset = offset + getPos();
108 
109  //Drop shadow
110  pr->styleSet( _pSkin->parameter("CL_SHADOW_DARK").color() );
111  _pFont->draw(offset+laPoint3(1,1), _strText);
112 
113  //Draw text
114  if(_bCustomColor) pr->styleSet( _rgbCustom );
115  else pr->styleSet( _pSkin->parameter("CL_LABEL_TXT").color() );
116 
117  _pFont->draw(offset, _strText);
118 }
119 
120 
121 // Draw the horisontal line
122 void uiHR::draw()
123 {
124  laRenderer* r = ::laSystemIntegrator::getRenderer();
125  laColor cLine = _pSkin->parameter("CL_BUTTON").color();
126  laColor cShade = _pSkin->parameter("CL_SHADOW").color();
127  laPoint3 ptOffset(2,2);
128 
129  //laFont *f = _pSkin->parameter("FN_DEFAULT").font();
130 
131  r->styleLine(_ptSize.y());
132  r->modeTexture(M_FALSE);
133 
134  r->styleSet(cShade);
135  r->drawLine( _ptPos+ptOffset, _ptPos+laPoint3(_ptSize.x()+ptOffset.x(), ptOffset.y()) );
136 
137  r->styleSet(cLine);
138  r->drawLine( _ptPos, _ptPos+laPoint3(_ptSize.x(), 0) );
139 
140  uiWindow::draw();
141 }
virtual void modeTexture(M_BOOL bOn)=0
Enable/disable texturing.
void kill()
Discard window and all children.
Definition: uiLabel.cpp:68
laPoint3 _ptPos
Windos position (relative to parent)
Definition: uiWindow.h:75
#define M_AB
Text align bottom.
virtual void load(class laFileParser *fp)
Load a dialog layout form .cui file.
Definition: uiWindow.cpp:113
char _strText[256]
Text string.
Definition: uiLabel.h:44
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiLabel.cpp:52
#define M_AM
Text align middle.
#define M_AR
Text align right.
laPoint3 _ptSize
Window size.
Definition: uiWindow.h:76
M_BOOL _bCustomColor
Custom color, or use skin color if not set.
Definition: uiLabel.h:56
uiLabel(void)
Class Constructor.
Definition: uiLabel.cpp:39
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiWindow.cpp:99
#define M_AC
Text align center.
virtual void draw()
Draw event.
Definition: uiLabel.cpp:73
virtual void load(class laFileParser *fp)
Load from .cui file.
Definition: uiLabel.cpp:60
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void draw()
Display the window.
Definition: uiWindow.cpp:198
laPoint3 getPos()
Get relative window position with regard to parent.
Definition: uiWindow.h:132
laFont * _pFont
Pointer to active font.
Definition: uiLabel.h:45
File Parser.
Definition: laFileParser.h:41
virtual void kill()
Discard window and all children.
Definition: uiWindow.cpp:125