2008-07-16 01:21:25 +08:00
|
|
|
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
|
|
|
// $Id: osgwidgetinput.cpp 50 2008-05-06 05:06:36Z cubicool $
|
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
#include <osgDB/ReadFile>
|
2008-07-16 01:21:25 +08:00
|
|
|
#include <osgDB/WriteFile>
|
2008-11-28 22:36:39 +08:00
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2008-07-16 01:21:25 +08:00
|
|
|
#include <osgWidget/WindowManager>
|
|
|
|
#include <osgWidget/Box>
|
|
|
|
#include <osgWidget/Input>
|
2008-11-28 22:36:39 +08:00
|
|
|
#include <osgWidget/ViewerEventHandlers>
|
2008-07-16 01:21:25 +08:00
|
|
|
|
|
|
|
const unsigned int MASK_2D = 0xF0000000;
|
|
|
|
|
2016-06-08 20:32:14 +08:00
|
|
|
int main(int, char**)
|
|
|
|
{
|
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
|
|
|
|
);
|
2016-06-08 20:32:14 +08:00
|
|
|
|
2008-07-16 06:03:59 +08:00
|
|
|
osgWidget::Box* box = new osgWidget::Box("vbox", osgWidget::Box::VERTICAL);
|
2008-11-28 22:36:39 +08:00
|
|
|
osgWidget::Input* input = new osgWidget::Input("input", "", 50);
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +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
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
box->addWidget(input);
|
|
|
|
box->setOrigin(200.0f, 200.0f);
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
wm->addChild(box);
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
viewer.setUpViewInWindow(
|
|
|
|
50,
|
|
|
|
50,
|
|
|
|
static_cast<int>(wm->getWidth()),
|
|
|
|
static_cast<int>(wm->getHeight())
|
|
|
|
);
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
osg::Camera* camera = wm->createParentOrthoCamera();
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +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
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
wm->resizeAllWindows();
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
viewer.setSceneData(camera);
|
2008-07-16 06:03:59 +08:00
|
|
|
|
2008-11-28 22:36:39 +08:00
|
|
|
return viewer.run();
|
2008-07-16 01:21:25 +08:00
|
|
|
}
|