Exemple #1
0
bool WindowTree::onCursorMove( const RectInt & window, const PointInt & position, const PointInt & delta )
{
	if ( visible() )
	{
		if ( window.inRect( position ) )
		{
			m_CursorInWindow = true;
			m_LastCursorPosition = windowToScreen( position );

			setCursorState( SELECT );
			return true;
		}
		else
		{
			m_CursorInWindow = false;
		}
	}

	return NodeWindow::onCursorMove( window, position, delta );
}
void TouchInputManager::Update() {
    if (!camera) {
        LOGW_EVERY_N(60, "No camera defined -> no input handling");
        return;
    }
    TransformationComponent* tc = TRANSFORM(camera);

    const glm::vec2 windowSize(theRenderingSystem.screenW, theRenderingSystem.screenH);
    glm::vec2 coords;
    const unsigned pointers = ptr->maxTouchingCount();

    for (unsigned i=0; i<pointers; i++) {
        wasTouching[i] = touching[i];
        touching[i] = ptr->isTouching(i, &coords);
        if (touching[i]) {
            // convert window coordinates -> world coords
            lastTouchedPositionScreen[i] = windowToScreen(coords);
            lastTouchedPosition[i] = windowToWorld(coords, tc);

            if (!wasTouching[i]) {
                onTouchPosition[i] = lastTouchedPositionScreen[i];
            }
        }
        #if !SAC_MOBILE
        {
            lastOverPositionScreen[i] = windowToScreen(coords);
            lastOverPosition[i] = windowToWorld(coords, tc);
        }
        #endif

        // first click condition: was touched + is released
        if (!touching[i] && wasTouching[i]) {
            // click is valid if ~no move between on touch and on release event
            clicked[i] = (glm::distance2(lastTouchedPositionScreen[i], onTouchPosition[i]) < 0.005);

            if (clicked[i]) {
                float t = TimeUtil::GetTime();
                glm::vec2 pos = lastTouchedPositionScreen[i];

                if ((t - lastClickTime[i] < 0.3) && glm::distance2(pos, lastClickPosition[i]) < 0.005) {
                    doubleclicked[i] = true;
                    LOGV(1, "DOUBLE CLICKED("<< i << ") TOO!");
                } else {
                    lastClickPosition[i] = pos;
                    doubleclicked[i] = false;
                    LOGV(1, "CLICK(" << i << ") at " << t << ": " << pos);
                }
                lastClickTime[i] = t;
            } else {
                doubleclicked[i] = false;
            }
        } else {
            clicked[i] = doubleclicked[i] = false;
        }

        if (theReplayManager.isReplayModeEnabled()) {
            theReplayManager.saveIsTouching(i, touching[i], coords);
        }
    }


#if SAC_DEBUG
    if (!debugState[0])
        return;
    const auto* cam = TRANSFORM(ANCHOR(debugState[0])->parent);
    for (int i=0; i<MAX_TOUCH_POINT; i++) {
        TRANSFORM(debugState[i])->size = glm::vec2(0.05 * cam->size.y);

        ANCHOR(debugState[i])->position =
            AnchorSystem::adjustPositionWithCardinal(
                cam->size * glm::vec2(-0.5, 0.5) - glm::vec2(0, TRANSFORM(debugState[i])->size.y * i),
                TRANSFORM(debugState[i])->size,
                Cardinal::NW);

        if (touching[i])
            RENDERING(debugState[i])->color = Color(0, 1, 0);
        else
            RENDERING(debugState[i])->color = Color(1, 0, 0);
    }
#endif
}