JNR
uiDialogBaloon.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 uiDialogBaloon::uiDialogBaloon(void)
34 {
35  _pAnimatedText = NULL;
36  _bMode3D = M_FALSE;
37 }
38 
39 uiDialogBaloon::~uiDialogBaloon(void)
40 {
41 }
42 
43 // Internal construction method,
44 // called by create() and load()
45 void uiDialogBaloon::init()
46 {
47  uiContainer::init();
48 
49  //Textures
50  tbg = _pSkin->parameter("TX_BALOON_WNDBG").texture();
51  tborder_h = _pSkin->parameter("TX_BALOON_WNDBR_H").texture();
52  tborder_v = _pSkin->parameter("TX_BALOON_WNDBR_V").texture();
53  tangle = _pSkin->parameter("TX_BALOON_WNDAN").texture();
54 
55  col = _pSkin->parameter("CL_BALOON").color();
56  ptShadowOffset[0] = _pSkin->parameter("BALOON_SHADOW_OFFSETX").dval();
57  ptShadowOffset[1] = _pSkin->parameter("BALOON_SHADOW_OFFSETX").dval();
58 }
59 
60 #include <GL\GL.h>
61 
62 void uiDialogBaloon::drawBorders()
63 {
64  glEnable(GL_STENCIL_TEST); // in order to shouw up on top of the cinematic shutter
65  glStencilFunc(GL_ALWAYS, 1 /*p.id/*1*/, 0xFFF /*-1*/);
66  glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); //only if no obstacle;
67  glDisable(GL_DEPTH_TEST);
68 
69  uiContainer::drawBorders();
70 
71  laPoint3 pos = getPos();
72  laPoint3 size = getSize();
73 
74  //size[0] += M_UNIT/10.0;
75  //size[1] += M_UNIT/10.0;
76  pos[0] += size.x()/2;
77 
78  laRenderer *r = laSystemIntegrator::getRenderer();
79  r->modeTexture(M_FALSE);
80  r->modeLight(M_FALSE);
81  //r->styleSet(laColor(255,255,255,255));
82  glBegin(GL_TRIANGLES);
83  glVertex2f( _ptMouthPos.x(), _ptMouthPos.y() );
84  glVertex2f( M_MIN(pos.x() + 40, pos.x() + size.x()/2 - 40), pos.y() + size.y() - 1);
85  glVertex2f( pos.x(), pos.y() + size.y() - 1);
86  glEnd();
87 
88  glDisable(GL_STENCIL_TEST);
89 }
90 
91 // Repply
92 void uiDialogBaloon::reply()
93 {
95 
96  if(_pAnimatedText) _pAnimatedText->animate( *(laSystemIntegrator::getEnvironment()->getTimer()) );
97 }
98 
99 void uiDialogBaloon::draw()
100 {
101  laRenderer *r = laSystemIntegrator::getRenderer();
102  double scale = M_UNIT*0.005;
103 
104  if(_bMode3D)
105  {
106  _ptPos /= scale;
107  _ptSize /= scale;
108  _ptMouthPos /= scale;
109  if(_pAnimatedText) _pAnimatedText->fontSz( _pAnimatedText->getFontSz()/scale );
110 
111  r->transPush();
112  r->transScale( laPoint3(scale, scale, 1) );
113  }
114 
116  if(_pAnimatedText)
117  {
118  double ofs;
119 
120  switch( _pAnimatedText->fontAlign() )
121  {
122  case M_AL: ofs = 0; break;
123  case M_AC: ofs = getSize().x()/2; break;
124  case M_AR: ofs = getSize().x(); break;
125  }
126 
127  _pAnimatedText->draw( r, getPos()
128  + laPoint3(ofs + (_ptSize.x() - _pAnimatedText->width())/2.0,
129  (_ptSize.y() - _pAnimatedText->height())/2.0 )
130  );
131  }
132 
133  if(_bMode3D)
134  {
135  r->transPop();
136 
137  _ptPos *= scale;
138  _ptSize *= scale;
139  _ptMouthPos *= scale;
140 
141  if(_pAnimatedText) _pAnimatedText->fontSz( _pAnimatedText->getFontSz()*scale );
142  }
143 }
virtual void modeTexture(M_BOOL bOn)=0
Enable/disable texturing.
#define M_UNIT
Unit of 1 meter.
#define M_AL
Text align left.
#define M_AR
Text align right.
virtual void draw()
Display the window.
#define M_AC
Text align center.
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void modeLight(M_BOOL bOn)=0
Enable/disable lighting.
virtual void reply()
Handle input message.