CHANGED: #1471 CCtrlColPick is now in the NELGUI library and is under NLGUI namespace.

This commit is contained in:
dfighter1985 2012-06-16 03:39:23 +02:00
parent a248ec47fb
commit db38a00135
7 changed files with 317 additions and 307 deletions

View file

@ -0,0 +1,106 @@
// 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_CTRL_COL_PICK_H
#define RZ_CTRL_COL_PICK_H
#include "nel/misc/types_nl.h"
#include "nel/gui/ctrl_base.h"
namespace NLGUI
{
/**
* Class handling a Color Picker
* \author Matthieu 'TrapII' Besson
* \author Nevrax France
* \date 2003
*/
class CCtrlColPick : public CCtrlBase
{
public:
CCtrlColPick(const TCtorParam &param);
~CCtrlColPick();
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void updateCoords();
virtual void draw();
virtual bool handleEvent (const NLGUI::CEventDescriptor &event);
sint32 getColorR () const { return _ColorSelect.R; }
sint32 getColorG () const { return _ColorSelect.G; }
sint32 getColorB () const { return _ColorSelect.B; }
sint32 getColorA () const { return _ColorSelect.A; }
void setColorR (sint32 r) { _ColorSelect.R = (uint8)r; }
void setColorG (sint32 g) { _ColorSelect.G = (uint8)g; }
void setColorB (sint32 b) { _ColorSelect.B = (uint8)b; }
void setColorA (sint32 a) { _ColorSelect.A = (uint8)a; }
std::string getColor () const; // Get Color Selected
void setColor (const std::string &col); // Set Color Selected
std::string getColorOver () const; // Get Color Over
void setColorOver (const std::string &col); // Set Color Over
REFLECT_EXPORT_START(CCtrlColPick, CCtrlBase)
REFLECT_SINT32("r", getColorR, setColorR);
REFLECT_SINT32("g", getColorG, setColorG);
REFLECT_SINT32("b", getColorB, setColorB);
REFLECT_SINT32("a", getColorA, setColorA);
REFLECT_STRING("color", getColor, setColor);
REFLECT_STRING("color_over", getColorOver, setColorOver);
REFLECT_EXPORT_END
protected:
void selectColor (sint32 x, sint32 y);
NLMISC::CRGBA getColor (sint32 x, sint32 y);
protected:
bool _MouseDown;
sint32 _Texture;
NLMISC::CRGBA _ColorSelect; // Last Color selected
NLMISC::CRGBA _ColorOver; // Color Under Mouse Pointer
std::string _AHOnChange;
std::string _AHOnChangeParams;
CInterfaceProperty _ColSelR;
CInterfaceProperty _ColSelG;
CInterfaceProperty _ColSelB;
CInterfaceProperty _ColSelA;
};
}
#endif // RZ_CTRL_COL_PICK_H
/* End of ctrl_col_pick.h */

View file

