Exemple #1
0
cPrompt::cPrompt(int sess, QWidget *parent) :
  QLabel (parent), cActionBase ("prompt", sess)
{

  addEventHandler ("got-prompt", 50, PT_STRING);
  addEventHandler ("settings-changed", 50, PT_NOTHING);
}
Exemple #2
0
Button::Button()
{
  imageView.reset(new ImageView);
  imageView->name("buttonIcon");
  imageView->resizeOnImageChange = false;
  imageView->composite(false);
  imageView->backgroundColor(whiteColor);
  addSubview(imageView);

  titleLabel.reset(new Label);
  titleLabel->backgroundColor(clearColor);
  titleLabel->name("buttonTitle");
  titleLabel->composite(false);
  addSubview(titleLabel);

  _state = ButtonStateReleased;
  updateFromState();
  
  addEventHandler(ET_MouseDown, [this](Event* event) { mouseDown(event); }, EP_Bubble);
  addEventHandler(ET_MouseUpInside  , [this](Event* event) { mouseUpInside(event); }, EP_Bubble);
  addEventHandler(ET_MouseUpOutside, [this](Event* event) { mouseUpOutside(event); }, EP_Bubble);
  
  name("Button");
  layer->composite(true);
}
void CritterDialog::init()
{
    if (_initialized) return;
    State::init();

    setFullscreen(false);
    setModal(false);

    setPosition((Game::getInstance()->renderer()->size() - Point(640, 480)) / 2 + Point(0, 291));

    auto background = new UI::Image("art/intrface/di_talk.frm");
    addUI("background", background);

    auto question = new UI::TextArea("question", 140, -55);
    question->setSize({370, 0});
    question->setWordWrap(true);
    addUI("question", question);

    // Interface buttons
    auto reviewButton = new UI::ImageButton(UI::ImageButton::Type::DIALOG_REVIEW_BUTTON, 13, 154);
    reviewButton->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onReviewButtonClick(dynamic_cast<Event::Mouse*>(event)); });
    addUI(reviewButton);

    auto barterButton = new UI::ImageButton(UI::ImageButton::Type::DIALOG_RED_BUTTON, 593, 40);
    barterButton->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onBarterButtonClick(dynamic_cast<Event::Mouse*>(event)); });
    addUI(barterButton);
}
Exemple #4
0
            QOSGWidget::QOSGWidget(QWidget* parent)
                : QGLWidget(parent), osgViewer::Viewer(), _gw(0), _timer() {
                pix_ratio=1.0;
#if QT_VERSION == 0x050000
//fixed in future verions after 5.0
                pix_ratio= parent->window()->windowHandle()->devicePixelRatio();
                printf("pixel ratio %f\n",pix_ratio);
 #endif
                _gw = new osgViewer::GraphicsWindowEmbedded(0,0,width()/pix_ratio,height()/pix_ratio);
                
                setFocusPolicy(Qt::StrongFocus);
                setMouseTracking(true);
                /*#if defined(GL_MULTISAMPLE_ARB)
                QGLFormat fmt; 
                QGLFormat::setDefaultFormat(fmt); 
                fmt.setSamples(4); 
                fmt.setSampleBuffers(true); 
                setFormat(fmt);                    
#endif // GL_MULTISAMPLE_ARB
  */
                osg::Camera* c = getCamera();
                c->setViewport(new osg::Viewport(0,0,width()/pix_ratio,height()/pix_ratio));
                c->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width()/pix_ratio)/static_cast<double>(height()/pix_ratio), 1.0f, 10000.0f);
                c->setGraphicsContext(_gw.get());
                c->setClearColor(osg::Vec4(0.7f, 0.7f, 0.7f, 1.0f));
                setThreadingModel(osgViewer::Viewer::SingleThreaded);
                osg::Matrixd *mat=NULL;
                bool inverseMouse=false;
                _ap=new MyAnimationPath;

                _wwManip = new WorldWindManipulatorNew(this,
                                                       NULL,
                                                       inverseMouse,
                                                       mat,_ap);
                setCameraManipulator(_wwManip);//new ws::app::drawable::CameraController);
                //      _animationManip=new AnimationPathPlayer(_ap);
#if 1
		//#if defined(QT_DEBUG)                      
                addEventHandler(new osgViewer::StatsHandler);
                
                // add the help handler
                addEventHandler(new osgViewer::HelpHandler());
                
                // Allows us to toggle lighting and other basic state items with keyboard
                addEventHandler( new osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet()));
                
                // add the thread model handler
                addEventHandler(new osgViewer::ThreadingHandler);
