GUI Update. Mostly with Input Control Beta :)
This was SVN commit r1904.
This commit is contained in:
parent
6af0d7cfd3
commit
4113aa0a36
@ -70,7 +70,7 @@ void CButton::HandleMessage(const SGUIMessage &Message)
|
||||
// Important
|
||||
IGUIButtonBehavior::HandleMessage(Message);
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
|
||||
/*
|
||||
switch (Message.type)
|
||||
{
|
||||
case GUIM_PRESSED:
|
||||
@ -80,6 +80,7 @@ void CButton::HandleMessage(const SGUIMessage &Message)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void CButton::Draw()
|
||||
|
@ -403,14 +403,9 @@ void CGUI::Draw()
|
||||
// Clear the depth buffer, so the GUI is
|
||||
// drawn on top of everything else
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
// Adapt (origio) to being in top left corner and down
|
||||
// just like the mouse position
|
||||
glTranslatef(0.0f, (GLfloat)g_yres, -1000.0f);
|
||||
glScalef(1.0f, -1.f, 1.0f);
|
||||
guiLoadIdentity();
|
||||
|
||||
try
|
||||
{
|
||||
@ -899,7 +894,8 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
||||
|
||||
}
|
||||
|
||||
delete font;
|
||||
if (font)
|
||||
delete font;
|
||||
|
||||
for (list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin();
|
||||
it!=Text.m_SpriteCalls.end();
|
||||
@ -1187,9 +1183,9 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
ManuallySetZ = true;
|
||||
|
||||
// Try setting the value
|
||||
if (object->SetSetting(pFile->getAttributeString(attr.Name), (CStr)attr.Value) != PS_OK)
|
||||
if (object->SetSetting(pFile->getAttributeString(attr.Name), (CStr)attr.Value, true) != PS_OK)
|
||||
{
|
||||
ReportParseError("Can't set \"%s\" to \"%s\"", pFile->getAttributeString(attr.Name).c_str(), CStr(attr.Value).c_str());
|
||||
ReportParseError("(object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName().c_str(), pFile->getAttributeString(attr.Name).c_str(), CStr(attr.Value).c_str());
|
||||
|
||||
// This is not a fatal error
|
||||
}
|
||||
@ -1210,7 +1206,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
if (caption.Length())
|
||||
{
|
||||
// Set the setting caption to this
|
||||
object->SetSetting("caption", caption);
|
||||
object->SetSetting("caption", caption, true);
|
||||
|
||||
// There is no harm if the object didn't have a "caption"
|
||||
}
|
||||
@ -1291,12 +1287,12 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
// and add to that!
|
||||
if (absolute)
|
||||
{
|
||||
GUI<float>::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f);
|
||||
GUI<float>::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f, true);
|
||||
}
|
||||
else
|
||||
// If the object is relative, then we'll just store Z as "10"
|
||||
{
|
||||
GUI<float>::SetSetting(object, "z", 10.f);
|
||||
GUI<float>::SetSetting(object, "z", 10.f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -51,12 +51,24 @@ class CInput : public IGUIScrollBarOwner
|
||||
{
|
||||
GUI_OBJECT(CInput)
|
||||
|
||||
protected: // forwards
|
||||
struct SRow;
|
||||
|
||||
public:
|
||||
CInput();
|
||||
virtual ~CInput();
|
||||
|
||||
virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); }
|
||||
|
||||
// Check where the mouse is hovering, and get the appropriate text position.
|
||||
// return is the text-position index.
|
||||
// const in philosophy, but I need to retrieve the caption in a non-const way.
|
||||
int GetMouseHoveringTextPosition();
|
||||
|
||||
// Same as above, but only on one row in X, and a given value, not the mouse's
|
||||
// wanted is filled with x if the row didn't extend as far as we
|
||||
int GetXTextPosition(const std::list<SRow>::iterator &c, const float &x, float &wanted);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Handle Messages
|
||||
@ -88,9 +100,34 @@ protected:
|
||||
// that.
|
||||
void UpdateText(int from=0, int to_before=-1, int to_after=-1);
|
||||
|
||||
// Delete the current selection. Also places the pointer at the
|
||||
// crack between the two segments kept.
|
||||
void DeleteCurSelection();
|
||||
|
||||
// Is text selected? It can be denote two ways, m_iBufferPos_Tail
|
||||
// being -1 or the same as m_iBufferPos. This makes for clearer
|
||||
// code.
|
||||
bool SelectingText() const;
|
||||
|
||||
// Get area of where text can be drawn.
|
||||
float GetTextAreaWidth();
|
||||
|
||||
// Called every time the auto-scrolling should be checked.
|
||||
void UpdateAutoScroll();
|
||||
|
||||
protected:
|
||||
// Cursor position
|
||||
int m_iBufferPos;
|
||||
// Cursor position
|
||||
// (the second one is for selection of larger areas, -1 if not used)
|
||||
// A note on 'Tail', it was first called 'To', and the natural order
|
||||
// of X and X_To was X then X_To. Now Tail is called so, because it
|
||||
// can be placed both before and after, but the important things is
|
||||
// that m_iBufferPos is ALWAYS where the edit pointer is. Yes, there
|
||||
// is an edit pointer even though you select a larger area. For instance
|
||||
// if you want to resize the selection with Shift+Left/Right, there
|
||||
// are always two ways a selection can look. Check any OS GUI and you'll
|
||||
// see.
|
||||
int m_iBufferPos,
|
||||
m_iBufferPos_Tail;
|
||||
|
||||
// the outer vector is lines, and the inner is X positions
|
||||
// in a row. So that we can determine where characters are
|
||||
@ -105,7 +142,25 @@ protected:
|
||||
// List of rows, list because I use a lot of iterators, and change
|
||||
// its size continuously, it's easier and safer if I know the
|
||||
// iterators never gets invalidated.
|
||||
// For one-liners, only one row is used.
|
||||
std::list< SRow > m_CharacterPositions;
|
||||
|
||||
// *** Things for a multi-lined input control *** //
|
||||
|
||||
// This is when you change row with up/down, and the row you jump
|
||||
// to doesn't have anything at that X position, then it will
|
||||
// keep the WantedX position in mind when switching to the next
|
||||
// row. It will keep on being used until it reach a row which meets
|
||||
// the requirements.
|
||||
// 0.0f means not in use.
|
||||
float m_WantedX;
|
||||
|
||||
// If we are in the process of selecting a larger selection of text
|
||||
// using the mouse click (hold) and drag, this is true.
|
||||
bool m_SelectingText;
|
||||
|
||||
// *** Things for one-line input control *** //
|
||||
float m_HorizontalScroll;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -91,9 +91,8 @@ void CText::SetupText()
|
||||
|
||||
void CText::HandleMessage(const SGUIMessage &Message)
|
||||
{
|
||||
// TODO Gee:
|
||||
IGUIScrollBarOwner::HandleMessage(Message);
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
|
||||
|
||||
switch (Message.type)
|
||||
{
|
||||
@ -104,7 +103,8 @@ void CText::HandleMessage(const SGUIMessage &Message)
|
||||
// Update scroll-bar
|
||||
// TODO Gee: (2004-09-01) Is this really updated each time it should?
|
||||
if (scrollbar &&
|
||||
(Message.value == CStr("size") || Message.value == CStr("z") ||
|
||||
(Message.value == CStr("size") ||
|
||||
Message.value == CStr("z") ||
|
||||
Message.value == CStr("absolute")))
|
||||
{
|
||||
|
||||
@ -114,6 +114,11 @@ void CText::HandleMessage(const SGUIMessage &Message)
|
||||
GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top );
|
||||
}
|
||||
|
||||
if (Message.value == CStr("scrollbar"))
|
||||
{
|
||||
SetupText();
|
||||
}
|
||||
|
||||
// Update scrollbar
|
||||
if (Message.value == CStr("scrollbar_style"))
|
||||
{
|
||||
@ -121,9 +126,6 @@ void CText::HandleMessage(const SGUIMessage &Message)
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
|
||||
// Update text
|
||||
SetupText();
|
||||
}
|
||||
|
||||
break;
|
||||
@ -142,9 +144,24 @@ void CText::HandleMessage(const SGUIMessage &Message)
|
||||
HandleMessage(SGUIMessage(GUIM_MOUSE_MOTION));
|
||||
break;
|
||||
|
||||
case GUIM_LOAD:
|
||||
{
|
||||
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 );
|
||||
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
IGUITextOwner::HandleMessage(Message);
|
||||
}
|
||||
|
||||
void CText::Draw()
|
||||
|
@ -9,6 +9,8 @@ gee@pyro.nu
|
||||
#include "Parser.h"
|
||||
#include "i18n.h"
|
||||
|
||||
extern int g_yres;
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <>
|
||||
@ -236,6 +238,15 @@ bool __ParseString<CGUISpriteInstance>(const CStr& Value, CGUISpriteInstance &Ou
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
void guiLoadIdentity()
|
||||
{
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0f, (GLfloat)g_yres, -1000.0f);
|
||||
glScalef(1.0f, -1.f, 1.0f);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Help Classes/Structs for the GUI implementation
|
||||
//--------------------------------------------------------
|
||||
@ -434,7 +445,7 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, const SGUIMes
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
template <typename T>
|
||||
PS_RESULT GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
|
||||
{
|
||||
@ -468,7 +479,8 @@ PS_RESULT GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value)
|
||||
PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
const T &Value, const bool& SkipMessage)
|
||||
{
|
||||
if (pObject == NULL)
|
||||
return PS_OBJECT_FAIL;
|
||||
@ -500,7 +512,8 @@ PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &
|
||||
//RecurseObject(0, pObject, IGUIObject::ResetStates);
|
||||
}
|
||||
|
||||
HandleMessage(pObject, SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
|
||||
if (!SkipMessage)
|
||||
HandleMessage(pObject, SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
|
||||
|
||||
return PS_OK;
|
||||
}
|
||||
@ -509,7 +522,7 @@ PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &
|
||||
#define TYPE(T) \
|
||||
template PS_RESULT GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \
|
||||
template PS_RESULT GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \
|
||||
template PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value);
|
||||
template PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage);
|
||||
#define GUITYPE_IGNORE_CGUISpriteInstance
|
||||
#include "GUItypes.h"
|
||||
|
||||
@ -518,4 +531,4 @@ PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &
|
||||
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
|
||||
// instead. (This is mainly useful to stop me accidentally using the wrong function.)
|
||||
template PS_RESULT GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value);
|
||||
template PS_RESULT GUI<CGUISpriteInstance>::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value);
|
||||
template PS_RESULT GUI<CGUISpriteInstance>::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value, const bool& SkipMessage);
|
||||
|
@ -36,6 +36,10 @@ class CGUIString;
|
||||
template <typename T>
|
||||
bool __ParseString(const CStr& Value, T &tOutput);
|
||||
|
||||
// Load Identity matrix and
|
||||
// adapt (origio) to being in top left corner and down
|
||||
// just like the mouse position
|
||||
void guiLoadIdentity();
|
||||
|
||||
// Icon, you create them in the XML file with root element <setup>
|
||||
// you use them in text owned by different objects... Such as CText.
|
||||
@ -176,8 +180,10 @@ public:
|
||||
* @param pObject Object pointer
|
||||
* @param Setting Setting by name
|
||||
* @param Value Sets value to this, note type T!
|
||||
* @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
|
||||
*/
|
||||
static PS_RESULT SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value);
|
||||
static PS_RESULT SetSetting(IGUIObject *pObject, const CStr& Setting,
|
||||
const T &Value, const bool &SkipMessage=false);
|
||||
|
||||
#ifdef g_GUI
|
||||
/**
|
||||
@ -219,9 +225,9 @@ public:
|
||||
* Can safely be removed.
|
||||
*/
|
||||
static PS_RESULT SetSetting(
|
||||
const CStr& Object, const CStr& Setting, const T &Value)
|
||||
const CStr& Object, const CStr& Setting, const T &Value, const bool& SkipMessage=false)
|
||||
{
|
||||
return SetSetting(g_GUI, Object, Setting, Value);
|
||||
return SetSetting(g_GUI, Object, Setting, Value, SkipMessage);
|
||||
}
|
||||
#endif // g_GUI
|
||||
|
||||
@ -239,7 +245,8 @@ public:
|
||||
*/
|
||||
static PS_RESULT SetSetting(
|
||||
CGUI &GUIinstance, const CStr& Object,
|
||||
const CStr& Setting, const T &Value)
|
||||
const CStr& Setting, const T &Value,
|
||||
const bool& SkipMessage=false)
|
||||
{
|
||||
if (!GUIinstance.ObjectExists(Object))
|
||||
return PS_OBJECT_FAIL;
|
||||
@ -251,7 +258,7 @@ public:
|
||||
// one with the friend relationship
|
||||
IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
|
||||
|
||||
return SetSetting(pObject, Setting, Value);
|
||||
return SetSetting(pObject, Setting, Value, SkipMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,10 +224,10 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
|
||||
if (!GUI<type>::ParseString(Value, _Value)) \
|
||||
return PS_FAIL; \
|
||||
\
|
||||
GUI<type>::SetSetting(this, Setting, _Value); \
|
||||
GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
|
||||
}
|
||||
|
||||
PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
|
||||
PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage)
|
||||
{
|
||||
if (!SettingExists(Setting))
|
||||
{
|
||||
|
@ -261,7 +261,7 @@ public:
|
||||
*
|
||||
* @return PS_RESULT (PS_OK if successful)
|
||||
*/
|
||||
PS_RESULT SetSetting(const CStr& Setting, const CStr& Value);
|
||||
PS_RESULT SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false);
|
||||
|
||||
/**
|
||||
* Retrieves the type of a named setting.
|
||||
|
@ -186,6 +186,11 @@ public:
|
||||
*/
|
||||
float GetPos() const { return m_Pos; }
|
||||
|
||||
/**
|
||||
* Set scroll-position by hand
|
||||
*/
|
||||
virtual void SetPos(const float &f) { m_Pos = f; UpdatePosBoundaries(); }
|
||||
|
||||
/**
|
||||
* Scroll towards 1.0 one step
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user