From Jeremy Moles, updates to osgwidget examples.

Merged by Robert Osfield from OpenSceneGraph-osgWidget-dev
This commit is contained in:
Robert Osfield 2008-11-28 14:36:39 +00:00
parent 16bae8830e
commit 9b1841d009
18 changed files with 1116 additions and 230 deletions

View File

@ -65,13 +65,13 @@ public:
// Take special note here! Not only do the Button objects have their // Take special note here! Not only do the Button objects have their
// own overridden methods for changing the color, but they have attached // own overridden methods for changing the color, but they have attached
// callbacks for doing the work with local data. // callbacks for doing the work with local data.
getByName("Widget_1")->addCallback(osgWidget::Callback( getByName("Widget_1")->addCallback(new osgWidget::Callback(
&AddRemove::handlePressAdd, &AddRemove::handlePressAdd,
this, this,
osgWidget::EVENT_MOUSE_PUSH osgWidget::EVENT_MOUSE_PUSH
)); ));
getByName("Widget_2")->addCallback(osgWidget::Callback( getByName("Widget_2")->addCallback(new osgWidget::Callback(
&AddRemove::handlePressRemove, &AddRemove::handlePressRemove,
this, this,
osgWidget::EVENT_MOUSE_PUSH osgWidget::EVENT_MOUSE_PUSH
@ -94,7 +94,6 @@ public:
ss << "a random widget " << num; ss << "a random widget " << num;
_win1->addWidget(new ABCWidget(ss.str())); _win1->addWidget(new ABCWidget(ss.str()));
_win1->resize();
num++; num++;
@ -110,7 +109,6 @@ public:
osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get(); osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get();
_win1->removeWidget(w); _win1->removeWidget(w);
_win1->resize();
return true; return true;
} }

View File

@ -55,7 +55,7 @@ struct ColorWidget: public osgWidget::Widget {
} }
}; };
osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BOX_TYPE bt) { osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BoxType bt) {
osgWidget::Box* box = new osgWidget::Box(name, bt, true); osgWidget::Box* box = new osgWidget::Box(name, bt, true);
osgWidget::Widget* widget1 = new osgWidget::Widget(name + "_widget1", 100.0f, 100.0f); 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* widget2 = new osgWidget::Widget(name + "_widget2", 100.0f, 100.0f);
@ -78,17 +78,14 @@ osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BOX_TYPE bt)
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
osgViewer::CompositeViewer viewer; osgViewer::Viewer viewer;
osgViewer::View* view = new osgViewer::View();
osgWidget::WindowManager* wm = new osgWidget::WindowManager( osgWidget::WindowManager* wm = new osgWidget::WindowManager(
view, &viewer,
1280.0f, 1280.0f,
1024.0f, 1024.0f,
MASK_2D, MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG | osgWidget::WindowManager::WM_PICK_DEBUG
osgWidget::WindowManager::WM_NO_INVERT_Y
); );
wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY); wm->setPointerFocusMode(osgWidget::WindowManager::PFM_SLOPPY);
@ -118,5 +115,5 @@ int main(int argc, char** argv) {
model->setNodeMask(MASK_3D); model->setNodeMask(MASK_3D);
return osgWidget::createCompositeExample(viewer, view, wm, model); return osgWidget::createExample(viewer, wm, model);
} }

View File

@ -12,7 +12,7 @@ bool colorWidgetEnter(osgWidget::Event& event) {
// osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl; // osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl;
return true; return false;
} }
bool colorWidgetLeave(osgWidget::Event& event) { bool colorWidgetLeave(osgWidget::Event& event) {
@ -47,11 +47,11 @@ osgWidget::Widget* createWidget(
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->setEventMask(osgWidget::EVENT_ALL);
widget->addCallback(osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH)); widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH));
widget->addCallback(osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE)); widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE));
widget->addCallback(osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER)); widget->addCallback(new osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER));
widget->addCallback(osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE)); widget->addCallback(new osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE));
widget->addCallback(osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER)); widget->addCallback(new osgWidget::Callback(&widgetMouseOver, osgWidget::EVENT_MOUSE_OVER));
widget->setColor(col, col, col, 0.5f); widget->setColor(col, col, col, 0.5f);
widget->setLayer(layer); widget->setLayer(layer);
@ -71,7 +71,7 @@ int main(int argc, char** argv) {
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas"); osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
canvas->addCallback(osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER)); canvas->addCallback(new osgWidget::Callback(&windowMouseOver, osgWidget::EVENT_MOUSE_OVER));
canvas->attachMoveCallback(); canvas->attachMoveCallback();
canvas->attachRotateCallback(); canvas->attachRotateCallback();
canvas->attachScaleCallback(); canvas->attachScaleCallback();
@ -116,3 +116,27 @@ int main(int argc, char** argv) {
return osgWidget::createExample(viewer, wm); return osgWidget::createExample(viewer, wm);
} }
/*
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::Canvas* canvas = new osgWidget::Canvas("canvas");
canvas->addWidget(new osgWidget::Widget("spacer", 2.0f, 300.0f), 1280.0f, 0.0f);
canvas->setOrigin(0.0f, 300.0f);
wm->addChild(canvas);
return osgWidget::createExample(viewer, wm);
}
*/

View File