#endif // QT_DEBUG                
                
                // add the window size toggle handler
                addEventHandler(new osgViewer::WindowSizeHandler);    
                movieCallback = new WindowCaptureCallback();
                //Movie capture callback
                addMovieCallbackToViewer(*this, movieCallback);

                // updateGL will invoke glDraw which invokes paintGL
                connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
                _timer.start(30);
            }
Exemple #5
0
void UI::OptionsList::resetEventHandlers()
{
    clearEventHandlers();
    Component::assignEventHandlers();
    addEventHandler(DrawAllEvent(), DrawEventHandler(*this));
    addEventHandler(TerminalGeometryChangedEvent(), DrawEventHandler(*this));
}
Exemple #6
0
ItemsList::ItemsList(const Point& pos) : Falltergeist::UI::Base(pos)
{
    _texture = new Graphics::Texture(_slotWidth, _slotHeight * _slotsNumber);
    _texture->fill(0x000000FF);

    addEventHandler("mouseleftdown",  [this](Event::Event* event){ this->onMouseLeftDown(dynamic_cast<Event::Mouse*>(event)); });
    addEventHandler("mousedragstart", [this](Event::Event* event){ this->onMouseDragStart(dynamic_cast<Event::Mouse*>(event)); });
    addEventHandler("mousedrag",      [this](Event::Event* event){ this->onMouseDrag(dynamic_cast<Event::Mouse*>(event)); });
    addEventHandler("mousedragstop",  [this](Event::Event* event){ this->onMouseDragStop(dynamic_cast<Event::Mouse*>(event)); });
}
Exemple #7
0
void LoadGame::init()
{
    if (_initialized) return;
    State::init();

    setModal(true);
    setFullscreen(true);

    auto game = Game::getInstance();
    //auto player = Game::getInstance()->player();

    // background
    auto bg = new UI::Image("art/intrface/lsgame.frm");
    Point bgPos = Point((game->renderer()->size() - bg->size()) / 2);
    auto bgX = bgPos.x();
    auto bgY = bgPos.y();
    bg->setPosition(bgPos);
    addUI(bg);

    // BUTTONS

    // button: up arrow
    addUI("button_up", new UI::ImageButton(UI::ImageButton::Type::SMALL_UP_ARROW, bgX+35, bgY+58));
    // button: down arrow
    addUI("button_down", new UI::ImageButton(UI::ImageButton::Type::SMALL_DOWN_ARROW, bgX+35, bgY+72));

    // button: Done
    auto doneButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, bgX+391, bgY+349);
    doneButton->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onDoneButtonClick(dynamic_cast<Event::Mouse*>(event)); });
    addUI(doneButton);

    // button: Cancel
    auto cancelButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, bgX+495, bgY+349);
    cancelButton->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->doCancel(); });
    addUI(cancelButton);

    // LABELS

    auto font3_907824ff = ResourceManager::getInstance()->font("font3.aaf", 0x907824ff);

    // LOAD GAME LABEL
    auto saveGameLabel = new UI::TextArea(_t(MSG_LOAD_SAVE, 110), bgX+48, bgY+27);
    saveGameLabel->setFont(font3_907824ff);
    addUI(saveGameLabel);

    // DONE BUTTON LABEL
    auto doneButtonLabel = new UI::TextArea(_t(MSG_OPTIONS, 300), bgX+410, bgY+348);
    doneButtonLabel->setFont(font3_907824ff);
    addUI(doneButtonLabel);

    // CANCEL BUTTON LABEL
    auto cancelButtonLabel = new UI::TextArea(_t(MSG_OPTIONS, 121), bgX+515, bgY+348);
    cancelButtonLabel->setFont(font3_907824ff);
    addUI(cancelButtonLabel);
}
void ExitConfirmState::init()
{
    if (_initialized) return;
    State::init();

    setModal(true);
    setFullscreen(false);

    auto background = new Image("art/intrface/lgdialog.frm");

    auto backgroundX = (Game::getInstance()->renderer()->width() - background->width())*0.5;
    auto backgroundY = (Game::getInstance()->renderer()->height() - background->height())*0.5;

    auto box1 = new Image("art/intrface/donebox.frm");
    auto box2 = new Image("art/intrface/donebox.frm");
    box1->setX(backgroundX+38);
    box1->setY(backgroundY+98);
    box2->setX(backgroundX+170);
    box2->setY(backgroundY+98);

    auto yesButton = new ImageButton(ImageButton::TYPE_SMALL_RED_CIRCLE, backgroundX+50, backgroundY+102);
    auto noButton = new ImageButton(ImageButton::TYPE_SMALL_RED_CIRCLE, backgroundX+183, backgroundY+102);
    yesButton->addEventHandler("mouseleftclick", this, (EventRecieverMethod) &ExitConfirmState::onYesButtonClick);
    noButton->addEventHandler("mouseleftclick", this, (EventRecieverMethod) &ExitConfirmState::onNoButtonClick);

    // label: Are you sure you want to quit?
    auto msg = ResourceManager::msgFileType("text/english/game/misc.msg");
    auto font = ResourceManager::font("font1.aaf", 0xb89c28ff);
    auto quitLabel = new TextArea(msg->message(0), backgroundX+30, backgroundY+52);
    quitLabel->setFont(font)->setWidth(244)->setHorizontalAlign(TextArea::HORIZONTAL_ALIGN_CENTER);

    // label: yes & no
    auto msg2 = ResourceManager::msgFileType("text/english/game/dbox.msg");
    auto fontBig = ResourceManager::font("font3.aaf", 0xb89c28ff);
    // label: yes 101
    auto yesButtonLabel = new TextArea(msg2->message(101), backgroundX+74, backgroundY+101);
    yesButtonLabel->setFont(fontBig);
    // label: no 102
    auto noButtonLabel = new TextArea(msg2->message(102), backgroundX+204, backgroundY+101);
    noButtonLabel->setFont(fontBig);

    background->setX(backgroundX);
    background->setY(backgroundY);

    addUI(background);
    addUI(box1);
    addUI(box2);
    addUI(yesButton);
    addUI(noButton);
    addUI(quitLabel);
    addUI(yesButtonLabel);
    addUI(noButtonLabel);
}
Exemple #9
0
    void App::init()
    {
        /* Check if main instance already exists */
        if (App::main_instance_)
        {
            throw Error ("Cannot create multiple apps at once.");
        }

        /* Initialize SDL */
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            throw Error ("Could not initialize SDL.");
        }

        /* Allow app to modify config */
        Window::Config config;
        onInit(config);

        /* Create new window with config */
        window_ = std::make_unique<Window>(config);

        /* Initialize GLEW with created window context */
        glewExperimental = true;
        if (glewInit() != GLEW_OK)
        {
            throw Error ("Failed to init GLEW.");
        }

        /* Flush errors caused by GLEW */
        while (glGetError());

        /* Initialize controllers */
        keyboard_   = std::make_unique<Keyboard>();
        mouse_      = std::make_unique<Mouse>();

        /* Register SDL event handlers */
        addEventHandler(getWindow());
        addEventHandler(getKeyboard());
        addEventHandler(getMouse());

        scene_ = std::make_unique<Scene>();

        renderer_ = std::make_unique<Renderer>(
                window_->getWidth(),
                window_->getHeight());

        App::main_instance_ = this;
        should_quit_ = false;
        
        onPostInit();
    }
