1
0
forked from 0ad/0ad

no message

This was SVN commit r92.
This commit is contained in:
Gee 2003-11-25 02:47:12 +00:00
parent 530eecfe16
commit 6d86a928a3
11 changed files with 181 additions and 62 deletions

View File

@ -7,6 +7,10 @@ gee@pyro.nu
//#include "stdafx."
#include "GUI.h"
// temp GeeTODO
#include "font.h"
#include "ogl.h"
using namespace std;
// Offsets
@ -69,9 +73,7 @@ CButton::~CButton()
void CButton::HandleMessage(const EGUIMessage &Message)
{
// TODO REMOVE
#define OUTPUT(x) g_console.submit("echo Object(<red>%s</>) <AADDFF>%s</>", m_Name.c_str(), #x);
// Important
IGUIButtonBehavior::HandleMessage(Message);
switch (Message)
@ -102,6 +104,7 @@ void CButton::HandleMessage(const EGUIMessage &Message)
break;
case GUIM_PRESSED:
GetGUI()->TEMPmessage = "Button " + string((const TCHAR*)m_Name) + " was pressed!";
/// OUTPUT(GUIM_PRESSED);
break;
@ -128,7 +131,6 @@ void CButton::Draw()
glPushMatrix();
glTranslatef(0.0f, 0.0f, GetBaseSettings().m_Z);
/// glTranslatef(0.0f, 0.0f, 0.0f);
// Do this
glBegin(GL_QUADS);
@ -154,7 +156,16 @@ void CButton::Draw()
//glDisable(GL_DEPTH_TEST);
//glColor3f(0,0,0);
/* glEnable(GL_TEXTURE_2D);
glColor3f(1,1,1);
//glLoadIdentity();
//glTranslatef(ca.left + 10, g_yres - (ca.top + 10), GetBaseSettings().m_Z + 0.1f);
glTranslatef(ca.left + 10, ca.top + 10, 0.0f);
//glScalef(0,-1,0);
font_bind(GetGUI()->TEMPfont);
glprintf("%s", (const TCHAR*)m_Name);
*/ //glColor3f(0,0,0);
//font.print(GetBaseSettings().m_Size.left + 3, GetBaseSettings().m_Size.top - 15, LEFT, "Object: %s", GetName().c_str());
//glEnable(GL_DEPTH_TEST);

View File

@ -49,6 +49,8 @@ bool CGUI::HandleEvent(const SDL_Event& ev)
// Only one object can be hovered
IGUIObject *pNearest = NULL;
try
{
// pNearest will after this point at the hovered object, possibly NULL
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
&IGUIObject::ChooseMouseOverAndClosest,
@ -61,15 +63,46 @@ bool CGUI::HandleEvent(const SDL_Event& ev)
&IGUIObject::UpdateMouseOver,
pNearest);
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<CClientArea>::GetSetting(*this, CStr(_T("a2")), CStr(_T("size")), ca);
GUI<bool>::GetSetting(*this, CStr(_T("a2")), CStr(_T("hidden")), hidden);
hidden = !hidden;
ca.pixel.right += 30;
GUI<CClientArea>::SetSetting(*this, CStr(_T("a2")), CStr(_T("size")), ca);
GUI<bool>::SetSetting(*this, CStr(_T("a2")), CStr(_T("hidden")), hidden);
*/ }
}
else
if (ev.type == SDL_MOUSEBUTTONUP)
{
if (pNearest)
pNearest->HandleMessage(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;
}
}
catch (PS_RESULT e)
{
// TODO
}
// 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)
@ -208,7 +241,7 @@ void CGUI::Draw()
{
glPopMatrix();
// TODO
// GeeTODO
return;
}
glPopMatrix();
@ -227,7 +260,7 @@ void CGUI::Destroy()
}
catch (PS_RESULT e)
{
// TODO
// GeeTODO
}
delete it->second;
@ -241,6 +274,7 @@ void CGUI::Destroy()
void CGUI::UpdateResolution()
{
// Update ALL cached
GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize );
}
@ -253,6 +287,10 @@ void CGUI::AddObject(IGUIObject* pObject)
// Add child to base object
m_BaseObject->AddChild(pObject);
// Cache tree
GUI<>::RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
/* }
catch (PS_RESULT e)
{
@ -299,7 +337,7 @@ void CGUI::ReportParseError(const CStr &str, ...)
// Important, set ParseError to true
++m_Errors;
/* MEGA TODO Gee
/* MEGA GeeTODO
char buffer[512];
va_list args;
@ -358,7 +396,7 @@ void CGUI::LoadXMLFile(const string &Filename)
int todo_remove = parser->getErrorCount();
// TODO report for real!
// GeeTODO report for real!
/// g_console.submit("echo Xerces XML Parsing Reports %d errors", parser->getErrorCount());
}
}
@ -392,6 +430,9 @@ void CGUI::LoadXMLFile(const string &Filename)
if (root_name == "objects")
{
Xerces_ReadRootObjects(node);
// Re-cache all values so these gets cached too.
//UpdateResolution();
}
else
if (root_name == "sprites")
@ -408,6 +449,7 @@ void CGUI::LoadXMLFile(const string &Filename)
}
XMLPlatformUtils::Terminate();
}
//===================================================================
@ -519,7 +561,7 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
// Check if name isn't set, report error in that case
if (!NameSet)
{
// Set Random name! TODO
// Generate internal name! GeeTODO
}
//
@ -547,7 +589,7 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
// First get element and not node
DOMElement *element = (DOMElement*)child;
// TODO REPORT ERROR
// GeeTODO REPORT ERROR
// Call this function on the child
Xerces_ReadObject(element, object);
@ -561,12 +603,12 @@ void CGUI::Xerces_ReadObject(DOMElement *pElement, IGUIObject *pParent)
// Text is only okay if it's the first element i.e. <object>caption ... </object>
if (i==0)
{
// TODO !!!!! CROP STRING!
// GeeTODO !!!!! CROP STRING!
// Set the setting caption to this
GUI<CStr>::SetSetting(object, "caption", caption);
}
// TODO check invalid strings?
// GeeTODO check invalid strings?
}
}

View File

@ -70,6 +70,9 @@ public:
CGUI();
~CGUI();
// TEMP TEMP GeeTODO
std::string TEMPmessage;
/**
* Initializes the GUI, needs to be called before the GUI is used
*/

