Exemplo n.º 1
0
bool Window::EmbeddedWindow::setWindow(Window* win) {
    if(!win) {
        warn()
            << "EmbeddedWindow [" << _name
            << "] attempted to set a NULL Window." << std::endl
        ;

        return false;
    }

    if (_window.valid() && _parent)
        unparented(_parent);

    _window = win;

    _window->resize();
    _window->setVisibilityMode(VM_PARTIAL);

    if(_parent) parented(_parent);

    WindowManager* wm = _getWindowManager();

    if(wm) managed(wm);

    return true;
}
Exemplo n.º 2
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);
}