@ -0,0 +1,208 @@
// 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/ctrl_col_pick.h"
#include "nel/misc/xml_auto_ptr.h"
#include "nel/gui/view_renderer.h"
#include "nel/gui/action_handler.h"
#include "nel/gui/widget_manager.h"
#include "nel/gui/interface_group.h"
using namespace NLMISC;
using namespace std;
NLMISC_REGISTER_OBJECT(CViewBase, CCtrlColPick, std::string, "colpick");
namespace NLGUI
{
// ------------------------------------------------------------------------------------------------
CCtrlColPick::CCtrlColPick(const TCtorParam &param)
:CCtrlBase(param)
{
_MouseDown = false;
_Texture = -2;
}
// ------------------------------------------------------------------------------------------------
CCtrlColPick::~CCtrlColPick()
{
// Texture has been created ?
if (_Texture>=0)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.deleteTexture (_Texture);
}
}
// ------------------------------------------------------------------------------------------------
bool CCtrlColPick::parse(xmlNodePtr node, CInterfaceGroup * parentGroup)
{
if (!CCtrlBase::parse(node, parentGroup))
return false;
CXMLAutoPtr prop;
// Read textures
prop = (char*) xmlGetProp( node, (xmlChar*)"texture" );
CViewRenderer &rVR = *CViewRenderer::getInstance();
if(prop)
{
string sTmp = NLMISC::strlwr((const char*)prop);
_Texture = rVR.createTexture (sTmp, 0, 0, 256, 64, false, false);
}
prop = (char*) xmlGetProp( node, (xmlChar*)"onchange" );
if (prop) _AHOnChange = NLMISC::strlwr(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"onchange_params" );
if (prop) _AHOnChangeParams = string((const char*)prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolr" );
if (prop) _ColSelR.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolg" );
if (prop) _ColSelG.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolb" );
if (prop) _ColSelB.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcola" );
if (prop) _ColSelA.link(prop);
return true;
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::updateCoords()
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 txw, txh;
rVR.getTextureSizeFromId (_Texture, txw, txh);
_W = txw;
_H = txh;
CCtrlBase::updateCoords();
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::draw()
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
CRGBA col = CRGBA(255,255,255,(uint8)CWidgetManager::getInstance()->getGlobalColor().A);
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal,
_WReal, _HReal,
0, false,
_Texture,
col );
}
// ------------------------------------------------------------------------------------------------
bool CCtrlColPick::handleEvent (const NLGUI::CEventDescriptor &event)
{
if (CCtrlBase::handleEvent(event)) return true;
if (!_Active)
return false;
if (event.getType() == NLGUI::CEventDescriptor::mouse)
{
const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event;
if ((CWidgetManager::getInstance()->getCapturePointerLeft() != this) &&
(!((eventDesc.getX() >= _XReal) &&
(eventDesc.getX() < (_XReal + _WReal))&&
(eventDesc.getY() > _YReal) &&
(eventDesc.getY() <= (_YReal+ _HReal)))))
return false;
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown)
{
_MouseDown = true;
selectColor(eventDesc.getX()-_XReal, eventDesc.getY()-_YReal);
return true;
}
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup)
{
_MouseDown = false;
return true;
}
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousemove)
{
if (_MouseDown)
{
selectColor(eventDesc.getX()-_XReal, eventDesc.getY()-_YReal);
}
return true;
}
}
return false;
}
// ------------------------------------------------------------------------------------------------
string CCtrlColPick::getColor () const
{
return NLMISC::toString(_ColorSelect.R) + " " + NLMISC::toString(_ColorSelect.G) + " " + NLMISC::toString(_ColorSelect.B) + " " + NLMISC::toString(_ColorSelect.A);
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::setColor (const string &col)
{
_ColorSelect = convertColor (col.c_str());
}
// ------------------------------------------------------------------------------------------------
string CCtrlColPick::getColorOver () const
{
return NLMISC::toString(_ColorOver.R) + " " + NLMISC::toString(_ColorOver.G) + " " + NLMISC::toString(_ColorOver.B) + " " + NLMISC::toString(_ColorOver.A);
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::setColorOver (const string &col)
{
_ColorOver = convertColor (col.c_str());
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::selectColor (sint32 x, sint32 y)
{
_ColorSelect = getColor (x, y);
if (_ColSelR.getNodePtr() != NULL)
_ColSelR.setSInt32(_ColorSelect.R);
if (_ColSelG.getNodePtr() != NULL)
_ColSelG.setSInt32(_ColorSelect.G);
if (_ColSelB.getNodePtr() != NULL)
_ColSelB.setSInt32(_ColorSelect.B);
if (_ColSelA.getNodePtr() != NULL)
_ColSelA.setSInt32(_ColorSelect.A);
if (!_AHOnChange.empty())
CAHManager::getInstance()->runActionHandler(_AHOnChange, this, _AHOnChangeParams);
}
// ------------------------------------------------------------------------------------------------
CRGBA CCtrlColPick::getColor (sint32 x, sint32 y)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x >= _WReal) x = _WReal-1;
if (y >= _HReal) y = _HReal-1;
return rVR.getTextureColor (_Texture, x, y);
}
}

View file

