1
0
forked from 0ad/0ad

Major updates

This was SVN commit r141.
This commit is contained in:
Gee 2003-12-27 06:26:03 +00:00
parent b111349e53
commit e21ebb37f5
28 changed files with 1822 additions and 234 deletions

140
binaries/data/gui/gui.dtd Executable file
View File

@ -0,0 +1,140 @@
<!--
<objects>
-->
<!ELEMENT objects (object*)>
<!ELEMENT object (#PCDATA|object|action)*>
<!--
Base Settings
-->
<!ATTLIST object name CDATA #IMPLIED>
<!ATTLIST object type CDATA #IMPLIED>
<!ATTLIST object absolute (true|false) #IMPLIED>
<!ATTLIST object enabled (true|false) #IMPLIED>
<!ATTLIST object ghost (true|false) #IMPLIED>
<!ATTLIST object hidden (true|false) #IMPLIED>
<!ATTLIST object size CDATA #IMPLIED>
<!ATTLIST object style CDATA #IMPLIED>
<!ATTLIST object z CDATA #IMPLIED>
<!--
Setting Pool
-->
<!ATTLIST object font CDATA #IMPLIED>
<!ATTLIST object input-initvalue-destroyed-at-focus (true|false) #IMPLIED>
<!ATTLIST object rectcolor-selected CDATA #IMPLIED>
<!ATTLIST object scrollbar (true|false) #IMPLIED>
<!ATTLIST object scrollbar-style CDATA #IMPLIED>
<!ATTLIST object sprite CDATA #IMPLIED>
<!ATTLIST object sprite2 CDATA #IMPLIED>
<!ATTLIST object sprite-disabled CDATA #IMPLIED>
<!ATTLIST object sprite2-disabled CDATA #IMPLIED>
<!ATTLIST object sprite-over CDATA #IMPLIED>
<!ATTLIST object sprite2-over CDATA #IMPLIED>
<!ATTLIST object sprite-pressed CDATA #IMPLIED>
<!ATTLIST object square-side CDATA #IMPLIED>
<!ATTLIST object textalign (left|center|right) #IMPLIED>
<!ATTLIST object textcolor CDATA #IMPLIED>
<!ATTLIST object textcolor-disabled CDATA #IMPLIED>
<!ATTLIST object textcolor-over CDATA #IMPLIED>
<!ATTLIST object textcolor-pressed CDATA #IMPLIED>
<!ATTLIST object textcolor-selected CDATA #IMPLIED>
<!ATTLIST object textvalign (top|center|bottom) #IMPLIED>
<!ATTLIST object tooltip CDATA #IMPLIED>
<!ATTLIST object tooltip-style CDATA #IMPLIED>
<!--
GUI XML Files DTD
Root Element: <styles>
Version:
-->
<!ELEMENT styles (style*)>
<!ELEMENT style (#PCDATA)>
<!ATTLIST style name CDATA #REQUIRED>
<!--
Setting Pool
-->
<!ATTLIST style absolute (true|false) #IMPLIED>
<!ATTLIST style enabled (true|false) #IMPLIED>
<!ATTLIST style ghost (true|false) #IMPLIED>
<!ATTLIST style hidden (true|false) #IMPLIED>
<!ATTLIST style size CDATA #IMPLIED>
<!ATTLIST style z CDATA #IMPLIED>
<!ATTLIST style font CDATA #IMPLIED>
<!ATTLIST style input-initvalue-destroyed-at-focus (true|false) #IMPLIED>
<!ATTLIST style rectcolor-selected CDATA #IMPLIED>
<!ATTLIST style scrollbar (true|false) #IMPLIED>
<!ATTLIST style scrollbar-style CDATA #IMPLIED>
<!ATTLIST style sprite CDATA #IMPLIED>
<!ATTLIST style sprite2 CDATA #IMPLIED>
<!ATTLIST style sprite-disabled CDATA #IMPLIED>
<!ATTLIST style sprite2-disabled CDATA #IMPLIED>
<!ATTLIST style sprite-over CDATA #IMPLIED>
<!ATTLIST style sprite2-over CDATA #IMPLIED>
<!ATTLIST style sprite-pressed CDATA #IMPLIED>
<!ATTLIST style square-side CDATA #IMPLIED>
<!ATTLIST style textalign (left|center|right) #IMPLIED>
<!ATTLIST style textcolor CDATA #IMPLIED>
<!ATTLIST style textcolor-disabled CDATA #IMPLIED>
<!ATTLIST style textcolor-over CDATA #IMPLIED>
<!ATTLIST style textcolor-pressed CDATA #IMPLIED>
<!ATTLIST style textcolor-selected CDATA #IMPLIED>
<!ATTLIST style textvalign (top|center|bottom) #IMPLIED>
<!ATTLIST style tooltip CDATA #IMPLIED>
<!ATTLIST style tooltip-style CDATA #IMPLIED>
<!--
GUI XML Files DTD
Root Element: <setup>
Version:
-->
<!ELEMENT setup (icon*,scrollbar*,tooltip*)>
<!ELEMENT scrollbar (#PCDATA)>
<!ELEMENT icon (#PCDATA)>
<!ELEMENT tooltip (#PCDATA)>
<!--
<scrollbar>
-->
<!ATTLIST scrollbar name CDATA #REQUIRED>
<!ATTLIST scrollbar width CDATA #IMPLIED>
<!ATTLIST scrollbar scroll-wheel CDATA #IMPLIED>
<!ATTLIST scrollbar alwaysshown CDATA #IMPLIED>
<!ATTLIST scrollbar scroll-speed CDATA #IMPLIED>
<!--
GUI XML Files DTD
Root Element: <sprites>
Version:
-->
<!ELEMENT sprites (sprite*)>
<!ELEMENT sprite (image+)>
<!ELEMENT image (#PCDATA)>
<!--
<sprite>
-->
<!ATTLIST sprite name CDATA #REQUIRED>
<!--
<image>
-->
<!ATTLIST image texture CDATA #IMPLIED>
<!ATTLIST image size CDATA #IMPLIED>
<!ATTLIST image texture_size CDATA #IMPLIED>
<!ATTLIST image backcolor CDATA #IMPLIED>
<!ATTLIST image bordercolor CDATA #IMPLIED>
<!ATTLIST image border (true|false) #IMPLIED>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE objects SYSTEM "objects.dtd">
<!DOCTYPE objects SYSTEM "gui.dtd">
<objects>
<!-- Empty GUI -->
<!-- Empty GUI, Download Hello2.xml and replace with this. -->
</objects>

View File

@ -1,9 +1,27 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE objects SYSTEM "objects.dtd">
<!DOCTYPE objects SYSTEM "gui.dtd">
<objects>
<object
name="backdrop"
type="text"
sprite="sprite1-disabled"
size="200 150 320 700"
scrollbar-style="sb"
z="100"
/>
<object
name="backdrop2"
type="text"
sprite="sprite1-disabled"
size="600 300 920 500"
scrollbar-style="sb"
z="100"
/>
<object
name="Child1"
type="button"
@ -19,14 +37,16 @@
style="button"
size="10 10 140 40"
z="200"
/>
>
</object>
<object
name="Child3"
type="button"
style="button"
size="150 10 280 40"
z="200"
z="200"
/>
<object

7
binaries/data/gui/setup.xml Executable file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE setup SYSTEM "gui.dtd">
<setup>
<scrollbar name="sb" width="25" />
</setup>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE sprites SYSTEM "sprites.dtd">
<!DOCTYPE sprites SYSTEM "gui.dtd">
<sprites>
<sprite name="sprite1">
@ -45,6 +45,21 @@
<image backcolor="176 37 37" size="2 2 100%-2 100%-2" />
</sprite>
<sprite name="sprite1-disabled">
<image backcolor="128 0 128" size="0 0 100% 100%" />
</sprite>
<sprite name="grey">
<image backcolor="128 128 128" size="0 0 100% 100%" />
</sprite>
<sprite name="blue">
<image backcolor="128 0 0" size="0 0 100% 100%" />
</sprite>
<sprite name="sprite2">
<!-- Starting with top left corner continuing in a counter-clockwise manner -->
<image backcolor="255 0 0" size="0 0 20 20" />

View File

@ -1,12 +1,21 @@
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE styles SYSTEM "styles.dtd">
<!DOCTYPE styles SYSTEM "gui.dtd">
<styles>
<!-- The default values -->
<style name="default"
hidden="false"
enabled="true"
z="0"
absolute="true"
/>
<style name="button"
sprite="sprite1"
sprite-over="sprite1-over"
sprite-pressed="sprite1-pressed"
sprite2="hejsan"
sprite-disabled="sprite1-disabled"
/>
</styles>

View File

@ -7,7 +7,7 @@ gee@pyro.nu
//#include "stdafx."
#include "GUI.h"
// temp GeeTODO
// TODO Gee: font.h is temporary.
#include "font.h"
#include "ogl.h"
@ -22,7 +22,7 @@ DECLARE_SETTINGS_INFO(SButtonSettings)
CButton::CButton()
{
// Settings defaults !
m_Settings.m_Disabled = false;
/* m_Settings.m_Disabled = false;
m_Settings.m_Font = "null";
m_Settings.m_Sprite = "null";
m_Settings.m_SpriteDisabled = "null";
@ -36,7 +36,7 @@ CButton::CButton()
m_Settings.m_TextValign = EValign_Center;
m_Settings.m_ToolTip = "null";
m_Settings.m_ToolTipStyle = "null";
*/
// Static! Only done once
if (m_SettingsInfo.empty())
@ -44,9 +44,10 @@ CButton::CButton()
// Setup the base ones too
SetupBaseSettingsInfo(m_SettingsInfo);
GUI_ADD_OFFSET_EXT(SButtonSettings, m_Sprite, "string", "sprite")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_SpriteOver, "string", "sprite-over")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_SpritePressed,"string", "sprite-pressed")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_Sprite, "string", "sprite")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_SpriteOver, "string", "sprite-over")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_SpritePressed, "string", "sprite-pressed")
GUI_ADD_OFFSET_EXT(SButtonSettings, m_SpriteDisabled, "string", "sprite-disabled")
}
}
@ -54,12 +55,12 @@ CButton::~CButton()
{
}
void CButton::HandleMessage(const EGUIMessage &Message)
void CButton::HandleMessage(const SGUIMessage &Message)
{
// Important
IGUIButtonBehavior::HandleMessage(Message);
switch (Message)
switch (Message.type)
{
case GUIM_PREPROCESS:
break;
@ -91,7 +92,7 @@ void CButton::HandleMessage(const EGUIMessage &Message)
}
}
void CButton::Draw()
void CButton::Draw()
{
////////// Gee: janwas, this is just temp to see it
glDisable(GL_TEXTURE_2D);
@ -99,12 +100,29 @@ void CButton::Draw()
if (GetGUI())
{
if (m_Pressed && m_Settings.m_SpritePressed != CStr("null"))
GetGUI()->DrawSprite(m_Settings.m_SpritePressed, GetBaseSettings().m_Z, m_CachedActualSize);
bool useBase = false;
if (!GetBaseSettings().m_Enabled)
{
if (m_Settings.m_SpriteDisabled != CStr("null"))
GetGUI()->DrawSprite(m_Settings.m_SpriteDisabled, GetBufferedZ(), m_CachedActualSize);
else
useBase = true;
}
else
if (m_MouseHovering && !m_Pressed && m_Settings.m_SpriteOver != CStr("null"))
GetGUI()->DrawSprite(m_Settings.m_SpriteOver, GetBaseSettings().m_Z, m_CachedActualSize);
else
GetGUI()->DrawSprite(m_Settings.m_Sprite, GetBaseSettings().m_Z, m_CachedActualSize);
if (m_MouseHovering)
{
if (m_Pressed && m_Settings.m_SpritePressed != CStr("null"))
GetGUI()->DrawSprite(m_Settings.m_SpritePressed, GetBufferedZ(), m_CachedActualSize);
else
if (!m_Pressed && m_Settings.m_SpriteOver != CStr("null"))
GetGUI()->DrawSprite(m_Settings.m_SpriteOver, GetBufferedZ(), m_CachedActualSize);
else
useBase = true;
}
else useBase = true;
if (useBase)
GetGUI()->DrawSprite(m_Settings.m_Sprite, GetBufferedZ(), m_CachedActualSize);
}
}