Exemple #10
0
ViewerQT::ViewerQT(QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f):
    AdapterWidget( parent, name, shareWidget, f)
{
    setCamera(this->getCamera());
    // Camera
     getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
     getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
     getCamera()->setGraphicsContext(getGraphicsWindow());
    getCamera()->setClearColor(osg::Vec4d(51/255.0, 51/255.0, 102/255.0, 0));
    getCamera()->setViewMatrix(osg::Matrix::identity());
//   // getCamera()->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
//   // getCamera()->setClearColor(osg::Vec4d(1, 1, 1, 0));
//    getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//    getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);
//    getCamera()->setRenderOrder(osg::Camera::POST_RENDER);
//    getCamera()->setUpdateCallback(new AxisCameraUpdateCallback());
//    QString axespath = QCoreApplication::applicationDirPath() + "/axes.osg";
//    osg::Node* axes = osgDB::readNodeFile(axespath.toLatin1().data());
//    qDebug()<<axes->asGroup()->getNumChildren();
//    qDebug()<<axespath;
//    getCamera()->addChild(axes);
    // Trackball
    m_rpTrackball = new osgGA::TrackballManipulator;
  //  setCameraManipulator(m_rpTrackball.get());
    addEventHandler(new osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet()));
   // addEventHandler(new osgViewer::WindowSizeHandler);
    addEventHandler(new osgViewer::StatsHandler);
    // Scene root
    m_rpSceneGroupRoot = new osg::Group;
    setSceneData(m_rpSceneGroupRoot.get());
    osg::Camera* camera = createHUD();
    addSlave(camera, false);
    m_rpSceneGroupRoot->addChild(camera);
    osgText::Text* text = new osgText::Text;
    m_rpSceneGroupRoot->addChild( createHUD_viewPoint( text));//加入HUD文字
