diff --git a/src/osgWidget/Box.cpp b/src/osgWidget/Box.cpp index fdc893c51..c3da08517 100644 --- a/src/osgWidget/Box.cpp +++ b/src/osgWidget/Box.cpp @@ -22,173 +22,173 @@ _lastAdd (box._lastAdd) { // TODO: Here's something to consider! If we resize the box by 1 every time, only the // first resizable Widget will continue to get larger. This is really silly. void Box::_resizeImplementation(point_type w, point_type h) { - // Get the number of Widgets that agree to fill. Also perfom some casting to integers - // in case we're being request to resize with pixel perfection. - point_type numFill = _getNumFill(); - int iw = static_cast(w); - int ih = static_cast(h); - int inumFill = static_cast(numFill); - int wrem = 0; - int hrem = 0; + // Get the number of Widgets that agree to fill. Also perfom some casting to integers + // in case we're being request to resize with pixel perfection. + point_type numFill = _getNumFill(); + int iw = static_cast(w); + int ih = static_cast(h); + int inumFill = static_cast(numFill); + int wrem = 0; + int hrem = 0; - // If we have some widgets that fill, use these variables to keep a running count - // of what needs to be added. - if(inumFill) { - wrem = iw % inumFill; - hrem = ih % inumFill; - } + // If we have some widgets that fill, use these variables to keep a running count + // of what needs to be added. + if(inumFill) { + wrem = iw % inumFill; + hrem = ih % inumFill; + } - // If we have any widgets that agree to fill and there has been an honest resize - // request, handle it here. The first case handles resizes where we have AT LEAST - // as many pixels to fill as we have objects. - if(numFill > 0.0f && (w != 0.0f || h != 0.0f)) { - unsigned int cur = 0; + // If we have any widgets that agree to fill and there has been an honest resize + // request, handle it here. The first case handles resizes where we have AT LEAST + // as many pixels to fill as we have objects. + if(numFill > 0.0f && (w != 0.0f || h != 0.0f)) { + unsigned int cur = 0; - for(Iterator i = begin(); i != end(); i++) if(i->valid() && i->get()->canFill()) { - point_type addWidth = 0.0f; - point_type addHeight = 0.0f; + for(Iterator i = begin(); i != end(); i++) if(i->valid() && i->get()->canFill()) { + point_type addWidth = 0.0f; + point_type addHeight = 0.0f; - // If our last added-to Widget was the last one, reset it to 0. - if(_lastAdd >= size()) _lastAdd = 0; + // If our last added-to Widget was the last one, reset it to 0. + if(_lastAdd >= size()) _lastAdd = 0; - // We EVENLY give any remaining space to all fillable Widgets. In the - // future we may want to be able to specify a fill "percent", which - // would be some portion of the total available space. - if(_boxType == HORIZONTAL) { - if(w) { - addWidth += static_cast(iw / inumFill); + // We EVENLY give any remaining space to all fillable Widgets. In the + // future we may want to be able to specify a fill "percent", which + // would be some portion of the total available space. + if(_boxType == HORIZONTAL) { + if(w) { + addWidth += static_cast(iw / inumFill); - if(cur >= _lastAdd && wrem) { - _lastAdd++; - addWidth++; - wrem--; - } - } + if(cur >= _lastAdd && wrem) { + _lastAdd++; + addWidth++; + wrem--; + } + } - if(h) addHeight += h; - } + if(h) addHeight += h; + } - else { - if(w) addWidth += w; + else { + if(w) addWidth += w; - if(h) { - addHeight += static_cast(ih / inumFill); + if(h) { + addHeight += static_cast(ih / inumFill); - if(cur >= _lastAdd && hrem) { - _lastAdd++; - addHeight++; - hrem--; - } - } - } + if(cur >= _lastAdd && hrem) { + _lastAdd++; + addHeight++; + hrem--; + } + } + } - if(addWidth != 0.0f) i->get()->addWidth(addWidth); + if(addWidth != 0.0f) i->get()->addWidth(addWidth); - if(addHeight != 0.0f) i->get()->addHeight(addHeight); + if(addHeight != 0.0f) i->get()->addHeight(addHeight); - cur++; - } - } + cur++; + } + } - // Get the width and height of our largest widgets; these values take - // into account the padding, and will be affected by any resizing that occured above. - point_type maxWidth = _getMaxWidgetWidthTotal(); - point_type maxHeight = _getMaxWidgetHeightTotal(); + // Get the width and height of our largest widgets; these values take + // into account the padding, and will be affected by any resizing that occured above. + point_type maxWidth = _getMaxWidgetWidthTotal(); + point_type maxHeight = _getMaxWidgetHeightTotal(); - // Create counters for the various offsets as we position Widgets. - point_type xoff = 0.0f; - point_type yoff = 0.0f; - point_type xadd = 0.0f; - point_type yadd = 0.0f; + // Create counters for the various offsets as we position Widgets. + point_type xoff = 0.0f; + point_type yoff = 0.0f; + point_type xadd = 0.0f; + point_type yadd = 0.0f; - for(Iterator i = begin(); i != end(); i++) { - Widget* widget = i->get(); + for(Iterator i = begin(); i != end(); i++) { + Widget* widget = i->get(); - // This positioning works by setting each Widget's unmodified origin and then - // letting Window::_positionWidget calculate the padding/fill. - if(_boxType == HORIZONTAL) { - // First, lets set it to the proper x offset, ignoring any padding. - widget->setOrigin(xoff, 0.0f); + // This positioning works by setting each Widget's unmodified origin and then + // letting Window::_positionWidget calculate the padding/fill. + if(_boxType == HORIZONTAL) { + // First, lets set it to the proper x offset, ignoring any padding. + widget->setOrigin(xoff, 0.0f); - // Immediately reset our xoff for the next iteration. - if(_uniform) { - _positionWidget(widget, maxWidth, maxHeight); + // Immediately reset our xoff for the next iteration. + if(_uniform) { + _positionWidget(widget, maxWidth, maxHeight); - xadd = maxWidth; - } + xadd = maxWidth; + } - else { - _positionWidget(widget, widget->getWidthTotal(), maxHeight); + else { + _positionWidget(widget, widget->getWidthTotal(), maxHeight); - xadd = widget->getWidthTotal(); - } - } + xadd = widget->getWidthTotal(); + } + } - else { - widget->setOrigin(0.0f, yoff); + else { + widget->setOrigin(0.0f, yoff); - if(_uniform) { - _positionWidget(widget, maxWidth, maxHeight); + if(_uniform) { + _positionWidget(widget, maxWidth, maxHeight); - yadd = maxHeight; - } + yadd = maxHeight; + } - else { - _positionWidget(widget, maxWidth, widget->getHeightTotal()); + else { + _positionWidget(widget, maxWidth, widget->getHeightTotal()); - yadd = widget->getHeightTotal(); - } - } + yadd = widget->getHeightTotal(); + } + } - xoff += xadd; - yoff += yadd; - } + xoff += xadd; + yoff += yadd; + } } Window::Sizes Box::_getWidthImplementation() const { - // The width of a horizontal box is all of the widgets added together. - if(_boxType == HORIZONTAL) { - // If we're a uniformly sized box, our width is our largest width plus our - // largest padding, multiplied times the number of widgets. Our minimum width - // is the size of the largest minWidth times the number of widgets. - if(_uniform) return Sizes( - _getMaxWidgetWidthTotal() * size(), - _getMaxWidgetMinWidthTotal() * size() - ); + // The width of a horizontal box is all of the widgets added together. + if(_boxType == HORIZONTAL) { + // If we're a uniformly sized box, our width is our largest width plus our + // largest padding, multiplied times the number of widgets. Our minimum width + // is the size of the largest minWidth times the number of widgets. + if(_uniform) return Sizes( + _getMaxWidgetWidthTotal() * size(), + _getMaxWidgetMinWidthTotal() * size() + ); - // Othweriwse, our width is all of the widths added together, and our minWidth - // is all of the minWidths added together. - else return Sizes( - _accumulate(&Widget::getWidthTotal), - _accumulate(&Widget::getMinWidthTotal) - ); - } + // Othweriwse, our width is all of the widths added together, and our minWidth + // is all of the minWidths added together. + else return Sizes( + _accumulate(&Widget::getWidthTotal), + _accumulate(&Widget::getMinWidthTotal) + ); + } - // If we're a vertical Box, our width is the width of the larget Widget in the group. - // Our minWidth is the largest minWidth of the Widgets in the group. - else return Sizes( - _getMaxWidgetWidthTotal(), - _getMaxWidgetMinWidthTotal() - ); + // If we're a vertical Box, our width is the width of the larget Widget in the group. + // Our minWidth is the largest minWidth of the Widgets in the group. + else return Sizes( + _getMaxWidgetWidthTotal(), + _getMaxWidgetMinWidthTotal() + ); } Window::Sizes Box::_getHeightImplementation() const { - if(_boxType == VERTICAL) { - if(_uniform) return Sizes( - _getMaxWidgetHeightTotal() * size(), - _getMaxWidgetMinHeightTotal() * size() - ); - - else return Sizes( - _accumulate(&Widget::getHeightTotal), - _accumulate(&Widget::getMinHeightTotal) - ); - } + if(_boxType == VERTICAL) { + if(_uniform) return Sizes( + _getMaxWidgetHeightTotal() * size(), + _getMaxWidgetMinHeightTotal() * size() + ); + + else return Sizes( + _accumulate(&Widget::getHeightTotal), + _accumulate(&Widget::getMinHeightTotal) + ); + } - else return Sizes( - _getMaxWidgetHeightTotal(), - _getMaxWidgetMinHeightTotal() - ); + else return Sizes( + _getMaxWidgetHeightTotal(), + _getMaxWidgetMinHeightTotal() + ); } } diff --git a/src/osgWidget/Canvas.cpp b/src/osgWidget/Canvas.cpp index e7a50f1a0..2459e79ad 100644 --- a/src/osgWidget/Canvas.cpp +++ b/src/osgWidget/Canvas.cpp @@ -14,19 +14,19 @@ Window(canvas, co) { } void Canvas::_resizeImplementation(point_type w, point_type h) { - // A Canvas has no layout, so it doesn't really know how to honor a resize - // request. :) The best I could do here is store the differences and add them - // later to the calls to getWidth/getHeight. + // A Canvas has no layout, so it doesn't really know how to honor a resize + // request. :) The best I could do here is store the differences and add them + // later to the calls to getWidth/getHeight. } bool Canvas::addWidget(Widget* widget, point_type x, point_type y) { - if(Window::addWidget(widget)) { - widget->setOrigin(x, y); + if(Window::addWidget(widget)) { + widget->setOrigin(x, y); - return true; - } + return true; + } - return false; + return false; } } diff --git a/src/osgWidget/Frame.cpp b/src/osgWidget/Frame.cpp index ad180dc0b..dab72159d 100644 --- a/src/osgWidget/Frame.cpp +++ b/src/osgWidget/Frame.cpp @@ -8,29 +8,29 @@ namespace osgWidget { std::string Frame::cornerToString(CORNER c) { - if(c == CORNER_LOWER_LEFT) return "CornerLowerLeft"; + if(c == CORNER_LOWER_LEFT) return "CornerLowerLeft"; - else if(c == CORNER_LOWER_RIGHT) return "CornerLowerRight"; + else if(c == CORNER_LOWER_RIGHT) return "CornerLowerRight"; - else if(c == CORNER_UPPER_RIGHT) return "CornerUpperRight"; + else if(c == CORNER_UPPER_RIGHT) return "CornerUpperRight"; - else return "CornerUpperLeft"; + else return "CornerUpperLeft"; } std::string Frame::borderToString(BORDER b) { - if(b == BORDER_LEFT) return "BorderLeft"; + if(b == BORDER_LEFT) return "BorderLeft"; - else if(b == BORDER_RIGHT) return "BorderRight"; + else if(b == BORDER_RIGHT) return "BorderRight"; - else if(b == BORDER_TOP) return "BorderTop"; + else if(b == BORDER_TOP) return "BorderTop"; - else return "BorderBottom"; + else return "BorderBottom"; } Frame::Corner::Corner(CORNER corner, point_type width, point_type height): Widget (cornerToString(corner), width, height), _corner (corner) { - setEventMask(EVENT_MASK_MOUSE_DRAG); + setEventMask(EVENT_MASK_MOUSE_DRAG); } Frame::Corner::Corner(const Corner& corner, const osg::CopyOp& co): @@ -39,54 +39,54 @@ _corner (corner._corner) { } bool Frame::Corner::mouseDrag(double x, double y, WindowManager* wm) { - Window* parent = getParent(); + Window* parent = getParent(); - if(!parent) return false; + if(!parent) return false; - if(wm->isInvertedY()) { - if(_corner == CORNER_UPPER_LEFT) { - if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); - } + if(wm->isInvertedY()) { + if(_corner == CORNER_UPPER_LEFT) { + if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); + } - else if(_corner == CORNER_UPPER_RIGHT) { - if(parent->resizeAdd(x, -y)) parent->addY(y); - } + else if(_corner == CORNER_UPPER_RIGHT) { + if(parent->resizeAdd(x, -y)) parent->addY(y); + } - else if(_corner == CORNER_LOWER_RIGHT) parent->resizeAdd(x, y); + else if(_corner == CORNER_LOWER_RIGHT) parent->resizeAdd(x, y); - else { - if(parent->resizeAdd(-x, y)) parent->addX(x); - } - } + else { + if(parent->resizeAdd(-x, y)) parent->addX(x); + } + } - // These are basically flipped-around versions of the above routines; we - // do it this way to avoid lots of uncessary if tests. - else { - if(_corner == CORNER_UPPER_LEFT) { - if(parent->resizeAdd(-x, y)) parent->addX(x); - } + // These are basically flipped-around versions of the above routines; we + // do it this way to avoid lots of uncessary if tests. + else { + if(_corner == CORNER_UPPER_LEFT) { + if(parent->resizeAdd(-x, y)) parent->addX(x); + } - else if(_corner == CORNER_UPPER_RIGHT) parent->resizeAdd(x, y); + else if(_corner == CORNER_UPPER_RIGHT) parent->resizeAdd(x, y); - else if(_corner == CORNER_LOWER_RIGHT) { - if(parent->resizeAdd(x, -y)) parent->addY(y); - } + else if(_corner == CORNER_LOWER_RIGHT) { + if(parent->resizeAdd(x, -y)) parent->addY(y); + } - else { - if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); - } - } + else { + if(parent->resizeAdd(-x, -y)) parent->addOrigin(x, y); + } + } - parent->update(); - - return true; + parent->update(); + + return true; } Frame::Border::Border(BORDER border, point_type width, point_type height): Widget (borderToString(border), width, height), _border (border) { - setCanFill(true); - setEventMask(EVENT_MASK_MOUSE_DRAG); + setCanFill(true); + setEventMask(EVENT_MASK_MOUSE_DRAG); } Frame::Border::Border(const Border& border, const osg::CopyOp& co): @@ -95,30 +95,30 @@ _border (border._border) { } bool Frame::Border::mouseDrag(double x, double y, WindowManager* wm) { - Window* parent = getParent(); + Window* parent = getParent(); - if(!parent) return false; + if(!parent) return false; - if(_border == BORDER_LEFT) { - if(parent->resizeAdd(-x, 0.0f)) parent->addX(x); - } + if(_border == BORDER_LEFT) { + if(parent->resizeAdd(-x, 0.0f)) parent->addX(x); + } - else if(_border == BORDER_RIGHT) parent->resizeAdd(x, 0.0f); + else if(_border == BORDER_RIGHT) parent->resizeAdd(x, 0.0f); - else if(_border == BORDER_TOP) parent->addOrigin(x, y); + else if(_border == BORDER_TOP) parent->addOrigin(x, y); - else { - // The only BORDER that inverted-Y affects is this... - if(wm->isInvertedY()) parent->resizeAdd(0.0f, y); + else { + // The only BORDER that inverted-Y affects is this... + if(wm->isInvertedY()) parent->resizeAdd(0.0f, y); - else { - if(parent->resizeAdd(0.0f, -y)) parent->addY(y); - } - } + else { + if(parent->resizeAdd(0.0f, -y)) parent->addY(y); + } + } - parent->update(); + parent->update(); - return true; + return true; } Frame::Frame(const std::string& name): @@ -130,122 +130,122 @@ Table(frame, co) { } Widget* Frame::_getCorner(CORNER c) const { - return const_cast(getByName(cornerToString(c))); + return const_cast(getByName(cornerToString(c))); } Widget* Frame::_getBorder(BORDER b) const { - return const_cast(getByName(borderToString(b))); + return const_cast(getByName(borderToString(b))); } void Frame::managed(WindowManager* wm) { - Window::managed(wm); + Window::managed(wm); - // Our Frame is created in an inverted-Y environment, so if this is the case - // just return here. - if(wm->isInvertedY()) return; + // Our Frame is created in an inverted-Y environment, so if this is the case + // just return here. + if(wm->isInvertedY()) return; - Corner* ll = getCorner(CORNER_LOWER_LEFT); - Corner* lr = getCorner(CORNER_LOWER_RIGHT); - Corner* ul = getCorner(CORNER_UPPER_LEFT); - Corner* ur = getCorner(CORNER_UPPER_RIGHT); - Border* t = getBorder(BORDER_TOP); - Border* b = getBorder(BORDER_BOTTOM); + Corner* ll = getCorner(CORNER_LOWER_LEFT); + Corner* lr = getCorner(CORNER_LOWER_RIGHT); + Corner* ul = getCorner(CORNER_UPPER_LEFT); + Corner* ur = getCorner(CORNER_UPPER_RIGHT); + Border* t = getBorder(BORDER_TOP); + Border* b = getBorder(BORDER_BOTTOM); - if(!ll || !lr || !ul || !ur || !t || !b) { - warn() - << "One or more of your Corner/Border objects in the Frame [" - << _name << "] are invalid; cannot invert orientation." << std::endl - ; + if(!ll || !lr || !ul || !ur || !t || !b) { + warn() + << "One or more of your Corner/Border objects in the Frame [" + << _name << "] are invalid; cannot invert orientation." << std::endl + ; - return; - } + return; + } - ll->setCornerAndName(CORNER_UPPER_LEFT); - lr->setCornerAndName(CORNER_UPPER_RIGHT); - ul->setCornerAndName(CORNER_LOWER_LEFT); - ur->setCornerAndName(CORNER_LOWER_RIGHT); - t->setBorderAndName(BORDER_BOTTOM); - b->setBorderAndName(BORDER_TOP); + ll->setCornerAndName(CORNER_UPPER_LEFT); + lr->setCornerAndName(CORNER_UPPER_RIGHT); + ul->setCornerAndName(CORNER_LOWER_LEFT); + ur->setCornerAndName(CORNER_LOWER_RIGHT); + t->setBorderAndName(BORDER_BOTTOM); + b->setBorderAndName(BORDER_TOP); } bool Frame::setWindow(Window* window) { - if(!window) return false; + if(!window) return false; - EmbeddedWindow* ew = getEmbeddedWindow(); + EmbeddedWindow* ew = getEmbeddedWindow(); - // If it's the first time setting the Window... - // if(!ew || !ew->getWindow()) return addWidget(window->embed(), 1, 1); - if(!ew) return addWidget(window->embed(), 1, 1); + // If it's the first time setting the Window... + // if(!ew || !ew->getWindow()) return addWidget(window->embed(), 1, 1); + if(!ew) return addWidget(window->embed(), 1, 1); - else return ew->setWindow(window); + else return ew->setWindow(window); } Frame* Frame::createSimpleFrame( - const std::string& name, - point_type cw, - point_type ch, - point_type w, - point_type h, - Frame* exFrame + const std::string& name, + point_type cw, + point_type ch, + point_type w, + point_type h, + Frame* exFrame ) { - Frame* frame = 0; - - // Use an "existing frame" if we have it (for example, if you've in inherited from - // Frame and want to use this stuff. - if(!exFrame) frame = new Frame(name); + Frame* frame = 0; + + // Use an "existing frame" if we have it (for example, if you've in inherited from + // Frame and want to use this stuff. + if(!exFrame) frame = new Frame(name); - else frame = exFrame; - - frame->addWidget(new Corner(CORNER_UPPER_LEFT, cw, ch), 0, 0); - frame->addWidget(new Border(BORDER_TOP, w, ch), 0, 1); - frame->addWidget(new Corner(CORNER_UPPER_RIGHT, cw, ch), 0, 2); - frame->addWidget(new Border(BORDER_LEFT, cw, h), 1, 0); - frame->addWidget(new Border(BORDER_RIGHT, cw, h), 1, 2); - frame->addWidget(new Corner(CORNER_LOWER_LEFT, cw, ch), 2, 0); - frame->addWidget(new Border(BORDER_BOTTOM, w, ch), 2, 1); - frame->addWidget(new Corner(CORNER_LOWER_RIGHT, cw, ch), 2, 2); + else frame = exFrame; + + frame->addWidget(new Corner(CORNER_UPPER_LEFT, cw, ch), 0, 0); + frame->addWidget(new Border(BORDER_TOP, w, ch), 0, 1); + frame->addWidget(new Corner(CORNER_UPPER_RIGHT, cw, ch), 0, 2); + frame->addWidget(new Border(BORDER_LEFT, cw, h), 1, 0); + frame->addWidget(new Border(BORDER_RIGHT, cw, h), 1, 2); + frame->addWidget(new Corner(CORNER_LOWER_LEFT, cw, ch), 2, 0); + frame->addWidget(new Border(BORDER_BOTTOM, w, ch), 2, 1); + frame->addWidget(new Corner(CORNER_LOWER_RIGHT, cw, ch), 2, 2); - EmbeddedWindow* ew = new EmbeddedWindow(name, w, h); + EmbeddedWindow* ew = new EmbeddedWindow(name, w, h); - ew->setCanFill(true); + ew->setCanFill(true); - frame->addWidget(ew, 1, 1); + frame->addWidget(ew, 1, 1); - return frame; + return frame; } Frame* Frame::createSimpleFrameWithSingleTexture( - const std::string& name, - const std::string& texture, - point_type tw, - point_type th, - point_type cw, - point_type ch, - point_type w, - point_type h, - Frame* exFrame + const std::string& name, + const std::string& texture, + point_type tw, + point_type th, + point_type cw, + point_type ch, + point_type w, + point_type h, + Frame* exFrame ) { - Frame* frame = 0; + Frame* frame = 0; - // The same as above... - if(!exFrame) frame = createSimpleFrame(name, cw, ch, w, h); + // The same as above... + if(!exFrame) frame = createSimpleFrame(name, cw, ch, w, h); - else frame = createSimpleFrame(name, cw, ch, w, h, exFrame); + else frame = createSimpleFrame(name, cw, ch, w, h, exFrame); - for(unsigned int i = 0; i < 9; i++) frame->getObjects()[i]->setImage(texture); + for(unsigned int i = 0; i < 9; i++) frame->getObjects()[i]->setImage(texture); - frame->getByRowCol(0, 0)->setTexCoordRegion(0.0f, th - ch, cw, ch); - frame->getByRowCol(0, 1)->setTexCoordRegion(cw, th - ch, tw - (cw * 2.0f), ch); - frame->getByRowCol(0, 2)->setTexCoordRegion(tw - cw, th - ch, cw, ch); - frame->getByRowCol(1, 0)->setTexCoordRegion(0.0f, ch, cw, th - (ch * 2.0f)); - frame->getByRowCol(1, 2)->setTexCoordRegion(tw - cw, ch, cw, th - (ch * 2.0f)); - frame->getByRowCol(2, 0)->setTexCoordRegion(0.0f, 0.0f, cw, ch); - frame->getByRowCol(2, 1)->setTexCoordRegion(cw, 0.0f, tw - (cw * 2.0f), ch); - frame->getByRowCol(2, 2)->setTexCoordRegion(tw - cw, 0.0f, cw, ch); + frame->getByRowCol(0, 0)->setTexCoordRegion(0.0f, th - ch, cw, ch); + frame->getByRowCol(0, 1)->setTexCoordRegion(cw, th - ch, tw - (cw * 2.0f), ch); + frame->getByRowCol(0, 2)->setTexCoordRegion(tw - cw, th - ch, cw, ch); + frame->getByRowCol(1, 0)->setTexCoordRegion(0.0f, ch, cw, th - (ch * 2.0f)); + frame->getByRowCol(1, 2)->setTexCoordRegion(tw - cw, ch, cw, th - (ch * 2.0f)); + frame->getByRowCol(2, 0)->setTexCoordRegion(0.0f, 0.0f, cw, ch); + frame->getByRowCol(2, 1)->setTexCoordRegion(cw, 0.0f, tw - (cw * 2.0f), ch); + frame->getByRowCol(2, 2)->setTexCoordRegion(tw - cw, 0.0f, cw, ch); - frame->getEmbeddedWindow()->setTexCoordRegion(cw, ch, tw - (cw * 2.0f), th - (ch * 2.0f)); + frame->getEmbeddedWindow()->setTexCoordRegion(cw, ch, tw - (cw * 2.0f), th - (ch * 2.0f)); - return frame; + return frame; } } diff --git a/src/osgWidget/Input.cpp b/src/osgWidget/Input.cpp index abf00f958..5ee494a3a 100644 --- a/src/osgWidget/Input.cpp +++ b/src/osgWidget/Input.cpp @@ -16,161 +16,161 @@ _size (0), _cursorIndex (0), _maxSize (size), _cursor (new Widget("cursor")) { - _text->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE); - _text->setKerningType(osgText::KERNING_NONE); + _text->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE); + _text->setKerningType(osgText::KERNING_NONE); - // Make the cursor un-copyable. - _cursor->setCanClone(false); - _cursor->setDataVariance(osg::Object::DYNAMIC); - _cursor->setColor(0.0f, 0.0f, 0.0f, 0.0f); + // Make the cursor un-copyable. + _cursor->setCanClone(false); + _cursor->setDataVariance(osg::Object::DYNAMIC); + _cursor->setColor(0.0f, 0.0f, 0.0f, 0.0f); - setEventMask( - // For showing/hiding the "cursor." - EVENT_MASK_FOCUS | - // For keypresses, obviously. - EVENT_MASK_KEY | - // For "click" focusing. - EVENT_MOUSE_PUSH - ); + setEventMask( + // For showing/hiding the "cursor." + EVENT_MASK_FOCUS | + // For keypresses, obviously. + EVENT_MASK_KEY | + // For "click" focusing. + EVENT_MOUSE_PUSH + ); - _offsets.resize(size, 0.0f); + _offsets.resize(size, 0.0f); - _text->getText().resize(size, ' '); - _text->update(); + _text->getText().resize(size, ' '); + _text->update(); } 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(); - point_type width = size.x() + _cursor->getWidth(); - point_type height = _cursor->getHeight(); + // 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(); + point_type width = size.x() + _cursor->getWidth(); + point_type height = _cursor->getHeight(); - if(width > getWidth()) setWidth(osg::round(width)); + if(width > getWidth()) setWidth(osg::round(width)); - if(height > getHeight()) setHeight(osg::round(height)); + if(height > getHeight()) setHeight(osg::round(height)); } void Input::_calculateCursorOffsets() { - // Determine the "offset" - const osgText::Text::TextureGlyphQuadMap& tgqm = _text->getTextureGlyphQuadMap(); + // Determine the "offset" + const osgText::Text::TextureGlyphQuadMap& tgqm = _text->getTextureGlyphQuadMap(); - const osgText::Text::TextureGlyphQuadMap::const_iterator tgqmi = tgqm.begin(); - - const osgText::Text::GlyphQuads& gq = tgqmi->second; + const osgText::Text::TextureGlyphQuadMap::const_iterator tgqmi = tgqm.begin(); + + const osgText::Text::GlyphQuads& gq = tgqmi->second; - point_type accum = 0.0f; + point_type accum = 0.0f; - std::ostream& os = warn() << "_offsets[ "; - - for(unsigned int i = 0; i < _maxSize; i++) { - osg::Vec2 ul = gq.getCoords()[0 + (i * 4)]; - osg::Vec2 ll = gq.getCoords()[1 + (i * 4)]; - osg::Vec2 lr = gq.getCoords()[2 + (i * 4)]; - osg::Vec2 ur = gq.getCoords()[3 + (i * 4)]; - - accum += osg::round(lr.x() - ll.x()); + std::ostream& os = warn() << "_offsets[ "; + + for(unsigned int i = 0; i < _maxSize; i++) { + osg::Vec2 ul = gq.getCoords()[0 + (i * 4)]; + osg::Vec2 ll = gq.getCoords()[1 + (i * 4)]; + osg::Vec2 lr = gq.getCoords()[2 + (i * 4)]; + osg::Vec2 ur = gq.getCoords()[3 + (i * 4)]; + + accum += osg::round(lr.x() - ll.x()); - _offsets[i] = accum; + _offsets[i] = accum; - os << _offsets[i] << " (" << static_cast(_text->getText()[i]) << ") "; - } + os << _offsets[i] << " (" << static_cast(_text->getText()[i]) << ") "; + } - os << "]" << std::endl; + os << "]" << std::endl; } bool Input::focus(WindowManager*) { - _cursor->setColor(1.0f, 1.0f, 1.0f, 0.5f); + _cursor->setColor(1.0f, 1.0f, 1.0f, 0.5f); - return true; + return true; } bool Input::unfocus(WindowManager*) { - _cursor->setColor(0.0f, 0.0f, 0.0f, 0.0f); + _cursor->setColor(0.0f, 0.0f, 0.0f, 0.0f); - return true; + return true; } void Input::parented(Window* parent) { - Label::parented(parent); + Label::parented(parent); - _cursor->setSize(2.0f, _text->getCharacterHeight()); + _cursor->setSize(2.0f, _text->getCharacterHeight()); - if(_cursorIndex) parent->getGeode()->setDrawable(_cursorIndex, _cursor.get()); + if(_cursorIndex) parent->getGeode()->setDrawable(_cursorIndex, _cursor.get()); - else _cursorIndex = parent->addDrawableAndGetIndex(_cursor.get()); + else _cursorIndex = parent->addDrawableAndGetIndex(_cursor.get()); } void Input::positioned() { - point_type ln = static_cast(_text->getLineCount()); + point_type ln = static_cast(_text->getLineCount()); - ln = ln == 0.0f ? 1.0f : ln; + ln = ln == 0.0f ? 1.0f : ln; - point_type th = - (_text->getCharacterHeight() * ln) + - (_text->getLineSpacing() * (ln - 1.0f)) - ; + point_type th = + (_text->getCharacterHeight() * ln) + + (_text->getLineSpacing() * (ln - 1.0f)) + ; - point_type x = getX() + _xoff; - point_type y = getY() + th + _yoff; + point_type x = getX() + _xoff; + point_type y = getY() + th + _yoff; - // XYCoord size = getTextSize(); + // XYCoord size = getTextSize(); - _text->setPosition(osg::Vec3(x, y, _calculateZ(LAYER_MIDDLE))); - - point_type xoffset = _index > 0 ? _offsets[_index - 1] : 0.0f; + _text->setPosition(osg::Vec3(x, y, _calculateZ(LAYER_MIDDLE))); + + point_type xoffset = _index > 0 ? _offsets[_index - 1] : 0.0f; - _cursor->setOrigin(x + xoffset + 1.0f, y - _cursor->getHeight() + 1.0f); - _cursor->setZ(_calculateZ(LAYER_MIDDLE)); + _cursor->setOrigin(x + xoffset + 1.0f, y - _cursor->getHeight() + 1.0f); + _cursor->setZ(_calculateZ(LAYER_MIDDLE)); } bool Input::keyUp(int key, int mask, WindowManager*) { - return false; + return false; } bool Input::keyDown(int key, int mask, WindowManager*) { - /* - osgText::String& s = _text->getText(); + /* + osgText::String& s = _text->getText(); - if(key == osgGA::GUIEventAdapter::KEY_BackSpace) { - if(_index >= 1) { - // s.erase(s.begin() + (_index - 1)); + if(key == osgGA::GUIEventAdapter::KEY_BackSpace) { + if(_index >= 1) { + // s.erase(s.begin() + (_index - 1)); - s[_index - 1] = ' '; + s[_index - 1] = ' '; - _text->update(); - - _calculateCursorOffsets(); + _text->update(); + + _calculateCursorOffsets(); - _index--; - } - } + _index--; + } + } - else { - if(key > 255 || _index >= _maxSize) return false; + else { + if(key > 255 || _index >= _maxSize) return false; - // else if(_index < s.size()) s.insert(s.begin() + _index, key); - // else if(_index == s.size()) s.push_back(key); + // else if(_index < s.size()) s.insert(s.begin() + _index, key); + // else if(_index == s.size()) s.push_back(key); - s[_index] = key; - - _text->update(); - - _calculateCursorOffsets(); + s[_index] = key; + + _text->update(); + + _calculateCursorOffsets(); - _index++; - } + _index++; + } - // _text->update(); + // _text->update(); - _calculateSize(getTextSize()); + _calculateSize(getTextSize()); - getParent()->resize(); - */ + getParent()->resize(); + */ - warn() << "Input is disabled until someone can help me understand how to use osgText; sorry..." << std::endl; + warn() << "Input is disabled until someone can help me understand how to use osgText; sorry..." << std::endl; - return false; + return false; } } diff --git a/src/osgWidget/Label.cpp b/src/osgWidget/Label.cpp index 2618273cd..65f8130f5 100644 --- a/src/osgWidget/Label.cpp +++ b/src/osgWidget/Label.cpp @@ -11,130 +11,130 @@ Label::Label(const std::string& name, const std::string& label): Widget (name, 0, 0), _textIndex (0), _text (new osgText::Text()) { - _text->setText(label); - _text->setAlignment(osgText::Text::LEFT_BOTTOM); - _text->setDataVariance(osg::Object::DYNAMIC); + _text->setText(label); + _text->setAlignment(osgText::Text::LEFT_BOTTOM); + _text->setDataVariance(osg::Object::DYNAMIC); - // TODO: Make a patch for this! - // If you're wondering why we don't use this let me explain... - // - // _text->setAlignment(osgText::Text::CENTER_CENTER); - // - // When you set the position of an osgText::Text object which has a CENTER_CENTER - // alignment, the internal implementation of osgText may give it values that have - // a "decimal" portion, which is NO GOOD on orthographic 2D displays where we - // want "pixel perfect" ratios. Thus, until I can remedy this internally with - // osgText::Text, I will need to calculate the center myself. + // TODO: Make a patch for this! + // If you're wondering why we don't use this let me explain... + // + // _text->setAlignment(osgText::Text::CENTER_CENTER); + // + // When you set the position of an osgText::Text object which has a CENTER_CENTER + // alignment, the internal implementation of osgText may give it values that have + // a "decimal" portion, which is NO GOOD on orthographic 2D displays where we + // want "pixel perfect" ratios. Thus, until I can remedy this internally with + // osgText::Text, I will need to calculate the center myself. - setColor(0.0f, 0.0f, 0.0f, 0.0f); + setColor(0.0f, 0.0f, 0.0f, 0.0f); } Label::Label(const Label& label, const osg::CopyOp& co): Widget (label, co), _textIndex (label._textIndex) { - _text = new osgText::Text(*label._text, co); + _text = new osgText::Text(*label._text, co); } void Label::_calculateSize(const XYCoord& size) { - if(size.x() && size.y()) setMinimumSize(size.x(), size.y()); + if(size.x() && size.y()) setMinimumSize(size.x(), size.y()); - if(getWidth() < size.x()) setWidth(size.x()); - - if(getHeight() < size.y()) setHeight(size.y()); + if(getWidth() < size.x()) setWidth(size.x()); + + if(getHeight() < size.y()) setHeight(size.y()); } // TODO: This will almost certainly get out of sync. :( void Label::parented(Window* parent) { - // If we've been cloned, use the index of the old text Drawable. - if(_textIndex) parent->getGeode()->setDrawable(_textIndex, _text.get()); + // If we've been cloned, use the index of the old text Drawable. + if(_textIndex) parent->getGeode()->setDrawable(_textIndex, _text.get()); - // Otherwise, add it as new. - else _textIndex = parent->addDrawableAndGetIndex(_text.get()); + // Otherwise, add it as new. + else _textIndex = parent->addDrawableAndGetIndex(_text.get()); } void Label::unparented(Window* parent) { - if(_textIndex) parent->getGeode()->removeDrawable(_text.get()); + if(_textIndex) parent->getGeode()->removeDrawable(_text.get()); - _textIndex = 0; + _textIndex = 0; } void Label::managed(WindowManager* wm) { - if(wm->isInvertedY()) { - // We rotate along our X axis, so we need to make sure and translate the - // text later to preserve centering. - _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION); - _text->setRotation(osg::Quat( - osg::DegreesToRadians(180.0f), - osg::Vec3(1.0f, 0.0f, 0.0f) - )); - } + if(wm->isInvertedY()) { + // We rotate along our X axis, so we need to make sure and translate the + // text later to preserve centering. + _text->setAxisAlignment(osgText::Text::USER_DEFINED_ROTATION); + _text->setRotation(osg::Quat( + osg::DegreesToRadians(180.0f), + osg::Vec3(1.0f, 0.0f, 0.0f) + )); + } } void Label::positioned() { - XYCoord size = getTextSize(); - point_type x = osg::round(((getWidth() - size.x()) / 2.0f) + getX()); - point_type y = 0.0f; + XYCoord size = getTextSize(); + point_type x = osg::round(((getWidth() - size.x()) / 2.0f) + getX()); + point_type y = 0.0f; - if(getWindowManager() && getWindowManager()->isInvertedY()) y = - osg::round(((getHeight() - size.y()) / 2.0f) + getY() + size.y()) - ; + if(getWindowManager() && getWindowManager()->isInvertedY()) y = + osg::round(((getHeight() - size.y()) / 2.0f) + getY() + size.y()) + ; - else y = osg::round(((getHeight() - size.y()) / 2.0f) + getY()); - - // These values are permisable with CENTER_CENTER mode is active. - // point_type x = round(getX() + (getWidth() / 2.0f)); - // point_type y = round(getY() + (getHeight() / 2.0f)); - - /* - warn() << "Label widget size : " << getWidth() << " x " << getHeight() << std::endl; - warn() << "Label widget tsize: " << getWidthTotal() << " x " << getHeightTotal() << std::endl; - warn() << "Label XY coords : " << getX() << " x " << getY() << std::endl; - warn() << "Label BB in size : " << size.x() << " x " << size.y() << std::endl; - warn() << "Label xy position : " << x << " y " << y << std::endl; - warn() << "------------------------------------" << std::endl; - */ + else y = osg::round(((getHeight() - size.y()) / 2.0f) + getY()); + + // These values are permisable with CENTER_CENTER mode is active. + // point_type x = round(getX() + (getWidth() / 2.0f)); + // point_type y = round(getY() + (getHeight() / 2.0f)); + + /* + warn() << "Label widget size : " << getWidth() << " x " << getHeight() << std::endl; + warn() << "Label widget tsize: " << getWidthTotal() << " x " << getHeightTotal() << std::endl; + warn() << "Label XY coords : " << getX() << " x " << getY() << std::endl; + warn() << "Label BB in size : " << size.x() << " x " << size.y() << std::endl; + warn() << "Label xy position : " << x << " y " << y << std::endl; + warn() << "------------------------------------" << std::endl; + */ - _text->setPosition(osg::Vec3(x, y, _calculateZ(getLayer() + 1))); + _text->setPosition(osg::Vec3(x, y, _calculateZ(getLayer() + 1))); } void Label::setLabel(const std::string& label) { - _text->setText(label); + _text->setText(label); - _calculateSize(getTextSize()); + _calculateSize(getTextSize()); } void Label::setFont(const std::string& font) { - _text->setFont(font); - - _calculateSize(getTextSize()); + _text->setFont(font); + + _calculateSize(getTextSize()); } void Label::setFontSize(unsigned int size) { - _text->setCharacterSize(size); - _text->setFontResolution(size, size); - - _calculateSize(getTextSize()); + _text->setCharacterSize(size); + _text->setFontResolution(size, size); + + _calculateSize(getTextSize()); } void Label::setFontColor(const Color& c) { - _text->setColor(c); + _text->setColor(c); } void Label::setShadow(point_type offset) { - _text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT); - _text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER); - _text->setBackdropOffset(offset); + _text->setBackdropType(osgText::Text::DROP_SHADOW_BOTTOM_RIGHT); + _text->setBackdropImplementation(osgText::Text::NO_DEPTH_BUFFER); + _text->setBackdropOffset(offset); - _calculateSize(getTextSize()); + _calculateSize(getTextSize()); } XYCoord Label::getTextSize() const { - osg::BoundingBox bb = _text->getBound(); + osg::BoundingBox bb = _text->getBound(); - return XYCoord( - osg::round(bb.xMax() - bb.xMin()), - osg::round(bb.yMax() - bb.yMin()) - ); + return XYCoord( + osg::round(bb.xMax() - bb.xMin()), + osg::round(bb.yMax() - bb.yMin()) + ); } } diff --git a/src/osgWidget/Lua.cpp b/src/osgWidget/Lua.cpp index 972b1a46b..6d63071bd 100644 --- a/src/osgWidget/Lua.cpp +++ b/src/osgWidget/Lua.cpp @@ -28,34 +28,34 @@ namespace lua { const char* G_WM = "osgWidget_G_WindowManager"; WindowManager* getWindowManager(lua_State* L) { - lua_pushstring(L, G_WM); - lua_gettable(L, LUA_REGISTRYINDEX); + lua_pushstring(L, G_WM); + lua_gettable(L, LUA_REGISTRYINDEX); - return reinterpret_cast(lua_touserdata(L, -1)); + return reinterpret_cast(lua_touserdata(L, -1)); } int newWindow(lua_State* L) { - osg::ref_ptr w = new Box("testLUA", Box::HORIZONTAL); + osg::ref_ptr w = new Box("testLUA", Box::HORIZONTAL); - lua_pushstring(L, w->getName().c_str()); + lua_pushstring(L, w->getName().c_str()); - return 1; + return 1; } int newWidget(lua_State* L) { - osg::ref_ptr w = new Widget("testLUA", 0.0f, 0.0f); - - lua_pushstring(L, w->getName().c_str()); + osg::ref_ptr w = new Widget("testLUA", 0.0f, 0.0f); + + lua_pushstring(L, w->getName().c_str()); - return 1; + return 1; } int getWindow(lua_State* L) { - WindowManager* wm = getWindowManager(L); + WindowManager* wm = getWindowManager(L); - lua_pushlightuserdata(L, wm); + lua_pushlightuserdata(L, wm); - return 1; + return 1; } #endif @@ -64,107 +64,107 @@ int getWindow(lua_State* L) { // A helper function for all those cases where we need to inform the user that there isn't // a LUA engine available. bool noLuaFail(const std::string& err) { - warn() << err << "; Lua not compiled in library." << std::endl; + warn() << err << "; Lua not compiled in library." << std::endl; - return false; + return false; } // Our "private", internal data. struct LuaEngineData { #ifdef OSGWIDGET_USELUA - LuaEngineData(): - lua(0) { - } + LuaEngineData(): + lua(0) { + } - lua_State* lua; + lua_State* lua; #endif }; LuaEngine::LuaEngine(WindowManager* wm): _wm(wm) { #ifdef OSGWIDGET_USELUA - _data = new LuaEngineData(); + _data = new LuaEngineData(); #else - _data = 0; + _data = 0; #endif } bool LuaEngine::initialize() { #ifdef OSGWIDGET_USELUA - _data->lua = lua_open(); + _data->lua = lua_open(); - luaL_openlibs(_data->lua); - - static const struct luaL_reg library[] = { - {"newWindow", lua::newWindow}, - {"newWidget", lua::newWidget}, - {"getWindow", lua::getWindow}, - {0, 0} - }; + luaL_openlibs(_data->lua); + + static const struct luaL_reg library[] = { + {"newWindow", lua::newWindow}, + {"newWidget", lua::newWidget}, + {"getWindow", lua::getWindow}, + {0, 0} + }; - luaL_openlib(_data->lua, "osgwidget", library, 0); + luaL_openlib(_data->lua, "osgwidget", library, 0); - // An alternative to using the Registry here would be to pass the WindowManager - // as a userdata "closure" (pvalue). Please see the following doc on more info: - // http://www.lua.org/pil/27.3.3.html - lua_pushstring(_data->lua, lua::G_WM); - lua_pushlightuserdata(_data->lua, _wm); - lua_settable(_data->lua, LUA_REGISTRYINDEX); + // An alternative to using the Registry here would be to pass the WindowManager + // as a userdata "closure" (pvalue). Please see the following doc on more info: + // http://www.lua.org/pil/27.3.3.html + lua_pushstring(_data->lua, lua::G_WM); + lua_pushlightuserdata(_data->lua, _wm); + lua_settable(_data->lua, LUA_REGISTRYINDEX); - return true; + return true; #else - return noLuaFail("Can't initialize the LuaEngine"); + return noLuaFail("Can't initialize the LuaEngine"); #endif } bool LuaEngine::close() { #ifdef OSGWIDGET_USELUA - lua_close(_data->lua); + lua_close(_data->lua); - delete _data; + delete _data; - return true; + return true; #else - return noLuaFail("Can't close the LuaEngine"); + return noLuaFail("Can't close the LuaEngine"); #endif } bool LuaEngine::eval(const std::string& code) { #ifdef OSGWIDGET_USELUA - if(luaL_dostring(_data->lua, code.c_str())) { - warn() << "LuaEngine::eval - " << lua_tostring(_data->lua, -1) << std::endl; + if(luaL_dostring(_data->lua, code.c_str())) { + warn() << "LuaEngine::eval - " << lua_tostring(_data->lua, -1) << std::endl; - return false; - } + return false; + } - return true; + return true; #else - return noLuaFail("Can't evaluate code in LuaEngine"); + return noLuaFail("Can't evaluate code in LuaEngine"); #endif } bool LuaEngine::runFile(const std::string& filePath) { #ifdef OSGWIDGET_USELUA - if(!osgDB::fileExists(filePath)) { - warn() << "Couldn't find file \"" << filePath << "\" for LuaEngine." << std::endl; + if(!osgDB::fileExists(filePath)) { + warn() << "Couldn't find file \"" << filePath << "\" for LuaEngine." << std::endl; - return false; - } + return false; + } - if(luaL_dofile(_data->lua, filePath.c_str())) { - warn() << "LuaEngine::runFile - " << lua_tostring(_data->lua, -1) << std::endl; + if(luaL_dofile(_data->lua, filePath.c_str())) { + warn() << "LuaEngine::runFile - " << lua_tostring(_data->lua, -1) << std::endl; - return false; - } + return false; + } - return true; + return true; #else - return noLuaFail("Can't run file in LuaEngine"); + return noLuaFail("Can't run file in LuaEngine"); #endif } diff --git a/src/osgWidget/Python.cpp b/src/osgWidget/Python.cpp index e5fb28711..777310798 100644 --- a/src/osgWidget/Python.cpp +++ b/src/osgWidget/Python.cpp @@ -22,40 +22,40 @@ namespace py { static PyObject* G_ERR = 0; PyObject* newWindow(PyObject* self, PyObject* args) { - PyObject* buffer = 0; - const char* name = 0; - int width = 0; - int height = 0; + PyObject* buffer = 0; + const char* name = 0; + int width = 0; + int height = 0; - /* - if(PyArg_ParseTuple(args, "sO!ii", &name, &PyBuffer_Type, &buffer, &width, &height)) { - const void* buf = 0; - int len = 0; + /* + if(PyArg_ParseTuple(args, "sO!ii", &name, &PyBuffer_Type, &buffer, &width, &height)) { + const void* buf = 0; + int len = 0; - if(!PyObject_AsReadBuffer(buffer, &buf, &len)) { - // if(Database::instance().add(name, buf, width, height)) - return Py_BuildValue("i", len); + if(!PyObject_AsReadBuffer(buffer, &buf, &len)) { + // if(Database::instance().add(name, buf, width, height)) + return Py_BuildValue("i", len); - // else PyErr_SetString(G_ERR, "Couldn't add image to database."); - } + // else PyErr_SetString(G_ERR, "Couldn't add image to database."); + } - else PyErr_SetString(G_ERR, "Couldn't read buffer data."); + else PyErr_SetString(G_ERR, "Couldn't read buffer data."); - return 0; - } - */ + return 0; + } + */ - PyErr_SetString(G_ERR, "still testing..."); + PyErr_SetString(G_ERR, "still testing..."); - return 0; + return 0; } static PyMethodDef methods[] = { - { - "newWindow", newWindow, METH_VARARGS, - "docstring" - }, - { 0, 0, 0, 0 } + { + "newWindow", newWindow, METH_VARARGS, + "docstring" + }, + { 0, 0, 0, 0 } }; #endif @@ -64,151 +64,151 @@ static PyMethodDef methods[] = { // A helper function for all those cases where we need to inform the user that there isn't // a LUA engine available. bool noPythonFail(const std::string& err) { - warn() << err << "; Python not compiled in library." << std::endl; + warn() << err << "; Python not compiled in library." << std::endl; - return false; + return false; } // Our "private", internal data. struct PythonEngineData { #ifdef OSGWIDGET_USEPYTHON - PythonEngineData(): - mod (0), - err (0), - main (0) { - } + PythonEngineData(): + mod (0), + err (0), + main (0) { + } - bool valid() const { - return mod && err && main; - } + bool valid() const { + return mod && err && main; + } - PyObject* mod; - PyObject* err; - PyObject* main; + PyObject* mod; + PyObject* err; + PyObject* main; #endif }; PythonEngine::PythonEngine(WindowManager* wm): _wm(wm) { #ifdef OSGWIDGET_USEPYTHON - _data = new PythonEngineData(); + _data = new PythonEngineData(); #else - _data = 0; + _data = 0; #endif } bool PythonEngine::initialize() { #ifdef OSGWIDGET_USEPYTHON - Py_InitializeEx(0); + Py_InitializeEx(0); - if(!_data->valid()) { - _data->mod = Py_InitModule3("osgwidget", py::methods, "main docstring"); - _data->err = PyErr_NewException((char*)("osgwidget.error"), 0, 0); - _data->main = PyModule_GetDict(PyImport_AddModule("__main__")); + if(!_data->valid()) { + _data->mod = Py_InitModule3("osgwidget", py::methods, "main docstring"); + _data->err = PyErr_NewException((char*)("osgwidget.error"), 0, 0); + _data->main = PyModule_GetDict(PyImport_AddModule("__main__")); - Py_INCREF(_data->err); + Py_INCREF(_data->err); - // TODO: ...sigh... - py::G_ERR = _data->err; + // TODO: ...sigh... + py::G_ERR = _data->err; - PyModule_AddObject(_data->mod, "error", _data->err); - } + PyModule_AddObject(_data->mod, "error", _data->err); + } - return true; + return true; #else - return noPythonFail("Can't initialize the PythonEngine"); + return noPythonFail("Can't initialize the PythonEngine"); #endif } bool PythonEngine::close() { #ifdef OSGWIDGET_USEPYTHON - if(_data->valid()) { - Py_DECREF(_data->err); + if(_data->valid()) { + Py_DECREF(_data->err); - Py_Finalize(); - } + Py_Finalize(); + } - delete _data; + delete _data; - return true; + return true; #else - return noPythonFail("Can't close the PythonEngine"); + return noPythonFail("Can't close the PythonEngine"); #endif } bool PythonEngine::eval(const std::string& code) { #ifdef OSGWIDGET_USEPYTHON - PyObject* r = PyRun_String(code.c_str(), Py_file_input, _data->main, _data->main); + PyObject* r = PyRun_String(code.c_str(), Py_file_input, _data->main, _data->main); - if(!r) { - r = PyErr_Occurred(); + if(!r) { + r = PyErr_Occurred(); - if(r) { - PyErr_Print(); - PyErr_Clear(); - } + if(r) { + PyErr_Print(); + PyErr_Clear(); + } - return false; - } + return false; + } - return true; + return true; #else - return noPythonFail("Can't evaluate code in PythonEngine"); + return noPythonFail("Can't evaluate code in PythonEngine"); #endif } bool PythonEngine::runFile(const std::string& filePath) { #ifdef OSGWIDGET_USEPYTHON - if(!osgDB::fileExists(filePath)) { - warn() - << "Couldn't find file \"" << filePath << "\" for PythonEngine." - << std::endl - ; + if(!osgDB::fileExists(filePath)) { + warn() + << "Couldn't find file \"" << filePath << "\" for PythonEngine." + << std::endl + ; - return false; - } + return false; + } - FILE* f = fopen(filePath.c_str(), "r"); - PyObject* r = PyRun_File(f, filePath.c_str(), Py_file_input, _data->main, _data->main); + FILE* f = fopen(filePath.c_str(), "r"); + PyObject* r = PyRun_File(f, filePath.c_str(), Py_file_input, _data->main, _data->main); - fclose(f); + fclose(f); - if(!r) { - r = PyErr_Occurred(); + if(!r) { + r = PyErr_Occurred(); - if(r) { - // The following snippet lets us get the return code. That is: if the - // script is stopped with sys.exit() or similar. We could use this - // return code to do something sensible... later. - if(PyErr_ExceptionMatches(PyExc_SystemExit)) { - PyObject* ty = 0; - PyObject* er = 0; - PyObject* tr = 0; + if(r) { + // The following snippet lets us get the return code. That is: if the + // script is stopped with sys.exit() or similar. We could use this + // return code to do something sensible... later. + if(PyErr_ExceptionMatches(PyExc_SystemExit)) { + PyObject* ty = 0; + PyObject* er = 0; + PyObject* tr = 0; - PyErr_Fetch(&ty, &er, &tr); + PyErr_Fetch(&ty, &er, &tr); - Py_DECREF(ty); - Py_DECREF(er); - Py_DECREF(er); - } + Py_DECREF(ty); + Py_DECREF(er); + Py_DECREF(er); + } - else { - PyErr_Print(); - PyErr_Clear(); - } - } + else { + PyErr_Print(); + PyErr_Clear(); + } + } - return false; - } + return false; + } - return true; + return true; #else - return noPythonFail("Can't evaluate code in PythonEngine"); + return noPythonFail("Can't evaluate code in PythonEngine"); #endif } diff --git a/src/osgWidget/StyleManager.cpp b/src/osgWidget/StyleManager.cpp index ac5951781..48e129a2e 100644 --- a/src/osgWidget/StyleManager.cpp +++ b/src/osgWidget/StyleManager.cpp @@ -9,7 +9,7 @@ namespace osgWidget { Style::Style(const std::string& name, const std::string& style): _style(style) { - setName(name); + setName(name); } Style::Style(const Style& style, const osg::CopyOp& co): @@ -18,309 +18,309 @@ _style (style._style) { } bool Style::applyStyle(Widget* widget, Reader r) { - std::string str; - osg::Vec2 vec2; - osg::Vec3 vec3; - osg::Vec4 vec4; - float f; + std::string str; + osg::Vec2 vec2; + osg::Vec3 vec3; + osg::Vec4 vec4; + float f; - if(_match("pos %i %i", r) || _match("pos %f %f", r)) { - r.readSequence(vec2); - - widget->setOrigin(vec2); - } + if(_match("pos %i %i", r) || _match("pos %f %f", r)) { + r.readSequence(vec2); + + widget->setOrigin(vec2); + } - else if(_match("pos-x %i", r) || _match("pos-x %f", r)) { - r.readSequence(f); - - widget->setX(f); - } + else if(_match("pos-x %i", r) || _match("pos-x %f", r)) { + r.readSequence(f); + + widget->setX(f); + } - else if(_match("pos-y %i", r) || _match("pos-y %f", r)) { - r.readSequence(f); - - widget->setY(f); - } + else if(_match("pos-y %i", r) || _match("pos-y %f", r)) { + r.readSequence(f); + + widget->setY(f); + } - else if(_match("size %i %i", r) || _match("size %f %f", r)) { - r.readSequence(vec2); - - widget->setSize(vec2); - } + else if(_match("size %i %i", r) || _match("size %f %f", r)) { + r.readSequence(vec2); + + widget->setSize(vec2); + } - else if(_match("width %i", r) || _match("width %f", r)) { - r.readSequence(f); - - widget->setWidth(f); - } + else if(_match("width %i", r) || _match("width %f", r)) { + r.readSequence(f); + + widget->setWidth(f); + } - else if(_match("height %i", r) || _match("height %f", r)) { - r.readSequence(f); - - widget->setHeight(f); - } + else if(_match("height %i", r) || _match("height %f", r)) { + r.readSequence(f); + + widget->setHeight(f); + } - // Color using 4x 0-255 integers. - else if(_match("color %i %i %i %i", r)) { - r.readSequence(vec4); - - widget->setColor(vec4 / 255.0f); - } + // Color using 4x 0-255 integers. + else if(_match("color %i %i %i %i", r)) { + r.readSequence(vec4); + + widget->setColor(vec4 / 255.0f); + } - // Color using 3x 0-255 integers with a default alpha of 255. - else if(_match("color %i %i %i", r)) { - r.readSequence(vec3); - - widget->setColor(osg::Vec4(vec3[0], vec3[1], vec3[2], 255.0f) / 255.0f); - } - - // Color using 4x 0.0f-1.0f floats. - else if(_match("color %f %f %f %f", r)) { - r.readSequence(vec4); - - widget->setColor(vec4); - } + // Color using 3x 0-255 integers with a default alpha of 255. + else if(_match("color %i %i %i", r)) { + r.readSequence(vec3); + + widget->setColor(osg::Vec4(vec3[0], vec3[1], vec3[2], 255.0f) / 255.0f); + } + + // Color using 4x 0.0f-1.0f floats. + else if(_match("color %f %f %f %f", r)) { + r.readSequence(vec4); + + widget->setColor(vec4); + } - // Color using 3x 0.0f-1.0f floats with a default alpha of 1.0f. - else if(_match("color %f %f %f", r)) { - r.readSequence(vec3); - - widget->setColor(osg::Vec4(vec3[0], vec3[1], vec3[2], 1.0f)); - } + // Color using 3x 0.0f-1.0f floats with a default alpha of 1.0f. + else if(_match("color %f %f %f", r)) { + r.readSequence(vec3); + + widget->setColor(osg::Vec4(vec3[0], vec3[1], vec3[2], 1.0f)); + } - // Set padding uniformly. - else if(_match("padding %i", r)) { - r.readSequence(f); - - widget->setPadding(f); - } + // Set padding uniformly. + else if(_match("padding %i", r)) { + r.readSequence(f); + + widget->setPadding(f); + } - // Set left padding. - else if(_match("padding-left %i", r)) { - r.readSequence(f); - - widget->setPadLeft(f); - } + // Set left padding. + else if(_match("padding-left %i", r)) { + r.readSequence(f); + + widget->setPadLeft(f); + } - // Set right padding. - else if(_match("padding-right %i", r)) { - r.readSequence(f); - - widget->setPadRight(f); - } + // Set right padding. + else if(_match("padding-right %i", r)) { + r.readSequence(f); + + widget->setPadRight(f); + } - // Set top padding. - else if(_match("padding-top %i", r)) { - r.readSequence(f); - - widget->setPadTop(f); - } + // Set top padding. + else if(_match("padding-top %i", r)) { + r.readSequence(f); + + widget->setPadTop(f); + } - // Set bottom padding. - else if(_match("padding-bottom %i", r)) { - r.readSequence(f); - - widget->setPadBottom(f); - } + // Set bottom padding. + else if(_match("padding-bottom %i", r)) { + r.readSequence(f); + + widget->setPadBottom(f); + } - else if(_match("layer %w", r)) { - r.readSequence(str); + else if(_match("layer %w", r)) { + r.readSequence(str); - widget->setLayer(strToLayer(str)); - } + widget->setLayer(strToLayer(str)); + } - else if(_match("valign %w", r)) { - r.readSequence(str); + else if(_match("valign %w", r)) { + r.readSequence(str); - widget->setAlignVertical(strToVAlign(str)); - } + widget->setAlignVertical(strToVAlign(str)); + } - else if(_match("halign %w", r)) { - r.readSequence(str); - - widget->setAlignHorizontal(strToHAlign(str)); - } + else if(_match("halign %w", r)) { + r.readSequence(str); + + widget->setAlignHorizontal(strToHAlign(str)); + } - else if(_match("coordmode %w", r)) { - r.readSequence(str); + else if(_match("coordmode %w", r)) { + r.readSequence(str); - widget->setCoordinateMode(strToCoordMode(str)); - } + widget->setCoordinateMode(strToCoordMode(str)); + } - else if(_match("fill %w", r)) { - r.readSequence(str); + else if(_match("fill %w", r)) { + r.readSequence(str); - widget->setCanFill(strToFill(str)); - } + widget->setCanFill(strToFill(str)); + } - else if(_match("image %s", r)) { - r.readSequence(str); + else if(_match("image %s", r)) { + r.readSequence(str); - widget->setImage(str, true); - } + widget->setImage(str, true); + } - // Otherwise, increment the stream pointer. - else return false; + // Otherwise, increment the stream pointer. + else return false; - return true; + return true; } bool Style::applyStyle(Label* label, Reader r) { - return false; + return false; } bool Style::applyStyle(Input* input, Reader r) { - return false; + return false; } bool Style::applyStyle(Window* window, Reader r) { - osg::Vec2 vec2; - float f; + osg::Vec2 vec2; + float f; - if(_match("pos %i %i", r) || _match("pos %f %f", r)) { - r.readSequence(vec2); - - window->setOrigin(vec2.x(), vec2.y()); - } + if(_match("pos %i %i", r) || _match("pos %f %f", r)) { + r.readSequence(vec2); + + window->setOrigin(vec2.x(), vec2.y()); + } - else if(_match("pos-x %i", r) || _match("pos-x %f", r)) { - r.readSequence(f); - - window->setX(f); - } + else if(_match("pos-x %i", r) || _match("pos-x %f", r)) { + r.readSequence(f); + + window->setX(f); + } - else if(_match("pos-y %i", r) || _match("pos-y %f", r)) { - r.readSequence(f); - - window->setY(f); - } + else if(_match("pos-y %i", r) || _match("pos-y %f", r)) { + r.readSequence(f); + + window->setY(f); + } - else if(_match("size %i %i", r) || _match("size %f %f", r)) { - r.readSequence(vec2); + else if(_match("size %i %i", r) || _match("size %f %f", r)) { + r.readSequence(vec2); - window->resize(vec2.x(), vec2.y()); - } + window->resize(vec2.x(), vec2.y()); + } - else if(_match("width %i", r) || _match("width %f", r)) { - r.readSequence(f); - - window->resize(f); - } + else if(_match("width %i", r) || _match("width %f", r)) { + r.readSequence(f); + + window->resize(f); + } - else if(_match("height %i", r) || _match("height %f", r)) { - r.readSequence(f); - - window->resize(0.0f, f); - } + else if(_match("height %i", r) || _match("height %f", r)) { + r.readSequence(f); + + window->resize(0.0f, f); + } - else return false; + else return false; - return true; + return true; } bool Style::applyStyle(Window::EmbeddedWindow*, Reader r) { - return false; + return false; } bool Style::applyStyle(Box* box, Reader r) { - if(applyStyle(static_cast(box), r)) return true; + if(applyStyle(static_cast(box), r)) return true; - return false; + return false; } bool Style::applyStyle(Frame::Corner*, Reader r) { - return false; + return false; } bool Style::applyStyle(Frame::Border*, Reader r) { - return false; + return false; } Widget::Layer Style::strToLayer(const std::string& layer) { - std::string l = lowerCase(layer); + std::string l = lowerCase(layer); - if(l == "top") return Widget::LAYER_TOP; + if(l == "top") return Widget::LAYER_TOP; - else if(l == "high") return Widget::LAYER_HIGH; + else if(l == "high") return Widget::LAYER_HIGH; - else if(l == "middle") return Widget::LAYER_MIDDLE; + else if(l == "middle") return Widget::LAYER_MIDDLE; - else if(l == "low") return Widget::LAYER_LOW; - - else if(l == "bg") return Widget::LAYER_BG; + else if(l == "low") return Widget::LAYER_LOW; + + else if(l == "bg") return Widget::LAYER_BG; - else { - warn() << "Unkown Layer name [" << layer << "]; using LAYER_MIDDLE." << std::endl; + else { + warn() << "Unkown Layer name [" << layer << "]; using LAYER_MIDDLE." << std::endl; - return Widget::LAYER_MIDDLE; - } + return Widget::LAYER_MIDDLE; + } } Widget::VerticalAlignment Style::strToVAlign(const std::string& valign) { - std::string va = lowerCase(valign); + std::string va = lowerCase(valign); - if(va == "center") return Widget::VA_CENTER; + if(va == "center") return Widget::VA_CENTER; - else if(va == "top") return Widget::VA_TOP; + else if(va == "top") return Widget::VA_TOP; - else if(va == "bottom") return Widget::VA_BOTTOM; + else if(va == "bottom") return Widget::VA_BOTTOM; - else { - warn() << "Unkown VAlign name [" << valign << "]; using VA_CENTER." << std::endl; + else { + warn() << "Unkown VAlign name [" << valign << "]; using VA_CENTER." << std::endl; - return Widget::VA_CENTER; - } + return Widget::VA_CENTER; + } } Widget::HorizontalAlignment Style::strToHAlign(const std::string& halign) { - std::string ha = lowerCase(halign); + std::string ha = lowerCase(halign); - if(ha == "center") return Widget::HA_CENTER; + if(ha == "center") return Widget::HA_CENTER; - else if(ha == "left") return Widget::HA_LEFT; + else if(ha == "left") return Widget::HA_LEFT; - else if(ha == "right") return Widget::HA_RIGHT; + else if(ha == "right") return Widget::HA_RIGHT; - else { - warn() << "Unkown HAlign name [" << halign << "]; using HA_CENTER." << std::endl; + else { + warn() << "Unkown HAlign name [" << halign << "]; using HA_CENTER." << std::endl; - return Widget::HA_CENTER; - } + return Widget::HA_CENTER; + } } Widget::CoordinateMode Style::strToCoordMode(const std::string& coordmode) { - std::string cm = lowerCase(coordmode); + std::string cm = lowerCase(coordmode); - if(cm == "absolute") return Widget::CM_ABSOLUTE; + if(cm == "absolute") return Widget::CM_ABSOLUTE; - else if(cm == "relative") return Widget::CM_RELATIVE; + else if(cm == "relative") return Widget::CM_RELATIVE; - else { - warn() - << "Unkown CoordMode name [" << coordmode - << "]; using CM_ABSOLUTE." << std::endl - ; + else { + warn() + << "Unkown CoordMode name [" << coordmode + << "]; using CM_ABSOLUTE." << std::endl + ; - return Widget::CM_ABSOLUTE; - } + return Widget::CM_ABSOLUTE; + } } bool Style::strToFill(const std::string& fill) { - std::string cm = lowerCase(fill); - - if(cm == "true") return true; + std::string cm = lowerCase(fill); + + if(cm == "true") return true; - else if(cm == "false") return false; + else if(cm == "false") return false; - else { - warn() - << "Unkown Fill name [" << fill - << "]; using false." << std::endl - ; + else { + warn() + << "Unkown Fill name [" << fill + << "]; using false." << std::endl + ; - return false; - } + return false; + } } StyleManager::StyleManager() { @@ -328,50 +328,50 @@ StyleManager::StyleManager() { StyleManager::StyleManager(const StyleManager& manager, const osg::CopyOp& co): osg::Object(manager, co) { - for(ConstIterator i = _styles.begin(); i != _styles.end(); i++) if(i->second.valid()) { - _styles[i->first] = new Style(*i->second.get(), osg::CopyOp::DEEP_COPY_ALL); - } + for(ConstIterator i = _styles.begin(); i != _styles.end(); i++) if(i->second.valid()) { + _styles[i->first] = new Style(*i->second.get(), osg::CopyOp::DEEP_COPY_ALL); + } } bool StyleManager::_applyStyleToObject(osg::Object* obj, const std::string& style) { - std::string c = obj->className(); + std::string c = obj->className(); - if(!std::string("Widget").compare(c)) return _coerceAndApply( - obj, - style, - c - ); + if(!std::string("Widget").compare(c)) return _coerceAndApply( + obj, + style, + c + ); - else if(!std::string("Label").compare(c)) return _coerceAndApply