Пример #1
0
void    update_menuScene(t_menuRsc *rsc, t_mouse *m, Uint32 elapse)
{
    SDL_GetMouseState(&m->x, &m->y);

    updateMousePosition(rsc->new_game, m);
    updateMousePosition(rsc->exit, m);
    updateMousePosition(rsc->setting, m);
    updateMousePosition(rsc->high_score, m);

    //updateAnimateTexture(rsc->title, elapse);
    m->clicked = 0;
}
Пример #2
0
void ImagePreview::mouseMoveEvent( QMouseEvent *pEvent )
{
	updateMousePosition( pEvent->pos() );

//	if( mMouse )
//	{
//		mMouse->updateMouseButtons( pEvent->buttons() );
//	}

	mMouseLeft = pEvent->buttons() & Qt::LeftButton;
}
Пример #3
0
bool PlatformScrollbar::handleMousePressEvent(const PlatformMouseEvent& e)
{
    if (!parent())
        return true;

    // TODO(pkasting): http://b/583875 Right-click should invoke a context menu
    // (maybe this would be better handled elsewhere?)
    if (!m_enabled || (e.button() != LeftButton)) {
        return true;
    }

    ASSERT(m_captureStart == None);

    IntPoint pos = convertFromContainingWindow(e.pos());

    const bool horz = (orientation() == HorizontalScrollbar);
    updateMousePosition(pos.x(), pos.y());
    switch (m_mouseOver) {
    case Arrow1:
        scroll(horz ? ScrollLeft : ScrollUp, ScrollByLine);
        break;
    case Track:
        return true;
    case BeforeThumb:
        scroll(horz ? ScrollLeft : ScrollUp, ScrollByPage);
        break;
    case Thumb:
        m_dragOrigin.thumbPos = horz ? pos.x() : pos.y();
        m_dragOrigin.scrollVal = value();
        break;
    case AfterThumb:
        scroll(horz ? ScrollRight : ScrollDown, ScrollByPage);
        break;
    case Arrow2:
        scroll(horz ? ScrollRight : ScrollDown, ScrollByLine);
        break;
    default:
        ASSERT_NOT_REACHED();
    }

    setCapturingMouse(true);

    // Kick off auto-repeat timer
    if (m_mouseOver != Thumb)
        m_autorepeatTimer.start(kAutorepeatInitialDelay,
                                kAutorepeatRepeatInterval);

    m_needsLayout = true;
    // FIXME: Invalidate only the portions that actually changed
    invalidate();

    return true;
}
Пример #4
0
void PlatformScrollbar::handleMouseMoveEventWhenCapturing(const PlatformMouseEvent& e)
{
    IntPoint pos = convertFromContainingWindow(e.pos());
    updateMousePosition(pos.x(), pos.y());

    if (m_captureStart != Thumb) {
        // FIXME: Invalidate only the portions that actually changed
        invalidate();
        return;
    }

    int xCancelDistance, yCancelDistance, backgroundSpan, thumbGirth, delta;
    // NOTE: The cancel distance calculations are based on the behavior of the
    // MSVC8 main window scrollbar + some guessing/extrapolation
    if (orientation() == HorizontalScrollbar) {
        xCancelDistance = kOffEndMultiplier * horizontalScrollbarHeight();
        yCancelDistance = kOffSideMultiplier * horizontalScrollbarHeight();
        backgroundSpan = m_segmentRects[AfterThumb].right() -
            m_segmentRects[BeforeThumb].x();
        thumbGirth = m_segmentRects[Thumb].right() - m_segmentRects[Thumb].x();
        delta = pos.x() - m_dragOrigin.thumbPos;
    } else {
        xCancelDistance = kOffSideMultiplier * verticalScrollbarWidth();
        yCancelDistance = kOffEndMultiplier * verticalScrollbarWidth();
        backgroundSpan = m_segmentRects[AfterThumb].bottom() -
            m_segmentRects[BeforeThumb].y();
        thumbGirth = m_segmentRects[Thumb].bottom() - m_segmentRects[Thumb].y();
        delta = pos.y() - m_dragOrigin.thumbPos;
    }

    // Snap scrollbar back to drag origin if mouse gets too far away
    if ((m_lastNativePos.x() <
            (m_segmentRects[BeforeThumb].x() - xCancelDistance)) ||
        (m_lastNativePos.x() >
            (m_segmentRects[AfterThumb].right() + xCancelDistance)) ||
        (m_lastNativePos.y() <
            (m_segmentRects[BeforeThumb].y() - yCancelDistance)) ||
        (m_lastNativePos.y() >
            (m_segmentRects[AfterThumb].bottom() + yCancelDistance)))
        delta = 0;

    // Convert delta from pixel coords to scrollbar logical coords
    if (backgroundSpan > thumbGirth) {
        if (setValue(m_dragOrigin.scrollVal + (delta *
            (m_totalSize - m_visibleSize) / (backgroundSpan - thumbGirth)))) {
            m_needsLayout = true;
            // FIXME: Invalidate only the portions that actually changed
            invalidate();
        }
    }
}
Пример #5
0
bool PlatformScrollbar::handleMouseOutEvent(const PlatformMouseEvent& e)
{
    if (!parent())
        return true;

    ASSERT(m_captureStart == None);

    // Pass bogus values that will never match real mouse coords.
    updateMousePosition(-1, -1);

    // FIXME: Invalidate only the portions that actually changed
    invalidate();
    return true;
}
Пример #6
0
bool PlatformScrollbar::handleMouseReleaseEvent(const PlatformMouseEvent& e)
{
    ScrollView* parentView = parent();
    if (!parentView)
        return true;

    IntPoint pos = convertFromContainingWindow(e.pos());
    updateMousePosition(pos.x(), pos.y());

    setCapturingMouse(false);

    // FIXME: Invalidate only the portions that actually changed
    invalidate();
    return true;
}
Пример #7
0
bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& e)
{
    if (!parent())
        return true;

    if (m_captureStart != None) {
        handleMouseMoveEventWhenCapturing(e);
        return true;
    }

    IntPoint pos = convertFromContainingWindow(e.pos());
    updateMousePosition(pos.x(), pos.y());

    // FIXME: Invalidate only the portions that actually changed
    invalidate();
    return true;
}
Пример #8
0
    KoToolManager::instance()->addController(m_canvasController);
    KoToolManager::instance()->registerTools(actionCollection(), m_canvasController);

    m_zoomController = new KoZoomController(m_canvasController, &m_zoomHandler, actionCollection());
    connect(m_zoomController, SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)),
            this, SLOT(slotZoomChanged(KoZoomMode::Mode,qreal)));

    m_zoomAction = m_zoomController->zoomAction();
    m_mainWindow->addStatusBarItem(m_zoomAction->createWidget(m_mainWindow->statusBar()), 0, this);

    m_zoomController->setZoomMode(KoZoomMode::ZOOM_WIDTH);

    gridLayout->addWidget(m_canvasController, 1, 1);

    connect(m_canvasController->proxyObject, SIGNAL(canvasMousePositionChanged(QPoint)),
            this, SLOT(updateMousePosition(QPoint)));

    KoToolBoxFactory toolBoxFactory;
    m_mainWindow->createDockWidget(&toolBoxFactory);

    connect(m_canvasController, SIGNAL(toolOptionWidgetsChanged(QList<QPointer<QWidget> >)), m_mainWindow->dockerManager(), SLOT(newOptionWidgets(QList<QPointer<QWidget> >)));

    SectionsBoxDockFactory structureDockerFactory;
    m_sectionsBoxDock = qobject_cast<SectionsBoxDock*>(m_mainWindow->createDockWidget(&structureDockerFactory));
    Q_ASSERT(m_sectionsBoxDock);
    m_sectionsBoxDock->setup(m_doc, this);

    SectionPropertiesDockFactory sectionPropertiesDockerFactory;
    m_sectionPropertiesDock = qobject_cast<SectionPropertiesDock*>(m_mainWindow->createDockWidget(&sectionPropertiesDockerFactory));
    Q_ASSERT(m_sectionPropertiesDock);
    m_sectionPropertiesDock->setRootSection(m_doc);