@ -5,6 +5,7 @@
#include <osgWidget/WindowManager> #include <osgWidget/WindowManager>
#include <osgWidget/Frame> #include <osgWidget/Frame>
#include <osgWidget/Box> #include <osgWidget/Box>
#include <osgDB/ReadFile>
const unsigned int MASK_2D = 0xF0000000; const unsigned int MASK_2D = 0xF0000000;
@ -27,6 +28,37 @@ int main(int argc, char** argv) {
300.0f 300.0f
); );
osgWidget::Frame* frame2 = osgWidget::Frame::createSimpleFrameFromTheme(
"frameTheme",
osgDB::readImageFile("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::readImageFile("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::readImageFile("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::Table* table = new osgWidget::Table("table", 2, 2);
osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL); osgWidget::Box* bottom = new osgWidget::Box("panel", osgWidget::Box::HORIZONTAL);
@ -69,9 +101,9 @@ int main(int argc, char** argv) {
osgWidget::Widget* center = new osgWidget::Widget("center", 256.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); osgWidget::Widget* right = new osgWidget::Widget("right", 512.0f, 256.0f);
left->setImage ("osgWidget/panel-left.tga", true); left->setImage("osgWidget/panel-left.tga", true);
center->setImage("osgWidget/panel-center.tga", true); center->setImage("osgWidget/panel-center.tga", true);
right->setImage ("osgWidget/panel-right.tga", true); right->setImage("osgWidget/panel-right.tga", true);
center->setTexCoordWrapHorizontal(); center->setTexCoordWrapHorizontal();
@ -83,6 +115,9 @@ int main(int argc, char** argv) {
// Add everything to the WindowManager. // Add everything to the WindowManager.
wm->addChild(frame); wm->addChild(frame);
wm->addChild(frame2);
wm->addChild(frame22);
wm->addChild(frame3);
wm->addChild(bottom); wm->addChild(bottom);
return osgWidget::createExample(viewer, wm); return osgWidget::createExample(viewer, wm);

View File

@ -1,106 +1,16 @@
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: osgwidgetinput.cpp 50 2008-05-06 05:06:36Z cubicool $ // $Id: osgwidgetinput.cpp 50 2008-05-06 05:06:36Z cubicool $
#include <osgDB/ReadFile>
#include <osgDB/WriteFile> #include <osgDB/WriteFile>
#include <osgViewer/ViewerEventHandlers>
#include <osgWidget/Util>
#include <osgWidget/WindowManager> #include <osgWidget/WindowManager>
#include <osgWidget/Box> #include <osgWidget/Box>
#include <osgWidget/Table>
#include <osgWidget/Frame>
#include <osgWidget/Label>
#include <osgWidget/Input> #include <osgWidget/Input>
#include <osgWidget/ViewerEventHandlers>
const unsigned int MASK_2D = 0xF0000000; const unsigned int MASK_2D = 0xF0000000;
const char* INFO =
"Use the Input Wigets below to enter the X, Y, and Z position of a\n"
"sphere to be inserted into the scene. Once you've done this, use\n"
"the button below to add it!"
;
void setupLabel(osgWidget::Label* label) {
label->setFontSize(16);
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label->setFont("fonts/Vera.ttf");
label->setPadding(2.0f);
label->setHeight(18.0f);
label->setCanFill(true);
}
osgWidget::Input* createTableRow(
osgWidget::Table* table,
unsigned int rowNum,
const std::string& valName
) {
std::stringstream ssLabel;
std::stringstream ssInput;
ssLabel << "Label_Row" << rowNum;
ssInput << "Input_Row" << rowNum;
osgWidget::Label* label = new osgWidget::Label(ssLabel.str(), valName);
osgWidget::Input* input = new osgWidget::Input(ssInput.str(), "", 20);
setupLabel(label);
setupLabel(input);
label->setWidth(50.0f);
label->setColor(0.1f, 0.1f, 0.1f, 1.0f);
input->setWidth(150.0f);
input->setColor(0.4f, 0.4f, 0.4f, 1.0f);
table->addWidget(label, rowNum, 0);
table->addWidget(input, rowNum, 1);
return input;
}
osgWidget::Label* createLabel(const std::string& text) {
osgWidget::Label* label = new osgWidget::Label("", text);
setupLabel(label);
return label;
}
class Button: public osgWidget::Label {
public:
typedef std::vector<osgWidget::Input*> Inputs;
private:
Inputs _xyz;
public:
Button(const std::string& text, const Inputs& inputs):
osgWidget::Label("", text),
_xyz(inputs) {
setupLabel(this);
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
setShadow(0.1f);
addHeight(4.0f);
}
bool mousePush(double, double, osgWidget::WindowManager*) {
osgWidget::warn()
<< "x: " << _xyz[0]->getLabel() << std::endl
<< "y: " << _xyz[1]->getLabel() << std::endl
<< "z: " << _xyz[2]->getLabel() << std::endl
;
return false;
}
};
// TODO: Testing our _parent/EmbeddedWindow stuff.
bool info(osgWidget::Event& ev) {
osgWidget::warn() << "MousePush @ Window: " << ev.getWindow()->getName() << std::endl;
return true;
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
@ -113,73 +23,37 @@ int main(int argc, char** argv) {
); );
osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL); osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
osgWidget::Table* table = new osgWidget::Table("table", 3, 2); osgWidget::Input* input = new osgWidget::Input("input", "", 50);
osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL);
osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL); input->setFont("fonts/VeraMono.ttf");
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( input->setFontColor(0.0f, 0.0f, 0.0f, 1.0f);
"frame", input->setFontSize(15);
"osgWidget/theme.png", input->setYOffset(input->calculateBestYOffset("y"));
64.0f, input->setSize(400.0f, input->getText()->getCharacterHeight());
64.0f,
16.0f, box->addWidget(input);
16.0f, box->setOrigin(200.0f, 200.0f);
100.0f,
100.0f wm->addChild(box);
viewer.setUpViewInWindow(
50,
50,
static_cast<int>(wm->getWidth()),
static_cast<int>(wm->getHeight())
); );
osgWidget::Input* x = createTableRow(table, 0, "X Position"); osg::Camera* camera = wm->createParentOrthoCamera();
osgWidget::Input* y = createTableRow(table, 1, "Y Position");
osgWidget::Input* z = createTableRow(table, 2, "Z Position");
Button::Inputs inputs; 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::WindowSizeHandler());
inputs.push_back(x); wm->resizeAllWindows();
inputs.push_back(y);
inputs.push_back(z);
table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH)); viewer.setSceneData(camera);
lbox1->addWidget(createLabel(INFO)); return viewer.run();
lbox2->addWidget(new Button("Add To Scene...", inputs));
box->addWidget(lbox1->embed());
box->addWidget(table->embed());
box->addWidget(lbox2->embed());
box->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
frame->setWindow(box);
frame->getEmbeddedWindow()->setSize(box->getWidth(), box->getHeight());
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
frame->attachTabFocusCallback();
for(osgWidget::Frame::Iterator i = frame->begin(); i != frame->end(); i++) {
if(i->valid()) i->get()->setColor(0.5f, 0.7f, 1.0f, 1.0f);
}
wm->addChild(frame);
/*
// Print out our focus list, it should just have 3 widgets.
osgWidget::WidgetList wl;
box->getFocusList(wl);
for(osgWidget::WidgetList::iterator i = wl.begin(); i != wl.end(); i++) {
osgWidget::warn() << i->get()->getName() << std::endl;
}
*/
lbox1->getBackground()->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::UPPER_LEFT);
lbox1->getBackground()->setColor(0.0f, 1.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);
lbox1->getBackground()->setColor(0.0f, 0.0f, 1.0f, 1.0f, osgWidget::Widget::LOWER_RIGHT);
lbox1->getBackground()->setColor(1.0f, 1.0f, 1.0f, 1.0f, osgWidget::Widget::UPPER_RIGHT);
lbox1->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
lbox1->update();
int r = osgWidget::createExample(viewer, wm);
// osgWidget::writeWindowManagerNode(wm);
// osgDB::writeNodeFile(*box, "osgWidget.osg");
return r;
} }

