Beispiel #1
0
void Window::handleEvent(const SDL_Event &event)
{
    switch (event.type) {
        case SDL_QUIT:
            quit = true;
            break;
        case SDL_ACTIVEEVENT:
            (event.active.gain == 1) ? isActive = true : isActive = false;
            break;
        case SDL_VIDEORESIZE:
            resize(event.resize.w, event.resize.h);
            break;
        case SDL_MOUSEBUTTONDOWN:
            if (event.button.button == SDL_BUTTON_WHEELUP) {
                from->z() += 0.5f;
            } else if (event.button.button == SDL_BUTTON_WHEELDOWN) {
                from->z() -= 0.5f;
            }
            break;
        case SDL_MOUSEMOTION:
            break;
        case SDL_KEYDOWN:
            handleKeyDown(event.key.keysym);
            break;
        case SDL_KEYUP:
            handleKeyUp(event.key.keysym);
            break;
    }
    handleKeyCombo();
}
void WebEditorClient::handleKeyboardEvent(WebCore::KeyboardEvent* event)
{
    Node* node = event->target()->toNode();
    ASSERT(node);
    Frame* frame = node->document().frame();
    ASSERT(frame);

    // FIXME: Reorder the checks in a more sensible way.

    const PlatformKeyboardEvent* platformEvent = event->keyEvent();
    if (!platformEvent)
        return;

    // If this was an IME event don't do anything.
    if (platformEvent->windowsVirtualKeyCode() == VK_PROCESSKEY)
        return;

    // Don't allow text insertion for nodes that cannot edit.
    if (!frame->editor().canEdit())
        return;

    // This is just a normal text insertion, so wait to execute the insertion
    // until a keypress event happens. This will ensure that the insertion will not
    // be reflected in the contents of the field until the keyup DOM event.
    if (event->type() == eventNames().keypressEvent)
        return handleKeyPress(*frame, *event, *platformEvent);
    if (event->type() == eventNames().keydownEvent)
        return handleKeyDown(*frame, *event, *platformEvent);
}
Beispiel #3
0
void BladeRunnerEngine::handleEvents() {
	if (shouldQuit()) {
		_gameIsRunning = false;
		return;
	}

	Common::Event event;
	Common::EventManager *eventMan = _system->getEventManager();
	while (eventMan->pollEvent(event)) {
		switch (event.type) {
		case Common::EVENT_KEYUP:
			handleKeyUp(event);
			break;
		case Common::EVENT_KEYDOWN:
			handleKeyDown(event);
			break;
		case Common::EVENT_LBUTTONUP:
			handleMouseAction(event.mouse.x, event.mouse.y, true, false);
			break;
		case Common::EVENT_RBUTTONUP:
		case Common::EVENT_MBUTTONUP:
			handleMouseAction(event.mouse.x, event.mouse.y, false, false);
			break;
		case Common::EVENT_LBUTTONDOWN:
			handleMouseAction(event.mouse.x, event.mouse.y, true, true);
			break;
		case Common::EVENT_RBUTTONDOWN:
		case Common::EVENT_MBUTTONDOWN:
			handleMouseAction(event.mouse.x, event.mouse.y, false, true);
			break;
		default:
			; // nothing to do
		}
	}
}
void update_input()
{
    while (SDL_PollEvent(&event))
    {
        switch (event.type)
        {
            case SDL_KEYDOWN:
                handleKeyPress(&event.key.keysym);
                break;
            case SDL_MOUSEMOTION:
                handleMouseMove(&event.motion);
                break;
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                handleMousePress();
                break;
            case SDL_QUIT:
                done = TRUE;
                break;
            default:
                break;
        }
    }
    handleKeyDown();

    if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT))
        mouse_left();

    if(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))
        mouse_right();
}
Beispiel #5
0
bool OSystem_SDL::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
	switch (ev.type) {
	case SDL_KEYDOWN:
		return handleKeyDown(ev, event);
	case SDL_KEYUP:
		return handleKeyUp(ev, event);
	case SDL_MOUSEMOTION:
		return handleMouseMotion(ev, event);
	case SDL_MOUSEBUTTONDOWN:
		return handleMouseButtonDown(ev, event);
	case SDL_MOUSEBUTTONUP:
		return handleMouseButtonUp(ev, event);
	case SDL_JOYBUTTONDOWN:
		return handleJoyButtonDown(ev, event);
	case SDL_JOYBUTTONUP:
		return handleJoyButtonUp(ev, event);
	case SDL_JOYAXISMOTION:
		return handleJoyAxisMotion(ev, event);

	case SDL_VIDEOEXPOSE:
		//_forceFull = true;
		break;

	case SDL_QUIT:
		event.type = Common::EVENT_QUIT;
		return true;

	}
	
	return false;
}
Beispiel #6
0
void Journal::use() {
    BobSlot *joe = _vm->graphics()->bob(0);
    _prevJoeX = joe->x;
    _prevJoeY = joe->y;

    _panelMode = PM_NORMAL;
    _system = g_system;

    _panelTextCount = 0;
    memset(_panelTextY, 0, sizeof(_panelTextY));
    memset(&_textField, 0, sizeof(_textField));

    memset(_saveDescriptions, 0, sizeof(_saveDescriptions));
    _vm->findGameStateDescriptions(_saveDescriptions);

    setup();
    redraw();
    update();
    _vm->display()->palFadeIn(ROOM_JOURNAL);

    _quitMode = QM_LOOP;
    while (_quitMode == QM_LOOP) {
        Common::Event event;
        Common::EventManager *eventMan = _system->getEventManager();
        while (eventMan->pollEvent(event)) {
            switch (event.type) {
            case Common::EVENT_KEYDOWN:
                handleKeyDown(event.kbd.ascii, event.kbd.keycode);
                break;
            case Common::EVENT_LBUTTONDOWN:
                handleMouseDown(event.mouse.x, event.mouse.y);
                break;
            case Common::EVENT_WHEELUP:
                handleMouseWheel(-1);
                break;
            case Common::EVENT_WHEELDOWN:
                handleMouseWheel(1);
                break;
            case Common::EVENT_RTL:
            case Common::EVENT_QUIT:
                return;
            default:
                break;
            }
        }
        _system->delayMillis(20);
        _system->updateScreen();
    }

    _vm->writeOptionSettings();

    _vm->display()->clearTexts(0, GAME_SCREEN_HEIGHT - 1);
    _vm->graphics()->putCameraOnBob(0);
    if (_quitMode == QM_CONTINUE) {
        continueGame();
    }
}
bool CameraManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::FRAME):
        {
			return handleFrame(ea, us);
        }
        default:
            break;
    }

    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::PUSH):
        {
			return handlePush(ea, us);
        }
        case(osgGA::GUIEventAdapter::RELEASE):
        {
            return handleRelease(ea, us);
        }
        case(osgGA::GUIEventAdapter::DRAG):
        case(osgGA::GUIEventAdapter::SCROLL):
        {
			return handleScroll(ea, us);
        }
        case(osgGA::GUIEventAdapter::MOVE):
        {
            return false;
        }
		case(osgGA::GUIEventAdapter::KEYDOWN):
		{
			return handleKeyDown(ea, us);
		}
		case(osgGA::GUIEventAdapter::KEYUP):
		{
			return handleKeyUp( ea, us );
		}
        case(osgGA::GUIEventAdapter::FRAME):
		{
            if (_thrown)
            {
                if (calcMovement()) us.requestRedraw();
            }

            return false;
		}
        default:
            return false;
    }
}
/**
 *	This method handles key events for the global application.
 */
