mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-28 07:45:40 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
109
Engine/source/gui/utility/guiBubbleTextCtrl.cpp
Normal file
109
Engine/source/gui/utility/guiBubbleTextCtrl.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "gui/utility/guiBubbleTextCtrl.h"
|
||||
#include "gui/core/guiCanvas.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiBubbleTextCtrl);
|
||||
|
||||
ConsoleDocClass( GuiBubbleTextCtrl,
|
||||
"@brief A single-line text control that displays its text in a multi-line popup when clicked.\n\n"
|
||||
|
||||
"This control acts like a GuiTextCtrl (and inherits from it), when clicked it creates a GuiMLTextCtrl "
|
||||
"roughly where you clicked with the same text in it. This allows you to have a single line text control "
|
||||
"which upon clicking will display the entire text contained in a multi-line format.\n\n"
|
||||
|
||||
"@tsexample\n"
|
||||
"new GuiBubbleTextCtrl(BubbleTextGUI)\n"
|
||||
"{\n"
|
||||
" text = \"This is the first sentence. This second sentence can be sized outside of the default single "
|
||||
"line view, upon clicking this will be displayed in a multi-line format.\";\n"
|
||||
"};\n"
|
||||
"@endtsexample\n\n"
|
||||
|
||||
"@see GuiTextCtrl\n"
|
||||
"@see GuiMLTextCtrl\n\n"
|
||||
|
||||
"@ingroup GuiControls\n"
|
||||
);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiBubbleTextCtrl::popBubble()
|
||||
{
|
||||
// Release the mouse:
|
||||
mInAction = false;
|
||||
mouseUnlock();
|
||||
|
||||
// Pop the dialog
|
||||
getRoot()->popDialogControl(mDlg);
|
||||
|
||||
// Kill the popup
|
||||
mDlg->removeObject(mPopup);
|
||||
mPopup->removeObject(mMLText);
|
||||
mMLText->deleteObject();
|
||||
mPopup->deleteObject();
|
||||
mDlg->deleteObject();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiBubbleTextCtrl::onMouseDown(const GuiEvent &event)
|
||||
{
|
||||
if (mInAction)
|
||||
{
|
||||
popBubble();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mDlg = new GuiControl();
|
||||
AssertFatal(mDlg, "Failed to create the GuiControl for the BubbleTextCtrl");
|
||||
mDlg->setDataField( StringTable->insert("profile"), NULL, "GuiModelessDialogProfile");
|
||||
mDlg->setField("horizSizing", "width");
|
||||
mDlg->setField("vertSizing", "height");
|
||||
mDlg->setField("extent", "640 480");
|
||||
|
||||
mPopup = new GuiControl();
|
||||
AssertFatal(mPopup, "Failed to create the GuiControl for the BubbleTextCtrl");
|
||||
mPopup->setDataField( StringTable->insert("profile"), NULL, "GuiBubblePopupProfile");
|
||||
|
||||
mMLText = new GuiMLTextCtrl();
|
||||
AssertFatal(mMLText, "Failed to create the GuiMLTextCtrl for the BubbleTextCtrl");
|
||||
mMLText->setDataField( StringTable->insert("profile"), NULL, "GuiBubbleTextProfile");
|
||||
mMLText->setField("position", "2 2");
|
||||
mMLText->setField("extent", "296 51");
|
||||
|
||||
mMLText->setText((char*)mText,dStrlen(mText));
|
||||
|
||||
mMLText->registerObject();
|
||||
mPopup->registerObject();
|
||||
mDlg->registerObject();
|
||||
|
||||
mPopup->addObject(mMLText);
|
||||
mDlg->addObject(mPopup);
|
||||
|
||||
mPopup->resize(event.mousePoint,Point2I(300,55));
|
||||
|
||||
getRoot()->pushDialogControl(mDlg,0);
|
||||
mouseLock();
|
||||
|
||||
mInAction = true;
|
||||
}
|
||||
60
Engine/source/gui/utility/guiBubbleTextCtrl.h
Normal file
60
Engine/source/gui/utility/guiBubbleTextCtrl.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GUIBUBBLETEXTCTRL_H_
|
||||
#define _GUIBUBBLETEXTCTRL_H_
|
||||
|
||||
#ifndef _GUITEXTCTRL_H_
|
||||
#include "gui/controls/guiTextCtrl.h"
|
||||
#endif
|
||||
#ifndef _GUIMLTEXTCTRL_H_
|
||||
#include "gui/controls/guiMLTextCtrl.h"
|
||||
#endif
|
||||
|
||||
/// A single-line text control that displays its text in a multi-line popup when
|
||||
/// clicked.
|
||||
class GuiBubbleTextCtrl : public GuiTextCtrl
|
||||
{
|
||||
private:
|
||||
|
||||
typedef GuiTextCtrl Parent;
|
||||
|
||||
protected:
|
||||
bool mInAction;
|
||||
GuiControl *mDlg;
|
||||
GuiControl *mPopup;
|
||||
GuiMLTextCtrl *mMLText;
|
||||
|
||||
void popBubble();
|
||||
|
||||
public:
|
||||
|
||||
DECLARE_CONOBJECT(GuiBubbleTextCtrl);
|
||||
DECLARE_DESCRIPTION( "A single-line text control that displays its text in a multi-line\n"
|
||||
"popup when clicked." );
|
||||
|
||||
GuiBubbleTextCtrl() { mInAction = false; }
|
||||
|
||||
virtual void onMouseDown(const GuiEvent &event);
|
||||
};
|
||||
|
||||
#endif /* _GUI_BUBBLE_TEXT_CONTROL_H_ */
|
||||
165
Engine/source/gui/utility/guiInputCtrl.cpp
Normal file
165
Engine/source/gui/utility/guiInputCtrl.cpp
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "gui/utility/guiInputCtrl.h"
|
||||
#include "sim/actionMap.h"
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInputCtrl);
|
||||
|
||||
ConsoleDocClass( GuiInputCtrl,
|
||||
"@brief A control that locks the mouse and reports all keyboard input events to script.\n\n"
|
||||
|
||||
"This is useful for implementing custom keyboard handling code, and most commonly "
|
||||
"used in Torque for a menu that allows a user to remap their in-game controls\n\n "
|
||||
|
||||
"@tsexample\n"
|
||||
"new GuiInputCtrl(OptRemapInputCtrl)\n"
|
||||
"{\n"
|
||||
" lockMouse = \"0\";\n"
|
||||
" position = \"0 0\";\n"
|
||||
" extent = \"64 64\";\n"
|
||||
" minExtent = \"8 8\";\n"
|
||||
" horizSizing = \"center\";\n"
|
||||
" vertSizing = \"bottom\";\n"
|
||||
" profile = \"GuiInputCtrlProfile\";\n"
|
||||
" visible = \"1\";\n"
|
||||
" active = \"1\";\n"
|
||||
" tooltipProfile = \"GuiToolTipProfile\";\n"
|
||||
" hovertime = \"1000\";\n"
|
||||
" isContainer = \"0\";\n"
|
||||
" canSave = \"1\";\n"
|
||||
" canSaveDynamicFields = \"0\";\n"
|
||||
"};\n"
|
||||
"@endtsexample\n\n"
|
||||
|
||||
"@see GuiMouseEventCtrl\n"
|
||||
|
||||
"@ingroup GuiUtil\n");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void GuiInputCtrl::initPersistFields()
|
||||
{
|
||||
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool GuiInputCtrl::onWake()
|
||||
{
|
||||
// Set the default profile on start-up:
|
||||
if( !mProfile )
|
||||
{
|
||||
GuiControlProfile* profile;
|
||||
Sim::findObject( "GuiInputCtrlProfile", profile);
|
||||
if( profile )
|
||||
setControlProfile( profile );
|
||||
}
|
||||
|
||||
if ( !Parent::onWake() )
|
||||
return( false );
|
||||
|
||||
if( !smDesignTime )
|
||||
mouseLock();
|
||||
|
||||
setFirstResponder();
|
||||
|
||||
return( true );
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiInputCtrl::onSleep()
|
||||
{
|
||||
Parent::onSleep();
|
||||
mouseUnlock();
|
||||
clearFirstResponder();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
static bool isModifierKey( U16 keyCode )
|
||||
{
|
||||
switch ( keyCode )
|
||||
{
|
||||
case KEY_LCONTROL:
|
||||
case KEY_RCONTROL:
|
||||
case KEY_LALT:
|
||||
case KEY_RALT:
|
||||
case KEY_LSHIFT:
|
||||
case KEY_RSHIFT:
|
||||
return( true );
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiInputCtrl, onInputEvent, void, (const char* device, const char* action, bool state ),
|
||||
( device, action, state),
|
||||
"@brief Callback that occurs when an input is triggered on this control\n\n"
|
||||
"@param device The device type triggering the input, such as keyboard, mouse, etc\n"
|
||||
"@param action The actual event occuring, such as a key or button\n"
|
||||
"@param state True if the action is being pressed, false if it is being release\n\n"
|
||||
);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool GuiInputCtrl::onInputEvent( const InputEventInfo &event )
|
||||
{
|
||||
// TODO - add POV support...
|
||||
if ( event.action == SI_MAKE )
|
||||
{
|
||||
if ( event.objType == SI_BUTTON
|
||||
|| event.objType == SI_POV
|
||||
|| ( ( event.objType == SI_KEY ) && !isModifierKey( event.objInst ) ) )
|
||||
{
|
||||
char deviceString[32];
|
||||
if ( !ActionMap::getDeviceName( event.deviceType, event.deviceInst, deviceString ) )
|
||||
return( false );
|
||||
|
||||
const char* actionString = ActionMap::buildActionString( &event );
|
||||
|
||||
//Con::executef( this, "onInputEvent", deviceString, actionString, "1" );
|
||||
onInputEvent_callback(deviceString, actionString, 1);
|
||||
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
else if ( event.action == SI_BREAK )
|
||||
{
|
||||
if ( ( event.objType == SI_KEY ) && isModifierKey( event.objInst ) )
|
||||
{
|
||||
char keyString[32];
|
||||
if ( !ActionMap::getKeyString( event.objInst, keyString ) )
|
||||
return( false );
|
||||
|
||||
//Con::executef( this, "onInputEvent", "keyboard", keyString, "0" );
|
||||
onInputEvent_callback("keyboard", keyString, 0);
|
||||
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
57
Engine/source/gui/utility/guiInputCtrl.h
Normal file
57
Engine/source/gui/utility/guiInputCtrl.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GUIINPUTCTRL_H_
|
||||
#define _GUIINPUTCTRL_H_
|
||||
|
||||
#ifndef _GUIMOUSEEVENTCTRL_H_
|
||||
#include "gui/utility/guiMouseEventCtrl.h"
|
||||
#endif
|
||||
#ifndef _EVENT_H_
|
||||
#include "platform/event.h"
|
||||
#endif
|
||||
|
||||
|
||||
/// A control that locks the mouse and reports all keyboard input events
|
||||
/// to script. This is useful for implementing custom keyboard handling code.
|
||||
class GuiInputCtrl : public GuiMouseEventCtrl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef GuiMouseEventCtrl Parent;
|
||||
|
||||
// GuiControl.
|
||||
virtual bool onWake();
|
||||
virtual void onSleep();
|
||||
|
||||
virtual bool onInputEvent( const InputEventInfo &event );
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT(GuiInputCtrl);
|
||||
DECLARE_CATEGORY( "Gui Other Script" );
|
||||
DECLARE_DESCRIPTION( "A control that locks the mouse and reports all keyboard input events to script." );
|
||||
|
||||
DECLARE_CALLBACK( void, onInputEvent, ( const char* device, const char* action, bool state ));
|
||||
};
|
||||
|
||||
#endif // _GUI_INPUTCTRL_H
|
||||
373
Engine/source/gui/utility/guiMouseEventCtrl.cpp
Normal file
373
Engine/source/gui/utility/guiMouseEventCtrl.cpp
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "gui/utility/guiMouseEventCtrl.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiMouseEventCtrl);
|
||||
|
||||
ConsoleDocClass( GuiMouseEventCtrl,
|
||||
"@brief Used to overlaps a 'hot region' where you want to catch inputs with and have specific events occur based on individual callbacks.\n\n"
|
||||
|
||||
"Mouse event callbacks supported by this control are: onMouseUp, onMouseDown, onMouseMove, onMouseDragged, onMouseEnter, onMouseLeave,\n"
|
||||
"onRightMouseDown, onRightMouseUp and onRightMouseDragged.\n\n"
|
||||
|
||||
"@tsexample\n"
|
||||
"new GuiMouseEventCtrl()\n"
|
||||
"{\n"
|
||||
" lockMouse = \"0\";\n"
|
||||
" //Properties not specific to this control have been omitted from this example.\n"
|
||||
"};\n"
|
||||
"@endtsexample\n\n"
|
||||
|
||||
"@see GuiControl\n\n"
|
||||
|
||||
"@ingroup GuiCore\n"
|
||||
);
|
||||
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseDown, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse is pressed down while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse was pressed down in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseDown(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseUp, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse is released while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse was released in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseUp(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseMove, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse is moved (without dragging) while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse was moved in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseMove(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseDragged, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse is dragged while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse was dragged in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseDragged(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseEnter, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse enters this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse entered this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseEnter(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onMouseLeave, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse leaves this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Mouse left this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onMouseLeave(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseDown, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the right mouse button is pressed while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Right mouse button was pressed in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onRightMouseDown(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseUp, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the right mouse button is released while in this control.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Right mouse button was released in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onRightMouseUp(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK( GuiMouseEventCtrl, onRightMouseDragged, void, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ),
|
||||
( modifier, mousePoint, mouseClickCount ),
|
||||
"@brief Callback that occurs whenever the mouse is dragged in this control while the right mouse button is pressed.\n\n"
|
||||
"@param modifier Key that was pressed during this callback. Values are:\n\n"
|
||||
"$EventModifier::RSHIFT\n\n"
|
||||
"$EventModifier::SHIFT\n\n"
|
||||
"$EventModifier::LCTRL\n\n"
|
||||
"$EventModifier::RCTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::CTRL\n\n"
|
||||
"$EventModifier::RALT\n\n"
|
||||
"$EventModifier::ALT\n\n"
|
||||
"@param mousePoint X/Y location of the mouse point\n"
|
||||
"@param mouseClickCount How many mouse clicks have occured for this event\n\n"
|
||||
"@tsexample\n"
|
||||
"// Right mouse button was dragged in this control, causing the callback\n"
|
||||
"GuiMouseEventCtrl::onRightMouseDragged(%this,%modifier,%mousePoint,%mouseClickCount)\n"
|
||||
"{\n"
|
||||
" // Code to call when a mouse event occurs.\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@see GuiControl\n\n"
|
||||
);
|
||||
|
||||
GuiMouseEventCtrl::GuiMouseEventCtrl()
|
||||
{
|
||||
mLockMouse = false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiMouseEventCtrl::sendMouseEvent(const char * name, const GuiEvent & event)
|
||||
{
|
||||
char buf[3][32];
|
||||
dSprintf(buf[0], 32, "%d", event.modifier);
|
||||
dSprintf(buf[1], 32, "%d %d", event.mousePoint.x, event.mousePoint.y);
|
||||
dSprintf(buf[2], 32, "%d", event.mouseClickCount);
|
||||
|
||||
if(dStricmp(name,"onMouseDown") == 0)
|
||||
onMouseDown_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onMouseUp") == 0)
|
||||
onMouseUp_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onMouseMove") == 0)
|
||||
onMouseMove_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onMouseDragged") == 0)
|
||||
onMouseDragged_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onMouseEnter") == 0)
|
||||
onMouseEnter_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onMouseLeave") == 0)
|
||||
onMouseLeave_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onRightMouseDown") == 0)
|
||||
onRightMouseDown_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onRightMouseUp") == 0)
|
||||
onRightMouseUp_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
else if(dStricmp(name,"onRightMouseDragged") == 0)
|
||||
onRightMouseDragged_callback(event.modifier, event.mousePoint, event.mouseClickCount);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiMouseEventCtrl::initPersistFields()
|
||||
{
|
||||
addGroup( "Input" );
|
||||
|
||||
addField("lockMouse", TypeBool, Offset(mLockMouse, GuiMouseEventCtrl),
|
||||
"Whether the control should lock the mouse between up and down button events." );
|
||||
|
||||
endGroup( "Input" );
|
||||
|
||||
Parent::initPersistFields();
|
||||
|
||||
Con::setIntVariable("$EventModifier::LSHIFT", SI_LSHIFT);
|
||||
Con::setIntVariable("$EventModifier::RSHIFT", SI_RSHIFT);
|
||||
Con::setIntVariable("$EventModifier::SHIFT", SI_SHIFT);
|
||||
Con::setIntVariable("$EventModifier::LCTRL", SI_LCTRL);
|
||||
Con::setIntVariable("$EventModifier::RCTRL", SI_RCTRL);
|
||||
Con::setIntVariable("$EventModifier::CTRL", SI_CTRL);
|
||||
Con::setIntVariable("$EventModifier::LALT", SI_LALT);
|
||||
Con::setIntVariable("$EventModifier::RALT", SI_RALT);
|
||||
Con::setIntVariable("$EventModifier::ALT", SI_ALT);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void GuiMouseEventCtrl::onMouseDown(const GuiEvent & event)
|
||||
{
|
||||
if(mLockMouse)
|
||||
mouseLock();
|
||||
sendMouseEvent("onMouseDown", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onMouseUp(const GuiEvent & event)
|
||||
{
|
||||
if(mLockMouse)
|
||||
mouseUnlock();
|
||||
sendMouseEvent("onMouseUp", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onMouseMove(const GuiEvent & event)
|
||||
{
|
||||
sendMouseEvent("onMouseMove", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onMouseDragged(const GuiEvent & event)
|
||||
{
|
||||
sendMouseEvent("onMouseDragged", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onMouseEnter(const GuiEvent & event)
|
||||
{
|
||||
sendMouseEvent("onMouseEnter", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onMouseLeave(const GuiEvent & event)
|
||||
{
|
||||
sendMouseEvent("onMouseLeave", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onRightMouseDown(const GuiEvent & event)
|
||||
{
|
||||
if(mLockMouse)
|
||||
mouseLock();
|
||||
sendMouseEvent("onRightMouseDown", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onRightMouseUp(const GuiEvent & event)
|
||||
{
|
||||
if(mLockMouse)
|
||||
mouseUnlock();
|
||||
sendMouseEvent("onRightMouseUp", event);
|
||||
}
|
||||
|
||||
void GuiMouseEventCtrl::onRightMouseDragged(const GuiEvent & event)
|
||||
{
|
||||
sendMouseEvent("onRightMouseDragged", event);
|
||||
}
|
||||
75
Engine/source/gui/utility/guiMouseEventCtrl.h
Normal file
75
Engine/source/gui/utility/guiMouseEventCtrl.h
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _GUIMOUSEEVENTCTRL_H_
|
||||
#define _GUIMOUSEEVENTCTRL_H_
|
||||
|
||||
#ifndef _GUICONTROL_H_
|
||||
#include "gui/core/guiControl.h"
|
||||
#endif
|
||||
#ifndef _EVENT_H_
|
||||
#include "platform/event.h"
|
||||
#endif
|
||||
|
||||
|
||||
class GuiMouseEventCtrl : public GuiControl
|
||||
{
|
||||
private:
|
||||
typedef GuiControl Parent;
|
||||
void sendMouseEvent(const char * name, const GuiEvent &);
|
||||
|
||||
// field info
|
||||
bool mLockMouse;
|
||||
|
||||
public:
|
||||
|
||||
GuiMouseEventCtrl();
|
||||
|
||||
DECLARE_CALLBACK( void, onMouseDown, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onMouseUp, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onMouseMove, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onMouseDragged, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onMouseEnter, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onMouseLeave, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onRightMouseDown, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onRightMouseUp, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
DECLARE_CALLBACK( void, onRightMouseDragged, ( U8 modifier, Point2I mousePoint,U8 mouseClickCount ));
|
||||
|
||||
// GuiControl
|
||||
void onMouseDown(const GuiEvent & event);
|
||||
void onMouseUp(const GuiEvent & event);
|
||||
void onMouseMove(const GuiEvent & event);
|
||||
void onMouseDragged(const GuiEvent & event);
|
||||
void onMouseEnter(const GuiEvent & event);
|
||||
void onMouseLeave(const GuiEvent & event);
|
||||
void onRightMouseDown(const GuiEvent & event);
|
||||
void onRightMouseUp(const GuiEvent & event);
|
||||
void onRightMouseDragged(const GuiEvent & event);
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
DECLARE_CONOBJECT( GuiMouseEventCtrl );
|
||||
DECLARE_CATEGORY( "Gui Other Script" );
|
||||
DECLARE_DESCRIPTION( "A control that relays all mouse events to script." );
|
||||
};
|
||||
|
||||
#endif
|
||||
618
Engine/source/gui/utility/messageVector.cpp
Normal file
618
Engine/source/gui/utility/messageVector.cpp
Normal file
|
|
@ -0,0 +1,618 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "gui/utility/messageVector.h"
|
||||
#include "core/fileObject.h"
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(MessageVector);
|
||||
|
||||
ConsoleDocClass( MessageVector,
|
||||
"@brief Store a list of chat messages.\n\n"
|
||||
|
||||
"This is responsible for managing messages which appear in the chat HUD, not the actual control rendered to the screen\n\n"
|
||||
|
||||
"@tsexample\n"
|
||||
"// Declare ChatHud, which is what will display the actual chat from a MessageVector\n"
|
||||
"new GuiMessageVectorCtrl(ChatHud) {\n"
|
||||
" profile = \"ChatHudMessageProfile\";\n"
|
||||
" horizSizing = \"width\";\n"
|
||||
" vertSizing = \"height\";\n"
|
||||
" position = \"1 1\";\n"
|
||||
" extent = \"252 16\";\n"
|
||||
" minExtent = \"8 8\";\n"
|
||||
" visible = \"1\";\n"
|
||||
" helpTag = \"0\";\n"
|
||||
" lineSpacing = \"0\";\n"
|
||||
" lineContinuedIndex = \"10\";\n"
|
||||
" matchColor = \"0 0 255 255\";\n"
|
||||
" maxColorIndex = \"5\";\n"
|
||||
"};\n\n"
|
||||
"// All messages are stored in this HudMessageVector, the actual\n"
|
||||
"// MainChatHud only displays the contents of this vector.\n"
|
||||
"new MessageVector(HudMessageVector);\n\n"
|
||||
"// Attach the MessageVector to the chat control\n"
|
||||
"chatHud.attach(HudMessageVector);\n"
|
||||
"@endtsexample\n\n"
|
||||
|
||||
"@see GuiMessageVectorCtrl for more details on how this is used."
|
||||
|
||||
"@ingroup GuiUtil\n"
|
||||
);
|
||||
|
||||
DefineEngineMethod( MessageVector, clear, void, (),,
|
||||
"Clear all messages in the vector\n\n"
|
||||
"@tsexample\n"
|
||||
"HudMessageVector.clear();\n"
|
||||
"@endtsexample\n\n")
|
||||
{
|
||||
object->clear();
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, clear, void, 2, 2, "Clear the message vector.")
|
||||
//{
|
||||
// object->clear();
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, pushBackLine, void, ( const char* msg, S32 tag ),,
|
||||
"Push a line onto the back of the list.\n\n"
|
||||
"@param msg Text that makes up the message\n"
|
||||
"@param tag Numerical value associated with this message, useful for searching.\n\n"
|
||||
"@tsexample\n"
|
||||
"// Add the message...\n"
|
||||
"HudMessageVector.pushBackLine(\"Hello World\", 0);\n"
|
||||
"@endtsexample\n\n")
|
||||
{
|
||||
object->pushBackLine(msg, tag);
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, pushBackLine, void, 3, 4, "(string msg, int tag=0)"
|
||||
// "Push a line onto the back of the list.")
|
||||
//{
|
||||
// U32 tag = 0;
|
||||
// if (argc == 4)
|
||||
// tag = dAtoi(argv[3]);
|
||||
//
|
||||
// object->pushBackLine(argv[2], tag);
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, popBackLine, bool, (),,
|
||||
"Pop a line from the back of the list; destroys the line.\n\n"
|
||||
"@tsexample\n"
|
||||
"HudMessageVector.popBackLine();\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return False if there are no lines to pop (underflow), true otherwise")
|
||||
{
|
||||
if (object->getNumLines() == 0) {
|
||||
Con::errorf(ConsoleLogEntry::General, "MessageVector::popBackLine(): underflow");
|
||||
return false;
|
||||
}
|
||||
|
||||
object->popBackLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, popBackLine, bool, 2, 2, "()"
|
||||
// "Pop a line from the back of the list; destroys the line.")
|
||||
//{
|
||||
// if (object->getNumLines() == 0) {
|
||||
// Con::errorf(ConsoleLogEntry::General, "MessageVector::popBackLine(): underflow");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// object->popBackLine();
|
||||
// return true;
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, pushFrontLine, void, ( const char* msg, S32 tag ),,
|
||||
"Push a line onto the front of the vector.\n\n"
|
||||
"@param msg Text that makes up the message\n"
|
||||
"@param tag Numerical value associated with this message, useful for searching.\n\n"
|
||||
"@tsexample\n"
|
||||
"// Add the message...\n"
|
||||
"HudMessageVector.pushFrontLine(\"Hello World\", 0);\n"
|
||||
"@endtsexample\n\n")
|
||||
{
|
||||
object->pushFrontLine(msg, tag);
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, pushFrontLine, void, 3, 4, "(string msg, int tag=0)"
|
||||
// "Push a line onto the front of the vector.")
|
||||
//{
|
||||
// U32 tag = 0;
|
||||
// if (argc == 4)
|
||||
// tag = dAtoi(argv[3]);
|
||||
//
|
||||
// object->pushFrontLine(argv[2], tag);
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, popFrontLine, bool, (),,
|
||||
"Pop a line from the front of the vector, destroying the line.\n\n"
|
||||
"@tsexample\n"
|
||||
"HudMessageVector.popFrontLine();\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return False if there are no lines to pop (underflow), true otherwise")
|
||||
{
|
||||
if (object->getNumLines() == 0) {
|
||||
Con::errorf(ConsoleLogEntry::General, "MessageVector::popFrontLine(): underflow");
|
||||
return false;
|
||||
}
|
||||
|
||||
object->popFrontLine();
|
||||
return true;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, popFrontLine, bool, 2, 2,
|
||||
// "Pop a line from the front of the vector, destroying the line.")
|
||||
//{
|
||||
// if (object->getNumLines() == 0) {
|
||||
// Con::errorf(ConsoleLogEntry::General, "MessageVector::popFrontLine(): underflow");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// object->popFrontLine();
|
||||
// return true;
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, insertLine, bool, ( S32 insertPos, const char* msg, S32 tag ),,
|
||||
"Push a line onto the back of the list.\n\n"
|
||||
"@param msg Text that makes up the message\n"
|
||||
"@param tag Numerical value associated with this message, useful for searching.\n\n"
|
||||
"@tsexample\n"
|
||||
"// Add the message...\n"
|
||||
"HudMessageVector.insertLine(1, \"Hello World\", 0);\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return False if insertPos is greater than the number of lines in the current vector")
|
||||
{
|
||||
if (insertPos > object->getNumLines())
|
||||
return false;
|
||||
|
||||
object->insertLine(insertPos, msg, tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, insertLine, bool, 4, 5, "(int insertPos, string msg, int tag=0)"
|
||||
// "Insert a new line into the vector at the specified position.")
|
||||
//{
|
||||
// U32 pos = U32(dAtoi(argv[2]));
|
||||
// if (pos > object->getNumLines())
|
||||
// return false;
|
||||
//
|
||||
// S32 tag = 0;
|
||||
// if (argc == 5)
|
||||
// tag = dAtoi(argv[4]);
|
||||
//
|
||||
// object->insertLine(pos, argv[3], tag);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, deleteLine, bool, ( S32 deletePos),,
|
||||
"Delete the line at the specified position.\n\n"
|
||||
"@param deletePos Position in the vector containing the line to be deleted\n"
|
||||
"@tsexample\n"
|
||||
"// Delete the first line (index 0) in the vector...\n"
|
||||
"HudMessageVector.deleteLine(0);\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return False if deletePos is greater than the number of lines in the current vector")
|
||||
{
|
||||
if (deletePos >= object->getNumLines())
|
||||
return false;
|
||||
|
||||
object->deleteLine(deletePos);
|
||||
return true;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, deleteLine, bool, 3, 3, "(int deletePos)"
|
||||
// "Delete the line at the specified position.")
|
||||
//{
|
||||
// U32 pos = U32(dAtoi(argv[2]));
|
||||
// if (pos >= object->getNumLines())
|
||||
// return false;
|
||||
//
|
||||
// object->deleteLine(pos);
|
||||
// return true;
|
||||
//}
|
||||
static ConsoleDocFragment _MessageVectordump1(
|
||||
"@brief Dump the message vector to a file without a header.\n\n"
|
||||
|
||||
"@param filename Name and path of file to dump text to.\n"
|
||||
|
||||
"@tsexample\n"
|
||||
"// Dump the entire chat log to a text file\n"
|
||||
"HudMessageVector.dump(\"./chatLog.txt\");\n"
|
||||
"@endtsexample\n\n\n",
|
||||
"MessageVector",
|
||||
"void dump( string filename);");
|
||||
|
||||
static ConsoleDocFragment _MessageVectordump2(
|
||||
"@brief Dump the message vector to a file with a header.\n\n"
|
||||
|
||||
"@param filename Name and path of file to dump text to.\n"
|
||||
"@param header Prefix information for write out\n\n"
|
||||
|
||||
"@tsexample\n"
|
||||
"// Arbitrary header data\n"
|
||||
"%headerInfo = \"Ars Moriendi Chat Log\";\n\n"
|
||||
"// Dump the entire chat log to a text file\n"
|
||||
"HudMessageVector.dump(\"./chatLog.txt\", %headerInfo);\n"
|
||||
"@endtsexample\n\n\n",
|
||||
"MessageVector",
|
||||
"void dump( string filename, string header);");
|
||||
|
||||
ConsoleMethod( MessageVector, dump, void, 3, 4, "(string filename, string header=NULL)"
|
||||
"Dump the message vector to a file, optionally prefixing a header."
|
||||
"@hide")
|
||||
{
|
||||
|
||||
if ( argc == 4 )
|
||||
object->dump( argv[2], argv[3] );
|
||||
else
|
||||
object->dump( argv[2] );
|
||||
}
|
||||
|
||||
DefineEngineMethod( MessageVector, getNumLines, S32, (),,
|
||||
"Get the number of lines in the vector.\n\n"
|
||||
"@tsexample\n"
|
||||
"// Find out how many lines have been stored in HudMessageVector\n"
|
||||
"%chatLines = HudMessageVector.getNumLines();\n"
|
||||
"echo(%chatLines);\n"
|
||||
"@endtsexample\n\n")
|
||||
{
|
||||
return object->getNumLines();
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, getNumLines, S32, 2, 2, "Get the number of lines in the vector.")
|
||||
//{
|
||||
// return object->getNumLines();
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, getLineTextByTag, const char*, ( S32 tag),,
|
||||
"Scan through the lines in the vector, returning the first line that has a matching tag.\n\n"
|
||||
"@param tag Numerical value assigned to a message when it was added or inserted\n"
|
||||
"@tsexample\n"
|
||||
"// Locate text in the vector tagged with the value \"1\", then print it\n"
|
||||
"%taggedText = HudMessageVector.getLineTextByTag(1);\n"
|
||||
"echo(%taggedText);\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return Text from a line with matching tag, other wise \"\"")
|
||||
{
|
||||
for(U32 i = 0; i < object->getNumLines(); i++)
|
||||
if(object->getLine(i).messageTag == tag)
|
||||
return object->getLine(i).message;
|
||||
return "";
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, getLineTextByTag, const char*, 3, 3, "(int tag)"
|
||||
// "Scan through the lines in the vector, returning the first line that has a matching tag.")
|
||||
//{
|
||||
// U32 tag = dAtoi(argv[2]);
|
||||
//
|
||||
// for(U32 i = 0; i < object->getNumLines(); i++)
|
||||
// if(object->getLine(i).messageTag == tag)
|
||||
// return object->getLine(i).message;
|
||||
// return "";
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, getLineIndexByTag, S32, ( S32 tag),,
|
||||
"Scan through the vector, returning the line number of the first line that matches the specified tag; else returns -1 if no match was found.\n\n"
|
||||
"@param tag Numerical value assigned to a message when it was added or inserted\n"
|
||||
"@tsexample\n"
|
||||
"// Locate a line of text tagged with the value \"1\", then delete it.\n"
|
||||
"%taggedLine = HudMessageVector.getLineIndexByTag(1);\n"
|
||||
"HudMessageVector.deleteLine(%taggedLine);\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return Line with matching tag, other wise -1")
|
||||
{
|
||||
for(U32 i = 0; i < object->getNumLines(); i++)
|
||||
if(object->getLine(i).messageTag == tag)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, getLineIndexByTag, S32, 3, 3, "(int tag)"
|
||||
// "Scan through the vector, returning the line number of the first line that matches the specified tag; else returns -1 if no match was found.")
|
||||
//{
|
||||
// U32 tag = dAtoi(argv[2]);
|
||||
//
|
||||
// for(U32 i = 0; i < object->getNumLines(); i++)
|
||||
// if(object->getLine(i).messageTag == tag)
|
||||
// return i;
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, getLineText, const char*, ( S32 pos),,
|
||||
"Get the text at a specified line.\n\n"
|
||||
"@param pos Position in vector to grab text from\n"
|
||||
"@tsexample\n"
|
||||
"// Print a line of text at position 1.\n"
|
||||
"%text = HudMessageVector.getLineText(1);\n"
|
||||
"echo(%text);\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return Text at specified line, if the position is greater than the number of lines return \"\"")
|
||||
{
|
||||
if (pos >= object->getNumLines()) {
|
||||
Con::errorf(ConsoleLogEntry::General, "MessageVector::getLineText(con): out of bounds line");
|
||||
return "";
|
||||
}
|
||||
|
||||
return object->getLine(pos).message;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, getLineText, const char*, 3, 3, "(int line)"
|
||||
// "Get the text at a specified line.")
|
||||
//{
|
||||
// U32 pos = U32(dAtoi(argv[2]));
|
||||
// if (pos >= object->getNumLines()) {
|
||||
// Con::errorf(ConsoleLogEntry::General, "MessageVector::getLineText(con): out of bounds line");
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// return object->getLine(pos).message;
|
||||
//}
|
||||
|
||||
DefineEngineMethod( MessageVector, getLineTag, S32, ( S32 pos),,
|
||||
"Get the tag of a specified line.\n\n"
|
||||
"@param pos Position in vector to grab tag from\n"
|
||||
"@tsexample\n"
|
||||
"// Remove all lines that do not have a tag value of 1.\n"
|
||||
"while( HudMessageVector.getNumLines())\n"
|
||||
"{\n"
|
||||
" %tag = HudMessageVector.getLineTag(1);\n"
|
||||
" if(%tag != 1)\n"
|
||||
" %tag.delete();\n"
|
||||
" HudMessageVector.popFrontLine();\n"
|
||||
"}\n"
|
||||
"@endtsexample\n\n"
|
||||
"@return Tag value of a given line, if the position is greater than the number of lines return 0")
|
||||
{
|
||||
if (pos >= object->getNumLines()) {
|
||||
Con::errorf(ConsoleLogEntry::General, "MessageVector::getLineTag(con): out of bounds line");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return object->getLine(pos).messageTag;
|
||||
}
|
||||
|
||||
//ConsoleMethod( MessageVector, getLineTag, S32, 3, 3, "(int line)"
|
||||
// "Get the tag of a specified line.")
|
||||
//{
|
||||
// U32 pos = U32(dAtoi(argv[2]));
|
||||
// if (pos >= object->getNumLines()) {
|
||||
// Con::errorf(ConsoleLogEntry::General, "MessageVector::getLineTag(con): out of bounds line");
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// return object->getLine(pos).messageTag;
|
||||
//}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
MessageVector::MessageVector()
|
||||
{
|
||||
VECTOR_SET_ASSOCIATION(mMessageLines);
|
||||
VECTOR_SET_ASSOCIATION(mSpectators);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
MessageVector::~MessageVector()
|
||||
{
|
||||
for (U32 i = 0; i < mMessageLines.size(); i++) {
|
||||
char* pDelete = const_cast<char*>(mMessageLines[i].message);
|
||||
delete [] pDelete;
|
||||
mMessageLines[i].message = 0;
|
||||
mMessageLines[i].messageTag = 0xFFFFFFFF;
|
||||
}
|
||||
mMessageLines.clear();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::initPersistFields()
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool MessageVector::onAdd()
|
||||
{
|
||||
return Parent::onAdd();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::onRemove()
|
||||
{
|
||||
// Delete all the lines from the observers, and then forcibly detatch ourselves
|
||||
//
|
||||
for (S32 i = mMessageLines.size() - 1; i >= 0; i--)
|
||||
spectatorMessage(LineDeleted, i);
|
||||
spectatorMessage(VectorDeletion, 0);
|
||||
mSpectators.clear();
|
||||
|
||||
Parent::onRemove();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::pushBackLine(const char* newMessage, const S32 newMessageTag)
|
||||
{
|
||||
insertLine(mMessageLines.size(), newMessage, newMessageTag);
|
||||
}
|
||||
|
||||
|
||||
void MessageVector::popBackLine()
|
||||
{
|
||||
AssertFatal(mMessageLines.size() != 0, "MessageVector::popBackLine: nothing to pop!");
|
||||
if (mMessageLines.size() == 0)
|
||||
return;
|
||||
|
||||
deleteLine(mMessageLines.size() - 1);
|
||||
}
|
||||
|
||||
void MessageVector::clear()
|
||||
{
|
||||
while(mMessageLines.size())
|
||||
deleteLine(mMessageLines.size() - 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::pushFrontLine(const char* newMessage, const S32 newMessageTag)
|
||||
{
|
||||
insertLine(0, newMessage, newMessageTag);
|
||||
}
|
||||
|
||||
|
||||
void MessageVector::popFrontLine()
|
||||
{
|
||||
AssertFatal(mMessageLines.size() != 0, "MessageVector::popBackLine: nothing to pop!");
|
||||
if (mMessageLines.size() == 0)
|
||||
return;
|
||||
|
||||
deleteLine(0);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::insertLine(const U32 position,
|
||||
const char* newMessage,
|
||||
const S32 newMessageTag)
|
||||
{
|
||||
AssertFatal(position >= 0 && position <= mMessageLines.size(), "MessageVector::insertLine: out of range position!");
|
||||
AssertFatal(newMessage != NULL, "Error, no message to insert!");
|
||||
|
||||
U32 len = dStrlen(newMessage) + 1;
|
||||
char* copy = new char[len];
|
||||
dStrcpy(copy, newMessage);
|
||||
|
||||
mMessageLines.insert(position);
|
||||
mMessageLines[position].message = copy;
|
||||
mMessageLines[position].messageTag = newMessageTag;
|
||||
|
||||
// Notify of insert
|
||||
spectatorMessage(LineInserted, position);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::deleteLine(const U32 position)
|
||||
{
|
||||
AssertFatal(position >= 0 && position < mMessageLines.size(), "MessageVector::deleteLine: out of range position!");
|
||||
|
||||
char* pDelete = const_cast<char*>(mMessageLines[position].message);
|
||||
delete [] pDelete;
|
||||
mMessageLines[position].message = NULL;
|
||||
mMessageLines[position].messageTag = 0xFFFFFFFF;
|
||||
|
||||
mMessageLines.erase(position);
|
||||
|
||||
// Notify of delete
|
||||
spectatorMessage(LineDeleted, position);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
bool MessageVector::dump( const char* filename, const char* header )
|
||||
{
|
||||
Con::printf( "Dumping message vector %s to %s...", getName(), filename );
|
||||
FileObject file;
|
||||
if ( !file.openForWrite( filename ) )
|
||||
return( false );
|
||||
|
||||
// If passed a header line, write it out first:
|
||||
if ( header )
|
||||
file.writeLine( (const U8*) header );
|
||||
|
||||
// First write out the record count:
|
||||
char* lineBuf = (char*) dMalloc( 10 );
|
||||
dSprintf( lineBuf, 10, "%d", mMessageLines.size() );
|
||||
file.writeLine( (const U8*) lineBuf );
|
||||
|
||||
// Write all of the lines of the message vector:
|
||||
U32 len;
|
||||
for ( U32 i = 0; i < mMessageLines.size(); i++ )
|
||||
{
|
||||
len = ( dStrlen( mMessageLines[i].message ) * 2 ) + 10;
|
||||
lineBuf = (char*) dRealloc( lineBuf, len );
|
||||
dSprintf( lineBuf, len, "%d ", mMessageLines[i].messageTag );
|
||||
expandEscape( lineBuf + dStrlen( lineBuf ), mMessageLines[i].message );
|
||||
file.writeLine( (const U8*) lineBuf );
|
||||
}
|
||||
|
||||
file.close();
|
||||
return( true );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void MessageVector::registerSpectator(SpectatorCallback callBack, void *spectatorKey)
|
||||
{
|
||||
AssertFatal(callBack != NULL, "Error, must have a callback!");
|
||||
|
||||
// First, make sure that this hasn't been registered already...
|
||||
U32 i;
|
||||
for (i = 0; i < mSpectators.size(); i++) {
|
||||
AssertFatal(mSpectators[i].key != spectatorKey, "Error, spectator key already registered!");
|
||||
if (mSpectators[i].key == spectatorKey)
|
||||
return;
|
||||
}
|
||||
|
||||
mSpectators.increment();
|
||||
mSpectators.last().callback = callBack;
|
||||
mSpectators.last().key = spectatorKey;
|
||||
|
||||
// Need to message this spectator of all the lines currently inserted...
|
||||
for (i = 0; i < mMessageLines.size(); i++) {
|
||||
(*mSpectators.last().callback)(mSpectators.last().key,
|
||||
LineInserted, i);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageVector::unregisterSpectator(void * spectatorKey)
|
||||
{
|
||||
for (U32 i = 0; i < mSpectators.size(); i++) {
|
||||
if (mSpectators[i].key == spectatorKey) {
|
||||
// Need to message this spectator of all the lines currently inserted...
|
||||
for (S32 j = mMessageLines.size() - 1; j >= 0 ; j--) {
|
||||
(*mSpectators[i].callback)(mSpectators[i].key,
|
||||
LineDeleted, j);
|
||||
}
|
||||
|
||||
mSpectators.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AssertFatal(false, "MessageVector::unregisterSpectator: tried to unregister a spectator that isn't subscribed!");
|
||||
Con::errorf(ConsoleLogEntry::General,
|
||||
"MessageVector::unregisterSpectator: tried to unregister a spectator that isn't subscribed!");
|
||||
}
|
||||
|
||||
void MessageVector::spectatorMessage(MessageCode code, const U32 arg)
|
||||
{
|
||||
for (U32 i = 0; i < mSpectators.size(); i++) {
|
||||
(*mSpectators[i].callback)(mSpectators[i].key,
|
||||
code, arg);
|
||||
}
|
||||
}
|
||||
|
||||
127
Engine/source/gui/utility/messageVector.h
Normal file
127
Engine/source/gui/utility/messageVector.h
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _MESSAGEVECTOR_H_
|
||||
#define _MESSAGEVECTOR_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
#ifndef _TVECTOR_H_
|
||||
#include "core/util/tVector.h"
|
||||
#endif
|
||||
#ifndef _SIMBASE_H_
|
||||
#include "console/simBase.h"
|
||||
#endif
|
||||
|
||||
/// Store a list of chat messages.
|
||||
///
|
||||
/// This is responsible for managing messages which appear in the chat HUD.
|
||||
///
|
||||
/// @see GuiMessageVectorCtrl for more details on how this is used.
|
||||
class MessageVector : public SimObject
|
||||
{
|
||||
typedef SimObject Parent;
|
||||
|
||||
//-------------------------------------- Public interface...
|
||||
public:
|
||||
MessageVector();
|
||||
~MessageVector();
|
||||
|
||||
public:
|
||||
struct MessageLine {
|
||||
char* message;
|
||||
S32 messageTag;
|
||||
};
|
||||
|
||||
|
||||
// Spectator registration...
|
||||
public:
|
||||
enum MessageCode {
|
||||
LineInserted = 0,
|
||||
LineDeleted = 1,
|
||||
|
||||
VectorDeletion = 2
|
||||
};
|
||||
|
||||
typedef void (*SpectatorCallback)(void * spectatorKey,
|
||||
const MessageCode code,
|
||||
const U32 argument);
|
||||
|
||||
void registerSpectator(SpectatorCallback, void * spectatorKey);
|
||||
void unregisterSpectator(void *spectatorKey);
|
||||
|
||||
// Query functions
|
||||
public:
|
||||
U32 getNumLines() const;
|
||||
const MessageLine& getLine(const U32 line) const;
|
||||
|
||||
// Mutators
|
||||
public:
|
||||
void pushBackLine(const char*, const S32);
|
||||
void popBackLine();
|
||||
void pushFrontLine(const char*, const S32);
|
||||
void popFrontLine();
|
||||
void clear();
|
||||
|
||||
virtual void insertLine(const U32 position, const char*, const S32);
|
||||
virtual void deleteLine(const U32);
|
||||
|
||||
bool dump( const char* filename, const char* header = NULL );
|
||||
|
||||
|
||||
//-------------------------------------- Internal interface
|
||||
protected:
|
||||
bool onAdd();
|
||||
void onRemove();
|
||||
|
||||
private:
|
||||
struct SpectatorRef {
|
||||
SpectatorCallback callback;
|
||||
void * key;
|
||||
};
|
||||
|
||||
Vector<MessageLine> mMessageLines;
|
||||
|
||||
Vector<SpectatorRef> mSpectators;
|
||||
void spectatorMessage(MessageCode, const U32 arg);
|
||||
|
||||
public:
|
||||
DECLARE_CONOBJECT(MessageVector);
|
||||
static void initPersistFields();
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
inline U32 MessageVector::getNumLines() const
|
||||
{
|
||||
return mMessageLines.size();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
inline const MessageVector::MessageLine& MessageVector::getLine(const U32 line) const
|
||||
{
|
||||
AssertFatal(line < mMessageLines.size(), "MessageVector::getLine: out of bounds line index");
|
||||
return mMessageLines[line];
|
||||
}
|
||||
|
||||
#endif // _H_GUICHATVECTOR_
|
||||
Loading…
Add table
Add a link
Reference in a new issue