add scutheon

This commit is contained in:
jiegeaiai 2025-02-09 22:49:40 +08:00
parent 84849a25bc
commit 5d86df20ba
5 changed files with 888 additions and 0 deletions

41
doc/dyt修改.txt Normal file
View File

@ -0,0 +1,41 @@
1.参数编辑时候崩溃bug。参数编辑窗口添加点击参数名称在蓝色状态时候点击字母按键会崩溃。后续进行过某些操作就不会崩溃了。
解决方案
a、修改当前的crash
2.参数编辑第一次生成matlabparam还是在workspace下后续生成在release下simmatlab文件需要保存在release下才能运行。参数文件和运行的.m文件路径需要统一
解决方案
a、放到想定空间所在的目录
3.窗口1的Report和窗口2的Report Table 展示的是不是同样的内容如果是可以删除一个。需要在窗口1或2看的report时候通过窗口管理拖动实现。
解决方案
a、保留窗口2的Report Table
b、窗口2中的Report Table, 可以拖动变成dock模式添加到其他的窗口中
c、有缩放属性的控件鼠标都显示为双箭头
d、所有的窗口表头可以采用拖动的形式调整列的位置
4.需要连续用到的操作、功能类似的放到一个大界面。这些不知道具体怎么分就需要讨论细分一下比如:
功能控制一样的窗口管理和ui设置都是控制界面的放到同一个栏目
解决方案
a、窗口管理放到系统管理里面点击按钮弹出菜单可以勾选
操作步骤连续的①参数编辑②MatlabParam文件关联③SimMatlab关联④运行.m文件。这些放到一块方便操作
解决方案
a、暂时不动
5.关联文件时候更改文件的按键不太明显。
解决方案
a、属性控件文件选择按钮不明显
b、属性控件中间的分割线能左右移动
6.提供的轨迹文件是如何输入到dyt界面的我们需要知道。
解决方案
a、下次发版带一个配置好的空间想定
7.属性、实体、report等这些窗口加上稍微明显一点的边界然后点击边界拖动时候改变窗口大小或者改变位置。就和桌面上的文件一样任意改变窗口大小和位置。
解决方案
a、界面美化层次感
b、鼠标拖动放大缩小之后松开鼠标再次拖动无法缩小
c、所有窗口都用dock形式用户随意拖动放置到其他窗口中
d、窗口布局影响窗口位置
e、窗口会自动变大
f、report窗口能分离出来

View File

