Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CProgressBar.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19 CProgressBar
20 */
21 
22 #include "precompiled.h"
23 #include "GUI.h"
24 #include "CProgressBar.h"
25 
26 #include "lib/ogl.h"
27 
28 
29 //-------------------------------------------------------------------
30 // Constructor / Destructor
31 //-------------------------------------------------------------------
33 {
34  AddSetting(GUIST_CGUISpriteInstance, "sprite_background");
35  AddSetting(GUIST_CGUISpriteInstance, "sprite_bar");
36  AddSetting(GUIST_float, "caption"); // aka value from 0 to 100
37  AddSetting(GUIST_CStrW, "tooltip");
38  AddSetting(GUIST_CStr, "tooltip_style");
39 }
40 
42 {
43 }
44 
46 {
47  // Important
49 
50  switch (Message.type)
51  {
53  // Update scroll-bar
54  // TODO Gee: (2004-09-01) Is this really updated each time it should?
55  if (Message.value == CStr("caption"))
56  {
57  float value;
58  GUI<float>::GetSetting(this, "caption", value);
59  if (value > 100.f)
60  GUI<float>::SetSetting(this, "caption", 100.f);
61  else
62  if (value < 0.f)
63  GUI<float>::SetSetting(this, "caption", 0.f);
64  }
65  break;
66  default:
67  break;
68  }
69 }
70 
72 {
73  if (GetGUI())
74  {
75  float bz = GetBufferedZ();
76 
77  CGUISpriteInstance *sprite_background, *sprite_bar;
78  int cell_id = 0;
79  float value = 0;
80  GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
81  GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
82  GUI<float>::GetSetting(this, "caption", value);
83 
84  GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
85 
86 
87  // Get size of bar (notice it is drawn slightly closer, to appear above the background)
90  GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
91  }
92 }
void DrawSprite(const CGUISpriteInstance &Sprite, int CellID, const float &Z, const CRect &Rect, const CRect &Clipping=CRect())
Draw GUI Sprite.
Definition: CGUI.cpp:467
CStr value
Optional data.
Definition: GUIbase.h:127
float top
Definition: Overlay.h:159
float left
Returning CPos representing each corner.
Definition: Overlay.h:159
static PSRETURN GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value)
Retrieves a setting by name from object pointer.
Definition: GUIutil.cpp:344
void HandleMessage(SGUIMessage &Message)
virtual float GetBufferedZ() const
Returns not the Z value, but the actual buffered Z value, i.e.
Definition: IGUIObject.cpp:406
float GetWidth() const
Definition: Overlay.cpp:232
virtual ~CProgressBar()
virtual void Draw()
Draws the progress bar.
void AddSetting(const EGUISettingType &Type, const CStr &Name)
Add a setting to m_Settings.
Definition: IGUIObject.cpp:172
CRect m_CachedActualSize
Cached size, real size m_Size is actually dependent on resolution and can have different real outcome...
Definition: IGUIObject.h:434
CGUI * GetGUI()
Definition: IGUIObject.h:388
static PSRETURN SetSetting(IGUIObject *pObject, const CStr &Setting, const T &Value, const bool &SkipMessage=false)
Sets a value by name using a real datatype as input.
Definition: GUIutil.cpp:366
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:106
EGUIMessageType type
Describes what the message regards.
Definition: GUIbase.h:122
float bottom
Definition: Overlay.h:159
virtual void HandleMessage(SGUIMessage &Message)
This function is called with different messages for instance when the mouse enters the object...
Definition: IGUIObject.h:322
static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr &Setting, T *&Value)
Definition: GUIutil.cpp:317
Rectangle class used for screen rectangles.
Definition: Overlay.h:71