コード例 #1
0
ファイル: DemoKeeper.cpp プロジェクト: sskoruppa/Glove_Code
	void DemoKeeper::injectMouseMove(int _absx, int _absy, int _absz)
	{
		if (!getGUI())
			return;

		// при зажатой правой вращаем сцену
		if (mRightButtonPressed)
		{
			// относительное смещение
			int rel_x = _absx - mSaveCursorX;
			int rel_y = _absy - mSaveCursorY;

			_absx = mSaveCursorX;
			_absy = mSaveCursorY;

			setMousePosition(mSaveCursorX, mSaveCursorY);

			// вращаем сцену
			updateCamera(rel_x, rel_y);
		}
		else
		{
			// ввод мыши находить вне гу¤
			if (!getGUI()->injectMouseMove(_absx, _absy, _absz))
			{
			}
		}
	}
コード例 #2
0
ファイル: OISListener.cpp プロジェクト: 67-6f-64/OryxEngine
	OISListener::OISListener(size_t handle,OISSubsystem* sys,bool grabMouse)
	{
		mSubsystem = sys;

		std::ostringstream windowHndStr;
		windowHndStr << handle;

		OIS::ParamList pl;
		pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));

		if(!grabMouse)
		{
		#ifdef OIS_WIN32_PLATFORM
			pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" )));
			pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
			pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
			pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
		#elif defined OIS_LINUX_PLATFORM
			pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false")));
			pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false")));
			pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
			pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
		#endif
		}

		mInputManager = OIS::InputManager::createInputSystem(pl);
		mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
		mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
		mKeyboard->setEventCallback(this);
		mMouse->setEventCallback(this);
		const OIS::MouseState &ms = mMouse->getMouseState();
		ms.width = 800;
		ms.height = 600;
		setMousePosition(ms.width/2,ms.height/2);
	}
コード例 #3
0
ファイル: DemoKeeper.cpp プロジェクト: MyGUI/mygui
	void DemoKeeper::injectMouseMove(int _absx, int _absy, int _absz)
	{
		if (MyGUI::Gui::getInstancePtr() == nullptr)
			return;

		// при зажатой правой вращаем сцену
		if (mRightButtonPressed)
		{
			// относительное смещение
			int rel_x = _absx - mSaveCursorX;
			int rel_y = _absy - mSaveCursorY;

			_absx = mSaveCursorX;
			_absy = mSaveCursorY;

			setMousePosition(mSaveCursorX, mSaveCursorY);

			// вращаем сцену
			updateCamera(rel_x, rel_y);
		}
		else
		{
			// ввод мыши находить вне гуя
			if (!MyGUI::InputManager::getInstance().injectMouseMove(_absx, _absy, _absz))
			{
			}
		}
	}