View File

@ -38,7 +38,6 @@ gee@pyro.nu
*/
struct SButtonSettings
{
bool m_Disabled;
CStr m_Font;
CStr m_Sprite;
CStr m_SpriteDisabled;
@ -88,7 +87,7 @@ public:
*
* @param Message GUI Message
*/
virtual void HandleMessage(const EGUIMessage &Message);
virtual void HandleMessage(const SGUIMessage &Message);
/**
* Draws the Button

View File

@ -6,10 +6,6 @@ gee@pyro.nu
//#include "stdafx."
#include "GUI.h"
#include <string>
#include <assert.h>
#include <stdarg.h>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
@ -20,6 +16,10 @@ gee@pyro.nu
#include "Prometheus.h"
#include "input.h"
#include <string>
#include <assert.h>
#include <stdarg.h>
// namespaces used
XERCES_CPP_NAMESPACE_USE
using namespace std;
@ -42,8 +42,25 @@ bool gui_handler(const SDL_Event& ev)
bool CGUI::HandleEvent(const SDL_Event& ev)
{
if(ev.type == SDL_MOUSEMOTION)
{
m_MouseX = ev.motion.x, m_MouseY = ev.motion.y;
// pNearest will after this point at the hovered object, possibly NULL
GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::HandleMessage,
SGUIMessage(GUIM_MOUSE_MOTION));
}
char buf[30];
sprintf(buf, "type = %d", ev.type);
TEMPmessage = buf;
if (ev.type == SDL_MOUSEBUTTONDOWN)
{
sprintf(buf, "button = %d", ev.button.button);
TEMPmessage = buf;
}
// JW: (pre|post)process omitted; what're they for? why would we need any special button_released handling?
// Only one object can be hovered
@ -52,57 +69,86 @@ bool CGUI::HandleEvent(const SDL_Event& ev)
try
{
// pNearest will after this point at the hovered object, possibly NULL
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::ChooseMouseOverAndClosest,
pNearest);
// Now we'll call UpdateMouseOver on *all* objects,
// we'll input the one hovered, and they will each
// update their own data and send messages accordingly
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::UpdateMouseOver,
pNearest);
if (ev.type == SDL_MOUSEBUTTONDOWN)
//if (ev.type == SDL_MOUSEBUTTONDOWN)
{
if (pNearest)
if (ev.type == SDL_MOUSEBUTTONDOWN)
{
pNearest->HandleMessage(GUIM_MOUSE_PRESS_LEFT);
switch (ev.button.button)
{
case SDL_BUTTON_LEFT:
if (pNearest)
{
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_PRESS_LEFT));
// some temp
CClientArea ca;
bool hidden;
// some temp
CClientArea ca;
bool hidden;
GUI<CClientArea>::GetSetting(*this, CStr("Child1"), CStr("size"), ca);
GUI<bool>::GetSetting(*this, CStr("Child1"), CStr("hidden"), hidden);
//hidden = !hidden;
ca.pixel.left -= 30;
ca.pixel.bottom += 15;
/*GUI<CClientArea>::GetSetting(*this, CStr("backdrop"), CStr("size"), ca);
GUI<bool>::GetSetting(*this, CStr("backdrop"), CStr("hidden"), hidden);
//hidden = !hidden;
ca.pixel.right += 3;
ca.pixel.bottom += 3;
GUI<CClientArea>::SetSetting(*this, CStr("Child1"), CStr("size"), ca);
GUI<bool>::SetSetting(*this, CStr("Child1"), CStr("hidden"), hidden);
GUI<CClientArea>::SetSetting(*this, CStr("backdrop"), CStr("size"), ca);
GUI<bool>::SetSetting(*this, CStr("backdrop"), CStr("hidden"), hidden);
*/ }
break;
case 3: // wheel down
if (pNearest)
{
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_WHEEL_DOWN));
}
break;
case 4: // wheel up
if (pNearest)
{
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_WHEEL_UP));
}
break;
default:
break;
}
}
}
else
if (ev.type == SDL_MOUSEBUTTONUP)
{
if (pNearest)
pNearest->HandleMessage(GUIM_MOUSE_RELEASE_LEFT);
else
if (ev.type == SDL_MOUSEBUTTONUP)
{
if (ev.button.button == SDL_BUTTON_LEFT)
{
if (pNearest)
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_RELEASE_LEFT));
}
// Reset all states on all visible objects
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
&IGUIObject::ResetStates);
// Reset all states on all visible objects
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
&IGUIObject::ResetStates);
// It will have reset the mouse over of the current hovered, so we'll
// have to restore that
if (pNearest)
pNearest->m_MouseHovering = true;
// It will have reset the mouse over of the current hovered, so we'll
// have to restore that
if (pNearest)
pNearest->m_MouseHovering = true;
}
}
}
catch (PS_RESULT e)
{
// TODO
// TODO Gee: Handle
}
// JW: what's the difference between mPress and mDown? what's the code below responsible for?
/*/* // Generally if just mouse is clicked
@ -142,7 +188,7 @@ IGUIObject *CGUI::ConstructObject(const CStr &str)
return (*m_ObjectTypes[str])();
else
{
// Report in log (GeeTODO)
// TODO Gee: Report in log
return NULL;
}
}
@ -153,13 +199,14 @@ void CGUI::Initialize()
// You can also add types outside the GUI to extend the flexibility of the GUI.
// Prometheus though will have all the object types inserted from here.
AddObjectType("button", &CButton::ConstructObject);
AddObjectType("text", &CText::ConstructObject);
}
void CGUI::Process()
{
/*/*
// GeeTODO / check if m_pInput is valid, otherwise return
// TODO Gee: check if m_pInput is valid, otherwise return
/// assert(m_pInput);
// Pre-process all objects
@ -242,7 +289,7 @@ void CGUI::Draw()
{
glPopMatrix();
// GeeTODO
// TODO Gee: Report error.
return;
}
glPopMatrix();
@ -253,8 +300,8 @@ void CGUI::DrawSprite(const CStr &SpriteName,
const CRect &Rect,
const CRect &Clipping)
{
// This is no error, so we won't report it.
if (SpriteName == CStr("null"))
// This is not an error, it's just a choice not to draw any sprite.
if (SpriteName == CStr("null") || SpriteName == CStr())
return;
bool DoClipping = (Clipping != CRect(0,0,0,0));
@ -263,7 +310,7 @@ void CGUI::DrawSprite(const CStr &SpriteName,
// Fetch real sprite from name
if (m_Sprites.count(SpriteName) == 0)
{
// GeeTODO report error
// TODO Gee: Report error
return;
}
else Sprite = m_Sprites[SpriteName];
@ -305,7 +352,7 @@ void CGUI::Destroy()
}
catch (PS_RESULT e)
{
// GeeTODO
// TODO Gee: Handle
}
delete it->second;
@ -382,7 +429,7 @@ void CGUI::ReportParseError(const CStr &str, ...)
// Important, set ParseError to true
++m_Errors;
/* MEGA GeeTODO
/* TODO Gee: (MEGA)
char buffer[512];
va_list args;
@ -405,27 +452,25 @@ void CGUI::LoadXMLFile(const string &Filename)
// Initialize XML library
XMLPlatformUtils::Initialize();
// Create parser instance
XercesDOMParser *parser = new XercesDOMParser();
bool ParseFailed = false;
if (parser)
{
// Setup parser
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setCreateEntityReferenceNodes(false);
// Create parser instance
XercesDOMParser *parser = new XercesDOMParser();
// Set cosutomized error handler
CXercesErrorHandler *errorHandler = new CXercesErrorHandler();
parser->setErrorHandler(errorHandler);
try
bool ParseFailed = false;
if (parser)
{
/// g_nemLog("*** Xerces XML Parsing Errors");
// Setup parser
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setCreateEntityReferenceNodes(false);
// Set cosutomized error handler
CXercesErrorHandler *errorHandler = new CXercesErrorHandler();
parser->setErrorHandler(errorHandler);
/// g_nemLog("*** Xerces XML Parsing Errors");
// Get main node
LocalFileInputSource source( XMLString::transcode( Filename.c_str() ) );
@ -437,72 +482,58 @@ void CGUI::LoadXMLFile(const string &Filename)
ParseFailed = parser->getErrorCount() != 0;
if (ParseFailed)
{
int todo_remove = parser->getErrorCount();
// GeeTODO report for real!
/// g_console.submit("echo Xerces XML Parsing Reports %d errors", parser->getErrorCount());
// TODO Gee: Report for real!
/// g_console.submit("echo Xerces XML Parsing Reports %d errors", parser->getErrorCount());
}
}
catch (const XMLException& toCatch)
{
char* message = XMLString::transcode(toCatch.getMessage());
/// g_console.submit("echo Exception message is: %s", message);
XMLString::release(&message);
}
catch (const DOMException& toCatch)
{
char* message = XMLString::transcode(toCatch.msg);
/// g_console.submit("echo Exception message is: %s", message);
XMLString::release(&message);
}
catch (...)
{
/// g_console.submit("echo Unexpected Exception");
}
// Parse Failed?
if (!ParseFailed)
{
DOMDocument *doc = parser->getDocument();
DOMElement *node = doc->getDocumentElement();
// Parse Failed?
if (!ParseFailed)
{
DOMDocument *doc = parser->getDocument();
DOMElement *node = doc->getDocumentElement();
// Check root element's (node) name so we know what kind of
// data we'll be expecting
string root_name = XMLString::transcode( node->getNodeName() );
// Check root element's (node) name so we know what kind of
// data we'll be expecting
string root_name = XMLString::transcode( node->getNodeName() );
if (root_name == "objects")
{
Xerces_ReadRootObjects(node);
if (root_name == "objects")
{
Xerces_ReadRootObjects(node);
// Re-cache all values so these gets cached too.
//UpdateResolution();
}
else
if (root_name == "sprites")
{
Xerces_ReadRootSprites(node);
}
else
if (root_name == "styles")
{
Xerces_ReadRootStyles(node);
}
else
{
// GeeTODO output in log
// Re-cache all values so these gets cached too.
//UpdateResolution();
}
else
if (root_name == "sprites")
{
Xerces_ReadRootSprites(node);
}
else
if (root_name == "styles")
{
Xerces_ReadRootStyles(node);
}
else
if (root_name == "setup")
{
Xerces_ReadRootSetup(node);
}
else
{
// TODO Gee: Output in log
}
}
}
// Now report if any other errors occured
if (m_Errors > 0)
{
/// g_console.submit("echo GUI Tree Creation Reports %d errors", m_Errors);
}
delete parser;
}
// Now report if any other errors occured
if (m_Errors > 0)
{
/// g_console.submit("echo GUI Tree Creation Reports %d errors", m_Errors);
}
XMLPlatformUtils::Terminate();
}
//===================================================================
@ -514,8 +545,7 @@ void CGUI::Xerces_ReadRootObjects(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// Iterate main children
// they should all be <object> elements
DOMNodeList *children = pElement->getChildNodes();
for (int i=0; i<children->getLength(); ++i)
for (u16 i=0; i<children->getLength(); ++i)
{
DOMNode *child = children->item(i);
@ -533,8 +563,7 @@ void CGUI::Xerces_ReadRootSprites(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// Iterate main children
// they should all be <sprite> elements
DOMNodeList *children = pElement->getChildNodes();
for (int i=0; i<children->getLength(); ++i)
for (u16 i=0; i<children->getLength(); ++i)
{
DOMNode *child = children->item(i);
@ -552,8 +581,7 @@ void CGUI::Xerces_ReadRootStyles(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// Iterate main children
// they should all be <styles> elements
DOMNodeList *children = pElement->getChildNodes();
for (int i=0; i<children->getLength(); ++i)
for (u16 i=0; i<children->getLength(); ++i)
{
DOMNode *child = children->item(i);
@ -566,10 +594,35 @@ void CGUI::Xerces_ReadRootStyles(XERCES_CPP_NAMESPACE::DOMElement *pElement)
}
}
void CGUI::Xerces_ReadRootSetup(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
// Iterate main children
// they should all be <icon>, <scrollbar> or <tooltip>.
DOMNodeList *children = pElement->getChildNodes();
for (u16 i=0; i<children->getLength(); ++i)
{
DOMNode *child = children->item(i);
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// Read in this whole object into the GUI
DOMElement *element = (DOMElement*)child;
CStr name = XMLString::transcode( element->getNodeName() );
if (name == CStr("scrollbar"))
{
Xerces_ReadScrollBarStyle(element);
}
// No need for else, we're using DTD.
}
}
}
void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
{
assert(pParent && pElement);
int i;
u16 i;
// Our object we are going to create
IGUIObject *object = NULL;
@ -594,42 +647,33 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
//
// Read Style and set defaults
//
// If the setting "style" is set, try loading that setting.
//
// Always load default (if it's available) first!
//
CStr argStyle = XMLString::transcode( pElement->getAttribute( XMLString::transcode("style") ) );
if (argStyle != CStr())
if (m_Styles.count(CStr("default")) == 1)
object->LoadStyle(*this, CStr("default"));
if (argStyle != CStr())
{
// Get style
// additional check
if (m_Styles.count(argStyle) == 0)
{
// GeeTODO Error
}
else
{
// Get setting
SGUIStyle Style = m_Styles[argStyle];
// Iterate settings, it won't be able to set them all probably, but that doesn't matter
std::map<CStr, CStr>::const_iterator cit;
for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit)
{
// Try set setting in object
try
{
object->SetSetting(cit->first, cit->second);
}
// It doesn't matter if it fail, it's not suppose to be able to set every setting.
// since it's generic.
catch (...) {}
}
// TODO Gee: Error
}
else object->LoadStyle(*this, argStyle);
}
//
// Read Attributes
//
bool NameSet = false;
bool ManuallySetZ = false; // if z has been manually set, this turn true
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
@ -651,6 +695,9 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
continue;
}
if (attr_name == CStr("z"))
ManuallySetZ = true;
// Try setting the value
try
{
@ -667,7 +714,7 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
// Check if name isn't set, report error in that case
if (!NameSet)
{
// Generate internal name! GeeTODO
// TODO Gee: Generate internal name!
}
//
@ -695,7 +742,7 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
// First get element and not node
DOMElement *element = (DOMElement*)child;
// GeeTODO REPORT ERROR
// TODO Gee: REPORT ERROR
// Call this function on the child
Xerces_ReadObject(element, object);
@ -710,15 +757,43 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
if (i==0)
{
// Thank you CStr =)
// caption.Trim(PS_TRIM_BOTH);
caption.Trim(PS_TRIM_BOTH);
// Set the setting caption to this
GUI<CStr>::SetSetting(object, "caption", caption);
}
// else ... GeeTODO give warning
// else
// TODO Gee: give warning
}
}
//
// Check if Z wasn't manually set
//
if (!ManuallySetZ)
{
// Set it automatically to 10 plus its parents
if (pParent==NULL)
{
// TODO Gee: Report error
}
else
{
// If the object is absolute, we'll have to get the parent's Z buffered,
// and add to that!
if (object->GetBaseSettings().m_Absolute)
{
GUI<float>::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f);
}
else
// If the object is relative, then we'll just store Z as "10"
{
GUI<float>::SetSetting(object, "z", 10.f);
}
}
}
//
// Input Child
//
@ -760,7 +835,7 @@ void CGUI::Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// Iterate children
DOMNodeList *children = pElement->getChildNodes();
for (int i=0; i<children->getLength(); ++i)
for (u16 i=0; i<children->getLength(); ++i)
{
// Get node
DOMNode *child = children->item(i);
@ -794,7 +869,7 @@ void CGUI::Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISpri
// Image object we're adding
SGUIImage image;
// TODO - Setup defaults here (or maybe they are in the SGUIImage ctor)
// TODO Gee: Setup defaults here (or maybe they are in the SGUIImage ctor)
//
// Read Attributes
@ -802,7 +877,7 @@ void CGUI::Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISpri
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
for (int i=0; i<attributes->getLength(); ++i)
for (u16 i=0; i<attributes->getLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
@ -819,7 +894,7 @@ void CGUI::Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISpri
CClientArea ca;
if (!GUI<CClientArea>::ParseString(attr_value, ca))
{
// GeeTODO : Error
// TODO Gee: Error
}
else image.m_Size = ca;
}
@ -829,13 +904,13 @@ void CGUI::Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISpri
CColor color;
if (!GUI<CColor>::ParseString(attr_value, color))
{
// GeeTODO : Error
// TODO Gee: Error
}
else image.m_BackColor = color;
}
else
{
// GeeTODO Log
// TODO Gee: Log
//g_console.submit("echo Error attribute " + attr_name + " is not expected in <image>");
return;
}
@ -862,7 +937,7 @@ void CGUI::Xerces_ReadStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
for (int i=0; i<attributes->getLength(); ++i)
for (u16 i=0; i<attributes->getLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
@ -872,10 +947,6 @@ void CGUI::Xerces_ReadStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement)
// and not a new default
if (attr_name == CStr("name"))
name = attr_value;
else
// Type cannot be styled
if (attr_name == CStr("type"))
; // GeeTODO output warning
else
style.m_SettingsDefaults[attr_name] = attr_value;
}
@ -886,3 +957,44 @@ void CGUI::Xerces_ReadStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement)
m_Styles[name] = style;
}
void CGUI::Xerces_ReadScrollBarStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
assert(pElement);
// style object we're adding
SGUIScrollBarStyle scrollbar;
CStr name;
//
// Read Attributes
//
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
for (u16 i=0; i<attributes->getLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
CStr attr_value = XMLString::transcode( attr->getValue() );
if (attr_name == CStr("name"))
name = attr_value;
else
if (attr_name == CStr("width"))
{
int i;
if (!GUI<int>::ParseString(attr_value, i))
{
// TODO Gee: Report in log file
}
scrollbar.m_Width = i;
}
}
//
// Add to CGUI
//
m_ScrollBarStyles[name] = scrollbar;
}

View File

@ -70,6 +70,7 @@ struct SGUIStyle
class CGUI : public Singleton<CGUI>
{
friend class IGUIObject;
friend class IGUIScrollBarOwner;
friend class CInternalCGUIAccessorBase;
private:
@ -80,7 +81,7 @@ public:
CGUI();
~CGUI();
// TEMP TEMP GeeTODO
// TODO Gee: (MEGA) Extremely temporary.
std::string TEMPmessage;
/**
@ -145,8 +146,10 @@ public:
* their constructors. Also it needs to associate a type
* by a string name of the type.
*
* To add a type:\n
* To add a type:
* @code
* AddObjectType("button", &CButton::ConstructObject);
* @endcode
*
* @param str Reference name of object type
* @param pFunc Pointer of function ConstuctObject() in the object
@ -288,6 +291,16 @@ private:
*/
void Xerces_ReadRootStyles(XERCES_CPP_NAMESPACE::DOMElement *pElement);
/**
* Reads in the root element \<setup\> (the DOMElement).
*
* @param pElement The Xerces C++ Parser object that represents
* the setup-tag.
*
* @see LoadXMLFile()
*/
void Xerces_ReadRootSetup(XERCES_CPP_NAMESPACE::DOMElement *pElement);
// Read Subs
/**
@ -345,6 +358,17 @@ private:
*/
void Xerces_ReadStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement);
/**
* Reads in the element \<scrollbar\> (the DOMElement) and stores the
* result in m_ScrollBarStyles.
*
* @param pElement The Xerces C++ Parser object that represents
* the scrollbar-tag.
*
* @see LoadXMLFile()
*/
void Xerces_ReadScrollBarStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement);
//@}
private:
@ -374,7 +398,7 @@ private:
/**
* Base Object, all its children are considered parentless
* because this is no real object per se.
* because this is not a real object per se.
*/
IGUIObject* m_BaseObject;
@ -406,6 +430,9 @@ private:
/// Styles
std::map<CStr, SGUIStyle> m_Styles;
/// Scroll-bar styles
std::map<CStr, SGUIScrollBarStyle> m_ScrollBarStyles;
//@}
};

