void MenuBar::updateLayout(void) { //Determine the Max Preferred Height of my MenuItems Real32 MaxHeight(0); Real32 TotalWidth(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(MaxHeight < getChildren(i)->getPreferredSize().y()) { MaxHeight = getChildren(i)->getPreferredSize().y(); } TotalWidth += getChildren(i)->getPreferredSize().x(); } //Set My preferred Size Pnt2f TopLeft, BottomRight; Pnt2f InsetsTopLeft, InsetsBottomRight; getBounds(TopLeft, BottomRight); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) ); Vec2f NewSize( TotalWidth+InsetSize.x(), MaxHeight+InsetSize.y()); if(getPreferredSize() != NewSize) { setPreferredSize(NewSize); } getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Now position and size the Items Real32 LeftOffset(InsetsTopLeft.x()); Vec2f Size; Pnt2f Pos; for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { Size.setValues(getChildren(i)->getPreferredSize().x(), MaxHeight); if(getChildren(i)->getSize() != Size) { getChildren(i)->setSize(Size); } Pos.setValues(LeftOffset, InsetsTopLeft.y()); if(getChildren(i)->getPosition() != Pos) { getChildren(i)->setPosition(Pos); } LeftOffset += getChildren(i)->getPreferredSize().x(); } }
void ColorChooser::updateLayout(void) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); ComponentRefPtr PreviewPanel; if(getPreviewPanel() != NULL) { PreviewPanel = getPreviewPanel(); } else { PreviewPanel = _DefaultPreviewPanel; } Pnt2f PreviewTopLeft(InsetsTopLeft.x(), InsetsBottomRight.y()), PreviewBottomRight(InsetsBottomRight); PreviewTopLeft.setValues(PreviewTopLeft.x(), InsetsBottomRight.y()-PreviewPanel->getPreferredSize().y()); PreviewPanel->setPosition(PreviewTopLeft); PreviewPanel->setSize(PreviewBottomRight - PreviewTopLeft); Pnt2f ChooserTopLeft(InsetsTopLeft), ChooserBottomRight(InsetsBottomRight.x(), PreviewTopLeft.y()); if(getMFInternalChooserPanels()->size() > 1 && _LayoutTabPanel != NULL) { _LayoutTabPanel->setPosition(ChooserTopLeft); _LayoutTabPanel->setSize(ChooserBottomRight - ChooserTopLeft); } else if(getMFInternalChooserPanels()->size() == 1) { editMFInternalChooserPanels()->front()->setPosition(ChooserTopLeft); editMFInternalChooserPanels()->front()->setSize(ChooserBottomRight - ChooserTopLeft); } }
void RotatedComponent::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const { if(getInternalComponent() != NULL) { Pnt2f TopLeft, BottomRight; getInsideInsetsBounds(TopLeft, BottomRight); TheGraphics->incrDrawBounderiesNesting(); TheGraphics->initAddDrawBounderies(); TheGraphics->drawRect(TopLeft, BottomRight,Color4f(0.0f,0.0f,0.0f,1.0f),1.0); TheGraphics->uninitAddDrawBounderies(); TheGraphics->activateDrawBounderiesTest(); glPushMatrix(); glTranslatef(static_cast<Real32>(getSize().x())/2.0,static_cast<Real32>(getSize().y())/2.0,0.0); glRotatef(-osgRad2Degree(getAngle()), 0.0,0.0,1.0); glTranslatef(-static_cast<Real32>(getInternalComponent()->getSize().x())/2.0,-static_cast<Real32>(getInternalComponent()->getSize().y())/2.0,0.0); getInternalComponent()->draw(TheGraphics, getOpacity()*Opacity); glPopMatrix(); TheGraphics->decrDrawBounderiesNestring(); TheGraphics->initRemoveDrawBounderies(); TheGraphics->drawRect(TopLeft, BottomRight,Color4f(0.0f,0.0f,0.0f,1.0f),1.0); TheGraphics->uninitRemoveDrawBounderies(); TheGraphics->activateDrawBounderiesTest(); } }
void Slider::updateSliderTrack(void) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); UInt16 MajorAxis, MinorAxis; if(getOrientation() == VERTICAL_ORIENTATION) { MajorAxis = 1; } else { MajorAxis = 0; } MinorAxis = (MajorAxis+1)%2; //Update the Knob position if(getKnobButton() != NULL && getRangeModel() != NULL) { Vec2f Size; Size[MinorAxis] = getKnobButton()->getPreferredSize().x(); Size[MajorAxis] = getKnobButton()->getPreferredSize().y(); Pnt2f AlignedPosition; //Size[MajorAxis] = getSize()[MajorAxis] - 2; Vec2f Alignment(0.5,0.5); Alignment[MajorAxis] = static_cast<Real32>(getValue() - getMinimum())/static_cast<Real32>(getMaximum() - getMinimum()); AlignedPosition = calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), getKnobButton()->getPreferredSize(), Alignment.y(), Alignment.x()); getKnobButton()->setPosition(AlignedPosition); getKnobButton()->setSize(Size); } }
void UIViewport::updateViewComponentSize(void) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f Size(getCorrectedViewSize()); if(getViewComponent()->getScrollableTracksViewportHeight()) { Size[1] = (InsetsBottomRight - InsetsTopLeft).y(); } if(getViewComponent()->getScrollableHeightMinTracksViewport()) { Size[1] = osgMax(Size[1],(InsetsBottomRight - InsetsTopLeft).y()); } if(getViewComponent()->getScrollableTracksViewportWidth()) { Size[0] = (InsetsBottomRight - InsetsTopLeft).x(); } if(getViewComponent()->getScrollableWidthMinTracksViewport()) { Size[0] = osgMax(Size[0],(InsetsBottomRight - InsetsTopLeft).x()); } getViewComponent()->setSize(Size); }
void ScrollBar::updateLayout(void) { UInt16 MajorAxis, MinorAxis; if(getOrientation() == ScrollBar::VERTICAL_ORIENTATION) { MajorAxis = 1; } else { MajorAxis = 0; } MinorAxis = (MajorAxis+1)%2; Pnt2f TopLeft, BottomRight; getInsideInsetsBounds(TopLeft, BottomRight); Pnt2f Position; Vec2f Size; //Min Button if(editMinButton() != NULL) { Size[MajorAxis] = editMinButton()->getPreferredSize()[MajorAxis]; Size[MinorAxis] = BottomRight[MinorAxis] - TopLeft[MinorAxis]; Position = TopLeft; editMinButton()->setPosition(Position); editMinButton()->setSize(Size); } //Max Button if(editMaxButton() != NULL) { Size[MajorAxis] = editMaxButton()->getPreferredSize()[MajorAxis]; Size[MinorAxis] = BottomRight[MinorAxis] - TopLeft[MinorAxis]; Position = BottomRight - Size; editMaxButton()->setPosition(Position); editMaxButton()->setSize(Size); } //Scroll Field if(editScrollField() != NULL) { Size[MajorAxis] = (BottomRight[MajorAxis] - TopLeft[MajorAxis]) - editMinButton()->getSize()[MajorAxis] - editMaxButton()->getSize()[MajorAxis]; Size[MinorAxis] = BottomRight[MinorAxis] - TopLeft[MinorAxis]; Position[MajorAxis] = editMinButton()->getPosition()[MajorAxis] + editMinButton()->getSize()[MajorAxis]; Position[MinorAxis] = editMinButton()->getPosition()[MinorAxis]; editScrollField()->setPosition(Position); editScrollField()->setSize(Size); } //ScrollBar updateScrollBarLayout(); }
void UIViewport::getViewBounds(Pnt2f& TopLeft, Pnt2f& BottomRight) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); TopLeft.setValues(getViewPosition().x(),getViewPosition().y()); BottomRight = TopLeft + (InsetsBottomRight - InsetsTopLeft); }
void UIViewport::maximizeVisibility(const Pnt2f& TopLeft, const Pnt2f& BottomRight) { //Scroll as little as possible until as much as can be is visible Pnt2f ViewTopLeft, ViewBottomRight; getViewBounds(ViewTopLeft,ViewBottomRight); Pnt2f NewViewPosition(getViewPosition()); //Vertical if(ViewTopLeft.y() > TopLeft.y()) { //Scroll up NewViewPosition[1] = TopLeft.y(); } else if(ViewBottomRight.y() < BottomRight.y()) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Scroll down NewViewPosition[1] = BottomRight.y() - (InsetsBottomRight - InsetsTopLeft).y(); } //Horizontal if(ViewTopLeft.x() > TopLeft.x()) { //Scroll left NewViewPosition[0] = TopLeft.x(); } else if(ViewBottomRight.x() < BottomRight.x()) { Pnt2f InsetsTopLeft, InsetsBottomRight; getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Scroll right NewViewPosition[0] = BottomRight.x() - (InsetsBottomRight - InsetsTopLeft).x(); } setViewPosition(NewViewPosition); }
void PopupMenu::updateLayout(void) { //Determine the Max Preferred Width of my MenuItems Real32 MaxWidth(0); Real32 TotalHeight(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(MaxWidth < getChildren(i)->getRequestedSize().x()) { MaxWidth = getChildren(i)->getRequestedSize().x(); } TotalHeight += getChildren(i)->getRequestedSize().y(); if(i!=0) { TotalHeight += 1.0f; } } //Set My preferred Size Pnt2f TopLeft, BottomRight; Pnt2f InsetsTopLeft, InsetsBottomRight; getBounds(TopLeft, BottomRight); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) ); setPreferredSize(Vec2f(MaxWidth+InsetSize.x(), TotalHeight+InsetSize.y())); //Sneakily set my size _sfSize.setValue(getPreferredSize()); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Now position and size the Items Real32 TopOffset(InsetsTopLeft.y()); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { getChildren(i)->setSize(Vec2f(MaxWidth, getChildren(i)->getRequestedSize().y())); getChildren(i)->setPosition(Pnt2f(InsetsTopLeft.x(), TopOffset)); TopOffset += getChildren(i)->getRequestedSize().y() +1; } }
void ComboBox::showPopup(void) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); getComboListPopupMenu()->setInvoker(this); getComboListPopupMenu()->setVisible(true); getComboListPopupMenu()->setPosition(ComponentToFrame(BorderTopLeft + Vec2f(0,BorderBottomRight.y()), this)); getComboListPopupMenu()->setSelection(getModel()->getSelectedItemIndex()); getParentWindow()->pushToActivePopupMenus(getComboListPopupMenu()); }
void ComboBox::updateLayout(void) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); Vec2f Size; Pnt2f Pos; if(getExpandButton() != NULL) { //Place the Expand button on the Left Size = getExpandButton()->getPreferredSize(); if(getExpandButton()->getSize() != Size) { getExpandButton()->setSize(Size); } Pos = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), getExpandButton()->getSize(),0.5, 1.0); if(getExpandButton()->getPosition() != Pos) { getExpandButton()->setPosition(Pos); } } //Editor if(getEditable() && getEditor() != NULL && getEditor()->getEditorComponent() != NULL) { Size = Vec2f(BorderBottomRight.x() - BorderTopLeft.x() - getExpandButton()->getSize().x(), getExpandButton()->getSize().y()); if(getEditor()->getEditorComponent()->getSize() != Size) { getEditor()->getEditorComponent()->setSize(Size); } Pos = Pnt2f(BorderTopLeft.x(), getExpandButton()->getPosition().y()); if(getEditor()->getEditorComponent()->getPosition() != Pos) { getEditor()->getEditorComponent()->setPosition(Pos); } } //Selected Item Component if(!getEditable() && getComponentGeneratorSelectedItem() != NULL) { Size = Vec2f(BorderBottomRight.x() - BorderTopLeft.x() - getExpandButton()->getSize().x(), getExpandButton()->getSize().y()); if(getComponentGeneratorSelectedItem()->getSize() != Size) { getComponentGeneratorSelectedItem()->setSize(Size); } Pos = Pnt2f(BorderTopLeft.x(), getExpandButton()->getPosition().y()); if(getComponentGeneratorSelectedItem()->getPosition() != Pos) { getComponentGeneratorSelectedItem()->setPosition(Pos); } } }
void PopupMenu::updateSeparatorSizes(void) { Pnt2f InsideInsetsTopLeft, InsideInsetsBottomRight; getInsideInsetsBounds(InsideInsetsTopLeft, InsideInsetsBottomRight); Vec2f InsideInsetsSize(InsideInsetsBottomRight - InsideInsetsTopLeft); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { Vec2f NewSize(Vec2f(InsideInsetsSize.x(), getChildren(i)->getRequestedSize().y())); if(getChildren(i)->getType() == Separator::getClassType() && dynamic_cast<Separator*>(getChildren(i))->getPreferredSize() != NewSize) { dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(NewSize); } } }
void RotatedComponent::updateLayout(void) { Pnt2f TopLeft, BottomRight; getInsideInsetsBounds(TopLeft, BottomRight); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(getChildren(i)->getPosition() != Pnt2f(0,0)) { getChildren(i)->setPosition(Pnt2f(0,0)); } if(getChildren(i)->getSize() != getChildren(i)->getPreferredSize()) { getChildren(i)->setSize(getChildren(i)->getPreferredSize()); } } }
Pnt2f Slider::getSliderTrackTopLeft(void) const { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); Pnt2f Pos; if(getOrientation() == VERTICAL_ORIENTATION) { Pos = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Vec2f(0,0), 0.0, getAlignment()); Pos[1] += getTrackInset(); } else { Pos = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Vec2f(0,0), getAlignment(), 0.0); Pos[0] += getTrackInset(); } return Pos; }
void Toolbar::updateSeparatorSizes(void) { Pnt2f InsideInsetsTopLeft, InsideInsetsBottomRight; getInsideInsetsBounds(InsideInsetsTopLeft, InsideInsetsBottomRight); Vec2f InsideInsetsSize(InsideInsetsBottomRight - InsideInsetsTopLeft); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(getChildren(i)->getType() == Separator::getClassType()) { if(getOrientation() == BoxLayout::HORIZONTAL_ORIENTATION) { dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(Vec2f(getChildren(i)->getRequestedSize().x(), InsideInsetsSize.y())); } else { dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(Vec2f(InsideInsetsSize.x(), getChildren(i)->getRequestedSize().y())); } } } }
void TableHeader::updateLayout(void) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); UInt32 CumulativeWidth(0); UInt32 Height(0); //Use the Model to update the position and sizes of the Headers for(UInt32 i(0) ; i<getMFColumnHeaders()->size() ; ++i) { getColumnHeaders(i)->setPosition( Pnt2f(BorderTopLeft.x() + CumulativeWidth, BorderTopLeft.y()) ); getColumnHeaders(i)->setSize( Vec2f(getColumnModel()->getColumn(i)->getWidth(), getColumnHeaders(i)->getPreferredSize().y()) ); Height = osgMax<UInt32>(Height, getColumnHeaders(i)->getSize().y()); CumulativeWidth += getColumnHeaders(i)->getSize().x(); //Add on the Margin if(i != getMFColumnHeaders()->size()-1) { CumulativeWidth += getColumnModel()->getColumnMargin(); } } //Use the Model to update the position and sizes of the Margins //Update My Preferred Size Pnt2f TopLeft, BottomRight; getBounds(TopLeft, BottomRight); Vec2f NewPreferredSize(CumulativeWidth + (BottomRight.x() - TopLeft.x() - BorderBottomRight.x() + BorderTopLeft.x()), Height + (BottomRight.y() - TopLeft.y() - BorderBottomRight.y() + BorderTopLeft.y())); if(NewPreferredSize != getPreferredSize()) { setPreferredSize(NewPreferredSize); } }
void TabPanel::updateLayout(void) { Pnt2f InsideInsetsTopLeft,InsideInsetsBottomRight; getInsideInsetsBounds(InsideInsetsTopLeft,InsideInsetsBottomRight); UInt16 AxisIndex(0); if (getTabPlacement() == PLACEMENT_EAST || getTabPlacement() == PLACEMENT_WEST) { AxisIndex=1; } Real32 largestMinorAxis(0.0f); Real32 cumMajorAxis(0.0f); Pnt2f alignOffset(0.0f,0.0f); Vec2f offset(0.0f,0.0f); Vec2f TabBorderTopLeftWidth, TabBorderBottomRightWidth; calculateMaxTabBorderLengths(TabBorderTopLeftWidth[0], TabBorderBottomRightWidth[0],TabBorderTopLeftWidth[1], TabBorderBottomRightWidth[1]); // first layout all of the tabs // naturally the alignments and such is necessary // on the first sweep, get the maximum size and cumLength const Real32 TabMajorAxisSpacing(5.0f); Vec2f TabReqSize; for (UInt32 i=0; i < getMFTabs()->size(); ++i) { TabReqSize = getTabs(i)->getRequestedSize() + Vec2f(getTabBorderInsets().x() + getTabBorderInsets().y(), getTabBorderInsets().z() + getTabBorderInsets().w()); cumMajorAxis += TabReqSize[AxisIndex]; if (TabReqSize[(AxisIndex+1)%2] > largestMinorAxis) { largestMinorAxis = TabReqSize[(AxisIndex+1)%2]; } } cumMajorAxis += TabMajorAxisSpacing * 2.0f * getMFTabs()->size(); cumMajorAxis += static_cast<Real32>(getMFTabs()->size()) * (TabBorderTopLeftWidth[AxisIndex] + TabBorderBottomRightWidth[AxisIndex]); largestMinorAxis += (TabBorderTopLeftWidth[(AxisIndex+1)%2] + TabBorderBottomRightWidth[(AxisIndex+1)%2]); // set up the alignment and offset Vec2f TabSize; TabSize[AxisIndex] = cumMajorAxis; TabSize[(AxisIndex+1)%2] = largestMinorAxis; Vec2f Alignment; Alignment[(AxisIndex+1)%2] = getTabAlignment(); switch(getTabPlacement()) { case PLACEMENT_SOUTH: case PLACEMENT_EAST: Alignment[AxisIndex] = 1.0; break; case PLACEMENT_NORTH: case PLACEMENT_WEST: Alignment[AxisIndex] = 0.0; break; } alignOffset = calculateAlignment(InsideInsetsTopLeft, (InsideInsetsBottomRight-InsideInsetsTopLeft),TabSize,Alignment.x(),Alignment.y()); offset = Vec2f(InsideInsetsTopLeft); offset[(AxisIndex+1)%2] += TabBorderTopLeftWidth[(AxisIndex+1)%2]; // set sizes and positions of all tabs Vec2f Size; Pnt2f Pos; for (UInt32 i=0; i < getMFTabs()->size(); ++i) { offset[AxisIndex] += TabBorderTopLeftWidth[AxisIndex]; Size = getTabs(i)->getRequestedSize() + Vec2f(getTabBorderInsets().x() + getTabBorderInsets().y(), getTabBorderInsets().z() + getTabBorderInsets().w()); if(getTabs(i)->getSize() != Size) { getTabs(i)->setSize(Size); } Pos = alignOffset + offset; if(getTabs(i)->getPosition() != Pos) { getTabs(i)->setPosition(Pos); } offset[AxisIndex] += getTabs(i)->getSize()[AxisIndex] + TabBorderBottomRightWidth[AxisIndex]; } if((getSelectedIndex()+1) > getMFTabContents()->size()) { setSelectedIndex(getMFTabContents()->size()-1); } if(getMFTabContents()->size() > 0 && getSelectedIndex() != -1) { Vec2f ContentBorderTopLeftWidth, ContentBorderBottomRightWidth; calculateContentBorderLengths(getContentBorder(), ContentBorderTopLeftWidth[0], ContentBorderBottomRightWidth[0],ContentBorderTopLeftWidth[1], ContentBorderBottomRightWidth[1]); // now set size and position of the active tab's contents offset = Vec2f(InsideInsetsTopLeft); if (getTabPlacement() == PLACEMENT_NORTH || getTabPlacement() == PLACEMENT_WEST) { offset[(AxisIndex+1)%2] += largestMinorAxis; } Size = InsideInsetsBottomRight-InsideInsetsTopLeft-(ContentBorderTopLeftWidth + ContentBorderBottomRightWidth); Size[(AxisIndex+1)%2] -= TabSize[(AxisIndex+1)%2]; if(getTabContents(getSelectedIndex())->getSize() != Size) { getTabContents(getSelectedIndex())->setSize(Size); } Pos = Pnt2f(0.0f,0.0f) + offset + ContentBorderTopLeftWidth; if(getTabContents(getSelectedIndex())->getPosition() != Pos) { getTabContents(getSelectedIndex())->setPosition(Pos); } } }
void Slider::updateLayout(void) { UInt16 MajorAxis, MinorAxis; if(getOrientation() == VERTICAL_ORIENTATION) { MajorAxis = 1; } else { MajorAxis = 0; } MinorAxis = (MajorAxis+1)%2; updateSliderTrack(); //Update the Track if(getDrawTrack() && getTrackDrawObject() != NULL) { Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); Vec2f Size(getTrackDrawObject()->getPreferredSize()); Pnt2f AlignedPosition; Size[MajorAxis] = getTrackLength(); if(getOrientation() == VERTICAL_ORIENTATION) { AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, 0.5, getAlignment()); } else { AlignedPosition = calculateAlignment(BorderTopLeft, (BorderBottomRight-BorderTopLeft), Size, getAlignment(), 0.5); } getTrackDrawObject()->setPosition(AlignedPosition); getTrackDrawObject()->setSize(Size); } //Update the MinorTickMarks if(getDrawMinorTicks() && getRangeModel() != NULL) { Pnt2f MinorTickTopLeft, MinorTickBottomRight; getDrawObjectBounds(*editMFMinorTickDrawObjects(), MinorTickTopLeft, MinorTickBottomRight); Vec2f Alignment; Real32 MaxLength(0.0); for(UInt32 i(0) ; i<getMFMinorTickDrawObjects()->size() ; ++i) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; getMinorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight); MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x()); } editMFMinorTickPositions()->clear(); for(UInt32 i(0) ; i< osgAbs<Int32>(getMaximum() - getMinimum())/getMinorTickSpacing() ; ++i) { if( (i * getMinorTickSpacing())%getMajorTickSpacing() != 0 ) { Alignment[MajorAxis] = static_cast<Real32>(i * getMinorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum()); editMFMinorTickPositions()->push_back( calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MinorTickBottomRight - MinorTickTopLeft), Alignment.y(), Alignment.x())); if(getTicksOnRightBottom()) { editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset(); } else { editMFMinorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength; } } } } //Update the MajorTickMarks if(getDrawMajorTicks() && getRangeModel() != NULL) { Pnt2f MajorTickTopLeft, MajorTickBottomRight; getDrawObjectBounds(*editMFMajorTickDrawObjects(), MajorTickTopLeft, MajorTickBottomRight); Vec2f Alignment; Real32 MaxLength(0.0); for(UInt32 i(0) ; i<getMFMajorTickDrawObjects()->size() ; ++i) { Pnt2f DrawObjectTopLeft, DrawObjectBottomRight; getMajorTickDrawObjects(i)->getBounds(DrawObjectTopLeft, DrawObjectBottomRight); MaxLength = osgMax(MaxLength, DrawObjectBottomRight.x()-DrawObjectTopLeft.x()); } editMFMajorTickPositions()->clear(); for(UInt32 i(0) ; i<= osgAbs<Int32>(getMaximum() - getMinimum())/getMajorTickSpacing() ; ++i) { Alignment[MajorAxis] = static_cast<Real32>(i * getMajorTickSpacing())/static_cast<Real32>(getMaximum() - getMinimum()); editMFMajorTickPositions()->push_back( calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), (MajorTickBottomRight - MajorTickTopLeft), Alignment.y(), Alignment.x())); if(getTicksOnRightBottom()) { editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToTickOffset(); } else { editMFMajorTickPositions()->back()[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToTickOffset() - MaxLength; } } } //Update the Labels if(getDrawLabels() && getRangeModel() != NULL) { Vec2f Alignment; Pnt2f Pos; FieldContainerMap::const_iterator Itor; for(Itor = getLabelMap().begin() ; Itor != getLabelMap().end() ; ++Itor) { Alignment[MajorAxis] = static_cast<Real32>((*Itor).first - getMinimum())/static_cast<Real32>(getMaximum() - getMinimum()); Pos = calculateSliderAlignment(getSliderTrackTopLeft(), getSliderTrackSize(), dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize(), Alignment.y(), Alignment.x()); if(getTicksOnRightBottom()) { Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] + getTrackDrawObject()->getSize()[MinorAxis] + getTrackToLabelOffset(); } else { Pos[MinorAxis] = getTrackDrawObject()->getPosition()[MinorAxis] - getTrackToLabelOffset() - dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize()[MinorAxis]; } dynamic_pointer_cast<Component>((*Itor).second)->setPosition(Pos); dynamic_pointer_cast<Component>((*Itor).second)->setSize(dynamic_pointer_cast<Component>((*Itor).second)->getPreferredSize()); } } }
void RotatedComponent::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); //Do not respond to changes that have a Sync origin if(origin & ChangedOrigin::Sync) { return; } if(whichField & InternalComponentFieldMask) { clearChildren(); if(getInternalComponent() != NULL) { pushToChildren(getInternalComponent()); } } if((whichField & InternalComponentFieldMask) || (whichField & AngleFieldMask) || (whichField & ResizePolicyFieldMask)) { if(getInternalComponent() != NULL) { Vec2f Size; switch (static_cast<ResizePolicy>(getResizePolicy())) { case RESIZE_TO_MIN: { //Treat TopLeft as 0,0 //Get the Rotated Bounds of the Internal Component Pnt2f p1,p2,p3,p4; Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0); p1 = -ComponentCenter; p2.setValues(ComponentCenter.x(),-ComponentCenter.y()); p3 = ComponentCenter; p4.setValues(-ComponentCenter.x(),ComponentCenter.y()); //Rotate them p1 = Rotate(p1, -getAngle()); p2 = Rotate(p2, -getAngle()); p3 = Rotate(p3, -getAngle()); p4 = Rotate(p4, -getAngle()); //Get their min and max Pnt2f Min(osgMin(osgMin(osgMin(p1.x(),p2.x()),p3.x()),p4.x()), osgMin(osgMin(osgMin(p1.y(),p2.y()),p3.y()),p4.y())); Pnt2f Max(osgMax(osgMax(osgMax(p1.x(),p2.x()),p3.x()),p4.x()), osgMax(osgMax(osgMax(p1.y(),p2.y()),p3.y()),p4.y())); Pnt2f BorderTopLeft, BorderBottomRight; getInsideInsetsBounds(BorderTopLeft, BorderBottomRight); Pnt2f TopLeft, BottomRight; getBounds(TopLeft, BottomRight); setPreferredSize(Vec2f(Max.x() - Min.x() + (BorderTopLeft.x() - TopLeft.x()) + (BottomRight.x() - BorderBottomRight.x()), Max.y() - Min.y() + (BorderTopLeft.y() - TopLeft.y()) + (BottomRight.y() - BorderBottomRight.y()))); break; } case RESIZE_TO_MAX: { //Get the Internal Components Center Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0); //Get the distance from the Center to one of the TopLeft Corner Real32 Length = 2*ComponentCenter.dist(Pnt2f(0,0)); setPreferredSize(Vec2f(Length,Length)); break; } case NO_RESIZING: default: break; } getInternalComponent()->updateClipBounds(); //Check the Mouse if( getParentWindow() != NULL && getParentWindow()->getParentDrawingSurface() != NULL && getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL) { Pnt2f MouseLoc(getParentWindow()->getParentDrawingSurface()->getEventProducer()->getMousePosition()); MouseEventDetailsUnrecPtr e = MouseEventDetails::create(getParentWindow()->getParentDrawingSurface()->getEventProducer(),getSystemTime(),MouseEventDetails::NO_BUTTON,0,MouseLoc, NULL); checkMouseEnterExit(e,e->getLocation(),getInternalComponent(),getInternalComponent()->isContained(MouseLoc, true),e->getViewport()); } } } }