bool ApplicationInput::handleKeyEvent( const KeyEvent & event )
{
	bool handled = ConsoleManager::instance().handleKeyEvent( event );

	if (!handled && event.isKeyDown())
	{
		handled = handleKeyDown( event );
	}

	return handled;
}
Beispiel #9
0
void GenericCodeEditor::keyPressEvent(QKeyEvent * event)
{
    hideMouseCursor(event);

    QTextCursor cursor( textCursor() );

    bool updateCursor = false;

    if (event == QKeySequence::InsertLineSeparator) {
        // override to avoid entering a "soft" new line
        cursor.insertBlock();
        updateCursor = true;
    } else {
        switch (event->key()) {
        case Qt::Key_BraceRight:
        case Qt::Key_BracketRight:
        case Qt::Key_ParenRight:
            handleKeyRightParentheses( event, cursor );
            break;

        case Qt::Key_Delete:
            handleKeyDelete( event, cursor );
            break;

        case Qt::Key_Backspace:
            handleKeyBackspace( event, cursor, updateCursor );
            break;

        case Qt::Key_Down:
            handleKeyDown( event, cursor );
            break;

        case Qt::Key_Up:
            handleKeyUp( event, cursor );
            break;

        default:
            QPlainTextEdit::keyPressEvent(event);
        }
    }

    if (updateCursor) {
        cursor.setVerticalMovementX(-1);
        setTextCursor( cursor );
        ensureCursorVisible();
    }

    if (mDoc->keyDownActionEnabled() || Main::documentManager()->globalKeyDownActionEnabled())
        doKeyAction(event);
}
Beispiel #10
0
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
	switch (ev.type) {
	case SDL_KEYDOWN:
		return handleKeyDown(ev, event);
	case SDL_KEYUP:
		return handleKeyUp(ev, event);
	case SDL_MOUSEMOTION:
		return handleMouseMotion(ev, event);
	case SDL_MOUSEBUTTONDOWN:
		return handleMouseButtonDown(ev, event);
	case SDL_MOUSEBUTTONUP:
		return handleMouseButtonUp(ev, event);
	case SDL_JOYBUTTONDOWN:
		return handleJoyButtonDown(ev, event);
	case SDL_JOYBUTTONUP:
		return handleJoyButtonUp(ev, event);
	case SDL_JOYAXISMOTION:
		return handleJoyAxisMotion(ev, event);
	case SDL_JOYHATMOTION:
		return handleJoyHatMotion(ev, event);

	case SDL_VIDEOEXPOSE:
		if (_graphicsManager)
			_graphicsManager->notifyVideoExpose();
		return false;

	case SDL_VIDEORESIZE:
		if (_graphicsManager) {
			_graphicsManager->notifyResize(ev.resize.w, ev.resize.h);

			// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
			int screenID = ((OSystem_SDL *)g_system)->getGraphicsManager()->getScreenChangeID();
			if (screenID != _lastScreenID) {
				_lastScreenID = screenID;
				event.type = Common::EVENT_SCREEN_CHANGED;
				return true;
			}
		}
		return false;

	case SDL_QUIT:
		event.type = Common::EVENT_QUIT;
		return true;

	}

	return false;
}
Beispiel #11
0
static void processEvents()
{
	SDL_Event mEvent;
	while (SDL_PollEvent(&mEvent))
	{
		switch (mEvent.type)
		{
		case SDL_KEYDOWN:
			handleKeyDown(&mEvent.key.keysym);
			break;
		case SDL_QUIT:
			quit(0);
			break;
		}
	}
}
Beispiel #12
0
void TetrisState::handleInput(Tetris & tetris, SDL_Event e)
{
	switch (e.type) {
	case SDL_MOUSEBUTTONDOWN:
		handleMouseDown(tetris, e);
		break;
	case SDL_MOUSEBUTTONUP:
		handleMouseUp(tetris, e);
		break;
	case SDL_KEYDOWN:
		handleKeyDown(tetris, e);
		break;
	case SDL_KEYUP:
		handleKeyUp(tetris, e);
		break;
	default:
		break;
	}
}
Beispiel #13
0
void MenuSystem::handleEvents() {
	Common::Event event;
	Common::EventManager *eventMan = _vm->_system->getEventManager();
	while (eventMan->pollEvent(event)) {
		switch (event.type) {
		case Common::EVENT_KEYDOWN:
			handleKeyDown(event.kbd);
			break;
		case Common::EVENT_QUIT:
			_running = false;
			break;
		case Common::EVENT_MOUSEMOVE:
			handleMouseMove(event.mouse.x, event.mouse.y);
			break;
		case Common::EVENT_LBUTTONUP:
			handleMouseClick(event.mouse.x, event.mouse.y);
			break;
		default:
			break;
		}
	}
}
Beispiel #14
0
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
	switch (ev.type) {
	case SDL_KEYDOWN:
		return handleKeyDown(ev, event);
	case SDL_KEYUP:
		return handleKeyUp(ev, event);
	case SDL_MOUSEMOTION:
		return handleMouseMotion(ev, event);
	case SDL_MOUSEBUTTONDOWN:
		return handleMouseButtonDown(ev, event);
	case SDL_MOUSEBUTTONUP:
		return handleMouseButtonUp(ev, event);
	case SDL_JOYBUTTONDOWN:
		return handleJoyButtonDown(ev, event);
	case SDL_JOYBUTTONUP:
		return handleJoyButtonUp(ev, event);
	case SDL_JOYAXISMOTION:
		return handleJoyAxisMotion(ev, event);

	case SDL_VIDEOEXPOSE:
		if (_graphicsManager)
			_graphicsManager->notifyVideoExpose();
		return false;

	case SDL_VIDEORESIZE:
		if (_graphicsManager)
			_graphicsManager->notifyResize(ev.resize.w, ev.resize.h);
		return false;

	case SDL_QUIT:
		event.type = Common::EVENT_QUIT;
		return true;

	}

	return false;
}
Beispiel #15
0
void AvalancheEngine::updateEvents() {
	Common::Event event;

	while (_eventMan->pollEvent(event)) {
		switch (event.type) {
		case Common::EVENT_LBUTTONDOWN:
			_holdLeftMouse = true; // Used in checkclick() and Menu::menu_link().
			break;
		case Common::EVENT_LBUTTONUP:
			_holdLeftMouse = false; // Same as above.
			break;
		case Common::EVENT_KEYDOWN:
			if ((event.kbd.keycode == Common::KEYCODE_d) && (event.kbd.flags & Common::KBD_CTRL)) {
				// Attach to the debugger
				_console->attach();
				_console->onFrame();
			} else
				handleKeyDown(event);
			break;
		default:
			break;
		}
	}
}
Beispiel #16
0
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
	switch (ev.type) {
	case SDL_KEYDOWN:
		return handleKeyDown(ev, event);
	case SDL_KEYUP:
		return handleKeyUp(ev, event);
	case SDL_MOUSEMOTION:
		return handleMouseMotion(ev, event);
	case SDL_MOUSEBUTTONDOWN:
		return handleMouseButtonDown(ev, event);
	case SDL_MOUSEBUTTONUP:
		return handleMouseButtonUp(ev, event);
	case SDL_JOYBUTTONDOWN:
		return handleJoyButtonDown(ev, event);
	case SDL_JOYBUTTONUP:
		return handleJoyButtonUp(ev, event);
	case SDL_JOYAXISMOTION:
		return handleJoyAxisMotion(ev, event);

#if SDL_VERSION_ATLEAST(2, 0, 0)
	case SDL_MOUSEWHEEL: {
		Sint32 yDir = ev.wheel.y;
#if SDL_VERSION_ATLEAST(2, 0, 4)
		if (ev.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
			yDir *= -1;
		}
#endif
		// HACK: It seems we want the mouse coordinates supplied
		// with a mouse wheel event. However, SDL2 does not supply
		// these, thus we use whatever we got last time. It seems
		// these are always stored in _km.x, _km.y.
		processMouseEvent(event, _km.x, _km.y);
		if (yDir < 0) {
			event.type = Common::EVENT_WHEELDOWN;
			return true;
		} else if (yDir > 0) {
			event.type = Common::EVENT_WHEELUP;
			return true;
		} else {
			return false;
		}
		}

	case SDL_TEXTINPUT: {
		// When we get a TEXTINPUT event it means we got some user input for
		// which no KEYDOWN exists. SDL 1.2 introduces a "fake" key down+up
		// in such cases. We will do the same to mimic it's behavior.
		event.type = Common::EVENT_KEYDOWN;

		event.kbd = Common::KeyState(Common::KEYCODE_INVALID, convUTF8ToUTF32(ev.text.text), 0);

		SDLModToOSystemKeyFlags(SDL_GetModState(), event);
		// Set the scroll lock sticky flag
		if (_scrollLock)
			event.kbd.flags |= Common::KBD_SCRL;

		// Fake a key up when we have a proper ascii value.
		_queuedFakeKeyUp = (event.kbd.ascii != 0);
		_fakeKeyUp = event;
		_fakeKeyUp.type = Common::EVENT_KEYUP;

		return _queuedFakeKeyUp;
		}

	case SDL_WINDOWEVENT:
		switch (ev.window.event) {
		case SDL_WINDOWEVENT_EXPOSED:
			if (_graphicsManager)
				_graphicsManager->notifyVideoExpose();
			return false;

		case SDL_WINDOWEVENT_RESIZED:
			return handleResizeEvent(event, ev.window.data1, ev.window.data2);

		default:
			return false;
		}
#else
	case SDL_VIDEOEXPOSE:
		if (_graphicsManager)
			_graphicsManager->notifyVideoExpose();
		return false;

	case SDL_VIDEORESIZE:
		return handleResizeEvent(event, ev.resize.w, ev.resize.h);
#endif

	case SDL_QUIT:
		event.type = Common::EVENT_QUIT;
		return true;

	}

	return false;
}
Beispiel #17
0
// Called when the window needs to be redrawn.
void callbackDisplay()
{
	handleKeyDown();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	g_camera.update();
	g_shipCamera.update();

	GLuint fogFlag = glGetUniformLocation(g_program, "fogFlag");
	glUniform1i(fogFlag, 1);


	
	g_vessel->updateMovement();
	// Update movement of speed lines
	for (int i = 0; i < SPEED_LINE_COUNT; ++i) {
		if (speedLine[i]->m_position.z > 5.0f) {
			speedLine[i]->resetTranslation();
			speedLine[i]->resetPosition();
		}
		speedLine[i]->resetRotation();
		speedLine[i]->rotate(g_vessel->m_qRotation);
		vec3 linet = g_vessel->m_qRotation * vec3(0.0, 0.0, SPEED_LINE_SPEED);
		speedLine[i]->translate(linet.x, linet.y, linet.z);
	}	

	g_music->checkLoopTimer("starfox_theme.wav", MUSICGAIN);
	
	lightEffects le;
	le.numLights = LIGHTSOURCECOUNT + g_numLasers;
	le.ambientProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.diffuseProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.specularProducts = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.lightPositions = new vec4[le.numLights];//(vec4*)malloc(sizeof(vec4) * le.numLights);
	le.attenuations = new float[le.numLights];//(float*)malloc(sizeof(float) * le.numLights);
	 
	g_light = new Light[le.numLights];//(Light*)malloc(sizeof(Light) * le.numLights);

	g_light[0].m_position = vec3(0.0, 0.0, 0.0);
	g_light[0].m_lightAmbient = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_lightDiffuse = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_lightSpecular = vec4(1.0, 1.0, 1.0, 1.0);
	g_light[0].m_attenuation = 0.0000005;

	//g_light[1].m_position = tempShip->m_position;
	//g_light[1].m_lightAmbient = vec4(0.0, 0.0, 0.0, 1.0);
	//g_light[1].m_lightDiffuse = vec4(0.0, 0.6, 0.0, 1.0);
	//g_light[1].m_lightSpecular = vec4(0.0, 1.5, 0.0, 1.0);
	//g_light[1].m_attenuation = 0.0001;


	GLuint fogColor = glGetUniformLocation(g_program, "uFogColor");
	GLuint fogMinDist = glGetUniformLocation(g_program, "uFogMinDist");
	GLuint fogMaxDist = glGetUniformLocation(g_program, "uFogMaxDist");
	glUniform1f(fogMinDist, 1500.0f);
	glUniform1f(fogMaxDist, 1700.0f);
	glUniform4fv(fogColor, 1, vec4(0.0, 0.0, 0.0, 0.0));

	//tempShip->draw(g_drawType, g_camera, g_light, le);
	//tempShip->translate(-g_bulletV.x, -g_bulletV.y, -g_bulletV.z);

	int lightIndex = 1;
	for (int i = 0; i < MAX_LASERS; ++i) {
		if (g_lasers[i]->m_active) {
			g_light[lightIndex].m_position = g_lasers[i]->m_position;
			g_light[lightIndex].m_lightAmbient = vec4(0.0, 0.0, 0.0, 1.0);
			g_light[lightIndex].m_lightDiffuse = vec4(0.0, 0.6, 0.0, 1.0);
			g_light[lightIndex].m_lightSpecular = vec4(0.0, 1.5, 0.0, 1.0);
			g_light[lightIndex].m_attenuation = 0.001;
			++lightIndex;
			if (g_lasers[i]->dead()) {
				--g_numLasers;
				g_lasers[i]->kill();
			}
		}
	}

	for (int i = 0; i < MAX_LASERS; ++i) {
		if ((!g_lasers[i]->dead()) && g_lasers[i]->m_active) {
			g_lasers[i]->draw(g_drawType, g_camera, g_light, le);
			g_lasers[i]->laser_update();
		}
	}

	greenStar->draw(g_drawType, g_camera, g_light, le);
	if (g_vessel->m_shape->checkCollision(greenStar->m_shape)) {
		g_vessel->shake();
	}

	// Draw mama asteroid
	//gMamaAsteroid->draw(g_drawType, g_camera, g_light, le);
	//if (g_vessel->m_shape->checkCollision(gMamaAsteroid->m_shape)) {
	//	g_sound->playSound("ship_asteriod_impact.wav", 1.0, 1);
	//	std::cout << "BOOP3" << glutGet(GLUT_ELAPSED_TIME) <<  std::endl;
	//	g_vessel->shake();d
	//}

	// Draw all bloop asteroids
	for (int i = 0; i < BLOOPCOUNT; ++i) {
		if (asteroidAlive[i]) {
			bloop[i]->rotate(*(q[i % NUM_ASTEROID_ROTATIONS]));
			bloop[i]->draw(g_drawType, g_camera, g_light, le);
			if (g_vessel->m_shape->checkCollision(bloop[i]->m_shape)) {
				g_sound->playSound("ship_asteriod_impact.wav", 1.0, 1000);
				//asteroidAlive[i] = false;
				g_vessel->shake();
			}
			for (int j = 0; j < MAX_LASERS; ++j) {
				if (g_lasers[j]->m_active) {
					if (bloop[i]->m_shape->checkCollision(g_lasers[j]->m_shape)) {
						if (g_explosionIndex == 5)
							g_explosionIndex = 0;
						g_exp[g_explosionIndex]->playSound("ship_asteriod_impact.wav", 1.0, 500);
						//g_lasers[j]->kill();
						++g_explosionIndex;
						if (g_partExplodeIndex == MAXEXPLOSIONCOUNT)
							g_partExplodeIndex = 0;
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(bloop[i]->m_position.x, bloop[i]->m_position.y, bloop[i]->m_position.z);
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(2.0*bloop[i]->m_position.x, 1.155*-bloop[i]->m_position.y, 1.11*bloop[i]->m_position.z);
						g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(g_lasers[j]->m_position.x, -g_lasers[j]->m_position.y, g_lasers[j]->m_position.z);
						//g_explosion[g_partExplodeIndex]->getEngine()->createNewInstance(0.0, 0.0, -20.0);
						asteroidAlive[i] = false;
						g_partExplodeIndex++;
						g_score += 20;
					}	
				}
			}
		}
	}

	// Draw speed lines
	for (int i = 0; i < SPEED_LINE_COUNT; ++i) {
		speedLine[i]->draw(g_shipCamera, g_light, le);
	}
	glUniform1i(fogFlag, 0);
	starField->resetRotation();
	starField->rotate(g_camera.m_qRotation);
	starField->draw(g_drawType, g_shipCamera, g_light, le);
	glUniform1i(fogFlag, 1);

	// Draw the thrusters
	

	for (int i = 0; i < MAXEXPLOSIONCOUNT; i++) {
		g_explosion[i]->drawScene(&g_shipCamera,g_vessel->m_position);
	}

	vec3 pos = g_camera.m_position - g_camera.m_zAxis * 12.0f - g_camera.m_yAxis * 2.0f;
	//vec4 pos2 = Translate(0.0f, 1.0 * g_vessel->getVelocity().y / g_vessel->MAX_VELOCITY_Y, 0.0f) * pos;
	//pos = vec3(pos2.x, pos2.y, pos2.z);
	vec3 a = Quaternion(vec3(0.0f, -1.0f, 0.0f), 40.0f * (g_vessel->getVelocity().x / g_vessel->MAX_VELOCITY)) * vec3(0.0, 0.0, 1.0);
	vec3 b = Quaternion(vec3(1.0f, 0.0f, 0.0f), 50.0f * (g_vessel->getVelocity().y / g_vessel->MAX_VELOCITY_Y)) * vec3(0.0, 0.0, 1.0);
	vec4 ab = normalize(vec4(a.x + b.x, a.y + b.y, a.z + b.z, 0.0));
	vec3 ab1 = vec3(ab.x, ab.y, ab.z);
	if (g_shipAlive == 1) {
		xhair1->setPosition(-10 * (ab1));
		xhair2->setPosition(-100 * (ab1));
		glDisable(GL_DEPTH_TEST);
		xhair1->draw(MESH, g_shipCamera, g_light, le);
		xhair2->draw(MESH, g_shipCamera, g_light, le);
		glEnable(GL_DEPTH_TEST);
	}
	if (g_shipAlive == 1) {
		g_vessel->draw(g_drawType, g_shipCamera, g_light, le);
		thruster->drawScene(&g_shipCamera,g_vessel->m_position);
	}
	

	if (g_debug && g_shipAlive == 1) {
		glDisable(GL_DEPTH_TEST);
		g_menu->draw(g_drawType, g_shipCamera, g_light, le);
		debugDisplay();
		glEnable(GL_DEPTH_TEST);
	}

	glDisable(GL_DEPTH_TEST);
	g_shipExplosion->drawScene(&g_shipCamera,g_vessel->m_position);
	if (g_vessel->m_health == 10) {
		vec3 ff = vec3(10.4 * g_vessel->getVelocity().x / g_vessel->MAX_VELOCITY,0.0f, 0.0f);
		g_shipExplosion->getEngine()->createNewInstance(-ff.x, 10.0, -50.0);
		//g_vessel->shake();
	}
	glEnable(GL_DEPTH_TEST);

	if (g_vessel->m_health == 0) {
		g_shipAlive = 0;
	}

	delete [] le.ambientProducts;
	delete [] le.diffuseProducts;
	delete [] le.specularProducts;
	delete [] le.lightPositions;
	delete [] le.attenuations;
	delete [] g_light;

	std::cout << g_vessel->m_health << std::endl;
	calculateFPS();
	glutSwapBuffers();
}
pp_int32 PatternEditorControl::dispatchEvent(PPEvent* event)
{ 
	if (pattern == NULL)
		return -1;

	if (eventListener == NULL)
		return -1;

	switch (event->getID())
	{
		case eFocusGained:
		case eFocusGainedNoRepaint:
		{	
			hasFocus = true;
			if (menuInvokeChannel != -1)
			{
				lastMenuInvokeChannel = menuInvokeChannel;
				menuInvokeChannel = -1;
				//parentScreen->paintControl(this);			
			}
			
			if (event->getID() == eFocusGained)
				parentScreen->paintControl(this);			
			
			//resetKeyModifier();
			goto leave;
		}

		case eFocusLost:
		{	
			hasFocus = false;	
			parentScreen->paintControl(this);			
			//resetKeyModifier();
			goto leave;
		}

		case eFocusLostNoRepaint:
		{	
			hasFocus = false;
			//resetKeyModifier();
			goto leave;
		}

		case eMouseWheelMoved:
		{
			TMouseWheelEventParams* params = (TMouseWheelEventParams*)event->getDataPtr();
			
			// Vertical scrolling takes priority over horizontal scrolling and is mutually
			// exclusive from horizontal scrolling.
			if (params->deltaY)
			{
				PPEvent e = params->deltaY < 0 ? PPEvent(eBarScrollDown) : PPEvent(eBarScrollUp);
				handleEvent(reinterpret_cast<PPObject*>(vLeftScrollbar), &e);
			}
			
			else if (params->deltaX)
			{
				PPEvent e = params->deltaX > 0 ? PPEvent(eBarScrollDown) : PPEvent(eBarScrollUp);
				handleEvent(reinterpret_cast<PPObject*>(hBottomScrollbar), &e);
			}
			
			event->cancel();
			
			break;
		}

		case eRMouseDown:
		{			
			PPPoint* p = (PPPoint*)event->getDataPtr();

			if (hTopScrollbar->hit(*p))
			{
				if (controlCaughtByLMouseButton)
					break;
				controlCaughtByRMouseButton = true;
				caughtControl = hTopScrollbar;
				caughtControl->dispatchEvent(event);
			}
			else if (hBottomScrollbar->hit(*p))
			{
				if (controlCaughtByLMouseButton)
					break;
				controlCaughtByRMouseButton = true;
				caughtControl = hBottomScrollbar;
				caughtControl->dispatchEvent(event);
			}
			// Clicked on vertical scrollbar -> route event to scrollbar and catch scrollbar control
			else if (vLeftScrollbar->hit(*p))
			{
				if (controlCaughtByLMouseButton)
					break;
				controlCaughtByRMouseButton = true;
				caughtControl = vLeftScrollbar;
				caughtControl->dispatchEvent(event);				
			}
			else if (vRightScrollbar->hit(*p))
			{
				if (controlCaughtByLMouseButton)
					break;
				controlCaughtByRMouseButton = true;
				caughtControl = vRightScrollbar;
				caughtControl->dispatchEvent(event);				
			}
			else 
			{
				RMouseDownInChannelHeading = -1;
				lastAction = RMouseDownActionFirstRClick;

				PPPoint cp = *p;
				
				cp.x-=location.x + SCROLLBARWIDTH + getRowCountWidth() + 4;
				cp.y-=location.y + SCROLLBARWIDTH + font->getCharHeight() + 4;
				
				if (cp.x < 0)
					break;

				// right click on channel number
				if ((RMouseDownInChannelHeading = pointInChannelHeading(cp)) != -1)
				{
					goto leave;
				}
				else if (cp.y < 0) break;

				pp_int32 i = (cp.x / slotSize) + startPos;
				if (i < 0 || i > patternEditor->getNumChannels()-1)
					break;

				invokeMenu(i, *p);
			}
			
			goto leave;
		}

		case eRMouseUp:
		{
			controlCaughtByRMouseButton = false;
			if (caughtControl && !controlCaughtByLMouseButton && !controlCaughtByRMouseButton)
			{
				caughtControl->dispatchEvent(event);
				caughtControl = NULL;			
				break;
			}

			PPPoint cp = *((PPPoint*)event->getDataPtr());
			
			cp.x-=location.x + SCROLLBARWIDTH + getRowCountWidth() + 4;
			cp.y-=location.y + SCROLLBARWIDTH + font->getCharHeight() + 4;
			
			if (cp.x < 0 || RMouseDownInChannelHeading == -1)
				break;
			
			// right click on channel number
			if ((menuInvokeChannel = pointInChannelHeading(cp)) != -1 && 
				menuInvokeChannel == RMouseDownInChannelHeading &&
				lastAction == RMouseDownActionFirstRClick)
			{
				RMouseDownInChannelHeading = -1;
				parentScreen->paintControl(this);
				executeMenuCommand(MenuCommandIDMuteChannel);
				menuInvokeChannel = lastMenuInvokeChannel = -1;
				parentScreen->paintControl(this);
				goto leave;
			}
			RMouseDownInChannelHeading = -1;
			menuInvokeChannel = -1;
			parentScreen->paintControl(this);

			break;
		}

		case eLMouseDown:
		{
			hasDragged = false;

			PPPoint* p = (PPPoint*)event->getDataPtr();

			// Clicked on horizontal scrollbar -> route event to scrollbar and catch scrollbar control
			if (hTopScrollbar->hit(*p))
			{
				if (controlCaughtByRMouseButton)
					break;
				controlCaughtByLMouseButton = true;
				caughtControl = hTopScrollbar;
				caughtControl->dispatchEvent(event);
			}
			else if (hBottomScrollbar->hit(*p))
			{
				if (controlCaughtByRMouseButton)
					break;
				controlCaughtByLMouseButton = true;
				caughtControl = hBottomScrollbar;
				caughtControl->dispatchEvent(event);
			}
			// Clicked on vertical scrollbar -> route event to scrollbar and catch scrollbar control
			else if (vLeftScrollbar->hit(*p))
			{
				if (controlCaughtByRMouseButton)
					break;
				controlCaughtByLMouseButton = true;
				caughtControl = vLeftScrollbar;
				caughtControl->dispatchEvent(event);				
			}
			else if (vRightScrollbar->hit(*p))
			{
				if (controlCaughtByRMouseButton)
					break;
				controlCaughtByLMouseButton = true;
				caughtControl = vRightScrollbar;
				caughtControl->dispatchEvent(event);				
			}
			// Clicked in client area
			else
			{
				PPPoint cp = *p;
				
				cp.x-=location.x + SCROLLBARWIDTH + getRowCountWidth() + 4;
				cp.y-=location.y + SCROLLBARWIDTH + font->getCharHeight() + 4;
				
				if (cp.y <  -((pp_int32)font->getCharHeight() + 6))
					break;

				if (cp.x < -(getRowCountWidth() + 4))
					break;
				
				// select new row by clicking on row number
				if (cp.x < -3)
				{			
					pp_int32 newStartIndex = cp.y / font->getCharHeight();					
					pp_int32 newStartPos = cp.x / slotSize;
					
					pp_int32 visibleRows = (visibleHeight) / font->getCharHeight();
					pp_int32 visibleChannels = (visibleWidth) / slotSize;
					
					// copy of current selection
					patternEditor->getSelection().backup();
					
					preCursor = patternEditor->getCursor();
					
					if (newStartIndex < visibleRows && newStartIndex >= 0)
					{
						if (newStartIndex + startIndex < 0)
							break;
						
						preCursor.row = newStartIndex + startIndex;
					}
					
					ppreCursor = &preCursor;
					break;
				}
				else if (cp.x < 0)
				{
					break;
				}

				pp_int32 i;
				if ((i = pointInChannelHeading(cp)) != -1)
				{
				
					// Special commands
					// Right button is pressed and left button is pressed
					if (::getKeyModifier() & KeyModifierALT)
					{
						RMouseDownInChannelHeading = i;
						lastAction = RMouseDownActionSecondLClick;
					}
					
					if (RMouseDownInChannelHeading == i)
					{
						if (lastAction == RMouseDownActionFirstRClick ||
							lastAction == RMouseDownActionSecondLClick)
						{
							if (isSoloChannel(i))
								goto unmuteAll;
							menuInvokeChannel = i;
							executeMenuCommand(MenuCommandIDSoloChannel);
							parentScreen->paintControl(this);
							lastAction = RMouseDownActionFirstLClick;
							hasDragged = true;
							goto leave;
						}
						else if (lastAction == RMouseDownActionFirstLClick)
						{
unmuteAll:
							menuInvokeChannel = i;
							executeMenuCommand(MenuCommandIDUnmuteAll);
							parentScreen->paintControl(this);
							lastAction = RMouseDownActionSecondLClick;
							hasDragged = true;
							goto leave;
						}
					}
				
					if (i == lastMenuInvokeChannel)
					{
						lastMenuInvokeChannel = -1;
						goto leave;
					}
				
					// show menu
					pp_int32 menuPosY = location.y + SCROLLBARWIDTH + 1 + font->getCharHeight();
					pp_int32 menuPosX = location.x + SCROLLBARWIDTH + getRowCountWidth() + 4 + slotSize * (i - startPos);
				
					PPPoint p2(menuPosX, menuPosY);

					invokeMenu(i, p2);
					goto leave;					
				}
				else if (cp.y < 0) break;

				pp_int32 newStartIndex = cp.y / font->getCharHeight();

				pp_int32 newStartPos = cp.x / slotSize;
				
				pp_int32 visibleRows = (visibleHeight) / font->getCharHeight();
				pp_int32 visibleChannels = (visibleWidth) / slotSize;
				
				// copy of current selection
				patternEditor->getSelection().backup();
				
				// If we're pressing the shift key start selection 
				// at current cursor position
				if (::getKeyModifier() & selectionKeyModifier)
				{
					if (patternEditor->getSelection().start.isValid())
						patternEditor->getSelection().end = patternEditor->getCursor();
					else
						patternEditor->getSelection().start = patternEditor->getCursor();
				}

				preCursor = patternEditor->getCursor();

				if (newStartIndex < visibleRows && newStartIndex >= 0)
				{
					if (newStartIndex + startIndex < 0)
						break;

					preCursor.row = newStartIndex + startIndex;
				}

				if (newStartPos < visibleHeight && newStartPos >= 0)
				{
					selectionTicker = 0;
					startSelection = true;

					if (newStartPos + startPos < 0)
						break;

					preCursor.channel = newStartPos + startPos;
				
					if (preCursor.channel >= patternEditor->getNumChannels())
						break;
				
					// start selecting row
					if (!(::getKeyModifier() & selectionKeyModifier))
					{
						patternEditor->getSelection().start.channel = patternEditor->getSelection().end.channel = preCursor.channel;
						patternEditor->getSelection().start.row = patternEditor->getSelection().end.row = preCursor.row;
					}
					else
					{
						patternEditor->getSelection().end.channel = preCursor.channel;
						patternEditor->getSelection().end.row = preCursor.row;
					}

					pp_int32 innerPos = cp.x % slotSize;

					preCursor.inner = 0;
					if (!(::getKeyModifier() & selectionKeyModifier))
						patternEditor->getSelection().start.inner = 0;
					patternEditor->getSelection().end.inner = 0;
					for (pp_uint32 i = 0; i < sizeof(cursorPositions) - 1; i++)
					{
						if (innerPos >= cursorPositions[i] &&
							innerPos < cursorPositions[i+1])
						{
							preCursor.inner = i;
							if (!(::getKeyModifier() & selectionKeyModifier))
								patternEditor->getSelection().start.inner = i;
							patternEditor->getSelection().end.inner = i;
							break;
						}
					}
				}

				ppreCursor = &preCursor;

				//parentScreen->paintControl(this);
			}

			break;
		}

		case eLMouseUp:
			controlCaughtByLMouseButton = false;
			if (caughtControl && !controlCaughtByLMouseButton && !controlCaughtByRMouseButton)
			{
				caughtControl->dispatchEvent(event);
				caughtControl = NULL;			
				break;
			}
			
			menuInvokeChannel = -1;

			if (!hasDragged && !(::getKeyModifier() & selectionKeyModifier) && ppreCursor)
			{
				if (properties.clickToCursor)
				{
					patternEditor->setCursor(*ppreCursor);
			
					notifyUpdate(AdvanceCodeSelectNewRow);
					
					switch (properties.scrollMode)
					{
						case ScrollModeToCenter:
						case ScrollModeStayInCenter:
							assureCursorVisible();
							break;
						case ScrollModeToEnd:
							break;
					}
				}
				
				patternEditor->resetSelection();
			}
			
			parentScreen->paintControl(this);

			startSelection = false;
			ppreCursor = NULL;

			break;

		case eLMouseDrag:
		{
			if (caughtControl && controlCaughtByLMouseButton)
			{
				caughtControl->dispatchEvent(event);
				break;
			}			
			
			if (!startSelection)
				break;
			
			hasDragged = true;

			goto markSelection;
			//break;
		}

		case eRMouseDrag:
		{
			if (caughtControl && controlCaughtByRMouseButton)
				caughtControl->dispatchEvent(event);

			break;
		}
		
		case eRMouseRepeat:
		{
			if (caughtControl && controlCaughtByRMouseButton)
				caughtControl->dispatchEvent(event);

			break;
		}

		case eLMouseRepeat:
		{
			if (caughtControl && controlCaughtByLMouseButton)
			{
				caughtControl->dispatchEvent(event);
				break;
			}		

			// for slowing down mouse pressed events
			selectionTicker++;

			if (selectionTicker&1)
				break;
			
			// no selection has been made or mouse hasn't been dragged
			if (!startSelection || !hasDragged)
			{
				// mouse hasn't been dragged and selection ticker has reached threshold value
				if (!hasDragged && selectionTicker > 0)
				{
					// get point
					PPPoint* p = (PPPoint*)event->getDataPtr();
					
					// make sure scrollbars weren't pressed
					if (!hTopScrollbar->hit(*p) &&
						!hBottomScrollbar->hit(*p) &&
						!vLeftScrollbar->hit(*p) &&
						!vRightScrollbar->hit(*p))
					{
						// translate into local coordinate system
						PPPoint cp = *p;
						
						cp.x-=location.x + SCROLLBARWIDTH + getRowCountWidth() + 4;
						cp.y-=location.y + SCROLLBARWIDTH + font->getCharHeight() + 4;
						
						// not in our local CS
						if (cp.x < 0 || cp.y < 0)
							break;
						
						// valid channel?
						pp_int32 i = (cp.x / slotSize) + startPos;
						if (i < 0 || i > patternEditor->getNumChannels()-1)
							break;

						// restore last selection
						// will be made when mouse left mouse button is pressed
						if (patternEditor->getSelection().isCopyValid())
						{
							patternEditor->getSelection().restore();
						}
						
						// No more cursor positioning
						ppreCursor = NULL;
						
						invokeMenu(i, *p);
						// we're finished with event handling here
						goto leave;
					}
				}
				break;
			}

markSelection:
			PPPoint cp = *((PPPoint*)event->getDataPtr());

			PPPoint cp2 = cp;

			cp.x-=location.x + SCROLLBARWIDTH + getRowCountWidth() + 4;
			cp.y-=location.y + SCROLLBARWIDTH + font->getCharHeight() + 4;
			
			cp2.x-=location.x;
			cp2.y-=location.y;

			if (cp2.x > size.width - SCROLLBARWIDTH /*- (slotSize>>1)*/)
			{
				if (startPos + (visibleWidth / slotSize) < patternEditor->getNumChannels())
					startPos++;
			}
			else if (cp2.x < SCROLLBARWIDTH + (signed)getRowCountWidth() + 4)
			{
				if (startPos > 0)
					startPos--;
			}
	
			if (cp2.y > size.height - SCROLLBARWIDTH /*- ((signed)font->getCharHeight()*3)*/)
			{
				if (properties.scrollMode != ScrollModeStayInCenter)
				{
					if (startIndex + (visibleHeight / font->getCharHeight()) < pattern->rows)
						startIndex++;
				}
				else
				{
					scrollCursorDown();
					assureCursorVisible(true, false);
				}
			}
			else if (cp2.y < SCROLLBARWIDTH + ((signed)font->getCharHeight()*4 /*+ 4*/))
			{
				if (properties.scrollMode != ScrollModeStayInCenter)
				{
					if (startIndex > 0)
						startIndex--;
				}
				else
				{
					scrollCursorUp();
					assureCursorVisible(true, false);
				}
			}

			if (cp.x < 0)
			{
				cp.x = 0;
				//goto leave;
			}

			if (cp.y < 0)
			{
				cp.y = 0;
				//goto leave;
			}

			pp_int32 newStartIndex = cp.y / font->getCharHeight();
			
			pp_int32 newStartPos = cp.x / slotSize;
			
			pp_int32 visibleRows = (visibleHeight) / font->getCharHeight();
			pp_int32 visibleChannels = (visibleWidth) / slotSize;
			
			//if (newStartIndex < visibleRows && 
			//	newStartPos < visibleChannels)
			//{
				mp_sint32 cursorPositionRow = newStartIndex + startIndex;				
				mp_sint32 cursorPositionChannel = newStartPos + startPos;

				if (cursorPositionRow < 0) cursorPositionRow = 0;
				if (cursorPositionChannel < 0) cursorPositionChannel = 0;

				//if (cursorPositionRow < 0 || cursorPositionChannel < 0) 
				//	break;

				if (cursorPositionChannel >= patternEditor->getNumChannels())
				{
					patternEditor->getSelection().end.channel = patternEditor->getNumChannels()-1;
					patternEditor->getSelection().end.inner = 7;
				}
				else
				{
					
					// start selecting row
					patternEditor->getSelection().end.channel = cursorPositionChannel;
					patternEditor->getSelection().end.row = cursorPositionRow;			
					
					pp_int32 innerPos = cp.x % slotSize;
					
					//selectionEnd.inner = 7;
					for (pp_uint32 i = 0; i < sizeof(cursorPositions) - 1; i++)
					{
						if (innerPos >= cursorPositions[i] &&
							innerPos < cursorPositions[i+1])
						{
							patternEditor->getSelection().end.inner = i;
							break;
						}
					}
				}
				
				setScrollbarPositions(startIndex, startPos);
				
			//}
			
			parentScreen->paintControl(this);

			break;
		}

		case eKeyDown:
		{	
			//assureCursorVisible();
			
			pp_uint16 keyCode = *((pp_uint16*)event->getDataPtr());
			pp_uint16 scanCode = *(((pp_uint16*)event->getDataPtr())+1);
			pp_uint16 character = *(((pp_uint16*)event->getDataPtr())+2);

			assureCursor = true;
			assureUpdate = false;

			bool keyboadStartSelectionFlipped = false;
			// start selection
			if (keyCode == VK_LEFT ||
				keyCode == VK_RIGHT ||
				keyCode == VK_UP ||
				keyCode == VK_DOWN ||
				keyCode == VK_PRIOR ||
				keyCode == VK_NEXT ||
				keyCode == VK_HOME ||
				keyCode == VK_END ||
				keyCode == VK_TAB)
			{
				if ((::getKeyModifier() == (unsigned)selectionKeyModifier) && keyboardStartSelection)
				{
					patternEditor->getSelection().start = patternEditor->getSelection().end = patternEditor->getCursor();
					keyboardStartSelection = false;
					if (keyCode == VK_LEFT ||
						keyCode == VK_RIGHT ||
						keyCode == VK_UP ||
						keyCode == VK_DOWN)
					{
						keyboadStartSelectionFlipped = true;
					}
				}
			}

			switch (keyCode)
			{
				// store key modifiers
				case VK_ALT:
					assureCursor = false;
					if (selectionKeyModifier & KeyModifierALT)
						keyboardStartSelection = true;
					break;
				case VK_SHIFT:
					assureCursor = false;
					if (selectionKeyModifier & KeyModifierSHIFT)
						keyboardStartSelection = true;
					break;
				case VK_CONTROL:
					assureCursor = false;
					if (selectionKeyModifier & KeyModifierCTRL)
						keyboardStartSelection = true;
					break;
			
				default:
				{
					bool res = executeBinding(scanCodeBindings, scanCode);

					if (!res)
						res = executeBinding(eventKeyDownBindings, keyCode);
					
					if (!res)
						handleKeyDown(keyCode, scanCode, character);
					
					break;
				}
			}
			
			// normal selection
			if (keyCode == VK_LEFT ||
				keyCode == VK_RIGHT ||
				keyCode == VK_UP ||
				keyCode == VK_DOWN ||
				keyCode == VK_PRIOR ||
				keyCode == VK_NEXT ||
				keyCode == VK_HOME ||
				keyCode == VK_END ||
				keyCode == VK_TAB)
			{
				if ((::getKeyModifier() == (unsigned)selectionKeyModifier) && 
					!keyboardStartSelection && 
					!keyboadStartSelectionFlipped)
				{
					patternEditor->getSelection().end = patternEditor->getCursor();
				}
				else if (::getKeyModifier() == (KeyModifierALT|KeyModifierSHIFT) &&
						 patternEditor->getSelection().start.isValid())
				{
					patternEditor->getSelection().end = patternEditor->getCursor();
				}
			}						
												
			if (assureCursor)
			{
				assureCursorVisible();
				parentScreen->paintControl(this);
			}
			else if (assureUpdate)
			{
				parentScreen->paintControl(this);
			}

			break;
		}

		case eKeyChar:
		{
			assureUpdate = false;

			pp_uint8 character = *((pp_uint8*)event->getDataPtr());

			handleKeyChar(character);

			if (assureUpdate)
				parentScreen->paintControl(this);

			break;
		}

		case eKeyUp:
		{	
			pp_uint16 keyCode = *((pp_uint16*)event->getDataPtr());

			switch (keyCode)
			{
				case VK_SHIFT:
					if (selectionKeyModifier & KeyModifierSHIFT)
						keyboardStartSelection = false;					
					break;
				case VK_ALT:
					if (selectionKeyModifier & KeyModifierALT)
						keyboardStartSelection = false;					
					break;
				case VK_CONTROL:
					if (selectionKeyModifier & KeyModifierCTRL)
						keyboardStartSelection = false;					
					break;
			}
			break;
		}

		default:
			if (caughtControl == NULL)
				break;

			caughtControl->dispatchEvent(event);
			goto leave;
		
	}

leave:
	return 0;
}
Beispiel #19
0
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
	switch (ev.type) {
	case SDL_KEYDOWN:
		return handleKeyDown(ev, event);
	case SDL_KEYUP:
		return handleKeyUp(ev, event);
	case SDL_MOUSEMOTION:
		return handleMouseMotion(ev, event);
	case SDL_MOUSEBUTTONDOWN:
		return handleMouseButtonDown(ev, event);
	case SDL_MOUSEBUTTONUP:
		return handleMouseButtonUp(ev, event);
	case SDL_JOYBUTTONDOWN:
		return handleJoyButtonDown(ev, event);
	case SDL_JOYBUTTONUP:
		return handleJoyButtonUp(ev, event);
	case SDL_JOYAXISMOTION:
		return handleJoyAxisMotion(ev, event);

#if SDL_VERSION_ATLEAST(2, 0, 0)
	case SDL_MOUSEWHEEL: {
		Sint32 yDir = ev.wheel.y;
		// HACK: It seems we want the mouse coordinates supplied
		// with a mouse wheel event. However, SDL2 does not supply
		// these, thus we use whatever we got last time. It seems
		// these are always stored in _km.x, _km.y.
		if (!processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER)) {
			return false;
		}
		if (yDir < 0) {
			event.type = Common::EVENT_WHEELDOWN;
			return true;
		} else if (yDir > 0) {
			event.type = Common::EVENT_WHEELUP;
			return true;
		} else {
			return false;
		}
		}

	case SDL_TEXTINPUT: {
		// When we get a TEXTINPUT event it means we got some user input for
		// which no KEYDOWN exists. SDL 1.2 introduces a "fake" key down+up
		// in such cases. We will do the same to mimic it's behavior.
		event.type = Common::EVENT_KEYDOWN;

		event.kbd = Common::KeyState(Common::KEYCODE_INVALID, convUTF8ToUTF32(ev.text.text), 0);

		SDLModToOSystemKeyFlags(SDL_GetModState(), event);
		// Set the scroll lock sticky flag
		if (_scrollLock)
			event.kbd.flags |= Common::KBD_SCRL;

		// Fake a key up when we have a proper ascii value.
		_queuedFakeKeyUp = (event.kbd.ascii != 0);
		_fakeKeyUp = event;
		_fakeKeyUp.type = Common::EVENT_KEYUP;

		return _queuedFakeKeyUp;
		}

	case SDL_WINDOWEVENT:
		switch (ev.window.event) {
		case SDL_WINDOWEVENT_EXPOSED:
			if (_graphicsManager)
				_graphicsManager->notifyVideoExpose();
			return false;

		// SDL2 documentation indicate that SDL_WINDOWEVENT_SIZE_CHANGED is sent either as a result
		// of the size being changed by an external event (for example the user resizing the window
		// or going fullscreen) or a call to the SDL API (for example SDL_SetWindowSize). On the
		// other hand SDL_WINDOWEVENT_RESIZED is only sent for resize resulting from an external event,
		// and is always preceded by a SDL_WINDOWEVENT_SIZE_CHANGED event.
		// We need to handle the programmatic resize as well so that the graphics manager always know
		// the current size. See comments in SdlWindow::createOrUpdateWindow for details of one case
		// where we need to call SDL_SetWindowSize and we need the resulting event to be processed.
		// However if the documentation is correct we can ignore SDL_WINDOWEVENT_RESIZED since when we
		// get one we should always get a SDL_WINDOWEVENT_SIZE_CHANGED as well.
		case SDL_WINDOWEVENT_SIZE_CHANGED:
		//case SDL_WINDOWEVENT_RESIZED:
			return handleResizeEvent(event, ev.window.data1, ev.window.data2);

		default:
			return false;
		}