View File

@ -47,8 +47,8 @@ int main(int argc, char** argv) {
1280.0f, 1280.0f,
1024.0f, 1024.0f,
MASK_2D, MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG | // osgWidget::WindowManager::WM_USE_RENDERBINS |
osgWidget::WindowManager::WM_NO_INVERT_Y osgWidget::WindowManager::WM_PICK_DEBUG
); );
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL); osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
@ -64,7 +64,9 @@ int main(int argc, char** argv) {
label2->addSize(21.0f, 22.0f); label2->addSize(21.0f, 22.0f);
label1->setColor(1.0f, 0.5f, 0.0f, 0.0f); label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
label2->setColor(1.0f, 0.5f, 0.0f, 0.0f); label2->setColor(1.0f, 0.5f, 0.0f, 0.5f);
label2->setImage("Images/Brick-Norman-Brown.TGA", true);
box->addWidget(label1); box->addWidget(label1);
box->addWidget(label2); box->addWidget(label2);
@ -85,11 +87,11 @@ int main(int argc, char** argv) {
label4->setColor(0.0f, 0.0f, 0.5f, 0.5f); label4->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setColor(0.0f, 0.0f, 0.5f, 0.5f); label5->setColor(0.0f, 0.0f, 0.5f, 0.5f);
label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT); //label5->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM); //label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
// Test our label copy construction... // Test our label copy construction...
osgWidget::Label* label6 = osg::clone(label5,"label6"); osgWidget::Label* label6 = osg::clone(label5, "label6", osg::CopyOp::DEEP_COPY_ALL);
label6->setLabel("abcdefghijklmnopqrs"); label6->setLabel("abcdefghijklmnopqrs");
@ -108,7 +110,7 @@ int main(int argc, char** argv) {
// vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT); // vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
// Test our label-in-window copy construction... // Test our label-in-window copy construction...
osgWidget::Box* clonedBox = osg::clone(box,"HBOX-new"); osgWidget::Box* clonedBox = osg::clone(box, "HBOX-new", osg::CopyOp::DEEP_COPY_ALL);
clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f); clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);

View File

@ -3,6 +3,5 @@
SET(TARGET_SRC osgwidgetmenu.cpp ) SET(TARGET_SRC osgwidgetmenu.cpp )
SET(TARGET_ADDED_LIBRARIES osgWidget ) SET(TARGET_ADDED_LIBRARIES osgWidget )
#### end var setup ### #### end var setup ###
SETUP_EXAMPLE(osgwidgetmenu) SETUP_EXAMPLE(osgwidgetmenu)

View File

@ -105,8 +105,7 @@ int main(int argc, char** argv) {
1280.0f, 1280.0f,
1024.0f, 1024.0f,
MASK_2D, MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG | osgWidget::WindowManager::WM_PICK_DEBUG
osgWidget::WindowManager::WM_NO_BETA_WARN
); );
osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL); osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL);

View File

@ -0,0 +1,7 @@
#this file is automatically generated
SET(TARGET_SRC osgwidgetmessagebox.cpp )
SET(TARGET_ADDED_LIBRARIES osgWidget )
#### end var setup ###
SETUP_EXAMPLE(osgwidgetmessagebox)

View File