@ -0,0 +1,513 @@
#include "entities/ScutcheonComponent.h"
#include <osgViewer/Renderer>
Scutcheon::Scutcheon() {
}
Scutcheon::Scutcheon(const QString& titleText, osg::ref_ptr<osg::MatrixTransform> targetObj) :
osgWidget::Box("Scutcheon", osgWidget::Box::VERTICAL),
mTargetObj(targetObj),
mIndex(0),
mIsVisible(true),
mIsItemVisible(true),
mIsMouseDrag(false),
mIsMousePush(false) {
getBackground()->setColor(1.0, 1.0, 1.0, 0.5);
setEventMask(osgWidget::EVENT_ALL);
attachMoveCallback();
mTitleText = titleText;
addLabelTitle(titleText);
}
Scutcheon::~Scutcheon() {
}
void Scutcheon::addLabelTitle(const QString& titleText) {
osg::ref_ptr<osgWidget::Label> labelTitle = new osgWidget::Label("labelTitle");
labelTitle->setFont(FONT_TEXT);
labelTitle->setFontSize(14);
labelTitle->setFontColor(1.0f, 1.0f, 0.0f, 1.0f);
labelTitle->setColor(1.0f, 1.0f, 1.0f, 0.3f);
labelTitle->addSize(128.0f, 32.0f);
//labelTitle->setEventMask(osgWidget::EVENT_MOUSE_DRAG);
//labelTitle->addCallback(new osgWidget::Callback(&osgScutcheon::callbackMousePush, this, osgWidget::EVENT_MOUSE_DRAG));
//labelTitle->setShadow(0.08f);
labelTitle->setCanFill(true);
labelTitle->setImage(TITLE_IMAGE);
labelTitle->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
labelTitle->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
labelTitle->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
labelTitle->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
osgText::String labelString = TextCodecUtils::QStringToOsgTextString(titleText);
labelTitle->setLabel(labelString);
addWidget(labelTitle);
}
void Scutcheon::addLabelItem(const QString& labelText) {
++mIndex;
ScutcheonMenu* labelItem = new ScutcheonMenu(labelText, this);
labelItem->setIndex(mIndex);
mLabelItemManager.push_back(labelItem);
addWidget(labelItem);
}
void Scutcheon::addLabelItem(ScutcheonMenu& labelItem) {
++mIndex;
labelItem.setIndex(mIndex);
mLabelItemManager.push_back(&labelItem);
if (mIsItemVisible) {
addWidget(&labelItem);
}
}
void Scutcheon::moveLabelItem() {
int x = this->getX();
int y = this->getY();
for (int i = 0; i < mLabelItemManager.size(); ++i) {
ScutcheonMenu* labelItem = mLabelItemManager.at(i);
labelItem->moveTo(x, y);
}
}
bool Scutcheon::callbackMouseDrag(osgWidget::Event& ev) {
return true;
}
bool Scutcheon::mouseDrag(double, double, const osgWidget::WindowManager*) {
qDebug() << "osgScutcheon mouseDrag called";
mIsMouseDrag = true;
return true;
}
bool Scutcheon::mousePush(double, double, const osgWidget::WindowManager*) {
mIsMousePush = true;
qDebug() << "osgScutcheon mousePush called" << mIsMousePush << ":" << mTitleText;
return true;
}
bool Scutcheon::mouseRelease(double, double, const osgWidget::WindowManager*) {
qDebug() << "osgScutcheon mouseRelease called" << mIsMouseDrag << ":" << mTitleText;
if (!mIsMouseDrag) {
if (mIsMousePush && mIsItemVisible) {
std::vector<osg::ref_ptr<ScutcheonMenu> >::const_iterator it;
for (it = mLabelItemManager.begin(); it != mLabelItemManager.end(); ++it) {
(*it)->getChildMenu()->hide();
this->removeWidget((*it));
qDebug() << "item removed!" << (*it)->getIndex();
}
} else {
if (this->getNumChildren() <= mLabelItemManager.size()) {
std::vector<osg::ref_ptr<ScutcheonMenu> >::const_iterator it;
for (it = mLabelItemManager.begin(); it != mLabelItemManager.end(); ++it) {
this->addWidget((*it));
qDebug() << "item added!" << (*it)->getIndex();
}
}
}
mIsItemVisible = !mIsItemVisible;
}
mIsMousePush = false;
mIsMouseDrag = false;
return true;
}
std::vector<osg::ref_ptr<ScutcheonMenu> > Scutcheon::getLabelItemManager() const {
return mLabelItemManager;
}
void Scutcheon::onMouseEvent(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* viewer) {
int etype = ea.getEventType();
if (etype == ea.FRAME) {
if (mTargetObj) {
osg::Vec3 position = mTargetObj->getMatrix().getTrans() + osg::Vec3d(0, 0, 0);
osgViewer::Renderer* renderer = dynamic_cast<osgViewer::Renderer*>(viewer->getCamera()->getRenderer());
osg::Vec3 renderPos;
renderer->getSceneView(0)->projectObjectIntoWindow(position, renderPos);
float x = this->getX();
float y = this->getY();
float w = this->getWidth();
float h = this->getHeight();
float offset = 0.0;
osg::Vec3 stPt(x + 0.5 * w, y + 0.5 * h, 0);
if (stPt.y()- renderPos.y()>0.5*h)
{
stPt[1] = stPt.y()-0.5*h+offset;
}
else if (stPt.y()- renderPos.y()<-0.5*h)
{
stPt[1] = stPt.y()+0.5*h+offset;
}
if (stPt.x()- renderPos.x()>0.5*w)
{
stPt[0] = stPt.x()-0.5*w-offset;
}
else if (stPt.x()- renderPos.x()<-0.5*w)
{
stPt[0] = stPt.x()+0.5*w-offset;
}
setPos(renderPos + osg::Vec3d(50, 50, 50));
createLine(stPt, renderPos);
}
}
if ((etype == ea.PUSH) && ea.getButtonMask() == ea.LEFT_MOUSE_BUTTON) {
if (mIsMousePush) {
//qDebug() << "mousePush called" ;
m_LBDownPt.set(ea.getX(), ea.getY(), 0);
m_LastPt = m_LBDownPt;
}
}
if ((etype == ea.DRAG)) {
//qDebug() << "mouseDrag called" ;
if (mIsMouseDrag) {
osg::Vec3 pt(ea.getX() - m_LastPt[0], ea.getY() - m_LastPt[1], 0);
setOffset(m_offset + pt);
m_LastPt.set(ea.getX(), ea.getY(), 0);
ea.setHandled(true);
}
}
if ((etype == ea.RELEASE)) {
//qDebug() << "mouseDrag release" ;
}
}
void Scutcheon::setPos(osg::Vec3 pos) {
m_pos = pos;
pos = m_pos + m_offset;
this->setOrigin(pos.x(), pos.y());
this->update();
moveLabelItem();
}
void Scutcheon::setOffset(osg::Vec3 offset) {
m_offset = offset;
offset = m_pos + m_offset;
this->setOrigin(offset.x(), offset.y());
this->update();
moveLabelItem();
}
osg::ref_ptr<osg::MatrixTransform> Scutcheon::getTargetObject() {
return mTargetObj;
}
int Scutcheon::getItemCount() {
return mLabelItemManager.size();
}
void Scutcheon::setVisibility(bool b) {
mIsVisible = b;
if (mIsVisible) {
this->show();
m_line->setNodeMask(1);
} else {
this->hide();
m_line->setNodeMask(0);
for (int i = 0; i < mLabelItemManager.size(); i++) {
mLabelItemManager.at(i)->getChildMenu()->hide();
}
}
}
void Scutcheon::createLine(const osg::Vec3& startPt, const osg::Vec3& endPt) {
if (NULL == m_line) {
m_line = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(startPt);
vertices->push_back(endPt);
m_line->setVertexArray(vertices);
osg::Vec3Array* normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
m_line->setNormalArray(normals);
m_line->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0, 1.0, 0.0, 1.0));
m_line->setColorArray(colors);
m_line->setColorBinding(osg::Geometry::BIND_OVERALL);
m_line->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, 2));
m_line->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//m_line->getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(1.0f),osg::StateAttribute::ON);
m_line->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
osg::Geode* geode = new osg::Geode();
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->addDrawable(m_line);
//this->addChild(geode);
this->getWindowManager()->addChild(geode);
} else {
osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(m_line->getVertexArray());
(*vertices)[0].set(startPt.x(), startPt.y(), 0.0);
(*vertices)[1].set(endPt.x(), endPt.y(), 0.0);
vertices->dirty();
m_line->setVertexArray(vertices);
m_line->dirtyDisplayList();
}
}
///////////////////////////////////////////////////////////////
/// \brief osgScutcheonManager::osgScutcheonManager
/// 标牌管理器
/// ///////////////////////////////////////////////////////////
ScutcheonManager* ScutcheonManager::m_pInstance = NULL;
ScutcheonManager::ScutcheonManager(osgViewer::Viewer* pViewer, osg::Group* pScreneRoot) {
m_bVisible = true;
mWindowManager = new osgWidget::WindowManager(pViewer, 50.0f, 50.0f, 1, /*0xF0000000*/
osgWidget::WindowManager::WM_PICK_DEBUG);
osg::Camera* camera = mWindowManager->createParentOrthoCamera();
pScreneRoot->addChild(camera);
/*pViewer->addEventHandler(new osgWidget::MouseHandler(mWindowManager));
pViewer->addEventHandler(new osgWidget::KeyboardHandler(mWindowManager));
pViewer->addEventHandler(new osgWidget::ResizeHandler(mWindowManager, camera));
pViewer->addEventHandler(new osgWidget::CameraSwitchHandler(mWindowManager, camera));*/
}
ScutcheonManager::~ScutcheonManager() {
m_bGUIStoped = true;
clear();
}
ScutcheonManager* ScutcheonManager::instance() {
if (NULL == m_pInstance) {
//osgViewer::Viewer* getOSGViewer(){ return m_pViewer; }
//osg::Group* getRoot(){ return m_pRoot.get(); }
/* m_pInstance = new osgScutcheonManager(GraphicsView::instance()->getOSGViewer(),
GraphicsView::instance()->getRoot());
GraphicsView::instance()->getOSGViewer()->addEventHandler(m_pInstance);*/
}
return m_pInstance;
}
void ScutcheonManager::destroy() {
if (NULL != m_pInstance) {
delete m_pInstance;
m_pInstance = NULL;
}
}
bool ScutcheonManager::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) {
if (m_bStopGUI) {
m_bGUIStoped = true;
} else {
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
int nCount = m_LabelList.size();
for (int i = 0; i < nCount; i++) {
m_LabelList[i]->onMouseEvent(ea, viewer);
}
}
return false;
}
int ScutcheonManager::addLabel(Scutcheon* label) {
m_bVisible = true;
if (label == NULL) {
return 0;
}
lock(true);
// while (!m_bStopGUI) QThread::sleep(100);
int nCount = m_LabelList.size();
for (int i = 0; i < nCount; i++) {
if (m_LabelList[i] == label) {
lock(false);
return 0;
}
}
mWindowManager->addChild(label);
mWindowManager->resizeAllWindows();
m_LabelList.push_back(label);
lock(false);
return m_LabelList.size();
}
int ScutcheonManager::delLabel(Scutcheon*& label) {
lock(true);
while (!m_bStopGUI) QThread::sleep(100);
for (std::vector<Scutcheon*>::iterator vit = m_LabelList.begin(); vit != m_LabelList.end(); vit++) {
if ((*vit) == label) {
m_LabelList.erase(vit);
//label->setVisibility(false);
delete label;
label = NULL;
lock(false);
return m_LabelList.size();
}
}
lock(false);
return 0;
}
int ScutcheonManager::delLabel(osg::MatrixTransform* tethernode) {
return 0;
}
void ScutcheonManager::clear() {
lock(true);
//while (!m_bGUIStoped) Sleep(200);
while (m_LabelList.size() > 0) {
Scutcheon* back = m_LabelList.back();
delLabel(back);
}
lock(false);
}
void ScutcheonManager::lock(bool b) {
if (b) {
m_bStopGUI = true;
m_bGUIStoped = false;
} else {
m_bStopGUI = false;
m_bGUIStoped = true;
}
}
osg::ref_ptr<osgWidget::WindowManager> ScutcheonManager::getWindowManager() const {
return mWindowManager;
}
ScutcheonMenu::ScutcheonMenu(const QString& label, osg::ref_ptr<Scutcheon> parentMenu) :
osgWidget::Label("menu1"),
mChildMenu(NULL),
mParentMenu(parentMenu),
mHasChildMenu(false),
mIndex(0),
mMenuItemCount(0) {
initLabel(label);
}
void ScutcheonMenu::addChildMenu(const QString& menuText) {
ImageLabel* childMenuContent = new ImageLabel(menuText);
if (mChildMenu == NULL) {
mChildMenu = new osgWidget::Box("childMenu", osgWidget::Box::VERTICAL, true);
mChildMenu->addWidget(childMenuContent);
mMenuItemManager.push_back(childMenuContent);
mChildMenu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.6f);
mChildMenu->resize();
mChildMenu->hide();
mHasChildMenu = true;
//mParentMenu->addChild(mChildMenu);
mParentMenu->getWindowManager()->addChild(mChildMenu.get());
} else {
mChildMenu->addWidget(childMenuContent);
mMenuItemManager.push_back(childMenuContent);
}
++mMenuItemCount;
}
void ScutcheonMenu::updateChildMenuText(int index, QString labelText) {
if (index >= 0 && index < getMenuItemCount()) {
//mMenuItemManager.at(index)->setLabelText(labelText);
}
}
void ScutcheonMenu::initLabel(const QString& labelText) {
setFont(FONT_TEXT);
setFontSize(15);
setFontColor(0.0f, 0.0f, 1.0f, 1.0f);
addSize(128.0f, 32.0f);
setColor(1.0f, 1.0f, 0.0f, 0.6f);
//setShadow(0.08f);
setCanFill(true);
setEventMask(osgWidget::EVENT_ALL);
setImage(ITEM_IAMGE);
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);
osgText::String labelString = TextCodecUtils::QStringToOsgTextString(labelText);
setLabel(labelString);
}
void ScutcheonMenu::hideOtherChildMenu() {
for (int i = 0; i < mParentMenu->getLabelItemManager().size(); i++) {
osg::ref_ptr<ScutcheonMenu> childItem = mParentMenu->getLabelItemManager().at(i);
if (childItem->getChildMenu() != mChildMenu) {
childItem->getChildMenu()->hide();
}
qDebug() << "hideOtherChildMenu";
}
}
void ScutcheonMenu::hideAllChildMenu(osgWidget::WindowManager* wm) {
osgWidget::Window* tmp = 0;
unsigned int count = wm->getNumChildren();
for (unsigned int i = 0; i < count; ++i) {
tmp = dynamic_cast<osgWidget::Window*>(wm->getChild(i));
if (tmp) {
QString name = QString::fromStdString(tmp->getName());
if (tmp != mChildMenu.get() && name == "childMenu") {
if (tmp->isVisible()) {
tmp->hide();
}
}
}
}
}
bool ScutcheonMenu::mousePush(double, double, const osgWidget::WindowManager* wm) {
hideOtherChildMenu();
//hideAllChildMenu(mParentMenu->getWindowManager());
if (!mChildMenu->isVisible()) {
mChildMenu->show();
qDebug() << "hideOtherChildMenu show";
} else {
mChildMenu->hide();
qDebug() << "hideOtherChildMenu hide";
}
return true;
}
ImageLabel::ImageLabel(const QString& labelText) : osgWidget::Label("menu1") {
setFont(FONT_TEXT);
setFontSize(13);
setFontColor(0.0f, 0.2f, 1.0f, 1.0f);
addSize(128.0f, 32.0f);
setColor(1.0f, 1.0f, 1.0f, 0.6f);
//setPadding(1.0f);
//setShadow(0.08f);
setCanFill(true);
setEventMask(osgWidget::EVENT_ALL);
setImage(ITEM_IAMGE);
setLabelText(labelText);
}
void ImageLabel::setLabelText(QString labelText) {
setAlignHorizontal(osgWidget::Widget::HA_LEFT);
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);
osgText::String labelString = TextCodecUtils::QStringToOsgTextString(labelText);
setLabel(labelString);
}

