From Cedric Pinson and Jeremey Moles, Changes to OpenSceneGraph-osgWidget-dev branch.
Notes from Robert Osfield, Merged changes to OpenSceneGraph-osgWidget-dev r9367 (prior to my botched attempt at merged svn/trunk into the branch).
This commit is contained in:
@@ -234,10 +234,10 @@ public:
|
||||
osg::StateSet* setupStateSet()
|
||||
{
|
||||
osg::StateSet* st = new osg::StateSet();
|
||||
|
||||
|
||||
st->setAttributeAndModes(new osg::Material(), true);
|
||||
st->setMode(GL_BLEND, true);
|
||||
|
||||
|
||||
AnimtkStateSetUpdateCallback* callback = new AnimtkStateSetUpdateCallback();
|
||||
osgAnimation::Vec4KeyframeContainer* keys = callback->_sampler->getOrCreateKeyframeContainer();
|
||||
keys->push_back(osgAnimation::Vec4Keyframe(0, osg::Vec4(1,0,0,1)));
|
||||
@@ -248,7 +248,7 @@ osg::StateSet* setupStateSet()
|
||||
keys->push_back(osgAnimation::Vec4Keyframe(10, osg::Vec4(1,0,0,1)));
|
||||
callback->start();
|
||||
st->setUpdateCallback(callback);
|
||||
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
@@ -300,10 +300,10 @@ osg::MatrixTransform* setupAnimtkNode(osg::Geode* staticGeode)
|
||||
node->setUpdateCallback(callback);
|
||||
|
||||
osg::Geode* geode = new osg::Geode();
|
||||
|
||||
|
||||
geode->setStateSet(setupStateSet());
|
||||
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 2)));
|
||||
|
||||
|
||||
node->addChild(geode);
|
||||
|
||||
return node;
|
||||
@@ -312,7 +312,7 @@ osg::MatrixTransform* setupAnimtkNode(osg::Geode* staticGeode)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
|
||||
osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator();
|
||||
|
||||
viewer.setCameraManipulator(tbm);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <osgAnimation/Skeleton>
|
||||
#include <osgAnimation/RigGeometry>
|
||||
#include <osgAnimation/Skinning>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
|
||||
osg::Geode* createAxis()
|
||||
{
|
||||
@@ -178,7 +179,9 @@ int main (int argc, char* argv[])
|
||||
right0->addChild(right1.get());
|
||||
skelroot->addChild(root.get());
|
||||
|
||||
osg::ref_ptr<osgAnimation::AnimationManager> manager = new osgAnimation::AnimationManager;
|
||||
osg::Group* scene = new osg::Group;
|
||||
osg::ref_ptr<osgAnimation::BasicAnimationManager> manager = new osgAnimation::BasicAnimationManager;
|
||||
scene->setUpdateCallback(manager.get());
|
||||
|
||||
osgAnimation::Animation* anim = new osgAnimation::Animation;
|
||||
{
|
||||
@@ -223,7 +226,6 @@ int main (int argc, char* argv[])
|
||||
manager->playAnimation(anim);
|
||||
|
||||
// we will use local data from the skeleton
|
||||
osg::Group* scene = new osg::Group;
|
||||
osg::MatrixTransform* rootTransform = new osg::MatrixTransform;
|
||||
rootTransform->setMatrix(osg::Matrix::rotate(osg::PI_2,osg::Vec3(1,0,0)));
|
||||
right0->addChild(createAxis());
|
||||
@@ -234,9 +236,9 @@ int main (int argc, char* argv[])
|
||||
trueroot->setMatrix(osg::Matrix(root->getMatrixInBoneSpace().ptr()));
|
||||
trueroot->addChild(createAxis());
|
||||
trueroot->setDataVariance(osg::Object::DYNAMIC);
|
||||
rootTransform->addChild(manager.get());
|
||||
// rootTransform->addChild(scene.get());
|
||||
scene->addChild(rootTransform);
|
||||
manager->addChild(skelroot.get());
|
||||
// manager->addChild(skelroot.get());
|
||||
|
||||
osgAnimation::RigGeometry* geom = createTesselatedBox(4, 4.0);
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgAnimation/AnimationManager>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
#include <osgAnimation/Channel>
|
||||
#include <osgAnimation/UpdateCallback>
|
||||
|
||||
@@ -80,10 +80,11 @@ int main (int argc, char* argv[])
|
||||
root->addChild (trans.get());
|
||||
|
||||
// Define a scheduler for our animations
|
||||
osgAnimation::AnimationManager* mng = new osgAnimation::AnimationManager();
|
||||
osg::Group* grp = new osg::Group;
|
||||
osgAnimation::BasicAnimationManager* mng = new osgAnimation::BasicAnimationManager();
|
||||
grp->setUpdateCallback(mng);
|
||||
|
||||
|
||||
mng->addChild(root);
|
||||
grp->addChild(root);
|
||||
|
||||
// And we finaly define our channel
|
||||
osgAnimation::Vec3LinearChannel* channelAnimation1 = new osgAnimation::Vec3LinearChannel;
|
||||
@@ -113,6 +114,6 @@ int main (int argc, char* argv[])
|
||||
mng->playAnimation(anim1);
|
||||
mng->playAnimation(anim2);
|
||||
|
||||
viewer.setSceneData( mng );
|
||||
viewer.setSceneData( grp );
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <osgAnimation/Skinning>
|
||||
#include <osgAnimation/Timeline>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
#include <osgAnimation/TimelineAnimationManager>
|
||||
|
||||
|
||||
struct NoseBegin : public osgAnimation::Action::Callback
|
||||
@@ -54,16 +55,20 @@ struct ExampleTimelineUsage : public osgGA::GUIEventHandler
|
||||
osg::ref_ptr<osgAnimation::StripAnimation> _mainLoop;
|
||||
osg::ref_ptr<osgAnimation::StripAnimation> _scratchHead;
|
||||
osg::ref_ptr<osgAnimation::StripAnimation> _scratchNose;
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerTimeline> _manager;
|
||||
osg::ref_ptr<osgAnimation::TimelineAnimationManager> _manager;
|
||||
|
||||
bool _releaseKey;
|
||||
|
||||
ExampleTimelineUsage(osgAnimation::AnimationManagerTimeline* manager)
|
||||
ExampleTimelineUsage(osgAnimation::TimelineAnimationManager* manager)
|
||||
{
|
||||
_releaseKey = false;
|
||||
_manager = manager;
|
||||
|
||||
osgAnimation::AnimationMap map = _manager->getAnimationMap();
|
||||
const osgAnimation::AnimationList& list = _manager->getAnimationList();
|
||||
osgAnimation::AnimationMap map;
|
||||
for (osgAnimation::AnimationList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||
map[(*it)->getName()] = *it;
|
||||
|
||||
_mainLoop = new osgAnimation::StripAnimation(map["Idle_Main"].get(),0.0,0.0);
|
||||
_mainLoop->setLoop(0); // means forever
|
||||
|
||||
@@ -157,27 +162,26 @@ int main (int argc, char* argv[])
|
||||
osg::ArgumentParser psr(&argc, argv);
|
||||
|
||||
osgViewer::Viewer viewer(psr);
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group();
|
||||
|
||||
std::string file = "osgAnimation/nathan.osg";
|
||||
if(argc >= 2)
|
||||
file = psr[1];
|
||||
|
||||
// replace the manager
|
||||
osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(osgDB::readNodeFile(file));
|
||||
osg::Group* root = dynamic_cast<osg::Group*>(osgDB::readNodeFile(file));
|
||||
osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
|
||||
if(!animationManager)
|
||||
{
|
||||
std::cerr << "Couldn't convert the file's toplevel object into an AnimationManager." << std::endl;
|
||||
std::cerr << "Did not found AnimationManagerBase updateCallback needed to animate elements" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgAnimation::AnimationManagerTimeline> tl = new osgAnimation::AnimationManagerTimeline(*animationManager);
|
||||
|
||||
animationManager->removeChildren(0, animationManager->getNumChildren());
|
||||
osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager);
|
||||
root->setUpdateCallback(tl);
|
||||
ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get());
|
||||
group->addChild(tl.get());
|
||||
group->setEventCallback(callback);
|
||||
group->setUpdateCallback(callback);
|
||||
root->setEventCallback(callback);
|
||||
root->getUpdateCallback()->addNestedCallback(callback);
|
||||
|
||||
|
||||
|
||||
// add the state manipulator
|
||||
@@ -201,7 +205,7 @@ int main (int argc, char* argv[])
|
||||
// add the screen capture handler
|
||||
viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||
|
||||
viewer.setSceneData(group.get());
|
||||
viewer.setSceneData(root);
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgAnimation/AnimationManager>
|
||||
#include <osgAnimation/BasicAnimationManager>
|
||||
|
||||
class AnimtkViewerModelController
|
||||
{
|
||||
@@ -35,11 +35,12 @@ public:
|
||||
return avmc;
|
||||
}
|
||||
|
||||
static bool setModel(osgAnimation::AnimationManager* model)
|
||||
static bool setModel(osgAnimation::BasicAnimationManager* model)
|
||||
{
|
||||
AnimtkViewerModelController& self = instance();
|
||||
self._model = model;
|
||||
self._map = self._model->getAnimationMap();
|
||||
for (osgAnimation::AnimationList::const_iterator it = self._model->getAnimationList().begin(); it != self._model->getAnimationList().end(); it++)
|
||||
self._map[(*it)->getName()] = *it;
|
||||
|
||||
for(osgAnimation::AnimationMap::iterator it = self._map.begin(); it != self._map.end(); it++)
|
||||
self._amv.push_back(it->first);
|
||||
@@ -76,7 +77,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool next()
|
||||
{
|
||||
@@ -110,7 +111,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osgAnimation::AnimationManager> _model;
|
||||
osg::ref_ptr<osgAnimation::BasicAnimationManager> _model;
|
||||
osgAnimation::AnimationMap _map;
|
||||
AnimationMapVector _amv;
|
||||
unsigned int _focus;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgAnimation/AnimationManagerBase>
|
||||
|
||||
const int WIDTH = 1440;
|
||||
const int HEIGHT = 900;
|
||||
@@ -41,7 +42,7 @@ osg::Geode* createAxis()
|
||||
osg::Geometry* geometry = new osg::Geometry();
|
||||
osg::Vec3Array* vertices = new osg::Vec3Array();
|
||||
osg::Vec4Array* colors = new osg::Vec4Array();
|
||||
|
||||
|
||||
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
|
||||
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
|
||||
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
|
||||
@@ -55,7 +56,7 @@ osg::Geode* createAxis()
|
||||
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
|
||||
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
|
||||
geometry->setVertexArray(vertices);
|
||||
geometry->setColorArray(colors);
|
||||
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||
@@ -79,26 +80,28 @@ int main(int argc, char** argv)
|
||||
|
||||
osgViewer::Viewer viewer(psr);
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group();
|
||||
|
||||
osgAnimation::AnimationManager* animationManager = dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1]));
|
||||
|
||||
if(!animationManager)
|
||||
osg::Group* node = dynamic_cast<osg::Group*>(osgDB::readNodeFile(psr[1])); //dynamic_cast<osgAnimation::AnimationManager*>(osgDB::readNodeFile(psr[1]));
|
||||
if(!node)
|
||||
{
|
||||
std::cerr << "Couldn't convert the file's toplevel object into an AnimationManager." << std::endl;
|
||||
std::cerr << "Can't read file " << psr[1]<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set our Singleton's model.
|
||||
AnimtkViewerModelController::setModel(animationManager);
|
||||
osgAnimation::AnimationManagerBase* base = dynamic_cast<osgAnimation::AnimationManagerBase*>(node->getUpdateCallback());
|
||||
osgAnimation::BasicAnimationManager* manager = new osgAnimation::BasicAnimationManager(*base);
|
||||
node->setUpdateCallback(manager);
|
||||
AnimtkViewerModelController::setModel(manager);
|
||||
|
||||
animationManager->addChild(createAxis());
|
||||
node->addChild(createAxis());
|
||||
|
||||
AnimtkViewerGUI* gui = new AnimtkViewerGUI(&viewer, WIDTH, HEIGHT, 0x1234);
|
||||
osg::Camera* camera = gui->createParentOrthoCamera();
|
||||
|
||||
animationManager->setNodeMask(0x0001);
|
||||
|
||||
node->setNodeMask(0x0001);
|
||||
|
||||
group->addChild(animationManager);
|
||||
group->addChild(node);
|
||||
group->addChild(camera);
|
||||
|
||||
viewer.addEventHandler(new AnimtkKeyEventHandler());
|
||||
|
||||
@@ -25,22 +25,22 @@
|
||||
#include <osgWidget/WindowManager>
|
||||
|
||||
class AnimtkViewerGUI: public osgWidget::WindowManager {
|
||||
osg::ref_ptr<osgWidget::Box> _buttonBox;
|
||||
osg::ref_ptr<osgWidget::Box> _listBox;
|
||||
osg::ref_ptr<osgWidget::Box> _labelBox;
|
||||
osg::ref_ptr<osgWidget::Box> _buttonBox;
|
||||
osg::ref_ptr<osgWidget::Box> _listBox;
|
||||
osg::ref_ptr<osgWidget::Box> _labelBox;
|
||||
|
||||
protected:
|
||||
osgWidget::Widget* _createButton(const std::string&);
|
||||
|
||||
bool _buttonPush(osgWidget::Event&);
|
||||
bool _listMouseHover(osgWidget::Event&);
|
||||
osgWidget::Widget* _createButton(const std::string&);
|
||||
|
||||
bool _buttonPush(osgWidget::Event&);
|
||||
bool _listMouseHover(osgWidget::Event&);
|
||||
|
||||
void _createButtonBox();
|
||||
void _createListBox();
|
||||
void _createLabelBox();
|
||||
void _createButtonBox();
|
||||
void _createListBox();
|
||||
void _createLabelBox();
|
||||
|
||||
public:
|
||||
AnimtkViewerGUI(osgViewer::View*, float, float, unsigned int);
|
||||
AnimtkViewerGUI(osgViewer::View*, float, float, unsigned int);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ struct ButtonFunctor: public WidgetSampler
|
||||
float _previous;
|
||||
|
||||
const float _speed;
|
||||
|
||||
|
||||
ButtonFunctor(): _speed(5) { _direction = -_speed; _previous = 0;}
|
||||
|
||||
bool enter(osgWidget::Event& ev)
|
||||
@@ -229,7 +229,7 @@ AnimtkViewerGUI::AnimtkViewerGUI(osgViewer::View* view, float w, float h, unsign
|
||||
osgWidget::Widget* AnimtkViewerGUI::_createButton(const std::string& name)
|
||||
{
|
||||
osgWidget::Widget* b = new osgWidget::Widget(name, 64.0f, 64.0f);
|
||||
|
||||
|
||||
if(!b) return 0;
|
||||
|
||||
b->setImage(IMAGE_PATH + name + ".png", true);
|
||||
@@ -237,7 +237,7 @@ osgWidget::Widget* AnimtkViewerGUI::_createButton(const std::string& name)
|
||||
|
||||
ButtonFunctor* bt = new ButtonFunctor();
|
||||
b->setUpdateCallback(bt);
|
||||
|
||||
|
||||
b->addCallback(new osgWidget::Callback(&ButtonFunctor::enter, bt, osgWidget::EVENT_MOUSE_ENTER));
|
||||
b->addCallback(new osgWidget::Callback(&ButtonFunctor::leave, bt, osgWidget::EVENT_MOUSE_LEAVE));
|
||||
b->addCallback(new osgWidget::Callback(&AnimtkViewerGUI::_buttonPush, this, osgWidget::EVENT_MOUSE_PUSH));
|
||||
@@ -259,7 +259,7 @@ bool AnimtkViewerGUI::_listMouseHover(osgWidget::Event& ev)
|
||||
else if(ev.type == osgWidget::EVENT_MOUSE_PUSH) {
|
||||
AnimtkViewerModelController::instance().playByName(ev.getWidget()->getName());
|
||||
}
|
||||
|
||||
|
||||
else return false;
|
||||
|
||||
return true;
|
||||
@@ -293,11 +293,11 @@ bool AnimtkViewerGUI::_buttonPush(osgWidget::Event& ev)
|
||||
l->setLabel(mc.getCurrentAnimationName());
|
||||
lf->setActive(true);
|
||||
}
|
||||
|
||||
|
||||
else if(name == "back")
|
||||
{
|
||||
mc.previous();
|
||||
|
||||
|
||||
l->setFontColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.7f));
|
||||
l->setLabel(mc.getCurrentAnimationName());
|
||||
lf->setActive(true);
|
||||
@@ -345,7 +345,7 @@ void AnimtkViewerGUI::_createButtonBox()
|
||||
_buttonBox->addWidget(open);
|
||||
_buttonBox->addWidget(osg::clone(space, "space1", osg::CopyOp::DEEP_COPY_ALL));
|
||||
_buttonBox->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.7f);
|
||||
|
||||
|
||||
_buttonBox->setEventMask(osgWidget::EVENT_MASK_MOUSE_DRAG);
|
||||
_buttonBox->addCallback(new osgWidget::Callback(&eatDrag, osgWidget::EVENT_MOUSE_DRAG));
|
||||
}
|
||||
@@ -392,7 +392,7 @@ void AnimtkViewerGUI::_createLabelBox()
|
||||
_labelBox = new osgWidget::Box("labelBox", osgWidget::Box::VERTICAL);
|
||||
|
||||
osgWidget::Label* label = new osgWidget::Label("label");
|
||||
|
||||
|
||||
label->setFont("fonts/Vera.ttf");
|
||||
label->setFontSize(50);
|
||||
label->setFontColor(0.0f, 0.0f, 0.0f, 0.7f);
|
||||
|
||||
@@ -16,104 +16,104 @@ const unsigned int MASK_2D = 0xF0000000;
|
||||
const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
struct ColorWidget: public osgWidget::Widget {
|
||||
ColorWidget():
|
||||
osgWidget::Widget("", 256.0f, 256.0f) {
|
||||
}
|
||||
ColorWidget():
|
||||
osgWidget::Widget("", 256.0f, 256.0f) {
|
||||
}
|
||||
|
||||
bool mouseEnter(double, double, osgWidget::WindowManager*) {
|
||||
addColor(-osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f));
|
||||
|
||||
// osgWidget::warn() << "enter: " << getColor() << std::endl;
|
||||
bool mouseEnter(double, double, osgWidget::WindowManager*) {
|
||||
addColor(-osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f));
|
||||
|
||||
// osgWidget::warn() << "enter: " << getColor() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseLeave(double, double, osgWidget::WindowManager*) {
|
||||
addColor(osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f));
|
||||
|
||||
// osgWidget::warn() << "leave: " << getColor() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool mouseLeave(double, double, osgWidget::WindowManager*) {
|
||||
addColor(osgWidget::Color(0.4f, 0.4f, 0.4f, 0.0f));
|
||||
|
||||
// osgWidget::warn() << "leave: " << getColor() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseOver(double x, double y, osgWidget::WindowManager*) {
|
||||
osgWidget::Color c = getImageColorAtPointerXY(x, y);
|
||||
bool mouseOver(double x, double y, osgWidget::WindowManager*) {
|
||||
osgWidget::Color c = getImageColorAtPointerXY(x, y);
|
||||
|
||||
if(c.a() < 0.001f) {
|
||||
// osgWidget::warn() << "Transparent Pixel: " << x << " " << y << std::endl;
|
||||
if(c.a() < 0.001f) {
|
||||
// osgWidget::warn() << "Transparent Pixel: " << x << " " << y << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keyUp(int key, int keyMask, osgWidget::WindowManager*) {
|
||||
// osgWidget::warn() << "..." << key << " - " << keyMask << std::endl;
|
||||
bool keyUp(int key, int keyMask, osgWidget::WindowManager*) {
|
||||
// osgWidget::warn() << "..." << key << " - " << keyMask << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BoxType bt) {
|
||||
osgWidget::Box* box = new osgWidget::Box(name, bt, true);
|
||||
osgWidget::Widget* widget1 = new osgWidget::Widget(name + "_widget1", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::Widget(name + "_widget2", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget3 = new ColorWidget();
|
||||
osgWidget::Box* box = new osgWidget::Box(name, bt, true);
|
||||
osgWidget::Widget* widget1 = new osgWidget::Widget(name + "_widget1", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::Widget(name + "_widget2", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget3 = new ColorWidget();
|
||||
|
||||
widget1->setColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
widget2->setColor(0.6f, 0.6f, 0.6f, 1.0f);
|
||||
widget1->setColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
widget2->setColor(0.6f, 0.6f, 0.6f, 1.0f);
|
||||
|
||||
widget3->setImage("osgWidget/natascha.png");
|
||||
widget3->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
widget3->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
|
||||
widget3->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
|
||||
widget3->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
|
||||
widget3->setImage("osgWidget/natascha.png");
|
||||
widget3->setTexCoord(0.0f, 0.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
widget3->setTexCoord(1.0f, 0.0f, osgWidget::Widget::LOWER_RIGHT);
|
||||
widget3->setTexCoord(1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
|
||||
widget3->setTexCoord(0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
|
||||
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
|
||||
return box;
|
||||
return box;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY);
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY);
|
||||
|
||||
osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Window* box2 = createBox("VBOX", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Window* box3 = createBox("HBOX2", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Window* box4 = createBox("VBOX2", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Window* box1 = createBox("HBOX", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Window* box2 = createBox("VBOX", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Window* box3 = createBox("HBOX2", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Window* box4 = createBox("VBOX2", osgWidget::Box::VERTICAL);
|
||||
|
||||
box1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 0.8f);
|
||||
box1->attachMoveCallback();
|
||||
box1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 0.8f);
|
||||
box1->attachMoveCallback();
|
||||
|
||||
box2->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.8f);
|
||||
box2->attachMoveCallback();
|
||||
box2->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.8f);
|
||||
box2->attachMoveCallback();
|
||||
|
||||
box3->getBackground()->setColor(0.0f, 0.0f, 1.0f, 0.8f);
|
||||
box3->attachMoveCallback();
|
||||
box3->getBackground()->setColor(0.0f, 0.0f, 1.0f, 0.8f);
|
||||
box3->attachMoveCallback();
|
||||
|
||||
wm->addChild(box1);
|
||||
wm->addChild(box2);
|
||||
wm->addChild(box3);
|
||||
wm->addChild(box4);
|
||||
wm->addChild(box1);
|
||||
wm->addChild(box2);
|
||||
wm->addChild(box3);
|
||||
wm->addChild(box4);
|
||||
|
||||
box4->hide();
|
||||
box4->hide();
|
||||
|
||||
osg::Node* model = osgDB::readNodeFile("spaceship.osg");
|
||||
osg::Node* model = osgDB::readNodeFile("spaceship.osg");
|
||||
|
||||
model->setNodeMask(MASK_3D);
|
||||
model->setNodeMask(MASK_3D);
|
||||
|
||||
return osgWidget::createExample(viewer, wm, model);
|
||||
return osgWidget::createExample(viewer, wm, model);
|
||||
}
|
||||
|
||||
@@ -8,135 +8,135 @@
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
bool colorWidgetEnter(osgWidget::Event& event) {
|
||||
event.getWidget()->addColor(0.5f, 0.2f, 0.3f, 0.0f);
|
||||
event.getWidget()->addColor(0.5f, 0.2f, 0.3f, 0.0f);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl;
|
||||
|
||||
return false;
|
||||
// osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool colorWidgetLeave(osgWidget::Event& event) {
|
||||
event.getWidget()->addColor(-0.5f, -0.2f, -0.3f, 0.0f);
|
||||
event.getWidget()->addColor(-0.5f, -0.2f, -0.3f, 0.0f);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseLeave" << std::endl;
|
||||
|
||||
return true;
|
||||
// osgWidget::warn() << "WIDGET mouseLeave" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool windowMouseOver(osgWidget::Event& event) {
|
||||
osgWidget::XYCoord xy = event.getWindow()->localXY(event.x, event.y);
|
||||
osgWidget::XYCoord xy = event.getWindow()->localXY(event.x, event.y);
|
||||
|
||||
// osgWidget::warn() << "WINDOW " << xy.x() << " - " << xy.y() << std::endl;
|
||||
// osgWidget::warn() << "WINDOW " << xy.x() << " - " << xy.y() << std::endl;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool widgetMouseOver(osgWidget::Event& event) {
|
||||
osgWidget::XYCoord xy = event.getWidget()->localXY(event.x, event.y);
|
||||
osgWidget::XYCoord xy = event.getWidget()->localXY(event.x, event.y);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseOver " << xy.x() << " - " << xy.y() << std::endl;
|
||||
// osgWidget::warn() << "WIDGET mouseOver " << xy.x() << " - " << xy.y() << std::endl;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
osgWidget::Widget* createWidget(
|
||||
const std::string& name,
|
||||
osgWidget::color_type col,
|
||||
osgWidget::Widget::Layer layer
|
||||
const std::string& name,
|
||||
osgWidget::color_type col,
|
||||
osgWidget::Widget::Layer layer
|
||||
) {
|
||||
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
|
||||
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
|
||||
|
||||
widget->setEventMask(osgWidget::EVENT_ALL);
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE));
|
||||
widget->addCallback(new osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER));
|
||||
widget->setColor(col, col, col, 0.5f);
|
||||
widget->setLayer(layer);
|
||||
|
||||
return widget;
|
||||
widget->setEventMask(osgWidget::EVENT_ALL);
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER));
|
||||
widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE));
|
||||
widget->addCallback(new osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER));
|
||||
widget->setColor(col, col, col, 0.5f);
|
||||
widget->setLayer(layer);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
|
||||
canvas->addCallback(new osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER));
|
||||
canvas->attachMoveCallback();
|
||||
canvas->attachRotateCallback();
|
||||
canvas->attachScaleCallback();
|
||||
canvas->addCallback(new osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER));
|
||||
canvas->attachMoveCallback();
|
||||
canvas->attachRotateCallback();
|
||||
canvas->attachScaleCallback();
|
||||
|
||||
canvas->addWidget(
|
||||
createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
|
||||
canvas->addWidget(
|
||||
createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
|
||||
200.0f,
|
||||
0.0f
|
||||
);
|
||||
canvas->addWidget(
|
||||
createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
|
||||
0.0f,
|
||||
0.0f
|
||||
);
|
||||
|
||||
canvas->addWidget(
|
||||
createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
|
||||
200.0f,
|
||||
0.0f
|
||||
);
|
||||
|
||||
canvas->addWidget(
|
||||
createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
|
||||
400.0f,
|
||||
0.0f
|
||||
);
|
||||
canvas->addWidget(
|
||||
createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
|
||||
400.0f,
|
||||
0.0f
|
||||
);
|
||||
|
||||
// Add a child and then resize it relatively to the size of the parent Window.
|
||||
osgWidget::Widget* relWidget = new osgWidget::Widget("relative");
|
||||
// Add a child and then resize it relatively to the size of the parent Window.
|
||||
osgWidget::Widget* relWidget = new osgWidget::Widget("relative");
|
||||
|
||||
relWidget->setLayer(osgWidget::Widget::LAYER_LOW, 1);
|
||||
relWidget->setCoordinateMode(osgWidget::Widget::CM_RELATIVE);
|
||||
relWidget->setSize(0.2f, 0.2f);
|
||||
relWidget->setColor(0.5f, 0.5f, 0.1f, 0.9f);
|
||||
relWidget->setLayer(osgWidget::Widget::LAYER_LOW, 1);
|
||||
relWidget->setCoordinateMode(osgWidget::Widget::CM_RELATIVE);
|
||||
relWidget->setSize(0.2f, 0.2f);
|
||||
relWidget->setColor(0.5f, 0.5f, 0.1f, 0.9f);
|
||||
|
||||
osgWidget::warn() << canvas->getWidth() << std::endl;
|
||||
osgWidget::warn() << canvas->getWidth() << std::endl;
|
||||
|
||||
canvas->addWidget(relWidget, 0.4f, 0.4f);
|
||||
|
||||
relWidget->addOrigin(0.1f, 0.1f);
|
||||
relWidget->addSize(0.2f, 0.2f);
|
||||
canvas->addWidget(relWidget, 0.4f, 0.4f);
|
||||
|
||||
relWidget->addOrigin(0.1f, 0.1f);
|
||||
relWidget->addSize(0.2f, 0.2f);
|
||||
|
||||
canvas->resize();
|
||||
canvas->resize();
|
||||
|
||||
// Finally, add the whole thing to the WindowManager.
|
||||
wm->addChild(canvas);
|
||||
// Finally, add the whole thing to the WindowManager.
|
||||
wm->addChild(canvas);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
|
||||
/*
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
|
||||
canvas->addWidget(new osgWidget::Widget("spacer", 2.0f, 300.0f), 1280.0f, 0.0f);
|
||||
canvas->addWidget(new osgWidget::Widget("spacer", 2.0f, 300.0f), 1280.0f, 0.0f);
|
||||
|
||||
canvas->setOrigin(0.0f, 300.0f);
|
||||
canvas->setOrigin(0.0f, 300.0f);
|
||||
|
||||
wm->addChild(canvas);
|
||||
wm->addChild(canvas);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -118,6 +118,7 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback
|
||||
osg::ref_ptr<osgWidget::Frame> _frame;
|
||||
float _width;
|
||||
float _height;
|
||||
osg::Matrix _matrix;
|
||||
EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame)
|
||||
{
|
||||
_motionOver = WidgetMotion(0.0, 0.4);
|
||||
@@ -138,13 +139,20 @@ struct EventOK : public osgWidget::Callback, osg::NodeCallback
|
||||
_width = _frame->getWidth();
|
||||
_height = _frame->getHeight();
|
||||
_motionOver.reset();
|
||||
_matrix = _frame->getMatrix();
|
||||
//_frame->setMatrix(osg::Matrix::scale(2, 2, 1) * _frame->getMatrix());
|
||||
_frame->setScale(1.1f); //osg::Matrix::scale(2, 2, 1) * _frame->getMatrix());
|
||||
_frame->update(); //osg::Matrix::scale(2, 2, 1) * _frame->getMatrix());
|
||||
std::cout << "enter" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE)
|
||||
else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE)
|
||||
{
|
||||
_over = false;
|
||||
_motionLeave.reset();
|
||||
//_frame->setMatrix(_matrix);
|
||||
_frame->setScale(1.0f);
|
||||
_frame->update();
|
||||
std::cout << "leave" << std::endl;
|
||||
return true;
|
||||
}
|
||||
@@ -218,7 +226,9 @@ osgWidget::Frame* MessageBox::createButtonOk(const std::string& theme,
|
||||
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
|
||||
box->getBackground()->setColor(colorBack);
|
||||
frame->getEmbeddedWindow()->setWindow(box);
|
||||
box->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
box->setEventMask(osgWidget::EVENT_NONE);
|
||||
frame->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
|
||||
frame->resizeFrame(box->getWidth(), box->getHeight());
|
||||
frame->resizeAdd(0, 0);
|
||||
@@ -255,9 +265,13 @@ bool MessageBox::create(const std::string& themeMessage,
|
||||
|
||||
_button = createButtonOk(themeButton, buttonText, font, fontSize);
|
||||
osgWidget::Widget* buttonOK = _button->embed();
|
||||
_button->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
buttonOK->setColor(osgWidget::Color(0,0,0,0));
|
||||
buttonOK->setCanFill(false);
|
||||
|
||||
labelTitle->setPadBottom(30.0f);
|
||||
labelText->setPadBottom(30.0f);
|
||||
|
||||
box->addWidget(buttonOK);
|
||||
box->addWidget(labelText);
|
||||
box->addWidget(labelTitle);
|
||||
@@ -325,12 +339,14 @@ int main(int argc, char** argv)
|
||||
osgWidget::point_type hw = message.getWindow()->getHeight();
|
||||
osgWidget::point_type ox = (w - ww) / 2;
|
||||
osgWidget::point_type oy = (h - hw) / 2;
|
||||
message.getWindow()->setPosition(osgWidget::Point(ox, oy, message.getWindow()->getPosition()[2] ));
|
||||
message.getWindow()->setPosition(osgWidget::Point(
|
||||
osg::round(ox), osg::round(oy), message.getWindow()->getPosition()[2])
|
||||
);
|
||||
// frame->resizeAdd(30, 30);
|
||||
|
||||
// AlphaSetterVisitor alpha(.8f);
|
||||
// frame->accept(alpha);
|
||||
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
|
||||
return osgWidget::createExample(viewer, wm); //osgDB::readNodeFile("cow.osg"));
|
||||
|
||||
}
|
||||
|
||||
@@ -566,6 +582,7 @@ osgWidget::Window* createButtonOk(const std::string& theme, const std::string& t
|
||||
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
|
||||
box->getBackground()->setColor(colorBack);
|
||||
frame->getEmbeddedWindow()->setWindow(box);
|
||||
box->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
box->setEventMask(osgWidget::EVENT_NONE);
|
||||
|
||||
frame->resizeFrame(box->getWidth(), box->getHeight());
|
||||
|
||||
@@ -9,83 +9,83 @@
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
struct UpdateProgressNode: public osg::NodeCallback {
|
||||
float start;
|
||||
float done;
|
||||
float start;
|
||||
float done;
|
||||
|
||||
UpdateProgressNode():
|
||||
start (0.0f),
|
||||
done (5.0f) {
|
||||
}
|
||||
UpdateProgressNode():
|
||||
start (0.0f),
|
||||
done (5.0f) {
|
||||
}
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) {
|
||||
const osg::FrameStamp* fs = nv->getFrameStamp();
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) {
|
||||
const osg::FrameStamp* fs = nv->getFrameStamp();
|
||||
|
||||
float t = fs->getSimulationTime();
|
||||
float t = fs->getSimulationTime();
|
||||
|
||||
if(start == 0.0f) start = t;
|
||||
if(start == 0.0f) start = t;
|
||||
|
||||
float width = ((t - start) / done) * 512.0f;
|
||||
float percent = (width / 512.0f) * 100.0f;
|
||||
|
||||
if(width < 1.0f || width > 512.0f) return;
|
||||
float width = ((t - start) / done) * 512.0f;
|
||||
float percent = (width / 512.0f) * 100.0f;
|
||||
|
||||
if(width < 1.0f || width > 512.0f) return;
|
||||
|
||||
osgWidget::Window* window = dynamic_cast<osgWidget::Window*>(node);
|
||||
osgWidget::Window* window = dynamic_cast<osgWidget::Window*>(node);
|
||||
|
||||
if(!window) return;
|
||||
if(!window) return;
|
||||
|
||||
osgWidget::Widget* w = window->getByName("pMeter");
|
||||
osgWidget::Label* l = dynamic_cast<osgWidget::Label*>(window->getByName("pLabel"));
|
||||
osgWidget::Widget* w = window->getByName("pMeter");
|
||||
osgWidget::Label* l = dynamic_cast<osgWidget::Label*>(window->getByName("pLabel"));
|
||||
|
||||
if(!w || !l) return;
|
||||
if(!w || !l) return;
|
||||
|
||||
w->setWidth(width);
|
||||
w->setTexCoordRegion(0.0f, 0.0f, width, 64.0f);
|
||||
w->setWidth(width);
|
||||
w->setTexCoordRegion(0.0f, 0.0f, width, 64.0f);
|
||||
|
||||
std::ostringstream ss;
|
||||
std::ostringstream ss;
|
||||
|
||||
ss << osg::round(percent) << "% Done" << std::endl;
|
||||
ss << osg::round(percent) << "% Done" << std::endl;
|
||||
|
||||
l->setLabel(ss.str());
|
||||
}
|
||||
l->setLabel(ss.str());
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
osgWidget::Widget* pOutline = new osgWidget::Widget("pOutline", 512.0f, 64.0f);
|
||||
osgWidget::Widget* pMeter = new osgWidget::Widget("pMeter", 0.0f, 64.0f);
|
||||
osgWidget::Label* pLabel = new osgWidget::Label("pLabel", "0% Done");
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
osgWidget::Widget* pOutline = new osgWidget::Widget("pOutline", 512.0f, 64.0f);
|
||||
osgWidget::Widget* pMeter = new osgWidget::Widget("pMeter", 0.0f, 64.0f);
|
||||
osgWidget::Label* pLabel = new osgWidget::Label("pLabel", "0% Done");
|
||||
|
||||
pOutline->setImage("osgWidget/progress-outline.png", true);
|
||||
pOutline->setLayer(osgWidget::Widget::LAYER_MIDDLE, 2);
|
||||
|
||||
pMeter->setImage("osgWidget/progress-meter.png");
|
||||
pMeter->setColor(0.7f, 0.1f, 0.1f, 0.7f);
|
||||
pMeter->setLayer(osgWidget::Widget::LAYER_MIDDLE, 1);
|
||||
pOutline->setImage("osgWidget/progress-outline.png", true);
|
||||
pOutline->setLayer(osgWidget::Widget::LAYER_MIDDLE, 2);
|
||||
|
||||
pMeter->setImage("osgWidget/progress-meter.png");
|
||||
pMeter->setColor(0.7f, 0.1f, 0.1f, 0.7f);
|
||||
pMeter->setLayer(osgWidget::Widget::LAYER_MIDDLE, 1);
|
||||
|
||||
pLabel->setFont("fonts/VeraMono.ttf");
|
||||
pLabel->setFontSize(20);
|
||||
pLabel->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
pLabel->setSize(512.0f, 64.0f);
|
||||
pLabel->setLayer(osgWidget::Widget::LAYER_MIDDLE, 3);
|
||||
pLabel->setFont("fonts/VeraMono.ttf");
|
||||
pLabel->setFontSize(20);
|
||||
pLabel->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
pLabel->setSize(512.0f, 64.0f);
|
||||
pLabel->setLayer(osgWidget::Widget::LAYER_MIDDLE, 3);
|
||||
|
||||
canvas->setOrigin(300.0f, 300.0f);
|
||||
canvas->addWidget(pMeter, 0.0f, 0.0f);
|
||||
canvas->addWidget(pOutline, 0.0f, 0.0f);
|
||||
canvas->addWidget(pLabel, 0.0f, 0.0f);
|
||||
canvas->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
canvas->setUpdateCallback(new UpdateProgressNode());
|
||||
canvas->setOrigin(300.0f, 300.0f);
|
||||
canvas->addWidget(pMeter, 0.0f, 0.0f);
|
||||
canvas->addWidget(pOutline, 0.0f, 0.0f);
|
||||
canvas->addWidget(pLabel, 0.0f, 0.0f);
|
||||
canvas->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
canvas->setUpdateCallback(new UpdateProgressNode());
|
||||
|
||||
wm->addChild(canvas);
|
||||
wm->addChild(canvas);
|
||||
|
||||
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
|
||||
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
|
||||
}
|
||||
|
||||
@@ -9,75 +9,75 @@
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
const std::string& STYLE1 =
|
||||
"color 0 0 0 128\n"
|
||||
"padding 5\n"
|
||||
"color 0 0 0 128\n"
|
||||
"padding 5\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE2 =
|
||||
"color 1.0 0.5 0.0\n"
|
||||
"color 1.0 0.5 0.0\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE3 =
|
||||
"fill true\n"
|
||||
"fill true\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE4 =
|
||||
"pos 100.0 100.0\n"
|
||||
"size 600 600\n"
|
||||
"pos 100.0 100.0\n"
|
||||
"size 600 600\n"
|
||||
;
|
||||
|
||||
class CustomStyled: public osgWidget::Widget {
|
||||
};
|
||||
|
||||
class CustomStyle: public osgWidget::Style {
|
||||
virtual bool applyStyle(osgWidget::Widget* w, osgWidget::Reader r) {
|
||||
CustomStyled* cs = dynamic_cast<CustomStyled*>(w);
|
||||
virtual bool applyStyle(osgWidget::Widget* w, osgWidget::Reader r) {
|
||||
CustomStyled* cs = dynamic_cast<CustomStyled*>(w);
|
||||
|
||||
if(!cs) return false;
|
||||
if(!cs) return false;
|
||||
|
||||
osgWidget::warn() << "Here, okay." << std::endl;
|
||||
osgWidget::warn() << "Here, okay." << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D
|
||||
);
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D
|
||||
);
|
||||
|
||||
osgWidget::Box* box = new osgWidget::Box("box", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Box* box = new osgWidget::Box("box", osgWidget::Box::VERTICAL);
|
||||
|
||||
osgWidget::Widget* widget1 = new osgWidget::Widget("w1", 200.0f, 200.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::Widget("w2", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget3 = new osgWidget::Widget("w3", 0.0f, 0.0f);
|
||||
CustomStyled* cs = new CustomStyled();
|
||||
osgWidget::Widget* widget1 = new osgWidget::Widget("w1", 200.0f, 200.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::Widget("w2", 100.0f, 100.0f);
|
||||
osgWidget::Widget* widget3 = new osgWidget::Widget("w3", 0.0f, 0.0f);
|
||||
CustomStyled* cs = new CustomStyled();
|
||||
|
||||
// Yep.
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style1", STYLE1));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style2", STYLE2));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("spacer", STYLE3));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("window", STYLE4));
|
||||
// wm->getStyleManager()->addStyle(new CustomStyle("widget", ""));
|
||||
// Yep.
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style1", STYLE1));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("widget.style2", STYLE2));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("spacer", STYLE3));
|
||||
wm->getStyleManager()->addStyle(new osgWidget::Style("window", STYLE4));
|
||||
// wm->getStyleManager()->addStyle(new CustomStyle("widget", ""));
|
||||
|
||||
widget1->setStyle("widget.style1");
|
||||
widget2->setStyle("widget.style2");
|
||||
widget3->setStyle("spacer");
|
||||
widget1->setStyle("widget.style1");
|
||||
widget2->setStyle("widget.style2");
|
||||
widget3->setStyle("spacer");
|
||||
|
||||
box->setStyle("window");
|
||||
box->setStyle("window");
|
||||
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
|
||||
wm->addChild(box);
|
||||
wm->addChild(box);
|
||||
|
||||
// box->resizePercent(0.0f, 100.0f);
|
||||
// box->resizePercent(0.0f, 100.0f);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
|
||||
@@ -13,58 +13,58 @@ const unsigned int MASK_2D = 0xF0000000;
|
||||
// horizontal placement cells. A Box, on the other hand, can only be vertical or horizontal.
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Table* table = new osgWidget::Table("table", 3, 3);
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Table* table = new osgWidget::Table("table", 3, 3);
|
||||
|
||||
// Here we create our "cells" manually, though it will often be convenient to
|
||||
// do so algorithmically. Also, notice how we set the text name of each widget to
|
||||
// correspond with it's "index" in the table. This is merely a convenience, which
|
||||
// we use later...
|
||||
table->addWidget(new osgWidget::Widget("0, 0", 100.0f, 25.0f), 0, 0);
|
||||
table->addWidget(new osgWidget::Widget("0, 1", 100.0f, 25.0f), 0, 1);
|
||||
table->addWidget(new osgWidget::Widget("0, 2", 100.0f, 75.0f), 0, 2);
|
||||
|
||||
table->addWidget(new osgWidget::Widget("1, 0", 200.0f, 45.0f), 1, 0);
|
||||
table->addWidget(new osgWidget::Widget("1, 1", 200.0f, 45.0f), 1, 1);
|
||||
table->addWidget(new osgWidget::Widget("1, 2", 200.0f, 45.0f), 1, 2);
|
||||
|
||||
table->addWidget(new osgWidget::Widget("2, 0", 300.0f, 65.0f), 2, 0);
|
||||
table->addWidget(new osgWidget::Widget("2, 1", 300.0f, 65.0f), 2, 1);
|
||||
table->addWidget(new osgWidget::Widget("2, 2", 300.0f, 65.0f), 2, 2);
|
||||
// Here we create our "cells" manually, though it will often be convenient to
|
||||
// do so algorithmically. Also, notice how we set the text name of each widget to
|
||||
// correspond with it's "index" in the table. This is merely a convenience, which
|
||||
// we use later...
|
||||
table->addWidget(new osgWidget::Widget("0, 0", 100.0f, 25.0f), 0, 0);
|
||||
table->addWidget(new osgWidget::Widget("0, 1", 100.0f, 25.0f), 0, 1);
|
||||
table->addWidget(new osgWidget::Widget("0, 2", 100.0f, 75.0f), 0, 2);
|
||||
|
||||
table->addWidget(new osgWidget::Widget("1, 0", 200.0f, 45.0f), 1, 0);
|
||||
table->addWidget(new osgWidget::Widget("1, 1", 200.0f, 45.0f), 1, 1);
|
||||
table->addWidget(new osgWidget::Widget("1, 2", 200.0f, 45.0f), 1, 2);
|
||||
|
||||
table->addWidget(new osgWidget::Widget("2, 0", 300.0f, 65.0f), 2, 0);
|
||||
table->addWidget(new osgWidget::Widget("2, 1", 300.0f, 65.0f), 2, 1);
|
||||
table->addWidget(new osgWidget::Widget("2, 2", 300.0f, 65.0f), 2, 2);
|
||||
|
||||
table->getBackground()->setColor(0.0f, 0.0f, 0.5f, 1.0f);
|
||||
table->attachMoveCallback();
|
||||
table->getBackground()->setColor(0.0f, 0.0f, 0.5f, 1.0f);
|
||||
table->attachMoveCallback();
|
||||
|
||||
// Use a hackish method of setting the spacing for all Widgets.
|
||||
for(osgWidget::Table::Iterator i = table->begin(); i != table->end(); i++)
|
||||
i->get()->setPadding(1.0f)
|
||||
;
|
||||
// Use a hackish method of setting the spacing for all Widgets.
|
||||
for(osgWidget::Table::Iterator i = table->begin(); i != table->end(); i++)
|
||||
i->get()->setPadding(1.0f)
|
||||
;
|
||||
|
||||
// Now we fetch the very first 0, 0 Widget in the table using an awkward method.
|
||||
// This is merely one way to fetch a Widget from a Window, there are many others.
|
||||
// The osgWidget::Window::getByName interface will be very handy in scripting languages
|
||||
// where users will want to retrieve handles to existing Windows using a useful
|
||||
// textual name, such as "MainGUIParent" or something.
|
||||
table->getByName("0, 0")->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
|
||||
table->getByName("0, 0")->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
|
||||
table->getByName("0, 0")->setPadLeft(50.0f);
|
||||
table->getByName("0, 0")->setPadTop(3.0f);
|
||||
|
||||
// Change the colors a bit to differentiate this row from the others.
|
||||
table->getByName("2, 0")->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
table->getByName("2, 1")->setColor(1.0f, 0.0f, 0.0f, 0.5f);
|
||||
table->getByName("2, 2")->setColor(1.0f, 0.0f, 0.0f, 0.5f);
|
||||
// Now we fetch the very first 0, 0 Widget in the table using an awkward method.
|
||||
// This is merely one way to fetch a Widget from a Window, there are many others.
|
||||
// The osgWidget::Window::getByName interface will be very handy in scripting languages
|
||||
// where users will want to retrieve handles to existing Windows using a useful
|
||||
// textual name, such as "MainGUIParent" or something.
|
||||
table->getByName("0, 0")->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
|
||||
table->getByName("0, 0")->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
|
||||
table->getByName("0, 0")->setPadLeft(50.0f);
|
||||
table->getByName("0, 0")->setPadTop(3.0f);
|
||||
|
||||
// Change the colors a bit to differentiate this row from the others.
|
||||
table->getByName("2, 0")->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);
|
||||
table->getByName("2, 1")->setColor(1.0f, 0.0f, 0.0f, 0.5f);
|
||||
table->getByName("2, 2")->setColor(1.0f, 0.0f, 0.0f, 0.5f);
|
||||
|
||||
wm->addChild(table);
|
||||
wm->addChild(table);
|
||||
|
||||
return createExample(viewer, wm);
|
||||
return createExample(viewer, wm);
|
||||
}
|
||||
|
||||
@@ -15,208 +15,208 @@ const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
// Here we create (and later demonstrate) the use of a simple function callback.
|
||||
bool windowClicked(osgWidget::Event& ev) {
|
||||
std::cout << "windowClicked: " << ev.getWindow()->getName() << std::endl;
|
||||
std::cout << "windowClicked: " << ev.getWindow()->getName() << std::endl;
|
||||
|
||||
if(ev.getData()) {
|
||||
std::string* s = static_cast<std::string*>(ev.getData());
|
||||
if(ev.getData()) {
|
||||
std::string* s = static_cast<std::string*>(ev.getData());
|
||||
|
||||
std::cout << "This is data attached to the event: " << *s << std::endl;
|
||||
}
|
||||
std::cout << "This is data attached to the event: " << *s << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool windowScrolled(osgWidget::Event& ev) {
|
||||
osgWidget::warn()
|
||||
<< "scrolling up? " << ev.getWindowManager()->isMouseScrollingUp()
|
||||
<< std::endl
|
||||
;
|
||||
osgWidget::warn()
|
||||
<< "scrolling up? " << ev.getWindowManager()->isMouseScrollingUp()
|
||||
<< std::endl
|
||||
;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Here we dcreate a new class and show how to use a method callback (which differs from
|
||||
// a function callback in that we are required to also pass the "this" argument).
|
||||
struct Object {
|
||||
bool windowClicked(osgWidget::Event& ev) {
|
||||
std::cout << "Object::windowClicked " << ev.getWindow()->getName() << std::endl;
|
||||
bool windowClicked(osgWidget::Event& ev) {
|
||||
std::cout << "Object::windowClicked " << ev.getWindow()->getName() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// This is the more "traditional" method of creating a callback.
|
||||
struct CallbackObject: public osgWidget::Callback {
|
||||
CallbackObject(osgWidget::EventType evType):
|
||||
osgWidget::Callback(evType) {
|
||||
}
|
||||
CallbackObject(osgWidget::EventType evType):
|
||||
osgWidget::Callback(evType) {
|
||||
}
|
||||
|
||||
virtual bool operator()(osgWidget::Event& ev) {
|
||||
std::cout << "here" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
virtual bool operator()(osgWidget::Event& ev) {
|
||||
std::cout << "here" << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// Let's get busy! The WindowManager class is actually an osg::Switch,
|
||||
// so you can add it to (ideally) an orthographic camera and have it behave as
|
||||
// expected. Note that you create a WindowManager with a NodeMask--it is very important
|
||||
// that this be unique for picking to work properly. This also makes it possible to have
|
||||
// multiple WindowManagers each operating on their own, unique set of Window objects.
|
||||
// The final bool argument is a group of flags that introduce optional functionality
|
||||
// for the WindowManager. In our case we include the flags USE_PYTHON and USE_LUA,
|
||||
// to demonstrate (and test) their usage. Finally, we pass the temporary WM_NO_BETA_WARN
|
||||
// argument, which prevents creating the orange warning window. :) It will be shown
|
||||
// in other examples...
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_USE_LUA |
|
||||
osgWidget::WindowManager::WM_USE_PYTHON |
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
// Let's get busy! The WindowManager class is actually an osg::Switch,
|
||||
// so you can add it to (ideally) an orthographic camera and have it behave as
|
||||
// expected. Note that you create a WindowManager with a NodeMask--it is very important
|
||||
// that this be unique for picking to work properly. This also makes it possible to have
|
||||
// multiple WindowManagers each operating on their own, unique set of Window objects.
|
||||
// The final bool argument is a group of flags that introduce optional functionality
|
||||
// for the WindowManager. In our case we include the flags USE_PYTHON and USE_LUA,
|
||||
// to demonstrate (and test) their usage. Finally, we pass the temporary WM_NO_BETA_WARN
|
||||
// argument, which prevents creating the orange warning window. :) It will be shown
|
||||
// in other examples...
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_USE_LUA |
|
||||
osgWidget::WindowManager::WM_USE_PYTHON |
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
// An actual osgWidget::Window is pure virtual, so we've got to use the osgWidget::Box
|
||||
// implementation for now. At a later time, support for Tables and other kinds of
|
||||
// advanced layout Window types will be added.
|
||||
osgWidget::Window* box = new osgWidget::Box("box", osgWidget::Box::HORIZONTAL);
|
||||
// An actual osgWidget::Window is pure virtual, so we've got to use the osgWidget::Box
|
||||
// implementation for now. At a later time, support for Tables and other kinds of
|
||||
// advanced layout Window types will be added.
|
||||
osgWidget::Window* box = new osgWidget::Box("box", osgWidget::Box::HORIZONTAL);
|
||||
|
||||
// Now we actually attach our two types of callbacks to the box instance. The first
|
||||
// uses the simple function signature, the second uses a bound method, passing "this"
|
||||
// as the second argument to the Callback constructor.
|
||||
Object obj;
|
||||
// Now we actually attach our two types of callbacks to the box instance. The first
|
||||
// uses the simple function signature, the second uses a bound method, passing "this"
|
||||
// as the second argument to the Callback constructor.
|
||||
Object obj;
|
||||
|
||||
static std::string data = "lol ur face!";
|
||||
static std::string data = "lol ur face!";
|
||||
|
||||
/*
|
||||
box->addCallback(new osgWidget::Callback(&windowClicked, osgWidget::EVENT_MOUSE_PUSH, &data));
|
||||
box->addCallback(new osgWidget::Callback(&windowScrolled, osgWidget::EVENT_MOUSE_SCROLL));
|
||||
box->addCallback(osgWidget::Callback(
|
||||
&Object::windowClicked,
|
||||
&obj,
|
||||
osgWidget::EVENT_MOUSE_PUSH
|
||||
));
|
||||
*/
|
||||
/*
|
||||
box->addCallback(new osgWidget::Callback(&windowClicked, osgWidget::EVENT_MOUSE_PUSH, &data));
|
||||
box->addCallback(new osgWidget::Callback(&windowScrolled, osgWidget::EVENT_MOUSE_SCROLL));
|
||||
box->addCallback(osgWidget::Callback(
|
||||
&Object::windowClicked,
|
||||
&obj,
|
||||
osgWidget::EVENT_MOUSE_PUSH
|
||||
));
|
||||
*/
|
||||
|
||||
box->addCallback(new CallbackObject(osgWidget::EVENT_MOUSE_PUSH));
|
||||
box->addCallback(new CallbackObject(osgWidget::EVENT_MOUSE_PUSH));
|
||||
|
||||
// Create some of our "testing" Widgets; included are two Widget subclasses I made
|
||||
// during testing which I've kept around for testing purposes. You'll notice
|
||||
// that you cannot move the box using the NullWidget, and that the NotifyWidget
|
||||
// is a bit verbose. :)
|
||||
osgWidget::Widget* widget1 = new osgWidget::NotifyWidget("widget1", 300.0f, 100.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::NullWidget("widget2", 400.0f, 75.0f);
|
||||
osgWidget::Widget* widget3 = new osgWidget::Widget("widget3", 100.0f, 100.0f);
|
||||
// Set the colors of widget1 and widget3 to green.
|
||||
widget1->setColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
widget1->setCanFill(true);
|
||||
widget3->setColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
// Create some of our "testing" Widgets; included are two Widget subclasses I made
|
||||
// during testing which I've kept around for testing purposes. You'll notice
|
||||
// that you cannot move the box using the NullWidget, and that the NotifyWidget
|
||||
// is a bit verbose. :)
|
||||
osgWidget::Widget* widget1 = new osgWidget::NotifyWidget("widget1", 300.0f, 100.0f);
|
||||
osgWidget::Widget* widget2 = new osgWidget::NullWidget("widget2", 400.0f, 75.0f);
|
||||
osgWidget::Widget* widget3 = new osgWidget::Widget("widget3", 100.0f, 100.0f);
|
||||
// Set the colors of widget1 and widget3 to green.
|
||||
widget1->setColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
widget1->setCanFill(true);
|
||||
widget3->setColor(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
widget1->setImage(osgDB::readImageFile("Images/Saturn.TGA"), true);
|
||||
widget1->setImage(osgDB::readImageFile("Images/Saturn.TGA"), true);
|
||||
|
||||
// Set the color of widget2, to differentiate it and make it sassy. This is
|
||||
// like a poor man's gradient!
|
||||
widget2->setColor(0.9f, 0.0f, 0.0f, 0.9f, osgWidget::Widget::LOWER_LEFT);
|
||||
widget2->setColor(0.9f, 0.0f, 0.0f, 0.9f, osgWidget::Widget::LOWER_RIGHT);
|
||||
widget2->setColor(0.0f, 0.0f, 0.9f, 0.9f, osgWidget::Widget::UPPER_RIGHT);
|
||||
widget2->setColor(0.0f, 0.0f, 0.9f, 0.9f, osgWidget::Widget::UPPER_LEFT);
|
||||
// Set the color of widget2, to differentiate it and make it sassy. This is
|
||||
// like a poor man's gradient!
|
||||
widget2->setColor(0.9f, 0.0f, 0.0f, 0.9f, osgWidget::Widget::LOWER_LEFT);
|
||||
widget2->setColor(0.9f, 0.0f, 0.0f, 0.9f, osgWidget::Widget::LOWER_RIGHT);
|
||||
widget2->setColor(0.0f, 0.0f, 0.9f, 0.9f, osgWidget::Widget::UPPER_RIGHT);
|
||||
widget2->setColor(0.0f, 0.0f, 0.9f, 0.9f, osgWidget::Widget::UPPER_LEFT);
|
||||
|
||||
// Now add our newly created widgets to our box.
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
// Now add our newly created widgets to our box.
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
|
||||
// For maximum efficiency, Windows don't automatically reallocate their geometry
|
||||
// and internal positioning every time a widget is added. Thus, we either have to
|
||||
// call the WindowManger::resizeAllWindows method or manually call
|
||||
// Window::resize when we're ready.
|
||||
box->resize();
|
||||
// For maximum efficiency, Windows don't automatically reallocate their geometry
|
||||
// and internal positioning every time a widget is added. Thus, we either have to
|
||||
// call the WindowManger::resizeAllWindows method or manually call
|
||||
// Window::resize when we're ready.
|
||||
box->resize();
|
||||
|
||||
// Now, lets clone our existing box and create a new copy of of it, also adding that
|
||||
// to the WindowManager. This demonstrates the usages of OSG's ->clone() support,
|
||||
// though that is abstracted by our META_UIObject macro.
|
||||
osgWidget::Window* boxCopy = osg::clone(box, "newBox", osg::CopyOp::DEEP_COPY_ALL);
|
||||
// Now, lets clone our existing box and create a new copy of of it, also adding that
|
||||
// to the WindowManager. This demonstrates the usages of OSG's ->clone() support,
|
||||
// though that is abstracted by our META_UIObject macro.
|
||||
osgWidget::Window* boxCopy = osg::clone(box, "newBox", osg::CopyOp::DEEP_COPY_ALL);
|
||||
|
||||
// Move our copy to make it visible.
|
||||
boxCopy->setOrigin(0.0f, 125.0f);
|
||||
// Move our copy to make it visible.
|
||||
boxCopy->setOrigin(0.0f, 125.0f);
|
||||
|
||||
boxCopy->getByName("widget1")->setColor(0.5f, 0.0f, 1.0f, 1.0f);
|
||||
boxCopy->getByName("widget3")->setColor(0.5f, 0.0f, 1.0f, 1.0f);
|
||||
boxCopy->getByName("widget1")->setColor(0.5f, 0.0f, 1.0f, 1.0f);
|
||||
boxCopy->getByName("widget3")->setColor(0.5f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
// Add the successfully created Box (if we get this far) into the WindowManager, so
|
||||
// that they can receive events.
|
||||
wm->addChild(box);
|
||||
wm->addChild(boxCopy);
|
||||
// Add the successfully created Box (if we get this far) into the WindowManager, so
|
||||
// that they can receive events.
|
||||
wm->addChild(box);
|
||||
wm->addChild(boxCopy);
|
||||
|
||||
// Now, ask our new box to be 100% the width of the WindowManager.
|
||||
boxCopy->resizePercent(100.0f, 0.0f);
|
||||
// Now, ask our new box to be 100% the width of the WindowManager.
|
||||
boxCopy->resizePercent(100.0f, 0.0f);
|
||||
|
||||
// Here we demonstrate the use of osgWidget/io_utils. This is really only useful for
|
||||
// debugging at the moment, but later I'll make it more generic for .osg and .ive
|
||||
// creation.
|
||||
// std::cout << *box << std::endl << *boxCopy << std::endl;
|
||||
// Here we demonstrate the use of osgWidget/io_utils. This is really only useful for
|
||||
// debugging at the moment, but later I'll make it more generic for .osg and .ive
|
||||
// creation.
|
||||
// std::cout << *box << std::endl << *boxCopy << std::endl;
|
||||
|
||||
// Setup our OSG objects for our scene; note the use of the utility function
|
||||
// createOrthoCamera, which is just a helper for setting up a proper viewing area.
|
||||
// An alternative (and a MUCH easier alternative at that!) is to
|
||||
// simply use the createParentOrthoCamera method of the WindowManager class,
|
||||
// which will wrap the calls to createOrthoCamera and addChild for us! Check out
|
||||
// some of the other examples to see this in action...
|
||||
osg::Group* group = new osg::Group();
|
||||
osg::Camera* camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f);
|
||||
osg::Node* model = osgDB::readNodeFile("cow.osg");
|
||||
// Setup our OSG objects for our scene; note the use of the utility function
|
||||
// createOrthoCamera, which is just a helper for setting up a proper viewing area.
|
||||
// An alternative (and a MUCH easier alternative at that!) is to
|
||||
// simply use the createParentOrthoCamera method of the WindowManager class,
|
||||
// which will wrap the calls to createOrthoCamera and addChild for us! Check out
|
||||
// some of the other examples to see this in action...
|
||||
osg::Group* group = new osg::Group();
|
||||
osg::Camera* camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f);
|
||||
osg::Node* model = osgDB::readNodeFile("cow.osg");
|
||||
|
||||
// Add our event handler; is this better as a MatrixManipulator? Add a few other
|
||||
// helpful ViewerEventHandlers.
|
||||
viewer.addEventHandler(new osgWidget::MouseHandler(wm));
|
||||
viewer.addEventHandler(new osgWidget::KeyboardHandler(wm));
|
||||
viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera));
|
||||
viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera));
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler());
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
|
||||
viewer.addEventHandler(new osgGA::StateSetManipulator(
|
||||
viewer.getCamera()->getOrCreateStateSet()
|
||||
));
|
||||
// Add our event handler; is this better as a MatrixManipulator? Add a few other
|
||||
// helpful ViewerEventHandlers.
|
||||
viewer.addEventHandler(new osgWidget::MouseHandler(wm));
|
||||
viewer.addEventHandler(new osgWidget::KeyboardHandler(wm));
|
||||
viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera));
|
||||
viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera));
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler());
|
||||
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
|
||||
viewer.addEventHandler(new osgGA::StateSetManipulator(
|
||||
viewer.getCamera()->getOrCreateStateSet()
|
||||
));
|
||||
|
||||
// Set our first non-UI node to be something other than the mask we created our
|
||||
// WindowManager with to avoid picking.
|
||||
// TODO: Do I need to create a mechanism for doing this automatically, or should
|
||||
// that be the responsibility of the users of osgWidget?
|
||||
model->setNodeMask(MASK_3D);
|
||||
// Set our first non-UI node to be something other than the mask we created our
|
||||
// WindowManager with to avoid picking.
|
||||
// TODO: Do I need to create a mechanism for doing this automatically, or should
|
||||
// that be the responsibility of the users of osgWidget?
|
||||
model->setNodeMask(MASK_3D);
|
||||
|
||||
// Add the WindowManager instance to the 2D camera. This isn't strictly necessary,
|
||||
// and you can get some cool results putting the WindowManager directly into a
|
||||
// 3D scene. This is not necessary if you use WindowManager::createParentOrthoCamera.
|
||||
camera->addChild(wm);
|
||||
// Add the WindowManager instance to the 2D camera. This isn't strictly necessary,
|
||||
// and you can get some cool results putting the WindowManager directly into a
|
||||
// 3D scene. This is not necessary if you use WindowManager::createParentOrthoCamera.
|
||||
camera->addChild(wm);
|
||||
|
||||
// Add our camera and a testing 3D model to the scene.
|
||||
group->addChild(camera);
|
||||
group->addChild(model);
|
||||
// Add our camera and a testing 3D model to the scene.
|
||||
group->addChild(camera);
|
||||
group->addChild(model);
|
||||
|
||||
// Here we show how to both run simple strings of code AND run entire files. These
|
||||
// assume that you're running the osgwidgetwindow example from the build directory,
|
||||
// otherwise you'll need to adjust the file path below in the call to runFile().
|
||||
wm->getLuaEngine()->eval("window = osgwidget.newWindow()");
|
||||
wm->getLuaEngine()->runFile("osgWidget/osgwidgetwindow.lua");
|
||||
// Here we show how to both run simple strings of code AND run entire files. These
|
||||
// assume that you're running the osgwidgetwindow example from the build directory,
|
||||
// otherwise you'll need to adjust the file path below in the call to runFile().
|
||||
wm->getLuaEngine()->eval("window = osgwidget.newWindow()");
|
||||
wm->getLuaEngine()->runFile("osgWidget/osgwidgetwindow.lua");
|
||||
|
||||
wm->getPythonEngine()->eval("import osgwidget");
|
||||
wm->getPythonEngine()->runFile("osgWidget/osgwidgetwindow.py");
|
||||
wm->getPythonEngine()->eval("import osgwidget");
|
||||
wm->getPythonEngine()->runFile("osgWidget/osgwidgetwindow.py");
|
||||
|
||||
viewer.setUpViewInWindow(0, 0, 1280, 1024);
|
||||
viewer.setSceneData(group);
|
||||
viewer.setUpViewInWindow(0, 0, 1280, 1024);
|
||||
viewer.setSceneData(group);
|
||||
|
||||
/*
|
||||
osgViewer::Viewer::Cameras cameras;
|
||||
viewer.getCameras(cameras);
|
||||
osg::Camera* c = cameras[0];
|
||||
osg::Matrix s = osg::Matrix::scale(1.0f, -1.0f, 1.0f);
|
||||
c->setProjectionMatrix(s * c->getProjectionMatrix());
|
||||
*/
|
||||
/*
|
||||
osgViewer::Viewer::Cameras cameras;
|
||||
viewer.getCameras(cameras);
|
||||
osg::Camera* c = cameras[0];
|
||||
osg::Matrix s = osg::Matrix::scale(1.0f, -1.0f, 1.0f);
|
||||
c->setProjectionMatrix(s * c->getProjectionMatrix());
|
||||
*/
|
||||
|
||||
return viewer.run();
|
||||
return viewer.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user