@ -0,0 +1,662 @@
// -*-c++-*- osgWidget - Copyright Cedric Pinson 2008
#include <osgWidget/Util>
#include <osgWidget/WindowManager>
#include <osgWidget/Frame>
#include <osgWidget/Box>
#include <osgWidget/Widget>
#include <osgWidget/Types>
#include <osgDB/ReadFile>
#include <osgAnimation/EaseMotion>
#include <osg/io_utils>
#include <iostream>
const unsigned int MASK_2D = 0xF0000000;
class MessageBox
{
protected:
osgWidget::Frame* createButtonOk(const std::string& theme, const std::string& text, const std::string& font, int fontSize);
osgWidget::Label* createLabel(const std::string& string, const std::string& font, int size, const osgWidget::Color& color);
osg::ref_ptr<osgWidget::Frame> _window;
osg::ref_ptr<osgWidget::Frame> _button;
public:
osgWidget::Frame* getButton();
osgWidget::Frame* getWindow();
bool create(const std::string& themeMessage,
const std::string& themeButton,
const std::string& titleText,
const std::string& messageText,
const std::string& buttonText,
const std::string& font,
int fontSize);
};
osgWidget::Frame* MessageBox::getButton() { return _button.get(); }
osgWidget::Frame* MessageBox::getWindow() { return _window.get(); }
struct AlphaSetterVisitor : public osg::NodeVisitor
{
float _alpha;
AlphaSetterVisitor( float alpha = 1.0):osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) { _alpha = alpha;}
void apply(osg::MatrixTransform& node)
{
osgWidget::Window* win = dynamic_cast<osgWidget::Window*>(&node);
if (win) {
// osgWidget::warn() << "I am in Window: " << win->getName() << std::endl;
for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++)
{
// osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl;
osgWidget::Color color = it->get()->getColor();
color[3] = color[3] *_alpha;
it->get()->setColor(color);
}
{
osgWidget::Color color = win->getBackground()->getColor();
color[3] = color[3] *_alpha;
win->getBackground()->setColor(color);
}
}
traverse(node);
}
};
struct ColorSetterVisitor : public osg::NodeVisitor
{
osgWidget::Color _color;
ColorSetterVisitor( const osgWidget::Color& color):osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) { _color = color;}
void apply(osg::MatrixTransform& node)
{
osgWidget::Window* win = dynamic_cast<osgWidget::Window*>(&node);
if (win) {
// osgWidget::warn() << "I am in Window: " << win->getName() << std::endl;
for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++)
{
// osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl;
// osgWidget::Color color = it->get()->getColor();
// color[3] = color[3] *_alpha;
it->get()->setColor(_color);
}
{
// osgWidget::Color color = win->getBackground()->getColor();
// color[3] = color[3] *_alpha;
win->getBackground()->setColor(osgWidget::Color(0,0,0,0));
}
}
traverse(node);
}
};
struct EventOK : public osgWidget::Callback, osg::NodeCallback
{
typedef osgAnimation::OutCubicMotion WidgetMotion;
// typedef osgAnimation::OutQuartMotion WidgetMotion;
WidgetMotion _motionOver;
WidgetMotion _motionLeave;
double _lastUpdate;
osgWidget::Color _defaultColor;
osgWidget::Color _overColor;
bool _over;
osg::ref_ptr<osgWidget::Frame> _frame;
float _width;
float _height;
EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame)
{
_motionOver = WidgetMotion(0.0, 0.4);
_motionLeave = WidgetMotion(0.0, 0.5);
_defaultColor = _frame->getEmbeddedWindow()->getColor();
_overColor = osgWidget::Color(229.0/255.0,
103.0/255.0,
17.0/255,
_defaultColor[3]);
_over = false;
}
bool operator()(osgWidget::Event& ev)
{
if (ev.type == osgWidget::EVENT_MOUSE_ENTER)
{
_over = true;
_width = _frame->getWidth();
_height = _frame->getHeight();
_motionOver.reset();
std::cout << "enter" << std::endl;
return true;
}
else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE)
{
_over = false;
_motionLeave.reset();
std::cout << "leave" << std::endl;
return true;
}
return false;
}
void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
const osg::FrameStamp* fs = nv->getFrameStamp();
double dt = fs->getSimulationTime() - _lastUpdate;
_lastUpdate = fs->getSimulationTime();
if (_frame.valid())
{
float value;
if (_over)
{
_motionOver.update(dt);
value = _motionOver.getValue();
}
else
{
_motionLeave.update(dt);
value = 1.0 - _motionLeave.getValue();
}
osgWidget::Color c = _defaultColor + ((_overColor - _defaultColor) * value);
ColorSetterVisitor colorSetter(c);
_frame->accept(colorSetter);
}
}
node->traverse(*nv);
}
};
osgWidget::Label* MessageBox::createLabel(const std::string& string, const std::string& font, int size, const osgWidget::Color& color)
{
osgWidget::Label* label = new osgWidget::Label("", "");
label->setFont(font);
label->setFontSize(size);
label->setFontColor(color);
label->setColor(osgWidget::Color(0,0,0,0));
label->setLabel(string);
label->setCanFill(true);
return label;
}
osgWidget::Frame* MessageBox::createButtonOk(const std::string& theme,
const std::string& text,
const std::string& font,
int fontSize)
{
osg::ref_ptr<osgWidget::Frame> frame = osgWidget::Frame::createSimpleFrameFromTheme(
"ButtonOK",
osgDB::readImageFile(theme),
300.0f,
50.0f,
osgWidget::Frame::FRAME_TEXTURE
);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
osgWidget::Label* label = createLabel(text, font, fontSize, osgWidget::Color(0,0,0,1));
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
box->addWidget(label);
box->resize();
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
box->getBackground()->setColor(colorBack);
frame->getEmbeddedWindow()->setWindow(box);
box->setEventMask(osgWidget::EVENT_NONE);
frame->resizeFrame(box->getWidth(), box->getHeight());
frame->resizeAdd(0, 0);
EventOK* event = new EventOK(frame);
frame->setUpdateCallback(event);
frame->addCallback(event);
return frame.release();
}
bool MessageBox::create(const std::string& themeMessage,
const std::string& themeButton,
const std::string& titleText,
const std::string& messageText,
const std::string& buttonText,
const std::string& font,
int fontSize)
{
osg::ref_ptr<osgWidget::Frame> frame = osgWidget::Frame::createSimpleFrameFromTheme(
"error",
osgDB::readImageFile(themeMessage),
300.0f,
50.0f,
osgWidget::Frame::FRAME_ALL
);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
osgWidget::Label* labelText = createLabel(messageText, font, fontSize, osgWidget::Color(0,0,0,1));
osgWidget::Label* labelTitle = createLabel(titleText, font, fontSize+5, osgWidget::Color(0.4,0,0,1));
osgWidget::Box* box = new osgWidget::Box("VBOX", osgWidget::Box::VERTICAL);
_button = createButtonOk(themeButton, buttonText, font, fontSize);
osgWidget::Widget* buttonOK = _button->embed();
buttonOK->setColor(osgWidget::Color(0,0,0,0));
buttonOK->setCanFill(false);
box->addWidget(buttonOK);
box->addWidget(labelText);
box->addWidget(labelTitle);
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
box->getBackground()->setColor(colorBack);
frame->setWindow(box);
box->resize();
frame->resizeFrame(box->getWidth(), box->getHeight());
_window = frame;
return true;
}
const char* LABEL1 =
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
"do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n"
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..."
;
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
);
int fontSize = 20;
std::string font="fonts/arial.ttf";
std::string buttonTheme = "osgWidget/theme-8-shadow.png";
std::string borderTheme = "osgWidget/theme-8.png";
MessageBox message;
message.create(borderTheme,
buttonTheme,
"Error - Critical",
LABEL1,
"Quit",
font,
fontSize);
AlphaSetterVisitor alpha(.8f);
message.getWindow()->accept(alpha);
wm->addChild(message.getWindow());
// center
osgWidget::point_type w = wm->getWidth();
osgWidget::point_type h = wm->getHeight();
osgWidget::point_type ww = message.getWindow()->getWidth();
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] ));
// frame->resizeAdd(30, 30);
// AlphaSetterVisitor alpha(.8f);
// frame->accept(alpha);
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
}
#if 0
struct AlphaSetterVisitor : public osg::NodeVisitor
{
float _alpha;
AlphaSetterVisitor( float alpha = 1.0):osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) { _alpha = alpha;}
void apply(osg::MatrixTransform& node)
{
osgWidget::Window* win = dynamic_cast<osgWidget::Window*>(&node);
if (win) {
// osgWidget::warn() << "I am in Window: " << win->getName() << std::endl;
for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++)
{
// osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl;
osgWidget::Color color = it->get()->getColor();
color[3] = color[3] *_alpha;
it->get()->setColor(color);
}
{
osgWidget::Color color = win->getBackground()->getColor();
color[3] = color[3] *_alpha;
win->getBackground()->setColor(color);
}
}
traverse(node);
}
};
struct ColorSetterVisitor : public osg::NodeVisitor
{
osgWidget::Color _color;
ColorSetterVisitor( const osgWidget::Color& color):osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) { _color = color;}
void apply(osg::MatrixTransform& node)
{
osgWidget::Window* win = dynamic_cast<osgWidget::Window*>(&node);
if (win) {
// osgWidget::warn() << "I am in Window: " << win->getName() << std::endl;
for (osgWidget::Window::Iterator it = win->begin(); it != win->end(); it++)
{
// osgWidget::warn() << " I am operating on Widget: " << it->get()->getName() << std::endl;
// osgWidget::Color color = it->get()->getColor();
// color[3] = color[3] *_alpha;
it->get()->setColor(_color);
}
{
// osgWidget::Color color = win->getBackground()->getColor();
// color[3] = color[3] *_alpha;
win->getBackground()->setColor(osgWidget::Color(0,0,0,0));
}
}
traverse(node);
}
};
struct EventOK : public osgWidget::Callback, osg::NodeCallback
{
typedef osgAnimation::OutQuartMotion WidgetMotion;
WidgetMotion _motionOver;
WidgetMotion _motionLeave;
double _lastUpdate;
osgWidget::Color _defaultColor;
osgWidget::Color _overColor;
bool _over;
osg::ref_ptr<osgWidget::Frame> _frame;
float _width;
float _height;
EventOK(osgWidget::Frame* frame) : osgWidget::Callback(osgWidget::EVENT_ALL), _frame(frame)
{
_motionOver = WidgetMotion(0.0, 0.4);
_motionLeave = WidgetMotion(0.0, 0.5);
_defaultColor = _frame->getEmbeddedWindow()->getColor();
_overColor = osgWidget::Color(229.0/255.0,
103.0/255.0,
17.0/255,
_defaultColor[3]);
_over = false;
}
bool operator()(osgWidget::Event& ev)
{
if (ev.type == osgWidget::EVENT_MOUSE_ENTER)
{
_over = true;
// std::cout << "Enter" << std::endl;
_width = _frame->getWidth();
_height = _frame->getHeight();
_motionOver.reset();
// _frame->resize(_width * 1.2, _height * 1.2);
return true;
}
else if (ev.type == osgWidget::EVENT_MOUSE_LEAVE)
{
_over = false;
// std::cout << "Leave" << std::endl;
// _frame->resize(_width, _height);
_motionLeave.reset();
return true;
}
return false;
}
void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
const osg::FrameStamp* fs = nv->getFrameStamp();
double dt = fs->getSimulationTime() - _lastUpdate;
_lastUpdate = fs->getSimulationTime();
if (_frame.valid())
{
float value;
if (_over)
{
_motionOver.update(dt);
value = _motionOver.getValue();
}
else
{
_motionLeave.update(dt);
value = 1.0 - _motionLeave.getValue();
}
osgWidget::Color c = _defaultColor + ((_overColor - _defaultColor) * value);
ColorSetterVisitor colorSetter(c);
_frame->accept(colorSetter);
}
}
node->traverse(*nv);
}
};
osgWidget::Label* createLabel(const std::string& string, const std::string& font, int size, const osgWidget::Color& color)
{
osgWidget::Label* label = new osgWidget::Label("", "");
label->setFont(font);
label->setFontSize(size);
label->setFontColor(color);
label->setColor(osgWidget::Color(0,0,0,0));
label->setLabel(string);
label->setCanFill(true);
return label;
}
osgWidget::Window* createButtonOk(const std::string& theme, const std::string& text, int fontSize)
{
osg::ref_ptr<osgWidget::Frame> frame = osgWidget::Frame::createSimpleFrameFromTheme(
"ButtonOK",
osgDB::readImageFile(theme),
300.0f,
50.0f,
osgWidget::Frame::FRAME_TEXTURE
);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
osgWidget::Label* label = createLabel(text, "fonts/Vera.ttf", fontSize, osgWidget::Color(0,0,0,1));
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
box->addWidget(label);
box->resize();
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
box->getBackground()->setColor(colorBack);
frame->getEmbeddedWindow()->setWindow(box);
box->setEventMask(osgWidget::EVENT_NONE);
frame->resizeFrame(box->getWidth(), box->getHeight());
frame->resizeAdd(0, 0);
EventOK* event = new EventOK(frame);
frame->setUpdateCallback(event);
frame->addCallback(event);
return frame.release();
}
osgWidget::Frame* createErrorMessage(const std::string& themeMessage,
const std::string& themeButton,
const std::string& titleText,
const std::string& messageText,
const std::string& buttonText,
const std::string& font,
int fontSize)
{
osg::ref_ptr<osgWidget::Frame> frame = osgWidget::Frame::createSimpleFrameFromTheme(
"error",
osgDB::readImageFile(themeMessage),
300.0f,
50.0f,
osgWidget::Frame::FRAME_ALL
);
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
osgWidget::Label* labelText = createLabel(messageText, font, fontSize, osgWidget::Color(0,0,0,1));
osgWidget::Label* labelTitle = createLabel(titleText, font, fontSize+5, osgWidget::Color(0.4,0,0,1));
osgWidget::Box* box = new osgWidget::Box("VBOX", osgWidget::Box::VERTICAL);
osgWidget::Widget* buttonOK = createButtonOk(themeButton, buttonText, fontSize)->embed();
buttonOK->setColor(osgWidget::Color(0,0,0,0));
buttonOK->setCanFill(false);
box->addWidget(buttonOK);
box->addWidget(labelText);
box->addWidget(labelTitle);
osgWidget::Color colorBack = frame->getEmbeddedWindow()->getColor();
box->getBackground()->setColor(colorBack);
frame->setWindow(box);
box->resize();
frame->resizeFrame(box->getWidth(), box->getHeight());
return frame.release();
}
const char* LABEL1 =
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed\n"
"do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n"
"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in..."
;
int main(int argc, char** argv)
{
std::string theme = "osgWidget/theme-1.png";
if (argc > 1)
theme = std::string(argv[1]);
osgViewer::Viewer viewer;
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
&viewer,
1280.0f,
1024.0f,
MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG
);
osgWidget::Frame* frame = createErrorMessage(theme,
"osgWidget/theme-8-shadow.png",
"Error - Critical",
LABEL1,
"Ok",
"fonts/Vera.ttf",
20);
// Add everything to the WindowManager.
wm->addChild(frame);
frame->resizeAdd(30, 30);
AlphaSetterVisitor alpha(.8f);
frame->accept(alpha);
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
}
#endif

