6a67be2e32
forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.4@15165 16af8721-9629-0410-8352-f15c8da7e697
125 lines
4.4 KiB
C++
125 lines
4.4 KiB
C++
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
|
// $Id: osgwidgetframe.cpp 40 2008-04-11 14:05:11Z cubicool $
|
|
|
|
#include <osgWidget/Util>
|
|
#include <osgWidget/WindowManager>
|
|
#include <osgWidget/Frame>
|
|
#include <osgWidget/Box>
|
|
#include <osgDB/ReadFile>
|
|
|
|
const unsigned int MASK_2D = 0xF0000000;
|
|
|
|
int main(int argc, char** argv) {
|
|
osgViewer::Viewer viewer;
|
|
|
|
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
|
&viewer,
|
|
1280.0f,
|
|
1024.0f,
|
|
MASK_2D,
|
|
osgWidget::WindowManager::WM_PICK_DEBUG
|
|
);
|
|
|
|
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrame(
|
|
"frame",
|
|
32.0f,
|
|
32.0f,
|
|
300.0f,
|
|
300.0f
|
|
);
|
|
|
|
osgWidget::Frame* frame2 = osgWidget::Frame::createSimpleFrameFromTheme(
|
|
"frameTheme",
|
|
osgDB::readRefImageFile("osgWidget/theme-1.png"),
|
|
300.0f,
|
|
300.0f,
|
|
osgWidget::Frame::FRAME_ALL
|
|
);
|
|
frame2->setPosition(300,100,0);
|
|
frame2->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
osgWidget::Frame* frame22 = osgWidget::Frame::createSimpleFrameFromTheme(
|
|
"frameTheme",
|
|
osgDB::readRefImageFile("osgWidget/theme-2.png"),
|
|
300.0f,
|
|
300.0f,
|
|
osgWidget::Frame::FRAME_ALL
|
|
);
|
|
frame22->setPosition(300,100,0);
|
|
frame22->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
|
|
osgWidget::Frame* frame3 = osgWidget::Frame::createSimpleFrameFromTheme(
|
|
"frameTheme",
|
|
osgDB::readRefImageFile("osgWidget/theme-2.png"),
|
|
300.0f,
|
|
300.0f,
|
|
osgWidget::Frame::FRAME_ALL
|
|
);
|
|
frame3->setPosition(300,100,0);
|
|
frame3->getBackground()->setColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
osgWidget::Table* table = new osgWidget::Table("table", 2, 2);
|
|
osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
|
|
|
|
table->addWidget(new osgWidget::Widget("red", 300.0f, 300.0f), 0, 0);
|
|
table->addWidget(new osgWidget::Widget("white", 300.0f, 300.0f), 0, 1);
|
|
table->addWidget(new osgWidget::Widget("yellow", 300.0f, 300.0f), 1, 0);
|
|
table->addWidget(new osgWidget::Widget("purple", 300.0f, 300.0f), 1, 1);
|
|
table->getByRowCol(0, 0)->setColor(1.0f, 0.0f, 0.0f, 1.0f);
|
|
table->getByRowCol(0, 1)->setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
|
table->getByRowCol(1, 0)->setColor(1.0f, 1.0f, 0.0f, 1.0f);
|
|
table->getByRowCol(1, 1)->setColor(1.0f, 0.0f, 1.0f, 1.0f);
|
|
table->getByRowCol(0, 0)->setMinimumSize(100.0f, 100.0f);
|
|
table->getByRowCol(0, 1)->setMinimumSize(100.0f, 100.0f);
|
|
table->getByRowCol(1, 0)->setMinimumSize(100.0f, 100.0f);
|
|
table->getByRowCol(1, 1)->setMinimumSize(100.0f, 100.0f);
|
|
|
|
frame->setWindow(table);
|
|
|
|
// Give frame some nice textures.
|
|
// TODO: This has to be done after setWindow(); wtf?
|
|
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
osgWidget::Widget* l = frame->getBorder(osgWidget::Frame::BORDER_LEFT);
|
|
osgWidget::Widget* r = frame->getBorder(osgWidget::Frame::BORDER_RIGHT);
|
|
osgWidget::Widget* t = frame->getBorder(osgWidget::Frame::BORDER_TOP);
|
|
osgWidget::Widget* b = frame->getBorder(osgWidget::Frame::BORDER_BOTTOM);
|
|
|
|
l->setImage("osgWidget/border-left.tga", true);
|
|
r->setImage("osgWidget/border-right.tga", true);
|
|
t->setImage("osgWidget/border-top.tga", true);
|
|
b->setImage("osgWidget/border-bottom.tga", true);
|
|
|
|
l->setTexCoordWrapVertical();
|
|
r->setTexCoordWrapVertical();
|
|
t->setTexCoordWrapHorizontal();
|
|
b->setTexCoordWrapHorizontal();
|
|
|
|
// Create the bottom, XArt panel.
|
|
osgWidget::Widget* left = new osgWidget::Widget("left", 512.0f, 256.0f);
|
|
osgWidget::Widget* center = new osgWidget::Widget("center", 256.0f, 256.0f);
|
|
osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f);
|
|
|
|
left->setImage("osgWidget/panel-left.tga", true);
|
|
center->setImage("osgWidget/panel-center.tga", true);
|
|
right->setImage("osgWidget/panel-right.tga", true);
|
|
|
|
center->setTexCoordWrapHorizontal();
|
|
|
|
bottom->addWidget(left);
|
|
bottom->addWidget(center);
|
|
bottom->addWidget(right);
|
|
bottom->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
bottom->setOrigin(0.0f, 1024.0f - 256.0f);
|
|
|
|
// Add everything to the WindowManager.
|
|
wm->addChild(frame);
|
|
wm->addChild(frame2);
|
|
wm->addChild(frame22);
|
|
wm->addChild(frame3);
|
|
wm->addChild(bottom);
|
|
|
|
return osgWidget::createExample(viewer, wm);
|
|
}
|