View File

@ -0,0 +1,10 @@
/*
SGUIScrollBarStyle
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx.h"
#include "GUI.h"
using namespace std;

116
source/gui/CGUIScrollBarStyle.h Executable file
View File

@ -0,0 +1,116 @@
/*
A GUI ScrollBar Style
by Gustav Larsson
gee@pyro.nu
--Overview--
A GUI scroll-bar style tells scroll-bars how they should look,
width, sprites used, etc.
--Usage--
Declare them in XML files, and reference them when declaring objects.
--More info--
Check GUI.h
*/
#ifndef CGUIScrollBarStyle_H
#define CGUIScrollBarStyle_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* The GUI Scroll-bar style.
*
* A scroll-bar style can choose whether to support horizontal, vertical
* or both.
*
* @see CGUIScrollBar
*/
struct CGUIScrollBarStyle
{
//--------------------------------------------------------
/** @name General Settings */
//--------------------------------------------------------
//@{
/**
* Width of bar, also both sides of the edge buttons.
*/
int m_Width;
/**
* Scrollable with the wheel.
*/
bool m_ScrollWheel;
/**
* How much (in percent, 0.1f = 10%) to scroll each time
* the wheel is admitted, or the buttons are pressed.
*/
float m_ScrollSpeed;
/**
* Whether or not the edge buttons should appear or not. Sometimes
* you actually don't want them, like perhaps in a combo box.
*/
bool m_ScrollButtons;
/**
* Sometimes there is *a lot* to scroll, but to prevent the scroll "bar"
* from being almost invisible (or ugly), you can set a minimum in pixel
* size.
*/
int m_MinimumBarSize;
//@}
//--------------------------------------------------------
/** @name Horizontal Sprites */
//--------------------------------------------------------
//@{
CStr m_SpriteButtonTop;
CStr m_SpriteButtonTopPressed;
CStr m_SpriteButtonTopDisabled;
CStr m_SpriteButtonBottom;
CStr m_SpriteButtonBottomPressed;
CStr m_SpriteButtonBottomDisabled;
CStr m_SpriteScrollBackHorizontal;
CStr m_SpriteScrollBarHorizontal;
//@}
//--------------------------------------------------------
/** @name Verical Sprites */
//--------------------------------------------------------
//@{
CStr m_SpriteButtonLeft;
CStr m_SpriteButtonLeftPressed;
CStr m_SpriteButtonLeftDisabled;
CStr m_SpriteButtonRight;
CStr m_SpriteButtonRightPressed;
CStr m_SpriteButtonRightDisabled;
CStr m_SpriteScrollBackVertical;
CStr m_SpriteScrollBarVertical;
//@}
};
#endif