View File

@ -0,0 +1,255 @@
/**
* @brief
* @author hph
* @date 2018/07/07
*/
#ifndef OSGSCUTCHEON_H
#define OSGSCUTCHEON_H
#include <QObject>
#include <iostream>
#include <sstream>
#include <QDebug>
#include <QTextCodec>
#include <QVector>
#include <QThread>
#include <osgWidget/Box>
#include <osgWidget/Label>
#include <osgWidget/WindowManager>
#include "utils/TextCodecUtil.h"
#define FONT_TEXT "fonts/simhei.ttf"
#define TITLE_IMAGE "../publish/data/texture/mark/label_title.png"
#define ITEM_IAMGE "../publish/data/texture/mark/label_normal_01.png"
class ScutcheonMenu;
class ImageLabel;
class Scutcheon : public osgWidget::Box {
public:
Scutcheon();
Scutcheon(const QString& titleText, osg::ref_ptr<osg::MatrixTransform> targetObj);
~Scutcheon();
public:
void addLabelTitle(const QString& titleText);
void addLabelItem(const QString& labelText);
void addLabelItem(ScutcheonMenu& labelItem);
void hideOtherLabelItem();
void moveLabelItem();
void createLine(const osg::Vec3& startPt = osg::Vec3(0, 0, 0), const osg::Vec3& endPt = osg::Vec3(0, 0, 0));
void onMouseEvent(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer* viewer);
osg::Geometry* getLine() const {
return m_line;
}
int getItemCount();
void setVisibility(bool b);
bool getVisibility() {
return mIsVisible;
}
void setPos(osg::Vec3 pos);
void setOffset(osg::Vec3 offset);
osg::ref_ptr<osg::MatrixTransform> getTargetObject();
std::vector<osg::ref_ptr<ScutcheonMenu> > getLabelItemManager() const;
private:
bool callbackMouseDrag(osgWidget::Event& ev);
protected:
bool mouseDrag(double, double, const osgWidget::WindowManager*);
bool mousePush(double, double, const osgWidget::WindowManager*);
bool mouseRelease(double, double, const osgWidget::WindowManager*);
public:
QString mTitleText;
std::vector<osg::ref_ptr<ScutcheonMenu> > mLabelItemManager;
int mIndex;
osg::ref_ptr<osg::MatrixTransform> mTargetObj;
osg::ref_ptr<osg::Geometry> m_line;
bool mIsVisible;
bool mIsItemVisible;
bool mIsMousePush;
bool mIsMouseDrag;
osg::Vec3 m_pos;
osg::Vec3 m_offset;
osg::Vec3 m_LastPt;
osg::Vec3 m_LBDownPt;
};
class ScutcheonManager : public osgGA::GUIEventHandler {
protected:
ScutcheonManager(osgViewer::Viewer* pViewer, osg::Group* pScreneRoot);
~ScutcheonManager();
public:
static ScutcheonManager* instance();
static void destroy();
bool handle(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&);
int addLabel(Scutcheon* label);
int delLabel(Scutcheon*& label);
int delLabel(osg::MatrixTransform* tethernode);
void clear();
void lock(bool b);
void setVisibility(bool b);
void setVisibilityByID(unsigned int ID, bool b);
bool getVisibilityByID(unsigned int ID);
bool getVisibility() const {
return m_bVisible;
}
void setLabelTxtColor(const osg::Vec4f& color);
void setLabelBgColor(const osg::Vec4f& color);
const osg::Vec4f& getLabelTxtColor() const {
return m_clrTxt;
}
const osg::Vec4f& getLabelBgColor() const {
return m_clrBg;
}
osg::ref_ptr<osgWidget::WindowManager> getWindowManager() const;
public:
static ScutcheonManager* m_pInstance;
osg::ref_ptr<osgWidget::WindowManager> mWindowManager;
//osgWidget::WindowManager* mWindowManager;
std::vector<Scutcheon*> m_LabelList;
bool m_bStopGUI;
bool m_bGUIStoped;
bool m_bVisible;
osg::Vec4f m_clrTxt;
osg::Vec4f m_clrBg;
};
class ScutcheonMenu : public osgWidget::Label {
public:
ScutcheonMenu(const QString& label, osg::ref_ptr<Scutcheon> parentMenu);
void addChildMenu(const QString& menuText);
void updateChildMenuText(int index, QString labelText);
void initLabel(const QString& labelText);
void setIndex(int index) {
mIndex = index;
}
void moveTo(int parentX, int parentY) {
if (mChildMenu) {
mChildMenu->setOrigin(parentX + 128.0, parentY + 32.0 * mIndex);
mChildMenu->update();
}
}
bool isHasChildMenu() {
return mHasChildMenu;
}
osg::ref_ptr<osgWidget::Window> getChildMenu() {
return mChildMenu;
}
int getIndex() {
return mIndex;
}
int getMenuItemCount() {
return mMenuItemManager.size();
}
void hideOtherChildMenu();
void hideAllChildMenu(osgWidget::WindowManager* wm);
void managed(osgWidget::WindowManager* wm) {
osgWidget::Label::managed(wm);
if (mChildMenu) {
mChildMenu->hide();
}
}
void positioned() {
osgWidget::Label::positioned();
if (mChildMenu) {
//qDebug() << "mChildMenu not NULL!!" << mIndex;
mChildMenu->setOrigin(mParentMenu->getX() + 128.0, mParentMenu->getY() + 32.0 * mIndex);
}
}
bool mousePush(double, double, const osgWidget::WindowManager* wm);
bool mouseEnter(double, double, const osgWidget::WindowManager*) {
setColor(1.0f, 1.0f, 1.0f, 0.3f);
return true;
}
bool mouseLeave(double, double, const osgWidget::WindowManager*) {
setColor(1.0f, 1.0f, 1.0f, 0.6f);
return true;
}
public:
QVector<osg::ref_ptr<ImageLabel> > mMenuItemManager;
private:
osg::ref_ptr<osgWidget::Box> mChildMenu;
osg::ref_ptr<Scutcheon> mParentMenu;
int mIndex;
int mMenuItemCount;
bool mHasChildMenu;
};
class ImageLabel : public osgWidget::Label {
public:
ImageLabel(const QString& labelText);
void setLabelText(QString labelText);
bool mousePush(double, double, const osgWidget::WindowManager*) {
return true;
}
bool mouseDrag(double, double, const osgWidget::WindowManager*) {
//osg::notify(osg::NOTICE) << _name << " > mouseDrag called" << std::endl;
return false;
}
bool mouseEnter(double, double, const osgWidget::WindowManager*) {
//setColor(1.0f, 1.0f, 1.0f, 1.0f);
setFontColor(0.0f, 0.0f, 1.0f, 1.0f);
return true;
}
bool mouseLeave(double, double, const osgWidget::WindowManager*) {
//setColor(1.0f, 1.0f, 1.0f, 0.8f);
setFontColor(0.0f, 0.2f, 1.0f, 1.0f);
return true;
}
bool mouseOver(double, double, const osgWidget::WindowManager*) {
return true;
}
};
#endif // OSGSCUTCHEON_H

