DYTSrouce/src/scene/ui/CompositeHandle.cpp

153 lines
3.1 KiB
C++
Raw Normal View History

2025-01-12 17:35:51 +00:00
#include "CompositeHandle.h"
#include "CompositeWidgetManager.h"
#include <iostream>
CompositeHandle::CompositeHandle(CompositeWidgetManager* cw) :_cw(cw),
_operate(cw->GetcanvasO()),
_N(cw->GetcanvasN()),
_light(cw->GetcanvasFX()),
_background(cw->GetcanvasBackGround()),
_num(0),
_move(false)
{
}
CompositeHandle::~CompositeHandle(void)
{
}
bool CompositeHandle::handle(const osgGA::GUIEventAdapter&ea, osgGA::GUIActionAdapter& aa)
{
if (_num != 0)
{
_cw->_local_y = sin(_angle);
_cw->_local_x = cos(_angle);
_angle = _angle + _num;
_cw->SendPosition();
if ((_num >= 0 && _angle >= osg::PI_2) || (_num < 0 && _angle < osg::PI_2))
{
_cw->_local_y = sin(osg::PI_2);
_cw->_local_x = cos(osg::PI_2);
_cw->SendPosition();
_num = 0;
_cw->_autoHome = false;
_cw->_N = false;
}
return false;
}
else
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::DRAG:
{
if (_cw->_state == CompositeWidgetManager::MOUSE_DRAG)
{
_cw->SendPosition();
}
break;
}
case osgGA::GUIEventAdapter::PUSH:
{
_cw->_N = false;
break;
}
case osgGA::GUIEventAdapter::DOUBLECLICK:
{
if (_cw->_N == true)
{
_num = (45 - _N->getRotate())*osg::PI / (100 * 180);
if (_num != 0)
{
_angle = (_N->getRotate() - 45)*osg::PI / 180 + osg::PI_2;
_cw->_autoHome = true;
}
return true;
}
else if (ea.getX() >= _cw->_center_x - 42 &&
ea.getX() < _cw->_center_x + 42 &&
ea.getY() > _cw->_center_y - 42 &&
ea.getY() < _cw->_center_y + 42)
{
return true;
}
break;
}
default:
break;
}
switch (_cw->_state)
{
case CompositeWidgetManager::MOUSE_PUSH:
{
if (_cw->_N != true || _cw->_autoHome == false)
{
_cw->SendPosition();
if (_cw->_local_y < 0)
{
if (_cw->_local_x > 0)
{
_light->setRotate(45 - (180 - 90 * asinf(_cw->_local_x / sqrtf(_cw->_local_x*_cw->_local_x + _cw->_local_y*_cw->_local_y)) / osg::PI_2));
}
else
{
_light->setRotate(45 - (-180 - 90 * asinf(_cw->_local_x / sqrtf(_cw->_local_x*_cw->_local_x + _cw->_local_y*_cw->_local_y)) / osg::PI_2));
}
}
else
{
_light->setRotate(45 - 90 * asinf(_cw->_local_x / sqrtf(_cw->_local_x*_cw->_local_x + _cw->_local_y*_cw->_local_y)) / osg::PI_2);
}
_light->getByName("light")->setColor(1, 1, 1, 0.5);
_light->resize();
}
break;
}
case CompositeWidgetManager::MOUSE_RELEASE:
{
_cw->_state = CompositeWidgetManager::DEFAULT;
_light->getByName("light")->setColor(1, 1, 1, 0);
break;
}
case CompositeWidgetManager::MOUSE_DRAG:
{
break;
}
default:
{
if (ea.getX() > _cw->_center_x - 50 &&
ea.getY() > _cw->_center_y - 200)
{
if (_cw->_center == 1)
{
_operate->getByName("center")->setColor(1, 1, 1, 1);
}
_background->getByName("backGround4")->setColor(1, 1, 1, 1);
}
else {
if (_cw->_center == 1)
{
_operate->getByName("center")->setColor(1, 1, 1, 0.1);
}
_background->getByName("backGround4")->setColor(1, 1, 1, 0);
}
}
break;
}
}
return false;
}