JNR
uiProgress.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 uiProgress::uiProgress(void)
34 {
35  //Defaults
36  _dMin = 0;
37  _dMax = 1;
38  _dCurrent = 0.9;
39  _pTask = NULL;
40 }
41 
42 uiProgress::~uiProgress(void)
43 {
44 }
45 
46 // Internal construction method,
47 // called by create() and load()
48 void uiProgress::init()
49 {
50  //Textures
51  _tBorder = _pSkin->parameter("TX_EDIT").texture();
52  _tProgress = _pSkin->parameter("TX_PROGRESS").texture();
53 }
54 
55 //Create
56 void uiProgress::create(laPoint3 pos, laPoint3 size)
57 {
58  //Create window
59  uiWindow::create(pos, size);
60 
61  //Initialize stuff
62  this->init();
63 }
64 
66 {
67  //Read window
68  uiWindow::load(fp);
69 
70  //Read range
71  fp->readDouble(&_dMin, M_FALSE);
72  fp->readDouble(&_dMax, M_FALSE);
73  fp->readDouble(&_dCurrent, M_FALSE);
74 
75  //Initialize stuff
76  this->init();
77 }
78 
80 {
82 }
83 
84 //Draw & reply methods
86 {
87  laRenderer* pr = ::laSystemIntegrator::getRenderer();
88 
89  double dLWidth = (_tBorder.w)/4.0;
90 
91  //Use the task object to update progress
92  if(_pTask)
93  {
94  _dMin = 0;
95  _dMax = 1;
96  _dCurrent = _pTask->progress();
97  }
98 
99  //Draw border
100  //
101  pr->vquadsMakeXYRect(0,
102  _ptPos, laPoint3(dLWidth, _ptSize.y()),
103  laPoint2(), laPoint2(0.25, 1));
104 
105  pr->vquadsMakeXYRect(1,
106  _ptPos + laPoint3(dLWidth, 0), _ptSize - laPoint3(2*dLWidth, 0),
107  laPoint2(0.25, 0), laPoint2(0.8-0.25, 1));
108 
109  pr->vquadsMakeXYRect(2,
110  _ptPos + laPoint3(_ptSize.x(), 0), laPoint3(-dLWidth, _ptSize.y()),
111  laPoint2(), laPoint2(0.25, 1));
112 
113  pr->styleSet( _pSkin->parameter("CL_BUTTON").color() );
114  _tBorder.use();
115  pr->vquadsDraw(3);
116 
117  //Draw progress
118  //
119  laPoint3 ptSize = _ptSize + laPoint3(-14, -10);
120  double dFraction = (_dCurrent-_dMin)/ (_dMax-_dMin);
121  ptSize[0] *= dFraction;
122 
123  pr->vquadsMakeXYRect(0,
124  _ptPos + laPoint3(4+3, 4+2), ptSize,
125  laPoint2(0,0), laPoint2(dFraction, 1));
126 
127  _tProgress.use();
128  pr->styleSet( _pSkin->parameter("CL_SHADOW_DARK").color() );
129  pr->vquadsDrawSingle();
130 
131  pr->vquadsMakeXYRect(1,
132  _ptPos + laPoint3(4, 4), ptSize,
133  laPoint2(0,0), laPoint2(dFraction, 1));
134 
135  _tProgress.use();
136  pr->styleSet( _pSkin->parameter("CL_BUTTON").color() );
137  pr->vquadsDrawSingle();
138 
139  uiWindow::draw();
140 }
141 
142 void uiProgress::setRange( double min, double max)
143 {
144  _dMin = min;
145  _dMax = max;
146  limitValue();
147 }
148 
149 void uiProgress::setValue( double val)
150 {
151  _dCurrent = val;
152  limitValue();
153 }
laPoint3 _ptPos
Windos position (relative to parent)
Definition: uiWindow.h:75
virtual void kill()
Discard window and all children.
Definition: uiProgress.cpp:79
virtual void load(class laFileParser *fp)
Load a dialog layout form .cui file.
Definition: uiWindow.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) ...
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: uiProgress.cpp:56
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
virtual void vquadsDraw(unsigned nQuads, laPoint2 *ar_uv=NULL, laColor *ar_color=NULL, M_BOOL bBillboards=M_FALSE, M_BOOL bUseColorArrays=M_FALSE)=0
Draw an array of VQ, starting with the psecified pointers (or the first VQ if null) ...
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiWindow.cpp:99
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void draw()
Display the window.
Definition: uiWindow.cpp:198
File Parser.
Definition: laFileParser.h:41
virtual void kill()
Discard window and all children.
Definition: uiWindow.cpp:125