OpenSceneGraph/examples/osgwidgetinput/osgwidgetinput.cpp

60 lines
1.7 KiB
C++
Raw Normal View History

// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
// $Id: osgwidgetinput.cpp 50 2008-05-06 05:06:36Z cubicool $
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgViewer/ViewerEventHandlers>
#include <osgWidget/WindowManager>
#include <osgWidget/Box>
#include <osgWidget/Input>
#include <osgWidget/ViewerEventHandlers>
const unsigned int MASK_2D = 0xF0000000;
int main(int argc, char** argv) {
2008-07-16 06:03:59 +08:00
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::Input* input = new osgWidget::Input("input", "", 50);
2008-07-16 06:03:59 +08:00
input->setFont("fonts/VeraMono.ttf");
input->setFontColor(0.0f, 0.0f, 0.0f, 1.0f);
input->setFontSize(15);
input->setYOffset(input->calculateBestYOffset("y"));
input->setSize(400.0f, input->getText()->getCharacterHeight());
2008-07-16 06:03:59 +08:00
box->addWidget(input);
box->setOrigin(200.0f, 200.0f);
2008-07-16 06:03:59 +08:00
wm->addChild(box);
2008-07-16 06:03:59 +08:00
viewer.setUpViewInWindow(
50,
50,
static_cast<int>(wm->getWidth()),
static_cast<int>(wm->getHeight())
);
2008-07-16 06:03:59 +08:00
osg::Camera* camera = wm->createParentOrthoCamera();
2008-07-16 06:03:59 +08:00
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());
2008-07-16 06:03:59 +08:00
wm->resizeAllWindows();
2008-07-16 06:03:59 +08:00
viewer.setSceneData(camera);
2008-07-16 06:03:59 +08:00
return viewer.run();
}