From d4d4041895991b8e36ef0b7cdae7c9f390d2915e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 23 Jun 2012 21:24:48 +0200 Subject: [PATCH] CHANGED: #1471 CGroupScrollText is now part of the NELGUI library and is under the NLGUI namespace. --HG-- branch : gui-refactoring --- code/nel/include/nel/gui/group_scrolltext.h | 86 +++++++ code/nel/src/gui/group_scrolltext.cpp | 242 ++++++++++++++++++ .../client/src/interface_v3/group_html.h | 2 +- .../src/interface_v3/group_scrolltext.cpp | 237 ----------------- .../src/interface_v3/group_scrolltext.h | 86 ------- .../src/interface_v3/interface_parser.cpp | 2 +- 6 files changed, 330 insertions(+), 325 deletions(-) create mode 100644 code/nel/include/nel/gui/group_scrolltext.h create mode 100644 code/nel/src/gui/group_scrolltext.cpp delete mode 100644 code/ryzom/client/src/interface_v3/group_scrolltext.cpp delete mode 100644 code/ryzom/client/src/interface_v3/group_scrolltext.h diff --git a/code/nel/include/nel/gui/group_scrolltext.h b/code/nel/include/nel/gui/group_scrolltext.h new file mode 100644 index 000000000..9806d61f4 --- /dev/null +++ b/code/nel/include/nel/gui/group_scrolltext.h @@ -0,0 +1,86 @@ +// Ryzom - MMORPG Framework +// 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 . + + + + +#ifndef CL_GROUP_SCROLLTEXT_H +#define CL_GROUP_SCROLLTEXT_H + +#include "nel/misc/types_nl.h" +#include "nel/gui/interface_group.h" + +namespace NLGUI +{ + class CCtrlBaseButton; + class CCtrlScroll; + class CGroupList; + + // Can be used to build a chat window or anything that displays sequences of strings + /** + * Widget to have a resizable scrolltext and its scrollbar + * \author Nicolas Vizerie + * \author Nevrax France + * \date 2002 + */ + class CGroupScrollText : public CInterfaceGroup + { + public: + /// Constructor + CGroupScrollText(const TCtorParam ¶m); + ~CGroupScrollText(); + + /// CInterfaceGroup Interface + virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); + virtual void updateCoords (); + virtual void checkCoords (); + virtual void draw (); + virtual void clearViews (); + virtual bool handleEvent (const NLGUI::CEventDescriptor &eventDesc); + + // get the list associated to this group + CGroupList *getList() const { return _List; } + + // Get the scroll bar + CCtrlScroll *getScrollBar() const { return _ScrollBar; } + + // from CCtrlBase + virtual void elementCaptured(CCtrlBase *capturedElement); + + + REFLECT_EXPORT_START(CGroupScrollText, CInterfaceGroup) + REFLECT_EXPORT_END + + private: + CGroupList *_List; + CCtrlScroll *_ScrollBar; + CCtrlBaseButton *_ButtonAdd; + CCtrlBaseButton *_ButtonSub; + bool _Settuped; + bool _InvertScrollBar; + sint32 _ListHeight; + protected: + void setup(); + void updateScrollBar(); + public: + // private use for action handlers + sint32 _StartHeight; + sint64 _EllapsedTime; + }; + +} + +#endif diff --git a/code/nel/src/gui/group_scrolltext.cpp b/code/nel/src/gui/group_scrolltext.cpp new file mode 100644 index 000000000..b2e603bf8 --- /dev/null +++ b/code/nel/src/gui/group_scrolltext.cpp @@ -0,0 +1,242 @@ +// Ryzom - MMORPG Framework +// 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 . + +#include "nel/gui/group_scrolltext.h" +#include "nel/gui/group_list.h" +#include "nel/gui/view_text.h" +#include "nel/gui/ctrl_scroll.h" +#include "nel/gui/ctrl_button.h" +#include "nel/gui/action_handler.h" +#include "nel/misc/i18n.h" +#include "nel/gui/widget_manager.h" + +NLMISC_REGISTER_OBJECT(CViewBase, CGroupScrollText, std::string, "scroll_text"); + +namespace NLGUI +{ + + //======================================================================== + CGroupScrollText::CGroupScrollText(const TCtorParam ¶m) : + CInterfaceGroup(param), + _List(NULL), + _ScrollBar(NULL), + _ButtonAdd(NULL), + _ButtonSub(NULL), + _Settuped(false), + _InvertScrollBar(true), + _ListHeight(0), + _StartHeight(0), + _EllapsedTime(0) + { + _IsGroupScrollText = true; + } + + //======================================================================== + CGroupScrollText::~CGroupScrollText() + { + } + + //======================================================================== + bool CGroupScrollText::parse(xmlNodePtr cur,CInterfaceGroup *parentGroup) + { + if(!CInterfaceGroup::parse(cur, parentGroup)) + return false; + CXMLAutoPtr ptr; + + // invert scroll bar? + ptr = xmlGetProp (cur, (xmlChar*)"invert_scroll_bar"); + if(ptr) _InvertScrollBar= convertBool(ptr); + + return true; + } + + //======================================================================== + void CGroupScrollText::updateCoords() + { + CInterfaceGroup::updateCoords(); + if (!_Settuped) setup(); + updateScrollBar(); + // re-update of scrollbar + if(_ScrollBar) + _ScrollBar->updateCoords(); + } + + //======================================================================== + void CGroupScrollText::updateScrollBar() + { + if (_List && _ScrollBar) + { + if (_List->getHReal() < _List->getMaxHReal()) + { + _ScrollBar->setActive(false); + } + else + { + _ScrollBar->setActive(true); + } + } + } + + //======================================================================== + void CGroupScrollText::checkCoords () + { + // update scrollbar if necessary + if (_List) + { + if (_List->getH() != _ListHeight) // see if the scrollbar should be updated + { + invalidateCoords(); + _ListHeight = _List->getH(); + } + } + CInterfaceGroup::checkCoords(); + } + + //======================================================================== + void CGroupScrollText::draw() + { + CInterfaceGroup::draw(); + } + + //======================================================================== + void CGroupScrollText::clearViews() + { + CInterfaceGroup::clearViews(); + } + + //======================================================================== + bool CGroupScrollText::handleEvent(const NLGUI::CEventDescriptor &event) + { + if (event.getType() == NLGUI::CEventDescriptor::mouse) + { + const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event; + // + if (_List && _ScrollBar) + { + if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel) + { + if (isIn(eventDesc.getX(), eventDesc.getY())) + { + sint32 h = _List->getMaxHReal() / 2; + if (h == 0) h = 1; + _ScrollBar->moveTargetY(- eventDesc.getWheel() * h); + return true; + } + } + } + } + if (CInterfaceGroup::handleEvent(event)) return true; + return false; + } + + //======================================================================== + void CGroupScrollText::setup() + { + // bind to the controls + _ScrollBar = dynamic_cast(CInterfaceGroup::getCtrl("scroll_bar")); + _ButtonAdd = dynamic_cast(CInterfaceGroup::getCtrl("button_add")); + _ButtonSub = dynamic_cast(CInterfaceGroup::getCtrl("button_sub")); + _List = dynamic_cast(CInterfaceGroup::getGroup("text_list")); + + if(_ScrollBar == NULL) + nlwarning(" scroll bar 'scroll_bar' missing or bad type.(%s)",this->_Id.c_str()); + // Add and sub button are not required + /* + if(buttonAdd == NULL) + nlwarning("Interface: CGroupScrollText: button 'button_add' missing or bad type"); + if(buttonSub == NULL) + nlwarning("Interface: CGroupScrollText: button 'button_sub' missing or bad type"); + */ + if(_List == NULL) + nlwarning(" group list 'text_list' missing or bad type"); + + // actions + if (_ButtonAdd) _ButtonAdd->setActionOnClockTick("gst_add"); + if (_ButtonSub) _ButtonSub->setActionOnClockTick("gst_sub"); + + // bind the scrollbar to the list + if (_ScrollBar) + { + _ScrollBar->setTarget(_List); + //_ScrollBar->setInverted(_InvertScrollBar); + } + _Settuped = true; + } + + //======================================================================== + void CGroupScrollText::elementCaptured(CCtrlBase *capturedElement) + { + if (capturedElement == _ButtonAdd || capturedElement == _ButtonSub) + { + // reset the counters for increase + _EllapsedTime = 0; + _StartHeight = getH(); + } + } + + // *************************************************************************** + // *************************************************************************** + // Actions Handlers + // *************************************************************************** + // *************************************************************************** + + + // *************************************************************************** + class CSTUp : public IActionHandler + { + public: + virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + { + const CWidgetManager::SInterfaceTimes × = CWidgetManager::getInstance()->getInterfaceTimes(); + + CGroupScrollText *pST = dynamic_cast(pCaller->getParent()); + if (pST == NULL) return; + if (pST->getList() == NULL) return; + // get the font height from the text template of the list + const CViewText *vt = pST->getList()->getTextTemplatePtr(); + if (!vt) return; + pST->_EllapsedTime += times.frameDiffMs; + // pST->setH(std::min((sint32) pST->getMaxHeight(), (sint32) (pST->_StartHeight + pST->_EllapsedTime / 9))); + pST->setH((sint32) (pST->_StartHeight + pST->_EllapsedTime / 9)); + pST->invalidateCoords(); + } + }; + REGISTER_ACTION_HANDLER (CSTUp, "gst_add"); + + // *************************************************************************** + class CSTDown : public IActionHandler + { + public: + virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) + { + const CWidgetManager::SInterfaceTimes × = CWidgetManager::getInstance()->getInterfaceTimes(); + + CGroupScrollText *pST = dynamic_cast(pCaller->getParent()); + if (pST == NULL) return; + if (pST->getList() == NULL) return; + // get the font height from the text template of the list + const CViewText *vt = pST->getList()->getTextTemplatePtr(); + if (!vt) return; + pST->_EllapsedTime += times.frameDiffMs; + // pST->setH(std::max((sint32) pST->getMinHeight(), (sint32) (pST->_StartHeight - pST->_EllapsedTime / 9))); + pST->setH((sint32) (pST->_StartHeight - pST->_EllapsedTime / 9)); + pST->invalidateCoords(); + } + }; + REGISTER_ACTION_HANDLER (CSTDown, "gst_sub"); + +} + diff --git a/code/ryzom/client/src/interface_v3/group_html.h b/code/ryzom/client/src/interface_v3/group_html.h index a0a4b7d7d..9f03ab050 100644 --- a/code/ryzom/client/src/interface_v3/group_html.h +++ b/code/ryzom/client/src/interface_v3/group_html.h @@ -25,7 +25,7 @@ #include "nel/misc/types_nl.h" #include "nel/gui/interface_group.h" -#include "group_scrolltext.h" +#include "nel/gui/group_scrolltext.h" #include "nel/gui/group_tree.h" #include "nel/gui/ctrl_button.h" #include "group_table.h" diff --git a/code/ryzom/client/src/interface_v3/group_scrolltext.cpp b/code/ryzom/client/src/interface_v3/group_scrolltext.cpp deleted file mode 100644 index 0c4ec9e8b..000000000 --- a/code/ryzom/client/src/interface_v3/group_scrolltext.cpp +++ /dev/null @@ -1,237 +0,0 @@ -// Ryzom - MMORPG Framework -// 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 . - -#include "group_scrolltext.h" -#include "nel/gui/group_list.h" -#include "nel/gui/view_text.h" -#include "nel/gui/ctrl_scroll.h" -#include "nel/gui/ctrl_button.h" -#include "nel/gui/action_handler.h" -#include "nel/misc/i18n.h" -#include "nel/gui/widget_manager.h" - -NLMISC_REGISTER_OBJECT(CViewBase, CGroupScrollText, std::string, "scroll_text"); - -//======================================================================== -CGroupScrollText::CGroupScrollText(const TCtorParam ¶m) : - CInterfaceGroup(param), - _List(NULL), - _ScrollBar(NULL), - _ButtonAdd(NULL), - _ButtonSub(NULL), - _Settuped(false), - _InvertScrollBar(true), - _ListHeight(0), - _StartHeight(0), - _EllapsedTime(0) -{ - _IsGroupScrollText = true; -} - -//======================================================================== -CGroupScrollText::~CGroupScrollText() -{ -} - -//======================================================================== -bool CGroupScrollText::parse(xmlNodePtr cur,CInterfaceGroup *parentGroup) -{ - if(!CInterfaceGroup::parse(cur, parentGroup)) - return false; - CXMLAutoPtr ptr; - - // invert scroll bar? - ptr = xmlGetProp (cur, (xmlChar*)"invert_scroll_bar"); - if(ptr) _InvertScrollBar= convertBool(ptr); - - return true; -} - -//======================================================================== -void CGroupScrollText::updateCoords() -{ - CInterfaceGroup::updateCoords(); - if (!_Settuped) setup(); - updateScrollBar(); - // re-update of scrollbar - if(_ScrollBar) - _ScrollBar->updateCoords(); -} - -//======================================================================== -void CGroupScrollText::updateScrollBar() -{ - if (_List && _ScrollBar) - { - if (_List->getHReal() < _List->getMaxHReal()) - { - _ScrollBar->setActive(false); - } - else - { - _ScrollBar->setActive(true); - } - } -} - -//======================================================================== -void CGroupScrollText::checkCoords () -{ - // update scrollbar if necessary - if (_List) - { - if (_List->getH() != _ListHeight) // see if the scrollbar should be updated - { - invalidateCoords(); - _ListHeight = _List->getH(); - } - } - CInterfaceGroup::checkCoords(); -} - -//======================================================================== -void CGroupScrollText::draw() -{ - CInterfaceGroup::draw(); -} - -//======================================================================== -void CGroupScrollText::clearViews() -{ - CInterfaceGroup::clearViews(); -} - -//======================================================================== -bool CGroupScrollText::handleEvent(const NLGUI::CEventDescriptor &event) -{ - if (event.getType() == NLGUI::CEventDescriptor::mouse) - { - const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event; - // - if (_List && _ScrollBar) - { - if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousewheel) - { - if (isIn(eventDesc.getX(), eventDesc.getY())) - { - sint32 h = _List->getMaxHReal() / 2; - if (h == 0) h = 1; - _ScrollBar->moveTargetY(- eventDesc.getWheel() * h); - return true; - } - } - } - } - if (CInterfaceGroup::handleEvent(event)) return true; - return false; -} - -//======================================================================== -void CGroupScrollText::setup() -{ - // bind to the controls - _ScrollBar = dynamic_cast(CInterfaceGroup::getCtrl("scroll_bar")); - _ButtonAdd = dynamic_cast(CInterfaceGroup::getCtrl("button_add")); - _ButtonSub = dynamic_cast(CInterfaceGroup::getCtrl("button_sub")); - _List = dynamic_cast(CInterfaceGroup::getGroup("text_list")); - - if(_ScrollBar == NULL) - nlwarning(" scroll bar 'scroll_bar' missing or bad type.(%s)",this->_Id.c_str()); - // Add and sub button are not required - /* - if(buttonAdd == NULL) - nlwarning("Interface: CGroupScrollText: button 'button_add' missing or bad type"); - if(buttonSub == NULL) - nlwarning("Interface: CGroupScrollText: button 'button_sub' missing or bad type"); - */ - if(_List == NULL) - nlwarning(" group list 'text_list' missing or bad type"); - - // actions - if (_ButtonAdd) _ButtonAdd->setActionOnClockTick("gst_add"); - if (_ButtonSub) _ButtonSub->setActionOnClockTick("gst_sub"); - - // bind the scrollbar to the list - if (_ScrollBar) - { - _ScrollBar->setTarget(_List); - //_ScrollBar->setInverted(_InvertScrollBar); - } - _Settuped = true; -} - -//======================================================================== -void CGroupScrollText::elementCaptured(CCtrlBase *capturedElement) -{ - if (capturedElement == _ButtonAdd || capturedElement == _ButtonSub) - { - // reset the counters for increase - _EllapsedTime = 0; - _StartHeight = getH(); - } -} - -// *************************************************************************** -// *************************************************************************** -// Actions Handlers -// *************************************************************************** -// *************************************************************************** - - -// *************************************************************************** -class CSTUp : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) - { - const CWidgetManager::SInterfaceTimes × = CWidgetManager::getInstance()->getInterfaceTimes(); - - CGroupScrollText *pST = dynamic_cast(pCaller->getParent()); - if (pST == NULL) return; - if (pST->getList() == NULL) return; - // get the font height from the text template of the list - const CViewText *vt = pST->getList()->getTextTemplatePtr(); - if (!vt) return; - pST->_EllapsedTime += times.frameDiffMs; -// pST->setH(std::min((sint32) pST->getMaxHeight(), (sint32) (pST->_StartHeight + pST->_EllapsedTime / 9))); - pST->setH((sint32) (pST->_StartHeight + pST->_EllapsedTime / 9)); - pST->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER (CSTUp, "gst_add"); - -// *************************************************************************** -class CSTDown : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */) - { - const CWidgetManager::SInterfaceTimes × = CWidgetManager::getInstance()->getInterfaceTimes(); - - CGroupScrollText *pST = dynamic_cast(pCaller->getParent()); - if (pST == NULL) return; - if (pST->getList() == NULL) return; - // get the font height from the text template of the list - const CViewText *vt = pST->getList()->getTextTemplatePtr(); - if (!vt) return; - pST->_EllapsedTime += times.frameDiffMs; -// pST->setH(std::max((sint32) pST->getMinHeight(), (sint32) (pST->_StartHeight - pST->_EllapsedTime / 9))); - pST->setH((sint32) (pST->_StartHeight - pST->_EllapsedTime / 9)); - pST->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER (CSTDown, "gst_sub"); - diff --git a/code/ryzom/client/src/interface_v3/group_scrolltext.h b/code/ryzom/client/src/interface_v3/group_scrolltext.h deleted file mode 100644 index 88fc2c6cb..000000000 --- a/code/ryzom/client/src/interface_v3/group_scrolltext.h +++ /dev/null @@ -1,86 +0,0 @@ -// Ryzom - MMORPG Framework -// 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 . - - - - -#ifndef CL_GROUP_SCROLLTEXT_H -#define CL_GROUP_SCROLLTEXT_H - -#include "nel/misc/types_nl.h" -#include "nel/gui/interface_group.h" - -namespace NLGUI -{ - class CCtrlBaseButton; - class CCtrlScroll; - class CGroupList; -} - -// Can be used to build a chat window or anything that displays sequences of strings -/** - * Widget to have a resizable scrolltext and its scrollbar - * \author Nicolas Vizerie - * \author Nevrax France - * \date 2002 - */ -class CGroupScrollText : public CInterfaceGroup -{ -public: - /// Constructor - CGroupScrollText(const TCtorParam ¶m); - ~CGroupScrollText(); - - /// CInterfaceGroup Interface - virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); - virtual void updateCoords (); - virtual void checkCoords (); - virtual void draw (); - virtual void clearViews (); - virtual bool handleEvent (const NLGUI::CEventDescriptor &eventDesc); - - // get the list associated to this group - CGroupList *getList() const { return _List; } - - // Get the scroll bar - CCtrlScroll *getScrollBar() const { return _ScrollBar; } - - // from CCtrlBase - virtual void elementCaptured(CCtrlBase *capturedElement); - - - REFLECT_EXPORT_START(CGroupScrollText, CInterfaceGroup) - REFLECT_EXPORT_END - -private: - CGroupList *_List; - CCtrlScroll *_ScrollBar; - CCtrlBaseButton *_ButtonAdd; - CCtrlBaseButton *_ButtonSub; - bool _Settuped; - bool _InvertScrollBar; - sint32 _ListHeight; -protected: - void setup(); - void updateScrollBar(); -public: - // private use for action handlers - sint32 _StartHeight; - sint64 _EllapsedTime; -}; - - -#endif diff --git a/code/ryzom/client/src/interface_v3/interface_parser.cpp b/code/ryzom/client/src/interface_v3/interface_parser.cpp index 62bc9c0a6..c896d1538 100644 --- a/code/ryzom/client/src/interface_v3/interface_parser.cpp +++ b/code/ryzom/client/src/interface_v3/interface_parser.cpp @@ -69,7 +69,7 @@ #include "nel/gui/group_tree.h" #include "group_menu.h" #include "nel/gui/group_container.h" -#include "group_scrolltext.h" +#include "nel/gui/group_scrolltext.h" #include "nel/gui/group_editbox.h" #include "group_skills.h" #include "group_html_forum.h"