View File

@ -2,11 +2,16 @@
// $Id: osgwidgetnotebook.cpp 45 2008-04-23 16:46:11Z cubicool $ // $Id: osgwidgetnotebook.cpp 45 2008-04-23 16:46:11Z cubicool $
#include <osg/io_utils> #include <osg/io_utils>
#include <osgGA/TrackballManipulator>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgWidget/Util> #include <osgWidget/Util>
#include <osgWidget/WindowManager> #include <osgWidget/WindowManager>
#include <osgWidget/Box> #include <osgWidget/Box>
#include <osgWidget/Canvas> #include <osgWidget/Canvas>
#include <osgWidget/Label> #include <osgWidget/Label>
#include <osgWidget/Label>
#include <osgWidget/ViewerEventHandlers>
const unsigned int MASK_2D = 0xF0000000; const unsigned int MASK_2D = 0xF0000000;
const unsigned int MASK_3D = 0x0F000000; const unsigned int MASK_3D = 0x0F000000;
@ -23,12 +28,12 @@ public:
for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer( for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(
osgWidget::Widget::LAYER_MIDDLE, osgWidget::Widget::LAYER_MIDDLE,
i i * 2
); );
_windows->getByName(ev.getWidget()->getName())->setLayer( _windows->getByName(ev.getWidget()->getName())->setLayer(
osgWidget::Widget::LAYER_MIDDLE, osgWidget::Widget::LAYER_MIDDLE,
objs.size() objs.size() * 2
); );
_windows->resize(); _windows->resize();
@ -78,13 +83,13 @@ public:
label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f); label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
label2->setLabel(descr.str()); label2->setLabel(descr.str());
label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i); label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i * 2);
label2->addSize(50.0f, 50.0f); label2->addSize(50.0f, 50.0f);
_windows->addWidget(label2, 0.0f, 0.0f); _windows->addWidget(label2, 0.0f, 0.0f);
label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH); label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);
label1->addCallback(osgWidget::Callback( label1->addCallback(new osgWidget::Callback(
&Notebook::callbackTabPressed, &Notebook::callbackTabPressed,
this, this,
osgWidget::EVENT_MOUSE_PUSH osgWidget::EVENT_MOUSE_PUSH
@ -107,6 +112,12 @@ public:
} }
}; };
void bound(osg::Node* node) {
osg::BoundingSphere bs = node->getBound();
osgWidget::warn() << "center: " << bs.center() << " radius: " << bs.radius() << std::endl;
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
@ -114,21 +125,20 @@ int main(int argc, char** argv) {
&viewer, &viewer,
1280.0f, 1280.0f,
720.0f, 720.0f,
MASK_2D, MASK_2D //,
osgWidget::WindowManager::WM_PICK_DEBUG //osgWidget::WindowManager::WM_USE_RENDERBINS
); );
Notebook* notebook = new Notebook("notebook"); Notebook* notebook1 = new Notebook("notebook1");
Notebook* notebook2 = new Notebook("notebook2");
osgWidget::warn() notebook2->setOrigin(100.0f, 100.0f);
<< "Sizes are..." << std::endl
<< "Cur: " << notebook->getSize() << std::endl
<< "Min: " << notebook->getMinSize() << std::endl
;
notebook->attachMoveCallback(); notebook1->attachMoveCallback();
notebook2->attachMoveCallback();
wm->addChild(notebook); wm->addChild(notebook1);
wm->addChild(notebook2);
return osgWidget::createExample(viewer, wm); return osgWidget::createExample(viewer, wm);
} }