コード例 #4
0
void InputAdapter::onSDLInputEvent(const SDL_Event & event)
{
    switch (event.type)
    {
        case SDL_KEYUP:
            setKeyDown(SDLKeyToDeliberation(event.key.keysym.sym), false);
            break;

        case SDL_KEYDOWN:
            setKeyDown(SDLKeyToDeliberation(event.key.keysym.sym), true);
            break;

        case SDL_MOUSEBUTTONUP:
            setMouseButtonDown(SDLMouseButtonToDeliberation(event.button.button), false);
            break;

        case SDL_MOUSEBUTTONDOWN:
            setMouseButtonDown(SDLMouseButtonToDeliberation(event.button.button), true);
            break;

        case SDL_MOUSEMOTION:
            setMousePosition({event.motion.x, event.motion.y});
            break;
    }

}
コード例 #5
0
void
InputManager::UpdateMouseButtons(int button,int state,int x,int y)
{
		switch (button)
		{
		case GLUT_LEFT_BUTTON:
			LEFTnewState = !state;
			break;
		case GLUT_MIDDLE_BUTTON:
			MIDDLEnewState =  !state;
			break;
		case GLUT_RIGHT_BUTTON:
			RIGHTnewState = !state;
			break;
		}

		setMousePosition(x,y);

		if(mouseClickObservers.Count()>0)
		{
			for(unsigned ID = mouseClickObservers.First(); ID <= mouseClickObservers.Last(); ID = mouseClickObservers.Next(ID))
			{
				if(mouseClickObservers[ID]->checkForObservability(OBSERVATE_KEYBOARD))
					((IInteractive*)mouseClickObservers[ID])->mouseClicks(button,state==GLUT_DOWN,Mouse.Position);
			}
		}
}
コード例 #6
0
void KisToolDyna::mousePressEvent(KoPointerEvent *e)
{
    setMousePosition(e->point);
    m_mouse.init(m_mousePos.x(), m_mousePos.y());
    m_odelx = m_mousePos.x();
    m_odely = m_mousePos.y();
    
    KisToolFreehand::mousePressEvent(e);
}
コード例 #7
0
void KisToolDyna::beginPrimaryAction(KoPointerEvent *event)
{
    setMousePosition(event->point);
    m_mouse.init(m_mousePos.x(), m_mousePos.y());
    m_odelx = m_mousePos.x();
    m_odely = m_mousePos.y();

    KisToolFreehand::beginPrimaryAction(event);
}
コード例 #8
0
void KisToolDyna::continuePrimaryAction(KoPointerEvent *event)
{
    setMousePosition(event->point);

    if (applyFilter(m_mousePos.x(), m_mousePos.y())) {
        KoPointerEvent newEvent = filterEvent(event);
        KisToolFreehand::continuePrimaryAction(&newEvent);
    }
}
コード例 #9
0
ファイル: opengl-graphics.cpp プロジェクト: 86400/scummvm
void OpenGLGraphicsManager::showOverlay() {
	_overlayVisible = true;
	_forceRedraw = true;

	// Allow drawing inside full screen area.
	_backBuffer.enableScissorTest(false);

	// Update cursor position.
	setMousePosition(_cursorX, _cursorY);
}
コード例 #10
0
ファイル: opengl-graphics.cpp プロジェクト: 86400/scummvm
void OpenGLGraphicsManager::hideOverlay() {
	_overlayVisible = false;
	_forceRedraw = true;

	// Limit drawing to screen area.
	_backBuffer.enableScissorTest(true);
	_scissorOverride = 3;

	// Update cursor position.
	setMousePosition(_cursorX, _cursorY);
}
コード例 #11
0
void
InputManager::notifyMouse(int x, int y) 
{
	setMousePosition(x,y);

	if(MouseMotionObservers.Count()==0)
		return;

	for(unsigned ID = MouseMotionObservers.First(); ID <= MouseMotionObservers.Last(); ID = MouseMotionObservers.Next(ID))
		((IInteractive*)MouseMotionObservers[ID])->mouseMotion(x,y);
}
コード例 #12
0
void KisToolDyna::initStroke(KoPointerEvent *event)
{
    QRectF imageSize = QRectF(QPointF(0.0,0.0),currentImage()->size());
    QRectF documentSize = currentImage()->pixelToDocument(imageSize);
    m_surfaceWidth = documentSize.width();
    m_surfaceHeight = documentSize.height();
    setMousePosition(event->point);
    m_mouse.init(m_mousePos.x(), m_mousePos.y());

    KisToolFreehand::initStroke(event);
}
コード例 #13
0
ファイル: mouse.c プロジェクト: finallyjustice/xv6_gui
void mouseinit()
{
  outb(0x64, 0xa8);
  outb(0x64, 0xd4);
  outb(0x60, 0xf4);
  outb(0x64, 0x60);
  outb(0x60, 0x47);
  setMousePosition(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
  initlock(&mouse_lock, "mouse");
  picenable(IRQ_MOUSE);
  ioapicenable(IRQ_MOUSE, 0);
}
コード例 #14
0
ファイル: Input.cpp プロジェクト: simplerr/Banzai
/**
@param msg The message.
@param wParam Message data.
@param lParam Message data.
*/
LRESULT Input::msgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_MOUSEMOVE:	{
		setMousePosition(Vector(LOWORD(lParam), HIWORD(lParam)));
		return 0;
		}
	case WM_LBUTTONDOWN:	{
		//showMsg("doo");
		return 0;
		}
	}
}
コード例 #15
0
ファイル: graphics.cpp プロジェクト: dergunov/scummvm
bool TizenGraphicsManager::moveMouse(int16 &x, int16 &y) {
	int16 currentX, currentY;
	getMousePosition(currentX, currentY);

	// save the current hardware coordinates
	setMousePosition(x, y);

	// return x/y as game coordinates
	adjustMousePosition(x, y);

	// convert current x/y to game coordinates
	adjustMousePosition(currentX, currentY);

	// return whether game coordinates have changed
	return (currentX != x || currentY != y);
}
コード例 #16
0
void KisToolDyna::mouseMoveEvent(KoPointerEvent *e)
{
    if(!MOVE_CONDITION(event, KisTool::PAINT_MODE)) {
        KisToolFreehand::mouseMoveEvent(e);
        return;
    }

    setMousePosition(e->point);

    if (applyFilter(m_mousePos.x(), m_mousePos.y())) {
        KoPointerEvent newEvent = filterEvent(e);
        KisToolFreehand::mouseMoveEvent(&newEvent);
    }

    if (m_painter && m_painter->paintOp() && currentPaintOpPreset()->settings()->isAirbrushing()) {
        m_timer->start(m_rate);
    }
}
コード例 #17
0
ファイル: DemoKeeper.cpp プロジェクト: MyGUI/mygui
	void DemoKeeper::createScene()
	{
		base::BaseDemoManager::createScene();
		createEntities();

		const MyGUI::VectorWidgetPtr& root = MyGUI::LayoutManager::getInstance().loadLayout("HelpPanel.layout");
		if (root.size() == 1)
			root.at(0)->findWidget("Text")->castType<MyGUI::TextBox>()->setCaption("Implementation of custom complex cursor behaviour, interaction of system and in-game cursors.");

		std::string resourceCategory = MyGUI::ResourceManager::getInstance().getCategoryName();
		MyGUI::FactoryManager::getInstance().registerFactory<ResourcePointerContext>(resourceCategory);

		MyGUI::ResourceManager::getInstance().load("Contexts.xml");

#ifdef MYGUI_SAMPLES_INPUT_OIS
		MyGUI::ResourceManager::getInstance().load("DemoPointers.xml");
#elif MYGUI_SAMPLES_INPUT_WIN32
		MyGUI::ResourceManager::getInstance().load("DemoPointersW32.xml");
#elif MYGUI_SAMPLES_INPUT_WIN32_OIS
		MyGUI::ResourceManager::getInstance().load("DemoPointersW32.xml");
#endif

		mPointerContextManager = new PointerContextManager(this);
		mPointerContextManager->addContext("ptrx_Normal");
		mPointerContextManager->setPointer("default");

		mEnemyPanel = new EnemyPanel();
		mFriendPanel = new FriendPanel();
		mControlPanel = new ControlPanel(mPointerContextManager);

		MyGUI::IntSize size = MyGUI::RenderManager::getInstance().getViewSize();
		setMousePosition(size.width / 2, size.height / 2);
		updateCursorPosition();

#ifdef MYGUI_OGRE_PLATFORM
		mEnemyPanel->setVisible(false);
		mFriendPanel->setVisible(false);
#endif

		updateCamera(0, 0);
	}
