Merged develop.

This commit is contained in:
dfighter1985 2014-09-27 00:08:06 +02:00
commit 3fbe51185f
7 changed files with 200 additions and 83 deletions

View file

@ -57,6 +57,7 @@ namespace NLGUI
CInterfaceElement* findFromShortId(const std::string &id);
/// Dynamic creation
virtual void addElement (CInterfaceElement *child, sint eltOrder = -1 );
virtual void addView (CViewBase *child , sint eltOrder = -1);
virtual void addCtrl (CCtrlBase *child, sint eltOrder = -1);
virtual void addGroup (CInterfaceGroup *child, sint eltOrder = -1);

View file

@ -1,32 +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 WIDGET_ADD_WATCHER
#define WIDGET_ADD_WATCHER
#include <string>
namespace NLGUI
{
class IWidgetAdditionWatcher
{
public:
virtual void widgetAdded( const std::string &name ) = 0;
};
}
#endif

View file

@ -75,6 +75,16 @@ namespace NLGUI
virtual void process() = 0;
};
// Interface for event handlers that can be called when widgets are added or moved
class IWidgetWatcher
{
public:
IWidgetWatcher(){}
virtual ~IWidgetWatcher(){}
virtual void onWidgetAdded( const std::string &name ) = 0;
virtual void onWidgetMoved( const std::string &oldid, const std::string &newid ) = 0;
};
/// Frame render times
struct SInterfaceTimes
{
@ -498,10 +508,12 @@ namespace NLGUI
void notifySelectionWatchers();
void registerSelectionWatcher( IEditorSelectionWatcher *watcher );
void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher );
void notifyAdditionWatchers( const std::string &widgetName );
void registerAdditionWatcher( IWidgetAdditionWatcher *watcher );
void unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher );
void onWidgetAdded( const std::string &id );
void onWidgetMoved( const std::string &oldid, const std::string &newid );
void registerWidgetWatcher( IWidgetWatcher *watcher );
void unregisterWidgetWatcher( IWidgetWatcher *watcher );
CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName );
@ -532,7 +544,7 @@ namespace NLGUI
NLMISC::CRefPtr< CViewBase > _CapturedView;
NLMISC::CRefPtr< CInterfaceElement > draggedElement;
NLMISC::CRefPtr< CInterfaceElement > draggedElement; // the element that we're currently dragging
bool startDragging();
void stopDragging();
@ -594,7 +606,7 @@ namespace NLGUI
std::vector< INewScreenSizeHandler* > newScreenSizeHandlers;
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
std::vector< IEditorSelectionWatcher* > selectionWatchers;
std::vector< IWidgetAdditionWatcher* > additionWatchers;
std::vector< IWidgetWatcher* > widgetWatchers;
std::string currentEditorSelection;

View file

