/* * setMarginWidth - Set the margin width. * * parameter _margineWidth - GLfloat */ void SliceWidget::setMarginWidth(GLfloat _marginWidth) { marginWidth = _marginWidth; if (isManaged) { parent->requestResize(this, calcNaturalSize()); } else resize(GLMotif::Box(GLMotif::Vector(0.0f, 0.0f, 0.0f), calcNaturalSize())); } // end setMarginWidth()
void PopupWindow::setCloseButton(bool enable) { if(enable&&closeButton==0) { /* Create the close button: */ closeButton=new NewButton("HideButton",this,false); closeButton->setBorderWidth(titleBar->getBorderWidth()); closeButton->setBorderType(titleBar->getBorderType()); closeButton->setBorderColor(titleBar->getBorderColor()); closeButton->setBackgroundColor(titleBar->getBackgroundColor()); closeButton->setArmedBackgroundColor(titleBar->getBackgroundColor()); closeButton->setForegroundColor(titleBar->getForegroundColor()); closeButton->getSelectCallbacks().add(this,&PopupWindow::closeButtonCallback); Glyph* cbGlyph=new Glyph("Glyph",closeButton,GlyphGadget::CROSS,GlyphGadget::IN); cbGlyph->setBorderWidth(0.0f); closeButton->manageChild(); /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); } if(!enable&&closeButton!=0) { /* Delete the close button: */ deleteChild(closeButton); closeButton=0; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); } }
void ColorMap::setMarginWidth(GLfloat newMarginWidth) { /* Set the new margin width: */ marginWidth=newMarginWidth; if(isManaged) { /* Try adjusting the widget size to accomodate the new margin width: */ parent->requestResize(this,calcNaturalSize()); } else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void ColorMap::setPreferredSize(const Vector& newPreferredSize) { /* Set the new preferred size: */ preferredSize=newPreferredSize; if(isManaged) { /* Try adjusting the widget size to accomodate the new preferred size: */ parent->requestResize(this,calcNaturalSize()); } else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void DropdownBox::setArrowSize(GLfloat newArrowSize) { /* Adjust the arrow glyph: */ arrow.setGlyphSize(newArrowSize); /* Adjust the label position: */ setInsets(0.0f,arrow.getPreferredBoxSize()+spacing); /* Try adjusting the widget size to accomodate the new setting: */ if(isManaged) parent->requestResize(this,calcNaturalSize()); else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
/* * setPreferredSize - Set color map preferred size. * * parameter _preferredSize - const GLMotif::Vector& */ void SliceWidget::setPreferredSize(const GLMotif::Vector& _preferredSize) { preferredSize = _preferredSize; if (isManaged) { parent->requestResize(this, calcNaturalSize()); } else resize(GLMotif::Box(GLMotif::Vector(0.0f, 0.0f, 0.0f), calcNaturalSize())); GLfloat x1 = SliceWidgetAreaBox.getCorner(0)[0]; GLfloat x2 = SliceWidgetAreaBox.getCorner(1)[0]; GLfloat y1 = SliceWidgetAreaBox.getCorner(0)[1]; GLfloat y2 = SliceWidgetAreaBox.getCorner(2)[1]; GLfloat z = SliceWidgetAreaBox.getCorner(0)[2]; GLfloat width = x2 - x1; GLfloat height = y2 - y1; } // end setPreferredSize()
void Pager::removeChild(Widget* removeChild) { /* Find the given widget in the list of children: */ WidgetList::iterator cIt; unsigned int childIndex=0; for(cIt=children.begin();cIt!=children.end()&&*cIt!=removeChild;++cIt,++childIndex) ; if(cIt!=children.end()) { /* Remove the child from the list: */ children.erase(cIt); /* Remove the child's associated page button from the list: */ deleteChild(pageButtons[childIndex]); pageButtons.erase(pageButtons.begin()+childIndex); /* Update the child insertion position: */ if(nextChildIndex>GLint(children.size())) nextChildIndex=GLint(children.size()); if(isManaged) { /* Try to resize the widget to calculate the new layout: */ parent->requestResize(this,calcNaturalSize()); } } }
void Popup::setTitleSpacing(GLfloat newTitleSpacing) { /* Change the title spacing: */ titleSpacing=newTitleSpacing; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void Popup::setMarginWidth(GLfloat newMarginWidth) { /* Change the margin width: */ marginWidth=newMarginWidth; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void PopupWindow::setChildBorderWidth(GLfloat newChildBorderWidth) { /* Change the child border width: */ childBorderWidth=newChildBorderWidth; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void ColorBar::setValueRange(double newValueMin,double newValueMax) { /* Set the new value range: */ valueMin=newValueMin; valueMax=newValueMax; /* Update the tick marks: */ updateTickMarks(); if(isManaged) { /* Try adjusting the widget size to accomodate the new label: */ parent->requestResize(this,calcNaturalSize()); } else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void PopupWindow::setTitleString(const char* newTitleString) { /* Change the title bar's label string: */ titleBar->setString(newTitleString); /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void DropdownBox::clearItems(void) { /* Remove all buttons from the drop-down list: */ while(numItems>0) { items->removeWidgets(numItems-1); --numItems; } /* Reset the selected item: */ selectedItem=-1; /* Resize the widget to accomodate the new list: */ if(isManaged) parent->requestResize(this,calcNaturalSize()); else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void ScaleBar::pointerButtonDown(GLMotif::Event& event) { Scalar newScale=currentScale; /* Check if the event happened in the left or right corner: */ float relEventPos=(event.getWidgetPoint().getPoint()[0]-getInterior().origin[0])/getInterior().size[0]; if(relEventPos<=0.333f) { /* Calculate the next smaller quasi-binary scale factor: */ newScale=Scalar(getSmallerQuasiBinary(currentScale)); } else if(relEventPos>=0.667f) { /* Calculate the next bigger quasi-binary scale factor: */ newScale=Scalar(getBiggerQuasiBinary(currentScale)); } if(newScale!=currentScale&&activateNavigationTool(reinterpret_cast<const Tool*>(this))) { /* Adjust the navigation transformation: */ Scalar newNavScale; const Geometry::LinearUnit& unit=getCoordinateManager()->getUnit(); if(unit.isImperial()) { /* Calculate scale factor through imperial units: */ newNavScale=getInchFactor()*newScale/unit.getInchFactor(); } else { /* Calculate scale factor through metric units: */ newNavScale=getMeterFactor()*newScale/unit.getMeterFactor(); } /* Get the current navigation transformation and calculate the display center position in navigation coordinates: */ const NavTransform& nav=getNavigationTransformation(); Point center=nav.inverseTransform(getDisplayCenter()); /* Create the new navigation transformation: */ NavTransform newNav=NavTransform(nav.getTranslation(),nav.getRotation(),newNavScale); newNav.leftMultiply(NavTransform::translate(getDisplayCenter()-newNav.transform(center))); setNavigationTransformation(newNav); deactivateNavigationTool(reinterpret_cast<const Tool*>(this)); currentScale=newScale; /* Update the scale bar: */ calcSize(newNav); /* Resize the widget so that the clicked point stays in the same place: */ GLMotif::Vector newSize=calcNaturalSize(); GLfloat newInteriorWidth=newSize[0]-2.0f*getBorderWidth(); GLfloat newOrigin=event.getWidgetPoint().getPoint()[0]-newInteriorWidth*relEventPos-getBorderWidth(); resize(GLMotif::Box(GLMotif::Vector(newOrigin,0.0f,0.0f),newSize)); } }
void Pager::setMarginWidth(GLfloat newMarginWidth) { /* Set the margin width: */ marginWidth=newMarginWidth; if(isManaged) { /* Try to resize the widget to accomodate the new setting: */ parent->requestResize(this,calcNaturalSize()); } }
void PopupWindow::setTitleBorderWidth(GLfloat newTitleBorderWidth) { /* Set border width of the title bar: */ titleBar->setBorderWidth(newTitleBorderWidth); if(hideButton!=0) hideButton->setBorderWidth(newTitleBorderWidth); if(closeButton!=0) closeButton->setBorderWidth(newTitleBorderWidth); /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void DropdownBox::addItem(const char* newItem) { /* Get the style sheet: */ // const GLMotif::StyleSheet& ss=*getManager()->getStyleSheet(); /* Create a new button in the drop-down list: */ char itemButtonName[40]; snprintf(itemButtonName,sizeof(itemButtonName),"ItemButton%d",numItems); Button* button=new Button(itemButtonName,items,newItem); button->setBorderType(Widget::PLAIN); button->setBorderWidth(0.0f); button->setHAlignment(GLFont::Left); button->getSelectCallbacks().add(itemSelectedCallbackWrapper,this); ++numItems; /* Resize the widget to accomodate the new item: */ if(isManaged) parent->requestResize(this,calcNaturalSize()); else resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void Popup::addChild(Widget* newChild) { /* Delete the current child: */ delete child; child=0; /* Add the new child: */ child=newChild; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void PopupWindow::addChild(Widget* newChild) { if(newChild!=titleBar&&newChild!=hideButton&&newChild!=closeButton) { /* Delete the current child: */ deleteChild(child); /* Add the new child: */ child=newChild; /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); } }
ScaleBar::ScaleBar(const char* sName,GLMotif::WidgetManager* sManager) :GLMotif::Widget(sName,0,false),manager(sManager), targetLength(getDisplaySize()*Scalar(0.2)), currentMantissa(1),currentExponent(0),currentNavLength(1),currentScale(1), lengthLabel(0),scaleLabel(0), currentPhysLength(0) { /* Set widget parameters: */ setBorderWidth(0.0f); setBorderType(GLMotif::Widget::PLAIN); /* Set default background and foreground colors: */ Color bgColor=Vrui::getBackgroundColor(); bgColor[3]=0.0f; Color fgColor; for(int i=0;i<3;++i) fgColor[i]=1.0f-bgColor[i]; fgColor[3]=1.0f; setBorderColor(bgColor); setBackgroundColor(bgColor); setForegroundColor(fgColor); /* Create the initial scale bar length label: */ if(getCoordinateManager()->getUnit().unit!=Geometry::LinearUnit::UNKNOWN) { char labelText[10]; snprintf(labelText,sizeof(labelText),"1 %s",getCoordinateManager()->getUnit().getAbbreviation()); lengthLabel=new GLLabel(labelText,*getUiFont()); } else lengthLabel=new GLLabel("1",*getUiFont()); lengthLabel->setBackground(bgColor); lengthLabel->setForeground(fgColor); scaleLabel=new GLLabel("1:1",*getUiFont()); scaleLabel->setBackground(bgColor); scaleLabel->setForeground(fgColor); /* Calculate the initial navigation-space scale bar length: */ calcSize(getNavigationTransformation()); /* Resize the widget: */ GLMotif::Vector newSize=calcNaturalSize(); GLMotif::Vector newOrigin=GLMotif::Vector(0.0f,0.0f,0.0f); newOrigin[0]=-newSize[0]*0.5f; resize(GLMotif::Box(newOrigin,newSize)); /* Register a navigation change callback with the Vrui kernel: */ getNavigationTransformationChangedCallbacks().add(this,&ScaleBar::navigationChangedCallback); }
void ScaleBar::navigationChangedCallback(NavigationTransformationChangedCallbackData* cbData) { /* Check if the navigation scale changed: */ if(cbData->oldTransform.getScaling()!=cbData->newTransform.getScaling()) { /* Update the scale bar: */ calcSize(cbData->newTransform); /* Resize the widget: */ GLMotif::Vector newSize=calcNaturalSize(); GLMotif::Vector newOrigin=GLMotif::Vector(0.0f,0.0f,0.0f); newOrigin[0]=-newSize[0]*0.5f; resize(GLMotif::Box(newOrigin,newSize)); } }
void PopupWindow::removeChild(Widget* removeChild) { /* Check if the given widget is really the child: */ if(child!=0&&child==removeChild) { /* Tell the child that it is being removed: */ child->unmanageChild(); /* Remove the child: */ child=0; } /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void Popup::setTitle(const char* titleString) { /* Delete the current title: */ delete title; title=0; if(titleString!=0) { /* Create a new title widget: */ title=new Label("_Title",this,titleString,false); title->setHAlignment(GLFont::Center); } /* Resize the widget: */ resize(Box(Vector(0.0f,0.0f,0.0f),calcNaturalSize())); }
void Pager::addChild(Widget* newChild) { /* Do nothing if the new child is actually a page button: */ if(addingPageButton) return; /* Add the child to the list at the selected position: */ children.insert(children.begin()+nextChildIndex,newChild); /* Create a new page button: */ char pbName[20]; snprintf(pbName,sizeof(pbName),"PageButton%u",nextPageIndex); ++nextPageIndex; Button* newPageButton; addingPageButton=true; if(!nextPageName.empty()) { newPageButton=new Button(pbName,this,nextPageName.c_str()); nextPageName=""; } else { /* Create a default page button label: */ char pbLabel[20]; snprintf(pbLabel,sizeof(pbLabel),"Page %u",nextPageIndex); newPageButton=new Button(pbName,this,pbLabel); } addingPageButton=false; newPageButton->setBorderWidth(newPageButton->getBorderWidth()*0.5f); newPageButton->getSelectCallbacks().add(this,&Pager::pageButtonSelectCallback); /* Add the page button to the list: */ pageButtons.insert(pageButtons.begin()+nextChildIndex,newPageButton); /* Select the just-added child: */ setCurrentChildIndex(nextChildIndex); /* Prepare for the next page: */ nextChildIndex=GLint(children.size()); if(isManaged) { /* Try to resize the widget to accomodate the new child: */ parent->requestResize(this,calcNaturalSize()); } }
void PopupWindow::pointerMotion(Event& event) { if(isResizing) { const Point& p=event.getWidgetPoint().getPoint(); /* Get the current exterior box: */ Box exterior=getExterior(); /* Get the minimal exterior size: */ Vector minSize=calcNaturalSize(); /* Resize the box horizontally: */ if(resizeBorderMask&0x1) { GLfloat right=exterior.origin[0]+exterior.size[0]; GLfloat newLeft=p[0]+resizeOffset[0]; GLfloat newSize=right-newLeft; if(newSize<minSize[0]) newSize=minSize[0]; exterior.origin[0]=right-newSize; exterior.size[0]=newSize; } else if(resizeBorderMask&0x2) { GLfloat left=exterior.origin[0]; GLfloat newRight=p[0]+resizeOffset[0]; GLfloat newSize=newRight-left; if(newSize<minSize[0]) newSize=minSize[0]; exterior.size[0]=newSize; } /* Resize the box vertically: */ if(resizeBorderMask&0x4) { GLfloat top=exterior.origin[1]+exterior.size[1]; GLfloat newBottom=p[1]+resizeOffset[1]; GLfloat newSize=top-newBottom; if(newSize<minSize[1]) newSize=minSize[1]; exterior.origin[1]=top-newSize; exterior.size[1]=newSize; } else if(resizeBorderMask&0x8) { GLfloat bottom=exterior.origin[1]; GLfloat newTop=p[1]+resizeOffset[1]; GLfloat newSize=newTop-bottom; if(newSize<minSize[1]) newSize=minSize[1]; exterior.size[1]=newSize; } if(exterior.size[0]!=getExterior().size[0]||exterior.size[1]!=getExterior().size[1]) { /* Resize the popup window: */ resize(exterior); } } }