Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/elements/glgui_energywidgetvertical.cc @ 10541

Last change on this file since 10541 was 10516, checked in by patrick, 18 years ago

merged playability back to trunk

File size: 4.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "glgui_energywidgetvertical.h"
19
20#include "multi_type.h"
21#include <iostream>
22#include "math.h"
23#include "glgui_image.h"
24
25namespace OrxGui
26{
27  /**
28   * @brief standard constructor
29   */
30  GLGuiEnergyWidgetVertical::GLGuiEnergyWidgetVertical ()
31  {
32    this->_bar = new GLGuiBar();
33    this->_valueText = new GLGuiText();
34    this->_image = new GLGuiImage();
35
36    this->setAbsDir2D(270);
37    this->setBackgroundTexture(Texture());
38    this->setBackgroundColor(Color(1,1,1,0));
39    this->setBorderTop(10);
40    this->setBorderLeft(10);
41    this->setBorderRight(10);
42    this->setBorderBottom(10);
43    this->setWidgetSize(120,50);
44
45    this->_bar->setParent2D(this);
46    this->_bar->setBackgroundTexture(Texture());
47    this->_bar->setBackgroundColor(Color(0,0,0,0));
48    this->_bar->setForegroundTexture("textures/gui/gui_element_background_faded.png");
49    this->_bar->setForegroundColor(Color::green);
50    this->_bar->setChangedValueColor(Color(1,0,0,0.2));
51    this->_bar->setBorderTop(0);
52    this->_bar->setBorderLeft(0);
53    this->_bar->setBorderRight(0);
54    this->_bar->setBorderBottom(0);
55    this->_bar->setWidgetSize(100,30);
56    //this->_bar.setRelCoor2D(borderLeft(), 0);
57    this->_bar->setRelCoor2D(0,0);
58
59    this->_image->setParent2D(this);
60    this->_image->setBorderTop(0);
61    this->_image->setBorderLeft(0);
62    this->_image->setBorderRight(0);
63    this->_image->setBorderBottom(0);
64    this->_image->setWidgetSize(30,30);
65    this->_image->setForegroundColor(Color(1,1,1,0.6));
66    this->_image->setBackgroundTexture(Texture());
67    this->_image->setBackgroundColor(Color(1,1,1,0));
68    this->_image->loadImageFromFile("textures/evil-flower.png");
69    //this->_image.setRelCoor2D(borderLeft(), borderTop() + this->_bar.getSizeX2D());
70    this->_image->setRelCoor2D(0,0);
71    this->_image->setRelDir2D(90);
72    this->_image->setVisibility(true);
73
74
75    this->_valueText->setParent2D(this->_bar);
76    this->_valueText->setWidgetSize(100,20);
77    //this->_valueText.setRelCoor2D(borderLeft(), borderTop() + this->_bar.getSizeX2D());
78    this->_valueText->setAbsCoor2D(-15,-20);
79    this->_valueText->setChangedTextColor(Color::white);
80    this->_valueText->setForegroundColor(Color::white);
81    this->_valueText->setBackgroundTexture(Texture());
82    this->_valueText->setBackgroundColor(Color(0,0,0,0));
83  }
84
85
86  /**
87   * @brief standard deconstructor
88   */
89  GLGuiEnergyWidgetVertical::~GLGuiEnergyWidgetVertical ()
90  {
91
92    if ( this->_valueText )
93    {
94      delete this->_valueText;
95      this->_valueText = NULL;
96    }
97
98    if ( this->_image )
99    {
100      delete this->_image;
101      this->_image = NULL;
102    }
103
104    /*
105    if ( this->_bar )
106    {
107      delete this->_bar;
108      this->_bar = NULL;
109    }
110    */
111  }
112
113  void GLGuiEnergyWidgetVertical::setMaximum(float max)
114  {
115    this->_bar->setMaximum(max);
116  }
117
118  void GLGuiEnergyWidgetVertical::setValue(float value)
119  {
120    MultiType val(value);
121    //MultiType val(200.00);
122    val.setType(MT_INT);
123
124
125    this->_bar->setValue(value);
126    this->_bar->setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar->maximum()));
127    //this->_bar.setFrontColor(Color(1,1,1,1), true);
128    this->_valueText->setText(val.getString());
129    //this->_valueText.setText("asdfas");
130  }
131
132  void GLGuiEnergyWidgetVertical::setDisplayedImage(const std::string& imageName)
133  {
134    this->_image->loadImageFromFile(imageName);
135  }
136
137  void GLGuiEnergyWidgetVertical::resize()
138  {
139    Vector2D widgetSize = this->getSize2D();
140
141    this->setBorderTop(widgetSize.y * 0.1);
142    this->setBorderBottom(widgetSize.y * 0.1);
143    this->setBorderLeft(widgetSize.x * 0.2);
144    this->setBorderRight(widgetSize.x * 0.2);
145
146    this->_bar->setWidgetSize(widgetSize.x * 0.8, widgetSize.y * 0.6);
147    this->_image->setWidgetSize(widgetSize.y * 0.6, widgetSize.y * 0.6);
148    this->_valueText->setWidgetSize(widgetSize.x* 0.8, widgetSize.y * 0.4);
149  }
150
151
152  void GLGuiEnergyWidgetVertical::showing()
153  {
154
155    this->_bar->show();
156    this->_image->show();
157    this->_valueText->show();
158  }
159
160  void GLGuiEnergyWidgetVertical::hiding()
161  {
162    this->_image->hide();
163    this->_valueText->hide();
164    this->_bar->hide();
165  }
166}
Note: See TracBrowser for help on using the repository browser.