View File

@ -0,0 +1,89 @@
/*
IGUIScrollBar
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx.h"
#include "GUI.h"
using namespace std;
void CGUIScrollBarVertical::SetPosFromMousePos(int _x, int _y)
{
m_Pos = m_PosWhenPressed + ((float)_y-m_BarPressedAtY)/(m_Length-GetStyle().m_Width*2)*2.f;
}
void CGUIScrollBarVertical::Draw()
{
int StartX = (m_RightAligned)?(m_X-GetStyle().m_Width):(m_X);
// Draw background
g_GUI.DrawSprite(GetStyle().m_SpriteScrollBackVertical, m_Z+0.1f,
CRect( StartX,
m_Y+GetStyle().m_Width,
StartX+GetStyle().m_Width,
m_Y+m_Length-GetStyle().m_Width)
);
// Draw top button
g_GUI.DrawSprite(GetStyle().m_SpriteButtonTop, m_Z+0.2f, CRect(StartX, m_Y, StartX+GetStyle().m_Width, m_Y+GetStyle().m_Width));
// Draw bottom button
g_GUI.DrawSprite(GetStyle().m_SpriteButtonBottom, m_Z+0.2f, CRect(StartX, m_Y+m_Length-GetStyle().m_Width, StartX+GetStyle().m_Width, m_Y+m_Length));
// Draw bar
if (m_BarPressed)
g_GUI.DrawSprite(GetStyle().m_SpriteScrollBarVertical, m_Z+0.2f, GetBarRect());
else
g_GUI.DrawSprite(GetStyle().m_SpriteScrollBarVertical, m_Z+0.2f, GetBarRect());
}
bool CGUIScrollBarVertical::HandleMessage(const SGUIMessage &Message)
{
IGUIScrollBar::HandleMessage(Message);
/* switch (Message.type)
{
*/ return true;
}
CRect CGUIScrollBarVertical::GetBarRect() const
{
int size;
float from, to;
size = (int)((m_Length-GetStyle().m_Width*2)*m_BarSize);
from = (float)(m_Y+GetStyle().m_Width);
to = (float)(m_Y+m_Length-GetStyle().m_Width-size);
// Setup rectangle
CRect ret;
ret.top = (int)(from + (to-from)*m_Pos);
ret.bottom = ret.top+size;
ret.right = m_X + ((m_RightAligned)?(0):(GetStyle().m_Width));
ret.left = ret.right - GetStyle().m_Width;
return ret;
}
bool CGUIScrollBarVertical::HoveringButtonMinus(int mouse_x, int mouse_y)
{
int StartX = (m_RightAligned)?(m_X-GetStyle().m_Width):(m_X);
return (mouse_x > StartX &&
mouse_x < StartX + GetStyle().m_Width &&
mouse_y > m_Y &&
mouse_y < m_Y + GetStyle().m_Width);
}
bool CGUIScrollBarVertical::HoveringButtonPlus(int mouse_x, int mouse_y)
{
int StartX = (m_RightAligned)?(m_X-GetStyle().m_Width):(m_X);
return (mouse_x > StartX &&
mouse_x < StartX + GetStyle().m_Width &&
mouse_y > m_Y + m_Length - GetStyle().m_Width &&
mouse_y < m_Y + m_Length);
}

