From Jeremy Moles, import of the osgWidget NodeKit, sourced from the original http://osgwidget.googlecode.com/svn/trunk
Notes from Robert Osfield, I've merged osgWidget trunk, and added/changed CMakeLists.txt file to make it suitable for inclusion in the core OSG, and moved imagery/scripts/shaders out into OpenSceneGraph-Data
This commit is contained in:
@@ -149,6 +149,24 @@ IF(DYNAMIC_OPENSCENEGRAPH)
|
||||
ADD_SUBDIRECTORY(osgviewerCocoa)
|
||||
ENDIF(APPLE)
|
||||
|
||||
IF (BUILD_OSGWIDGET))
|
||||
ADD_SUBDIRECTORY(osgwidgetaddremove)
|
||||
ADD_SUBDIRECTORY(osgwidgetbox)
|
||||
ADD_SUBDIRECTORY(osgwidgetcanvas)
|
||||
ADD_SUBDIRECTORY(osgwidgetframe)
|
||||
ADD_SUBDIRECTORY(osgwidgetinput)
|
||||
ADD_SUBDIRECTORY(osgwidgetlabel)
|
||||
ADD_SUBDIRECTORY(osgwidgetmenu)
|
||||
ADD_SUBDIRECTORY(osgwidgetnotebook)
|
||||
ADD_SUBDIRECTORY(osgwidgetscrolled)
|
||||
ADD_SUBDIRECTORY(osgwidgetshader)
|
||||
ADD_SUBDIRECTORY(osgwidgetstyled)
|
||||
ADD_SUBDIRECTORY(osgwidgettable)
|
||||
ADD_SUBDIRECTORY(osgwidgetversion)
|
||||
ADD_SUBDIRECTORY(osgwidgetwindow
|
||||
ENDIF(BUILD_OSGWIDGET)
|
||||
|
||||
|
||||
#ADD_SUBDIRECTORY(osgcegui)
|
||||
#to add subject to find socket#ADD_SUBDIRECTORY(osgcluster)
|
||||
|
||||
|
||||
9
examples/osgwidgetaddremove/CMakeLists.txt
Normal file
9
examples/osgwidgetaddremove/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetaddremove)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetaddremove osgwidgetaddremove.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetaddremove PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetaddremove DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
134
examples/osgwidgetaddremove/osgwidgetaddremove.cpp
Normal file
134
examples/osgwidgetaddremove/osgwidgetaddremove.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetaddremove.cpp 45 2008-04-23 16:46:11Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Table>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Label>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
class ABCWidget: public osgWidget::Label {
|
||||
public:
|
||||
ABCWidget(const std::string& label):
|
||||
osgWidget::Label("", label) {
|
||||
setFont("fonts/Calibri1.ttf");
|
||||
setFontSize(20);
|
||||
setCanFill(true);
|
||||
setShadow(0.08f);
|
||||
addSize(10.0f, 10.0f);
|
||||
}
|
||||
};
|
||||
|
||||
class Button: public osgWidget::Label {
|
||||
public:
|
||||
Button(const std::string& label):
|
||||
osgWidget::Label("", label) {
|
||||
setFont("fonts/Calibri1.ttf");
|
||||
setFontSize(30);
|
||||
setColor(0.8f, 0.2f, 0.2f, 0.8f);
|
||||
setCanFill(true);
|
||||
setShadow(0.1f);
|
||||
setEventMask(osgWidget::EVENT_MASK_MOUSE_CLICK);
|
||||
addSize(20.0f, 20.0f);
|
||||
}
|
||||
|
||||
// NOTE! I need to make it clearer than Push/Release can happen so fast that
|
||||
// the changes you make aren't visible with your refresh rate. Throttling state
|
||||
// changes and what-have-you on mousePush/mouseRelease/etc. is going to be
|
||||
// annoying...
|
||||
|
||||
virtual bool mousePush(double, double, osgWidget::WindowManager*) {
|
||||
addColor(0.2f, 0.2f, 0.2f, 0.0f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool mouseRelease(double, double, osgWidget::WindowManager*) {
|
||||
addColor(-0.2f, -0.2f, -0.2f, 0.0f);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class AddRemove: public osgWidget::Box {
|
||||
osg::ref_ptr<osgWidget::Window> _win1;
|
||||
|
||||
public:
|
||||
AddRemove():
|
||||
osgWidget::Box ("buttons", osgWidget::Box::VERTICAL),
|
||||
_win1 (new osgWidget::Box("win1", osgWidget::Box::VERTICAL)) {
|
||||
addWidget(new Button("Add Widget"));
|
||||
addWidget(new Button("Remove Widget"));
|
||||
|
||||
// Take special note here! Not only do the Button objects have their
|
||||
// own overridden methods for changing the color, but they have attached
|
||||
// callbacks for doing the work with local data.
|
||||
getByName("Widget_1")->addCallback(osgWidget::Callback(
|
||||
&AddRemove::handlePressAdd,
|
||||
this,
|
||||
osgWidget::EVENT_MOUSE_PUSH
|
||||
));
|
||||
|
||||
getByName("Widget_2")->addCallback(osgWidget::Callback(
|
||||
&AddRemove::handlePressRemove,
|
||||
this,
|
||||
osgWidget::EVENT_MOUSE_PUSH
|
||||
));
|
||||
}
|
||||
|
||||
virtual void managed(osgWidget::WindowManager* wm) {
|
||||
osgWidget::Box::managed(wm);
|
||||
|
||||
_win1->setOrigin(250.0f, 0.0f);
|
||||
|
||||
wm->addChild(_win1.get());
|
||||
}
|
||||
|
||||
bool handlePressAdd(osgWidget::Event& ev) {
|
||||
static unsigned int num = 0;
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "a random widget " << num;
|
||||
|
||||
_win1->addWidget(new ABCWidget(ss.str()));
|
||||
_win1->resize();
|
||||
|
||||
num++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool handlePressRemove(osgWidget::Event& ev) {
|
||||
// TODO: Temporary hack!
|
||||
const osgWidget::Box::Vector& v = _win1->getObjects();
|
||||
|
||||
if(!v.size()) return false;
|
||||
|
||||
osgWidget::Widget* w = _win1->getObjects()[v.size() - 1].get();
|
||||
|
||||
_win1->removeWidget(w);
|
||||
_win1->resize();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D
|
||||
);
|
||||
|
||||
osgWidget::Box* buttons = new AddRemove();
|
||||
|
||||
wm->addChild(buttons);
|
||||
|
||||
return createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetbox/CMakeLists.txt
Normal file
9
examples/osgwidgetbox/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetbox)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetbox osgwidgetbox.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetbox PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetbox DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
122
examples/osgwidgetbox/osgwidgetbox.cpp
Normal file
122
examples/osgwidgetbox/osgwidgetbox.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetbox.cpp 59 2008-05-15 20:55:31Z cubicool $
|
||||
|
||||
// NOTE: You'll find this example very similar to osgwidgetwindow. However, here we
|
||||
// demonstrate a bit of subclassing of Widget so that we can respond to events
|
||||
// such as mouseEnter and mouseLeave. We also demonstrate the use of padding, though
|
||||
// fill and alignment should be working too.
|
||||
|
||||
#include <osg/io_utils>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Box>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
struct ColorWidget: public osgWidget::Widget {
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
if(c.a() < 0.001f) {
|
||||
// osgWidget::warn() << "Transparent Pixel: " << x << " " << y << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keyUp(int key, int keyMask, osgWidget::WindowManager*) {
|
||||
// osgWidget::warn() << "..." << key << " - " << keyMask << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
osgWidget::Box* createBox(const std::string& name, osgWidget::Box::BOX_TYPE 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();
|
||||
|
||||
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);
|
||||
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::CompositeViewer viewer;
|
||||
|
||||
osgViewer::View* view = new osgViewer::View();
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
view,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG |
|
||||
osgWidget::WindowManager::WM_NO_INVERT_Y
|
||||
);
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
|
||||
box4->hide();
|
||||
|
||||
osg::Node* model = osgDB::readNodeFile("spaceship.osg");
|
||||
|
||||
model->setNodeMask(MASK_3D);
|
||||
|
||||
return osgWidget::createCompositeExample(viewer, view, wm, model);
|
||||
}
|
||||
9
examples/osgwidgetcanvas/CMakeLists.txt
Normal file
9
examples/osgwidgetcanvas/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetcanvas)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetcanvas osgwidgetcanvas.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetcanvas PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetcanvas DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
118
examples/osgwidgetcanvas/osgwidgetcanvas.cpp
Normal file
118
examples/osgwidgetcanvas/osgwidgetcanvas.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetcanvas.cpp 33 2008-04-04 19:03:12Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
bool colorWidgetEnter(osgWidget::Event& event) {
|
||||
event.getWidget()->addColor(0.5f, 0.2f, 0.3f, 0.0f);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseEnter " << event.getWidget()->getName() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool colorWidgetLeave(osgWidget::Event& event) {
|
||||
event.getWidget()->addColor(-0.5f, -0.2f, -0.3f, 0.0f);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseLeave" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool windowMouseOver(osgWidget::Event& event) {
|
||||
osgWidget::XYCoord xy = event.getWindow()->localXY(event.x, event.y);
|
||||
|
||||
// osgWidget::warn() << "WINDOW " << xy.x() << " - " << xy.y() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool widgetMouseOver(osgWidget::Event& event) {
|
||||
osgWidget::XYCoord xy = event.getWidget()->localXY(event.x, event.y);
|
||||
|
||||
// osgWidget::warn() << "WIDGET mouseOver " << xy.x() << " - " << xy.y() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
osgWidget::Widget* createWidget(
|
||||
const std::string& name,
|
||||
osgWidget::color_type col,
|
||||
osgWidget::Widget::LAYER layer
|
||||
) {
|
||||
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
|
||||
|
||||
widget->setEventMask(osgWidget::EVENT_ALL);
|
||||
widget->addCallback(osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_PUSH));
|
||||
widget->addCallback(osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_RELEASE));
|
||||
widget->addCallback(osgWidget::Callback(&colorWidgetEnter, osgWidget::EVENT_MOUSE_ENTER));
|
||||
widget->addCallback(osgWidget::Callback(&colorWidgetLeave, osgWidget::EVENT_MOUSE_LEAVE));
|
||||
widget->addCallback(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;
|
||||
|
||||
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(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("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");
|
||||
|
||||
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;
|
||||
|
||||
canvas->addWidget(relWidget, 0.4f, 0.4f);
|
||||
|
||||
relWidget->addOrigin(0.1f, 0.1f);
|
||||
relWidget->addSize(0.2f, 0.2f);
|
||||
|
||||
canvas->resize();
|
||||
|
||||
// Finally, add the whole thing to the WindowManager.
|
||||
wm->addChild(canvas);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetframe/CMakeLists.txt
Normal file
9
examples/osgwidgetframe/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetframe)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetframe osgwidgetframe.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetframe PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetframe DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
89
examples/osgwidgetframe/osgwidgetframe.cpp
Normal file
89
examples/osgwidgetframe/osgwidgetframe.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// -*-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>
|
||||
|
||||
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::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("../examples/osgwidgetframe/images/border-left.tga", true);
|
||||
r->setImage("../examples/osgwidgetframe/images/border-right.tga", true);
|
||||
t->setImage("../examples/osgwidgetframe/images/border-top.tga", true);
|
||||
b->setImage("../examples/osgwidgetframe/images/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("../examples/osgwidgetframe/images/panel-left.tga", true);
|
||||
center->setImage("../examples/osgwidgetframe/images/panel-center.tga", true);
|
||||
right->setImage("../examples/osgwidgetframe/images/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(bottom);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetinput/CMakeLists.txt
Normal file
9
examples/osgwidgetinput/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetinput)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetinput osgwidgetinput.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetinput PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetinput DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
186
examples/osgwidgetinput/osgwidgetinput.cpp
Normal file
186
examples/osgwidgetinput/osgwidgetinput.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetinput.cpp 50 2008-05-06 05:06:36Z cubicool $
|
||||
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Table>
|
||||
#include <osgWidget/Frame>
|
||||
#include <osgWidget/Label>
|
||||
#include <osgWidget/Input>
|
||||
|
||||
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/monospace.ttf");
|
||||
label->setFont("fonts/Calibri1.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) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Table* table = new osgWidget::Table("table", 3, 2);
|
||||
osgWidget::Box* lbox1 = new osgWidget::Box("lbox1", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Box* lbox2 = new osgWidget::Box("lbox2", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Frame* frame = osgWidget::Frame::createSimpleFrameWithSingleTexture(
|
||||
"frame",
|
||||
"osgWidget/theme.png",
|
||||
64.0f,
|
||||
64.0f,
|
||||
16.0f,
|
||||
16.0f,
|
||||
100.0f,
|
||||
100.0f
|
||||
);
|
||||
|
||||
osgWidget::Input* x = createTableRow(table, 0, "X Position");
|
||||
osgWidget::Input* y = createTableRow(table, 1, "Y Position");
|
||||
osgWidget::Input* z = createTableRow(table, 2, "Z Position");
|
||||
|
||||
Button::Inputs inputs;
|
||||
|
||||
inputs.push_back(x);
|
||||
inputs.push_back(y);
|
||||
inputs.push_back(z);
|
||||
|
||||
table->addCallback(osgWidget::Callback(&info, osgWidget::EVENT_MOUSE_PUSH));
|
||||
|
||||
lbox1->addWidget(createLabel(INFO));
|
||||
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;
|
||||
}
|
||||
9
examples/osgwidgetlabel/CMakeLists.txt
Normal file
9
examples/osgwidgetlabel/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetlabel)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetlabel osgwidgetlabel.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetlabel PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetlabel DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
120
examples/osgwidgetlabel/osgwidgetlabel.cpp
Normal file
120
examples/osgwidgetlabel/osgwidgetlabel.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetlabel.cpp 66 2008-07-14 21:54:09Z cubicool $
|
||||
|
||||
#include <osg/io_utils>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Label>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
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..."
|
||||
;
|
||||
|
||||
const char* LABEL2 =
|
||||
"...reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n"
|
||||
"pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \n"
|
||||
"culpa qui officia deserunt mollit anim id est laborum. BBBBB"
|
||||
;
|
||||
|
||||
osgWidget::Label* createLabel(const std::string& l, unsigned int size=13) {
|
||||
osgWidget::Label* label = new osgWidget::Label("", "");
|
||||
|
||||
label->setFont("fonts/arial.ttf");
|
||||
label->setFontSize(size);
|
||||
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
label->setLabel(l);
|
||||
|
||||
/*
|
||||
text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT);
|
||||
text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER);
|
||||
text->setBackdropOffset(0.2f);
|
||||
*/
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
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::WindowManager::WM_NO_INVERT_Y
|
||||
);
|
||||
|
||||
osgWidget::Box* box = new osgWidget::Box("HBOX", osgWidget::Box::HORIZONTAL);
|
||||
osgWidget::Box* vbox = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Label* label1 = createLabel(LABEL1);
|
||||
osgWidget::Label* label2 = createLabel(LABEL2);
|
||||
|
||||
// Setup the labels for horizontal box.
|
||||
label1->setPadding(10.0f);
|
||||
label2->setPadding(10.0f);
|
||||
|
||||
label1->addSize(21.0f, 22.0f);
|
||||
label2->addSize(21.0f, 22.0f);
|
||||
|
||||
label1->setColor(1.0f, 0.5f, 0.0f, 0.0f);
|
||||
label2->setColor(1.0f, 0.5f, 0.0f, 0.0f);
|
||||
|
||||
box->addWidget(label1);
|
||||
box->addWidget(label2);
|
||||
box->attachMoveCallback();
|
||||
box->attachScaleCallback();
|
||||
box->attachRotateCallback();
|
||||
|
||||
// Setup the labels for the vertical box.
|
||||
osgWidget::Label* label3 = createLabel("Label 3", 80);
|
||||
osgWidget::Label* label4 = createLabel("Label 4", 60);
|
||||
osgWidget::Label* label5 = createLabel("ABCDEFGHIJK", 93);
|
||||
|
||||
label3->setPadding(3.0f);
|
||||
label4->setPadding(3.0f);
|
||||
label5->setPadding(3.0f);
|
||||
|
||||
label3->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->setAlignHorizontal(osgWidget::Widget::HA_LEFT);
|
||||
label5->setAlignVertical(osgWidget::Widget::VA_BOTTOM);
|
||||
|
||||
// Test our label copy construction...
|
||||
osgWidget::Label* label6 = label5->cloneAs("label6");
|
||||
|
||||
label6->setLabel("abcdefghijklmnopqrs");
|
||||
|
||||
vbox->addWidget(label3);
|
||||
vbox->addWidget(label4);
|
||||
vbox->addWidget(label5);
|
||||
vbox->addWidget(label6);
|
||||
vbox->attachMoveCallback();
|
||||
vbox->attachScaleCallback();
|
||||
|
||||
vbox->resize();
|
||||
|
||||
// vbox->setVisibilityMode(osgWidget::Window::VM_ENTIRE);
|
||||
// vbox->setVisibleArea(50, 50, 500, 200);
|
||||
// vbox->setAnchorVertical(osgWidget::Window::VA_TOP);
|
||||
// vbox->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
|
||||
|
||||
// Test our label-in-window copy construction...
|
||||
osgWidget::Box* clonedBox = box->cloneAs("HBOX-new");
|
||||
|
||||
clonedBox->getBackground()->setColor(0.0f, 1.0f, 0.0f, 0.5f);
|
||||
|
||||
wm->addChild(box);
|
||||
wm->addChild(vbox);
|
||||
wm->addChild(clonedBox);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetmenu/CMakeLists.txt
Normal file
9
examples/osgwidgetmenu/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetmenu)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetmenu osgwidgetmenu.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetmenu PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetmenu DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
129
examples/osgwidgetmenu/osgwidgetmenu.cpp
Normal file
129
examples/osgwidgetmenu/osgwidgetmenu.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetmenu.cpp 66 2008-07-14 21:54:09Z cubicool $
|
||||
|
||||
#include <iostream>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Label>
|
||||
|
||||
// For now this is just an example, but osgWidget::Menu will later be it's own Window.
|
||||
// I just wanted to get this out there so that people could see it was possible.
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
struct ColorLabel: public osgWidget::Label {
|
||||
ColorLabel(const char* label):
|
||||
osgWidget::Label("", "") {
|
||||
setFont("fonts/Calibri1.ttf");
|
||||
setFontSize(14);
|
||||
setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
setColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
addHeight(18.0f);
|
||||
setCanFill(true);
|
||||
setLabel(label);
|
||||
setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE);
|
||||
}
|
||||
|
||||
bool mousePush(double, double, osgWidget::WindowManager*) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseEnter(double, double, osgWidget::WindowManager*) {
|
||||
setColor(0.6f, 0.6f, 0.6f, 1.0f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseLeave(double, double, osgWidget::WindowManager*) {
|
||||
setColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ColorLabelMenu: public ColorLabel {
|
||||
osg::ref_ptr<osgWidget::Window> _window;
|
||||
|
||||
public:
|
||||
ColorLabelMenu(const char* label):
|
||||
ColorLabel(label) {
|
||||
_window = new osgWidget::Box(
|
||||
std::string("Menu_") + label,
|
||||
osgWidget::Box::VERTICAL,
|
||||
true
|
||||
);
|
||||
|
||||
_window->addWidget(new ColorLabel("Open Some Stuff"));
|
||||
_window->addWidget(new ColorLabel("Do It Now"));
|
||||
_window->addWidget(new ColorLabel("Hello, How Are U?"));
|
||||
_window->addWidget(new ColorLabel("Hmmm..."));
|
||||
_window->addWidget(new ColorLabel("Option 5"));
|
||||
|
||||
_window->resize();
|
||||
|
||||
setColor(0.8f, 0.8f, 0.8f, 0.8f);
|
||||
}
|
||||
|
||||
void managed(osgWidget::WindowManager* wm) {
|
||||
osgWidget::Label::managed(wm);
|
||||
|
||||
wm->addChild(_window.get());
|
||||
|
||||
_window->hide();
|
||||
}
|
||||
|
||||
void positioned() {
|
||||
osgWidget::Label::positioned();
|
||||
|
||||
_window->setOrigin(getX(), getHeight());
|
||||
_window->resize(getWidth());
|
||||
}
|
||||
|
||||
bool mousePush(double, double, osgWidget::WindowManager*) {
|
||||
if(!_window->isVisible()) _window->show();
|
||||
|
||||
else _window->hide();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseLeave(double, double, osgWidget::WindowManager*) {
|
||||
if(!_window->isVisible()) setColor(0.8f, 0.8f, 0.8f, 0.8f);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
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::WindowManager::WM_NO_BETA_WARN
|
||||
);
|
||||
|
||||
osgWidget::Window* menu = new osgWidget::Box("menu", osgWidget::Box::HORIZONTAL);
|
||||
|
||||
menu->addWidget(new ColorLabelMenu("Pick me!"));
|
||||
menu->addWidget(new ColorLabelMenu("No, wait, pick me!"));
|
||||
menu->addWidget(new ColorLabelMenu("Dont pick them..."));
|
||||
menu->addWidget(new ColorLabelMenu("Grarar!?!"));
|
||||
|
||||
wm->addChild(menu);
|
||||
|
||||
menu->getBackground()->setColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
menu->resizePercent(100.0f);
|
||||
|
||||
osg::Node* model = osgDB::readNodeFile("osgcool.osg");
|
||||
|
||||
model->setNodeMask(MASK_3D);
|
||||
|
||||
return osgWidget::createExample(viewer, wm, model);
|
||||
}
|
||||
9
examples/osgwidgetnotebook/CMakeLists.txt
Normal file
9
examples/osgwidgetnotebook/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetnotebook)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetnotebook osgwidgetnotebook.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetnotebook PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetnotebook DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
134
examples/osgwidgetnotebook/osgwidgetnotebook.cpp
Normal file
134
examples/osgwidgetnotebook/osgwidgetnotebook.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetnotebook.cpp 45 2008-04-23 16:46:11Z cubicool $
|
||||
|
||||
#include <osg/io_utils>
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Box>
|
||||
#include <osgWidget/Canvas>
|
||||
#include <osgWidget/Label>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
const unsigned int MASK_3D = 0x0F000000;
|
||||
|
||||
class Notebook: public osgWidget::Box {
|
||||
osg::ref_ptr<osgWidget::Box> _tabs;
|
||||
osg::ref_ptr<osgWidget::Canvas> _windows;
|
||||
|
||||
public:
|
||||
// NOTE: This whole thing is just a hack to demonstrate a concept. The real
|
||||
// implementation would need to be much cleaner.
|
||||
bool callbackTabPressed(osgWidget::Event& ev) {
|
||||
osgWidget::Canvas::Vector& objs = _windows->getObjects();
|
||||
|
||||
for(unsigned int i = 0; i < objs.size(); i++) objs[i]->setLayer(
|
||||
osgWidget::Widget::LAYER_MIDDLE,
|
||||
i
|
||||
);
|
||||
|
||||
_windows->getByName(ev.getWidget()->getName())->setLayer(
|
||||
osgWidget::Widget::LAYER_MIDDLE,
|
||||
objs.size()
|
||||
);
|
||||
|
||||
_windows->resize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Notebook(const std::string& name):
|
||||
osgWidget::Box(name, osgWidget::Box::VERTICAL) {
|
||||
_tabs = new osgWidget::Box("tabs", osgWidget::Box::HORIZONTAL);
|
||||
_windows = new osgWidget::Canvas("canvas");
|
||||
|
||||
for(unsigned int i = 0; i < 4; i++) {
|
||||
std::stringstream ss;
|
||||
|
||||
// Setup everything for our Tab...
|
||||
ss << "Tab_" << i;
|
||||
|
||||
osgWidget::Label* label1 = new osgWidget::Label(ss.str());
|
||||
|
||||
label1->setFont("fonts/monospace.ttf");
|
||||
label1->setFontSize(20);
|
||||
label1->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
label1->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
|
||||
label1->setLabel(ss.str());
|
||||
label1->addSize(20.0f, 20.0f);
|
||||
label1->setShadow(0.1f);
|
||||
label1->setCanFill(true);
|
||||
|
||||
_tabs->addWidget(label1);
|
||||
|
||||
// Setup everything for the Window corresponding to the Tab
|
||||
// in the Canvas down below.
|
||||
std::stringstream descr;
|
||||
|
||||
descr
|
||||
<< "This is some text" << std::endl
|
||||
<< "for the Tab_" << i << " tab." << std::endl
|
||||
<< "Press the button up top" << std::endl
|
||||
<< "And this should go to the next Window!" << std::endl
|
||||
;
|
||||
|
||||
osgWidget::Label* label2 = new osgWidget::Label(ss.str());
|
||||
|
||||
label2->setFont("fonts/monospace.ttf");
|
||||
label2->setFontSize(15);
|
||||
label2->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
label2->setColor(0.0f, i / 4.0f, 0.3f, 1.0f);
|
||||
label2->setLabel(descr.str());
|
||||
label2->setLayer(osgWidget::Widget::LAYER_MIDDLE, i);
|
||||
label2->addSize(50.0f, 50.0f);
|
||||
|
||||
_windows->addWidget(label2, 0.0f, 0.0f);
|
||||
|
||||
label1->setEventMask(osgWidget::EVENT_MOUSE_PUSH);
|
||||
label1->addCallback(osgWidget::Callback(
|
||||
&Notebook::callbackTabPressed,
|
||||
this,
|
||||
osgWidget::EVENT_MOUSE_PUSH
|
||||
));
|
||||
}
|
||||
|
||||
osgWidget::Label* label = new osgWidget::Label("label");
|
||||
|
||||
label->setFont("fonts/monospace.ttf");
|
||||
label->setFontSize(15);
|
||||
label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
label->setLabel("Drag the window here...");
|
||||
label->addSize(20.0f, 20.0f);
|
||||
label->setShadow(0.08f);
|
||||
label->setCanFill(true);
|
||||
|
||||
addWidget(label);
|
||||
addWidget(_tabs->embed());
|
||||
addWidget(_windows->embed());
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
720.0f,
|
||||
MASK_2D,
|
||||
osgWidget::WindowManager::WM_PICK_DEBUG
|
||||
);
|
||||
|
||||
Notebook* notebook = new Notebook("notebook");
|
||||
|
||||
osgWidget::warn()
|
||||
<< "Sizes are..." << std::endl
|
||||
<< "Cur: " << notebook->getSize() << std::endl
|
||||
<< "Min: " << notebook->getMinSize() << std::endl
|
||||
;
|
||||
|
||||
notebook->attachMoveCallback();
|
||||
|
||||
wm->addChild(notebook);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetscrolled/CMakeLists.txt
Normal file
9
examples/osgwidgetscrolled/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetscrolled)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetscrolled osgwidgetscrolled.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetscrolled PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetscrolled DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
134
examples/osgwidgetscrolled/osgwidgetscrolled.cpp
Normal file
134
examples/osgwidgetscrolled/osgwidgetscrolled.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetframe.cpp 34 2008-04-07 03:12:41Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Frame>
|
||||
#include <osgWidget/Box>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
// NOTE: THIS IS JUST A TEMPORARY HACK! :) This functionality will all eventually be
|
||||
// encapsulate into another class in osgWidget proper.
|
||||
bool scrollWindow(osgWidget::Event& ev) {
|
||||
// The first thing we need to do is make sure we have a Frame object...
|
||||
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
|
||||
|
||||
if(!frame) return false;
|
||||
|
||||
// And now we need to make sure our Frame has a valid internal EmbeddedWindow widget.
|
||||
osgWidget::Window::EmbeddedWindow* ew =
|
||||
dynamic_cast<osgWidget::Window::EmbeddedWindow*>(frame->getEmbeddedWindow())
|
||||
;
|
||||
|
||||
if(!ew) return false;
|
||||
|
||||
// Lets get the visible area so that we can use it to make sure our scrolling action
|
||||
// is necessary in the first place.
|
||||
const osgWidget::Quad& va = ew->getWindow()->getVisibleArea();
|
||||
|
||||
// The user wants to scroll up; make sure that the visible area's Y origin isn't already
|
||||
// at 0.0f, 0.0f.
|
||||
if(ev.getWindowManager()->isMouseScrollingUp() && va[1] != 0.0f)
|
||||
ew->getWindow()->addVisibleArea(0, -20)
|
||||
;
|
||||
|
||||
else if(va[1] <= (ew->getWindow()->getHeight() - ew->getHeight()))
|
||||
ew->getWindow()->addVisibleArea(0, 20)
|
||||
;
|
||||
|
||||
// We need to manually call update to make sure the visible area scissoring is done
|
||||
// properly.
|
||||
frame->update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool changeTheme(osgWidget::Event& ev) {
|
||||
std::string theme;
|
||||
|
||||
if(ev.key == osgGA::GUIEventAdapter::KEY_Right)
|
||||
theme = "osgWidget/theme-1.png"
|
||||
;
|
||||
|
||||
else if(ev.key == osgGA::GUIEventAdapter::KEY_Left)
|
||||
theme = "osgWidget/theme-2.png"
|
||||
;
|
||||
|
||||
else return false;
|
||||
|
||||
osgWidget::Frame* frame = dynamic_cast<osgWidget::Frame*>(ev.getWindow());
|
||||
|
||||
if(!frame) return false;
|
||||
|
||||
// This is just one way to access all our Widgets; we could just as well have used:
|
||||
//
|
||||
// for(osgWidget::Frame::Iterator i = frame.begin(); i != frame.end() i++) {}
|
||||
//
|
||||
// ...and it have worked, too.
|
||||
for(unsigned int row = 0; row < 3; row++) {
|
||||
for(unsigned int col = 0; col < 3; col++) {
|
||||
frame->getByRowCol(row, col)->setImage(theme);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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::createSimpleFrameWithSingleTexture(
|
||||
"frame",
|
||||
"../examples/osgwidgetscrolled/theme-2.png",
|
||||
64.0f,
|
||||
64.0f,
|
||||
16.0f,
|
||||
16.0f,
|
||||
100.0f,
|
||||
100.0f
|
||||
);
|
||||
|
||||
frame->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
// This is our Transformers box. :)
|
||||
osgWidget::Box* box = new osgWidget::Box("images", osgWidget::Box::VERTICAL);
|
||||
osgWidget::Widget* img1 = new osgWidget::Widget("im1", 256.0f, 256.0f);
|
||||
osgWidget::Widget* img2 = new osgWidget::Widget("im2", 256.0f, 256.0f);
|
||||
osgWidget::Widget* img3 = new osgWidget::Widget("im3", 256.0f, 256.0f);
|
||||
osgWidget::Widget* img4 = new osgWidget::Widget("im4", 256.0f, 256.0f);
|
||||
|
||||
img1->setImage("../examples/osgwidgetscrolled/images/starscream.jpg", true);
|
||||
img2->setImage("../examples/osgwidgetscrolled/images/optimus.jpg", true);
|
||||
img3->setImage("../examples/osgwidgetscrolled/images/megatron.jpg", true);
|
||||
img4->setImage("../examples/osgwidgetscrolled/images/bumblebee.jpg", true);
|
||||
|
||||
img1->setMinimumSize(10.0f, 10.0f);
|
||||
img2->setMinimumSize(10.0f, 10.0f);
|
||||
img3->setMinimumSize(10.0f, 10.0f);
|
||||
img4->setMinimumSize(10.0f, 10.0f);
|
||||
|
||||
box->addWidget(img1);
|
||||
box->addWidget(img2);
|
||||
box->addWidget(img3);
|
||||
box->addWidget(img4);
|
||||
box->setEventMask(osgWidget::EVENT_NONE);
|
||||
|
||||
frame->getEmbeddedWindow()->setWindow(box);
|
||||
frame->getEmbeddedWindow()->setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
frame->resize(300.0f, 300.0f);
|
||||
frame->addCallback(osgWidget::Callback(&scrollWindow, osgWidget::EVENT_MOUSE_SCROLL));
|
||||
frame->addCallback(osgWidget::Callback(&changeTheme, osgWidget::EVENT_KEY_DOWN));
|
||||
|
||||
wm->addChild(frame);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetshader/CMakeLists.txt
Normal file
9
examples/osgwidgetshader/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetshader)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetshader osgwidgetshader.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetshader PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetshader DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
74
examples/osgwidgetshader/osgwidgetshader.cpp
Normal file
74
examples/osgwidgetshader/osgwidgetshader.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Canvas>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
osgWidget::Widget* createWidget(
|
||||
const std::string& name,
|
||||
osgWidget::color_type col,
|
||||
osgWidget::Widget::LAYER layer
|
||||
) {
|
||||
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
|
||||
|
||||
widget->setColor(col, col, col, 0.2f);
|
||||
widget->setLayer(layer);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D
|
||||
);
|
||||
|
||||
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
||||
|
||||
canvas->attachMoveCallback();
|
||||
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("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
|
||||
400.0f,
|
||||
0.0f
|
||||
);
|
||||
|
||||
|
||||
wm->addChild(canvas);
|
||||
|
||||
osg::Program* program = new osg::Program();
|
||||
|
||||
program->addShader(osg::Shader::readShaderFile(
|
||||
osg::Shader::VERTEX,
|
||||
"osgWidget/osgwidgetshader-vert.glsl"
|
||||
));
|
||||
|
||||
program->addShader(osg::Shader::readShaderFile(
|
||||
osg::Shader::FRAGMENT,
|
||||
"osgWidget/osgwidgetshader-frag.glsl"
|
||||
));
|
||||
|
||||
canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetstyled/CMakeLists.txt
Normal file
9
examples/osgwidgetstyled/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetstyled)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetstyled osgwidgetstyled.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetstyled PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetstyled DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
83
examples/osgwidgetstyled/osgwidgetstyled.cpp
Normal file
83
examples/osgwidgetstyled/osgwidgetstyled.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/StyleManager>
|
||||
#include <osgWidget/Box>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
const std::string& STYLE1 =
|
||||
"color 0 0 0 128\n"
|
||||
"padding 5\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE2 =
|
||||
"color 1.0 0.5 0.0\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE3 =
|
||||
"fill true\n"
|
||||
;
|
||||
|
||||
const std::string& STYLE4 =
|
||||
"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);
|
||||
|
||||
if(!cs) return false;
|
||||
|
||||
osgWidget::warn() << "Here, okay." << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osgViewer::Viewer viewer;
|
||||
|
||||
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
||||
&viewer,
|
||||
1280.0f,
|
||||
1024.0f,
|
||||
MASK_2D
|
||||
);
|
||||
|
||||
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();
|
||||
|
||||
// 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");
|
||||
|
||||
box->setStyle("window");
|
||||
|
||||
box->addWidget(widget1);
|
||||
box->addWidget(widget2);
|
||||
box->addWidget(widget3);
|
||||
|
||||
wm->addChild(box);
|
||||
|
||||
// box->resizePercent(0.0f, 100.0f);
|
||||
|
||||
return osgWidget::createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgettable/CMakeLists.txt
Normal file
9
examples/osgwidgettable/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgettable)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgettable osgwidgettable.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgettable PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgettable DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
69
examples/osgwidgettable/osgwidgettable.cpp
Normal file
69
examples/osgwidgettable/osgwidgettable.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgettable.cpp 43 2008-04-17 03:40:05Z cubicool $
|
||||
|
||||
#include <osgWidget/Util>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/Table>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
|
||||
// This examples demonstrates the use of an osgWidget::Table, which differs from a Box in
|
||||
// many ways. First and foremost, a Table's size is intially known, whereas a Box can be
|
||||
// dynamically added to. Secondly, a table is matrix Layout, with both vertical and
|
||||
// horizontal placement cells. A Box, on the other hand, can only be vertical or horizontal.
|
||||
|
||||
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::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);
|
||||
|
||||
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)
|
||||
;
|
||||
|
||||
// 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")->setPadding(10.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);
|
||||
|
||||
return createExample(viewer, wm);
|
||||
}
|
||||
9
examples/osgwidgetversion/CMakeLists.txt
Normal file
9
examples/osgwidgetversion/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetversion)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetversion osgwidgetversion.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetversion PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetversion DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
14
examples/osgwidgetversion/osgwidgetversion.cpp
Normal file
14
examples/osgwidgetversion/osgwidgetversion.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetversion.cpp 2 2008-01-24 16:11:26Z cubicool $
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgWidget/Version>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
osg::notify(osg::NOTICE)
|
||||
<< osgWidgetGetLibraryName() << " "
|
||||
<< osgWidgetGetVersion() << std::endl
|
||||
;
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
examples/osgwidgetwindow/CMakeLists.txt
Normal file
9
examples/osgwidgetwindow/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
PROJECT(osgwidgetwindow)
|
||||
|
||||
LINK_LIBRARIES(debug osgWidgetd optimized osgWidget)
|
||||
|
||||
ADD_EXECUTABLE(osgwidgetwindow osgwidgetwindow.cpp)
|
||||
|
||||
SET_TARGET_PROPERTIES(osgwidgetwindow PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||
|
||||
INSTALL(TARGETS osgwidgetwindow DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
204
examples/osgwidgetwindow/osgwidgetwindow.cpp
Normal file
204
examples/osgwidgetwindow/osgwidgetwindow.cpp
Normal file
@@ -0,0 +1,204 @@
|
||||
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
||||
// $Id: osgwidgetwindow.cpp 66 2008-07-14 21:54:09Z cubicool $
|
||||
|
||||
#include <iostream>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgGA/StateSetManipulator>
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgWidget/WindowManager>
|
||||
#include <osgWidget/ViewerEventHandlers>
|
||||
#include <osgWidget/Box>
|
||||
|
||||
const unsigned int MASK_2D = 0xF0000000;
|
||||
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;
|
||||
|
||||
if(ev.getData()) {
|
||||
std::string* s = static_cast<std::string*>(ev.getData());
|
||||
|
||||
std::cout << "This is data attached to the event: " << *s << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool windowScrolled(osgWidget::Event& ev) {
|
||||
osgWidget::warn()
|
||||
<< "scrolling up? " << ev.getWindowManager()->isMouseScrollingUp()
|
||||
<< std::endl
|
||||
;
|
||||
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
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 |
|
||||
osgWidget::WindowManager::WM_NO_BETA_WARN
|
||||
);
|
||||
|
||||
// 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;
|
||||
|
||||
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(osgWidget::Callback(
|
||||
&Object::windowClicked,
|
||||
&obj,
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// 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();
|
||||
|
||||
// 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 = box->cloneAs("newBox");
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
// 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::createInvertedYOrthoCamera(1280.0f, 1024.0f);
|
||||
osg::Node* model = osgDB::readNodeFile("cow.osg");
|
||||
|
||||
// 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 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");
|
||||
|
||||
wm->getPythonEngine()->eval("import osgwidget");
|
||||
wm->getPythonEngine()->runFile("osgWidget/osgwidgetwindow.py");
|
||||
|
||||
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());
|
||||
*/
|
||||
|
||||
return viewer.run();
|
||||
}
|
||||
Reference in New Issue
Block a user