Index: ps/trunk/binaries/data/gui/hello2.xml
===================================================================
--- ps/trunk/binaries/data/gui/hello2.xml (revision 140)
+++ ps/trunk/binaries/data/gui/hello2.xml (revision 141)
@@ -1,48 +1,68 @@
-
+
+
+
+
+
+ >
+
+
Index: ps/trunk/binaries/data/gui/gui.dtd
===================================================================
--- ps/trunk/binaries/data/gui/gui.dtd (nonexistent)
+++ ps/trunk/binaries/data/gui/gui.dtd (revision 141)
@@ -0,0 +1,140 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Property changes on: ps/trunk/binaries/data/gui/gui.dtd
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIScrollBar.cpp
===================================================================
--- ps/trunk/source/gui/IGUIScrollBar.cpp (nonexistent)
+++ ps/trunk/source/gui/IGUIScrollBar.cpp (revision 141)
@@ -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;
+}
Property changes on: ps/trunk/source/gui/IGUIScrollBar.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIScrollBar.h
===================================================================
--- ps/trunk/source/gui/IGUIScrollBar.h (nonexistent)
+++ ps/trunk/source/gui/IGUIScrollBar.h (revision 141)
@@ -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
Property changes on: ps/trunk/source/gui/IGUIScrollBar.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIButtonBehavior.cpp
===================================================================
--- ps/trunk/source/gui/IGUIButtonBehavior.cpp (revision 140)
+++ ps/trunk/source/gui/IGUIButtonBehavior.cpp (revision 141)
@@ -1,70 +1,76 @@
/*
IGUIButtonBehavior
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx.h"
#include "GUI.h"
using namespace std;
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false)
{
}
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;
break;
/* case GUIM_POSTPROCESS:
// Check if button has been pressed
if (m_Pressed)
{
// Now check if mouse is released, that means
// it's released outside, since GUIM_MOUSE_RELEASE_LEFT
// would've handled m_Pressed and reset it already
// Get input structure
/// if (GetGUI()->GetInput()->mRelease(NEMM_BUTTON1))
{
// Reset
m_Pressed = false;
}
}
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;
// BUTTON WAS CLICKED
HandleMessage(GUIM_PRESSED);
}
break;
case GUIM_SETTINGS_UPDATED:
// If it's hidden, then it can't be pressed
//if (GetBaseSettings().m_Hidden)
// m_Pressed = false;
break;
default:
break;
}
}
Index: ps/trunk/source/gui/IGUISettingsObject.h
===================================================================
--- ps/trunk/source/gui/IGUISettingsObject.h (revision 140)
+++ ps/trunk/source/gui/IGUISettingsObject.h (revision 141)
@@ -1,146 +1,146 @@
/*
-Object with settings
+GUI Object Base - Setting Extension
by Gustav Larsson
gee@pyro.nu
--Overview--
Generic object that stores a struct with settings
--Usage--
If an object wants settings with a standard,
it will use this as a middle step instead of being
directly derived from IGUIObject
--Examples--
instead of:
class CButton : public IGUIObject
you go:
class CButton : public IGUISettingsObject
and SButtonSettings will be included as m_Settings with
all gets and sets set up
--More info--
Check GUI.h
*/
#ifndef IGUISettingsObject_H
#define IGUISettingsObject_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Error declarations
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* Appends more settings to the IGUIObject.
* Can be used with multiple inheritance.
*
* @see IGUIObject
*/
template
class IGUISettingsObject : virtual public IGUIObject
{
public:
IGUISettingsObject() {}
virtual ~IGUISettingsObject() {}
/**
* Get Offsets, important to include so it returns this
* m_Offsets and not IGUIObject::m_SettingsInfo
*
* @return Settings infos
*/
virtual map_Settings GetSettingsInfo() const { return m_SettingsInfo; }
/**
* @return Returns a copy of m_Settings
*/
SETTINGS GetSettings() const { return m_Settings; }
/// Sets settings
void SetSettings(const SETTINGS &Set)
{
m_Settings = Set;
//CheckSettingsValidity();
// Since that function out-commented above really
// does just update the base settings, we'll call
// the message immediately instead
try
{
HandleMessage(GUIM_SETTINGS_UPDATED);
}
catch (...) { }
}
protected:
/**
* You input the setting struct you want, and it will return a pointer to
* the struct.
*
* @param SettingsStruct tells us which pointer to return
*/
virtual void *GetStructPointer(const EGUISettingsStruct &SettingsStruct) const
{
switch (SettingsStruct)
{
case GUISS_BASE:
return (void*)&m_BaseSettings;
case GUISS_EXTENDED:
return (void*)&m_Settings;
default:
- // GeeTODO report error
+ // TODO Gee: Report error
return NULL;
}
}
/// Settings struct
SETTINGS m_Settings;
/**
* Offset database\n
* tells us where a variable by a string name is
* located hardcoded, in order to acquire a pointer
* for that variable... Say "frozen" gives
* the offset from IGUIObject to m_Frozen.
*
* note! _NOT_ from SGUIBaseSettings to m_Frozen!
*
* Note that it's imperative that this m_SettingsInfo includes
* all offsets of m_BaseSettings too, because when
* using this class, this m_SettingsInfo will be the only
* one used.
*/
static map_Settings m_SettingsInfo;
};
#endif
Index: ps/trunk/source/gui/CGUIScrollBarStyle.cpp
===================================================================
--- ps/trunk/source/gui/CGUIScrollBarStyle.cpp (nonexistent)
+++ ps/trunk/source/gui/CGUIScrollBarStyle.cpp (revision 141)
@@ -0,0 +1,10 @@
+/*
+SGUIScrollBarStyle
+by Gustav Larsson
+gee@pyro.nu
+*/
+
+//#include "stdafx.h"
+#include "GUI.h"
+
+using namespace std;
Property changes on: ps/trunk/source/gui/CGUIScrollBarStyle.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIScrollBarOwner.cpp
===================================================================
--- ps/trunk/source/gui/IGUIScrollBarOwner.cpp (nonexistent)
+++ ps/trunk/source/gui/IGUIScrollBarOwner.cpp (revision 141)
@@ -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::iterator it;
+ for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
+ {
+ delete *it;
+ }
+}
+
+void IGUIScrollBarOwner::ResetStates()
+{
+ IGUIObject::ResetStates();
+
+ vector::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::iterator it;
+ for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
+ {
+ (*it)->HandleMessage(Message);
+ }
+}
+
+void IGUIScrollBarOwner::Draw()
+{
+ vector::iterator it;
+ for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
+ {
+ (*it)->Draw();
+ }
+}
\ No newline at end of file
Property changes on: ps/trunk/source/gui/IGUIScrollBarOwner.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIButtonBehavior.h
===================================================================
--- ps/trunk/source/gui/IGUIButtonBehavior.h (revision 140)
+++ ps/trunk/source/gui/IGUIButtonBehavior.h (revision 141)
@@ -1,77 +1,77 @@
/*
-GUI Object - Button
+GUI Object Base - Button Behavior
by Gustav Larsson
gee@pyro.nu
--Overview--
Interface class that enhance the IGUIObject with
buttony behavior (click and release to click a button),
and the GUI message GUIM_PRESSED.
When creating a class with extended settings and
buttony behavior, just do a multiple inheritance.
--More info--
Check GUI.h
*/
#ifndef IGUIButtonBehavior_H
#define IGUIButtonBehavior_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* @author Gustav Larsson
*
* Appends button behaviours to the IGUIObject.
* Can be used with multiple inheritance alongside
* IGUISettingsObject and such.
*
* @see IGUIObject
*/
class IGUIButtonBehavior : virtual public IGUIObject
{
public:
IGUIButtonBehavior();
virtual ~IGUIButtonBehavior();
/**
* @see IGUIObject#HandleMessage()
*/
- virtual void HandleMessage(const EGUIMessage &Message);
+ virtual void HandleMessage(const SGUIMessage &Message);
protected:
virtual void ResetStates()
{
m_MouseHovering = false;
m_Pressed = false;
}
/**
* Everybody knows how a button works, you don't simply press it,
* you have to first press the button, and then release it...
* in between those two steps you can actually leave the button
* area, as long as you release it within the button area... Anyway
* this lets us know we are done with step one (clicking).
*/
bool m_Pressed;
};
#endif
Index: ps/trunk/source/gui/CButton.cpp
===================================================================
--- ps/trunk/source/gui/CButton.cpp (revision 140)
+++ ps/trunk/source/gui/CButton.cpp (revision 141)
@@ -1,110 +1,128 @@
/*
CButton
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx."
#include "GUI.h"
-// temp GeeTODO
+// TODO Gee: font.h is temporary.
#include "font.h"
#include "ogl.h"
using namespace std;
// Offsets
DECLARE_SETTINGS_INFO(SButtonSettings)
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
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";
m_Settings.m_SpriteOver = "null";
m_Settings.m_SpritePressed = "null";
m_Settings.m_TextAlign = EAlign_Center;
// m_Settings.m_TextColor = CColor();
// m_Settings.m_TextColorDisabled;
// m_Settings.m_TextColorOver;
// m_Settings.m_TextColorPressed;
m_Settings.m_TextValign = EValign_Center;
m_Settings.m_ToolTip = "null";
m_Settings.m_ToolTipStyle = "null";
-
+*/
// Static! Only done once
if (m_SettingsInfo.empty())
{
// 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")
}
}
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;
case GUIM_POSTPROCESS:
break;
case GUIM_MOUSE_OVER:
break;
case GUIM_MOUSE_ENTER:
break;
case GUIM_MOUSE_LEAVE:
break;
case GUIM_MOUSE_PRESS_LEFT:
break;
case GUIM_MOUSE_RELEASE_LEFT:
break;
case GUIM_PRESSED:
GetGUI()->TEMPmessage = "Button " + string((const TCHAR*)m_Name) + " was pressed!";
break;
default:
break;
}
}
-void CButton::Draw()
+void CButton::Draw()
{
////////// Gee: janwas, this is just temp to see it
glDisable(GL_TEXTURE_2D);
//////////
if (GetGUI())
{
- if (m_Pressed && m_Settings.m_SpritePressed != CStr("null"))
- GetGUI()->DrawSprite(m_Settings.m_SpritePressed, GetBaseSettings().m_Z, m_CachedActualSize);
- else
- if (m_MouseHovering && !m_Pressed && m_Settings.m_SpriteOver != CStr("null"))
- GetGUI()->DrawSprite(m_Settings.m_SpriteOver, 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
- 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);
}
}
Index: ps/trunk/source/gui/CGUIScrollBarStyle.h
===================================================================
--- ps/trunk/source/gui/CGUIScrollBarStyle.h (nonexistent)
+++ ps/trunk/source/gui/CGUIScrollBarStyle.h (revision 141)
@@ -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
Property changes on: ps/trunk/source/gui/CGUIScrollBarStyle.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIScrollBarOwner.h
===================================================================
--- ps/trunk/source/gui/IGUIScrollBarOwner.h (nonexistent)
+++ ps/trunk/source/gui/IGUIScrollBarOwner.h (revision 141)
@@ -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 m_ScrollBars;
+};
+
+#endif
Property changes on: ps/trunk/source/gui/IGUIScrollBarOwner.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/CButton.h
===================================================================
--- ps/trunk/source/gui/CButton.h (revision 140)
+++ ps/trunk/source/gui/CButton.h (revision 141)
@@ -1,99 +1,98 @@
/*
GUI Object - Button
by Gustav Larsson
gee@pyro.nu
--Overview--
GUI Object representing a simple button
--More info--
Check GUI.h
*/
#ifndef CButton_H
#define CButton_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
/**
* Button Settings
*/
struct SButtonSettings
{
- bool m_Disabled;
CStr m_Font;
CStr m_Sprite;
CStr m_SpriteDisabled;
CStr m_SpriteOver;
CStr m_SpritePressed;
EAlign m_TextAlign;
CColor m_TextColor;
CColor m_TextColorDisabled;
CColor m_TextColorOver;
CColor m_TextColorPressed;
EValign m_TextValign;
CStr m_ToolTip;
CStr m_ToolTipStyle;
};
///////////////////////////////////////////////////////////////////////////////
/**
* @author Gustav Larsson
*
* Button
*
* @see IGUIObject
* @see IGUISettingsObject
* @see IGUIButtonBehavior
* @see SButtonSettings
*/
class CButton : public IGUISettingsObject, public IGUIButtonBehavior
{
GUI_OBJECT(CButton)
public:
CButton();
virtual ~CButton();
/**
* Since we're doing multiple inheritance, this is to avoid error message
*
* @return Settings infos
*/
virtual map_Settings GetSettingsInfo() const { return IGUISettingsObject::m_SettingsInfo; }
virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
/**
* Handle Messages
*
* @param Message GUI Message
*/
- virtual void HandleMessage(const EGUIMessage &Message);
+ virtual void HandleMessage(const SGUIMessage &Message);
/**
* Draws the Button
*/
virtual void Draw();
};
#endif
Index: ps/trunk/source/gui/IGUIObject.cpp
===================================================================
--- ps/trunk/source/gui/IGUIObject.cpp (revision 140)
+++ ps/trunk/source/gui/IGUIObject.cpp (revision 141)
@@ -1,335 +1,381 @@
/*
IGUIObject
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx."
#include "GUI.h"
///// janwas: again, including etiquette?
#include "Parser.h"
#include
/////
using namespace std;
// Offsets
map_Settings IGUIObject::m_SettingsInfo;
//-------------------------------------------------------------------
// Implementation Macros
//-------------------------------------------------------------------
/*#define _GUI_ADD_OFFSET(type, str, var) \
SettingsInfo[str].m_Offset = offsetof(IGUIObject, m_BaseSettings) + offsetof(SGUIBaseSettings,var); \
SettingsInfo[str].m_Type = type;
*/
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
IGUIObject::IGUIObject() :
m_pGUI(NULL),
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
if (m_SettingsInfo.empty())
{
SetupBaseSettingsInfo(m_SettingsInfo);
}
}
IGUIObject::~IGUIObject()
{
}
//-------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------
void IGUIObject::AddChild(IGUIObject *pChild)
{
//
// assert(pChild);
pChild->SetParent(this);
m_Children.push_back(pChild);
// If this (not the child) object is already attached
// to a CGUI, it pGUI pointer will be non-null.
// This will mean we'll have to check if we're using
// names already used.
if (pChild->GetGUI())
{
try
{
// Atomic function, if it fails it won't
// have changed anything
//UpdateObjects();
pChild->GetGUI()->UpdateObjects();
}
catch (PS_RESULT e)
{
// If anything went wrong, reverse what we did and throw
// an exception telling it never added a child
m_Children.erase( m_Children.end()-1 );
// We'll throw the same exception for easier
// error handling
throw e;
}
}
// else do nothing
}
void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap)
{
// Just don't do anything about the top node
if (m_pParent == NULL)
return;
// Now actually add this one
// notice we won't add it if it's doesn't have any parent
// (i.e. being the base object)
if (m_Name == string())
{
throw PS_NEEDS_NAME;
}
if (ObjectMap.count(m_Name) > 0)
{
throw PS_NAME_AMBIGUITY;
}
else
{
ObjectMap[m_Name] = this;
}
}
void IGUIObject::Destroy()
{
// Is there anything besides the children to destroy?
}
void IGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo)
{
/* _GUI_ADD_OFFSET("bool", "enabled", m_Enabled)
_GUI_ADD_OFFSET("bool", "hidden", m_Hidden)
_GUI_ADD_OFFSET("client area", "size", m_Size)
_GUI_ADD_OFFSET("string", "style", m_Style)
_GUI_ADD_OFFSET("float", "z", m_Z)
_GUI_ADD_OFFSET("string", "caption", m_Caption)
_GUI_ADD_OFFSET("bool", "absolute", m_Absolute)
*/
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Enabled, "bool", "enabled")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Hidden, "bool", "hidden")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Size, "client area", "size")
GUI_ADD_OFFSET_GENERIC(SettingsInfo, GUISS_BASE, SGUIBaseSettings, m_Style, "string", "style")
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()
{
if(!GetGUI())
throw PS_NEEDS_PGUI;
u16 mouse_x = GetMouseX(),
mouse_y = GetMouseY();
return (mouse_x >= m_CachedActualSize.left &&
mouse_x <= m_CachedActualSize.right &&
mouse_y >= m_CachedActualSize.top &&
mouse_y <= m_CachedActualSize.bottom);
}
u16 IGUIObject::GetMouseX() const
{
return ((GetGUI())?(GetGUI()->m_MouseX):0);
}
u16 IGUIObject::GetMouseY() const
{
return ((GetGUI())?(GetGUI()->m_MouseY):0);
}
void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver)
{
// Check if this is the object being hovered.
if (pMouseOver == this)
{
if (!m_MouseHovering)
{
// It wasn't hovering, so that must mean it just entered
HandleMessage(GUIM_MOUSE_ENTER);
}
// Either way, set to true
m_MouseHovering = true;
// call mouse over
HandleMessage(GUIM_MOUSE_OVER);
}
else // Some other object (or none) is hovered
{
if (m_MouseHovering)
{
m_MouseHovering = false;
HandleMessage(GUIM_MOUSE_LEAVE);
}
}
}
bool IGUIObject::SettingExists(const CStr &Setting) const
{
// Because GetOffsets will direct dynamically defined
// classes with polymorifsm to respective m_SettingsInfo
// we need to make no further updates on this function
// in derived classes.
return (GetSettingsInfo().count(Setting) == 1)?true:false;
}
void IGUIObject::SetSetting(const CStr &Setting, const CStr &Value)
{
if (!SettingExists(Setting))
{
throw PS_FAIL;
}
// Get setting
SGUISetting set = GetSettingsInfo()[Setting];
if (set.m_Type == CStr(_T("string")))
{
GUI::SetSetting(this, Setting, Value);
}
else
if (set.m_Type == CStr(_T("bool")))
{
bool _Value;
if (!GUI::ParseString(Value, _Value))
throw PS_FAIL;
GUI::SetSetting(this, Setting, _Value);
}
else
if (set.m_Type == CStr(_T("float")))
{
float _Value;
if (!GUI::ParseString(Value, _Value))
throw PS_FAIL;
GUI::SetSetting(this, Setting, _Value);
}
else
if (set.m_Type == CStr(_T("rect")))
{
CRect _Value;
if (!GUI::ParseString(Value, _Value))
throw PS_FAIL;
GUI::SetSetting(this, Setting, _Value);
}
else
if (set.m_Type == CStr(_T("client area")))
{
CClientArea _Value;
if (!GUI::ParseString(Value, _Value))
throw PS_FAIL;
GUI::SetSetting(this, Setting, _Value);
}
else
{
throw PS_FAIL;
}
}
void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
{
if (MouseOver())
{
// Check if we've got competition at all
if (pObject == NULL)
{
pObject = this;
return;
}
// Or if it's closer
- if (GetBaseSettings().m_Z >= pObject->GetBaseSettings().m_Z)
+ if (GetBufferedZ() >= pObject->GetBufferedZ())
{
pObject = this;
return;
}
}
}
-IGUIObject *IGUIObject::GetParent()
+IGUIObject *IGUIObject::GetParent() const
{
// Important, we're not using GetParent() for these
// checks, that could screw it up
if (m_pParent)
{
if (m_pParent->m_pParent == NULL)
return NULL;
}
return m_pParent;
}
void * IGUIObject::GetStructPointer(const EGUISettingsStruct &SettingsStruct) const
{
switch (SettingsStruct)
{
case GUISS_BASE:
return (void*)&m_BaseSettings;
default:
- // GeeTODO report error
+ // TODO Gee: report error
return NULL;
}
}
void IGUIObject::UpdateCachedSize()
{
// If absolute="false" and the object has got a parent,
// use its cached size instead of the screen. Notice
// it must have just been cached for it to work.
if (m_BaseSettings.m_Absolute == false && m_pParent)
m_CachedActualSize = m_BaseSettings.m_Size.GetClientArea( m_pParent->m_CachedActualSize );
else
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::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
if (GetBaseSettings().m_Hidden)
{
// Simulate that no object is hovered for this object and all its children
// why? because it's
try
{
GUI::RecurseObject(0, this, &IGUIObject::UpdateMouseOver, NULL);
}
catch (...) {}
}
try
{
// Send message to itself
HandleMessage(GUIM_SETTINGS_UPDATED);
}
catch (...)
{
}
}
Index: ps/trunk/source/gui/GUIbase.h
===================================================================
--- ps/trunk/source/gui/GUIbase.h (revision 140)
+++ ps/trunk/source/gui/GUIbase.h (revision 141)
@@ -1,129 +1,157 @@
/*
GUI Core, stuff that the whole GUI uses
by Gustav Larsson
gee@pyro.nu
--Overview--
Contains defines, includes, types etc that the whole
GUI should have included.
--More info--
Check GUI.h
*/
#ifndef GUIbase_H
#define GUIbase_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
//--------------------------------------------------------
// Forward declarations
//--------------------------------------------------------
class IGUIObject;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
// 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; \
si[CStr(str)].m_Type = CStr(type);
#define GUI_ADD_OFFSET_BASE(_struct, var, type, str) \
GUI_ADD_OFFSET_GENERIC(m_SettingsInfo, GUISS_BASE, _struct, var, type, str)
#define GUI_ADD_OFFSET_EXT(_struct, var, type, str) \
GUI_ADD_OFFSET_GENERIC(m_SettingsInfo, GUISS_EXTENDED, _struct, var, type, str)
// Declares the static variable in IGUISettingsObject<>
#define DECLARE_SETTINGS_INFO(_struct) \
map_Settings IGUISettingsObject<_struct>::m_SettingsInfo;
// Setup an object's ConstructObject function
#define GUI_OBJECT(obj) \
public: \
static IGUIObject *ConstructObject() { return new obj(); }
//--------------------------------------------------------
// Types
//--------------------------------------------------------
/**
* @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
GUIM_MOUSE_OVER,
GUIM_MOUSE_ENTER,
GUIM_MOUSE_LEAVE,
GUIM_MOUSE_PRESS_LEFT,
GUIM_MOUSE_PRESS_RIGHT,
GUIM_MOUSE_DOWN_LEFT,
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;
};
/**
* Recurse restrictions, when we recurse, if an object
* is hidden for instance, you might want it to skip
* the children also
* Notice these are flags! and we don't really need one
* for no restrictions, because then you'll just enter 0
*/
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
{
GUISS_BASE,
GUISS_EXTENDED
};
// Typedefs
typedef std::map map_pObjects;
typedef std::vector vector_pObjects;
//--------------------------------------------------------
// Error declarations
//--------------------------------------------------------
DECLARE_ERROR(PS_NAME_TAKEN)
DECLARE_ERROR(PS_OBJECT_FAIL)
DECLARE_ERROR(PS_SETTING_FAIL)
DECLARE_ERROR(PS_VALUE_INVALID)
DECLARE_ERROR(PS_NEEDS_PGUI)
DECLARE_ERROR(PS_NAME_AMBIGUITY)
DECLARE_ERROR(PS_NEEDS_NAME)
DECLARE_ERROR(PS_LEXICAL_FAIL)
DECLARE_ERROR(PS_SYNTACTICAL_FAIL)
#endif
Index: ps/trunk/source/gui/CGUIScrollBarVertical.cpp
===================================================================
--- ps/trunk/source/gui/CGUIScrollBarVertical.cpp (nonexistent)
+++ ps/trunk/source/gui/CGUIScrollBarVertical.cpp (revision 141)
@@ -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);
+}
Property changes on: ps/trunk/source/gui/CGUIScrollBarVertical.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/GUIutil.h
===================================================================
--- ps/trunk/source/gui/GUIutil.h (revision 140)
+++ ps/trunk/source/gui/GUIutil.h (revision 141)
@@ -1,548 +1,565 @@
/*
GUI util
by Gustav Larsson
gee@pyro.nu
--Overview--
Contains help class GUI<>, which gives us templated
parameter to all functions within GUI.
--More info--
Check GUI.h
*/
#ifndef GUIutil_H
#define GUIutil_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
#include "Parser.h"
//--------------------------------------------------------
// Help Classes/Structs for the GUI
//--------------------------------------------------------
// TEMP
struct CRect
{
CRect() {}
CRect(int _l, int _t, int _r, int _b) :
left(_l),
top(_t),
right(_r),
bottom(_b) {}
int bottom, top, left, right;
bool operator ==(const CRect &rect) const
{
return (bottom==rect.bottom) &&
(top==rect.top) &&
(left==rect.left) &&
(right==rect.right);
}
bool operator !=(const CRect &rect) const
{
return !(*this==rect);
}
};
// TEMP
struct CColor
{
float r, g, b, a;
};
/**
* @author Gustav Larsson
*
* Client Area is a rectangle relative to a parent rectangle
*
* You can input the whole value of the Client Area by
* string. Like used in the GUI.
*/
struct CClientArea
{
public:
CClientArea();
CClientArea(const CStr &Value);
/// Pixel modifiers
CRect pixel;
/// Percent modifiers (I'll let this be integers, I don't think a greater precision is needed)
CRect percent;
/**
* Get client area rectangle when the parent is given
*/
CRect GetClientArea(const CRect &parent) const;
/**
* The ClientArea can be set from a string looking like:
*
* @code
* "0 0 100% 100%"
* "50%-10 50%-10 50%+10 50%+10" @endcode
*
* i.e. First percent modifier, then + or - and the pixel modifier.
* Although you can use just the percent or the pixel modifier. Notice
* though that the percent modifier must always be the first when
* both modifiers are inputted.
*
* @return true if success, false if failure. If false then the client area
* will be unchanged.
*/
bool SetClientArea(const CStr &Value);
};
//--------------------------------------------------------
// Forward declarations
//--------------------------------------------------------
class CGUI;
class IGUIObject;
/**
* @author Gustav Larsson
*
* Base class to only the class GUI. This superclass is
* kind of a templateless extention of the class GUI.
* Used for other functions to friend with, because it
* it can't friend with GUI since it's templated.
*/
class CInternalCGUIAccessorBase
{
protected:
/// Get object pointer
static IGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr &Object);
/// const version
static const IGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr &Object);
/// Wrapper for ResetStates
static void QueryResetting(IGUIObject *pObject);
};
/**
* @author Gustav Larsson
*
* Includes static functions that needs one template
* argument.
*
* int is only to please functions that doesn't even use T
* and are only within this class because it's convenient
*/
template
class GUI : public CInternalCGUIAccessorBase
{
// Private functions further ahead
friend class CGUI;
friend class IGUIObject;
friend class CInternalCGUIAccessorBase;
public:
/**
* Retrieves a setting by name from object pointer
*
* @param pObject Object pointer
* @param Setting Setting by name
* @param Value Stores value here, note type T!
*/
static PS_RESULT GetSetting(const IGUIObject *pObject, const CStr &Setting, T &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
// Set value
Value =
*(T*)((size_t)pObject->GetStructPointer(pObject->GetSettingsInfo()[Setting].m_SettingsStruct) +
pObject->GetSettingsInfo()[Setting].m_Offset);
return PS_OK;
}
/**
* Sets a value by name using a real datatype as input.
*
* This is the official way of setting a setting, no other
* way should only causiously be used!
*
* @param pObject Object pointer
* @param Setting Setting by name
* @param Value Sets value to this, note type T!
*/
static PS_RESULT SetSetting(IGUIObject *pObject, const CStr &Setting, const T &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
// Set value
*(T*)((size_t)pObject->GetStructPointer(pObject->GetSettingsInfo()[Setting].m_SettingsStruct) +
pObject->GetSettingsInfo()[Setting].m_Offset) = Value;
//
// Some settings needs special attention at change
//
// If setting was "size", we need to re-cache itself and all children
if (Setting == CStr(_T("size")))
{
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
}
else
if (Setting == CStr(_T("hidden")))
{
// Hiding an object requires us to reset it and all children
QueryResetting(pObject);
//RecurseObject(0, pObject, IGUIObject::ResetStates);
}
+ pObject->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
+
return PS_OK;
}
/**
* Retrieves a setting by settings name and object name
*
* @param GUI GUI Object const ref
* @param Object Object name
* @param Setting Setting by name
* @param Value Stores value here, note type T!
*/
static PS_RESULT GetSetting(
const CGUI &GUIinstance, const CStr &Object,
const CStr &Setting, T &Value)
{
if (!GUIinstance.ObjectExists(Object))
return PS_OBJECT_FAIL;
// Retrieve pointer and call sibling function
const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
return GetSetting(pObject, Setting, Value);
}
/**
* Sets a value by setting and object name using a real
* datatype as input
*
* This is just a wrapper so that we can type the object name
* and not input the actual pointer.
*
* @param GUI GUI Object, reference since we'll be changing values
* @param Object Object name
* @param Setting Setting by name
* @param Value Sets value to this, note type T!
*/
static PS_RESULT SetSetting(
CGUI &GUIinstance, const CStr &Object,
const CStr &Setting, const T &Value)
{
if (!GUIinstance.ObjectExists(Object))
return PS_OBJECT_FAIL;
// Retrieve pointer and call sibling function
// Important, we don't want to use this T, we want
// to use the standard T, since that will be the
// one with the friend relationship
IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
return SetSetting(pObject, Setting, Value);
}
/**
* Sets a value by setting and object name using a real
* datatype as input.
*
* This is just a wrapper for _mem_ParseString() which really
* works the magic.
*
* @param Type type in string, like "float" or "client area"
* @param Value The value in string form, like "0 0 100% 100%"
* @param tOutput Parsed value of type T
* @return True at success.
*
* @see _mem_ParseString()
*/
static bool ParseString(const CStr &Value, T &tOutput)
{
void *mem = NULL;
if (!_mem_ParseString(Value, mem))
return false;
// Copy from memory
tOutput = *(T*)mem;
delete [] mem;
- // Undefined type - GeeTODO, maybe report in log
+ // TODO Gee: Undefined type - maybe report in log
return true;
}
private:
/**
* Input a value in string form, and it will output the result in
* Memory with type T.
*
* @param Type type in string, like "float" or "client area"
* @param Value The value in string form, like "0 0 100% 100%"
* @param Memory Should be NULL, will be constructed within the function.
* @return True at success.
*/
static bool _mem_ParseString(const CStr &Value, void *&Memory)
{
/* if (typeid(T) == typeid(CStr))
{
tOutput = Value;
return true;
}
else
*/ if (typeid(T) == typeid(bool))
{
bool _Value;
if (Value == CStr(_T("true")))
_Value = true;
else
if (Value == CStr(_T("false")))
_Value = false;
else
return false;
Memory = malloc(sizeof(bool));
memcpy(Memory, (const void*)&_Value, sizeof(bool));
return true;
}
else
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
CParser parser;
parser.InputTaskType("", "_$value_$value_$value_$value_");
string str = (const TCHAR*)Value;
CParserLine line;
line.ParseString(parser, str);
if (!line.m_ParseOK)
{
// Parsing failed
return false;
}
int values[4];
for (int i=0; i<4; ++i)
{
if (!line.GetArgInt(i, values[i]))
{
// Parsing failed
return false;
}
}
// Finally the rectangle values
CRect _Value(values[0], values[1], values[2], values[3]);
Memory = malloc(sizeof(CRect));
memcpy(Memory, (const void*)&_Value, sizeof(CRect));
return true;
}
else
if (typeid(T) == typeid(CClientArea))
{
// Get Client Area
CClientArea _Value;
// Check if valid!
if (!_Value.SetClientArea(Value))
{
return false;
}
Memory = malloc(sizeof(CClientArea));
memcpy(Memory, (const void*)&_Value, sizeof(CClientArea));
return true;
}
else
if (typeid(T) == typeid(CColor))
{
// Use the parser to parse the values
CParser parser;
parser.InputTaskType("", "_$value_$value_$value_[$value_]");
string str = (const TCHAR*)Value;
CParserLine line;
line.ParseString(parser, str);
if (!line.m_ParseOK)
{
- // Parsing failed GeeTODO
+ // TODO Gee: Parsing failed
return false;
}
float values[4];
values[3] = 255.f; // default
for (int i=0; iRestrictions:\n
* You can also set restrictions, so that if the recursion
* reaches an objects with certain setup, it just doesn't
* call the function on the object, nor it's children for
* that matter. i.e. it cuts that object off from the
* recursion tree. What setups that can cause restrictions
* are hardcoded and specific. Check out the defines
* GUIRR_* for all different setups.
*
* Error reports are either logged or thrown out of RecurseObject.
* Always use it with try/catch!
*
* @param RR Recurse Restrictions, set to 0 if no restrictions
* @param pObject Top object, this is where the iteration starts
* @param pFunc Function to recurse
* @param Argument Argument for pFunc of type T
* @throws PS_RESULT Depends on what pFunc might throw. PS_RESULT is standard.
* Itself doesn't throw anything.
*/
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;
(pObject->*pFunc)(Argument);
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc, Argument);
}
}
/**
* Argument is reference.
*
* @see RecurseObject()
*/
static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument)
{
if (CheckIfRestricted(RR, pObject))
return;
(pObject->*pFunc)(Argument);
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc, Argument);
}
}
/**
* With no argument.
*
* @see RecurseObject()
*/
static void RecurseObject(const int &RR, IGUIObject *pObject, void_Object_pFunction pFunc)
{
if (CheckIfRestricted(RR, pObject))
return;
(pObject->*pFunc)();
-
+
// Iterate children
vector_pObjects::iterator it;
for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
{
RecurseObject(RR, *it, pFunc);
}
}
private:
/**
* Checks restrictions for the iteration, for instance if
* you tell the recursor to avoid all hidden objects, it
* will, and this function checks a certain object's
* restriction values.
*
* @param RR What kind of restriction, for instance hidden or disabled
* @param pObject Object
* @return true if restricted
*/
static bool CheckIfRestricted(const int &RR, IGUIObject *pObject)
{
if (RR & GUIRR_HIDDEN)
{
if (pObject->GetBaseSettings().m_Hidden)
return true;
}
if (RR & GUIRR_DISABLED)
{
if (pObject->GetBaseSettings().m_Enabled)
return true;
}
+ if (RR & GUIRR_GHOST)
+ {
+ if (pObject->GetBaseSettings().m_Ghost)
+ return true;
+ }
// false means not restricted
return false;
}
};
#endif
Index: ps/trunk/source/gui/CGUI.cpp
===================================================================
--- ps/trunk/source/gui/CGUI.cpp (revision 140)
+++ ps/trunk/source/gui/CGUI.cpp (revision 141)
@@ -1,888 +1,1000 @@
/*
CGUI
by Gustav Larsson
gee@pyro.nu
*/
//#include "stdafx."
#include "GUI.h"
-#include
-#include
-#include
-
#include
#include
#include
#include
#include
#include "XercesErrorHandler.h"
#include "Prometheus.h"
#include "input.h"
+#include
+#include
+#include
+
// namespaces used
XERCES_CPP_NAMESPACE_USE
using namespace std;
#ifdef _MSC_VER
#pragma comment(lib, "xerces-c_2.lib")
#endif
//-------------------------------------------------------------------
// called from main loop when (input) events are received.
// event is passed to other handlers if false is returned.
// trampoline: we don't want to make the implementation (in CGUI) static
//-------------------------------------------------------------------
bool gui_handler(const SDL_Event& ev)
{
return g_GUI.HandleEvent(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::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
IGUIObject *pNearest = NULL;
try
{
// pNearest will after this point at the hovered object, possibly NULL
- GUI::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
+ GUI::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::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
+ GUI::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);
-
- // some temp
- CClientArea ca;
- bool hidden;
-
- GUI::GetSetting(*this, CStr("Child1"), CStr("size"), ca);
- GUI::GetSetting(*this, CStr("Child1"), CStr("hidden"), hidden);
-
- //hidden = !hidden;
- ca.pixel.left -= 30;
- ca.pixel.bottom += 15;
+ switch (ev.button.button)
+ {
+ case SDL_BUTTON_LEFT:
+ if (pNearest)
+ {
+ pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_PRESS_LEFT));
+
+ // some temp
+ CClientArea ca;
+ bool hidden;
+
+ /*GUI::GetSetting(*this, CStr("backdrop"), CStr("size"), ca);
+ GUI::GetSetting(*this, CStr("backdrop"), CStr("hidden"), hidden);
+
+ //hidden = !hidden;
+ ca.pixel.right += 3;
+ ca.pixel.bottom += 3;
+
+ GUI::SetSetting(*this, CStr("backdrop"), CStr("size"), ca);
+ GUI::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;
- GUI::SetSetting(*this, CStr("Child1"), CStr("size"), ca);
- GUI::SetSetting(*this, CStr("Child1"), CStr("hidden"), hidden);
+ 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);
-
- // It will have reset the mouse over of the current hovered, so we'll
- // have to restore that
- if (pNearest)
- pNearest->m_MouseHovering = true;
+ // 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;
+ }
}
}
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
if (m_pInput->mDown(NEMM_BUTTON1) && pNearest)
{
pNearest->HandleMessage(GUIM_MOUSE_DOWN_LEFT);
}
*/
return false;
}
//-------------------------------------------------------------------
// Constructor / Destructor
//-------------------------------------------------------------------
CGUI::CGUI()
{
m_BaseObject = new CGUIDummyObject;
m_BaseObject->SetGUI(this);
// This will make this invisible, not add
//m_BaseObject->SetName(BASE_OBJECT_NAME);
}
CGUI::~CGUI()
{
if (m_BaseObject)
delete m_BaseObject;
}
//-------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------
IGUIObject *CGUI::ConstructObject(const CStr &str)
{
if (m_ObjectTypes.count(str) > 0)
return (*m_ObjectTypes[str])();
else
{
- // Report in log (GeeTODO)
+ // TODO Gee: Report in log
return NULL;
}
}
void CGUI::Initialize()
{
// Add base types!
// 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
try
{
GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_PREPROCESS);
}
catch (PS_RESULT e)
{
return;
}
// Check mouse over
try
{
// Only one object can be hovered
// check which one it is, if any !
IGUIObject *pNearest = NULL;
GUI::RecurseObject(GUIRR_HIDDEN, 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::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::UpdateMouseOver, pNearest);
// If pressed
if (m_pInput->mPress(NEMM_BUTTON1) && pNearest)
{
pNearest->HandleMessage(GUIM_MOUSE_PRESS_LEFT);
}
else
// If released
if (m_pInput->mRelease(NEMM_BUTTON1) && pNearest)
{
pNearest->HandleMessage(GUIM_MOUSE_RELEASE_LEFT);
}
// Generally if just mouse is clicked
if (m_pInput->mDown(NEMM_BUTTON1) && pNearest)
{
pNearest->HandleMessage(GUIM_MOUSE_DOWN_LEFT);
}
}
catch (PS_RESULT e)
{
return;
}
// Post-process all objects
try
{
GUI::RecurseObject(0, m_BaseObject, &IGUIObject::HandleMessage, GUIM_POSTPROCESS);
}
catch (PS_RESULT e)
{
return;
}
*/
}
void CGUI::Draw()
{
glPushMatrix();
glLoadIdentity();
// Adapt (origio) to being in top left corner and down
// just like the mouse position
glTranslatef(0.0f, g_yres, -1000.0f);
glScalef(1.0f, -1.f, 1.0f);
try
{
// Recurse IGUIObject::Draw() with restriction: hidden
// meaning all hidden objects won't call Draw (nor will it recurse its children)
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, &IGUIObject::Draw);
}
catch (PS_RESULT e)
{
glPopMatrix();
- // GeeTODO
+ // TODO Gee: Report error.
return;
}
glPopMatrix();
}
void CGUI::DrawSprite(const CStr &SpriteName,
const float &Z,
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));
CGUISprite Sprite;
// Fetch real sprite from name
if (m_Sprites.count(SpriteName) == 0)
{
- // GeeTODO report error
+ // TODO Gee: Report error
return;
}
else Sprite = m_Sprites[SpriteName];
glPushMatrix();
glTranslatef(0.0f, 0.0f, Z);
// Iterate all images and request them being drawn be the
// CRenderer
std::vector::const_iterator cit;
for (cit=Sprite.m_Images.begin(); cit!=Sprite.m_Images.end(); ++cit)
{
CRect real = cit->m_Size.GetClientArea(Rect);
glColor3f(cit->m_BackColor.r , cit->m_BackColor.g, cit->m_BackColor.b);
//glColor3f((float)real.right/1000.f, 0.5f, 0.5f);
// Do this
glBegin(GL_QUADS);
glVertex2i(real.right, real.bottom);
glVertex2i(real.left, real.bottom);
glVertex2i(real.left, real.top);
glVertex2i(real.right, real.top);
glEnd();
}
glPopMatrix();
}
void CGUI::Destroy()
{
// We can use the map to delete all
// now we don't want to cancel all if one Destroy fails
map_pObjects::iterator it;
for (it = m_pAllObjects.begin(); it != m_pAllObjects.end(); ++it)
{
try
{
it->second->Destroy();
}
catch (PS_RESULT e)
{
- // GeeTODO
+ // TODO Gee: Handle
}
delete it->second;
it->second = NULL;
}
// Clear all
m_pAllObjects.clear();
m_Sprites.clear();
}
void CGUI::UpdateResolution()
{
// Update ALL cached
GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize );
}
void CGUI::AddObject(IGUIObject* pObject)
{
try
{
// Add CGUI pointer
GUI::RecurseObject(0, pObject, &IGUIObject::SetGUI, this);
// Add child to base object
m_BaseObject->AddChild(pObject);
// Cache tree
GUI<>::RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
}
catch (PS_RESULT e)
{
throw e;
}
}
void CGUI::UpdateObjects()
{
// We'll fill a temporary map until we know everything
// succeeded
map_pObjects AllObjects;
try
{
// Fill freshly
GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects );
}
catch (PS_RESULT e)
{
// Throw the same error
throw e;
}
// Else actually update the real one
m_pAllObjects = AllObjects;
}
bool CGUI::ObjectExists(const CStr &Name) const
{
if (m_pAllObjects.count(Name))
return true;
else
return false;
}
void CGUI::ReportParseError(const CStr &str, ...)
{
// Print header
if (m_Errors==0)
{
/// g_nemLog("*** GUI Tree Creation Errors");
}
// Important, set ParseError to true
++m_Errors;
-/* MEGA GeeTODO
+/* TODO Gee: (MEGA)
char buffer[512];
va_list args;
// get arguments
va_start(args, str);
vsprintf(buffer, str.c_str(), args);
va_end(args);
*/
/// g_nemLog(" %s", buffer);
}
/**
* @callgraph
*/
void CGUI::LoadXMLFile(const string &Filename)
{
// Reset parse error
// we can later check if this has increased
m_Errors = 0;
// Initialize XML library
XMLPlatformUtils::Initialize();
+ {
+ // Create parser instance
+ XercesDOMParser *parser = new XercesDOMParser();
- // Create parser instance
- XercesDOMParser *parser = new XercesDOMParser();
-
- bool ParseFailed = false;
+ bool ParseFailed = false;
- if (parser)
- {
- // 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);
-
- try
+ 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() ) );
// parse
parser->parse(source);
// Check how many errors
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);
+ // 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;
}
-
XMLPlatformUtils::Terminate();
-
}
//===================================================================
// XML Reading Xerces Specific Sub-Routines
//===================================================================
void CGUI::Xerces_ReadRootObjects(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
// Iterate main children
// they should all be elements
DOMNodeList *children = pElement->getChildNodes();
-
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
DOMNode *child = children->item(i);
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// Read in this whole object into the GUI
DOMElement *element = (DOMElement*)child;
Xerces_ReadObject(element, m_BaseObject);
}
}
}
void CGUI::Xerces_ReadRootSprites(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
// Iterate main children
// they should all be elements
DOMNodeList *children = pElement->getChildNodes();
-
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
DOMNode *child = children->item(i);
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// Read in this whole object into the GUI
DOMElement *element = (DOMElement*)child;
Xerces_ReadSprite(element);
}
}
}
void CGUI::Xerces_ReadRootStyles(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
// Iterate main children
// they should all be elements
DOMNodeList *children = pElement->getChildNodes();
-
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
DOMNode *child = children->item(i);
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// Read in this whole object into the GUI
DOMElement *element = (DOMElement*)child;
Xerces_ReadStyle(element);
}
}
}
+void CGUI::Xerces_ReadRootSetup(XERCES_CPP_NAMESPACE::DOMElement *pElement)
+{
+ // Iterate main children
+ // they should all be , or .
+ DOMNodeList *children = pElement->getChildNodes();
+ for (u16 i=0; igetLength(); ++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;
// Well first of all we need to determine the type
CStr type = XMLString::transcode( pElement->getAttribute( XMLString::transcode("type") ) );
// Construct object from specified type
// henceforth, we need to do a rollback before aborting.
// i.e. releasing this object
object = ConstructObject(type);
if (!object)
{
// Report error that object was unsuccessfully loaded
ReportParseError(CStr("Unrecognized type: ") + type);
delete object;
return;
}
//
// 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::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();
for (i=0; igetLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
CStr attr_value = XMLString::transcode( attr->getValue() );
// Ignore "type" and "style", we've already checked it
if (attr_name == CStr("type") || attr_name == CStr("style") )
continue;
// Also the name needs some special attention
if (attr_name == CStr("name"))
{
object->SetName(attr_value);
NameSet = true;
continue;
}
+ if (attr_name == CStr("z"))
+ ManuallySetZ = true;
+
// Try setting the value
try
{
object->SetSetting(attr_name, attr_value);
}
catch (PS_RESULT e)
{
ReportParseError(CStr("Can't set \"") + attr_name + CStr("\" to \"") + attr_value + CStr("\""));
// This is not a fatal error
}
}
// Check if name isn't set, report error in that case
if (!NameSet)
{
- // Generate internal name! GeeTODO
+ // TODO Gee: Generate internal name!
}
//
// Read Children
//
// Iterate children
DOMNodeList *children = pElement->getChildNodes();
for (i=0; igetLength(); ++i)
{
// Get node
DOMNode *child = children->item(i);
// Check type (it's probably text or element)
// A child element
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// Check what name the elements got
string element_name = XMLString::transcode( child->getNodeName() );
if (element_name == "object")
{
// 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);
}
}
else
if (child->getNodeType() == DOMNode::TEXT_NODE)
{
CStr caption = XMLString::transcode( child->getNodeValue() );
// Text is only okay if it's the first element i.e. caption ...
if (i==0)
{
// Thank you CStr =)
-// caption.Trim(PS_TRIM_BOTH);
+ caption.Trim(PS_TRIM_BOTH);
// Set the setting caption to this
GUI::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::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f);
+ }
+ else
+ // If the object is relative, then we'll just store Z as "10"
+ {
+ GUI::SetSetting(object, "z", 10.f);
+ }
+ }
+ }
+
+
+ //
// Input Child
//
try
{
if (pParent == m_BaseObject)
AddObject(object);
else
pParent->AddChild(object);
}
catch (PS_RESULT e)
{
ReportParseError(e);
}
}
void CGUI::Xerces_ReadSprite(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
assert(pElement);
// Sprite object we're adding
CGUISprite sprite;
// and what will be its reference name
CStr name;
//
// Read Attributes
//
// Get name, we know it exists because of DTD requirements
name = XMLString::transcode( pElement->getAttribute( XMLString::transcode("name") ) );
//
// Read Children (the images)
//
// Iterate children
DOMNodeList *children = pElement->getChildNodes();
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
// Get node
DOMNode *child = children->item(i);
// Check type (it's probably text or element)
// A child element
if (child->getNodeType() == DOMNode::ELEMENT_NODE)
{
// All Elements will be of type "image" by DTD law
// First get element and not node
DOMElement *element = (DOMElement*)child;
// Call this function on the child
Xerces_ReadImage(element, sprite);
}
}
//
// Add Sprite
//
m_Sprites[name] = sprite;
}
void CGUI::Xerces_ReadImage(XERCES_CPP_NAMESPACE::DOMElement *pElement, CGUISprite &parent)
{
assert(pElement);
// 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
//
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
CStr attr_value(XMLString::transcode( attr->getValue() ));
// This is the only attribute we want
if (attr_name == CStr("texture"))
{
image.m_Texture = attr_value;
}
else
if (attr_name == CStr("size"))
{
CClientArea ca;
if (!GUI::ParseString(attr_value, ca))
{
- // GeeTODO : Error
+ // TODO Gee: Error
}
else image.m_Size = ca;
}
else
if (attr_name == CStr("backcolor"))
{
CColor color;
if (!GUI::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 ");
return;
}
}
//
// Input
//
parent.AddImage(image);
}
void CGUI::Xerces_ReadStyle(XERCES_CPP_NAMESPACE::DOMElement *pElement)
{
assert(pElement);
// style object we're adding
SGUIStyle style;
CStr name;
//
// Read Attributes
//
// Now we can iterate all attributes and store
DOMNamedNodeMap *attributes = pElement->getAttributes();
- for (int i=0; igetLength(); ++i)
+ for (u16 i=0; igetLength(); ++i)
{
DOMAttr *attr = (DOMAttr*)attributes->item(i);
CStr attr_name = XMLString::transcode( attr->getName() );
CStr attr_value = XMLString::transcode( attr->getValue() );
// The "name" setting is actually the name of the style
// 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;
}
//
// Add to CGUI
//
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; igetLength(); ++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::ParseString(attr_value, i))
+ {
+ // TODO Gee: Report in log file
+ }
+ scrollbar.m_Width = i;
+ }
+ }
+
+ //
+ // Add to CGUI
+ //
+
+ m_ScrollBarStyles[name] = scrollbar;
+}
Index: ps/trunk/source/gui/CText.cpp
===================================================================
--- ps/trunk/source/gui/CText.cpp (nonexistent)
+++ ps/trunk/source/gui/CText.cpp (revision 141)
@@ -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);
+ }
+
+}
Property changes on: ps/trunk/source/gui/CText.cpp
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+author date id revision
\ No newline at end of property
Index: ps/trunk/source/gui/IGUIObject.h
===================================================================
--- ps/trunk/source/gui/IGUIObject.h (revision 140)
+++ ps/trunk/source/gui/IGUIObject.h (revision 141)
@@ -1,419 +1,452 @@
/*
The base class of an object
by Gustav Larsson
gee@pyro.nu
--Overview--
All objects are derived from this class, it's an ADT
so it can't be used per se
Also contains a Dummy object which is used for
completely blank objects.
--Usage--
Write about how to use it here
--Examples--
Provide examples of how to use this code, if necessary
--More info--
Check GUI.h
*/
#ifndef IGUIObject_H
#define IGUIObject_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "GUI.h"
#include
#include
struct SGUISetting;
+struct SGUIStyle;
class CGUI;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
// Map with pointers
typedef std::map map_Settings;
//--------------------------------------------------------
// Error declarations
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
// Text alignments
enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center };
enum EValign { EValign_Top, EValign_Bottom, EValign_Center };
/**
* @author Gustav Larsson
*
* Stores the information where to find a variable
* in a GUI-Object object, also what type it is.
*/
struct SGUISetting
{
size_t m_Offset; // The offset from IGUIObject to the variable (not from SGUIBaseSettings or similar)
EGUISettingsStruct m_SettingsStruct;
CStr m_Type; // "string" or maybe "int"
};
/**
* @author Gustav Larsson
*
* Base settings, all objects possess these settings
* in their m_BaseSettings
* Instructions can be found in the documentations.
*/
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
};
//////////////////////////////////////////////////////////
/**
* @author Gustav Larsson
*
* GUI object such as a button or an input-box.
* Abstract data type !
*/
class IGUIObject
{
friend class CGUI;
friend class CInternalCGUIAccessorBase;
+ friend class IGUIScrollBar;
#ifndef _MSC_VER
template
#endif
friend class GUI;
public:
IGUIObject();
virtual ~IGUIObject();
/**
* Get offsets
*
* @return Retrieves settings info
*/
virtual map_Settings GetSettingsInfo() const { return m_SettingsInfo; }
/**
* Checks if mouse is hovering this object.
* The mouse position is cached in CGUI.
*
* This function checks if the mouse is hovering the
* rectangle that the base setting "size" makes.
* Although it is virtual, so one could derive
* an object from CButton, which changes only this
* to checking the circle that "size" makes.
*
* @return true if mouse is hovering
*/
virtual bool MouseOver();
//--------------------------------------------------------
/** @name Leaf Functions */
//--------------------------------------------------------
//@{
/// Get object name, name is unique
CStr GetName() const { return m_Name; }
/// Get object name
void SetName(const CStr &Name) { m_Name = Name; }
/**
* Adds object and its children to the map, it's name being the
* first part, and the second being itself.
*
* @param ObjectMap Adds this to the map_pObjects.
*
* @throws PS_NEEDS_NAME Name is missing
* @throws PS_NAME_AMBIGUITY Name is already taken
*/
void AddToPointersMap(map_pObjects &ObjectMap);
/**
* Notice nothing will be returned or thrown if the child hasn't
* been inputted into the GUI yet. This is because that's were
* all is checked. Now we're just linking two objects, but
* it's when we're inputting them into the GUI we'll check
* validity! Notice also when adding it to the GUI this function
* will inevitably have been called by CGUI::AddObject which
* will catch the throw and return the error code.
* i.e. The user will never put in the situation wherein a throw
* must be caught, the GUI's internal error handling will be
* completely transparent to the interfacially sequential model.
*
* @param pChild Child to add
*
* @throws PS_RESULT from CGUI::UpdateObjects().
*/
void AddChild(IGUIObject *pChild);
//@}
//--------------------------------------------------------
/** @name Iterate */
//--------------------------------------------------------
//@{
vector_pObjects::iterator ChildrenItBegin() { return m_Children.begin(); }
vector_pObjects::iterator ChildrenItEnd() { return m_Children.end(); }
//@}
//--------------------------------------------------------
/** @name Settings Management */
//--------------------------------------------------------
//@{
SGUIBaseSettings GetBaseSettings() const { return m_BaseSettings; }
/**
* Checks if settings exists, only available for derived
* classes that has this set up, that's why the base
* class just returns false
*
* @param Setting setting name
* @return True if settings exist.
*/
bool SettingExists(const CStr &Setting) const;
/**
* All sizes are relative to resolution, and the calculation
* is not wanted in real time, therefore it is cached, update
* the cached size with this function.
*/
void UpdateCachedSize();
/**
* Should be called every time the settings has been updated
* will also send a message GUIM_SETTINGS_UPDATED, so that
* if a derived object wants to add things to be updated,
* they add it in that message part, this is a better solution
* than making this virtual, since the updates that the base
* class does, are the most essential.
* 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();
/**
* Sets up a map_size_t to include the variables in m_BaseSettings
*
* @param SettingsInfo Pointers that should be filled with base variables
*/
void SetupBaseSettingsInfo(map_Settings &SettingsInfo);
/**
* Set a setting by string, regardless of what type it is.
*
* example a CRect(10,10,20,20) would be "10 10 20 20"
*
* @param Setting Setting by name
* @param Value Value to set to
*
* @throws PS_RESULT
*/
void SetSetting(const CStr &Setting, const CStr &Value);
//@}
protected:
//--------------------------------------------------------
/** @name Called by CGUI and friends
*
* Methods that the CGUI will call using
* its friendship, these should not
* be called by user.
* These functions' security are a lot
* what constitutes the GUI's
*/
//--------------------------------------------------------
//@{
/**
* 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();
/**
* 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.
*
* @throws PS_RESULT if any. But this will mostlikely be
* very rare since if an object is drawn unsuccessfully
* it'll probably only output in the Error log, and not
* disrupt the whole GUI drawing.
*/
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; }
void SetGUI(CGUI * const &pGUI) { m_pGUI = pGUI; }
// Set parent
void SetParent(IGUIObject *pParent) { m_pParent = pParent; }
virtual void ResetStates()
{
m_MouseHovering = false;
}
/**
* NOTE! This will not just return m_pParent, when that is
* need use it! There is one exception to it, when the parent is
* the top-node (the object that isn't a real object), this
* will return NULL, so that the top-node's children are
* seemingly parentless.
*
* @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
* the struct.
*
* @param SettingsStruct tells us which pointer ot return
*/
virtual void *GetStructPointer(const EGUISettingsStruct &SettingsStruct) const;
// Get cached mouse x/y from CGUI
u16 GetMouseX() const;
u16 GetMouseY() const;
/**
* Cached size, real size m_Size is actually dependent on resolution
* and can have different *real* outcomes, this is the real outcome
* cached to avoid slow calculations in real time.
*/
CRect m_CachedActualSize;
//@}
private:
//--------------------------------------------------------
/** @name Internal functions */
//--------------------------------------------------------
//@{
/**
* Inputs a reference pointer, checks if the new inputted object
* if hovered, if so, then check if this's Z value is greater
* than the inputted object... If so then the object is closer
* and we'll replace the pointer with this.
* Also Notice input can be NULL, which means the Z value demand
* is out. NOTICE you can't input NULL as const so you'll have
* to set an object to NULL.
*
* @param pObject Object pointer, can be either the old one, or
* the new one.
*/
void ChooseMouseOverAndClosest(IGUIObject* &pObject);
/**
* Inputes the object that is currently hovered, this function
* updates this object accordingly (i.e. if it's the object
* being inputted one thing happens, and not, another).
*
* @param pMouseOver Object that is currently hovered,
* can OF COURSE be NULL too!
*/
void UpdateMouseOver(IGUIObject * const &pMouseOver);
//@}
// Variables
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
IGUIObject *m_pParent;
/// Base settings
SGUIBaseSettings m_BaseSettings;
/**
* This is an array of true or false, each element is associated with
* a string representing a setting. Number of elements is equal to
* number of settings.
*
* A true means the setting has been manually set in the file when
* read. This is important to know because I don't want to force
* the user to include its -XML-files first, so somehow
* the GUI needs to know which settings were set, and which is meant
* to
*/
// More variables
/// Is mouse hovering the object? used with the function MouseOver()
bool m_MouseHovering;
/**
* Tells us where a variable by a string name is
* located hardcoded, in order to acquire a pointer
* for that variable... Say "frozen" gives
* the offset from IGUIObject to m_Frozen.
* note! @uNOT from SGUIBaseSettings to
* m_Frozen!
*/
static map_Settings m_SettingsInfo;
private:
/// An object can't function stand alone
CGUI *m_pGUI;
};
/**
* @author Gustav Larsson
*
* Dummy object used primarily for the root object
* which isn't a *real* object in the GUI.
*/
class CGUIDummyObject : public IGUIObject
{
- virtual void HandleMessage(const EGUIMessage &Message) {}
+ virtual void HandleMessage(const SGUIMessage &Message) {}
virtual void Draw() {}
};
#endif
Index: ps/trunk/source/gui/GUI.h
===================================================================
--- ps/trunk/source/gui/GUI.h (revision 140)
+++ ps/trunk/source/gui/GUI.h (revision 141)
@@ -1,77 +1,81 @@
/*
GUI Inclusion file
by Gustav Larsson
gee@pyro.nu
--Overview--
Include this file and it will include the whole GUI
--More info--
http://gee.pyro.nu/GUI/
*/
// Main page for GUI documentation
/**
* @mainpage
* Welcome to the Wildfire Games Graphical User Interface Documentation.
*
* Additional Downloads can be made from the link below.\n
* Technical Design Document
*
* The GUI uses Xerces C++ Parser,
* Current official version (ensured to work): 2.3.0
*
* @dot
* digraph
* {
* node [shape=record, fontname=Helvetica, fontsize=10];
* 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;
* }
* @enddot
*/
#ifndef GUI_H
#define GUI_H
//--------------------------------------------------------
// Compiler specific
//--------------------------------------------------------
// Important that we do this before