Esempio n. 1
0
int processSdlEvents(void) {
    SDL_Event event;

    resetEvents();
    while (SDL_PollEvent(&event)) {
        switch(event.type) {
        case SDL_KEYDOWN:
            switch(event.key.keysym.sym) {
            case SDLK_ESCAPE:
                return 1;
                break;
            default:
                keyboardEvent(&event.key,1);
                break;
            }
            break;
        case SDL_KEYUP:
            keyboardEvent(&event.key,0);
            break;
        case SDL_MOUSEMOTION:
            mouseMovedEvent(event.motion.x,event.motion.y,
                       event.motion.xrel,event.motion.yrel);
            break;
        case SDL_MOUSEBUTTONDOWN:
            mouseButtonEvent(event.button.button,1);
            break;
        case SDL_MOUSEBUTTONUP:
            mouseButtonEvent(event.button.button,0);
            break;
        case SDL_QUIT:
            exit(0);
            break;
        }
        /* If the next event to process is of type KEYUP or
         * MOUSEBUTTONUP we want to stop processing here, so that
         * a fast up/down event be noticed by Lua. */
        if (SDL_PeepEvents(&event,1,SDL_PEEKEVENT,SDL_ALLEVENTS)) {
            if (event.type == SDL_KEYUP ||
                event.type == SDL_MOUSEBUTTONUP)
                break; /* Go to lua before processing more. */
        }
    }

    /* Call the setup function, only the first time. */
    if (l81.epoch == 0) {
        setup();
        if (l81.luaerr) return l81.luaerr;
    }
    /* Call the draw function at every iteration.  */
    draw();
    l81.epoch++;
    /* Refresh the screen */
    if (l81.opt_show_fps) showFPS();
    SDL_Flip(l81.fb->screen);
    /* Wait some time if the frame was produced in less than 1/FPS seconds. */
    SDL_framerateDelay(&l81.fb->fps_mgr);
    /* Stop execution on error */
    return l81.luaerr;
}
Esempio n. 2
0
	void Application::processEvents(Context& context)
	{
		SDL_Event event;

		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				keyEvent(context, createKeyPressEvent(event.key));
				break;
			case SDL_TEXTINPUT:
				textInputEvent(context, TextInputEvent(event.text.text));
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mouseButtonEvent(context, createMouseButtonEvent(event.button, video.getScreen().getClientHeight()));
				break;
			case SDL_MOUSEMOTION:
				mouseMotionEvent(context, createMouseMotionEvent(event.motion, video.getScreen().getClientHeight()));
				break;
			case SDL_MOUSEWHEEL:
				mouseWheelEvent(context, MouseWheelEvent(0, 0, event.wheel.x, event.wheel.y));
				break;
			case SDL_QUIT:
				requestClose = true;
				break;
			default:
				break;
			}
		}
	}
Esempio n. 3
0
void Camera::onEvent(Event& e)
{
	if (e.IsInCategory(EventCategory::EventCategoryKeyboard)) {
		keyboardEvent(dynamic_cast<KeyEvent&>(e));
		toString();
	}
	else if (e.IsInCategory(EventCategory::EventCategoryMouse)) {
		mouseEvent(dynamic_cast<MouseMovedEvent&>(e));
	}
	else if (e.IsInCategory(EventCategory::EventCategoryMouseButton)) {
		mouseButtonEvent(e);
	}
}
Esempio n. 4
0
bool Screen::mouseButtonCallbackEvent(int button, int action, int modifiers) {
    mModifiers = modifiers;
    mLastInteraction = glfwGetTime();
    try {
        if (mFocusPath.size() > 1) {
            const Window *window =
                dynamic_cast<Window *>(mFocusPath[mFocusPath.size() - 2]);
            if (window && window->modal()) {
                if (!window->contains(mMousePos))
                    return false;
            }
        }

        if (action == GLFW_PRESS)
            mMouseState |= 1 << button;
        else
            mMouseState &= ~(1 << button);

        auto dropWidget = findWidget(mMousePos);
        if (mDragActive && action == GLFW_RELEASE &&
            dropWidget != mDragWidget)
            mDragWidget->mouseButtonEvent(
                mMousePos - mDragWidget->parent()->absolutePosition(), button,
                false, mModifiers);

        if (dropWidget != nullptr && dropWidget->cursor() != mCursor) {
            mCursor = dropWidget->cursor();
            glfwSetCursor(mGLFWWindow, mCursors[(int) mCursor]);
        }

        if (action == GLFW_PRESS && button == GLFW_MOUSE_BUTTON_1) {
            mDragWidget = findWidget(mMousePos);
            if (mDragWidget == this)
                mDragWidget = nullptr;
            mDragActive = mDragWidget != nullptr;
            if (!mDragActive)
                updateFocus(nullptr);
        } else {
            mDragActive = false;
            mDragWidget = nullptr;
        }

        return mouseButtonEvent(mMousePos, button, action == GLFW_PRESS,
                                mModifiers);
    } catch (const std::exception &e) {
        std::cerr << "Caught exception in event handler: " << e.what() << std::endl;
        abort();
    }

    return false;
}