JNR
uiIcon3D.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 uiIcon3D::uiIcon3D(uiIconDescriptor3D *dsc)
34 {
35  ASSERT(dsc!=NULL, "Nil icon descriptor.");
36 
37  _pDescriptor = dsc;
38  _isDiscarded = _isDiscarding = M_FALSE;
39 
40  _ttAppear.parameters(2);
41  _ttAppear.enable();
42 
43  _ttDiscard.parameters(1);
44  _ttDiscard.enable(M_FALSE);
45 
46  ticon3d_bg = _pSkin->parameter("TX_ICON3D").texture();
47  ticon3d_sel = _pSkin->parameter("TX_ICON3D_SEL").texture();
48  create(laPoint3(), laPoint3());
49 
50  _ang = rand()%360;
51  _bSelected = M_FALSE;
52 }
53 
54 uiIcon3D::~uiIcon3D(void)
55 {
56  delete _pDescriptor;
57 }
58 
59 void uiIcon3D::discardingIcon(M_BOOL bOn)
60 {
61  _isDiscarding = bOn;
62  _ttDiscard.enable(bOn);
63  _ttDiscard.reset();
64  _isDiscarding = bOn;
65  if(!bOn) _isDiscarded = M_FALSE;
66 }
67 
69 {
70  ASSERT(_pDescriptor, "Nil icon descriptor.");
71 
72  laRenderer *pr = ::laSystemIntegrator::getRenderer();
73  laTimer *pt = ::laSystemIntegrator::getEnvironment()->getTimer();
74 
75  //Appear/diappear
76  //
77  double alpha = 255;
78  double scale = 1;
79 
80  if( !_ttAppear.isElapsed() )
81  {
82  alpha = (1-_ttAppear.reminder())*255;
83  }
84 
85  if( _ttDiscard.isEnabled() )
86  {
87  alpha = _ttDiscard.reminder()*255;
88  scale = _ttDiscard.reminder();
89  }
90 
91  pr->transPush();
92  pr->transTranslate( _ptPos );
93  pr->transScale( laPoint3( scale, scale, 1) );
94 
95  // Draw selection
96  //
97  pr->modeLight(M_FALSE);
98 
99  if( _bSelected )
100  {
101  laColor col = _pSkin->parameter("CL_CONTAINER_SELECTED").color();
102  col[3]= alpha;
103 
104  pr->vquadsMakeXYRect(0,
105  laPoint3(), laPoint3(ticon3d_sel.w, ticon3d_sel.h),
106  laPoint2(), laPoint2(1,1) );
107 
108  pr->styleSet( col );
109  ticon3d_sel.use();
110  pr->vquadsDrawSingle();
111  }
112  else
113  {
114  laColor col = _pSkin->parameter("CL_CONTAINER").color();
115  col[3]= alpha;
116  pr->styleSet( col );
117  }
118 
119  // Draw icon background
120  //
121  pr->vquadsMakeXYRect(0, laPoint3((ticon3d_sel.w - ticon3d_bg.w)/2.0, (ticon3d_sel.h - ticon3d_bg.h)/2.0),
122  laPoint3(ticon3d_bg.w, ticon3d_bg.h),
123  laPoint2(), laPoint2(1,1) );
124 
125  ticon3d_bg.use();
126  pr->vquadsDrawSingle();
127 
128  // Draw 3D icon
129  //
130  pr->modeLight(M_TRUE);
131  pr->modeDepthBuffer(M_TRUE);
132  pr->modeOutline( laOutline(M_TRUE, laColor(), 1) );
133 
134  pr->lightAmbient(0, laColor(100,100,100,255) );
135  pr->lightMakeSunlight(0, laPoint3( 0, 0, -2*M_UNIT ) );
136  pr->styleSet( laColor(255,255,255,alpha) );
137 
138  pr->transTranslate( laPoint3(ticon3d_sel.w*0.5, ticon3d_sel.h*0.5, 0) );
139 
140  pr->styleSet( _pSkin->parameter("CL_LABEL_TXT").color() );
141  _pSkin->parameter("FN_DEFAULT").font()->ctlAlignH(M_AL);
142  _pSkin->parameter("FN_DEFAULT").font()->ctlAlignV(M_AB);
143  _pSkin->parameter("FN_DEFAULT").font()->ctlSize(12);
144 
145  pr->modeLight(M_FALSE);
146  _pDescriptor->draw_description( laPoint3(ticon3d_sel.w*0.5, (int)-0.5*ticon3d_sel.w), pr, _pSkin->parameter("FN_DEFAULT").font() );
147 
148  pr->transScale( laPoint3( 1.2*ticon3d_bg.w/M_UNIT, 1.2*ticon3d_bg.w/M_UNIT, 1) );
149 
150  _ang+= pt->delta()*15;
151  pr->transRotate( 25, laPoint3(0,0,1) );
152  pr->transRotate( _ang, laPoint3(0,1,0) );
153 
154  pr->modeLight(M_TRUE);
155  _pDescriptor->draw_model( laPoint3(), pr );
156 
157  pr->modeOutline( laOutline(M_FALSE) );
158  pr->modeDepthBuffer(M_FALSE);
159  pr->modeLight(M_FALSE);
160 
161  pr->transPop();
162 }
163 
165 {
166  ASSERT(_pDescriptor, "Nil icon descriptor.");
167 
168  //Discard size mod
169  //
170  double scale = 1;
171 
172  if( _ttDiscard.isEnabled() )
173  scale = _ttDiscard.reminder();
174 
175  //Resize
176  laPoint3 ptDSz = _pDescriptor->description_size( _pSkin->parameter("FN_DEFAULT").font() );
177 
178  _ptSize[0] = scale*(ticon3d_sel.w + ptDSz.x());
179  _ptSize[1] = scale*M_MAX(ticon3d_sel.h, ptDSz.y());
180 
181  //_ptSize = ptDSz;
182  //_ptSize += laPoint3(ticon3d_sel.w, ticon3d_sel.h);
183 
184 
185  //Icon appearance/discarding timer
186  laTimer *pt = ::laSystemIntegrator::getEnvironment()->getTimer();
187 
188  if( _ttDiscard.isEnabled() && _ttDiscard.isElapsed() )
189  _isDiscarded = M_TRUE;
190 
191  _ttDiscard.animate(*pt);
192  _ttAppear.animate(*pt);
193 
194 }
laPoint3 _ptPos
Windos position (relative to parent)
Definition: uiWindow.h:75
#define M_AB
Text align bottom.
virtual void reply()
Handle input message.
Definition: uiIcon3D.cpp:164
#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
#define M_AL
Text align left.
Object outline properties.
Definition: laRenderer.h:66
laPoint3 _ptSize
Window size.
Definition: uiWindow.h:76
Abstract interface for icon descriptors; to be used in class uiIcon3D.
Definition: uiIcon3D.h:42
virtual void create(laPoint3 pos, laPoint3 size)
Create new empty window.
Definition: uiWindow.cpp:99
virtual void modeOutline(const laOutline &outline)
Set outline parameters.
Definition: laRenderer.h:174
virtual void modeDepthBuffer(M_BOOL bOn)=0
Enable/disable depth buffer.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void modeLight(M_BOOL bOn)=0
Enable/disable lighting.
virtual void draw()
Display the window.
Definition: uiIcon3D.cpp:68