//    pickHandler = new PickHandler;
//    addEventHandler(pickHandler);

    addEventHandler(new PickDragHandler(text));
    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator =
            new osgGA::KeySwitchMatrixManipulator;
    keyswitchManipulator->addMatrixManipulator(1,"Trackball",new osgGA::TrackballManipulator());
    keyswitchManipulator->addMatrixManipulator(2,"Flight",new osgGA::FlightManipulator());
    keyswitchManipulator->addMatrixManipulator(3,"Drive",new osgGA::DriveManipulator());
    keyswitchManipulator->addMatrixManipulator(4,"Terrain",new osgGA::TerrainManipulator());
    setCameraManipulator(keyswitchManipulator.get());
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _timer.start(10);
}
	//-----------------------------------------------------------------------
	ParticleEventHandler* ParticleObserver::createEventHandler(const String& eventHandlerType)
	{
		assert(eventHandlerType != "" && "eventHandlerType is empty!");
		ParticleEventHandler* eventHandler = ParticleSystemManager::getSingletonPtr()->createEventHandler(eventHandlerType);
		addEventHandler(eventHandler);
		return eventHandler;
	}
void CritterObject::think()
{
    if (movementQueue()->size() > 0)
    {
        if (!_moving)
        {
            _moving = true;

            delete _ui;
            _orientation = hexagon()->orientationTo(movementQueue()->back());
            auto animation = _generateMovementAnimation();
            animation->setActionFrame(_running ? 2 : 4);
            animation->addEventHandler("actionFrame",    std::bind(&CritterObject::onMovementAnimationEnded, this, std::placeholders::_1));
            animation->addEventHandler("animationEnded", std::bind(&CritterObject::onMovementAnimationEnded, this, std::placeholders::_1));
            animation->play();
            _ui = animation;
        }
    }
    else
    {
        auto anim = (UI::Animation*)ui();
        if (!_moving && (!anim || !anim->playing()))
        {
            if (SDL_GetTicks() > _nextIdleAnim)
            {
                setActionAnimation("aa");
                _setupNextIdleAnim();
            }
        }
    }
    Object::think();
}
Exemple #13
0
/*
 * Create a balloon-evaluation area for a Widget.
 * There can be either a "mesg" for a fixed string or "mesgCB" to generate a
 * message by calling this callback function.
 * When "mesg" is not NULL it must remain valid for as long as the balloon is
 * used.  It is not freed here.
 * Returns a pointer to the resulting object (NULL when out of memory).
 */
    BalloonEval *
gui_mch_create_beval_area(
    void	*target,
    char_u	*mesg,
    void	(*mesgCB)(BalloonEval *, int),
    void	*clientData)
{
#ifndef FEAT_GUI_GTK
    char	*display_name;	    /* get from gui.dpy */
    int		screen_num;
    char	*p;
#endif
    BalloonEval	*beval;

    if (mesg != NULL && mesgCB != NULL)
    {
	IEMSG(_("E232: Cannot create BalloonEval with both message and callback"));
	return NULL;
    }

    beval = (BalloonEval *)alloc_clear(sizeof(BalloonEval));
    if (beval != NULL)
    {
#ifdef FEAT_GUI_GTK
	beval->target = GTK_WIDGET(target);
#else
	beval->target = (Widget)target;
	beval->appContext = XtWidgetToApplicationContext((Widget)target);
#endif
	beval->showState = ShS_NEUTRAL;
	beval->msg = mesg;
	beval->msgCB = mesgCB;
	beval->clientData = clientData;

	/*
	 * Set up event handler which will keep its eyes on the pointer,
	 * and when the pointer rests in a certain spot for a given time
	 * interval, show the beval.
	 */
	addEventHandler(beval->target, beval);
	createBalloonEvalWindow(beval);

#ifndef FEAT_GUI_GTK
	/*
	 * Now create and save the screen width and height. Used in drawing.
	 */
	display_name = DisplayString(gui.dpy);
	p = strrchr(display_name, '.');
	if (p != NULL)
	    screen_num = atoi(++p);
	else
	    screen_num = 0;
	beval->screen_width = DisplayWidth(gui.dpy, screen_num);
	beval->screen_height = DisplayHeight(gui.dpy, screen_num);
#endif
    }

    return beval;
}
Exemple #14
0
/**
 * Add the given message (m) to the MessageHash marking it as a core command
 * @param msgTable the MessageHash we want to add to
 * @param m the Message we are adding
 * @return MOD_ERR_OK on a successful add.
 **/