View File

@ -0,0 +1,99 @@
/*
A GUI ScrollBar
by Gustav Larsson
gee@pyro.nu
--Overview--
A GUI Scrollbar, this class doesn't present all functionality
to the scrollbar, it just controls the drawing and a wrapper
for interaction with it.
--Usage--
Used in everywhere scrollbars are needed, like in a combobox for instance.
--More info--
Check GUI.h
*/
#ifndef CGUIScrollBarVertical_H
#define CGUIScrollBarVertical_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* Vertical implementation of IGUIScrollBar
*
* @see IGUIScrollBar
*/
class CGUIScrollBarVertical : public IGUIScrollBar
{
public:
CGUIScrollBarVertical() {}
virtual ~CGUIScrollBarVertical() {}
public:
/**
* Draw the scroll-bar
*/
virtual void Draw();
/**
* If an object that contains a scrollbar has got messages, send
* them to the scroll-bar and it will see if the message regarded
* itself.
*
* @param Message SGUIMessage
* @return true if messages handled the scroll-bar some. False if
* the message should be processed by the object.
*/
virtual bool HandleMessage(const SGUIMessage &Message);
/**
* Set m_Pos with mouse_x/y input, i.e. when draggin.
*/
virtual void SetPosFromMousePos(int _x, int _y);
/**
* @see IGUIScrollBar#HoveringButtonMinus
*/
virtual bool HoveringButtonMinus(int m_x, int m_y);
/**
* @see IGUIScrollBar#HoveringButtonPlus
*/
virtual bool HoveringButtonPlus(int m_x, int m_y);
/**
* Set Right Aligned
* @param align Alignment
*/
void SetRightAligned(const bool &align) { m_RightAligned = align; }
protected:
/**
* Get the rectangle of the actual BAR.
* @return Rectangle, CRect
*/
virtual CRect GetBarRect() const;
/**
* Should the scroll bar proceed to the left or to the right of the m_X value.
* Notice, this has nothing to do with where the owner places it.
*/
bool m_RightAligned;
};
#endif

95
source/gui/CText.cpp Executable file
View File

@ -0,0 +1,95 @@
/*
CText
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx."
#include "GUI.h"
// TODO Gee: font.h is temporary.
#include "font.h"
#include "ogl.h"
using namespace std;
// Offsets
DECLARE_SETTINGS_INFO(STextSettings)
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
CText::CText()
{
// Static! Only done once
if (m_SettingsInfo.empty())
{
// Setup the base ones too
SetupBaseSettingsInfo(m_SettingsInfo);
GUI_ADD_OFFSET_EXT(STextSettings, m_Sprite, "string", "sprite")
GUI_ADD_OFFSET_EXT(STextSettings, m_ScrollBar, "bool", "scrollbar")
GUI_ADD_OFFSET_EXT(STextSettings, m_ScrollBarStyle, "string", "scrollbar-style")
}
// Add scroll-bar
CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
bar->SetRightAligned(true);
AddScrollBar(bar);
}
CText::~CText()
{
}
void CText::HandleMessage(const SGUIMessage &Message)
{
// TODO Gee:
IGUIScrollBarOwner::HandleMessage(Message);
switch (Message.type)
{
case GUIM_SETTINGS_UPDATED:
if (Message.value == CStr("size") || Message.value == CStr("z") ||
Message.value == CStr("absolute"))
{
GetScrollBar(0).SetX( m_CachedActualSize.right );
GetScrollBar(0).SetY( m_CachedActualSize.top );
GetScrollBar(0).SetZ( GetBufferedZ() );
GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top );
}
if (Message.value == CStr("scrollbar-style"))
{
GetScrollBar(0).SetScrollBarStyle( GetSettings().m_ScrollBarStyle );
}
break;
case GUIM_MOUSE_WHEEL_DOWN:
GetScrollBar(0).ScrollPlus();
break;
case GUIM_MOUSE_WHEEL_UP:
GetScrollBar(0).ScrollMinus();
break;
default:
break;
}
}
void CText::Draw()
{
////////// Gee: janwas, this is just temp to see it
glDisable(GL_TEXTURE_2D);
//////////
// First call draw on ScrollBarOwner
IGUIScrollBarOwner::Draw();
if (GetGUI())
{
GetGUI()->DrawSprite(m_Settings.m_Sprite, GetBufferedZ(), m_CachedActualSize);
}
}

99
source/gui/CText.h Executable file
View File

@ -0,0 +1,99 @@
/*
GUI Object - Text [field]
by Gustav Larsson
gee@pyro.nu
--Overview--
GUI Object representing a text field
--More info--
Check GUI.h
*/
#ifndef CText_H
#define CText_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
// TODO Gee: Remove
class IGUIScrollBar;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* Text Settings
*/
struct STextSettings
{
CStr m_Font;
CStr m_Sprite;
EAlign m_TextAlign;
CColor m_TextColor;
EValign m_TextValign;
CStr m_ToolTip;
CStr m_ToolTipStyle;
bool m_ScrollBar;
CStr m_ScrollBarStyle;
};
///////////////////////////////////////////////////////////////////////////////
/**
* @author Gustav Larsson
*
* Text field that just displays static text.
*
* @see IGUIObject
* @see IGUISettingsObject
* @see STextSettings
*/
class CText : public IGUISettingsObject<STextSettings>, public IGUIScrollBarOwner
{
GUI_OBJECT(CText)
public:
CText();
virtual ~CText();
/**
* Since we're doing multiple inheritance, this is to avoid error message
*
* @return Settings infos
*/
virtual map_Settings GetSettingsInfo() const { return IGUISettingsObject<STextSettings>::m_SettingsInfo; }
virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); }
/**
* Handle Messages
*
* @param Message GUI Message
*/
virtual void HandleMessage(const SGUIMessage &Message);
/**
* Draws the Text
*/
virtual void Draw();
// TODO Gee: Temp!
//CGUIScrollBar m_ScrollBar;
};
#endif