コード例 #18
0
void OpenGLGraphicsManager::warpMouse(int x, int y) {
	int16 currentX = _cursorX;
	int16 currentY = _cursorY;
	adjustMousePosition(currentX, currentY);

	// Check whether the (virtual) coordinate actually changed. If not, then
	// simply do nothing. This avoids ugly "jittering" due to the actual
	// output screen having a bigger resolution than the virtual coordinates.
	if (currentX == x && currentY == y) {
		return;
	}

	// Scale the virtual coordinates into actual physical coordinates.
	if (_overlayVisible) {
		if (!_overlay) {
			return;
		}
	
		// It might be confusing that we actually have to handle something
		// here when the overlay is visible. This is because for very small
		// resolutions we have a minimal overlay size and have to adjust
		// for that.
		x = (x * _outputScreenWidth)  / _overlay->getWidth();
		y = (y * _outputScreenHeight) / _overlay->getHeight();
	} else {
		if (!_gameScreen) {
			return;
		}

		x = (x * _displayWidth)  / _gameScreen->getWidth();
		y = (y * _displayHeight) / _gameScreen->getHeight();

		x += _displayX;
		y += _displayY;
	}

	setMousePosition(x, y);
	setInternalMousePosition(x, y);
}
コード例 #19
0
void KisToolDyna::initPaint(KoPointerEvent *e)
{
    m_rate = currentPaintOpPreset()->settings()->rate();
    
    QRectF imageSize = QRectF(QPointF(0.0,0.0),currentImage()->size());
    QRectF documentSize = currentImage()->pixelToDocument(imageSize);
    m_surfaceWidth = documentSize.width();
    m_surfaceHeight = documentSize.height();
    setMousePosition(e->point);
    m_mouse.init(m_mousePos.x(), m_mousePos.y());
    
    KisToolFreehand::initPaint(e);

    if (!m_painter) {
        warnKrita << "Didn't create a painter! Something is wrong!";
        return;
    }

    if (currentPaintOpPreset()->settings()->isAirbrushing()) {
        m_timer->start(m_rate);
    }
}
コード例 #20
0
ファイル: mouse.c プロジェクト: finallyjustice/xv6_gui
void moveMousePosition(int x, int y)
{
  setMousePosition(mouse_info.x_position + x, mouse_info.y_position + y);
}
コード例 #21
0
ファイル: SDLMouseManager.cpp プロジェクト: Antidote/Orion
void SDLMouseManager::setMousePosition(Vector2i position)
{
    setMousePosition(position.x, position.y);
}
コード例 #22
0
ファイル: mouse.cpp プロジェクト: MaddTheSane/scummvm
/**
 * Move mouse
 * @remarks	Originally called 'mov_mouse'
 */