#else
	case SDL_VIDEOEXPOSE:
		if (_graphicsManager)
			_graphicsManager->notifyVideoExpose();
		return false;

	case SDL_VIDEORESIZE:
		return handleResizeEvent(event, ev.resize.w, ev.resize.h);
#endif

	case SDL_QUIT:
		event.type = Common::EVENT_QUIT;
		return true;

	}

	return false;
}
/** Handles events. Returns true if handled, false otherwise.*/
bool OrbitCameraManipulator::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
	switch( ea.getEventType() )
	{

	case osgGA::GUIEventAdapter::FRAME:
		return handleFrame( ea, aa );

	case osgGA::GUIEventAdapter::RESIZE:
		return handleResize( ea, aa );

	default:
		break;
	}

	if( ea.getHandled() )
	{
		return false;
	}

	computeRayPointer( ea, aa );

	bool handled = false;
	switch( ea.getEventType() )
	{
	case osgGA::GUIEventAdapter::MOVE:
		handled = handleMouseMove( ea, aa );
		break;

	case osgGA::GUIEventAdapter::DRAG:
		handled = handleMouseDrag( ea, aa );
		break;

	case osgGA::GUIEventAdapter::PUSH:
		handled = handleMousePush( ea, aa );
		break;

	case osgGA::GUIEventAdapter::RELEASE:
		handled = handleMouseRelease( ea, aa );
		break;

	case osgGA::GUIEventAdapter::KEYDOWN:
		handled = handleKeyDown( ea, aa );
		break;

	case osgGA::GUIEventAdapter::KEYUP:
		m_control_key_down = false;
		handled = handleKeyUp( ea, aa );
		break;

	case osgGA::GUIEventAdapter::SCROLL:
		if( _flags & PROCESS_MOUSE_WHEEL )
			handled = handleMouseWheel( ea, aa );
		else
			handled = false;
		break;

	default:
		handled = false;
	}

	return handled;
}