View File

@ -0,0 +1,7 @@
#this file is automatically generated
SET(TARGET_SRC osgwidgetperformance.cpp )
SET(TARGET_ADDED_LIBRARIES osgWidget )
#### end var setup ###
SETUP_EXAMPLE(osgwidgetperformance)

View File

@ -0,0 +1,154 @@
#include <iostream>
#include <osg/ArgumentParser>
#include <osgDB/ReadFile>
#include <osgWidget/Canvas>
#include <osgWidget/WindowManager>
#include <osgWidget/Util>
void setupArguments(osg::ArgumentParser& args) {
args.getApplicationUsage()->setDescription(
args.getApplicationName() + " is a performance testing application for osgWidget."
);
args.getApplicationUsage()->setCommandLineUsage(
args.getApplicationName() + " [options] widgets"
);
args.getApplicationUsage()->addCommandLineOption(
"--width <int>",
"The WindowManager width."
);
args.getApplicationUsage()->addCommandLineOption(
"--height <int>",
"The WindowManager height."
);
args.getApplicationUsage()->addCommandLineOption(
"--size <int>",
"The size of the square Widgets."
);
args.getApplicationUsage()->addCommandLineOption(
"--single-window",
"All widgets are put inside a single Window."
);
args.getApplicationUsage()->addCommandLineOption(
"--multi-window",
"All widgets are in their own Windows."
);
}
void readSize(osg::ArgumentParser& args, const char* opt, unsigned int& val) {
std::string size;
while(args.read(opt, size)) {
int s = std::atoi(size.c_str());
if(s > 0) val = s;
}
}
int doError(const char* errorMsg) {
osgWidget::warn() << errorMsg << std::endl;
return 1;
}
int doApp(osgViewer::Viewer& viewer, osg::Node* node, unsigned int width, unsigned int height) {
osgWidget::WindowManager* wm = new osgWidget::WindowManager(&viewer, width, height, 0x12);
wm->addChild(node);
return osgWidget::createExample(viewer, wm);
}
int main(int argc, char** argv) {
osg::ArgumentParser args(&argc, argv);
setupArguments(args);
osgViewer::Viewer viewer(args);
while(args.read("--help")) {
args.getApplicationUsage()->write(
std::cout,
osg::ApplicationUsage::COMMAND_LINE_OPTION
);
return 0;
}
std::string size;
unsigned int width = 1280;
unsigned int height = 1024;
unsigned int wSize = 10;
bool singleWindow = false;
bool multiWindow = false;
readSize(args, "--width", width);
readSize(args, "--height", height);
readSize(args, "--size", wSize);
while(args.read("--single-window")) singleWindow = true;
while(args.read("--multi-window")) multiWindow = true;
unsigned int numWidgets = 0;
if(args.argc() >= 2) numWidgets = std::atoi(args[1]);
else return doError("Please specify the number of Widgets to use.");
if(numWidgets <= 0) return doError("Please specify one or more Widgets to use.");
if(!singleWindow && !multiWindow) return doError(
"Please specify one of --single-window or --multi-window."
);
if(singleWindow) {
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
canvas->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
unsigned int rows = height / (wSize + 2);
unsigned int cols = (numWidgets / rows) + 1;
unsigned int w = 0;
/*
osg::Image* image = osgDB::readImageFile("osgWidget/natascha.png");
osg::Texture2D* texture = new osg::Texture2D();
texture->setImage(0, image);
*/
for(unsigned int c = 0; c < cols; c++) {
for(unsigned int r = 0; r < rows; r++) {
if(w >= numWidgets) break;
osgWidget::Widget* widget = new osgWidget::Widget(
"",
wSize,
wSize
);
float col = static_cast<float>(w) / static_cast<float>(numWidgets);
widget->setColor(col, col, col, 0.9f);
// widget->setTexture(texture, true);
canvas->addWidget(widget, c * (wSize + 2), r * (wSize + 2));
w++;
}
}
return doApp(viewer, canvas, width, height);
}
else doError("Not supported yet.");
return 1;
}