View File

@ -31,7 +31,7 @@ gee@pyro.nu
* q [ label="Questions?"];
* c [ label="Comments?"];
* s [ label="Suggestions?"];
* email [label="E-mail Me" URL="mailto:slimgee@bredband.net"];
* email [label="E-mail Me" URL="mailto:gee@pyro.nu"];
* q -> email;
* c -> email;
* s -> email;
@ -69,7 +69,11 @@ gee@pyro.nu
#include "IGUIObject.h"
#include "IGUISettingsObject.h"
#include "IGUIButtonBehavior.h"
#include "IGUIScrollBarOwner.h"
#include "IGUIScrollBar.h"
#include "CGUIScrollBarVertical.h"
#include "CButton.h"
#include "CText.h"
#include "CGUISprite.h"
#include "CGUI.h"

View File

@ -35,9 +35,7 @@ class IGUIObject;
// Global CGUI
#define g_GUI CGUI::GetSingleton()
// Temp
#define CInput nemInput
// Object settings setups
#define GUI_ADD_OFFSET_GENERIC(si, guiss, _struct, var, type, str) \
si[CStr(str)].m_Offset = offsetof(_struct, var); \
si[CStr(str)].m_SettingsStruct = guiss; \
@ -64,11 +62,11 @@ public: \
//--------------------------------------------------------
/**
* @enum EGUIMessage
* Message send to IGUIObject::HandleMessage() in order
* to give life to Objects manually with
* a derived HandleMessage().
* Message types
*
* @see SGUIMessage
*/
enum EGUIMessage
enum EGUIMessageType
{
GUIM_PREPROCESS, // questionable
GUIM_POSTPROCESS, // questionable
@ -81,8 +79,34 @@ enum EGUIMessage
GUIM_MOUSE_DOWN_RIGHT,
GUIM_MOUSE_RELEASE_LEFT,
GUIM_MOUSE_RELEASE_RIGHT,
GUIM_SETTINGS_UPDATED,
GUIM_PRESSED
GUIM_MOUSE_WHEEL_UP,
GUIM_MOUSE_WHEEL_DOWN,
GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
GUIM_PRESSED,
GUIM_MOUSE_MOTION
};
/**
* Message send to IGUIObject::HandleMessage() in order
* to give life to Objects manually with
* a derived HandleMessage().
*/
struct SGUIMessage
{
SGUIMessage() {}
SGUIMessage(const EGUIMessageType &_type) : type(_type) {}
SGUIMessage(const EGUIMessageType &_type, const CStr &_value) : type(_type), value(_value) {}
~SGUIMessage() {}
/**
* Describes what the message regards
*/
EGUIMessageType type;
/**
* Optional data
*/
CStr value;
};
/**
@ -94,13 +118,17 @@ enum EGUIMessage
*/
enum
{
GUIRR_HIDDEN=1,
GUIRR_DISABLED=2
GUIRR_HIDDEN = 0x00000001,
GUIRR_DISABLED = 0x00000010,
GUIRR_GHOST = 0x00000100
};
/**
* @enum EGUISettingsStruct
* TODO comment
*
* Stored in SGUISetting, tells us in which struct
* the setting is located, that way we can query
* for the structs address.
*/
enum EGUISettingsStruct
{

View File

@ -210,6 +210,8 @@ public:
//RecurseObject(0, pObject, IGUIObject::ResetStates);
}
pObject->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
return PS_OK;
}
@ -290,7 +292,7 @@ public:
delete [] mem;
// Undefined type - GeeTODO, maybe report in log
// TODO Gee: Undefined type - maybe report in log
return true;
}
@ -332,12 +334,21 @@ private:
if (typeid(T) == typeid(float))
{
float _Value = Value.ToFloat();
// GeeTODO Okay float value!?
// TODO Gee: Okay float value!?
Memory = malloc(sizeof(float));
memcpy(Memory, (const void*)&_Value, sizeof(float));
return true;
}
else
if (typeid(T) == typeid(int))
{
int _Value = Value.ToInt();
// TODO Gee: Okay float value!?
Memory = malloc(sizeof(int));
memcpy(Memory, (const void*)&_Value, sizeof(int));
return true;
}
else
if (typeid(T) == typeid(CRect))
{
// Use the parser to parse the values
@ -399,7 +410,7 @@ private:
line.ParseString(parser, str);
if (!line.m_ParseOK)
{
// Parsing failed GeeTODO
// TODO Gee: Parsing failed
return false;
}
float values[4];
@ -408,14 +419,14 @@ private:
{
if (!line.GetArgFloat(i, values[i]))
{
// Parsing failed GeeTODO
// TODO Gee: Parsing failed
return false;
}
}
// Finally the rectangle values
CColor _Value;
// GeeTODO, done better when CColor is sweeter
// TODO Gee: Done better when CColor is sweeter
_Value.r = values[0]/255.f;
_Value.g = values[1]/255.f;
_Value.b = values[2]/255.f;
@ -426,7 +437,7 @@ private:
return true;
}
// Undefined type - GeeTODO, maybe report in log
// TODO Gee: Undefined type - maybe report in log
return false;
}
@ -463,6 +474,7 @@ private:
*/
static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument)
{
// TODO Gee: Don't run this for the base object.
if (CheckIfRestricted(RR, pObject))
return;
@ -507,7 +519,7 @@ private:
return;
(pObject->*pFunc)();
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
@ -539,6 +551,11 @@ private:
if (pObject->GetBaseSettings().m_Enabled)
return true;
}
if (RR & GUIRR_GHOST)
{
if (pObject->GetBaseSettings().m_Ghost)
return true;
}
// false means not restricted
return false;

View File

