DYTSrouce/src/scene/ui/CompositeWidgetManager.cpp
2025-01-13 01:35:51 +08:00

163 lines
5.1 KiB
C++

#include "CompositeWidgetManager.h"
#include "common/RecourceHelper.h"
#include "viewer/OsgViewUI.h"
CompositeWidgetManager::CompositeWidgetManager(void)
{
_center = false;
_local_x = 0.0;
_local_y = 0.0;
_N = false;
_autoHome = false;
_center_x = 742;
_center_y = 542;
_bAllow = true;
_state = CompositeWidgetManager::DEFAULT;
_mouseDirection = osg::Vec2(0, 0);
_canvasN = new osgWidget::Canvas("canvasN");
_canvasN->setOrigin(742, 542);
_canvasN->setRotate(45);
_canvasN->getBackground()->setColor(1, 0, 0, 0);
_canvasN->setStrata(osgWidget::Window::STRATA_FOREGROUND);
_canvasN->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
_canvasO = new osgWidget::Canvas("canvasO");
_canvasO->setOrigin(715, 515);
_canvasO->getBackground()->setColor(0, 1, 0, 0);
_canvasO->setStrata(osgWidget::Window::STRATA_FOREGROUND);
_canvasO->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
_canvasBackGround = new osgWidget::Canvas("canvasBackGround");
_canvasBackGround->setOrigin(697, 497);
_canvasBackGround->getBackground()->setColor(0, 0, 0, 0);
_canvasBackGround->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
_canvasBackGround->setStrata(osgWidget::Window::STRATA_FOREGROUND);
_canvasFX = new osgWidget::Canvas("FX");
_canvasFX->setOrigin(742, 540);
_canvasFX->getBackground()->setColor(0, 0, 0, 0);
_canvasFX->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
_canvasFX->setRotate(45);
_canvasFX->setStrata(osgWidget::Window::STRATA_FOREGROUND);
const std::string texturePath = RecourceHelper::Get().GetResourcesPath().toStdString();
_bgLayer1 = new CompositeWidget("backGround1", 54, 54, texturePath +"/northarrow/touming.png", "background", osgWidget::Widget::LAYER_TOP, this);
_bgLayer2 = new BackGroundWidget("backGround2", 12, 12, texturePath + "/northarrow/_n.png");
_bgLayer3 = new BackGroundWidget("backGround3", 84, 84, texturePath + "/northarrow/lookbackground.png");
_bgLayer4 = new BackGroundWidget("backGround4", 54, 54, texturePath + "/northarrow/looknorm.png");
_bgShadow = new BackGroundWidget("background_shadow", 54, 54, texturePath + "/northarrow/ringshadow.png");
_widgetCenter = new CompositeWidget("center", 15, 15, texturePath + "/northarrow/center1.png", "center", osgWidget::Widget::LAYER_TOP, this);
_widgetN = new CompositeWidget("N", 12, 12, texturePath + "/northarrow/_n.png", "N", osgWidget::Widget::LAYER_TOP, this);
_widgetFX = new BackGroundWidget("light", 60, 60, texturePath + "/northarrow/spotlight.png");
_widgetFXBackground = new BackGroundWidget("light_background", 51, 51, texturePath + "/northarrow/touming.png");
_canvasO->addWidget(_widgetCenter, 19, 20);
_canvasO->addWidget(_bgLayer1, 0, 0);
_canvasO->addWidget(_bgShadow, 0, 0);
_canvasO->getBackground()->setColor(0, 0, 0, 0);
_canvasN->addWidget(_bgLayer2, 19, 18);
_canvasN->addWidget(_widgetN, 19, 18);
_canvasN->getBackground()->setColor(0, 0, 0, 0);
_canvasBackGround->addWidget(_bgLayer3, 0, 0);
_canvasBackGround->addWidget(_bgLayer4, 14, 14);
_canvasBackGround->getBackground()->setColor(0, 0, 0, 0);
_canvasFX->addWidget(_widgetFX, 0, 0);
_canvasFX->addWidget(_widgetFXBackground, 0, 0);
_canvasFX->getBackground()->setColor(0, 0, 0, 0);
}
CompositeWidgetManager::~CompositeWidgetManager(void)
{
delete _canvasN;
delete _canvasO;
delete _canvasBackGround;
delete _canvasFX;
delete _bgLayer1;
delete _bgLayer2;
delete _bgLayer3;
delete _bgLayer4;
delete _bgShadow;
delete _widgetCenter;
delete _widgetN;
delete _widgetFX;
}
void CompositeWidgetManager::ResetCanvasPosition(double x, double y)
{
_canvasN->setOrigin(x - 100 + 42, y - 100 + 42);
_canvasO->setOrigin(x - 100 + 15, y - 100 + 14);
_canvasBackGround->setOrigin(x - 100, y - 100);
_canvasFX->setOrigin(x - 100 + 42, y - 100 + 40);
_canvasN->resize();
_canvasO->resize();
_canvasBackGround->resize();
_canvasFX->resize();
_center_x = x - 100 + 42;
_center_y = y - 100 + 42;
}
void CompositeWidgetManager::SendPosition()
{
_mouseDirection = osg::Vec2(_local_x, _local_y);
if (_center == 0 && _state != CompositeWidgetManager::MOUSE_DRAG && _autoHome != true)
{
QVariantList varList;
varList.push_back(QVariant(_mouseDirection.x()));
varList.push_back(QVariant(_mouseDirection.y()));
//emit signalPitch(QVariant(varList));
}
else if (_state == CompositeWidgetManager::MOUSE_DRAG || _autoHome == true)
{
QVariantList varList;
varList.push_back(QVariant(_mouseDirection.x()));
varList.push_back(QVariant(_mouseDirection.y()));
//emit signalHeading(QVariant(varList));
}
else
{
osg::Vec2 pos = _mouseDirection;
pos[0] = pos.x()* 0.2;
pos[1] = pos.y()* 0.1;
QVariantList varList;
varList.push_back(QVariant(pos.x()));
varList.push_back(QVariant(pos.y()));
//emit signalTraval(QVariant(varList));
}
}
void CompositeWidgetManager::SetHeading(double angle)
{
_canvasN->setRotate(angle + 45);
_canvasN->update();
}
void CompositeWidgetManager::AttachViewUI(OsgViewUI* ui) {
ui->addChild(_canvasO);
ui->addChild(_canvasN);
ui->addChild(_canvasFX);
ui->addChild(_canvasBackGround);
}
//void CompositeWidgetManager::slotHeading(double angle)
//{
// SetHeading(angle);
//}