View File

@ -10,7 +10,7 @@ gee@pyro.nu
--More info--
http://gee.pyro.nu/wfg/GUI/
Check GUI.h
*/
@ -67,8 +67,8 @@ public: \
*/
enum EGUIMessage
{
GUIM_PREPROCESS,
GUIM_POSTPROCESS,
GUIM_PREPROCESS, // questionable
GUIM_POSTPROCESS, // questionable
GUIM_MOUSE_OVER,
GUIM_MOUSE_ENTER,
GUIM_MOUSE_LEAVE,

View File

@ -28,10 +28,10 @@ CRect CClientArea::GetClientArea(const CRect &parent)
CRect client;
// This should probably be cached and not calculated all the time for every object.
client.left = int(float(parent.left) + float(parent.right-parent.left)*float(percent.left))/100.f + pixel.left;
client.top = int(float(parent.top) + float(parent.bottom-parent.top)*float(percent.top))/100.f + pixel.top;
client.right = int(float(parent.left) + float(parent.right-parent.left)*float(percent.right))/100.f + pixel.right;
client.bottom = int(float(parent.top) + float(parent.bottom-parent.top)*float(percent.bottom))/100.f + pixel.bottom;
client.left = parent.left + int(float((parent.right-parent.left)*percent.left)/100.f) + pixel.left;
client.top = parent.top + int(float((parent.bottom-parent.top)*percent.top)/100.f) + pixel.top;
client.right = parent.left + int(float((parent.right-parent.left)*percent.right)/100.f) + pixel.right;
client.bottom = parent.top + int(float((parent.bottom-parent.top)*percent.bottom)/100.f) + pixel.bottom;
return client;
}

View File

@ -10,7 +10,7 @@ gee@pyro.nu
--More info--
http://gee.pyro.nu/wfg/GUI/
Check GUI.h
*/
@ -165,7 +165,10 @@ public:
}
/**
* Sets a value by name using a real datatype as input
* 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
@ -183,7 +186,22 @@ public:
// This better be the correct adress
*(T*)((size_t)pObject+pObject->GetSettingsInfo()[Setting].m_Offset) = Value;
pObject->CheckSettingsValidity();
//
// 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
RecurseObject(0, pObject, IGUIObject::ResetStates);
}
return PS_OK;
}
@ -213,6 +231,9 @@ public:
* 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
@ -232,8 +253,6 @@ public:
// one with the friend relationship
IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
pObject->CheckSettingsValidity();
return SetSetting(pObject, Setting, Value);
}

View File

@ -24,7 +24,11 @@ void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message)
{
switch (Message)
{
case GUIM_POSTPROCESS:
case GUIM_PREPROCESS:
m_Pressed = false;
break;
/* case GUIM_POSTPROCESS:
// Check if button has been pressed
if (m_Pressed)
{
@ -40,7 +44,7 @@ void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message)
}
}
break;
*/
case GUIM_MOUSE_PRESS_LEFT:
m_Pressed = true;
break;
@ -54,6 +58,12 @@ void IGUIButtonBehavior::HandleMessage(const EGUIMessage &Message)
}
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;
}