@ -911,6 +911,31 @@ namespace NLGUI
}
}
// ------------------------------------------------------------------------------------------------
void CInterfaceGroup::addElement (CInterfaceElement *child, sint eltOrder /*= -1*/)
{
if (!child)
{
nlwarning("<CInterfaceGroup::addView> : tried to add a NULL view");
return;
}
if( child->isGroup() )
{
addGroup( static_cast< CInterfaceGroup* >( child ), eltOrder );
}
else
if( child->isCtrl() )
{
addCtrl( static_cast< CCtrlBase* >( child ), eltOrder );
}
else
if( child->isView() )
{
addView( static_cast< CViewBase* >( child ), eltOrder );
}
}
// ------------------------------------------------------------------------------------------------
void CInterfaceGroup::addView (CViewBase *child, sint eltOrder /*= -1*/)
{
@ -1312,6 +1337,11 @@ namespace NLGUI
for (ite = _EltOrder.begin() ; ite != _EltOrder.end(); ite++)
{
CViewBase *pVB = *ite;
if( pVB->getName() == "=MARKED=" )
{
nlinfo( "=MARKED=" );
}
if (pVB->getActive())
pVB->draw();
}

View file

@ -34,7 +34,6 @@
#include "nel/gui/interface_expr.h"
#include "nel/gui/reflect_register.h"
#include "nel/gui/editor_selection_watcher.h"
#include "nel/gui/widget_addition_watcher.h"
#include "nel/misc/events.h"
namespace NLGUI
@ -1036,7 +1035,7 @@ namespace NLGUI
setCapturePointerLeft(NULL);
setCapturePointerRight(NULL);
_CapturedView = NULL;
resetColorProps();
resetAlphaRolloverSpeedProps();
resetGlobalAlphasProps();
@ -2401,6 +2400,7 @@ namespace NLGUI
// This may happen when alt-tab has been used => the sheet is dragged but the left button is up
if (!CCtrlDraggable::getDraggedSheet())
{
// Take the top most control.
uint nMaxDepth = 0;
const std::vector< CCtrlBase* >& _CtrlsUnderPointer = getCtrlsUnderPointer();
@ -2630,8 +2630,11 @@ namespace NLGUI
else
if( draggedElement != NULL )
{
draggedElement->setXReal( newX );
draggedElement->setYReal( newY );
sint32 dx = newX - oldX;
sint32 dy = newY - oldY;
draggedElement->setXReal( draggedElement->getXReal() + dx );
draggedElement->setYReal( draggedElement->getYReal() + dy );
draggedElement->invalidateCoords();
}
}
@ -2659,13 +2662,33 @@ namespace NLGUI
e->setParent( NULL );
draggedElement = e;
return true;
}
void CWidgetManager::stopDragging()
{
draggedElement = NULL;
if( draggedElement != NULL )
{
CInterfaceGroup *g = getGroupUnder( draggedElement->getXReal(), draggedElement->getYReal() );
CInterfaceElement *e = draggedElement;
CInterfaceGroup *tw = getTopWindow();
if( g == NULL )
g = tw;
std::string oldid = e->getId();
e->setParent( g );
e->setIdRecurse( e->getShortId() );
e->setParentPos( g );
e->setParentSize( g );
g->addElement( e );
draggedElement = NULL;
onWidgetMoved( oldid, e->getId() );
}
}
// ------------------------------------------------------------------------------------------------
@ -3352,36 +3375,46 @@ namespace NLGUI
selectionWatchers.erase( itr );
}
void CWidgetManager::notifyAdditionWatchers( const std::string &widgetName )
void CWidgetManager::onWidgetAdded( const std::string &id )
{
std::vector< IWidgetAdditionWatcher* >::const_iterator itr = additionWatchers.begin();
while( itr != additionWatchers.end() )
std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
while( itr != widgetWatchers.end() )
{
(*itr)->widgetAdded( widgetName );
(*itr)->onWidgetAdded( id );
++itr;
}
}
void CWidgetManager::registerAdditionWatcher( IWidgetAdditionWatcher *watcher )
void CWidgetManager::onWidgetMoved( const std::string &oldid, const std::string &newid )
{
std::vector< IWidgetAdditionWatcher* >::const_iterator itr
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher );
// already exists
if( itr != additionWatchers.end() )
return;
additionWatchers.push_back( watcher );
std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
while( itr != widgetWatchers.end() )
{
(*itr)->onWidgetMoved( oldid, newid );
++itr;
}
}
void CWidgetManager::unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher )
void CWidgetManager::registerWidgetWatcher( IWidgetWatcher *watcher )
{
std::vector< IWidgetAdditionWatcher* >::iterator itr
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher );
// doesn't exist
if( itr == additionWatchers.end() )
std::vector< IWidgetWatcher* >::const_iterator itr
= std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// already exists
if( itr != widgetWatchers.end() )
return;
additionWatchers.erase( itr );
widgetWatchers.push_back( watcher );
}
void CWidgetManager::unregisterWidgetWatcher( IWidgetWatcher *watcher )
{
std::vector< IWidgetWatcher* >::iterator itr
= std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// doesn't exist
if( itr == widgetWatchers.end() )
return;
widgetWatchers.erase( itr );
}
CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName )
@ -3414,7 +3447,7 @@ namespace NLGUI
else
g->addView( v );
notifyAdditionWatchers( v->getId() );
onWidgetAdded( v->getId() );
return v;
}

View file