void MouseHandler::moveMouse(bool &funct, char &key) {
	bool p_key;
	char in1, in2;
	int cx, cy;
	bool click;

	// Set defaults and check pending events
	funct = false;
	key = '\377';
	p_key = _vm->keyPressed();

	// If mouse button clicked, return it
	if (_vm->getMouseClick())
		return;

	// Handle any pending keypresses
	while (p_key) {
		if (_vm->shouldQuit())
			return;

		in1 = _vm->getChar();
		getMousePosition(cx, cy, click);
		switch (toupper(in1)) {
		case '4':
			cx -= 8;
			break;
		case '2':
			cy += 8;
			break;
		case '6':
			cx += 8;
			break;
		case '8':
			cy -= 8;
			break;
		case '7':
			cy = 1;
			cx = 1;
			break;
		case '1':
			cx = 1;
			cy = 190;
			break;
		case '9':
			cx = 315 * kResolutionScaler;
			cy = 1;
			break;
		case '3':
			cy = 190;
			cx = 315 * kResolutionScaler;
			break;
		case '5':
			cy = 100;
			cx = 155 * kResolutionScaler;
			break;
		case ' ':
		case '\15':
			_vm->setMouseClick(true);
			return;
			break;
		case '\33':
			p_key = _vm->keyPressed();

			if (p_key) {
				in2 = _vm->getChar();

				if ((in2 >= ';') && (in2 <= 'D')) {
					funct = true;
					key = in2;
					return;
				} else {
					switch (in2) {
					case 'K':
						--cx;
						break;
					case 'P':
						++cy;
						break;
					case 'M':
						cx += 2;
						break;
					case 'H':
						--cy;
						break;
					case 'G':
						--cx;
						--cy;
						break;
					case 'I':
						++cx;
						--cy;
						break;
					case 'O':
						--cx;
						++cy;
						break;
					case 'Q':
						++cx;
						++cy;
						break;
					default:
						break;
					}    // case
				}
			}
			break;
		case 'I':
			cx = kResolutionScaler * 32;
			cy = 8;
			break;
		case 'D':
			cx = 80 * kResolutionScaler;
			cy = 8;
			break;
		case 'A':
			cx = 126 * kResolutionScaler;
			cy = 8;
			break;
		case 'S':
			cx = 174 * kResolutionScaler;
			cy = 8;
			break;
		case 'P':
			cx = 222 * kResolutionScaler;
			cy = 8;
			break;
		case 'F':
			cx = kResolutionScaler * 270;
			cy = 8;
			break;
		case '\23':
			_vm->_soundOff = !_vm->_soundOff;
			return;
			break;
		case '\24':           // ^T => mode tandy
			funct = true;
			key = '\11';
			break;
		case '\10':           // ^H => mode Hercule
			funct = true;
			key = '\7';
			break;
		case '\1':
		case '\3':
		case '\5':
			funct = true;
			key = in1;
			break;
		default:
			break;
		}

		setMousePosition(Common::Point(cx, cy));
		p_key = _vm->keyPressed();
	}
}
コード例 #23
0
ファイル: SdlContext.cpp プロジェクト: r-lyeh-forks/AGE
void SdlContext::refreshInputs()
{
    SCOPE_profile_cpu_function("RenderTimer");

    SDL_Event events;
    auto input = _dependencyManager->getInstance<Input>();

    input->frameUpdate();
    if (_firstCall)
    {
        _initJoysticks(*input);
        _firstCall = false;
    }
    while (SDL_PollEvent(&events))
    {
        switch (events.type)
        {
        case SDL_KEYDOWN:
            input->keyInputPressed(findAgeMappedKey(events.key.keysym.sym), findAgePhysicalKey(events.key.keysym.scancode));
            break;
        case SDL_KEYUP:
            input->keyInputReleased(findAgeMappedKey(events.key.keysym.sym), findAgePhysicalKey(events.key.keysym.scancode));
            break;
        case SDL_MOUSEBUTTONDOWN:
            input->mouseButtonPressed(findAgeMouseButton(events.button.button));
            break;
        case SDL_MOUSEBUTTONUP:
            input->mouseButtonReleased(findAgeMouseButton(events.button.button));
            break;
        case SDL_MOUSEWHEEL:
            input->setMouseWheel(glm::ivec2(events.wheel.x, events.wheel.y));
            break;
        case SDL_MOUSEMOTION:
            input->setMousePosition(glm::ivec2(events.motion.x, events.motion.y), glm::ivec2(events.motion.xrel, events.motion.yrel));
            break;
        case SDL_JOYDEVICEADDED:
            _addJoystick(*input, events.jdevice.which);
            break;
        case SDL_JOYDEVICEREMOVED:
            _removeJoystick(*input, events.jdevice.which);
            break;
        case SDL_JOYAXISMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jaxis.which);
            AgeJoystickAxis joyAxis = findAgeJoystickAxis(events.jaxis.axis);
            float value = (float)events.jaxis.value / 32768.0f;
            input->setJoystickAxis(joyId, joyAxis, value);
        }
        break;
        case SDL_JOYBUTTONDOWN:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jbutton.which);
            AgeJoystickButtons joyButton = findAgeJoystickButton(events.jbutton.button);
            input->joystickButtonPressed(joyId, joyButton);
        }
        break;
        case SDL_JOYBUTTONUP:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jbutton.which);
            AgeJoystickButtons joyButton = findAgeJoystickButton(events.jbutton.button);
            input->joystickButtonReleased(joyId, joyButton);
        }
        break;
        case SDL_JOYBALLMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jball.which);
            input->setJoystickTrackBall(joyId, events.jball.ball, glm::ivec2(events.jball.xrel, events.jball.yrel));
        }
        break;
        case SDL_JOYHATMOTION:
        {
            uint32_t joyId = _fromSdlJoystickIdToAge(events.jhat.which);
            AgeJoystickHatDirections joyHatDir = findAgeJoystickHatDirection(events.jhat.value);
            input->setJoystickHat(joyId, events.jhat.hat, joyHatDir);
        }
        break;
        case SDL_WINDOWEVENT:
            input->addWindowInput(findAgeWindowInput(events.window.event));
            break;
        default:
            input->addWindowInput(findAgeWindowInput(events.type));
            break;
        }
    }
    input->sendMouseStateToIMGUI();
}
コード例 #24
0
void OpenGLSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
	setMousePosition(mouse.x, mouse.y);
}
コード例 #25
0
ファイル: opengl-graphics.cpp プロジェクト: 86400/scummvm
bool OpenGLGraphicsManager::getGLPixelFormat(const Graphics::PixelFormat &pixelFormat, GLenum &glIntFormat, GLenum &glFormat, GLenum &glType) const {
#ifdef SCUMM_LITTLE_ENDIAN
	if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
#else
	if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
#endif
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_BYTE;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)) { // RGB565
		glIntFormat = GL_RGB;
		glFormat = GL_RGB;
		glType = GL_UNSIGNED_SHORT_5_6_5;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)) { // RGBA5551
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_SHORT_5_5_5_1;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0)) { // RGBA4444
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_SHORT_4_4_4_4;
		return true;
#if !USE_FORCED_GLES && !USE_FORCED_GLES2
	// The formats below are not supported by every GLES implementation.
	// Thus, we do not mark them as supported when a GLES context is setup.
	} else if (isGLESContext()) {
		return false;
#ifdef SCUMM_LITTLE_ENDIAN
	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_INT_8_8_8_8;
		return true;
#endif
	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0)) { // RGB555
		glIntFormat = GL_RGB;
		glFormat = GL_BGRA;
		glType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)) { // ARGB4444
		glIntFormat = GL_RGBA;
		glFormat = GL_BGRA;
		glType = GL_UNSIGNED_SHORT_4_4_4_4_REV;
		return true;
#ifdef SCUMM_BIG_ENDIAN
	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)) { // ABGR8888
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_INT_8_8_8_8_REV;
		return true;
#endif
	} else if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0)) { // BGRA8888
		glIntFormat = GL_RGBA;
		glFormat = GL_BGRA;
		glType = GL_UNSIGNED_INT_8_8_8_8;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0)) { // BGR565
		glIntFormat = GL_RGB;
		glFormat = GL_RGB;
		glType = GL_UNSIGNED_SHORT_5_6_5_REV;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 5, 5, 5, 1, 1, 6, 11, 0)) { // BGRA5551
		glIntFormat = GL_RGBA;
		glFormat = GL_BGRA;
		glType = GL_UNSIGNED_SHORT_5_5_5_1;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12)) { // ABGR4444
		glIntFormat = GL_RGBA;
		glFormat = GL_RGBA;
		glType = GL_UNSIGNED_SHORT_4_4_4_4_REV;
		return true;
	} else if (pixelFormat == Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)) { // BGRA4444
		glIntFormat = GL_RGBA;
		glFormat = GL_BGRA;
		glType = GL_UNSIGNED_SHORT_4_4_4_4;
		return true;
#endif // !USE_FORCED_GLES && !USE_FORCED_GLES2
	} else {
		return false;
	}
}