@ -1,204 +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 "stdpch.h"
#include "interface_manager.h"
#include "ctrl_col_pick.h"
#include "nel/misc/xml_auto_ptr.h"
using namespace NLMISC;
using namespace std;
NLMISC_REGISTER_OBJECT(CViewBase, CCtrlColPick, std::string, "colpick");
// ------------------------------------------------------------------------------------------------
CCtrlColPick::CCtrlColPick(const TCtorParam &param)
:CCtrlBase(param)
{
_MouseDown = false;
_Texture = -2;
}
// ------------------------------------------------------------------------------------------------
CCtrlColPick::~CCtrlColPick()
{
// Texture has been created ?
if (_Texture>=0)
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.deleteTexture (_Texture);
}
}
// ------------------------------------------------------------------------------------------------
bool CCtrlColPick::parse(xmlNodePtr node, CInterfaceGroup * parentGroup)
{
if (!CCtrlBase::parse(node, parentGroup))
return false;
CXMLAutoPtr prop;
// Read textures
prop = (char*) xmlGetProp( node, (xmlChar*)"texture" );
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance();
if(prop)
{
string sTmp = NLMISC::strlwr((const char*)prop);
_Texture = rVR.createTexture (sTmp, 0, 0, 256, 64, false, false);
}
prop = (char*) xmlGetProp( node, (xmlChar*)"onchange" );
if (prop) _AHOnChange = NLMISC::strlwr(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"onchange_params" );
if (prop) _AHOnChangeParams = string((const char*)prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolr" );
if (prop) _ColSelR.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolg" );
if (prop) _ColSelG.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcolb" );
if (prop) _ColSelB.link(prop);
prop = (char*) xmlGetProp( node, (xmlChar*)"dbcola" );
if (prop) _ColSelA.link(prop);
return true;
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::updateCoords()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 txw, txh;
rVR.getTextureSizeFromId (_Texture, txw, txh);
_W = txw;
_H = txh;
CCtrlBase::updateCoords();
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::draw()
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance();
CRGBA col = CRGBA(255,255,255,(uint8)CWidgetManager::getInstance()->getGlobalColor().A);
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal,
_WReal, _HReal,
0, false,
_Texture,
col );
}
// ------------------------------------------------------------------------------------------------
bool CCtrlColPick::handleEvent (const NLGUI::CEventDescriptor &event)
{
if (CCtrlBase::handleEvent(event)) return true;
if (!_Active)
return false;
if (event.getType() == NLGUI::CEventDescriptor::mouse)
{
const NLGUI::CEventDescriptorMouse &eventDesc = (const NLGUI::CEventDescriptorMouse &)event;
if ((CWidgetManager::getInstance()->getCapturePointerLeft() != this) &&
(!((eventDesc.getX() >= _XReal) &&
(eventDesc.getX() < (_XReal + _WReal))&&
(eventDesc.getY() > _YReal) &&
(eventDesc.getY() <= (_YReal+ _HReal)))))
return false;
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown)
{
_MouseDown = true;
selectColor(eventDesc.getX()-_XReal, eventDesc.getY()-_YReal);
return true;
}
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup)
{
_MouseDown = false;
return true;
}
if (eventDesc.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousemove)
{
if (_MouseDown)
{
selectColor(eventDesc.getX()-_XReal, eventDesc.getY()-_YReal);
}
return true;
}
}
return false;
}
// ------------------------------------------------------------------------------------------------
string CCtrlColPick::getColor () const
{
return NLMISC::toString(_ColorSelect.R) + " " + NLMISC::toString(_ColorSelect.G) + " " + NLMISC::toString(_ColorSelect.B) + " " + NLMISC::toString(_ColorSelect.A);
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::setColor (const string &col)
{
_ColorSelect = convertColor (col.c_str());
}
// ------------------------------------------------------------------------------------------------
string CCtrlColPick::getColorOver () const
{
return NLMISC::toString(_ColorOver.R) + " " + NLMISC::toString(_ColorOver.G) + " " + NLMISC::toString(_ColorOver.B) + " " + NLMISC::toString(_ColorOver.A);
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::setColorOver (const string &col)
{
_ColorOver = convertColor (col.c_str());
}
// ------------------------------------------------------------------------------------------------
void CCtrlColPick::selectColor (sint32 x, sint32 y)
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
_ColorSelect = getColor (x, y);
if (_ColSelR.getNodePtr() != NULL)
_ColSelR.setSInt32(_ColorSelect.R);
if (_ColSelG.getNodePtr() != NULL)
_ColSelG.setSInt32(_ColorSelect.G);
if (_ColSelB.getNodePtr() != NULL)
_ColSelB.setSInt32(_ColorSelect.B);
if (_ColSelA.getNodePtr() != NULL)
_ColSelA.setSInt32(_ColorSelect.A);
if (!_AHOnChange.empty())
CAHManager::getInstance()->runActionHandler(_AHOnChange, this, _AHOnChangeParams);
}
// ------------------------------------------------------------------------------------------------
CRGBA CCtrlColPick::getColor (sint32 x, sint32 y)
{
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance();
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x >= _WReal) x = _WReal-1;
if (y >= _HReal) y = _HReal-1;
return rVR.getTextureColor (_Texture, x, y);
}

