JNR
uiSlider.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 #include "stdafx.h"
31 #include "GUI.h"
32 
33 uiSlider::uiSlider(void)
34 {
35  sprintf(_strValueFormat, "%%.1f");
36 }
37 
38 uiSlider::~uiSlider(void)
39 {
40 }
41 
42 
43 void uiSlider::init()
44 {
45  uiProgress::init();
46 
47  _uiBtn.create( laPoint3(_ptSize.x(), -3), laPoint3(_ptSize.y(), _ptSize.y()+6));
48  _uiBtn._pParent = this;
49  _uiBtn.setFraction( (_dCurrent-_dMin) / (_dMax-_dMin) );
50 
51  _uiValueLabel.create( laPoint3(_ptSize.x()+_ptSize.y()-5, 0), laPoint3(40, _ptSize.y()) );
52  _uiValueLabel._pParent = this;
53  _uiValueLabel.align(M_AL, M_AM);
54 }
55 
57 {
58  //Read window
59  uiProgress::load(fp);
60 
61  //Read value format
62  fp->readText(_strValueFormat, M_FALSE);
63 
64  //Initialize stuff
65  this->init();
66 }
67 
68 //Reply
70 {
71  _uiBtn.reply();
72  _dCurrent = _uiBtn.getFraction()*(_dMax-_dMin) + _dMin;
73  limitValue();
74 
76 }
77 
78 // Draw
80 {
81  laRenderer* r = ::laSystemIntegrator::getRenderer();
82 
83  //draw myself
85 
86  r->transPush();
87  //draw button
88  r->transTranslate( _ptPos + getDecorationSize() );
89  _uiBtn.draw();
90 
91  //print value
92  char str[32];
93  sprintf(str, _strValueFormat, _dCurrent);
94  _uiValueLabel.setText(str);
95  _uiValueLabel.draw();
96  r->transPop();
97 
98 }
99 
100 //Init
101 void uiSlidingButton::init()
102 {
103  uiContainer::init();
104  toggleMoveable(M_TRUE, 1);
105 
106  _t = _pSkin->parameter("TX_SLIDER_BTN").texture();
107  toggleBorders(M_FALSE);
108  caption.show();
109  caption.move(laPoint3(), M_AC, M_AM);
110 }
111 
112 // Reply
114 {
115  //Use the uiContainer dragging cpapabilities
116  laPoint3 pos = _ptPos;
118 
119  //Limit slider position
120  if( pos.y() != _ptPos.y()) _ptPos[1] = pos.y();
121  if( _ptPos.x() < 3) _ptPos[0] = 3;
122  if( _ptPos.x() > _pParent->getSize().x()-10) _ptPos[0] = _pParent->getSize().x()-10;
123 }
124 
125 // Draw
127 {
128  laRenderer* pr = ::laSystemIntegrator::getRenderer();
129  _t.use();
130 
131  // drop shadow
132  //
133  //pr->transPush();
134  //pr->transTranslate( laPoint3(3,4) );
135  pr->vquadsMakeXYRect(0, _ptPos + laPoint3(3,4), _ptSize, laPoint2(), laPoint2(1, 1));
136  pr->styleSet( _pSkin->parameter("CL_SHADOW").color() );
137  pr->vquadsDrawSingle();
138  //pr->transPop();
139 
140  // draw button
141  pr->vquadsMakeXYRect(0, _ptPos, _ptSize, laPoint2(), laPoint2(1, 1));
142  pr->styleSet( _pSkin->parameter("CL_CONTAINER").color() );
143  pr->vquadsDrawSingle();
144 }
laPoint3 _ptPos
Windos position (relative to parent)
Definition: uiWindow.h:75
virtual void reply()
Handle input message.
Definition: uiSlider.cpp:113
virtual void vquadsDrawSingle(laPoint2 *ar_uv=NULL)=0
Draw a single VQ (Note this is slower than drawing an array of VQ and should be avoided) ...
virtual void move(laPoint3 ptNewPos, unsigned nHReference=M_AL, unsigned nVReference=M_AT)
Change window position.
Definition: uiWindow.cpp:51
2D Point
Definition: laPoint_novec.h:41
void draw()
Display the window.
Definition: uiProgress.cpp:85
void vquadsMakeXYRect(unsigned nIndex, const laPoint3 &pos, const laPoint3 &sz, const laPoint2 &uv, const laPoint2 &uv_sz)
Makes a quad aligned to the XY plane; (handy for GUI rendering )
Definition: laRenderer.h:328
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiLabel.cpp:52
#define M_AM
Text align middle.
virtual void draw()
Display the window.
Definition: uiSlider.cpp:79
#define M_AL
Text align left.
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiContainer.cpp:97
uiLabel caption
Caption.
Definition: uiContainer.h:83
laPoint3 _ptSize
Window size.
Definition: uiWindow.h:76
virtual void load(class laFileParser *fp)
Load a dialog layout form .cui file.
Definition: uiProgress.cpp:65
uiWindow * _pParent
Pointer to parent window, if any.
Definition: uiWindow.h:71
virtual void reply()
Handle input message.
Definition: uiSlider.cpp:69
void load(class laFileParser *fp)
Load a dialog layout form .cui file.
Definition: uiSlider.cpp:56
#define M_AC
Text align center.
virtual void draw()
Draw event.
Definition: uiLabel.cpp:73
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
void toggleBorders(M_BOOL bEnable)
Toggle border visbility.
Definition: uiContainer.h:87
virtual void draw()
Display the window.
Definition: uiSlider.cpp:126
virtual void reply()
Handle input message.
Definition: uiWindow.cpp:130
void toggleMoveable(M_BOOL bEnable, unsigned nButton=0)
Toggle moveable flag.
Definition: uiContainer.h:95
virtual void reply()
Handle input message.
File Parser.
Definition: laFileParser.h:41