View File

@ -0,0 +1,7 @@
#this file is automatically generated
SET(TARGET_SRC osgwidgetprogress.cpp )
SET(TARGET_ADDED_LIBRARIES osgWidget )
#### end var setup ###
SETUP_EXAMPLE(osgwidgetprogress)

View File

@ -0,0 +1,91 @@
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id$
#include <osgDB/ReadFile>
#include <osgWidget/Util>
#include <osgWidget/WindowManager>
#include <osgWidget/Canvas>
const unsigned int MASK_2D = 0xF0000000;
struct UpdateProgressNode: public osg::NodeCallback {
float start;
float done;
UpdateProgressNode():
start (0.0f),
done (5.0f) {
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) {
const osg::FrameStamp* fs = nv->getFrameStamp();
float t = fs->getSimulationTime();
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;
osgWidget::Window* window = dynamic_cast<osgWidget::Window*>(node);
if(!window) return;
osgWidget::Widget* w = window->getByName("pMeter");
osgWidget::Label* l = dynamic_cast<osgWidget::Label*>(window->getByName("pLabel"));
if(!w || !l) return;
w->setWidth(width);
w->setTexCoordRegion(0.0f, 0.0f, width, 64.0f);
std::ostringstream ss;
ss << osg::round(percent) << "% Done" << std::endl;
l->setLabel(ss.str());
}
};
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::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);
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());
wm->addChild(canvas);
return osgWidget::createExample(viewer, wm, osgDB::readNodeFile("cow.osg"));
}

View File