frac_t OpenGLGraphicsManager::getDesiredGameScreenAspect() const {
	const uint width  = _currentState.gameWidth;
	const uint height = _currentState.gameHeight;

	if (_currentState.aspectRatioCorrection) {
		// In case we enable aspect ratio correction we force a 4/3 ratio.
		// But just for 320x200 and 640x400 games, since other games do not need
		// this.
		if ((width == 320 && height == 200) || (width == 640 && height == 400)) {
			return intToFrac(4) / 3;
		}
	}

	return intToFrac(width) / height;
}

void OpenGLGraphicsManager::recalculateDisplayArea() {
	if (!_gameScreen || _outputScreenHeight == 0) {
		return;
	}

	const frac_t outputAspect = intToFrac(_outputScreenWidth) / _outputScreenHeight;
	const frac_t desiredAspect = getDesiredGameScreenAspect();

	_displayWidth = _outputScreenWidth;
	_displayHeight = _outputScreenHeight;

	// Adjust one dimension for mantaining the aspect ratio.
	if (outputAspect < desiredAspect) {
		_displayHeight = intToFrac(_displayWidth) / desiredAspect;
	} else if (outputAspect > desiredAspect) {
		_displayWidth = fracToInt(_displayHeight * desiredAspect);
	}

	// We center the screen in the middle for now.
	_displayX = (_outputScreenWidth  - _displayWidth ) / 2;
	_displayY = (_outputScreenHeight - _displayHeight) / 2;

	// Setup drawing limitation for game graphics.
	// This invovles some trickery because OpenGL's viewport coordinate system
	// is upside down compared to ours.
	_backBuffer.setScissorBox(_displayX,
	                          _outputScreenHeight - _displayHeight - _displayY,
	                          _displayWidth,
	                          _displayHeight);
	// Clear the whole screen for the first three frames to remove leftovers.
	_scissorOverride = 3;

	// Update the cursor position to adjust for new display area.
	setMousePosition(_cursorX, _cursorY);

	// Force a redraw to assure screen is properly redrawn.
	_forceRedraw = true;
}