View File

@ -58,6 +58,12 @@ public:
virtual void HandleMessage(const EGUIMessage &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...

View File

@ -37,6 +37,7 @@ IGUIObject::IGUIObject() :
m_BaseSettings.m_Hidden = false;
m_BaseSettings.m_Style = "null";
m_BaseSettings.m_Z = 0.f;
m_BaseSettings.m_Absolute = true;
// Static! Only done once
if (m_SettingsInfo.empty())
@ -52,12 +53,6 @@ IGUIObject::~IGUIObject()
//-------------------------------------------------------------------
// Functions
//-------------------------------------------------------------------
void IGUIObject::SetBaseSettings(const SGUIBaseSettings &Set)
{
m_BaseSettings = Set;
CheckSettingsValidity();
}
void IGUIObject::AddChild(IGUIObject *pChild)
{
//
@ -130,6 +125,7 @@ void IGUIObject::SetupBaseSettingsInfo(map_Settings &SettingsInfo)
_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)
}
bool IGUIObject::MouseOver()
@ -211,8 +207,24 @@ void IGUIObject::SetSetting(const CStr &Setting, const CStr &Value)
GUI<CStr>::SetSetting(this, Setting, Value);
}
else
if (set.m_Type == CStr(_T("bool")))
{
bool bValue;
if (Value == CStr(_T("true")))
bValue = true;
else
if (Value == CStr(_T("false")))
bValue = false;
else
throw PS_FAIL;
GUI<bool>::SetSetting(this, Setting, bValue);
}
else
if (set.m_Type == CStr(_T("float")))
{
// GeeTODO Okay float value!?
GUI<float>::SetSetting(this, Setting, Value.ToFloat() );
}
else
@ -222,7 +234,7 @@ void IGUIObject::SetSetting(const CStr &Setting, const CStr &Value)
CParser parser;
parser.InputTaskType("", "_$value_$value_$value_$value_");
// TODO Gee string really?
// GeeTODO string really?
string str = (const TCHAR*)Value;
CParserLine line;
@ -302,15 +314,20 @@ IGUIObject *IGUIObject::GetParent()
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::CheckSettingsValidity()
{
// Size might have been change, update cached size
UpdateCachedSize();
// If we hide an object, reset many of its parts
if (GetBaseSettings().m_Hidden)
{
@ -325,7 +342,7 @@ void IGUIObject::CheckSettingsValidity()
try
{
// Send message to myself
// Send message to itself
HandleMessage(GUIM_SETTINGS_UPDATED);
}
catch (...)

View File

@ -104,6 +104,7 @@ struct SGUIBaseSettings
class IGUIObject
{
friend class CGUI;
#ifndef _MSC_VER
template <class T>
#endif
@ -190,7 +191,6 @@ public:
//@{
SGUIBaseSettings GetBaseSettings() const { return m_BaseSettings; }
void SetBaseSettings(const SGUIBaseSettings &Set);
/**
* Checks if settings exists, only available for derived
@ -286,6 +286,11 @@ protected:
// Set parent
void SetParent(IGUIObject *pParent) { m_pParent = pParent; }
virtual void ResetStates()
{
m_MouseHovering = false;
}
/**
* <b>NOTE!</b> This will not just return m_pParent, when that is
* need use it! There is one exception to it, when the parent is
@ -308,7 +313,6 @@ protected:
*/
CRect m_CachedActualSize;
//@}
private:
//--------------------------------------------------------

View File

@ -108,7 +108,9 @@ static int set_vmode(int w, int h, int bpp)
glViewport(0, 0, w, h);
#ifndef NO_GUI
g_GUI.UpdateResolution();
#endif
oglInit(); // required after each mode change
@ -202,6 +204,11 @@ const float x = 600.0f, y = 512.0f;
glprintf("%d FPS", fps);
#ifndef NO_GUI
// Temp GUI message GeeTODO
glLoadIdentity();
glTranslatef(10, 60, 0);
glprintf("%s", g_GUI.TEMPmessage.c_str());
glLoadIdentity();
g_GUI.Draw();
#endif