@ -1,6 +1,8 @@
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008 // -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: osgwidgetframe.cpp 34 2008-04-07 03:12:41Z cubicool $ // $Id: osgwidgetframe.cpp 34 2008-04-07 03:12:41Z cubicool $
#include <osgDB/ReadFile>
#include <osgWidget/Util> #include <osgWidget/Util>
#include <osgWidget/WindowManager> #include <osgWidget/WindowManager>
#include <osgWidget/Frame> #include <osgWidget/Frame>
@ -84,17 +86,15 @@ int main(int argc, char** argv) {
1024.0f, 1024.0f,
MASK_2D, MASK_2D,
osgWidget::WindowManager::WM_PICK_DEBUG osgWidget::WindowManager::WM_PICK_DEBUG
//osgWidget::WindowManager::WM_NO_INVERT_Y
); );
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture( osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameFromTheme(
"frame", "frame",
"osgWidget/theme-2.png", osgDB::readImageFile("osgWidget/theme.png"),
64.0f, 40.0f,
64.0f, 40.0f,
16.0f, osgWidget::Frame::FRAME_ALL
16.0f,
100.0f,
100.0f
); );
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f); frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
@ -122,11 +122,12 @@ int main(int argc, char** argv) {
box->addWidget(img4); box->addWidget(img4);
box->setEventMask(osgWidget::EVENT_NONE); box->setEventMask(osgWidget::EVENT_NONE);
frame->getEmbeddedWindow()->setWindow(box); //frame->getEmbeddedWindow()->setWindow(box);
frame->setWindow(box);
frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f); frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f);
frame->resize(300.0f, 300.0f); frame->resize(300.0f, 300.0f);
frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL)); frame->addCallback(new osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL));
frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN)); frame->addCallback(new osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN));
wm->addChild(frame); wm->addChild(frame);

View File

@ -56,7 +56,8 @@ int main(int argc, char** argv) {
// textual name, such as "MainGUIParent" or something. // textual name, such as "MainGUIParent" or something.
table->getByName("0, 0")->setAlignHorizontal(osgWidget::Widget::HA_LEFT); table->getByName("0, 0")->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
table->getByName("0, 0")->setAlignVertical(osgWidget::Widget::VA_BOTTOM); table->getByName("0, 0")->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
table->getByName("0, 0")->setPadding(10.0f); 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. // 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, 0")->setColor(1.0f, 0.0f, 0.0f, 1.0f, osgWidget::Widget::LOWER_LEFT);

View File

@ -45,6 +45,19 @@ struct Object {
} }
}; };
// This is the more "traditional" method of creating a callback.
struct CallbackObject: public osgWidget::Callback {
CallbackObject(osgWidget::EventType evType):
osgWidget::Callback(evType) {
}
virtual bool operator()(osgWidget::Event& ev) {
std::cout << "here" << std::endl;
return false;
}
};
int main(int argc, char** argv) { int main(int argc, char** argv) {
osgViewer::Viewer viewer; osgViewer::Viewer viewer;
@ -65,8 +78,7 @@ int main(int argc, char** argv) {
MASK_2D, MASK_2D,
osgWidget::WindowManager::WM_USE_LUA | osgWidget::WindowManager::WM_USE_LUA |
osgWidget::WindowManager::WM_USE_PYTHON | osgWidget::WindowManager::WM_USE_PYTHON |
osgWidget::WindowManager::WM_PICK_DEBUG | osgWidget::WindowManager::WM_PICK_DEBUG
osgWidget::WindowManager::WM_NO_BETA_WARN
); );
// An actual osgWidget::Window is pure virtual, so we've got to use the osgWidget::Box // An actual osgWidget::Window is pure virtual, so we've got to use the osgWidget::Box
@ -81,13 +93,17 @@ int main(int argc, char** argv) {
static std::string data = "lol ur face!"; static std::string data = "lol ur face!";
box->addCallback(osgWidget::Callback(&windowClicked, osgWidget::EVENT_MOUSE_PUSH, &data)); /*
box->addCallback(osgWidget::Callback(&windowScrolled, osgWidget::EVENT_MOUSE_SCROLL)); 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( box->addCallback(osgWidget::Callback(
&Object::windowClicked, &Object::windowClicked,
&obj, &obj,
osgWidget::EVENT_MOUSE_PUSH 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 // 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 // during testing which I've kept around for testing purposes. You'll notice
@ -124,7 +140,7 @@ int main(int argc, char** argv) {
// Now, lets clone our existing box and create a new copy of of it, also adding that // 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, // to the WindowManager. This demonstrates the usages of OSG's ->clone() support,
// though that is abstracted by our META_UIObject macro. // though that is abstracted by our META_UIObject macro.
osgWidget::Window* boxCopy = osg::clone(box,"newBox"); osgWidget::Window* boxCopy = osg::clone(box, "newBox", osg::CopyOp::DEEP_COPY_ALL);
// Move our copy to make it visible. // Move our copy to make it visible.
boxCopy->setOrigin(0.0f, 125.0f); boxCopy->setOrigin(0.0f, 125.0f);
@ -145,16 +161,6 @@ int main(int argc, char** argv) {
// creation. // creation.
// std::cout << *box << std::endl << *boxCopy << std::endl; // std::cout << *box << std::endl << *boxCopy << std::endl;
// 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 osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(
viewer.getCamera()->getOrCreateStateSet()
));
// Setup our OSG objects for our scene; note the use of the utility function // 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. // createOrthoCamera, which is just a helper for setting up a proper viewing area.
// An alternative (and a MUCH easier alternative at that!) is to // An alternative (and a MUCH easier alternative at that!) is to
@ -162,9 +168,21 @@ int main(int argc, char** argv) {
// which will wrap the calls to createOrthoCamera and addChild for us! Check out // which will wrap the calls to createOrthoCamera and addChild for us! Check out
// some of the other examples to see this in action... // some of the other examples to see this in action...
osg::Group* group = new osg::Group(); osg::Group* group = new osg::Group();
osg::Camera* camera = osgWidget::createInvertedYOrthoCamera(1280.0f, 1024.0f); osg::Camera* camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f);
osg::Node* model = osgDB::readNodeFile("cow.osg"); 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()
));
// Set our first non-UI node to be something other than the mask we created our // Set our first non-UI node to be something other than the mask we created our
// WindowManager with to avoid picking. // WindowManager with to avoid picking.
// TODO: Do I need to create a mechanism for doing this automatically, or should // TODO: Do I need to create a mechanism for doing this automatically, or should