@ -20,9 +20,9 @@ IGUIButtonBehavior::~IGUIButtonBehavior()
{
}
void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message)
void IGUIButtonBehavior::HandleMessage(const SGUIMessage &Message)
{
switch (Message)
switch (Message.type)
{
case GUIM_PREPROCESS:
m_Pressed = false;
@ -46,10 +46,16 @@ void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message)
break;
*/
case GUIM_MOUSE_PRESS_LEFT:
if (!GetBaseSettings().m_Enabled)
break;
m_Pressed = true;
break;
case GUIM_MOUSE_RELEASE_LEFT:
if (!GetBaseSettings().m_Enabled)
break;
if (m_Pressed)
{
m_Pressed = false;

View File

@ -1,5 +1,5 @@
/*
GUI Object - Button
GUI Object Base - Button Behavior
by Gustav Larsson
gee@pyro.nu
@ -55,7 +55,7 @@ public:
/**
* @see IGUIObject#HandleMessage()
*/
virtual void HandleMessage(const EGUIMessage &Message);
virtual void HandleMessage(const SGUIMessage &Message);
protected:
virtual void ResetStates()

View File

@ -32,11 +32,10 @@ IGUIObject::IGUIObject() :
m_pParent(NULL),
m_MouseHovering(false)
{
// Default values of base settings !
m_BaseSettings.m_Enabled = true;
// TODO Gee: Remove this when base object is excluded from the recursion routines.
m_BaseSettings.m_Hidden = false;
m_BaseSettings.m_Style = "null";
m_BaseSettings.m_Z = 0.f;
m_BaseSettings.m_Ghost = false;
m_BaseSettings.m_Enabled = true;
m_BaseSettings.m_Absolute = true;
// Static! Only done once
@ -134,6 +133,7 @@ void IGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo)
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Z, "float", "z")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Caption, "string", "caption")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Absolute, "bool", "absolute")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Ghost, "bool", "ghost")
}
bool IGUIObject::MouseOver()
@ -264,7 +264,7 @@ void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
}
// Or if it's closer
if (GetBaseSettings().m_Z >= pObject->GetBaseSettings().m_Z)
if (GetBufferedZ() >= pObject->GetBufferedZ())
{
pObject = this;
return;
@ -272,7 +272,7 @@ void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
}
}
IGUIObject *IGUIObject::GetParent()
IGUIObject *IGUIObject::GetParent() const
{
// Important, we're not using GetParent() for these
// checks, that could screw it up
@ -293,7 +293,7 @@ void * IGUIObject::GetStructPointer(const EGUISettingsStruct &SettingsStruct) co
return (void*)&m_BaseSettings;
default:
// GeeTODO report error
// TODO Gee: report error
return NULL;
}
}
@ -309,7 +309,53 @@ void IGUIObject::UpdateCachedSize()
m_CachedActualSize = m_BaseSettings.m_Size.GetClientArea( CRect(0, 0, g_xres, g_yres) );
}
// GeeTODO keep this function and all???
void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr &StyleName)
{
// Fetch style
if (GUIinstance.m_Styles.count(StyleName)==1)
{
LoadStyle(GUIinstance.m_Styles[StyleName]);
}
else
;// TODO Gee: report error
}
void IGUIObject::LoadStyle(const SGUIStyle &Style)
{
// Iterate settings, it won't be able to set them all probably, but that doesn't matter
std::map<CStr, CStr>::const_iterator cit;
for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit)
{
// Try set setting in object
try
{
SetSetting(cit->first, cit->second);
}
// It doesn't matter if it fail, it's not suppose to be able to set every setting.
// since it's generic.
catch (PS_RESULT e)
{
// was ist das?
e;
}
}
}
float IGUIObject::GetBufferedZ() const
{
if (GetBaseSettings().m_Absolute)
return GetBaseSettings().m_Z;
else
{
if (GetParent())
return GetParent()->GetBufferedZ() + GetBaseSettings().m_Z;
else
// TODO Gee: Error, no object should be relative with a parent!
return GetBaseSettings().m_Z;
}
}
// TODO Gee: keep this function and all???
void IGUIObject::CheckSettingsValidity()
{
// If we hide an object, reset many of its parts

View File

@ -36,6 +36,7 @@ gee@pyro.nu
#include <vector>
struct SGUISetting;
struct SGUIStyle;
class CGUI;
//--------------------------------------------------------
@ -84,13 +85,14 @@ struct SGUISetting
*/
struct SGUIBaseSettings
{
bool m_Hidden;
bool m_Enabled;
bool m_Absolute;
CStr m_Caption; // Is usually set within an XML element and not in the attributes
bool m_Enabled;
bool m_Ghost;
bool m_Hidden;
CClientArea m_Size;
CStr m_Style;
float m_Z;
CStr m_Caption; // Is usually set within an XML element and not in the attributes
};
//////////////////////////////////////////////////////////
@ -105,6 +107,7 @@ class IGUIObject
{
friend class CGUI;
friend class CInternalCGUIAccessorBase;
friend class IGUIScrollBar;
#ifndef _MSC_VER
template <class T>
#endif
@ -219,7 +222,7 @@ public:
* This is not private since there should be no harm in
* checking validity.
*
* @throws GeeTODO not quite settled yet.
* @throws TODO not quite settled yet.
*/
void CheckSettingsValidity();
@ -258,7 +261,7 @@ protected:
/**
* Calls Destroy on all children, and deallocates all memory.
* BIG TODO Should it destroy it's children?
* MEGA TODO Should it destroy it's children?
*/
virtual void Destroy();
@ -266,9 +269,9 @@ protected:
* This function is called with different messages
* for instance when the mouse enters the object.
*
* @param Message EGUIMessage
* @param Message GUI Message
*/
virtual void HandleMessage(const EGUIMessage &Message)=0;
virtual void HandleMessage(const SGUIMessage &Message)=0;
/**
* Draws the object.
@ -280,6 +283,30 @@ protected:
*/
virtual void Draw()=0;
/**
* Loads a style.
*
* @param GUIinstance Reference to the GUI
* @param StyleName Style by name
*/
void LoadStyle(CGUI &GUIinstance, const CStr &StyleName);
/**
* Loads a style.
*
* @param Style The style object.
*/
void LoadStyle(const SGUIStyle &Style);
/**
* Returns not the Z value, but the actual buffered Z value, i.e. if it's
* defined relative, then it will check its parent's Z value and add
* the relativity.
*
* @return Actual Z value on the screen.
*/
float GetBufferedZ() const;
// This is done internally
CGUI *GetGUI() { return m_pGUI; }
const CGUI *GetGUI() const { return m_pGUI; }
@ -302,7 +329,12 @@ protected:
*
* @return Pointer to parent
*/
IGUIObject *GetParent();
IGUIObject *GetParent() const;
/**
* Same as reference, but returns a const
*/
// IGUIObject const *GetParent() const;
/**
* You input the setting struct you want, and it will return a pointer to
@ -362,7 +394,8 @@ protected:
/// Name of object
CStr m_Name;
/// Constructed on the heap, will be destroyed along with the the object TODO Really?
/// Constructed on the heap, will be destroyed along with the the object
// TODO Gee: really the above?
vector_pObjects m_Children;
/// Pointer to parent
@ -412,7 +445,7 @@ private:
*/
class CGUIDummyObject : public IGUIObject
{
virtual void HandleMessage(const EGUIMessage &Message) {}
virtual void HandleMessage(const SGUIMessage &Message) {}
virtual void Draw() {}
};

91
source/gui/IGUIScrollBar.cpp Executable file
View File

@ -0,0 +1,91 @@
/*
IGUIScrollBar
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx.h"
#include "GUI.h"
using namespace std;
//-------------------------------------------------------------------
// IGUIScrollBar
//-------------------------------------------------------------------
IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_X(300), m_Y(300), m_Length(200), m_Width(20), m_BarSize(0.5), m_Pos(0.5)
{
}
IGUIScrollBar::~IGUIScrollBar()
{
}
const SGUIScrollBarStyle & IGUIScrollBar::GetStyle() const
{
if (!m_pHostObject)
return SGUIScrollBarStyle();
return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle);
}
void IGUIScrollBar::UpdatePosBoundaries()
{
if (m_Pos > 1.f)
m_Pos = 1.f;
else
if (m_Pos < 0.f)
m_Pos = 0.f;
}
bool IGUIScrollBar::HandleMessage(const SGUIMessage &Message)
{
switch (Message.type)
{
case GUIM_MOUSE_MOTION:
if (m_BarPressed)
{
SetPosFromMousePos(m_pHostObject->GetMouseX(), m_pHostObject->GetMouseY());
UpdatePosBoundaries();
}
break;
case GUIM_MOUSE_PRESS_LEFT:
{
if (!m_pHostObject)
break;
int mouse_x = m_pHostObject->GetMouseX(),
mouse_y = m_pHostObject->GetMouseY();
// if bar is pressed
if (mouse_x >= GetBarRect().left &&
mouse_x <= GetBarRect().right &&
mouse_y >= GetBarRect().top &&
mouse_y <= GetBarRect().bottom)
{
m_BarPressed = true;
m_BarPressedAtX = mouse_x;
m_BarPressedAtY = mouse_y;
m_PosWhenPressed = m_Pos;
}
else
// if button-minus is pressed
if (HoveringButtonMinus(mouse_x, mouse_y))
{
ScrollMinus();
}
else
// if button-plus is pressed
if (HoveringButtonPlus(mouse_x, mouse_y))
{
ScrollPlus();
}
}
break;
default:
return false;
}
return true;
}

336
source/gui/IGUIScrollBar.h Executable file
View File

@ -0,0 +1,336 @@
/*
A GUI ScrollBar
by Gustav Larsson
gee@pyro.nu
--Overview--
A GUI Scrollbar, this class doesn't present all functionality
to the scrollbar, it just controls the drawing and a wrapper
for interaction with it.
--Usage--
Used in everywhere scrollbars are needed, like in a combobox for instance.
--More info--
Check GUI.h
*/
#ifndef IGUIScrollBar_H
#define IGUIScrollBar_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* The GUI Scroll-bar style. Tells us how scroll-bars look and feel.
*
* A scroll-bar style can choose whether to support horizontal, vertical
* or both.
*
* @see IGUIScrollBar
*/
struct SGUIScrollBarStyle
{
//--------------------------------------------------------
/** @name General Settings */
//--------------------------------------------------------
//@{
/**
* Width of bar, also both sides of the edge buttons.
*/
int m_Width;
/**
* Scrollable with the wheel.
*/
bool m_ScrollWheel;
/**
* How much (in percent, 0.1f = 10%) to scroll each time
* the wheel is admitted, or the buttons are pressed.
*/
float m_ScrollSpeed;
/**
* Whether or not the edge buttons should appear or not. Sometimes
* you actually don't want them, like perhaps in a combo box.
*/
bool m_ScrollButtons;
/**
* Sometimes there is *a lot* to scroll, but to prevent the scroll "bar"
* from being almost invisible (or ugly), you can set a minimum in pixel
* size.
*/
int m_MinimumBarSize;
//@}
//--------------------------------------------------------
/** @name Horizontal Sprites */
//--------------------------------------------------------
//@{
CStr m_SpriteButtonTop;
CStr m_SpriteButtonTopPressed;
CStr m_SpriteButtonTopDisabled;
CStr m_SpriteButtonBottom;
CStr m_SpriteButtonBottomPressed;
CStr m_SpriteButtonBottomDisabled;
CStr m_SpriteScrollBackHorizontal;
CStr m_SpriteScrollBarHorizontal;
//@}
//--------------------------------------------------------
/** @name Verical Sprites */
//--------------------------------------------------------
//@{
CStr m_SpriteButtonLeft;
CStr m_SpriteButtonLeftPressed;
CStr m_SpriteButtonLeftDisabled;
CStr m_SpriteButtonRight;
CStr m_SpriteButtonRightPressed;
CStr m_SpriteButtonRightDisabled;
CStr m_SpriteScrollBackVertical;
CStr m_SpriteScrollBarVertical;
//@}
};
/**
* @author Gustav Larsson
*
* The GUI Scroll-bar, used everywhere there is a scroll-bar in the game.
*
* To include a scroll-bar to an object, inherent the object from
* IGUIScrollBarOwner and call AddScrollBar() to add the scroll-bars.
*
* It's also important that the scrollbar is located within the parent
* object's mouse over area. Otherwise the input won't be sent to the
* scroll-bar.
*
* The class does not provide all functionality to the scroll-bar, many
* things the parent of the scroll-bar, must provide. Like a combo-box.
*/
class IGUIScrollBar
{
public:
IGUIScrollBar();
virtual ~IGUIScrollBar();
public:
/**
* Draw the scroll-bar
*/
virtual void Draw()=0;
/**
* If an object that contains a scrollbar has got messages, send
* them to the scroll-bar and it will see if the message regarded
* itself.
*
* @param Message SGUIMessage
* @return true if messages handled the scroll-bar some. False if
* the message should be processed by the object.
*/
virtual bool HandleMessage(const SGUIMessage &Message)=0;
/**
* Set m_Pos with mouse_x/y input, i.e. when draggin.
*/
virtual void SetPosFromMousePos(int _x, int _y)=0;
/**
* Hovering the scroll minus button
*
* @param m_x mouse x
* @param m_y mouse y
* @return True if mouse positions are hovering the button
*/
virtual bool HoveringButtonMinus(int m_x, int m_y) { return false; }
/**
* Hovering the scroll plus button
*
* @param m_x mouse x
* @param m_y mouse y
* @return True if mouse positions are hovering the button
*/
virtual bool HoveringButtonPlus(int m_x, int m_y) { return false; }
/**
* Scroll towards 1.0 one step
*/
virtual void ScrollPlus() { m_Pos += 0.1f; UpdatePosBoundaries(); }
/**
* Scroll towards 0.0 one step
*/
virtual void ScrollMinus() { m_Pos -= 0.1f; UpdatePosBoundaries(); }
/**
* Set host object, must be done almost at creation of scroll bar.
* @param pOwner Pointer to host object.
*/
void SetHostObject(IGUIScrollBarOwner * pOwner) { m_pHostObject = pOwner; }
/**
* Set Width
* @param width Width
*/
void SetWidth(const int16 &width) { m_Width = width; }
/**
* Set X Position
* @param x Position in this axis
*/
void SetX(const int &x) {m_X = x; }
/**
* Set Y Position
* @param y Position in this axis
*/
void SetY(const int &y) {m_Y = y; }
/**
* Set Z Position
* @param z Position in this axis
*/
void SetZ(const float &z) {m_Z = z; }
/**
* Set Length of scroll bar
* @param length Length
*/
void SetLength(const float &length) {m_Length = length; }
/**
* Set bar pressed
* @param pressed True if bar is pressed
*/
void SetBarPressed(const bool &b) { m_BarPressed = b; }
/**
* Set Scroll bar style string
* @param style String with scroll bar style reference name
*/
void SetScrollBarStyle(const CStr &style) { m_ScrollBarStyle = style; }
protected:
/**
* Get the rectangle of the actual BAR. not the whole scroll-bar.
*/
virtual CRect GetBarRect() const = 0;
/**
* Get style used by the scrollbar
* @return Scroll bar style struct.
*/
const SGUIScrollBarStyle & GetStyle() const;
/**
* Call every time m_Pos has been updated.
*/
void UpdatePosBoundaries();
protected:
//@}
//--------------------------------------------------------
/** @name Settings */
//--------------------------------------------------------
//@{
/**
* Width of the scroll bar
*/
int16 m_Width;
/**
* Absolute X Position
*/
int m_X;
/**
* Absolute Y Position
*/
int m_Y;
/**
* Absolute Z Position
*/
float m_Z;
/**
* Total length of scrollbar, including edge buttons.
*/
int m_Length;
/**
* Use input from the scroll-wheel? True or false.
*/
float m_BarSize;
/**
* Scroll bar style reference name
*/
CStr m_ScrollBarStyle;
/**
* Pointer to scroll bar style used.
*/
SGUIScrollBarStyle *m_pStyle;
/**
* Host object, prerequisite!
*/
IGUIScrollBarOwner *m_pHostObject;
/**
* Mouse position when bar was pressed
*/
int m_BarPressedAtX, m_BarPressedAtY;
//@}
//--------------------------------------------------------
/** @name States */
//--------------------------------------------------------
//@{
/**
* If the bar is currently being pressed and dragged.
*/
bool m_BarPressed;
/**
* Position of scroll bar, 0 means scrolled all the way to one side... 1 means
* scrolled all the way to the other side.
*/
float m_Pos;
/**
* Position from 0.f to 1.f it had when the bar was pressed.
*/
float m_PosWhenPressed;
//@}
};
#endif

View File

@ -0,0 +1,79 @@
/*
IGUIScrollBarOwner
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx.h"
#include "GUI.h"
using namespace std;
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
IGUIScrollBarOwner::IGUIScrollBarOwner()
{
}
IGUIScrollBarOwner::~IGUIScrollBarOwner()
{
// Delete scroll-bars
vector<IGUIScrollBar*>::iterator it;
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
{
delete *it;
}
}
void IGUIScrollBarOwner::ResetStates()
{
IGUIObject::ResetStates();
vector<IGUIScrollBar*>::iterator it;
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
{
(*it)->SetBarPressed(false);
}
}
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar * scrollbar)
{
scrollbar->SetHostObject(this);
m_ScrollBars.push_back(scrollbar);
}
const SGUIScrollBarStyle & IGUIScrollBarOwner::GetScrollBarStyle(const CStr &style) const
{
if (!GetGUI())
{
// TODO Gee: Output in log
return SGUIScrollBarStyle();
}
if (GetGUI()->m_ScrollBarStyles.count(style) == 0)
{
// TODO Gee: Output in log
return SGUIScrollBarStyle();
}
return GetGUI()->m_ScrollBarStyles.find(style)->second;
}
void IGUIScrollBarOwner::HandleMessage(const SGUIMessage &Message)
{
vector<IGUIScrollBar*>::iterator it;
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
{
(*it)->HandleMessage(Message);
}
}
void IGUIScrollBarOwner::Draw()
{
vector<IGUIScrollBar*>::iterator it;
for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
{
(*it)->Draw();
}
}

93
source/gui/IGUIScrollBarOwner.h Executable file
View File

@ -0,0 +1,93 @@
/*
GUI Object Base - Scroll-bar owner
by Gustav Larsson
gee@pyro.nu
--Overview--
Base-class this if you want scroll-bars in an object.
--More info--
Check GUI.h
*/
#ifndef IGUIScrollBarOwner_H
#define IGUIScrollBarOwner_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
struct SGUIScrollBarStyle;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* Base-class this if you want an object to contain
* one, or several, scroll-bars.
*
* @see IGUIObject
* @see IGUIScrollBar
*/
class IGUIScrollBarOwner : virtual public IGUIObject
{
public:
IGUIScrollBarOwner();
virtual ~IGUIScrollBarOwner();
virtual void Draw();
/**
* @see IGUIObject#HandleMessage()
*/
virtual void HandleMessage(const SGUIMessage &Message);
/**
*
*/
virtual void ResetStates();
/**
* Interface for the m_ScrollBar to use.
*/
virtual const SGUIScrollBarStyle & GetScrollBarStyle(const CStr &style) const;
/**
* Add a scroll-bar
*/
virtual void AddScrollBar(IGUIScrollBar * scrollbar);
/**
* Get Scroll Bar reference (it should be transparent it's actually
* pointers).
*/
virtual IGUIScrollBar & GetScrollBar(const int &index)
{
return *m_ScrollBars[index];
}
protected:
/**
* Predominately you will only have one, but you can have
* as many as you like.
*/
vector<IGUIScrollBar*> m_ScrollBars;
};
#endif

View File

@ -1,5 +1,5 @@
/*
Object with settings
GUI Object Base - Setting Extension
by Gustav Larsson
gee@pyro.nu
@ -118,7 +118,7 @@ protected:
return (void*)&m_Settings;
default:
// GeeTODO report error
// TODO Gee: Report error
return NULL;
}
}