void OpenGLGraphicsManager::updateCursorPalette() {
	if (!_cursor || !_cursor->hasPalette()) {
		return;
	}

	if (_cursorPaletteEnabled) {
		_cursor->setPalette(0, 256, _cursorPalette);
	} else {
		_cursor->setPalette(0, 256, _gamePalette);
	}

	_cursor->setColorKey(_cursorKeyColor);
}

void OpenGLGraphicsManager::recalculateCursorScaling() {
	if (!_cursor || !_gameScreen) {
		return;
	}

	// By default we use the unscaled versions.
	_cursorHotspotXScaled = _cursorHotspotX;
	_cursorHotspotYScaled = _cursorHotspotY;
	_cursorWidthScaled = _cursor->getWidth();
	_cursorHeightScaled = _cursor->getHeight();

	// In case scaling is actually enabled we will scale the cursor according
	// to the game screen.
	if (!_cursorDontScale) {
		const frac_t screenScaleFactorX = intToFrac(_displayWidth)  / _gameScreen->getWidth();
		const frac_t screenScaleFactorY = intToFrac(_displayHeight) / _gameScreen->getHeight();

		_cursorHotspotXScaled = fracToInt(_cursorHotspotXScaled * screenScaleFactorX);
		_cursorWidthScaled    = fracToInt(_cursorWidthScaled    * screenScaleFactorX);

		_cursorHotspotYScaled = fracToInt(_cursorHotspotYScaled * screenScaleFactorY);
		_cursorHeightScaled   = fracToInt(_cursorHeightScaled   * screenScaleFactorY);
	}
}

