Пример #1
0
void Module::onEvent(const SDL_Event & event)
{
	switch(event.type)
	{
	case SDL_KEYDOWN:
		onKeyDown(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode);
		break;
	case SDL_KEYUP:
		onKeyUp(event.key.keysym.sym, event.key.keysym.mod, event.key.keysym.unicode);
		break;
	case SDL_MOUSEMOTION:
		onMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel,
			event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT),
			event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT),
			event.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE));
		break;
	case SDL_JOYAXISMOTION:
		onJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
		break;
	case SDL_JOYBALLMOTION:
		onJoyBall(event.jball.which, event.jball.ball, event.jball.xrel, event.jball.yrel);
		break;
	case SDL_JOYHATMOTION:
		onJoyHat(event.jhat.which, event.jhat.hat, event.jhat.value);
		break;
	case SDL_JOYBUTTONDOWN:
		onJoyButtonDown(event.jbutton.which, event.jbutton.button);
		break;
	case SDL_JOYBUTTONUP:
		onJoyButtonUp(event.jbutton.which, event.jbutton.button);
		break;
	 case SDL_VIDEORESIZE:
	 	onResize(event.resize.w, event.resize.h);
	 	break;
		//case ...
		default:
		break;
	}
}
Пример #2
0
//METHODS
void Event::onEvent(SDL_Event* event) {
    switch(event->type) {
        case SDL_ACTIVEEVENT: {
            switch (event->active.state) {
                case SDL_APPMOUSEFOCUS: {
                    if (event->active.gain) onMouseFocus();
                    else onMouseBlur();
                    break;
                }
                case SDL_APPINPUTFOCUS: {
                    if (event->active.gain) onInputFocus();
                    else onInputBlur();
                    break;
                }
                case SDL_APPACTIVE: {
                    if (event->active.gain) onRestore();
                    else onMinimize();
                    break;
                }
            }
            break;
        }
        case SDL_KEYDOWN: {
            onKeyDown(event->key.keysym.sym, event->key.keysym.mod,
                event->key.keysym.unicode);
            break;
        }
        case SDL_KEYUP: {
            onKeyUp(event->key.keysym.sym, event->key.keysym.mod,
                event->key.keysym.unicode);
            break;
        }
        case SDL_MOUSEMOTION: {
            onMouseMove(event->motion.x, event->motion.y,
                event->motion.xrel, event->motion.yrel,
                (event->motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0,
                (event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0,
                (event->motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0);
            break;
        }
        case SDL_MOUSEBUTTONDOWN: {
            switch(event->button.button) {
                case SDL_BUTTON_LEFT: {
                    onLButtonDown(event->button.x, event->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    onRButtonDown(event->button.x, event->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    onMButtonDown(event->button.x, event->button.y);
                    break;
                }
            }
            break;
        }
        case SDL_MOUSEBUTTONUP: {
            switch(event->button.button) {
                case SDL_BUTTON_LEFT: {
                    onLButtonUp(event->button.x, event->button.y);
                    break;
                }
                case SDL_BUTTON_RIGHT: {
                    onRButtonUp(event->button.x, event->button.y);
                    break;
                }
                case SDL_BUTTON_MIDDLE: {
                    onMButtonUp(event->button.x, event->button.y);
                    break;
                }
            }
            break;
        }
        case SDL_JOYAXISMOTION: {
            onJoyAxis(event->jaxis.which, event->jaxis.axis,
                event->jaxis.value);
            break;
        }
        case SDL_JOYBALLMOTION: {
            onJoyBall(event->jball.which, event->jball.ball,
                event->jball.xrel, event->jball.yrel);
            break;
        }
        case SDL_JOYHATMOTION: {
            onJoyHat(event->jhat.which, event->jhat.hat,
                event->jhat.value);
            break;
        }
        case SDL_JOYBUTTONDOWN: {
            onJoyButtonDown(event->jbutton.which, event->jbutton.button);
            break;
        }
        case SDL_JOYBUTTONUP: {
            onJoyButtonUp(event->jbutton.which, event->jbutton.button);
            break;
        }
        case SDL_QUIT: {
            onExit();
            break;
        }
        case SDL_SYSWMEVENT: {
            //Ignore
            break;
        }
        case SDL_VIDEORESIZE: {
            onResize(event->resize.w, event->resize.h);
            break;
        }
        case SDL_VIDEOEXPOSE: {
            onExpose();
            break;
        }
        default: {
            onUser(event->user.type, event->user.code,
                event->user.data1, event->user.data2);
            break;
        }
    }
}
Пример #3
0
    /// event handlers
    void Module::onEvent(const SDL_Event& inEvent)
    {
        switch (inEvent.type)
        {
            case SDL_ACTIVEEVENT:
            {
                switch (inEvent.active.state)
                {
                    case SDL_APPMOUSEFOCUS:
                    {
                        if (inEvent.active.gain)
                            onMouseFocus();
                        else
                            onMouseBlur();

                        break;
                    }
                    case SDL_APPINPUTFOCUS:
                    {
                        if (inEvent.active.gain)
                            onInputFocus();
                        else
                            onInputBlur();

                        break;
                    }
                    case SDL_APPACTIVE:
                    {
                        if (inEvent.active.gain)
                            onRestore();
                        else
                            onMinimize();

                        break;
                    }
                }
                break;
            }

            case SDL_KEYDOWN:
            {
                onKeyDown(inEvent.key.keysym.sym, inEvent.key.keysym.mod,
                    inEvent.key.keysym.unicode);
                break;
            }

            case SDL_KEYUP:
            {
                onKeyUp(inEvent.key.keysym.sym, inEvent.key.keysym.mod,
                    inEvent.key.keysym.unicode);
                break;
            }

            case SDL_MOUSEMOTION:
            {
                onMouseMove(inEvent.motion.x, inEvent.motion.y,
                    inEvent.motion.xrel, inEvent.motion.yrel,
                    inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT),
                    inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT),
                    inEvent.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE));
                break;
            }

            case SDL_MOUSEBUTTONDOWN:
            {
                switch (inEvent.button.button)
                {
                    case SDL_BUTTON_LEFT:
                    {
                        onLButtonDown(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                    case SDL_BUTTON_RIGHT:
                    {
                        onRButtonDown(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                    case SDL_BUTTON_MIDDLE:
                    {
                        onMButtonDown(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                }
                break;
            }

            case SDL_MOUSEBUTTONUP:
            {
                switch (inEvent.button.button)
                {
                    case SDL_BUTTON_LEFT:
                    {
                        onLButtonUp(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                    case SDL_BUTTON_RIGHT:
                    {
                        onRButtonUp(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                    case SDL_BUTTON_MIDDLE:
                    {
                        onMButtonUp(inEvent.button.x, inEvent.button.y);
                        break;
                    }
                    case SDL_BUTTON_WHEELUP:
                    {
                        onMouseWheel(true, false);
                        break;
                    }
                    case SDL_BUTTON_WHEELDOWN:
                    {
                        onMouseWheel(false, true);
                        break;
                    }
                }
                break;
            }

            case SDL_JOYAXISMOTION:
            {
                onJoyAxis(inEvent.jaxis.which, inEvent.jaxis.axis,
                          inEvent.jaxis.value);
                break;
            }

            case SDL_JOYBALLMOTION:
            {
                onJoyBall(inEvent.jball.which, inEvent.jball.ball,
                          inEvent.jball.xrel, inEvent.jball.yrel);
                break;
            }

            case SDL_JOYHATMOTION:
            {
                onJoyHat(inEvent.jhat.which, inEvent.jhat.hat,
                         inEvent.jhat.value);
                break;
            }
            case SDL_JOYBUTTONDOWN:
            {
                onJoyButtonDown(inEvent.jbutton.which,
                    inEvent.jbutton.button);
                break;
            }

            case SDL_JOYBUTTONUP:
            {
                onJoyButtonUp(inEvent.jbutton.which, inEvent.jbutton.button);
                break;
            }

            case SDL_QUIT:
            {
                onExit();
                break;
            }

            case SDL_SYSWMEVENT:
            {
                break;
            }

            case SDL_VIDEORESIZE:
            {
                onResize(inEvent.resize.w, inEvent.resize.h);
                break;
            }

            case SDL_VIDEOEXPOSE:
            {
                onExpose();
                break;
            }

            default:
            {
                onUser(inEvent.user.type, inEvent.user.code,
                    inEvent.user.data1, inEvent.user.data2);
                break;
            }
        }
    }
Пример #4
0
void Event::onEvent(SDL_Event *event)
{
    switch (event->type)
    {
        case SDL_ACTIVEEVENT:
            switch (event->active.state)
            {
                case SDL_APPMOUSEFOCUS:
                    if (event->active.gain) {
                        onMouseFocus();
                    }
                    else {
                        onMouseBlur();
                    }
                    break;

                case SDL_APPINPUTFOCUS:
                    if (event->active.gain) {
                        onInputFocus();
                    }
                    else {
                        onInputBlur();
                    }
                    break;

                case SDL_APPACTIVE:
                    if (event->active.gain) {
                        onRestore();
                    }
                    else {
                        onMinimize();
                    }
                    break;
            }
        break; //SDL_ACTIVEEVENT

        case SDL_KEYDOWN:
            onKeyDown(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode);
            break;

        case SDL_KEYUP:
            onKeyUp(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode);
            break;

        case SDL_MOUSEBUTTONDOWN:
            onMouseDown(event->button.button, event->button.x, event->button.y);
            break;

        case SDL_MOUSEBUTTONUP:
            onMouseUp(event->button.button, event->button.x, event->button.y);
            break;

        case SDL_JOYAXISMOTION:
            onJoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value);
            break;

        case SDL_JOYBALLMOTION:
            onJoyBall(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel);
            break;

        case SDL_JOYHATMOTION:
            onJoyHat(event->jhat.which, event->jhat.hat, event->jhat.value);
            break;

        case SDL_JOYBUTTONDOWN:
            onJoyButtonDown(event->jbutton.which, event->jbutton.button);
            break;

        case SDL_JOYBUTTONUP:
            onJoyButtonUp(event->jbutton.which, event->jbutton.button);
            break;

        case SDL_QUIT:
            onQuit();
            break;

        case SDL_VIDEORESIZE:
            onResize(event->resize.w, event->resize.h);
            break;

        default:
            onUser(event->user.type, event->user.code, event->user.data1, event->user.data2);
            break;
    }
}