@ -18,7 +18,6 @@
#include "widget_hierarchy.h"
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/widget_addition_watcher.h"
namespace
{
@ -76,18 +75,24 @@ namespace
GUIEditor::WidgetHierarchy *h;
};
class CWidgetAdditionWatcher : public IWidgetAdditionWatcher
class CWidgetWatcher : public CWidgetManager::IWidgetWatcher
{
public:
CWidgetAdditionWatcher(){ h = NULL; }
~CWidgetAdditionWatcher(){}
CWidgetWatcher(){ h = NULL; }
~CWidgetWatcher(){}
void widgetAdded( const std::string &name )
void onWidgetAdded( const std::string &name )
{
if( h != NULL )
h->onWidgetAdded( name );
}
void onWidgetMoved( const std::string &oldid, const std::string &newid )
{
if( h != NULL )
h->onWidgetMoved( oldid, newid );
}
void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; }
private:
@ -95,7 +100,7 @@ namespace
};
CWidgetDeletionWatcher deletionWatcher;
CWidgetAdditionWatcher additionWatcher;
CWidgetWatcher widgetwatcher;
}
namespace GUIEditor
@ -107,7 +112,7 @@ namespace GUIEditor
connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
deletionWatcher.setWidgetHierarchy( this );
additionWatcher.setWidgetHierarchy( this );
widgetwatcher.setWidgetHierarchy( this );
}
WidgetHierarchy::~WidgetHierarchy()
@ -117,7 +122,7 @@ namespace GUIEditor
void WidgetHierarchy::clearHierarchy()
{
CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->unregisterAdditionWatcher( &additionWatcher );
CWidgetManager::getInstance()->unregisterWidgetWatcher( &widgetwatcher );
widgetHT->clear();
widgetHierarchyMap.clear();
}
@ -126,7 +131,7 @@ namespace GUIEditor
{
clearHierarchy();
CInterfaceElement::registerDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->registerAdditionWatcher( &additionWatcher );
CWidgetManager::getInstance()->registerWidgetWatcher( &widgetwatcher );
CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
if( mg != NULL )
@ -177,6 +182,27 @@ namespace GUIEditor
}
}
QTreeWidgetItem* WidgetHierarchy::findItem( const std::string &id )
{
std::map< std::string, QTreeWidgetItem* >::iterator itr
= widgetHierarchyMap.find( id );
if( itr == widgetHierarchyMap.end() )
return NULL;
else
return itr->second;
}
QTreeWidgetItem* WidgetHierarchy::findParent( const std::string &id )
{
// Get the parent's name
std::string::size_type p = id.find_last_of( ':' );
if( p == std::string::npos )
return NULL;
std::string parentId = id.substr( 0, p );
return findItem( parentId );
}
void WidgetHierarchy::onWidgetDeleted( const std::string &id )
{
std::map< std::string, QTreeWidgetItem* >::iterator itr
@ -231,6 +257,54 @@ namespace GUIEditor
widgetHierarchyMap[ id ] = item;
}
void WidgetHierarchy::onWidgetMoved( const std::string &oldid, const std::string &newid )
{
QTreeWidgetItem *newParent = NULL;
QTreeWidgetItem *item = NULL;
QString id;
newParent = findParent( newid );
item = findItem( oldid );
if( ( newParent == NULL ) || ( item == NULL ) )
return;
// Remove old item
QTreeWidgetItem *p = item->parent();
if( p != NULL )
p->setExpanded( false );
id = item->data( 0, Qt::DisplayRole ).toString();
delete item;
item = NULL;
// Remove reference to old item
widgetHierarchyMap.erase( oldid );
// Add new item
item = new QTreeWidgetItem();
item->setData( 0, Qt::DisplayRole, id );
item->setSelected( true );
newParent->addChild( item );
selectItem( item );
}
void WidgetHierarchy::selectItem( QTreeWidgetItem *item )
{
widgetHT->collapseAll();
QTreeWidgetItem *currItem = item;
while( currItem != NULL )
{
currItem->setExpanded( true );
currItem = currItem->parent();
}
widgetHT->setCurrentItem( item );
item->setSelected( true );
}
void WidgetHierarchy::getCurrentGroup( QString &g )
{
std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection();
@ -288,18 +362,11 @@ namespace GUIEditor
if( widgetHT->currentItem() != NULL )
widgetHT->currentItem()->setSelected( false );
// expand the tree items, so that we can see the selected item
QTreeWidgetItem *item = itr->second;
QTreeWidgetItem *currItem = item;
while( currItem != NULL )
{
currItem->setExpanded( true );
currItem = currItem->parent();
}
widgetHT->collapseAll();
// select the current item
item->setSelected( true );
widgetHT->setCurrentItem( item );
QTreeWidgetItem *item = itr->second;
selectItem( item );
currentSelection = newSelection;
}
@ -307,6 +374,8 @@ namespace GUIEditor
{
if( item->parent() == NULL )
return;
selectItem( item );
std::string n = item->text( 0 ).toUtf8().constData();
currentSelection = makeFullName( item, n );

View file

@ -44,11 +44,15 @@ namespace GUIEditor
void onWidgetDeleted( const std::string &id );
void onWidgetAdded( const std::string &id );
void onWidgetMoved( const std::string &oldid, const std::string &newid );
void getCurrentGroup( QString &g );
private:
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
QTreeWidgetItem* findItem( const std::string &id );
QTreeWidgetItem* findParent( const std::string &id );
void selectItem( QTreeWidgetItem *item );
public Q_SLOTS:
void onGUILoaded();