XYCoord Window::localXY(double absx, double absy) const {
    XYCoord xy = getAbsoluteOrigin();
    double  x  = absx - xy.x();
    double  y  = absy - xy.y();

    return XYCoord(x + _visibleArea[0], y + _visibleArea[1]);
}
Exemple #2
0
void WindowManager::_updatePickWindow(const WidgetList* wl, point_type x, point_type y) {
    Label* label = dynamic_cast<Label*>(_pickWindow->getByName("PickLabel"));

    if(!wl) {
        setValue(0, false);

        return;
    }

    setValue(0, true);

    std::stringstream ss;

    point_type xdiff = x;
    point_type ydiff = y;

    _getPointerXYDiff(xdiff, ydiff);

    ss
        << "At XY Coords: " << x << ", " << y
        << " ( diff " << xdiff << ", " << ydiff << " )"
        << std::endl
    ;

    const Window* parent = wl->back()->getParent();

    ss
        << "Window: " << parent->getName()
        << " ( xyz " << parent->getPosition() << " )"
        << " { zRange " << parent->getZRange() << " }"
        << " < size " << parent->getSize() << " >"
        << " EventMask: " << std::hex << parent->getEventMask()
        << std::endl
    ;

    for(WidgetList::const_iterator i = wl->begin(); i != wl->end(); i++) {
        Widget* widget = i->get();

        ss
            << "   - " << widget->getName()
            << " ( xyz " << widget->getPosition() << " )"
            << " [ XYZ " << widget->getPosition() * parent->getMatrix()
            << " ] < size " << widget->getSize() << " >"
            << " EventMask: " << std::hex << widget->getEventMask()
            << std::endl
        ;
    }

    label->setLabel(ss.str());

    XYCoord size = label->getTextSize();

    _pickWindow->resize(size.x() + 10.0f, size.y() + 10.0f);
    _pickWindow->setOrigin(5.0f, _height - _pickWindow->getHeight() - 5.0f);
    _pickWindow->update();
}
Exemple #3
0
void Input::_calculateSize(const XYCoord& size) {
    // An Input cannot currently set it's own size RELIABLY until the osgText implementation
    // is dratiscally improved. I'm getting wildly crazy results. :(
    // point_type height = size.y() > _cursor->getHeight() ? size.y() : _cursor->getHeight();

#if 0
    point_type width  = size.x() + _cursor->getWidth();
    point_type height = _cursor->getHeight();

    if(width > getWidth()) setWidth(osg::round(width));

    if(height > getHeight()) setHeight(osg::round(height));
#endif
}
void Window::update() {
    WindowList wl;

    getEmbeddedList(wl);

    for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) w->get()->update();

    matrix_type x  = _x;
    matrix_type y  = _y;
    XYCoord     xy = getAbsoluteOrigin();

    // We only honor ANCHOR requests on topmost Windows, not embedded ones.
    if((_vAnchor != VA_NONE || _hAnchor != HA_NONE) && !_parent && _wm) {
        if(_vAnchor == VA_TOP) y = _wm->getHeight() - _height.current;
        else if(_vAnchor == VA_CENTER) y = osg::round(_wm->getHeight() / 2.0f);
        else if(_vAnchor == VA_BOTTOM) y = 0.0f;

        if(_hAnchor == HA_LEFT) x = 0.0f;
        else if(_hAnchor == HA_CENTER) x = osg::round(_wm->getWidth() / 2.0f);
        else if(_hAnchor == HA_RIGHT) x = _wm->getWidth() - _width.current + _visibleArea[2];

        xy.set(x, y);
    }
    
    matrix_type z = _z;

    // We can't do proper scissoring until we have access to our parent WindowManager, and
    // we need to determine the sorting method we want to use.
    if(_wm) {
        if(_wm->isUsingRenderBins()) {
            getOrCreateStateSet()->setRenderBinDetails(
                static_cast<int>((1.0f - fabs(_z)) * OSGWIDGET_RENDERBIN_MOD),
                "RenderBin"
            );

            z = 0.0f;
        }

        int sx = static_cast<int>(xy.x());
        int sy = static_cast<int>(xy.y());
        int sw = static_cast<int>(_width.current);
        int sh = static_cast<int>(_height.current);

        // This sets the Scissor area to some offset defined by the user.
        if(_vis == VM_PARTIAL) {
            sw = static_cast<int>(_visibleArea[2]);
            sh = static_cast<int>(_visibleArea[3]);
        }

        // Otherwise, use the size of the WindowManager itself.
        else if(_vis == VM_ENTIRE) {
            sx = 0;
            sy = 0;
            sw = static_cast<int>(_wm->getWidth());
            sh = static_cast<int>(_wm->getHeight());
        }

        _scissor()->setScissor(sx, sy, sw, sh);
    }

    // Update the Window itself, setting it's matrix according to translate, rotate, and
    // scale values.
    osg::Matrix r = osg::Matrix::rotate(
        osg::DegreesToRadians(_r),
        osg::Vec3d(0.0f, 0.0f, 1.0f)
    );

    osg::Matrix s = osg::Matrix::scale(_s, _s, 1.0f);
    osg::Matrix t = osg::Matrix::translate(x - _visibleArea[0], y - _visibleArea[1], z);

    setMatrix(r * s * t);
}
Exemple #5
0
void Widget::setDimensions(point_type x, point_type y, point_type w, point_type h, point_type z) {
    if(w != -1.0f && w < _minWidth) {
        warn()
            << "Widget [" << _name
            << "] was asked to set it's width to " << w
            << ", but the minimum width is " << _minWidth
            << "." << std::endl
        ;

        w = _minWidth;
    }

    if(h != -1.0f && h < _minHeight) {
        warn()
            << "Widget [" << _name
            << "] was asked to set it's height to " << h
            << ", but the minimum height is " << _minHeight
            << "." << std::endl
        ;

        h = _minHeight;
    }

    PointArray* verts = _verts();

    if(_coordMode == CM_ABSOLUTE) {
        // If any of our values are 0, replace them with the current value.
        // We could just call getWidth(), etc., but all those dynamic_casts could eventually
        // get expensive, so we just use the already-created verts() array directly.
        if(x < 0.0f) x = MACRO_WIDGET_X(verts);
        if(y < 0.0f) y = MACRO_WIDGET_Y(verts);
        if(w < 0.0f) w = MACRO_WIDGET_W(verts);
        if(h < 0.0f) h = MACRO_WIDGET_H(verts);
    }

    else {
        if(x < 0.0f) x = _relCoords[0];
        if(y < 0.0f) y = _relCoords[1];
        if(w < 0.0f) w = _relCoords[2];
        if(h < 0.0f) h = _relCoords[3];
    }

    if(z < 0.0f) z = _calculateZ(_layer);

    // Now, we need to determine if the dimensions are actually percentage of the parent's
    // size, rather than an absolute values. The Widget must be parented for this to be
    // valid, however.
    if(_coordMode == CM_RELATIVE) {
        XYCoord size;

        if(_parent) size = _parent->getSize();

        if(x >= 0.0f && x <= 1.0f) {
            _relCoords[0] = x;

            x = size.x() * x;
        }

        if(y >= 0.0f && y <= 1.0f) {
            _relCoords[1] = y;

            y = size.y() * y;
        }

        if(w >= 0.0f && w <= 1.0f) {
            _relCoords[2] = w;

            w = size.x() * w;
        }

        if(h >= 0.0f && h <= 1.0f) {
            _relCoords[3] = h;

            h = size.y() * h;
        }
    }

    const WindowManager* wm = _getWindowManager();

    if(wm && wm->isUsingRenderBins()) {
        getOrCreateStateSet()->setRenderBinDetails(static_cast<int>(z), "RenderBin");

        z = 0.0f;
    }

    (*verts)[LL].set(x,     y,     z);
    (*verts)[LR].set(x + w, y,     z);
    (*verts)[UR].set(x + w, y + h, z);
    (*verts)[UL].set(x,     y + h, z);
}