Пример #9
0
void Widget::handleInput(){

	if(!initializedJoysticks){
		SDL_Init(SDL_INIT_JOYSTICK);
		if(SDL_NumJoysticks() > 0){
			guiLogger.log("found joysticks: " + std::to_string(SDL_NumJoysticks()));
			SDL_JoystickEventState(SDL_ENABLE);
			SDL_JoystickOpen(0);
		}
		else{
			guiLogger.log("found no joystick. SDL Init stat: " + std::to_string(SDL_WasInit(SDL_INIT_JOYSTICK)));
		}
		initializedJoysticks = true;
	}

	while(SDL_PollEvent(&event)){
		float *s;
		std::vector<Widget*> *widgets;
		switch(event.type){

		case SDL_JOYAXISMOTION:
			if(focused != NULL){
				if(event.jaxis.value < -3200 || event.jaxis.value > 3200){
					focused->handleAxisEvent(event.jaxis.axis, event.jaxis.value / 32767.0);
				}
				else{
					focused->handleAxisEvent(event.jaxis.axis, 0);
				}
			}
			break;
		case SDL_JOYBUTTONDOWN:
			if(focused != NULL){
				focused->handleButtonEvent(event.jbutton.button, true);
			}
			break;
		case SDL_JOYBUTTONUP:
			if(focused != NULL){
				focused->handleButtonEvent(event.jbutton.button, false);
			}
			break;

		case SDL_MOUSEMOTION:
			s = pixelToScreenSpace(event.motion.x, event.motion.y);

			updateMousePosition(s[0], s[1]);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			Widget *w;
			//if(getFocused() != NULL && getFocused()->isListeningToMouse()){
			while(!widgets->empty()){
				w = widgets->back();
				widgets->pop_back();
				if(w->isListeningToMouse()){
					w->handleMouseMotionEvent(s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop());
					for(Widget *w1 : w->children){
						if(!w1->isFocusable()){
							w1->handleMouseMotionEvent(s[0] - w1->getAbsoluteLeft(), s[1] - w1->getAbsoluteTop());
						}
					}
				}
			}
			//}

			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEBUTTONDOWN:
			updateMouseButton(event.button.button, true);

			s = pixelToScreenSpace(event.button.x, event.button.y);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			if(consoleActive && game::physics::pointInRect(s[0], s[1], console.getAbsoluteLeft(), console.getAbsoluteTop(), console.getWidth(), console.getHeight())){
				widgets->push_back(&console);
			}
		
			while(widgets->size() > 0){
				//Widget *w = widgets->at(i);
				Widget *w = widgets->back();
				widgets->pop_back();
				/**
				 * if the widget is listening to mouse events and focusable, let it handle the event, transforming the global event coordinates in local coordinates
				 * if the widget is also listening to keys, make it the currently focused widget
				 */
				if(w->isListeningToMouse() && w->isFocusable()){
					if(w->isListeningToKeys()){
						setFocus(w);
						//						if(focused != NULL)
						//							focused->hasFocus = false;
						//						focused = w;
						//						focused->hasFocus = true;
					}
					w->handleMouseButtonEvent(event.button.button, s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop(), true);
					for(Widget *h : w->children){
						if(!h->isFocusable()){
							h->handleMouseButtonEvent(event.button.button, s[0] - h->getAbsoluteLeft(), s[1] - h->getAbsoluteTop(), true);
						}
					}

					break;
				}
			}
			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEBUTTONUP:
			updateMouseButton(event.button.button, false);

			s = pixelToScreenSpace(event.button.x, event.button.y);

			widgets = new std::vector<Widget*>();
			getWidgetsAt(s[0], s[1], widgets);
			if(consoleActive && game::physics::pointInRect(s[0], s[1], console.getAbsoluteLeft(), console.getAbsoluteTop(), console.getWidth(), console.getHeight())){
				widgets->push_back(&console);
			}
			while(widgets->size() > 0){
				//Widget *w = widgets->at(i);
				Widget *w = widgets->back();
				widgets->pop_back();
				/**
				 * if the widget is listening to mouse events and focusable, let it handle the event, transforming the global event coordinates in local coordinates
				 * if the widget is also listening to keys, make it the currently focused widget
				 */
				if(w->isListeningToMouse() && w->isFocusable()){
					if(w->isListeningToKeys()){
						setFocus(w);
						//						if(focused != NULL)
						//							focused->hasFocus = false;
						//						focused = w;
						//						focused->hasFocus = true;
					}
					w->handleMouseButtonEvent(event.button.button, s[0] - w->getAbsoluteLeft(), s[1] - w->getAbsoluteTop(), false);
					for(Widget *h : w->children){
						if(!h->isFocusable()){
							h->handleMouseButtonEvent(event.button.button, s[0] - h->getAbsoluteLeft(), s[1] - h->getAbsoluteTop(), false);
						}
					}

					break;
				}
			}
			delete widgets;
			delete[] s;
			break;
		case SDL_MOUSEWHEEL:
			if(getFocused() != NULL && getFocused()->isListeningToMouse()){
				getFocused()->handleMouseWheelEvent(event.wheel.y);
			}
			break;
		case SDL_KEYDOWN:
			updateKey(event.key.keysym.scancode, true);
			//mapKey(event.key.keysym.scancode, true);
			if(event.key.keysym.sym == SDLK_ESCAPE){
				if(game::isInHomescreen()){
					render::stop();
					game::stop();
				}
				else{
					game::toHomescreenWidget();
					audio::clearMusicQueue();
					audio::queueMusic("sfx/temp/pippin_the_hunchback.wav");
					audio::nextSong();
				}
			}
#ifdef unix
			if(event.key.keysym.sym == SDLK_BACKQUOTE && (event.key.keysym.mod & (KMOD_SHIFT | KMOD_CAPS)) > 0){
#else
#ifdef windows
				if(event.key.keysym.sym == SDLK_BACKQUOTE){ // TODO find way to get shift mod with wine SDL
#else
					if(false){
#endif
#endif
						consoleActive = !consoleActive;
						if(consoleActive){
							setFocus(&console);
						}
						else if(getFocused() == &console){
							if(children.size() > 0){
								setFocus(children[0]);
							}
							else{
								setFocus(NULL);
							}
						}
					}
					if(focused != NULL){
						focused->handleKeyEvent(event.key.keysym.sym, event.key.keysym.mod, true);
					}
					break;
		case SDL_TEXTINPUT:
			if(focused != NULL){
				focused->handleTextEvent(std::string(event.text.text));
			}
			break;
		case SDL_KEYUP:
			updateKey(event.key.keysym.scancode, false);
			//mapKey(event.key.keysym.scancode, false);
			if(focused != NULL){
				focused->handleKeyEvent(event.key.keysym.sym, event.key.keysym.mod, false);
			}
			break;
				}
			}

		}

		void Widget::render(float updateFactor){
			render::setRenderTarget(render::HUD); //TODO unnecessary repeated setting of render Target
			for(Widget *w : children){
				render::setScissorArea(w->getAbsoluteLeft(), w->getAbsoluteTop() + w->getHeight(), w->getWidth(), w->getHeight());
				w->render(updateFactor);
			}
		}

		void Widget::renderConsole(float updateFactor){
			render::setRenderTarget(render::HUD);
			if(consoleActive){
				render::setScissorArea(console.getAbsoluteLeft(), console.getAbsoluteTop() + console.getHeight(), console.getWidth(), console.getHeight());
				console.render(updateFactor);
			}
		}