JNR
cuiProgressBar.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 // FILE: cuiProgressBar.cpp
32 //
33 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
34 //
35 #include "stdafx.h"
36 #include "GUI.h"
37 
38 #include "cuiProgressBar.h"
39 
40 cuiProgressBar::cuiProgressBar(void)
41 {
42  _Color = laColor(255,255,255);
43 
44  _dWidth = M_UNIT;
45  _dHeight = M_UNIT/10.0;
46 
47  _dMaxValue=1;
48  _dValue=0;
49 
50  _dLeftMargin = 0;
51  _dRightMargin = 0;
52 
53  _bTextures = M_FALSE;
54 }
55 
56 cuiProgressBar::~cuiProgressBar(void)
57 {
58 }
59 
60 void cuiProgressBar::draw(laRenderer* r, laPoint3 pos)
61 {
62  double Full_Width = ( (_dWidth-(_dLeftMargin+_dRightMargin))/_dMaxValue)*_dValue;
63  double Full_Width_m = ( (_dWidth-(_dLeftMargin+_dRightMargin))/_dMaxValue)*_dValue + _dLeftMargin;
64 
65  if(_texEmpty.id()) _texFull.use();
66 
67  _Color[3]= 255;
68 
69  r->vquadsMakeXYRect(0, pos, laPoint3(Full_Width_m, _dHeight), laPoint2(), laPoint2(Full_Width_m/_dWidth, 1));
70  r->styleSet(_Color);
71  r->vquadsDrawSingle();
72 
73  if(_bTextures)
74  {
75  _texEmpty.use();
76  }
77  else
78  {
79  _Color[3]= 100;
80  }
81 
82  pos[0] += Full_Width_m;
83 
84  r->vquadsMakeXYRect(0, pos, laPoint3(_dWidth-Full_Width_m, _dHeight), laPoint2(Full_Width_m/_dWidth,0), laPoint2(1-Full_Width_m/_dWidth, 1));
85  r->styleSet(_Color);
86  r->vquadsDrawSingle();
87 }
88 
89 void cuiProgressBar::setTextures(char* strEmptyTex, char* strFullTex, double dLeftMargin, double dRightMargin)
90 {
91  laRenderer* r = ::laSystemIntegrator::getRenderer();
92 
93  _bTextures = M_TRUE;
94  _texEmpty.load(strEmptyTex, M_TEX_TMAP);
95  _texFull.load(strFullTex, M_TEX_TMAP);
96 
97  _dLeftMargin = dLeftMargin;
98  _dRightMargin = dRightMargin;
99 }
#define M_UNIT
Unit of 1 meter.
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 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 interface for the Engine graphics renderer.
Definition: laRenderer.h:98
#define M_TEX_TMAP
Transparent texture with an alpha channel.