add sence ui
This commit is contained in:
parent
bfb1f1ac5f
commit
1dc7ec9f8b
@ -9,7 +9,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools OpenGL REQUIRED)
|
||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets LinguistTools DataVisualization Charts Network REQUIRED)
|
||||
|
||||
message("qt VERSION " ${QT_VERSION_MAJOR})
|
||||
@ -150,6 +150,7 @@ target_link_libraries(
|
||||
Qt${QT_VERSION_MAJOR}::Charts
|
||||
Qt${QT_VERSION_MAJOR}::DataVisualization
|
||||
Qt${QT_VERSION_MAJOR}::Network
|
||||
Qt${QT_VERSION_MAJOR}::OpenGL
|
||||
spdlog
|
||||
OpenThreads
|
||||
osg
|
||||
@ -163,6 +164,7 @@ target_link_libraries(
|
||||
osgShadow
|
||||
osgParticle
|
||||
osgSim
|
||||
osgWidget
|
||||
osgEarth
|
||||
Triton-MT-DLL
|
||||
libeng
|
||||
|
@ -50,6 +50,10 @@ const QString RecourceHelper::GetBasePath() const {
|
||||
return QApplication::applicationDirPath();
|
||||
}
|
||||
|
||||
const QString RecourceHelper::GetResourcesPath() const {
|
||||
return QApplication::applicationDirPath() + "/resources";
|
||||
}
|
||||
|
||||
void RecourceHelper::ChangeSkin(const QString& skin) {
|
||||
#if _DEBUG
|
||||
const QString qssFile = QString("%1skin/%2.qss").arg(QString(CONFIG_PATH)).arg(skin);
|
||||
|
@ -26,6 +26,7 @@ public:
|
||||
void OnChangeStyle();
|
||||
|
||||
const QString GetBasePath() const;
|
||||
const QString GetResourcesPath() const;
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
@ -116,7 +116,7 @@ void ConeWave::CreateTexturedCone(osg::Geode* geode) {
|
||||
fragmentShader->setShaderSource(fragSource);
|
||||
|
||||
osg::StateSet* stateset = coneDrawable_->getOrCreateStateSet();
|
||||
stateset->setRenderBinDetails(13, "DepthSortedBin");
|
||||
stateset->setRenderBinDetails(120, "OSGEARTH_SCREEN_SPACE_LAYOUT_BIN");
|
||||
osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc();
|
||||
stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
|
||||
osg::ref_ptr<osg::Program> program = new osg::Program();
|
||||
|
@ -174,3 +174,13 @@ void OEScene::AddToScene(osg::Node* node) {
|
||||
/* osg::Group* root = GetScene();
|
||||
root->addChild(node);*/
|
||||
}
|
||||
|
||||
OESceneUI* OEScene::GetOrCreateSceneUI() {
|
||||
if (sceneUI_) {
|
||||
LOG_INFO("scene ui is already attached");
|
||||
return sceneUI_.get();
|
||||
}
|
||||
|
||||
sceneUI_ = new OESceneUI(this);
|
||||
return sceneUI_.get();
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "common/SpdLogger.h"
|
||||
#include "config.h"
|
||||
#include "scene/ui/OESceneUI.h"
|
||||
|
||||
class OsgView;
|
||||
|
||||
@ -42,10 +43,13 @@ public:
|
||||
|
||||
void AddToScene(osg::Node* node);
|
||||
|
||||
OESceneUI* GetOrCreateSceneUI();
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Node> earthRootNode_;
|
||||
osg::ref_ptr<osgEarth::MapNode> earthMapNode_;
|
||||
osg::ref_ptr<osg::Group> entityRoot_;
|
||||
osg::ref_ptr<osgEarth::SkyNode> skyDome_;
|
||||
std::unique_ptr<osgEarth::Util::LogarithmicDepthBuffer> logarithmicDepthBuffer_;
|
||||
osg::ref_ptr<OESceneUI> sceneUI_;
|
||||
};
|
||||
|
57
src/scene/ui/BackGroundWidget.cpp
Normal file
57
src/scene/ui/BackGroundWidget.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "BackGroundWidget.h"
|
||||
#include <osg/Array>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
|
||||
#include "utils/ImageUtils.h"
|
||||
|
||||
BackGroundWidget::BackGroundWidget(const std::string& name,
|
||||
float w,
|
||||
float h,
|
||||
const std::string& fileName)
|
||||
:osgWidget::Widget(name, w, h)
|
||||
{
|
||||
//osg::Image *image = ImageUtils::readImage(fileName);
|
||||
|
||||
setImage(fileName, true, true);
|
||||
|
||||
setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
|
||||
setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
|
||||
setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
|
||||
|
||||
if ("light" == name)
|
||||
{
|
||||
setLayer(osgWidget::Widget::LAYER_HIGH);
|
||||
setColor(0, 0, 0, 0);
|
||||
}
|
||||
else if ("background_shadow" == name)
|
||||
{
|
||||
setLayer(osgWidget::Widget::LAYER_LOW);
|
||||
setColor(1, 1, 1, 1);
|
||||
}
|
||||
else if ("background2" == name)
|
||||
{
|
||||
setLayer(osgWidget::Widget::LAYER_BG);
|
||||
setColor(1, 1, 1, 1);
|
||||
}
|
||||
else if ("background4" == name)
|
||||
{
|
||||
setLayer(osgWidget::Widget::LAYER_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
setLayer(osgWidget::Widget::LAYER_BG);
|
||||
setColor(1, 1, 1, 1);
|
||||
}
|
||||
if (name == "zoomBackground")
|
||||
{
|
||||
setColor(0, 0, 0, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
BackGroundWidget::~BackGroundWidget(void)
|
||||
{
|
||||
}
|
14
src/scene/ui/BackGroundWidget.h
Normal file
14
src/scene/ui/BackGroundWidget.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef BackGroundWidget_H_
|
||||
#define BackGroundWidget_H_
|
||||
|
||||
#include <osgWidget/Widget>
|
||||
#include <string>
|
||||
|
||||
class BackGroundWidget : public osgWidget::Widget
|
||||
{
|
||||
public:
|
||||
BackGroundWidget(const std::string& name, float w, float h, const std::string& fileName);
|
||||
~BackGroundWidget(void);
|
||||
};
|
||||
|
||||
#endif
|
153
src/scene/ui/CompositeHandle.cpp
Normal file
153
src/scene/ui/CompositeHandle.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
#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;
|
||||
}
|
35
src/scene/ui/CompositeHandle.h
Normal file
35
src/scene/ui/CompositeHandle.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef OperateHandle_H_
|
||||
#define OperateHandle_H_
|
||||
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgWidget/Canvas>
|
||||
#include "CompositeWidget.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class CompositeWidgetManager;
|
||||
class CompositeHandle :public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
CompositeHandle(CompositeWidgetManager* cw);
|
||||
|
||||
~CompositeHandle(void);
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&);
|
||||
|
||||
private:
|
||||
osgWidget::Canvas* _operate;
|
||||
osgWidget::Canvas* _N;
|
||||
osgWidget::Canvas* _light;
|
||||
osgWidget::Canvas* _background;
|
||||
|
||||
CompositeWidgetManager* _cw;
|
||||
|
||||
double _num;
|
||||
bool _move;
|
||||
double _angle;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
116
src/scene/ui/CompositeWidget.cpp
Normal file
116
src/scene/ui/CompositeWidget.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#include "CompositeWidget.h"
|
||||
|
||||
#include "utils/ImageUtils.h"
|
||||
#include "CompositeWidgetManager.h"
|
||||
|
||||
|
||||
CompositeWidget::CompositeWidget(std::string name,
|
||||
float w,
|
||||
float h,
|
||||
std::string fileName,
|
||||
std::string message,
|
||||
osgWidget::Widget::Layer layer,
|
||||
CompositeWidgetManager *wm) :osgWidget::Widget(name, w, h)
|
||||
{
|
||||
//osg::Image *image = ImageUtils::readImage(fileName);
|
||||
|
||||
setImage(fileName, true, true);
|
||||
|
||||
setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
|
||||
setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
|
||||
setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
|
||||
setLayer(layer);
|
||||
setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MOUSE_RELEASE | osgWidget::EVENT_MOUSE_DRAG);
|
||||
if (message == "background" || message == "light")
|
||||
{
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
_PointerX = 0.0;
|
||||
_PointerY = 0.0;
|
||||
order = message;
|
||||
_wm = wm;
|
||||
}
|
||||
|
||||
CompositeWidget::~CompositeWidget(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool CompositeWidget::mousePush(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
if (order == "center")
|
||||
{
|
||||
if (_wm->_bAllow)
|
||||
{
|
||||
if (_wm->_center == true)
|
||||
{
|
||||
_wm->_center = false;
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_wm->_center = true;
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (order == "N")
|
||||
{
|
||||
_wm->_N = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_wm->_state = CompositeWidgetManager::MOUSE_PUSH;
|
||||
}
|
||||
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
|
||||
_PointerX = x;
|
||||
_PointerY = y;
|
||||
_wm->_local_x = _PointerX - _wm->_center_x;
|
||||
_wm->_local_y = _PointerY - _wm->_center_y;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CompositeWidget::mouseDrag(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
if (order == "N")
|
||||
{
|
||||
_wm->_state = CompositeWidgetManager::MOUSE_DRAG;
|
||||
_wm->_N = false;
|
||||
if (_wm->_autoHome == true)
|
||||
return false;
|
||||
|
||||
_PointerX += x;
|
||||
_PointerY += y;
|
||||
_wm->_local_x = _PointerX - _wm->_center_x;
|
||||
_wm->_local_y = _PointerY - _wm->_center_y;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CompositeWidget::mouseRelease(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
_wm->_state = CompositeWidgetManager::MOUSE_RELEASE;
|
||||
if (getName() != "center")
|
||||
{
|
||||
if (getName() != "backGround1")
|
||||
{
|
||||
setColor(1, 1, 1, 0);
|
||||
}
|
||||
}
|
||||
if (order == "N")
|
||||
{
|
||||
getParent()->resize();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
45
src/scene/ui/CompositeWidget.h
Normal file
45
src/scene/ui/CompositeWidget.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef CompositeWidget_h__
|
||||
#define CompositeWidget_h__
|
||||
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class CompositeWidgetManager;
|
||||
|
||||
class CompositeWidget : public osgWidget::Widget
|
||||
{
|
||||
public:
|
||||
CompositeWidget(std::string name,
|
||||
float w,
|
||||
float h,
|
||||
std::string fileName,
|
||||
std::string message,
|
||||
osgWidget::Widget::Layer layer,
|
||||
CompositeWidgetManager *wm);
|
||||
|
||||
~CompositeWidget(void);
|
||||
|
||||
bool mousePush(double, double, const osgWidget::WindowManager*);
|
||||
bool mouseRelease(double, double, const osgWidget::WindowManager*);
|
||||
bool mouseDrag(double, double, const osgWidget::WindowManager*);
|
||||
|
||||
std::string GetOrder() { return order; }
|
||||
double GetPointerX() { return _PointerX; }
|
||||
double GetPointerY() { return _PointerY; }
|
||||
|
||||
private:
|
||||
double _PointerX;
|
||||
double _PointerY;
|
||||
std::string order;
|
||||
|
||||
CompositeWidgetManager *_wm;
|
||||
};
|
||||
|
||||
#endif // CompositeWidget_h__
|
||||
|
162
src/scene/ui/CompositeWidgetManager.cpp
Normal file
162
src/scene/ui/CompositeWidgetManager.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
#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);
|
||||
//}
|
91
src/scene/ui/CompositeWidgetManager.h
Normal file
91
src/scene/ui/CompositeWidgetManager.h
Normal file
@ -0,0 +1,91 @@
|
||||
#ifndef CompositeWidgetManager_h__
|
||||
#define CompositeWidgetManager_h__
|
||||
|
||||
#include "BackGroundWidget.h"
|
||||
#include "CompositeHandle.h"
|
||||
#include "CompositeWidget.h"
|
||||
#include "ZoomWidget.h"
|
||||
#include "ZoomHandle.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class CompositeWidgetManager : public osg::Referenced {
|
||||
|
||||
public:
|
||||
CompositeWidgetManager(void);
|
||||
~CompositeWidgetManager(void);
|
||||
|
||||
void ResetCanvasPosition(double x, double y);
|
||||
void SendPosition();
|
||||
void SetHeading(double angle);
|
||||
|
||||
osgWidget::Canvas* GetcanvasN() {
|
||||
return _canvasN;
|
||||
}
|
||||
osgWidget::Canvas* GetcanvasO() {
|
||||
return _canvasO;
|
||||
}
|
||||
osgWidget::Canvas* GetcanvasBackGround() {
|
||||
return _canvasBackGround;
|
||||
}
|
||||
osgWidget::Canvas* GetcanvasFX() {
|
||||
return _canvasFX;
|
||||
}
|
||||
|
||||
void AttachViewUI(class OsgViewUI* ui);
|
||||
|
||||
//
|
||||
//
|
||||
//signals:
|
||||
// void signalPitch(QVariant var);
|
||||
// void signalTraval(QVariant var);
|
||||
// void signalHeading(QVariant var);
|
||||
|
||||
public slots:
|
||||
void slotHeading(double angle);
|
||||
|
||||
private:
|
||||
osgWidget::Canvas* _canvasN;
|
||||
osgWidget::Canvas* _canvasO;
|
||||
osgWidget::Canvas* _canvasBackGround;
|
||||
osgWidget::Canvas* _canvasFX;
|
||||
|
||||
CompositeWidget* _bgLayer1;
|
||||
osgWidget::Widget* _bgLayer2;
|
||||
osgWidget::Widget* _bgLayer3;
|
||||
osgWidget::Widget* _bgLayer4;
|
||||
osgWidget::Widget* _bgShadow;
|
||||
|
||||
CompositeWidget* _widgetCenter;
|
||||
|
||||
CompositeWidget* _widgetN;
|
||||
|
||||
osgWidget::Widget* _widgetFX;
|
||||
osgWidget::Widget* _widgetFXBackground;
|
||||
|
||||
osg::Vec2 _mouseDirection;
|
||||
|
||||
public:
|
||||
enum STATE {
|
||||
MOUSE_PUSH,
|
||||
MOUSE_RELEASE,
|
||||
MOUSE_LEAVE,
|
||||
MOUSE_OVER,
|
||||
MOUSE_DRAG,
|
||||
DEFAULT
|
||||
};
|
||||
|
||||
double _center_x;
|
||||
double _center_y;
|
||||
double _local_x;
|
||||
double _local_y;
|
||||
bool _center;
|
||||
STATE _state;
|
||||
bool _N;
|
||||
bool _autoHome;
|
||||
bool _bAllow;
|
||||
};
|
||||
|
||||
#endif // CompositeWidgetManager_h__
|
52
src/scene/ui/OESceneUI.cpp
Normal file
52
src/scene/ui/OESceneUI.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "scene/ui/OESceneUI.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
|
||||
#include "scene/OEScene.h"
|
||||
#include "scene/ui/CompositeWidgetManager.h"
|
||||
#include "scene/ui/CompositeHandle.h"
|
||||
#include "scene/ui/ZoomManager.h"
|
||||
#include "scene/ui/ZoomHandle.h"
|
||||
#include "scene/ui/QueryElevationWidget.h"
|
||||
|
||||
|
||||
OESceneUI::OESceneUI(OEScene* oeScene)
|
||||
: oeScene_(oeScene) {
|
||||
LOG_INFO("actor self={}", spdlog::fmt_lib::ptr(this));
|
||||
}
|
||||
|
||||
OESceneUI::~OESceneUI(void) {
|
||||
LOG_INFO("dctor self={}", spdlog::fmt_lib::ptr(this));
|
||||
}
|
||||
|
||||
void OESceneUI::InitUI(OsgViewUI* ui) {
|
||||
LOG_INFO("enter");
|
||||
if (isInit_) {
|
||||
LOG_INFO("already init");
|
||||
return;
|
||||
}
|
||||
|
||||
compositeWidgetManager_ = new CompositeWidgetManager();
|
||||
compositeWidgetManager_->AttachViewUI(ui);
|
||||
zoomManager_ = new ZoomManager();
|
||||
zoomManager_->AttachViewUI(ui);
|
||||
|
||||
queryElevationWidget_ = new QueryElevationWidget(oeScene_);
|
||||
queryElevationWidget_->AttachViewUI(ui);
|
||||
|
||||
ui->getView()->addEventHandler(new ZoomHandle(zoomManager_, compositeWidgetManager_));
|
||||
ui->getView()->addEventHandler(new CompositeHandle(compositeWidgetManager_));
|
||||
|
||||
isInit_ = true;
|
||||
LOG_INFO("exit");
|
||||
}
|
||||
|
||||
void OESceneUI::OnResize(double width, double height) {
|
||||
dyt_check(compositeWidgetManager_);
|
||||
dyt_check(zoomManager_);
|
||||
|
||||
compositeWidgetManager_->ResetCanvasPosition(width, height);
|
||||
zoomManager_->ResetCanvasPosition(width, height);
|
||||
queryElevationWidget_->ResetCanvasPosition(width, height);
|
||||
}
|
27
src/scene/ui/OESceneUI.h
Normal file
27
src/scene/ui/OESceneUI.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
#include <iostream>
|
||||
|
||||
#include "viewer/OsgViewUI.h"
|
||||
|
||||
class OESceneUI : public OsgViewUI::ViewUI
|
||||
{
|
||||
public:
|
||||
OESceneUI(class OEScene* oeScene);
|
||||
~OESceneUI(void) override;
|
||||
|
||||
void InitUI(OsgViewUI* ui) override;
|
||||
void OnResize(double width, double height) override;
|
||||
|
||||
private:
|
||||
class OEScene* oeScene_;
|
||||
bool isInit_{ false };
|
||||
osg::ref_ptr<class CompositeWidgetManager> compositeWidgetManager_{ nullptr };
|
||||
osg::ref_ptr<class ZoomManager> zoomManager_{ nullptr };
|
||||
osg::ref_ptr<class QueryElevationWidget> queryElevationWidget_{ nullptr };
|
||||
};
|
112
src/scene/ui/QueryElevationWidget.cpp
Normal file
112
src/scene/ui/QueryElevationWidget.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
#include "scene/ui/QueryElevationWidget.h"
|
||||
|
||||
#include <QString>
|
||||
#include <osgEarth/MapNode>
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
#include "viewer/OsgViewUI.h"
|
||||
#include "scene/OEScene.h"
|
||||
#include "scene/SceneContent.h"
|
||||
|
||||
|
||||
struct ColorLabel : public osgWidget::Label {
|
||||
ColorLabel(const char* label) :
|
||||
osgWidget::Label("", "") {
|
||||
setFont("fonts/Vera.ttf");
|
||||
setFontSize(14);
|
||||
setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
addHeight(18.0f);
|
||||
setCanFill(true);
|
||||
setLabel(label);
|
||||
}
|
||||
};
|
||||
|
||||
QueryElevationWidget::QueryElevationWidget(OEScene* oeScene)
|
||||
: osgWidget::Box("QueryElevation", osgWidget::Box::HORIZONTAL)
|
||||
, oeScene_(oeScene) {
|
||||
LOG_INFO("actor self={}", spdlog::fmt_lib::ptr(this));
|
||||
|
||||
label_ = new ColorLabel("Pick me!");
|
||||
addWidget(label_);
|
||||
getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.3f);
|
||||
}
|
||||
|
||||
|
||||
QueryElevationWidget::~QueryElevationWidget() {
|
||||
LOG_INFO("dctor self={}", spdlog::fmt_lib::ptr(this));
|
||||
}
|
||||
|
||||
void QueryElevationWidget::AttachViewUI(OsgViewUI* ui) {
|
||||
dyt_check(nullptr != ui);
|
||||
|
||||
ui->addChild(this);
|
||||
dyt_check(nullptr != oeScene_);
|
||||
osgEarth::MapNode* mapNode = oeScene_->GetMapNode();
|
||||
ui->getView()->addEventHandler(new QueryElevationEventHandler(mapNode, this));
|
||||
}
|
||||
|
||||
|
||||
void QueryElevationWidget::OnUpdateGeoPoint(double x, double y, double z) {
|
||||
// x 保存小数点后6位 c++14
|
||||
dyt_check(nullptr != label_);
|
||||
|
||||
QString info = QObject::tr("longitude:") + QString::number(x, 'f', 6) + ", "
|
||||
+ QString::fromLocal8Bit("latitude:") + QString::number(y, 'f', 6) + ", "
|
||||
+ QString::fromLocal8Bit("altitude:") + QString::number(z, 'f', 6);
|
||||
label_->setLabel(info.toLocal8Bit().constData());
|
||||
|
||||
}
|
||||
|
||||
void QueryElevationWidget::ResetCanvasPosition(double width, double height) {
|
||||
dyt_check(nullptr != label_);
|
||||
label_->setSize(width, 20);
|
||||
}
|
||||
|
||||
QueryElevationWidget::QueryElevationEventHandler::QueryElevationEventHandler(
|
||||
osgEarth::MapNode* mapNode, QueryElevationWidget* widget)
|
||||
: osgGA::GUIEventHandler()
|
||||
, mapNode_(mapNode)
|
||||
, widget_(widget) {
|
||||
LOG_INFO("actor self={}", spdlog::fmt_lib::ptr(this));
|
||||
dyt_check(nullptr != mapNode);
|
||||
dyt_check(nullptr != widget);
|
||||
}
|
||||
|
||||
QueryElevationWidget::QueryElevationEventHandler::~QueryElevationEventHandler() {
|
||||
LOG_INFO("dctor self={}", spdlog::fmt_lib::ptr(this));
|
||||
}
|
||||
|
||||
bool QueryElevationWidget::QueryElevationEventHandler::handle(
|
||||
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
|
||||
if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE || ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
|
||||
osgUtil::LineSegmentIntersector::Intersections intersections;
|
||||
osg::NodePath np;
|
||||
|
||||
np.push_back(mapNode_);
|
||||
osgViewer::View* view = dynamic_cast<osgViewer::View*>(aa.asView());
|
||||
if (view->computeIntersections(ea.getX(), ea.getY(), np, intersections)) {
|
||||
if (intersections.size() >= 1) {
|
||||
osgUtil::LineSegmentIntersector::Intersections::iterator it = intersections.begin();
|
||||
osg::Vec3d point;
|
||||
point = it->getWorldIntersectPoint();
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
double height = 0.0;
|
||||
osgEarth::GeoPoint geoPoint;
|
||||
geoPoint.fromWorld(g_srs_, point);
|
||||
|
||||
const osgEarth::SpatialReference* wgs84 = osgEarth::SpatialReference::get("wgs84");
|
||||
geoPoint = geoPoint.transform(wgs84);
|
||||
|
||||
widget_->OnUpdateGeoPoint(geoPoint.x(), geoPoint.y(), geoPoint.z());
|
||||
}
|
||||
}
|
||||
else {
|
||||
widget_->OnUpdateGeoPoint(0.0, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
36
src/scene/ui/QueryElevationWidget.h
Normal file
36
src/scene/ui/QueryElevationWidget.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Label>
|
||||
#include <osgEarth/MapNode>
|
||||
|
||||
class QueryElevationWidget : public osgWidget::Box {
|
||||
class QueryElevationEventHandler : public osgGA::GUIEventHandler {
|
||||
public:
|
||||
QueryElevationEventHandler(osgEarth::MapNode* mapNode, QueryElevationWidget* widget);
|
||||
~QueryElevationEventHandler() override;
|
||||
|
||||
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override;
|
||||
|
||||
private:
|
||||
osgEarth::MapNode* mapNode_;
|
||||
QueryElevationWidget* widget_;
|
||||
};
|
||||
public:
|
||||
QueryElevationWidget(class OEScene* oeScene);
|
||||
|
||||
~QueryElevationWidget() override;
|
||||
|
||||
void AttachViewUI(class OsgViewUI* ui);
|
||||
|
||||
void OnUpdateGeoPoint(double x, double y, double z);
|
||||
void ResetCanvasPosition(double width, double height);
|
||||
|
||||
private:
|
||||
class OEScene* oeScene_;
|
||||
osg::ref_ptr<osgWidget::Label> label_;
|
||||
|
||||
};
|
||||
|
61
src/scene/ui/ZoomHandle.cpp
Normal file
61
src/scene/ui/ZoomHandle.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "ZoomHandle.h"
|
||||
#include "ZoomManager.h"
|
||||
#include "CompositeWidgetManager.h"
|
||||
|
||||
ZoomHandle::ZoomHandle(ZoomManager* zoom, CompositeWidgetManager *pCompositeWidgetManager) :_zoom(zoom->GetCanvasZoom()), _zoom_(zoom)
|
||||
{
|
||||
_pCompositeWidgetManager = pCompositeWidgetManager;
|
||||
}
|
||||
|
||||
ZoomHandle::~ZoomHandle(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ZoomHandle::handle(const osgGA::GUIEventAdapter&ea, osgGA::GUIActionAdapter& aa)
|
||||
{
|
||||
if (ea.getEventType() == osgGA::GUIEventAdapter::DOUBLECLICK)
|
||||
{
|
||||
if (ea.getX() > _pCompositeWidgetManager->_center_x - 9 &&
|
||||
ea.getX() < _pCompositeWidgetManager->_center_x + 9 &&
|
||||
ea.getY() > _pCompositeWidgetManager->_center_y - 192 &&
|
||||
ea.getY() < _pCompositeWidgetManager->_center_y - 48)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
switch (_zoom_->state)
|
||||
{
|
||||
case ZoomManager::MOUSE_PUSH:
|
||||
{
|
||||
_zoom_->SendZoom();
|
||||
break;
|
||||
}
|
||||
case ZoomManager::MOUSE_RELEASE:
|
||||
{
|
||||
_zoom_->state = ZoomManager::DEFAULT;
|
||||
break;
|
||||
}
|
||||
case ZoomManager::MOUSE_DRAG:
|
||||
{
|
||||
_zoom_->SendZoom();
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (ea.getX() > _pCompositeWidgetManager->_center_x - 50 &&
|
||||
ea.getY() > _pCompositeWidgetManager->_center_y - 200)
|
||||
{
|
||||
_zoom->getByName("bar_")->setColor(1, 1, 1, 1);
|
||||
_zoom->getByName("zoomBackground")->setColor(1, 1, 1, 1);
|
||||
}
|
||||
else {
|
||||
_zoom->getByName("bar_")->setColor(1, 1, 1, 0);
|
||||
_zoom->getByName("zoomBackground")->setColor(1, 1, 1, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
26
src/scene/ui/ZoomHandle.h
Normal file
26
src/scene/ui/ZoomHandle.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef ZoomHandle_H_
|
||||
#define ZoomHandle_H_
|
||||
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgWidget/Canvas>
|
||||
#include "ZoomWidget.h"
|
||||
#include "CompositeWidget.h"
|
||||
|
||||
class ZoomManager;
|
||||
class CompositeWidgetManager;
|
||||
|
||||
class ZoomHandle :public osgGA::GUIEventHandler
|
||||
{
|
||||
public:
|
||||
ZoomHandle(ZoomManager* zoom, CompositeWidgetManager *pCompositeWidgetManager);
|
||||
~ZoomHandle(void);
|
||||
|
||||
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&);
|
||||
|
||||
private:
|
||||
osgWidget::Canvas* _zoom;
|
||||
ZoomManager* _zoom_;
|
||||
CompositeWidgetManager *_pCompositeWidgetManager;
|
||||
};
|
||||
|
||||
#endif
|
65
src/scene/ui/ZoomManager.cpp
Normal file
65
src/scene/ui/ZoomManager.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "ZoomManager.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
#include "viewer/OsgViewUI.h"
|
||||
#include "common/RecourceHelper.h"
|
||||
|
||||
ZoomManager::ZoomManager(void)
|
||||
{
|
||||
zoom = 0.0;
|
||||
state = ZoomManager::DEFAULT;
|
||||
|
||||
_canvasZoom = new osgWidget::Canvas("Zoom");
|
||||
_canvasZoom->setOrigin(733, 350);
|
||||
_canvasZoom->getBackground()->setColor(0, 0, 0, 0);
|
||||
_canvasZoom->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
_canvasZoom->setStrata(osgWidget::Window::STRATA_FOREGROUND);
|
||||
|
||||
const std::string texturePath = RecourceHelper::Get().GetResourcesPath().toStdString();
|
||||
_lessen = new ZoomWidget("lessen", 18, 20, texturePath + "/northarrow/zoom_down.png", "lessen", osgWidget::Widget::LAYER_TOP, this);
|
||||
_enlargement = new ZoomWidget("enlargement", 18, 20, texturePath + "/northarrow/zoom_up.png", "enlargement", osgWidget::Widget::LAYER_TOP, this);
|
||||
_zoomBackground = new BackGroundWidget("zoomBackground", 18, 144, texturePath + "/northarrow/zoomactive.png");
|
||||
_bar = new ZoomWidget("bar", 17, 10, texturePath + "/northarrow/zoombar_norm.png", "bar", osgWidget::Widget::LAYER_TOP, this);
|
||||
_bar_ = new BackGroundWidget("bar_", 18, 12, texturePath + "/northarrow/zoombar_norm_.png");
|
||||
_zoomBackground_shadow = new BackGroundWidget("background_shadow", 18, 144, texturePath + "/northarrow/zoombackground.png");
|
||||
|
||||
_canvasZoom->addWidget(_lessen, 0, 0);
|
||||
_canvasZoom->addWidget(_enlargement, 0, 124);
|
||||
_canvasZoom->addWidget(_bar_, 0, 66);
|
||||
_canvasZoom->addWidget(_bar, 0, 67);
|
||||
_canvasZoom->addWidget(_zoomBackground, 0, 0);
|
||||
_canvasZoom->addWidget(_zoomBackground_shadow, 0, 0);
|
||||
}
|
||||
|
||||
ZoomManager::~ZoomManager(void)
|
||||
{
|
||||
delete _canvasZoom;
|
||||
|
||||
delete _lessen;
|
||||
delete _enlargement;
|
||||
delete _zoomBackground;
|
||||
delete _bar;
|
||||
delete _bar_;
|
||||
delete _zoomBackground_shadow;
|
||||
|
||||
}
|
||||
|
||||
void ZoomManager::ResetCanvasPosition(double x, double y)
|
||||
{
|
||||
_canvasZoom->setOrigin(x - 100 + 33, y - 250);
|
||||
_canvasZoom->resize();
|
||||
}
|
||||
|
||||
void ZoomManager::SendZoom()
|
||||
{
|
||||
_zoomNum[0] = zoom;
|
||||
|
||||
//emit signalZoom(QVariant(_zoomNum[0]));
|
||||
}
|
||||
|
||||
void ZoomManager::AttachViewUI(OsgViewUI* ui) {
|
||||
dyt_check(nullptr != ui);
|
||||
|
||||
ui->addChild(_canvasZoom);
|
||||
}
|
56
src/scene/ui/ZoomManager.h
Normal file
56
src/scene/ui/ZoomManager.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef Zoom_H_
|
||||
#define Zoom_H_
|
||||
|
||||
#include "BackGroundWidget.h"
|
||||
#include "CompositeHandle.h"
|
||||
#include "CompositeWidget.h"
|
||||
#include "ZoomWidget.h"
|
||||
#include "ZoomHandle.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
class ZoomManager : public osg::Referenced {
|
||||
public:
|
||||
ZoomManager(void);
|
||||
~ZoomManager(void);
|
||||
|
||||
void ResetCanvasPosition(double x, double y);
|
||||
void SendZoom();
|
||||
|
||||
osgWidget::Canvas* GetCanvasZoom() {
|
||||
return _canvasZoom;
|
||||
}
|
||||
|
||||
void AttachViewUI(class OsgViewUI* ui);
|
||||
//
|
||||
//signals:
|
||||
// void signalZoom(QVariant var);
|
||||
|
||||
private:
|
||||
osgWidget::Canvas* _canvasZoom;
|
||||
|
||||
osgWidget::Widget* _lessen;
|
||||
osgWidget::Widget* _enlargement;
|
||||
osgWidget::Widget* _zoomBackground;
|
||||
osgWidget::Widget* _bar;
|
||||
osgWidget::Widget* _bar_;
|
||||
osgWidget::Widget* _zoomBackground_shadow;
|
||||
|
||||
int _zoomNum[1];
|
||||
|
||||
public:
|
||||
enum STATE {
|
||||
MOUSE_PUSH,
|
||||
MOUSE_RELEASE,
|
||||
MOUSE_LEAVE,
|
||||
MOUSE_OVER,
|
||||
MOUSE_DRAG,
|
||||
DEFAULT
|
||||
};
|
||||
|
||||
STATE state;
|
||||
double zoom;
|
||||
};
|
||||
|
||||
#endif
|
100
src/scene/ui/ZoomWidget.cpp
Normal file
100
src/scene/ui/ZoomWidget.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include "ZoomManager.h"
|
||||
|
||||
#include "ZoomWidget.h"
|
||||
#include "utils/ImageUtils.h"
|
||||
|
||||
ZoomWidget::ZoomWidget(std::string name,
|
||||
float w,
|
||||
float h,
|
||||
std::string fileName,
|
||||
std::string message,
|
||||
osgWidget::Widget::Layer layer,
|
||||
ZoomManager *pZoomManager)
|
||||
:osgWidget::Widget(name, w, h)
|
||||
{
|
||||
//osg::Image *image = ImageUtils::readImage(fileName);
|
||||
setImage(fileName, true, true);
|
||||
setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
|
||||
setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
|
||||
setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
|
||||
setLayer(layer);
|
||||
setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MOUSE_RELEASE | osgWidget::EVENT_MOUSE_DRAG);
|
||||
setColor(1, 1, 1, 0);
|
||||
|
||||
|
||||
_pointX = _pointY = 0.0;
|
||||
_order = message;
|
||||
_pZoomManager = pZoomManager;
|
||||
}
|
||||
|
||||
ZoomWidget::~ZoomWidget(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ZoomWidget::mousePush(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
_pZoomManager->state = ZoomManager::MOUSE_PUSH;
|
||||
_pointY = y;
|
||||
_pointX = x;
|
||||
if ("lessen" == _order)
|
||||
{
|
||||
_pZoomManager->zoom = -43;
|
||||
}
|
||||
else if ("enlargement" == _order)
|
||||
{
|
||||
_pZoomManager->zoom = 43;
|
||||
}
|
||||
setColor(1, 1, 1, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZoomWidget::mouseRelease(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
_pZoomManager->state = ZoomManager::MOUSE_RELEASE;
|
||||
|
||||
if ("bar" == _order)
|
||||
{
|
||||
setOrigin(0, 67);
|
||||
getParent()->getByName("bar_")->setOrigin(0, 66);
|
||||
getParent()->resize();
|
||||
}
|
||||
_pZoomManager->zoom = 0.0;
|
||||
setColor(1, 1, 1, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZoomWidget::mouseDrag(double x, double y, const osgWidget::WindowManager* wm)
|
||||
{
|
||||
if (_order == "bar")
|
||||
{
|
||||
_pointX += x;
|
||||
_pointY += y;
|
||||
|
||||
while (_pZoomManager->zoom > 43)
|
||||
_pZoomManager->zoom = 43;
|
||||
while (_pZoomManager->zoom < -43)
|
||||
_pZoomManager->zoom = -43;
|
||||
|
||||
if (y > 43 - _pZoomManager->zoom)
|
||||
{
|
||||
y = 43 - _pZoomManager->zoom;
|
||||
}
|
||||
if (y < -43 - _pZoomManager->zoom)
|
||||
{
|
||||
y = -43 - _pZoomManager->zoom;
|
||||
}
|
||||
|
||||
if (_pZoomManager->zoom >= -43 && _pZoomManager->zoom <= 43)
|
||||
{
|
||||
addOrigin(0, y);
|
||||
getParent()->getByName("bar_")->addOrigin(0, y);
|
||||
_pZoomManager->zoom += y;
|
||||
}
|
||||
else {
|
||||
_pZoomManager->zoom += y;
|
||||
}
|
||||
getParent()->resize();
|
||||
}
|
||||
return true;
|
||||
}
|
41
src/scene/ui/ZoomWidget.h
Normal file
41
src/scene/ui/ZoomWidget.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef ZoomWidget_H_
|
||||
#define ZoomWidget_H_
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
#include <iostream>
|
||||
|
||||
class ZoomManager;
|
||||
|
||||
class ZoomWidget : public osgWidget::Widget
|
||||
{
|
||||
public:
|
||||
ZoomWidget(std::string name,
|
||||
float w,
|
||||
float h,
|
||||
std::string fileName,
|
||||
std::string message,
|
||||
osgWidget::Widget::Layer layer,
|
||||
ZoomManager *pZoomManager);
|
||||
|
||||
~ZoomWidget(void);
|
||||
|
||||
bool mousePush(double, double, const osgWidget::WindowManager*);
|
||||
bool mouseRelease(double, double, const osgWidget::WindowManager*);
|
||||
bool mouseDrag(double, double, const osgWidget::WindowManager*);
|
||||
|
||||
std::string GetOrder() { return _order; }
|
||||
double GetPointerX() { return _pointX; }
|
||||
double GetpointerY() { return _pointY; }
|
||||
|
||||
private:
|
||||
double _pointX;
|
||||
double _pointY;
|
||||
std::string _order;
|
||||
ZoomManager *_pZoomManager;
|
||||
};
|
||||
|
||||
#endif
|
@ -874,6 +874,11 @@
|
||||
<source>Close Tab</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../scene/ui/QueryElevationWidget.cpp" line="54"/>
|
||||
<source>longitude:</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QtBoolEdit</name>
|
||||
@ -1249,18 +1254,18 @@
|
||||
<context>
|
||||
<name>QtOsgViewWidget</name>
|
||||
<message>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="366"/>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="374"/>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="369"/>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="377"/>
|
||||
<source>warning</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="366"/>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="369"/>
|
||||
<source>default workspace failed</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="374"/>
|
||||
<location filename="../viewer/QtOsgViewWidget.cpp" line="377"/>
|
||||
<source>open dyt file failed</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "UDPRecData.h"
|
||||
|
||||
#include <QVariant>;
|
||||
#include <QVariant>
|
||||
#include <QUdpSocket>
|
||||
|
||||
UDPRecData::UDPRecData(int nPort, QObject *parent)
|
26
src/utils/ImageUtils.cpp
Normal file
26
src/utils/ImageUtils.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "utils/ImageUtils.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QGLWidget>
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include "common/SpdLogger.h"
|
||||
|
||||
|
||||
osg::Image* ImageUtils::readImage(const std::string& filePath) {
|
||||
QImage image(filePath.c_str());
|
||||
if (image.isNull())
|
||||
return NULL;
|
||||
|
||||
image = QGLWidget::convertToGLFormat(image);
|
||||
int nByteCount = image.byteCount();
|
||||
unsigned char* pData = new unsigned char[nByteCount];
|
||||
for (int idx = 0; idx < nByteCount; ++idx) {
|
||||
pData[idx] = image.bits()[idx];
|
||||
}
|
||||
|
||||
osg::Image* pMarkerImage = new osg::Image();
|
||||
pMarkerImage->setImage(image.width(), image.height(), 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, pData, osg::Image::USE_NEW_DELETE, 1);
|
||||
|
||||
return pMarkerImage;
|
||||
}
|
9
src/utils/ImageUtils.h
Normal file
9
src/utils/ImageUtils.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <osg/Image>
|
||||
|
||||
|
||||
class ImageUtils {
|
||||
public:
|
||||
static osg::Image* readImage(const std::string& filePath);
|
||||
};
|
@ -1213,4 +1213,4 @@ bool CameraControlManipulator::handleMouseWheel(const osgGA::GUIEventAdapter& ea
|
||||
|
||||
bool CameraControlManipulator::handleMouseDeltaMovement(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,11 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osg/LightModel>
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
#include "viewer/KeyMapQtOsg.h"
|
||||
#include "viewer/OsgCameraManipulator.h"
|
||||
#include "viewer/OsgViewUI.h"
|
||||
|
||||
enum KeyboardModifier {
|
||||
NoModifier = 0x00000000,
|
||||
@ -103,6 +105,9 @@ void OsgView::Resize(int x, int y, int width, int height) {
|
||||
static_cast<double>(width) / static_cast<double>(height),
|
||||
0.1, 1000.0);
|
||||
#endif
|
||||
if (viewUI_) {
|
||||
viewUI_->Resize(width, height);
|
||||
}
|
||||
view_->requiresRedraw();
|
||||
}
|
||||
|
||||
@ -156,8 +161,18 @@ void OsgView::Initialize(OsgCameraManipulator* cameraManipulator) {
|
||||
SetCameraManipulator(cameraManipulator);
|
||||
}
|
||||
|
||||
//view_->addEventHandler(new osgViewer::StatsHandler);
|
||||
//view_->addEventHandler(new osgGA::StateSetManipulator(view_->getCamera()->getOrCreateStateSet()));
|
||||
if (!viewUI_.valid()) {
|
||||
const osg::Viewport* viewport = view_->getCamera()->getViewport();
|
||||
osg::Viewport::value_type width = viewport->width();
|
||||
osg::Viewport::value_type height = viewport->height();
|
||||
viewUI_ = new OsgViewUI(view_, width, height);
|
||||
osg::Group* root = view_->getSceneData()->asGroup();
|
||||
dyt_check(nullptr != root);
|
||||
root->addChild(viewUI_.get());
|
||||
}
|
||||
|
||||
view_->addEventHandler(new osgViewer::StatsHandler);
|
||||
view_->addEventHandler(new osgGA::StateSetManipulator(view_->getCamera()->getOrCreateStateSet()));
|
||||
initialized_ = true;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
class OsgCameraManipulator;
|
||||
class OsgViewUI;
|
||||
|
||||
class OsgView : public QObject {
|
||||
public:
|
||||
@ -29,6 +30,8 @@ public:
|
||||
void Initialize(OsgCameraManipulator* cameraManipulator);
|
||||
void Uninitialize(void);
|
||||
|
||||
OsgViewUI* GetViewUI(void) const { return viewUI_; }
|
||||
|
||||
bool SetCameraManipulator(OsgCameraManipulator* cameraManipulator);
|
||||
OsgCameraManipulator* GetCameraManipulator(void) const {
|
||||
return cameraManipulator_;
|
||||
@ -40,6 +43,7 @@ protected:
|
||||
private:
|
||||
osg::ref_ptr<osg::GraphicsContext> graphiceWindow_;
|
||||
osg::ref_ptr<osgViewer::View> view_;
|
||||
osg::ref_ptr<OsgViewUI> viewUI_;
|
||||
OsgCameraManipulator* cameraManipulator_{ nullptr };
|
||||
bool initialized_{ false };
|
||||
};
|
||||
|
67
src/viewer/OsgViewUI.cpp
Normal file
67
src/viewer/OsgViewUI.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "viewer/OsgViewUI.h"
|
||||
|
||||
#include <osg/Matrix>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
|
||||
#include "config.h"
|
||||
#include "common/SpdLogger.h"
|
||||
#include "viewer/KeyMapQtOsg.h"
|
||||
#include "viewer/OsgCameraManipulator.h"
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
|
||||
OsgViewUI::OsgViewUI(osgViewer::View* view/*= 0*/,
|
||||
osgWidget::point_type width, osgWidget::point_type height) noexcept
|
||||
: osgWidget::WindowManager(view, width, height, MASK_2D, 0) {
|
||||
hudCamera_ = createParentOrthoCamera();
|
||||
dyt_check(hudCamera_);
|
||||
hudCamera_->setName("OsgViewUI");
|
||||
|
||||
osg::Group* root = view->getSceneData()->asGroup();
|
||||
root->addChild(hudCamera_);
|
||||
|
||||
view->addEventHandler(new osgWidget::MouseHandler(this));
|
||||
view->addEventHandler(new osgWidget::KeyboardHandler(this));
|
||||
view->addEventHandler(new osgWidget::ResizeHandler(this, hudCamera_));
|
||||
view->addEventHandler(new osgWidget::CameraSwitchHandler(this, hudCamera_));
|
||||
view->addEventHandler(new osgViewer::WindowSizeHandler());
|
||||
|
||||
}
|
||||
|
||||
void OsgViewUI::Resize(double width, double height) {
|
||||
setSize(width, height);
|
||||
setWindowSize(width, height);
|
||||
hudCamera_->setProjectionMatrix(osg::Matrix::ortho2D(0.0, width, 0.0f, height));
|
||||
|
||||
for (auto& ui : viewUIs_) {
|
||||
ui->OnResize(width, height);
|
||||
}
|
||||
|
||||
resizeAllWindows();
|
||||
}
|
||||
|
||||
void OsgViewUI::AddUI(OsgViewUI::ViewUI* viewUI) {
|
||||
if (nullptr == viewUI) {
|
||||
return;
|
||||
}
|
||||
for (auto& ui : viewUIs_) {
|
||||
if (ui == viewUI) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
viewUI->InitUI(this);
|
||||
viewUIs_.push_back(viewUI);
|
||||
}
|
||||
|
||||
void OsgViewUI::RemoveUI(OsgViewUI::ViewUI* viewUI) {
|
||||
for (auto it = viewUIs_.begin(); it != viewUIs_.end(); ++it) {
|
||||
if (*it == viewUI) {
|
||||
viewUIs_.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
37
src/viewer/OsgViewUI.h
Normal file
37
src/viewer/OsgViewUI.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <osgWidget/WindowManager>
|
||||
|
||||
class OsgViewUI : public osgWidget::WindowManager {
|
||||
public:
|
||||
class ViewUI : public osg::Referenced {
|
||||
friend class OsgViewUI;
|
||||
public:
|
||||
virtual ~ViewUI() = default;
|
||||
virtual void InitUI(OsgViewUI* ui ) = 0;
|
||||
virtual void OnResize(double width, double height) = 0;
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
OsgViewUI(osgViewer::View* = 0,
|
||||
osgWidget::point_type = 0.0f,
|
||||
osgWidget::point_type = 0.0f) noexcept;
|
||||
~OsgViewUI() override = default;
|
||||
|
||||
osg::Camera* GetHUDCamera() const {
|
||||
return hudCamera_.get();
|
||||
}
|
||||
|
||||
void Resize(double width, double height);
|
||||
|
||||
void AddUI(OsgViewUI::ViewUI* viewUI);
|
||||
void RemoveUI(OsgViewUI::ViewUI* viewUI);
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Camera> hudCamera_;
|
||||
std::vector<osg::ref_ptr<ViewUI>> viewUIs_;
|
||||
|
||||
};
|
@ -24,10 +24,12 @@
|
||||
#include "viewer/OsgViewer.h"
|
||||
#include "viewer/OsgCameraManipulator.h"
|
||||
#include "viewer/CameraControlManipulator.h"
|
||||
#include "viewer/OsgViewUI.h"
|
||||
#include "scene/OsgScene.h"
|
||||
#include "workspace/WorkSpace.h"
|
||||
#include "workspace/WorkSpaceManager.h"
|
||||
#include "scene/SceneContent.h"
|
||||
#include "scene/ui/OESceneUI.h"
|
||||
#include "ui/MainFrame.h"
|
||||
|
||||
|
||||
@ -313,7 +315,6 @@ void QtOsgViewWidget::Initialize(void) {
|
||||
setMouseTracking(true);
|
||||
|
||||
activeScene_ = new OEScene;
|
||||
|
||||
activeScene_->AttachView(view_);
|
||||
activeScene_->InitEventHandle(view_);
|
||||
|
||||
@ -344,7 +345,9 @@ void QtOsgViewWidget::Initialize(void) {
|
||||
OsgCameraManipulator* cameraManipulator = new OsgCameraManipulator(manipulator, this);
|
||||
view_->Initialize(cameraManipulator);
|
||||
|
||||
//activeScene_
|
||||
OsgViewUI* viewUI = view_->GetViewUI();
|
||||
dyt_check(nullptr != viewUI);
|
||||
viewUI->AddUI(activeScene_->GetOrCreateSceneUI());
|
||||
}
|
||||
|
||||
void QtOsgViewWidget::Uninitialize(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user