Exemplo n.º 1
0
MouseEventResult Entity::onMouseMove(const Ray &ray, int timestamp) {
    MouseEventResult ret;
    ret.hit = false;
    ret.blocked = false;
    Number hitDistance;

    if(processInputEvents && enabled) {

        Vector3 localCoordinate = Vector3(ray.origin.x,ray.origin.y,0);
        Matrix4 inverse = getConcatenatedMatrix().Inverse();
        localCoordinate = inverse * localCoordinate;

        hitDistance = ray.boxIntersect(bBox, getAnchorAdjustedMatrix());
        if(hitDistance >= 0.0) {
            //setColor(1.0, 0.0, 0.0, 1.0);
            ret.hit = true;
            InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
            inputEvent->hitDistance = hitDistance;
            dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEMOVE);

            if(!mouseOver) {
                InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
                inputEvent->hitDistance = hitDistance;
                dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEOVER);
                mouseOver = true;
            }

            if(blockMouseInput) {
                ret.blocked = true;
            }
        } else {
            if(mouseOver) {
                dispatchEvent(new InputEvent(Vector2(localCoordinate.x, localCoordinate.y), timestamp), InputEvent::EVENT_MOUSEOUT);
                mouseOver = false;
            }
        }

        for(int i=children.size()-1; i>=0; i--) {
            MouseEventResult childRes = children[i]->onMouseMove(ray, timestamp);
            if(childRes.hit)
                ret.hit = true;

            if(childRes.blocked) {
                ret.blocked = true;
                break;
            }
        }
    }
    return ret;
}
Exemplo n.º 2
0
MouseEventResult Entity::onMouseDown(const Ray &ray, int mouseButton, int timestamp) {
    MouseEventResult ret;
    ret.hit = false;
    ret.blocked = false;
    Number hitDistance;

    if(processInputEvents && enabled) {
        hitDistance = ray.boxIntersect(bBox, getAnchorAdjustedMatrix());
        if(hitDistance >= 0.0) {
            if(customHitDetection(ray)) {
                ret.hit = true;

                Vector3 localCoordinate = Vector3(ray.origin.x,ray.origin.y,0);
                Matrix4 inverse = getConcatenatedMatrix().Inverse();
                localCoordinate = inverse * localCoordinate;

                InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
                inputEvent->hitDistance = hitDistance;
                inputEvent->mouseButton = mouseButton;
                dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEDOWN);

                if(timestamp - lastClickTicks < 400) {
                    InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
                    inputEvent->mouseButton = mouseButton;
                    dispatchEvent(inputEvent, InputEvent::EVENT_DOUBLECLICK);
                }
                lastClickTicks = timestamp;

                if(blockMouseInput) {
                    ret.blocked = true;
                }
            }
        }

        for(int i=children.size()-1; i>=0; i--) {
            MouseEventResult childRes = children[i]->onMouseDown(ray, mouseButton, timestamp);
            if(childRes.hit)
                ret.hit = true;

            if(childRes.blocked) {
                ret.blocked = true;
                break;
            }
        }
    }
    return ret;
}
Exemplo n.º 3
0
MouseEventResult Entity::onMouseUp(const Ray &ray, int mouseButton, int timestamp) {
    MouseEventResult ret;
    ret.hit = false;
    ret.blocked = false;
    Number hitDistance;

    if(processInputEvents && enabled) {

        Vector3 localCoordinate = Vector3(ray.origin.x,ray.origin.y,0);
        Matrix4 inverse = getConcatenatedMatrix().Inverse();
        localCoordinate = inverse * localCoordinate;

        InputEvent *inputEvent = new InputEvent(Vector2(localCoordinate.x, localCoordinate.y*yAdjust), timestamp);
        inputEvent->mouseButton = mouseButton;

        hitDistance = ray.boxIntersect(bBox, getAnchorAdjustedMatrix());
        if(hitDistance >= 0.0) {
            ret.hit = true;
            inputEvent->hitDistance = hitDistance;
            dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEUP);
            if(blockMouseInput) {
                ret.blocked = true;
            }
        } else {
            dispatchEvent(inputEvent, InputEvent::EVENT_MOUSEUP_OUTSIDE);
        }

        for(int i=children.size()-1; i>=0; i--) {
            MouseEventResult childRes = children[i]->onMouseUp(ray, mouseButton, timestamp);
            if(childRes.hit)
                ret.hit = true;

            if(childRes.blocked) {
                ret.blocked = true;
                break;
            }
        }
    }
    return ret;
}