View file

@ -1,100 +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_CTRL_COL_PICK_H
#define RZ_CTRL_COL_PICK_H
#include "nel/misc/types_nl.h"
#include "nel/gui/ctrl_base.h"
/**
* Class handling a Color Picker
* \author Matthieu 'TrapII' Besson
* \author Nevrax France
* \date 2003
*/
class CCtrlColPick : public CCtrlBase
{
public:
CCtrlColPick(const TCtorParam &param);
~CCtrlColPick();
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
virtual void updateCoords();
virtual void draw();
virtual bool handleEvent (const NLGUI::CEventDescriptor &event);
sint32 getColorR () const { return _ColorSelect.R; }
sint32 getColorG () const { return _ColorSelect.G; }
sint32 getColorB () const { return _ColorSelect.B; }
sint32 getColorA () const { return _ColorSelect.A; }
void setColorR (sint32 r) { _ColorSelect.R = (uint8)r; }
void setColorG (sint32 g) { _ColorSelect.G = (uint8)g; }
void setColorB (sint32 b) { _ColorSelect.B = (uint8)b; }
void setColorA (sint32 a) { _ColorSelect.A = (uint8)a; }
std::string getColor () const; // Get Color Selected
void setColor (const std::string &col); // Set Color Selected
std::string getColorOver () const; // Get Color Over
void setColorOver (const std::string &col); // Set Color Over
REFLECT_EXPORT_START(CCtrlColPick, CCtrlBase)
REFLECT_SINT32("r", getColorR, setColorR);
REFLECT_SINT32("g", getColorG, setColorG);
REFLECT_SINT32("b", getColorB, setColorB);
REFLECT_SINT32("a", getColorA, setColorA);
REFLECT_STRING("color", getColor, setColor);
REFLECT_STRING("color_over", getColorOver, setColorOver);
REFLECT_EXPORT_END
protected:
void selectColor (sint32 x, sint32 y);
NLMISC::CRGBA getColor (sint32 x, sint32 y);
protected:
bool _MouseDown;
sint32 _Texture;
NLMISC::CRGBA _ColorSelect; // Last Color selected
NLMISC::CRGBA _ColorOver; // Color Under Mouse Pointer
std::string _AHOnChange;
std::string _AHOnChangeParams;
CInterfaceProperty _ColSelR;
CInterfaceProperty _ColSelG;
CInterfaceProperty _ColSelB;
CInterfaceProperty _ColSelA;
};
#endif // RZ_CTRL_COL_PICK_H
/* End of ctrl_col_pick.h */

View file

@ -54,7 +54,7 @@
// Ctrl
#include "nel/gui/ctrl_scroll.h"
#include "nel/gui/ctrl_button.h"
#include "ctrl_col_pick.h"
#include "nel/gui/ctrl_col_pick.h"
#include "ctrl_tooltip.h"
#include "ctrl_text_button.h"
#include "group_paragraph.h" // For CCtrlLink

View file

@ -35,7 +35,7 @@
#include "dbgroup_select_number.h"
#include "nel/gui/ctrl_button.h"
#include "ctrl_text_button.h"
#include "ctrl_col_pick.h"
#include "nel/gui/ctrl_col_pick.h"
#include "nel/gui/ctrl_draggable.h"
#include "dbctrl_sheet.h"
#include "dbgroup_list_sheet.h"

View file

@ -20,7 +20,7 @@
#include "view_pointer.h"
#include "interface_manager.h"
#include "nel/gui/view_renderer.h"
#include "ctrl_col_pick.h"
#include "nel/gui/ctrl_col_pick.h"
#include "group_paragraph.h"
#include "group_html.h"
#include "group_map.h"