CHANGED: #1471 CViewPointer is now part of the NELGUI library and is under the NLGUI namespace.

This commit is contained in:
dfighter1985 2012-07-02 03:21:42 +02:00
parent 923695fe70
commit 363bb731c7
8 changed files with 651 additions and 646 deletions

View file

@ -0,0 +1,142 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef RZ_VIEW_POINTER_H
#define RZ_VIEW_POINTER_H
#include "nel/misc/types_nl.h"
#include "nel/misc/events.h"
#include "nel/gui/view_pointer_base.h"
namespace NLGUI
{
class CCtrlBase;
class CGroupContainer;
/**
* class describing the pointer
* \author Matthieu 'Trap' Besson
* \author Nevrax France
* \date 2002
*/
class CViewPointer : public CViewPointerBase
{
public:
DECLARE_UI_CLASS( CViewPointer )
CViewPointer( const TCtorParam &param );
virtual ~CViewPointer(){}
bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup);
void draw();
// Set cursor mode
void setStringMode (bool stringCursor);
bool getStringMode() const {return _StringMode;}
// Set cursor string
void setString (const ucstring &str);
// TEMP PATCH
void setCursor (const std::string &name)
{
_TxDefault = name;
_TxIdDefault = -2;
}
// TEMP PATCH
/// Show or hide the pointer. Please, use SetMouseMode (bool freelook) instead.
void show(bool s) {_PointerVisible = s;}
static void setHWMouse( bool hw ){ hwMouse = hw; }
private:
/// Drawing helpers
virtual bool drawResizer(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawRotate(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawScale(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawColorPicker(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawLink(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawBrowse(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawPan(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawCustom(CCtrlBase* pCB);
protected:
// Look of the cursor in different situation
std::string _TxDefault;
std::string _TxMoveWindow;
std::string _TxResizeBRTL;
std::string _TxResizeBLTR;
std::string _TxResizeTB;
std::string _TxResizeLR;
std::string _TxRotate;
std::string _TxScale;
std::string _TxColPick;
std::string _TxPan;
std::string _TxCanPan;
std::string _TxPanR2;
std::string _TxCanPanR2;
sint32 _TxIdDefault;
sint32 _TxIdMoveWindow;
sint32 _TxIdResizeBRTL;
sint32 _TxIdResizeBLTR;
sint32 _TxIdResizeTB;
sint32 _TxIdResizeLR;
sint32 _TxIdRotate;
sint32 _TxIdScale;
sint32 _TxIdColPick;
sint32 _TxIdPan;
sint32 _TxIdCanPan;
sint32 _TxIdPanR2;
sint32 _TxIdCanPanR2;
NLMISC::CRGBA _Color;
sint32 _OffsetX;
sint32 _OffsetY;
CGroupContainer *_LastHightLight;
// Cursor mode
bool _StringMode;
bool _ForceStringMode;
CInterfaceGroup *_StringCursor;
CInterfaceGroup *_StringCursorHardware;
ucstring _ContextString;
// draw current cursor with the given texture, or, if in hardware mode, change the hardware cursor shape
void drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot);
private:
// set the string into frame for software or hardware version
void setString (const ucstring &str, CInterfaceGroup *target);
static bool hwMouse;
};
}
#endif // RZ_VIEW_POINTER_H
/* End of view_pointer.h */

View file

@ -0,0 +1,505 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "nel/gui/view_pointer.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/view_renderer.h"
#include "nel/gui/group_paragraph.h"
#include "nel/gui/group_container.h"
#include "nel/misc/xml_auto_ptr.h"
#include "nel/misc/algo.h"
using namespace std;
using namespace NLMISC;
NLMISC_REGISTER_OBJECT(CViewBase, CViewPointer, std::string, "generic_pointer");
namespace NLGUI
{
bool CViewPointer::hwMouse = true;
// --------------------------------------------------------------------------------------------------------------------
CViewPointer::CViewPointer (const TCtorParam &param)
: CViewPointerBase(param)
{
_TxIdDefault = -2;
_TxIdMoveWindow = -2;
_TxIdResizeBRTL = -2;
_TxIdResizeBLTR = -2;
_TxIdResizeTB = -2;
_TxIdResizeLR = -2;
_TxIdRotate = -2;
_TxIdScale = -2;
_TxIdColPick = -2;
_TxIdPan = -2;
_TxIdCanPan = -2;
_TxIdPanR2 = -2;
_TxIdCanPanR2 = -2;
// The pointer must be draw over ALL layers
_RenderLayer= VR_LAYER_MAX;
_Color = CRGBA(255,255,255,255);
_LastHightLight = NULL;
_StringMode = false;
_ForceStringMode = false;
_StringCursor = NULL;
}
// +++ VIEW SPECIFIC +++
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointer::parse (xmlNodePtr cur,CInterfaceGroup * parentGroup)
{
CXMLAutoPtr prop;
if (! CViewBase::parse(cur, parentGroup) )
return false;
_OffsetX = getX();
_OffsetY = getY();
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_default");
if (prop) _TxDefault = (const char *) prop;
_TxDefault = NLMISC::strlwr (_TxDefault);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_move_window");
if (prop) _TxMoveWindow = (const char *) prop;
_TxMoveWindow = NLMISC::strlwr (_TxMoveWindow);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_BR_TL");
if (prop) _TxResizeBRTL = (const char *) prop;
_TxResizeBRTL = NLMISC::strlwr (_TxResizeBRTL);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_BL_TR");
if (prop) _TxResizeBLTR = (const char *) prop;
_TxResizeBLTR = NLMISC::strlwr (_TxResizeBLTR);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_TB");
if (prop) _TxResizeTB = (const char *) prop;
_TxResizeTB = NLMISC::strlwr (_TxResizeTB);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_LR");
if (prop) _TxResizeLR = (const char *) prop;
_TxResizeLR = NLMISC::strlwr (_TxResizeLR);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_rotate");
if (prop) _TxRotate = (const char *) prop;
_TxRotate = NLMISC::strlwr (_TxRotate);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_scale");
if (prop) _TxScale = (const char *) prop;
_TxScale = NLMISC::strlwr (_TxScale);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_colpick");
if (prop) _TxColPick = (const char *) prop;
_TxColPick = NLMISC::strlwr (_TxColPick);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_pan");
if (prop) _TxPan = (const char *) prop;
_TxPan = NLMISC::strlwr (_TxPan);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_can_pan");
if (prop) _TxCanPan = (const char *) prop;
_TxCanPan = NLMISC::strlwr (_TxCanPan);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_pan_r2");
if (prop) _TxPanR2 = (const char *) prop;
_TxPanR2 = NLMISC::strlwr (_TxPanR2);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_can_pan_r2");
if (prop) _TxCanPanR2 = (const char *) prop;
_TxCanPanR2 = NLMISC::strlwr (_TxCanPanR2);
prop = (char*) xmlGetProp (cur, (xmlChar*)"color");
if (prop) _Color = convertColor(prop);
return true;
}
// --------------------------------------------------------------------------------------------------------------------
class CCtrlDepthEntry
{
public:
CCtrlBase *Ctrl;
uint Depth;
bool operator<(const CCtrlDepthEntry &o) const
{
// Inverse Test => descending order
return Depth>o.Depth;
}
};
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::draw ()
{
// Do not display the pointer if not visible.
if(!_PointerVisible)
return;
CViewRenderer &rVR = *CViewRenderer::getInstance();
if ( CWidgetManager::getInstance()->isIngame() )
if (!_StringCursor)
{
// Create the string cursor instance
std::vector<std::pair<std::string,std::string> > templateParams;
templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor"));
_StringCursor = CWidgetManager::parser->createGroupInstance("string_cursor", "", templateParams);
if (_StringCursor)
_StringCursor->setParentPos(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
templateParams.clear();
templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor_hardware"));
_StringCursorHardware = CWidgetManager::parser->createGroupInstance("string_cursor_hardware", "", templateParams);
if (_StringCursorHardware)
_StringCursorHardware->setParentPos(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
}
CRGBA col;
if(getModulateGlobalColor())
col.modulateFromColor (_Color, CWidgetManager::getInstance()->getGlobalColor());
else
col= _Color;
//col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColor().A+1))>>8);
col.A = _Color.A;
if (_LastHightLight != NULL)
{
_LastHightLight->setHighLighted(false,0);
_LastHightLight = NULL;
}
if ( CWidgetManager::getInstance()->getCapturePointerLeft() != NULL && CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
CCtrlMover *pCM = dynamic_cast<CCtrlMover*>( CWidgetManager::getInstance()->getCapturePointerLeft());
if ((pCM != NULL) && (pCM->canMove() == true))
{
CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
if (pGC != NULL && !pGC->isLocked())
{
pGC->setHighLighted(true, 255);
_LastHightLight = pGC;
}
}
}
if (_TxIdDefault == -2)
{
_TxIdDefault = rVR.getTextureIdFromName (_TxDefault);
_TxIdMoveWindow = rVR.getTextureIdFromName (_TxMoveWindow);
_TxIdResizeBRTL = rVR.getTextureIdFromName (_TxResizeBRTL);
_TxIdResizeBLTR = rVR.getTextureIdFromName (_TxResizeBLTR);
_TxIdResizeTB = rVR.getTextureIdFromName (_TxResizeTB);
_TxIdResizeLR = rVR.getTextureIdFromName (_TxResizeLR);
_TxIdRotate = rVR.getTextureIdFromName (_TxRotate);
_TxIdScale = rVR.getTextureIdFromName (_TxScale);
_TxIdColPick = rVR.getTextureIdFromName (_TxColPick);
_TxIdPan = rVR.getTextureIdFromName (_TxPan);
_TxIdCanPan = rVR.getTextureIdFromName (_TxCanPan);
_TxIdPanR2 = rVR.getTextureIdFromName (_TxPanR2);
_TxIdCanPanR2 = rVR.getTextureIdFromName (_TxCanPanR2);
}
const vector<CCtrlBase *> &rICL = CWidgetManager::getInstance()->getCtrlsUnderPointer ();
// Draw the captured cursor
CCtrlBase *pCB = CWidgetManager::getInstance()->getCapturePointerLeft();
if (pCB != NULL)
{
if (drawResizer(pCB,col)) return;
if (drawColorPicker(pCB,col)) return;
if (drawRotate(pCB,col)) return;
if (drawPan(pCB,col)) return;
if (drawCustom(pCB)) return;
drawCursor(_TxIdDefault, col, 0);
return;
}
const vector<CViewBase *> &vUP = CWidgetManager::getInstance()->getViewsUnderPointer ();
for(uint i=0;i<vUP.size();i++)
{
CViewLink *vLink = dynamic_cast<CViewLink*>(vUP[i]);
if (vLink != NULL)
{
string tooltip;
uint8 rot;
if (vLink->getMouseOverShape(tooltip, rot, col))
{
setString(ucstring(tooltip));
sint32 texId = rVR.getTextureIdFromName ("curs_pick.tga");
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
drawCursor(texId, col, 0);
}
else
{
drawCursor(texId, col, 0);
}
return;
}
}
}
// Draw if capture right
pCB = CWidgetManager::getInstance()->getCapturePointerRight();
if (pCB != NULL)
{
// Is it a 3d scene ?
if (drawScale(pCB,col)) return;
drawCursor(_TxIdDefault, col, 0);
return;
}
bool overModalWindow = false;
// is the cursor currently over a modal window ?
CInterfaceGroup *currModal = CWidgetManager::getInstance()->getModalWindow();
if (currModal)
{
sint32 xPos = _XReal + _OffsetX;
sint32 yPos = _YReal + _OffsetY;
overModalWindow = currModal->isIn(xPos, yPos, _WReal, _HReal);
}
// Draw the cursor type that are under the pointer
if (CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
// Sorts the controls according to their depth, to approximate as best the CapturePointerLeft algo.
// Especially important so that Resizers controls get the precedence over the move control (else could randomly bug like in chat group)
static vector<CCtrlDepthEntry> sortedControls;
sortedControls.clear();
for(uint i=0;i<rICL.size();i++)
{
CCtrlDepthEntry cde;
cde.Ctrl= rICL[i];
// NB: not the exact CInterfaceManager getDepth test here, but should work fine
cde.Depth= cde.Ctrl->getParentDepth() + cde.Ctrl->getDeltaDepth();
sortedControls.push_back(cde);
}
std::sort(sortedControls.begin(), sortedControls.end());
// Then draw the correct cursor
for (uint32 i = 0; i < sortedControls.size(); ++i)
{
CCtrlBase *pCB = sortedControls[i].Ctrl;
if (overModalWindow)
{
if (!pCB->isSonOf(currModal)) continue;
}
if (drawBrowse(pCB, col)) return;
if (drawResizer(pCB,col)) return;
if (drawColorPicker(pCB,col)) return;
if (drawLink (pCB, col)) return;
if (drawCustom(pCB)) return;
// test for move highlight
if (_LastHightLight == NULL)
{
CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pCB);
if ( (pCM != NULL) && (pCM->canMove() == true) )
{
CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
if (pGC != NULL && !pGC->isLocked())
{
if (CWidgetManager::getInstance()->getCapturePointerLeft() != pCM)
pGC->setHighLighted(true, 128);
else
pGC->setHighLighted(true, 255);
_LastHightLight = pGC;
break;
}
}
}
}
}
if (CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
if (rICL.empty())
{
const vector<CInterfaceGroup *> &rIGL = CWidgetManager::getInstance()->getGroupsUnderPointer ();
for (uint32 i = 0; i < rIGL.size(); ++i)
{
CInterfaceGroup *pG = rIGL[i];
if (overModalWindow)
{
if (!pG->isSonOf(currModal)) continue;
}
if (drawPan (pG, col)) return;
if (drawBrowse(pG, col)) return;
}
}
}
if (_StringMode && CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
{
drawCursor(_TxIdDefault, col, 0);
}
}
}
else
{
// Draw the default cursor
drawCursor(_TxIdDefault, col, 0);
}
}
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointer::drawCustom(CCtrlBase* pCB)
{
string texName;
uint8 rot;
NLMISC::CRGBA col;
if (pCB->getMouseOverShape(texName, rot, col))
{
if (texName[0] == '@')
{
const string &tooltipInfos = texName.substr(1);
string tooltip;
vector<string> tooltipInfosList;
splitString(tooltipInfos, "@", tooltipInfosList);
texName = tooltipInfosList[0];
tooltip = tooltipInfosList[1];
nlinfo(tooltip.c_str());
setString(ucstring(tooltip));
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 texId = rVR.getTextureIdFromName (texName);
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
drawCursor(texId, col, 0);
}
else
{
drawCursor(texId, col, 0);
}
return true;
}
else
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 texId = rVR.getTextureIdFromName (texName);
drawCursor(texId, col, 0);
return true;
}
}
return false;
}
// +++ SET +++
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setStringMode (bool stringCursor)
{
_StringMode = stringCursor;
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setString (const ucstring &str, CInterfaceGroup *target)
{
if (target)
{
CInterfaceElement *element = target->getView ("fake_txt");
if (element)
{
CViewText *text = dynamic_cast<CViewText*> (element);
if (text)
text->setText(str);
}
element = target->getView ("real_txt");
if (element)
{
CViewText *text = dynamic_cast<CViewText*> (element);
if (text)
text->setText(str);
}
target->updateCoords();
target->updateCoords();
_ContextString = str;
}
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setString (const ucstring &str)
{
if (_ContextString != str)
{
setString(str, _StringCursor);
setString(str, _StringCursorHardware);
}
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 xPos = _XReal + _OffsetX;
sint32 yPos = _YReal + _OffsetY;
if ( !hwMouse )
{
rVR.draw11RotFlipBitmap (_RenderLayer, xPos, yPos, rot, false, texId, col);
}
else
{
// set new cursor for the hardware mouse
std::string name = rVR.getTextureNameFromId(texId);
rVR.getDriver()->setCursor(name, col, rot, (uint32) std::max(getX() - xPos, (sint32) 0), (uint32) std::max(getY() - yPos, (sint32) 0));
}
}
}

View file

@ -27,7 +27,7 @@
#include "nel/gui/interface_link.h"
#include "nel/gui/group_list.h"
#include "nel/gui/view_base.h"
#include "view_pointer.h"
#include "nel/gui/view_pointer.h"
#include "nel/gui/ctrl_base.h"
#include "nel/gui/ctrl_scroll.h"

View file

@ -44,7 +44,7 @@
#include "nel/gui/view_text_id.h"
#include "nel/gui/view_text_id_formated.h"
#include "view_radar.h"
#include "view_pointer.h"
#include "nel/gui/view_pointer.h"
// DBView (View linked to the database)
#include "nel/gui/dbview_bar.h"
#include "nel/gui/dbview_bar3.h"

View file

@ -39,9 +39,9 @@ namespace NLGUI
class CGroupList;
class CGroupContainer;
class CInterfaceAnim;
class CViewPointer;
}
class CViewPointer;
class CBrickJob;
// ***************************************************************************

View file

@ -1,499 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "view_pointer.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/view_renderer.h"
#include "nel/gui/group_paragraph.h"
#include "nel/misc/xml_auto_ptr.h"
#include "nel/gui/group_container.h"
using namespace std;
using namespace NLMISC;
NLMISC_REGISTER_OBJECT(CViewBase, CViewPointer, std::string, "generic_pointer");
bool CViewPointer::hwMouse = true;
// --------------------------------------------------------------------------------------------------------------------
CViewPointer::CViewPointer (const TCtorParam &param)
: CViewPointerBase(param)
{
_TxIdDefault = -2;
_TxIdMoveWindow = -2;
_TxIdResizeBRTL = -2;
_TxIdResizeBLTR = -2;
_TxIdResizeTB = -2;
_TxIdResizeLR = -2;
_TxIdRotate = -2;
_TxIdScale = -2;
_TxIdColPick = -2;
_TxIdPan = -2;
_TxIdCanPan = -2;
_TxIdPanR2 = -2;
_TxIdCanPanR2 = -2;
// The pointer must be draw over ALL layers
_RenderLayer= VR_LAYER_MAX;
_Color = CRGBA(255,255,255,255);
_LastHightLight = NULL;
_StringMode = false;
_ForceStringMode = false;
_StringCursor = NULL;
}
// +++ VIEW SPECIFIC +++
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointer::parse (xmlNodePtr cur,CInterfaceGroup * parentGroup)
{
CXMLAutoPtr prop;
if (! CViewBase::parse(cur, parentGroup) )
return false;
_OffsetX = getX();
_OffsetY = getY();
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_default");
if (prop) _TxDefault = (const char *) prop;
_TxDefault = NLMISC::strlwr (_TxDefault);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_move_window");
if (prop) _TxMoveWindow = (const char *) prop;
_TxMoveWindow = NLMISC::strlwr (_TxMoveWindow);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_BR_TL");
if (prop) _TxResizeBRTL = (const char *) prop;
_TxResizeBRTL = NLMISC::strlwr (_TxResizeBRTL);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_BL_TR");
if (prop) _TxResizeBLTR = (const char *) prop;
_TxResizeBLTR = NLMISC::strlwr (_TxResizeBLTR);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_TB");
if (prop) _TxResizeTB = (const char *) prop;
_TxResizeTB = NLMISC::strlwr (_TxResizeTB);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_resize_LR");
if (prop) _TxResizeLR = (const char *) prop;
_TxResizeLR = NLMISC::strlwr (_TxResizeLR);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_rotate");
if (prop) _TxRotate = (const char *) prop;
_TxRotate = NLMISC::strlwr (_TxRotate);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_scale");
if (prop) _TxScale = (const char *) prop;
_TxScale = NLMISC::strlwr (_TxScale);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_colpick");
if (prop) _TxColPick = (const char *) prop;
_TxColPick = NLMISC::strlwr (_TxColPick);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_pan");
if (prop) _TxPan = (const char *) prop;
_TxPan = NLMISC::strlwr (_TxPan);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_can_pan");
if (prop) _TxCanPan = (const char *) prop;
_TxCanPan = NLMISC::strlwr (_TxCanPan);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_pan_r2");
if (prop) _TxPanR2 = (const char *) prop;
_TxPanR2 = NLMISC::strlwr (_TxPanR2);
prop = (char*) xmlGetProp (cur, (xmlChar*)"tx_can_pan_r2");
if (prop) _TxCanPanR2 = (const char *) prop;
_TxCanPanR2 = NLMISC::strlwr (_TxCanPanR2);
prop = (char*) xmlGetProp (cur, (xmlChar*)"color");
if (prop) _Color = convertColor(prop);
return true;
}
// --------------------------------------------------------------------------------------------------------------------
class CCtrlDepthEntry
{
public:
CCtrlBase *Ctrl;
uint Depth;
bool operator<(const CCtrlDepthEntry &o) const
{
// Inverse Test => descending order
return Depth>o.Depth;
}
};
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::draw ()
{
// Do not display the pointer if not visible.
if(!_PointerVisible)
return;
CViewRenderer &rVR = *CViewRenderer::getInstance();
if ( CWidgetManager::getInstance()->isIngame() )
if (!_StringCursor)
{
// Create the string cursor instance
std::vector<std::pair<std::string,std::string> > templateParams;
templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor"));
_StringCursor = CWidgetManager::parser->createGroupInstance("string_cursor", "", templateParams);
if (_StringCursor)
_StringCursor->setParentPos(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
templateParams.clear();
templateParams.push_back (std::pair<std::string,std::string>("id", "string_cursor_hardware"));
_StringCursorHardware = CWidgetManager::parser->createGroupInstance("string_cursor_hardware", "", templateParams);
if (_StringCursorHardware)
_StringCursorHardware->setParentPos(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
}
CRGBA col;
if(getModulateGlobalColor())
col.modulateFromColor (_Color, CWidgetManager::getInstance()->getGlobalColor());
else
col= _Color;
//col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColor().A+1))>>8);
col.A = _Color.A;
if (_LastHightLight != NULL)
{
_LastHightLight->setHighLighted(false,0);
_LastHightLight = NULL;
}
if ( CWidgetManager::getInstance()->getCapturePointerLeft() != NULL && CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
CCtrlMover *pCM = dynamic_cast<CCtrlMover*>( CWidgetManager::getInstance()->getCapturePointerLeft());
if ((pCM != NULL) && (pCM->canMove() == true))
{
CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
if (pGC != NULL && !pGC->isLocked())
{
pGC->setHighLighted(true, 255);
_LastHightLight = pGC;
}
}
}
if (_TxIdDefault == -2)
{
_TxIdDefault = rVR.getTextureIdFromName (_TxDefault);
_TxIdMoveWindow = rVR.getTextureIdFromName (_TxMoveWindow);
_TxIdResizeBRTL = rVR.getTextureIdFromName (_TxResizeBRTL);
_TxIdResizeBLTR = rVR.getTextureIdFromName (_TxResizeBLTR);
_TxIdResizeTB = rVR.getTextureIdFromName (_TxResizeTB);
_TxIdResizeLR = rVR.getTextureIdFromName (_TxResizeLR);
_TxIdRotate = rVR.getTextureIdFromName (_TxRotate);
_TxIdScale = rVR.getTextureIdFromName (_TxScale);
_TxIdColPick = rVR.getTextureIdFromName (_TxColPick);
_TxIdPan = rVR.getTextureIdFromName (_TxPan);
_TxIdCanPan = rVR.getTextureIdFromName (_TxCanPan);
_TxIdPanR2 = rVR.getTextureIdFromName (_TxPanR2);
_TxIdCanPanR2 = rVR.getTextureIdFromName (_TxCanPanR2);
}
const vector<CCtrlBase *> &rICL = CWidgetManager::getInstance()->getCtrlsUnderPointer ();
// Draw the captured cursor
CCtrlBase *pCB = CWidgetManager::getInstance()->getCapturePointerLeft();
if (pCB != NULL)
{
if (drawResizer(pCB,col)) return;
if (drawColorPicker(pCB,col)) return;
if (drawRotate(pCB,col)) return;
if (drawPan(pCB,col)) return;
if (drawCustom(pCB)) return;
drawCursor(_TxIdDefault, col, 0);
return;
}
const vector<CViewBase *> &vUP = CWidgetManager::getInstance()->getViewsUnderPointer ();
for(uint i=0;i<vUP.size();i++)
{
CViewLink *vLink = dynamic_cast<CViewLink*>(vUP[i]);
if (vLink != NULL)
{
string tooltip;
uint8 rot;
if (vLink->getMouseOverShape(tooltip, rot, col))
{
setString(ucstring(tooltip));
sint32 texId = rVR.getTextureIdFromName ("curs_pick.tga");
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
drawCursor(texId, col, 0);
}
else
{
drawCursor(texId, col, 0);
}
return;
}
}
}
// Draw if capture right
pCB = CWidgetManager::getInstance()->getCapturePointerRight();
if (pCB != NULL)
{
// Is it a 3d scene ?
if (drawScale(pCB,col)) return;
drawCursor(_TxIdDefault, col, 0);
return;
}
bool overModalWindow = false;
// is the cursor currently over a modal window ?
CInterfaceGroup *currModal = CWidgetManager::getInstance()->getModalWindow();
if (currModal)
{
sint32 xPos = _XReal + _OffsetX;
sint32 yPos = _YReal + _OffsetY;
overModalWindow = currModal->isIn(xPos, yPos, _WReal, _HReal);
}
// Draw the cursor type that are under the pointer
if (CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
// Sorts the controls according to their depth, to approximate as best the CapturePointerLeft algo.
// Especially important so that Resizers controls get the precedence over the move control (else could randomly bug like in chat group)
static vector<CCtrlDepthEntry> sortedControls;
sortedControls.clear();
for(uint i=0;i<rICL.size();i++)
{
CCtrlDepthEntry cde;
cde.Ctrl= rICL[i];
// NB: not the exact CInterfaceManager getDepth test here, but should work fine
cde.Depth= cde.Ctrl->getParentDepth() + cde.Ctrl->getDeltaDepth();
sortedControls.push_back(cde);
}
std::sort(sortedControls.begin(), sortedControls.end());
// Then draw the correct cursor
for (uint32 i = 0; i < sortedControls.size(); ++i)
{
CCtrlBase *pCB = sortedControls[i].Ctrl;
if (overModalWindow)
{
if (!pCB->isSonOf(currModal)) continue;
}
if (drawBrowse(pCB, col)) return;
if (drawResizer(pCB,col)) return;
if (drawColorPicker(pCB,col)) return;
if (drawLink (pCB, col)) return;
if (drawCustom(pCB)) return;
// test for move highlight
if (_LastHightLight == NULL)
{
CCtrlMover *pCM = dynamic_cast<CCtrlMover*>(pCB);
if ( (pCM != NULL) && (pCM->canMove() == true) )
{
CGroupContainer *pGC = dynamic_cast<CGroupContainer *>(pCM->getParent());
if (pGC != NULL && !pGC->isLocked())
{
if (CWidgetManager::getInstance()->getCapturePointerLeft() != pCM)
pGC->setHighLighted(true, 128);
else
pGC->setHighLighted(true, 255);
_LastHightLight = pGC;
break;
}
}
}
}
}
if (CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
if (rICL.empty())
{
const vector<CInterfaceGroup *> &rIGL = CWidgetManager::getInstance()->getGroupsUnderPointer ();
for (uint32 i = 0; i < rIGL.size(); ++i)
{
CInterfaceGroup *pG = rIGL[i];
if (overModalWindow)
{
if (!pG->isSonOf(currModal)) continue;
}
if (drawPan (pG, col)) return;
if (drawBrowse(pG, col)) return;
}
}
}
if (_StringMode && CWidgetManager::getInstance()->isMouseHandlingEnabled())
{
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
{
drawCursor(_TxIdDefault, col, 0);
}
}
}
else
{
// Draw the default cursor
drawCursor(_TxIdDefault, col, 0);
}
}
// --------------------------------------------------------------------------------------------------------------------
bool CViewPointer::drawCustom(CCtrlBase* pCB)
{
string texName;
uint8 rot;
NLMISC::CRGBA col;
if (pCB->getMouseOverShape(texName, rot, col))
{
if (texName[0] == '@')
{
const string &tooltipInfos = texName.substr(1);
string tooltip;
vector<string> tooltipInfosList;
splitString(tooltipInfos, "@", tooltipInfosList);
texName = tooltipInfosList[0];
tooltip = tooltipInfosList[1];
nlinfo(tooltip.c_str());
setString(ucstring(tooltip));
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 texId = rVR.getTextureIdFromName (texName);
CInterfaceGroup *stringCursor = hwMouse ? _StringCursorHardware : _StringCursor;
if (stringCursor)
{
stringCursor->setX(_PointerX);
stringCursor->setY(_PointerY);
stringCursor->updateCoords();
stringCursor->draw();
// if in hardware mode, force to draw the default cursor no matter what..
if ( hwMouse )
drawCursor(texId, col, 0);
}
else
{
drawCursor(texId, col, 0);
}
return true;
}
else
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 texId = rVR.getTextureIdFromName (texName);
drawCursor(texId, col, 0);
return true;
}
}
return false;
}
// +++ SET +++
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setStringMode (bool stringCursor)
{
_StringMode = stringCursor;
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setString (const ucstring &str, CInterfaceGroup *target)
{
if (target)
{
CInterfaceElement *element = target->getView ("fake_txt");
if (element)
{
CViewText *text = dynamic_cast<CViewText*> (element);
if (text)
text->setText(str);
}
element = target->getView ("real_txt");
if (element)
{
CViewText *text = dynamic_cast<CViewText*> (element);
if (text)
text->setText(str);
}
target->updateCoords();
target->updateCoords();
_ContextString = str;
}
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::setString (const ucstring &str)
{
if (_ContextString != str)
{
setString(str, _StringCursor);
setString(str, _StringCursorHardware);
}
}
// --------------------------------------------------------------------------------------------------------------------
void CViewPointer::drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 xPos = _XReal + _OffsetX;
sint32 yPos = _YReal + _OffsetY;
if ( !hwMouse )
{
rVR.draw11RotFlipBitmap (_RenderLayer, xPos, yPos, rot, false, texId, col);
}
else
{
// set new cursor for the hardware mouse
std::string name = rVR.getTextureNameFromId(texId);
rVR.getDriver()->setCursor(name, col, rot, (uint32) std::max(getX() - xPos, (sint32) 0), (uint32) std::max(getY() - yPos, (sint32) 0));
}
}

View file

@ -1,143 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef RZ_VIEW_POINTER_H
#define RZ_VIEW_POINTER_H
#include "nel/misc/types_nl.h"
#include "nel/misc/events.h"
#include "nel/gui/view_pointer_base.h"
namespace NLGUI
{
class CCtrlBase;
class CGroupContainer;
}
/**
* class describing the pointer
* \author Matthieu 'Trap' Besson
* \author Nevrax France
* \date 2002
*/
class CViewPointer : public CViewPointerBase
{
public:
DECLARE_UI_CLASS( CViewPointer )
CViewPointer( const TCtorParam &param );
virtual ~CViewPointer(){}
bool parse (xmlNodePtr cur,CInterfaceGroup * parentGroup);
void draw();
// Set cursor mode
void setStringMode (bool stringCursor);
bool getStringMode() const {return _StringMode;}
// Set cursor string
void setString (const ucstring &str);
// TEMP PATCH
void setCursor (const std::string &name)
{
_TxDefault = name;
_TxIdDefault = -2;
}
// TEMP PATCH
/// Show or hide the pointer. Please, use SetMouseMode (bool freelook) instead.
void show(bool s) {_PointerVisible = s;}
static void setHWMouse( bool hw ){ hwMouse = hw; }
private:
/// Drawing helpers
virtual bool drawResizer(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawRotate(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawScale(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawColorPicker(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawLink(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawBrowse(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawPan(CCtrlBase* pCB, NLMISC::CRGBA col){ return false; }
virtual bool drawCustom(CCtrlBase* pCB);
protected:
// Look of the cursor in different situation
std::string _TxDefault;
std::string _TxMoveWindow;
std::string _TxResizeBRTL;
std::string _TxResizeBLTR;
std::string _TxResizeTB;
std::string _TxResizeLR;
std::string _TxRotate;
std::string _TxScale;
std::string _TxColPick;
std::string _TxPan;
std::string _TxCanPan;
std::string _TxPanR2;
std::string _TxCanPanR2;
sint32 _TxIdDefault;
sint32 _TxIdMoveWindow;
sint32 _TxIdResizeBRTL;
sint32 _TxIdResizeBLTR;
sint32 _TxIdResizeTB;
sint32 _TxIdResizeLR;
sint32 _TxIdRotate;
sint32 _TxIdScale;
sint32 _TxIdColPick;
sint32 _TxIdPan;
sint32 _TxIdCanPan;
sint32 _TxIdPanR2;
sint32 _TxIdCanPanR2;
NLMISC::CRGBA _Color;
sint32 _OffsetX;
sint32 _OffsetY;
CGroupContainer *_LastHightLight;
// Cursor mode
bool _StringMode;
bool _ForceStringMode;
CInterfaceGroup *_StringCursor;
CInterfaceGroup *_StringCursorHardware;
ucstring _ContextString;
// draw current cursor with the given texture, or, if in hardware mode, change the hardware cursor shape
void drawCursor(sint32 texId, NLMISC::CRGBA col, uint8 rot);
private:
// set the string into frame for software or hardware version
void setString (const ucstring &str, CInterfaceGroup *target);
static bool hwMouse;
};
#endif // RZ_VIEW_POINTER_H
/* End of view_pointer.h */

View file

@ -2,7 +2,7 @@
#define VIEW_POINTER_RYZOM_H
#include "view_pointer.h"
#include "nel/gui/view_pointer.h"
class CViewPointerRyzom : public CViewPointer
{