int addCoreEventHandler(EvtMessageHash * msgEvtTable[], EvtMessage * evm)
{
    if (!msgEvtTable || !evm) {
        return MOD_ERR_PARAMS;
    }
    evm->core = 1;
    return addEventHandler(msgEvtTable, evm);
}
void OSGViewerWidget::startRendering()
{
  addEventHandler(new StateSetManipulator(getSceneData()->getOrCreateStateSet()));

  threaded_painter_.moveToThread(&gl_thread_);
  connect(&gl_thread_, SIGNAL(started()), &threaded_painter_, SLOT(start()));
  gl_thread_.start();
}
Exemple #16
0
void Credits::onCreditsFinished()
{
    removeEventHandlers("fadedone");
    addEventHandler("fadedone", [this](Event* event) {
        this->onCreditsFadeDone(dynamic_cast<StateEvent*>(event));
    });
    Game::getInstance()->renderer()->fadeOut(0,0,0,1000);
}
Exemple #17
0
bool SDLViewer::setUpWindow(const char *caption, const ScreenSettings & screenSettings)
{
	setKeyEventSetsDone(0);
	if ( !setUpViewerAsSDLGraphicsWindow(caption, screenSettings) ) return false;
	//if ( !setUpViewerAsOSGGraphicsWindow(caption, screenSettings) ) return false;
	m_eventHandler = new SDLEventHandler();
	addEventHandler( m_eventHandler ); // Our base class has the responsibility to destroy m_eventHandler
	getCamera()->setClearMask(0);
	return true;
}
Exemple #18
0
//==============================================================================
ImGuiViewer::ImGuiViewer(const ::osg::Vec4& clearColor)
  : Viewer(clearColor),
    mImGuiHandler(new ImGuiHandler()),
    mAboutWidget(new AboutWidget())
{
  mImGuiHandler->setCameraCallbacks(getCamera());
  mImGuiHandler->addWidget(mAboutWidget, false);

  addEventHandler(mImGuiHandler);
}
Exemple #19
0
cTranscript::cTranscript (int sess) : cActionBase ("transcript", sess)
{
  running = false;
  advrunning = false;
  rotatedaily = false;
  file = NULL;
  advfile = NULL;
  overwrite = true;
  includedump = false;
  includetimestamp = false;
  type = advtype = 1;
  nextLineGagged = false;
  
  addEventHandler ("disconnected", 20, PT_NOTHING);
  addEventHandler ("got-line-after-triggers", 50, PT_TEXTCHUNK);
  addEventHandler ("will-gag", 50, PT_NOTHING);
  addEventHandler ("displayed-line", 50, PT_TEXTCHUNK);
  addEventHandler ("displayed-prompt", 50, PT_TEXTCHUNK);
}
Exemple #20
0
GL_Window::GL_Window(int x, int y, int w, int h, const char *label):
    Fl_Gl_Window(x, y, w, h, label)
{
    _gw = new osgViewer::GraphicsWindowEmbedded(x,y,w,h);

    root = new osg::Group;
    geode = new osg::Geode;

    osg::ref_ptr<osg::Capsule> myCapsule (new osg::Capsule(osg::Vec3f(),1,2));
    osg::ref_ptr<osg::Box> myBox (new osg::Box(osg::Vec3f(),2,2,2));
    osg::ref_ptr<osg::Cylinder> myCylinder (new osg::Cylinder(osg::Vec3f(),.75,2.5));
    osg::ref_ptr<osg::Sphere> mySphere (new osg::Sphere(osg::Vec3f(),1.5));
    osg::ref_ptr<osg::Cone> myCone (new osg::Cone(osg::Vec3f(),1,2));

    shape_vec.push_back(new osg::ShapeDrawable(myBox.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCapsule.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCone.get()));
    shape_vec.push_back(new osg::ShapeDrawable(myCylinder.get()));
    shape_vec.push_back(new osg::ShapeDrawable(mySphere.get()));

    geode->addDrawable(shape_vec[1].get());     // default shape to pick from

    root->addChild(geode.get());

    stateset = geode->getOrCreateStateSet();

    // initial material properties
    diffuse_color.set(1, 1, 1, 1.0);
    specular_color.set(1,1,1,1);
    ambient_color.set(1,1,1,1);
    shininess = 10;
    alpha = 1;

    // apply the properties to the material
    material = new osg::Material;
    material->setDiffuse(osg::Material::FRONT, diffuse_color);
    material->setSpecular(osg::Material::FRONT, specular_color);
    material->setShininess(osg::Material::FRONT, shininess);
    material->setAmbient(osg::Material::FRONT, ambient_color);

    stateset->setAttribute(material.get());
    //stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

    texture = new osg::Texture2D;

    getCamera()->setViewport(new osg::Viewport(0,0,w,h));
    getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(w)/static_cast<double>(h), 1.0f, 10000.0f);
    getCamera()->setGraphicsContext(_gw.get());

    setSceneData(root.get());
    setCameraManipulator(new osgGA::TrackballManipulator);
    addEventHandler(new osgViewer::StatsHandler);
    setThreadingModel(osgViewer::Viewer::SingleThreaded);
}
Exemple #21
0
SceneWidget::SceneWidget(QWidget * parent, const QGLWidget * shareWidget, Qt::WindowFlags f) :
    OSGViewerWidget(parent, shareWidget, f), point_cloud_(new PointCloud), distance_field_(new DenseField) {
  osg::ref_ptr < osg::LightModel > light_model = new osg::LightModel();
  light_model->setTwoSided(true);
  scene_root_->getOrCreateStateSet()->setAttributeAndModes(light_model.get(), osg::StateAttribute::ON);

  addSceneChild(point_cloud_);
  addSceneChild(distance_field_);

  addEventHandler(new PickHandler());
}
void CursorDropdown::init()
{
    if (_initialized) return;
    State::init();
    setFullscreen(false);
    if (!_onlyShowIcon)
    {
        setModal(true);
    }

    auto mouse = Game::getInstance()->mouse();
    _initialX = mouse->x();
    _initialY = mouse->y();

    showMenu();

    addEventHandler("mouseup", [this](Event::Event* event)
    {
        Event::Mouse* mouseEvent;
        if ((mouseEvent = dynamic_cast<Event::Mouse*>(event)) && mouseEvent->leftButton())
        {
            onLeftButtonUp(mouseEvent);
        }
    });
    auto moveHandler = [this](Event::Event* event)
    {
        if (active() && _onlyShowIcon)
        {
            Game::getInstance()->popState();
            event->setHandled(true);
        }
    };
    addEventHandler("mousemove", moveHandler);
    addEventHandler("mousedown", [this](Event::Event* event)
    {
        if (active() && !dynamic_cast<Event::Mouse*>(event)->leftButton())
        {
            Game::getInstance()->popState();
        }
    });
}
Exemple #23
0
QOSG::ViewerQT::ViewerQT( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , Vwr::CoreGraph* cg ):
	AdapterWidget( parent, name, shareWidget, f )
{
	this->cg = cg;
	cg->setCamera( this->getCamera() );

	this->mIsClicAruco=false;

	appConf = Util::ApplicationConfig::get();

	osg::DisplaySettings::instance()->setStereo( appConf->getValue( "Viewer.Display.Stereoscopic" ).toInt() );
	osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );

	getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
	getCamera()->setProjectionMatrixAsPerspective( 60, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
	getCamera()->setGraphicsContext( getGraphicsWindow() );
	getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

	manipulator = new Vwr::CameraManipulator( cg );
	QObject::connect( manipulator, SIGNAL( sendMouseRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByMouse( osg::Quat ) ) );
	QObject::connect( manipulator, SIGNAL( sendFaceDetRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByFaceDet( osg::Quat ) ) );

	pickHandler = new Vwr::PickHandler( manipulator, cg );

	addEventHandler( new osgViewer::StatsHandler );
	addEventHandler( pickHandler );
	setCameraManipulator( manipulator );

	// Gloger: background to white color after disabling skybox
	getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
	getCamera()->setViewMatrixAsLookAt( osg::Vec3d( -10, 0, 0 ), osg::Vec3d( 0, 0, 0 ), osg::Vec3d( 0, 1, 0 ) );

	setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

	connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

	_timer.start( 10 );
}
Exemple #24
0
void Container::init()
{
    if (_initialized) return;

    setModal(true);
    setFullscreen(false);

    auto game = Game::getInstance();

    setX((game->renderer()->width()  - 537)/2);
    setY((game->renderer()->height() - 376)/2);

    addUI("background", new Image("art/intrface/loot.frm"));

    addUI("button_done", new ImageButton(ImageButton::TYPE_SMALL_RED_CIRCLE, 478, 331));
    getActiveUI("button_done")->addEventHandler("mouseleftclick", [this](Event* event){ this->onDoneButtonClick(dynamic_cast<MouseEvent*>(event)); });


    // TAKEALL
    // invmadn
    // invmaup

    // invupds
    // invupin
    // invupout


    auto dudeList = new ItemsList(170, 35);
    dudeList->setItems(Game::getInstance()->player()->inventory());
    addUI(dudeList);

    auto containerList = new ItemsList(292, 35);
    containerList->setItems(object()->inventory());
    addUI(containerList);

    dudeList->addEventHandler("itemdragstop", [containerList](Event* event){ containerList->onItemDragStop(dynamic_cast<MouseEvent*>(event)); });
    containerList->addEventHandler("itemdragstop", [dudeList](Event* event){ dudeList->onItemDragStop(dynamic_cast<MouseEvent*>(event)); });

}
Exemple #25
0
void LoadGame::doCancel()
{
    if (!Game::getInstance()->locationState())
    {
        removeEventHandlers("fadedone");
        addEventHandler("fadedone", [this](Event::Event* event){ this->onCancelFadeDone(dynamic_cast<Event::State*>(event)); });
        Game::getInstance()->renderer()->fadeOut(255,255,255,1000);
    }
    else
    {
        Game::getInstance()->popState();
    }
}
void CritterDialog::addAnswer(const std::string& text)
{
    std::string line = "";
    line += 0x95;
    line += " ";
    line += text;

    int y = 50;
    for (auto answer : _answers)
    {
        y += answer->size().height() + 5;
    }

    auto answer = new UI::TextArea(line, 140, y);
    answer->setWordWrap(true);
    answer->setSize({370, 0});

    answer->addEventHandler("mousein", std::bind(&CritterDialog::onAnswerIn, this, std::placeholders::_1));
    answer->addEventHandler("mouseout", std::bind(&CritterDialog::onAnswerOut, this, std::placeholders::_1));
    answer->addEventHandler("mouseleftclick", std::bind(&CritterDialog::onAnswerClick, this, std::placeholders::_1));
    _answers.push_back(answer);
    addUI(answer);
}
void PlayerEditGender::init()
{
    if (_initialized) return;
    State::init();

    setFullscreen(false);
    setModal(true);

    Point bgPos = Point((Game::getInstance()->renderer()->size() - Point(640, 480)) / 2);
    int bgX = bgPos.x();
    int bgY = bgPos.y();

    auto bg = new UI::Image("art/intrface/charwin.frm");
    bg->setPosition(bgPos + Point(236, 0));

    _maleImage = new UI::ImageList((std::vector<std::string>){
                                    "art/intrface/maleoff.frm",
                                    "art/intrface/maleon.frm"
                                }, bgX+260, bgY+2);
    _maleImage->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onMaleButtonPress(dynamic_cast<Event::Mouse*>(event)); });

    _femaleImage = new UI::ImageList((std::vector<std::string>){
                                                            "art/intrface/femoff.frm",
                                                            "art/intrface/femon.frm"
                                                            }, bgX+310, bgY+2);
    _femaleImage->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onFemaleButtonPress(dynamic_cast<Event::Mouse*>(event)); });

    auto doneBox = new UI::Image("art/intrface/donebox.frm");
    doneBox->setPosition(bgPos + Point(250, 42));

    auto doneLabel = new UI::TextArea(_t(MSG_EDITOR, 100), bgX+281, bgY+45);
    auto font3_b89c28ff = ResourceManager::getInstance()->font("font3.aaf", 0xb89c28ff);
    doneLabel->setFont(font3_b89c28ff);

    auto doneButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, bgX+260, bgY+45);
    doneButton->addEventHandler("mouseleftclick", [this](Event::Event* event){ this->onDoneButtonClick(dynamic_cast<Event::Mouse*>(event)); });

    addUI(bg);
    addUI(doneBox);
    addUI(doneButton);
    addUI(doneLabel);
    addUI(_maleImage);
    addUI(_femaleImage);
    setGender(Game::getInstance()->player()->gender());
}
QOSG::ProjectiveARViewer::ProjectiveARViewer( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , osgViewer::Viewer* viewerPerspective ):
    AdapterWidget( parent, name, shareWidget, f )
{
    this->viewerPerspective = viewerPerspective;

    appConf = Util::ApplicationConfig::get();

    renderCamera = new osg::Camera;
    useGraph = true;

    // setup Graph (radius 0.5m)
    graphPos = osg::Vec3d(-0.75, -0.25, 0.25);
    graphRadius = 0.5;

    // setup Viewer
    viewerPos = osg::Vec3d(-1.88, -0.95, 1.72);
    viewerDir = osg::Vec3d( -0.75, 0, 0.238 ) - viewerPos;
    viewerFOV = 90;

    this->setSceneData(createProjectorScene());

    // setup Projector
    projectorPos = osg::Vec3d( -0.665, -1.345, 0.825);
    projectorDir = osg::Vec3d( -0.75, 0, 0.238 ) - projectorPos;
    projectorFOV = 30;

    getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
    getCamera()->setProjectionMatrixAsPerspective( projectorFOV, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
    getCamera()->setGraphicsContext( getGraphicsWindow() );
    getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

    getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
    getCamera()->setViewMatrixAsLookAt( projectorPos, projectorDir + projectorPos, osg::Vec3d( 0, 0, 1 ) );


    addEventHandler( new osgViewer::StatsHandler );

    setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

    connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

    _timer.start( 10 );
}
void GameCritterObject::think()
{
    if (movementQueue()->size() > 0)
    {
        if (!_moving)
        {
            _moving = true;

            delete _ui;
            _orientation = hexagon()->orientationTo(movementQueue()->back());
            auto animation = _generateMovementAnimation();
            animation->setActionFrame(_running ? 2 : 4);
            animation->addEventHandler("actionFrame",    std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1));
            animation->addEventHandler("animationEnded", std::bind(&GameCritterObject::onMovementAnimationEnded, this, std::placeholders::_1));
            animation->play();
            _ui = animation;
        }
    }
    GameObject::think();
}
OSGViewerWidget::OSGViewerWidget(QWidget * parent, const QGLWidget * shareWidget, Qt::WindowFlags f)
  :AdapterWidget(parent, shareWidget, f, true),
  scene_root_(new osg::Group),
  other_root_(new osg::Group),
  gl_thread_(this),
  threaded_painter_(this)
{
  osg::ref_ptr<osg::Group> root = new osg::Group;
  root->addChild(scene_root_);
  root->addChild(other_root_);
  setSceneData(root);

  scene_root_->getOrCreateStateSet()->setAttribute(new osg::Point(2.0f), osg::StateAttribute::ON);
  scene_root_->getOrCreateStateSet()->setAttribute(new osg::LineWidth(1.0f), osg::StateAttribute::ON);

  setCameraManipulator(new osgGA::TrackballManipulator);

  addEventHandler(new osgViewer::HelpHandler);
  addEventHandler(new osgViewer::StatsHandler);
  addEventHandler(new osgViewer::LODScaleHandler);
  addEventHandler(new osgViewer::ThreadingHandler);
  addEventHandler(new osgViewer::ScreenCaptureHandler(new WriteToFile));
  addEventHandler(new RecordCameraPathHandler);

  for (int i = 0; i < 6; ++ i)
  {
    osg::ref_ptr<LightSource> light_source = new LightSource(i);
    light_sources_.push_back(light_source);
    char index = '0'+i;
    addEventHandler(new ToggleHandler(light_source, index, std::string("Toggle Light Source ")+index));
    addChild(light_source, false);
  }

  double w = width();
  double h = height();
  getCamera()->setViewport(new osg::Viewport(0, 0, w, h));
  getCamera()->setProjectionMatrixAsPerspective(60.0f, w/h, 1.0f, 10000.0f);
  getCamera()->setGraphicsContext(getOrganGraphicsWindow());
  getCamera()->setClearColor(osg::Vec4(1, 1, 1, 1.0));

  setThreadingModel(osgViewer::Viewer::SingleThreaded);

  this->doneCurrent();
}