#ifdef USE_OSD
const Graphics::Font *OpenGLGraphicsManager::getFontOSD() {
	return FontMan.getFontByUsage(Graphics::FontManager::kLocalizedFont);
}
#endif

void OpenGLGraphicsManager::saveScreenshot(const Common::String &filename) const {
	const uint width  = _outputScreenWidth;
	const uint height = _outputScreenHeight;

	// A line of a BMP image must have a size divisible by 4.
	// We calculate the padding bytes needed here.
	// Since we use a 3 byte per pixel mode, we can use width % 4 here, since
	// it is equal to 4 - (width * 3) % 4. (4 - (width * Bpp) % 4, is the
	// usual way of computing the padding bytes required).
	const uint linePaddingSize = width % 4;
	const uint lineSize        = width * 3 + linePaddingSize;

	// Allocate memory for screenshot
	uint8 *pixels = new uint8[lineSize * height];

	// Get pixel data from OpenGL buffer
	GL_CALL(glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels));

	// BMP stores as BGR. Since we can't assume that GL_BGR is supported we
	// will swap the components from the RGB we read to BGR on our own.
	for (uint y = height; y-- > 0;) {
		uint8 *line = pixels + y * lineSize;

		for (uint x = width; x > 0; --x, line += 3) {
			SWAP(line[0], line[2]);
		}
	}

	// Open file
	Common::DumpFile out;
	out.open(filename);

	// Write BMP header
	out.writeByte('B');
	out.writeByte('M');
	out.writeUint32LE(height * lineSize + 54);
	out.writeUint32LE(0);
	out.writeUint32LE(54);
	out.writeUint32LE(40);
	out.writeUint32LE(width);
	out.writeUint32LE(height);
	out.writeUint16LE(1);
	out.writeUint16LE(24);
	out.writeUint32LE(0);
	out.writeUint32LE(0);
	out.writeUint32LE(0);
	out.writeUint32LE(0);
	out.writeUint32LE(0);
	out.writeUint32LE(0);

	// Write pixel data to BMP
	out.write(pixels, lineSize * height);

	// Free allocated memory
	delete[] pixels;
}

} // End of namespace OpenGL
コード例 #26
0
void QtInputAdapter::onMouseMoveEvent(QMouseEvent * event)
{
    setMousePosition({event->pos().x(), event->pos().y()});
}
コード例 #27
0
ファイル: InputImpl.cpp プロジェクト: PKEuS/SFML
void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& relativeTo)
{
    setMousePosition(position);
}