-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathInteractiveUI.cpp
126 lines (106 loc) · 5.63 KB
/
InteractiveUI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ============================================================================
**
** Demonstration of the event handling in osgNoesisGUI
** Copyright (C) 2012 Wang Rui
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** ========================================================================= */
#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osgDB/ReadFile>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/Viewer>
#include "Common/NoesisWrapper.h"
class CustomNoesisDrawable : public NoesisDrawable
{
public:
CustomNoesisDrawable( const std::string& uiFile )
: NoesisDrawable(uiFile) {}
protected:
virtual void registerEventHandlers()
{
Noesis::Gui::FrameworkElement* framework = NsStaticCast<Noesis::Gui::FrameworkElement*>( getUIRoot() );
if ( !framework ) return;
Noesis::Gui::ComboBox* combo0 = NsStaticCast<Noesis::Gui::ComboBox*>( framework->FindName("Background") );
if ( combo0 ) combo0->SelectionChanged() += Noesis::Core::MakeDelegate( this, &CustomNoesisDrawable::backgroundChanged );
Noesis::Gui::ComboBox* combo1 = NsStaticCast<Noesis::Gui::ComboBox*>( framework->FindName("Lights") );
if ( combo1 ) combo1->SelectionChanged() += Noesis::Core::MakeDelegate( this, &CustomNoesisDrawable::lightsChanged );
Noesis::Gui::ComboBox* combo2 = NsStaticCast<Noesis::Gui::ComboBox*>( framework->FindName("Visualization") );
if ( combo2 ) combo2->SelectionChanged() += Noesis::Core::MakeDelegate( this, &CustomNoesisDrawable::visualizationChanged );
Noesis::Gui::Slider* slider = NsStaticCast<Noesis::Gui::Slider*>( framework->FindName("Luminance") );
if ( slider ) slider->ValueChanged() += Noesis::Core::MakeDelegate( this, &CustomNoesisDrawable::luminanceChanged );
}
void backgroundChanged( Noesis::Core::BaseComponent* sender, const Noesis::Gui::SelectionChangedEventArgs& e )
{
Noesis::Gui::ComboBox* combo = NsStaticCast<Noesis::Gui::ComboBox*>( sender );
std::cout << "Select background index: " << combo->GetSelectedIndex() << std::endl;
}
void lightsChanged( Noesis::Core::BaseComponent* sender, const Noesis::Gui::SelectionChangedEventArgs& e )
{
Noesis::Gui::ComboBox* combo = NsStaticCast<Noesis::Gui::ComboBox*>( sender );
std::cout << "Select light index: " << combo->GetSelectedIndex() << std::endl;
}
void visualizationChanged( Noesis::Core::BaseComponent* sender, const Noesis::Gui::SelectionChangedEventArgs& e )
{
Noesis::Gui::ComboBox* combo = NsStaticCast<Noesis::Gui::ComboBox*>( sender );
std::cout << "Select visualization index: " << combo->GetSelectedIndex() << std::endl;
}
void luminanceChanged( Noesis::Core::BaseComponent* sender, const Noesis::Gui::RoutedPropertyChangedEventArgs<NsFloat32>& e )
{
std::cout << "Set luminance value: " << e.newValue << std::endl;
}
};
int main( int argc, char** argv )
{
osg::ArgumentParser arguments( &argc, argv );
osg::DisplaySettings::instance()->setMinimumNumStencilBits( 8 );
std::string uiFile("Gui/Tutorials/Integration/DX9/UI.xaml");
arguments.read( "--ui", uiFile );
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);
if ( !scene ) scene = osgDB::readNodeFile("cessna.osg");
osg::ref_ptr<CustomNoesisDrawable> noesis = new CustomNoesisDrawable(uiFile);
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->setCullingActive( false );
geode->addDrawable( noesis.get() );
geode->getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON );
geode->getOrCreateStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearMask( GL_STENCIL_BUFFER_BIT );
camera->setClearStencil( 1 );
camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
camera->setRenderOrder( osg::Camera::POST_RENDER );
camera->setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) );
camera->addChild( geode.get() );
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( scene.get() );
root->addChild( camera.get() );
osgViewer::Viewer viewer;
viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
viewer.addEventHandler( new osgViewer::StatsHandler );
viewer.addEventHandler( new osgViewer::WindowSizeHandler );
viewer.setSceneData( root.get() );
//viewer.setThreadingModel( osgViewer::Viewer::SingleThreaded );
viewer.realize();
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>( viewer.getCamera()->getGraphicsContext() );
if ( gw )
{
// Send a window size event for resizing the UI
int x, y, w, h; gw->getWindowRectangle( x, y, w, h );
viewer.getEventQueue()->windowResize( x, y, w, h );
}
return viewer.run();
}