1
1
forked from 0ad/0ad

Progress bar added, and an optional attribute for the [icon] tags in text.

You can now displace an icon using: "[icon="smiley" displace="2 -3"]

I may rename it from 'displace' to something else if someone gives me a
good suggestion.

This was SVN commit r1232.
This commit is contained in:
Gee 2004-10-14 02:32:26 +00:00
parent 51fbfc57db
commit c4684effb6
5 changed files with 176 additions and 5 deletions

View File

@ -20,6 +20,7 @@ gee@pyro.nu
#include "CText.h"
#include "CCheckBox.h"
#include "CRadioButton.h"
#include "CProgressBar.h"
#include "MiniMap.h"
#include "ps/Xeromyces.h"
@ -264,6 +265,7 @@ void CGUI::Initialize()
AddObjectType("text", &CText::ConstructObject);
AddObjectType("checkbox", &CCheckBox::ConstructObject);
AddObjectType("radiobutton", &CRadioButton::ConstructObject);
AddObjectType("progressbar", &CProgressBar::ConstructObject);
AddObjectType("minimap", &CMiniMap::ConstructObject);
}
@ -997,7 +999,6 @@ void CGUI::LoadXMLFile(const string &Filename)
try
{
if (root_name == "objects")
{
Xeromyces_ReadRootObjects(node, &XeroFile);

75
source/gui/CProgressBar.cpp Executable file
View File

@ -0,0 +1,75 @@
/*
CProgressBar
by Gustav Larsson
gee@pyro.nu
*/
#include "precompiled.h"
#include "GUI.h"
#include "CProgressBar.h"
#include "ogl.h"
using namespace std;
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
CProgressBar::CProgressBar()
{
AddSetting(GUIST_CStr, "sprite-background");
AddSetting(GUIST_CStr, "sprite-bar");
AddSetting(GUIST_float, "caption"); // aka value from 0 to 100
}
CProgressBar::~CProgressBar()
{
}
void CProgressBar::HandleMessage(const SGUIMessage &Message)
{
// Important
IGUIObject::HandleMessage(Message);
switch (Message.type)
{
case GUIM_SETTINGS_UPDATED:
// Update scroll-bar
// TODO Gee: (2004-09-01) Is this really updated each time it should?
if (Message.value == CStr("caption"))
{
float value;
GUI<float>::GetSetting(this, "caption", value);
if (value > 100.f)
GUI<float>::SetSetting(this, "caption", 100.f);
else
if (value < 0.f)
GUI<float>::SetSetting(this, "caption", 0.f);
}
break;
default:
break;
}
}
void CProgressBar::Draw()
{
if (GetGUI())
{
float bz = GetBufferedZ();
CStr sprite_background, sprite_bar;
float value;
GUI<CStr>::GetSetting(this, "sprite-background", sprite_background);
GUI<CStr>::GetSetting(this, "sprite-bar", sprite_bar);
GUI<float>::GetSetting(this, "caption", value);
GetGUI()->DrawSprite(sprite_background, bz, m_CachedActualSize);
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
GetGUI()->DrawSprite(sprite_bar, bz+0.01f, bar_size);
}
}

61
source/gui/CProgressBar.h Executable file
View File

@ -0,0 +1,61 @@
/*
GUI Object - Progress bar
by Gustav Larsson
gee@pyro.nu
--Overview--
GUI Object to show progress or a value visually.
--More info--
Check GUI.h
*/
#ifndef CProgressBar_H
#define CProgressBar_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* Object used to draw a value from 0 to 100 visually.
*
* @see IGUIObject
*/
class CProgressBar : public IGUIObject
{
GUI_OBJECT(CProgressBar)
public:
CProgressBar();
virtual ~CProgressBar();
protected:
/**
* Draws the progress bar
*/
virtual void Draw();
// If caption is set, make sure it's within the interval 0-100
void HandleMessage(const SGUIMessage &Message);
};
#endif

View File

@ -141,7 +141,18 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
TextCall.m_Size = size;
SpriteCall.m_Area = size;
// TODO Gee: (2004-08-16) Eventually shouldn't be hardcoded
// Now displace the sprite if the additional value in the tag
// exists
if (itTextChunk->m_Tags[0].m_TagAdditionalValue != string())
{
CSize displacement;
// Parse the value
if (!GUI<CSize>::ParseString(itTextChunk->m_Tags[0].m_TagAdditionalValue, displacement))
LOG(ERROR, LOG_CATEGORY, "Error parsing 'displace' value for tag [ICON]");
else
SpriteCall.m_Area += displacement;
}
SpriteCall.m_TextureName = icon.m_TextureName;
// Add sprite call
@ -288,7 +299,8 @@ void CGUIString::SetValue(const CStrW& str)
// Setup parser
// TODO Gee: (2004-08-16) Create and store this parser object somewhere to save loading time.
CParser Parser;
Parser.InputTaskType("start", "$ident[_=_$value]");
// I've added the option of an additional parameter. Only used for icons when writing this.
Parser.InputTaskType("start", "$ident[_=_$value_[$ident_=_$value_]]");
Parser.InputTaskType("end", "/$ident");
long position = 0;
@ -354,7 +366,7 @@ void CGUIString::SetValue(const CStrW& str)
{
if (Line.m_TaskTypeName == "start")
{
// The tag
// The tag
TextChunk::Tag tag;
std::string Str_TagType;
@ -367,9 +379,26 @@ void CGUIString::SetValue(const CStrW& str)
else
{
// Check for possible value-strings
if (Line.GetArgCount() == 2)
if (Line.GetArgCount() >= 2)
Line.GetArgString(1, tag.m_TagValue);
// Check if an additional parameter was specified
if (Line.GetArgCount() == 4)
{
string str;
Line.GetArgString(2, str);
if (tag.m_TagType == TextChunk::Tag::TAG_ICON &&
str == "displace")
{
Line.GetArgString(3, tag.m_TagAdditionalValue);
}
else
{
LOG(WARNING, LOG_CATEGORY, "Trying to declare an additional attribute ('%s') in a [%s]-tag, which the tag isn't accepting", str.c_str(), Str_TagType.c_str());
}
}
// Finalize last
if (curpos != from_nonraw)
{

View File

@ -202,6 +202,11 @@ public:
* m_TagValue is 'Hello'
*/
std::string m_TagValue;
/**
* Some tags need an additional value
*/
std::string m_TagAdditionalValue;
};
/**