Пример #1
0
bool CScreenCapture::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	osgViewer::ViewerBase* viewer = dynamic_cast<osgViewer::View*>(&aa)->getViewerBase();
	if (!viewer) return false;

	switch (ea.getEventType())
	{
	case (osgGA::GUIEventAdapter::FRAME) :
	{
		// Booleans aren't the best way of doing this, but I want to do
		// the actual adding here because I don't want to require
		// startCapture() take a viewer as argument, which could not be
		// the right one.
		if (_startCapture)
		{
			// Start capturing with the currently set number of frames.
			// If set to -1 it will capture continuously, if set to >0
			// it will capture that number of frames.
			_startCapture = false;
			addCallbackToViewer(*viewer);
		}
		else if (_stopCapture)
		{
			_stopCapture = false;
			removeCallbackFromViewer(*viewer);
		}
		break;
	}

	default:
		break;
	}
	return false;
}
Пример #2
0
// aa will point to an osgViewer::View, so we will take a screenshot
// of that view's graphics contexts.
bool ScreenCaptureHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
    osgViewer::ViewerBase* viewer = dynamic_cast<osgViewer::View*>(&aa)->getViewerBase();
    if (!viewer) return false;

    switch(ea.getEventType())
    {
        case (osgGA::GUIEventAdapter::FRAME):
        {
            // Booleans aren't the best way of doing this, but I want to do
            // the actual adding here because I don't want to require
            // startCapture() take a viewer as argument, which could not be
            // the right one.
            if (_startCapture)
            {
                // Start capturing with the currently set number of frames.
                // If set to -1 it will capture continuously, if set to >0
                // it will capture that number of frames.
                _startCapture = false;
                addCallbackToViewer(*viewer);
            }
            else if (_stopCapture)
            {
                _stopCapture = false;
                removeCallbackFromViewer(*viewer);
            }
            break;
        }

        case(osgGA::GUIEventAdapter::KEYUP):
        {
            if (ea.getKey() == _keyEventTakeScreenShot)
            {
                // Check that we will capture at least one frame.
                // Just check for ==0, because >0 is means we're already
                // capturing and <0 means it will capture all frames.
                WindowCaptureCallback* callback = static_cast<WindowCaptureCallback*>(_callback.get());
                if (callback->getFramesToCapture() == 0)
                {
                    setFramesToCapture(1);
                }
                addCallbackToViewer(*viewer);
                return true;
            }

            if (ea.getKey() == _keyEventToggleContinuousCapture)
            {
                if (getFramesToCapture() < 0)
                {
                    setFramesToCapture(0);
                    removeCallbackFromViewer(*viewer);
                }
                else
                {
                    setFramesToCapture(-1);
                    addCallbackToViewer(*viewer);
                }
                return true;
            }
            break;
        }
    default:
        break;
    }

    return false;
}