View File

@ -0,0 +1,64 @@
#include "utils/TextCodecUtil.h"
#include <sstream>
#include <string>
#include <iomanip>
#include <vector>
#include <osgText/Text>
#include "common/SpdLogger.h"
std::string TextCodecUtils::UnicodeToUTF8(const std::wstring& src) {
std::string result;
int n = WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, 0, 0, 0, 0);
result.resize(n);
::WideCharToMultiByte(CP_UTF8, 0, src.c_str(), -1, (char*)result.c_str(), result.length(), 0, 0);
return result;
}
std::wstring TextCodecUtils::Gb2312ToUnicode(const std::string& src) {
std::wstring result;
int n = MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, NULL, 0);
result.resize(n);
::MultiByteToWideChar(CP_ACP, 0, src.c_str(), -1, (LPWSTR)result.c_str(), result.length());
return result;
}
std::string TextCodecUtils::Gb2312ToUTF8(const std::string& src) {
std::string result;
result = UnicodeToUTF8(Gb2312ToUnicode(src));
return result;
}
std::string TextCodecUtils::QStringToOsgTextToStdString(QString& srcString) {
osgText::String dstString;
osg::ref_ptr<osgText::Text> text = new osgText::Text;
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("fonts/simhei.ttf");
text->setFont(font);
const std::string tmpStr = srcString.toStdString();
text->setText(tmpStr, osgText::String::ENCODING_UTF8);
dstString = text->getText();
return dstString.createUTF8EncodedString();
}
QString TextCodecUtils::AsciiToUTF8(std::string& src) {
setlocale(LC_ALL, "chs");
wchar_t wcsStr[100];
swprintf(wcsStr, L"%S", src.c_str());
QString placeName = QString::fromWCharArray(wcsStr);
return placeName;
//return "";
}
osgText::String TextCodecUtils::QStringToOsgTextString(const QString& srcString) {
osgText::String dstString;
osg::ref_ptr<osgText::Text> text = new osgText::Text;
osg::ref_ptr<osgText::Font> font = osgText::readFontFile("fonts/simhei.ttf");
text->setFont(font);
const std::string tmpStr = srcString.toStdString();
text->setText(tmpStr, osgText::String::ENCODING_UTF8);
dstString = text->getText();
return dstString;
}

15
src/utils/TextCodecUtil.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <string>
#include <QString>
#include <osgText/String>
class TextCodecUtils {
public:
static std::string UnicodeToUTF8(const std::wstring& src);
static std::wstring Gb2312ToUnicode(const std::string& src);
static std::string Gb2312ToUTF8(const std::string& src);
static std::string QStringToOsgTextToStdString(QString& srcString);
static osgText::String QStringToOsgTextString(const QString& srcString);
static QString AsciiToUTF8(std::string& src);
};