Ejemplo n.º 1
0
void MenuItem::drawText(Graphics* const TheGraphics, const Pnt2f& TopLeft, Real32 Opacity) const
{
   //If I have Text Then Draw it
   if(getText() != "" && getFont() != NULL)
   {
       Pnt2f b, BottomRight;
       getInsideBorderBounds(b, BottomRight);
      //Calculate Alignment
      Pnt2f AlignedPosition;
      Pnt2f TextTopLeft, TextBottomRight;
      getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

      AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),0.5, 0.0);

	  //Draw the Text
      TheGraphics->drawText(AlignedPosition, getText(), getFont(), getDrawnTextColor(), getOpacity()*Opacity);

      //Draw the Mnemonic Underline
      if(_MnemonicTextPosition != -1)
      {
          TheGraphics->drawTextUnderline(AlignedPosition, getText().substr(_MnemonicTextPosition,1), getFont(), getDrawnTextColor(), getOpacity()*Opacity);
      }
      
      //Draw the Accelerator Text
      if(_AcceleratorText.compare("") != 0)
      {
          Pnt2f AcceleratorTextTopLeft, AcceleratorTextBottomRight;
          getFont()->getBounds(_AcceleratorText, AcceleratorTextTopLeft, AcceleratorTextBottomRight);
          Pnt2f AcceleratorAlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (AcceleratorTextBottomRight - AcceleratorTextTopLeft),0.5, 1.0);

          TheGraphics->drawText(AcceleratorAlignedPosition, _AcceleratorText, getFont(), getDrawnTextColor(), getOpacity()*Opacity);
      }

   }
}
Ejemplo n.º 2
0
void TextField::mousePressed(MouseEventDetails* const e)
{
	Pnt2f TopLeftText, BottomRightText, TempPos;
	Pnt2f TopLeftText1, BottomRightText1;
	Pnt2f TopLeft, BottomRight;
	getFont()->getBounds(getDrawnText(), TopLeftText, BottomRightText);
    getInsideBorderBounds(TopLeft, BottomRight);
    TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());
	if(e->getButton() == MouseEventDetails::BUTTON1)
	{
		//set caret position to proper place
		//if the mouse is to the left of the text, set it to the begining.
		Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
		if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
		{
			setCaretPosition(0);
		}		//if the mouse is to the right of the text, set it to the end
		else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
		{
			setCaretPosition(getDrawnText().size());
		}
		else
		{
			for(UInt32 i = 0; i <getDrawnText().size(); i++)
			{		
				calculateTextBounds(0,i, TopLeftText, BottomRightText);
				calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
				if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
				   && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
				{
					if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= (BottomRightText1.x()-BottomRightText.x())/2.0+0.5 + BottomRightText.x())
					{
						setCaretPosition(i);
						break;
					}
					else
					{
						setCaretPosition(i+1);
						break;
					}
				}
			}
		}

		_TextSelectionEnd = getCaretPosition();
		_TextSelectionStart = getCaretPosition();
	}
	if(getParentWindow() != NULL && getParentWindow()->getParentDrawingSurface()!=NULL&& getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL)
	{
        _MouseDownKeyTypedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectKeyTyped(boost::bind(&TextField::handleMouseDownKeyTyped, this, _1));
        _MouseDownMouseReleasedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&TextField::handleMouseDownMouseReleased, this, _1));
        _MouseDownMouseDraggedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&TextField::handleMouseDownMouseDragged, this, _1));
    }
	Inherited::mousePressed(e);
}
Ejemplo n.º 3
0
void Label::calculateTextBounds(const UInt32 StartIndex, const UInt32 EndIndex, Pnt2f& TopLeft, Pnt2f& BottomRight)
{
    Pnt2f ComponentTopLeft, ComponentBottomRight;
    getInsideBorderBounds(ComponentTopLeft, ComponentBottomRight);

    Pnt2f AlignmentOffset = calculateAlignment(ComponentTopLeft, ComponentBottomRight-ComponentTopLeft, getFont()->getBounds(getText()), getAlignment().y(), getAlignment().x());

    getFont()->getBounds(getText().substr(StartIndex, EndIndex), TopLeft, BottomRight);
    TopLeft = TopLeft + Vec2f(AlignmentOffset);
    BottomRight = BottomRight + Vec2f(AlignmentOffset);
}
Ejemplo n.º 4
0
void ProgressBar::drawInternal(Graphics* const Graphics, Real32 Opacity) const
{

	//Draw The ProgressBar
    UIDrawObjectCanvasRefPtr DrawObject(getDrawnDrawObject());
    if(DrawObject != NULL)
    {
        if(DrawObject->getPosition() != _ProgressBarPosition)
        {
            DrawObject->setPosition(_ProgressBarPosition);
        }
        if(DrawObject->getSize() != _ProgressBarSize)
        {
            DrawObject->setSize(_ProgressBarSize);
        }
        DrawObject->draw(Graphics,getOpacity()*Opacity);
    }
	
	//Draw The Progress String
	if(getEnableProgressString() && getFont() != NULL)
	{
		Pnt2f TopLeft, BottomRight;
		getInsideBorderBounds(TopLeft, BottomRight);

		//Draw the progress String
		std::string StringToDraw;
		if(getProgressString().compare("") == 0)
		{
            if(!getIndeterminate())
            {
			    UInt32 Percent(static_cast<Int32>( osgFloor(getPercentComplete() * 100.0f) ));

			    std::stringstream TempSStream;
			    TempSStream << Percent;

			    StringToDraw = TempSStream.str() + std::string("%");
            }
		}
		else
		{
			StringToDraw = getProgressString();
		}

		//Calculate Alignment
		Pnt2f AlignedPosition;
		Pnt2f TextTopLeft, TextBottomRight;
		getFont()->getBounds(StringToDraw, TextTopLeft, TextBottomRight);

		AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),getAlignment().y(), getAlignment().x());

		//Draw the Text
		Graphics->drawText(AlignedPosition, StringToDraw, getFont(), getDrawnTextColor(), getOpacity()*Opacity);
	}
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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);
        }
    }
}
Ejemplo n.º 7
0
void Label::mousePressed(MouseEventDetails* const e)
{
    if(getTextSelectable())
    {
        Pnt2f TopLeftText, BottomRightText, TempPos;
        Pnt2f TopLeftText1, BottomRightText1;
        Pnt2f TopLeft, BottomRight;
        getFont()->getBounds(getText(), TopLeftText, BottomRightText);
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {
            //set caret position to proper place
            //if the mouse is to the left of the text, set it to the begining.
            Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
            if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
            {
                setCaretPosition(0);
            }        //if the mouse is to the right of the text, set it to the end
            else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
            {
                setCaretPosition(getText().size());
            }
            else
            {
                for(UInt32 i = 0; i <getText().size(); i++)
                {        
                    calculateTextBounds(0,i, TopLeftText, BottomRightText);
                    calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                    if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                       && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                    {
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= (BottomRightText1.x()-BottomRightText.x())/2.0+0.5 + BottomRightText.x())
                        {
                            setCaretPosition(i);
                            break;
                        }
                        else
                        {
                            setCaretPosition(i+1);
                            break;
                        }
                    }
                }
            }

            _TextSelectionEnd = getCaretPosition();
            _TextSelectionStart = getCaretPosition();
        }
    }
    Inherited::mousePressed(e);
}
Ejemplo n.º 8
0
OSG_BEGIN_NAMESPACE

void openCreditsWindow(void)
{
    ApplicationBuilderUnrecPtr AppBuilder = dynamic_cast<ApplicationBuilder*>(MainApplication::the()->getBuilderMode());

    DialogWindowRecPtr TheCreditsWindow = createCreditsWindow();

    dynamic_cast<Button*>(AppBuilder->findContainer("KabalaEngine.CreditsWindow.OkButton"))->connectActionPerformed(boost::bind(&handleCreditsWindowCloseButton, _1, TheCreditsWindow.get()));

    TheCreditsWindow->setPosition(calculateAlignment(Pnt2f(0.0f,0.0f), AppBuilder->getDrawingSurface()->getSize(), TheCreditsWindow->getPreferredSize(), 0.5f,0.5f));

    AppBuilder->getDrawingSurface()->openWindow(TheCreditsWindow);
}
   virtual void actionPerformed(const ActionEventUnrecPtr e)
    {
        std::vector<std::string> inputValues;
        inputValues.push_back("0");

        DialogWindowRefPtr TheDialog;
        TheDialog = DialogWindow::createInputDialog("Move selected index to", "Please enter the index to move to", DialogWindow::INPUT_TEXT,true,inputValues);
        TheDialog->setAllwaysOnTop(true);
        TheDialog->addDialogWindowListener(this);

        Pnt2f CenteredPosition = calculateAlignment(dynamic_cast<Component*>(e->getSource())->getParentWindow()->getPosition(), dynamic_cast<Component*>(e->getSource())->getParentWindow()->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
        TheDialog->setPosition(CenteredPosition);

        dynamic_cast<Component*>(e->getSource())->getParentWindow()->getDrawingSurface()->openWindow(TheDialog);
    }
DialogWindowUnrecPtr openFCTreeEditorDialog(FieldContainer* fc, 
                                        CommandManagerPtr CmdManager,
                                        const std::string& editorName,
                                        UIDrawingSurfaceUnrecPtr DrawingSurface)
{
    DialogWindowUnrecPtr TheDialog = createFCTreeEditorDialog(fc, CmdManager, editorName);

    Pnt2f CenteredPosition = calculateAlignment(Pnt2f(0.0f,0.0f), DrawingSurface->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
    TheDialog->setPosition(CenteredPosition);
    TheDialog->setTitle(std::string("Edit ") + fc->getType().getCName());
    TheDialog->setAllwaysOnTop(true);
    TheDialog->setResizable(true);

    DrawingSurface->openWindow(TheDialog);

    return TheDialog;
}
Ejemplo n.º 11
0
void FCPtrFieldEditor::openCreateHandler(void)
{
    const FieldContainerType* ThePtrType(getFieldContainerTypeFromPtrType(getEditingFC()->getFieldDescription(getEditingFieldId())->getFieldType().getContentType()));
    if(ThePtrType == NULL)
    {
        return;
    }

    //If the type is a node, then create a NodeCore instead
    //and then insert it as the core of a newly created node
    if(*ThePtrType == Node::getClassType())
    {
        ThePtrType = &NodeCore::getClassType();
    }

    std::vector<std::string> inputValues;
    UInt32 NumFieldContainersFound(0);
    const FieldContainerType* FoundType(NULL);
    for(UInt32 j(0) ; NumFieldContainersFound<FieldContainerFactory::the()->getNumTypes(); ++j)
    {
        FoundType = FieldContainerFactory::the()->findType(j);
        if(FoundType != NULL)
        {
            if(FoundType->isDerivedFrom(*ThePtrType)  && !FoundType->isAbstract())
            {
                inputValues.push_back(FoundType->getName());
            }
            ++NumFieldContainersFound;
        }
    }

    DialogWindowRefPtr TheDialog = DialogWindow::createInputDialog("Create Field Container",
                                                                   "Choose the type of object to create",
                                                                   DialogWindow::INPUT_COMBO,
                                                                   true,
                                                                   inputValues);
    _CreateContainerDialogClosedConnection = TheDialog->connectDialogWindowClosed(boost::bind(&FCPtrFieldEditor::handleCreateContainerDialogClosed, this, _1));

    Pnt2f CenteredPosition = calculateAlignment(Pnt2f(0.0f,0.0f), getParentWindow()->getParentDrawingSurface()->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
    TheDialog->setPosition(CenteredPosition);
    TheDialog->setAllwaysOnTop(true);
    TheDialog->setModal(true);
    TheDialog->setResizable(true);

    getParentWindow()->getParentDrawingSurface()->openWindow(TheDialog);
}
Ejemplo n.º 12
0
void Label::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    if(getText() != "" && getFont() != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        Pnt2f TempPos;
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getText()), getAlignment().y(), getAlignment().x());
        
        //Text Color
        Color4f TextColor = getDrawnTextColor();

        if(_TextSelectionStart >= _TextSelectionEnd)
        {
            TheGraphics->drawText(TempPos, getText(), getFont(), TextColor, getOpacity()*Opacity);
        }
        else
        {
            //Draw Text Before the Selection
            TheGraphics->drawText(TempPos, getText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity);

            //Draw Selection
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight);

            TheGraphics->drawQuad(TempPos + Vec2f(TextBottomRight.x(),0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd)).x(), 0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd))),
                                  TempPos + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity()*Opacity);

            //Draw Selected Text
            TheGraphics->drawText(TempPos + Vec2f(TextBottomRight.x(), 0), 
                                  getText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity);

            //Draw Text After selection
            getFont()->getBounds(getText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(TempPos + Vec2f(TextBottomRight.x(), 0),
                                  getText().substr(_TextSelectionEnd, getText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
}
Ejemplo n.º 13
0
void ToolTip::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    if(getText() != "" && getFont() != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        getInsideBorderBounds(TopLeft, BottomRight);

        Pnt2f TextTopLeft, TextBottomRight;
        getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);
        TheGraphics->drawText(calculateAlignment(TopLeft,
                              BottomRight-TopLeft,
                              (TextBottomRight-TextTopLeft),
                              getAlignment().y(),
                              getAlignment().x()),
                              getText(),
                              getFont(),
                              getTextColor(),
                              getOpacity()*Opacity);
    }
}
Ejemplo n.º 14
0
void FCPtrFieldEditor::openFindContainerHandler(void)
{
    const FieldContainerType* ThePtrType(getFieldContainerTypeFromPtrType(getEditingFC()->getFieldDescription(getEditingFieldId())->getFieldType().getContentType()));
    if(ThePtrType == NULL)
    {
        return;
    }

    std::vector<std::string> inputValues;
    _FindFCStore->setTypeToStore(ThePtrType);
    FCPtrEditorStore::FieldContianerVector fcStore(_FindFCStore->getList());

    std::string value;
    for(UInt32 i(0) ; i<fcStore.size(); ++i)
    {
        value.clear();
        if(fcStore[i]->getType().isDerivedFrom(AttachmentContainer::getClassType()) &&
           getName(dynamic_pointer_cast<AttachmentContainer>(fcStore[i])))
        {
            value += std::string(getName(dynamic_pointer_cast<AttachmentContainer>(fcStore[i]))) + " ";
        }
        value += "[" + fcStore[i]->getType().getName() + "] " + boost::lexical_cast<std::string>(fcStore[i]->getId());
        inputValues.push_back(value);
    }

    DialogWindowRefPtr TheDialog = DialogWindow::createInputDialog("Find Field Container",
                                                                   "Choose the container to use",
                                                                   DialogWindow::INPUT_LIST,
                                                                   true,
                                                                   inputValues);
    _FindContainerDialogClosedConnection = TheDialog->connectDialogWindowClosed(boost::bind(&FCPtrFieldEditor::handleFindContainerDialogClosed, this, _1));

    Pnt2f CenteredPosition = calculateAlignment(Pnt2f(0.0f,0.0f), getParentWindow()->getParentDrawingSurface()->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
    TheDialog->setPosition(CenteredPosition);
    TheDialog->setAllwaysOnTop(true);
    TheDialog->setResizable(true);

    getParentWindow()->getParentDrawingSurface()->openWindow(TheDialog);
}
void GenericMultiFieldEditor::insertAtIndex(FieldContainer* const fc,
                                            UInt32 fieldID,
                                            UInt32 index,
                                            UIDrawingSurface* const drawingSurface,
                                            CommandManager* cmdMgr)
{
    //Is this a pointer field
    GetFieldHandlePtr TheFieldHandle(fc->getField(fieldID));
    if(TheFieldHandle->isPointerField())
    {
        //Create
        const FieldContainerType* ThePtrType(getFieldContainerTypeFromPtrType(fc->getFieldDescription(fieldID)->getFieldType().getContentType()));
        if(ThePtrType == NULL)
        {
            return;
        }

        //If the type is a node, then create a NodeCore instead
        //and then insert it as the core of a newly created node
        if(*ThePtrType == Node::getClassType())
        {
            ThePtrType = &NodeCore::getClassType();
        }

        std::vector<std::string> inputValues;
        UInt32 NumFieldContainersFound(0);
        const FieldContainerType* FoundType(NULL);
        for(UInt32 j(0) ; NumFieldContainersFound<FieldContainerFactory::the()->getNumTypes(); ++j)
        {
            FoundType = FieldContainerFactory::the()->findType(j);
            if(FoundType != NULL)
            {
                if(FoundType->isDerivedFrom(*ThePtrType)  && !FoundType->isAbstract())
                {
                    inputValues.push_back(FoundType->getName());
                }
                ++NumFieldContainersFound;
            }
        }

        if(inputValues.size() == 1)
        {
            insertAtIndex(fc,fieldID,index,FieldContainerFactory::the()->findType(inputValues[0].c_str()),cmdMgr);
        }
        else
        {
            DialogWindowRefPtr TheDialog = DialogWindow::createInputDialog("Create " + fc->getFieldDescription(fieldID)->getFieldType().getContentType().getName(),
                                                                           "Choose the type of object to create",
                                                                           DialogWindow::INPUT_COMBO,
                                                                           true,
                                                                           inputValues);
            TheDialog->connectDialogWindowClosed(boost::bind(&GenericMultiFieldEditor::handleInsertFCPtrDialogClosed,
                                                             _1,
                                                             fc,
                                                             fieldID,
                                                             index,
                                                             cmdMgr));

            Pnt2f CenteredPosition = calculateAlignment(Pnt2f(0.0f,0.0f), drawingSurface->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
            TheDialog->setPosition(CenteredPosition);
            TheDialog->setAllwaysOnTop(true);
            TheDialog->setModal(true);
            TheDialog->setResizable(true);

            drawingSurface->openWindow(TheDialog);
        }
    }
    else
    {
        //Insert the default
        InsertFieldElementCommandPtr InsertIndexCommand = InsertFieldElementCommand::create(fc, fieldID, "", index);

        cmdMgr->executeCommand(InsertIndexCommand);
    }
}
Ejemplo n.º 16
0
void BoxLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
	/*!
      totalMajorAxis will be the sum of the MajorAxis of all of the
	  components, which is compared to MajorAxis, which is MajorAxis of the parent
	  component. These two variables will be used to determine the spacing of
	  each of the objects.
    */
	UInt32 AxisIndex(0);
	if(getOrientation() != HORIZONTAL_ORIENTATION ) AxisIndex = 1;

	Pnt2f borderTopLeft, borderBottomRight;
	dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
	Vec2f borderSize(borderBottomRight-borderTopLeft);
	Real32 MajorAxis(borderSize[AxisIndex]);
	Real32 totalMajorAxis(0);
	Real32 largestMinorAxis(0);
	Real32 spacing(0);
	Vec2f size;
	Vec2f offset(0,0);

	/*!
	  This first sweep through the components sets each component to its
	  preferred size, gets a sum of all the MajorAxes, and finds the
	  largest height.
    */
	for(UInt32 i=0 ; i<Components->size() ; ++i)
	{	// set the component to its preferred size
		// get sum of all components
		totalMajorAxis += (*Components)[i]->getPreferredSize()[AxisIndex];
		if ((*Components)[i]->getPreferredSize()[(AxisIndex+1)%2] > largestMinorAxis)
			largestMinorAxis = (*Components)[i]->getPreferredSize()[(AxisIndex+1)%2];
	}
	if(MajorAxis > totalMajorAxis)
	{
		spacing = (MajorAxis-totalMajorAxis)/(Components->size()+1);
		// in the case where there isn't equal spacing between each button,
		// translate more the first time to center the components
		if(spacing < getMajorAxisMinimumGap())
		{
			spacing = getMajorAxisMinimumGap();
		}
		if(spacing > getMajorAxisMaximumGap())
		{
			spacing = getMajorAxisMaximumGap();
		}
		borderTopLeft[AxisIndex] += (MajorAxis - (spacing*(Components->size()+1)+totalMajorAxis))*getMajorAxisAlignment() + spacing;
	}
	else
	{
		spacing = getMajorAxisMinimumGap();
	}


	if(getOrientation() == HORIZONTAL_ORIENTATION)
	{
		borderTopLeft = calculateAlignment(borderTopLeft, borderSize, Vec2f(0.0f,largestMinorAxis), getMinorAxisAlignment(), 0.0f);
	}
	else
	{
		borderTopLeft = calculateAlignment(borderTopLeft, borderSize, Vec2f(largestMinorAxis,0.0f), 0.0f, getMinorAxisAlignment());
	}

	/*!
	  This second sweep through the components sets each component to the
	  matching highest height, then positions each component equally spaced apart
    */
	for(UInt32 i=0; i<Components->size(); ++i)
	{	
		// for each individual button, keep track of the offsetMinorAxis in height
		// for use in keeping them vertically centered
		offset[(AxisIndex+1)%2] = 0;
		// change the component's height only if necessary
		if (largestMinorAxis > (*Components)[i]->getPreferredSize()[(AxisIndex+1)%2])
		{	
			if (largestMinorAxis <= (*Components)[i]->getMaxSize()[(AxisIndex+1)%2])
			{	// for when the max height is larger than the largestMinorAxis
				size[AxisIndex] = (*Components)[i]->getPreferredSize()[AxisIndex];
				size[(AxisIndex+1)%2] = largestMinorAxis;
			}
			else
			{	// in this case, max out the button to its max height
				size[AxisIndex] = (*Components)[i]->getPreferredSize()[AxisIndex];
				size[(AxisIndex+1)%2] = (*Components)[i]->getMaxSize()[(AxisIndex+1)%2];

				// find how far to set offset to make this button properly aligned
				if(getOrientation() == HORIZONTAL_ORIENTATION)
				{
					offset = Vec2f(calculateAlignment(Pnt2f(0,0), Vec2f(0.0f, largestMinorAxis), Vec2f(0.0f,(*Components)[i]->getMaxSize().y()), getComponentAlignment(), 0.0f));
				}
				else
				{
					offset = Vec2f(calculateAlignment(Pnt2f(0,0), Vec2f(largestMinorAxis,0.0f), Vec2f((*Components)[i]->getMaxSize().x(),0.0f), 0.0f, getComponentAlignment()));
				}
			}
		}
		else
		{
			size = (*Components)[i]->getPreferredSize();
		}
			(*Components)[i]->setSize(size);
			(*Components)[i]->setPosition(borderTopLeft + offset);

		// now set offset for the next button
		offset[AxisIndex] += spacing + (*Components)[i]->getPreferredSize()[AxisIndex];
	}
}
Ejemplo n.º 17
0
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());
        }
    }
}
Ejemplo n.º 18
0
void TextField::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f Alignment;
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //Text Color
    Color4f TextColor = getDrawnTextColor();

    if(getDrawnText() != "" && getFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getDrawnText()), getAlignment().y(), getAlignment().x());


        if(_TextSelectionStart >= _TextSelectionEnd)
        {
            TheGraphics->drawText(Alignment, getDrawnText(), getFont(), TextColor, getOpacity()*Opacity);
        }
        else
        {
            //Draw Text Befor the Selection
            TheGraphics->drawText(Alignment, getDrawnText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity);

            //Draw Selection
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight);

            TheGraphics->drawQuad(Alignment + Vec2f(TextBottomRight.x(),0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd)).x(), 0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd))),
                                  Alignment + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity());

            //Draw Selected Text
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0), 
                                  getDrawnText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity);

            //Draw Text After selection
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0),
                                  getDrawnText().substr(_TextSelectionEnd, getDrawnText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
    else
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds("|"), getAlignment().y(), getAlignment().x());
    }

    if(getEnabled() && getEditable() && getFocused() && _CurrentCaretBlinkElps <= 0.5*LookAndFeelManager::the()->getLookAndFeel()->getTextCaretRate())
    {
        //Draw the caret
        TheGraphics->drawLine(Alignment+Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(), 0),
                              Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(),  getFont()->getBounds(getDrawnText()).y()), 
                              .5, TextColor, getOpacity()*Opacity);
    }

    //Draw the Descriptive text if empty
    if(getDrawnText().empty() && !getEmptyDescText().empty()  && getEmptyDescTextFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getEmptyDescTextFont()->getBounds(getEmptyDescText()), getAlignment().y(), getAlignment().x());
        TheGraphics->drawText(Alignment, getEmptyDescText(), getEmptyDescTextFont(), getEmptyDescTextColor(), getOpacity()*Opacity);
    }
}
Ejemplo n.º 19
0
void TextField::handleMouseDownMouseDragged(MouseEventDetails* const e)
{
	Pnt2f TopLeftText, BottomRightText, TempPos;
	Pnt2f TopLeftText1, BottomRightText1;
	Pnt2f TopLeft, BottomRight;
	Int32 OriginalPosition = getCaretPosition();
	getFont()->getBounds(getDrawnText(), TopLeftText, BottomRightText);
    getInsideBorderBounds(TopLeft, BottomRight);
    TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());
    if(e->getButton() == MouseEventDetails::BUTTON1)
	{
		//set caret position to proper place
		//if the mouse is to the left of the text, set it to the begining.
		Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
		if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
		{
			setCaretPosition(0);
		}		//if the mouse is to the right of the text, set it to the end
		else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
		{
			setCaretPosition(getDrawnText().size());
		}
		else
		{
			//check letter by letter for the mouse's position
			for(UInt32 i = 0; i <getDrawnText().size(); i++)
			{		
				calculateTextBounds(0,i, TopLeftText, BottomRightText);
				calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
				if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
				   && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
				{
					if(DrawingSurfaceToComponent(e->getLocation(), this).x() < (BottomRightText1.x()-BottomRightText.x())/2.0 + BottomRightText.x())
					{

						setCaretPosition(i);
						break;
					}
					else
					{

						setCaretPosition(i+1);
						break;
					}
				}
			}
		}
		if(getCaretPosition() < OriginalPosition)
		{
			if(getCaretPosition() < _TextSelectionStart)
			{
				_TextSelectionStart = getCaretPosition();
			}
			else
			{
				_TextSelectionEnd = getCaretPosition();
			}
		}
		else if(getCaretPosition() > OriginalPosition)
		{
			if(getCaretPosition() > _TextSelectionEnd)
			{
				_TextSelectionEnd = getCaretPosition();
			}
			else
			{
				_TextSelectionStart = getCaretPosition();
			}
		}
	}
}
Ejemplo n.º 20
0
void Label::mouseClicked(MouseEventDetails* const e)
{    
    if(getTextSelectable())
    {
        Int32 Position(0);
        Int32 BeginWord = 0;
        Int32 EndWord = getText().size();
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {

            if(e->getClickCount() == 2)
            {
                Pnt2f TopLeftText, BottomRightText, TempPos;
                Pnt2f TopLeftText1, BottomRightText1;
                Pnt2f TopLeft, BottomRight;
                getFont()->getBounds(getText(), TopLeftText, BottomRightText);
                getInsideBorderBounds(TopLeft, BottomRight);
                TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());

                //set caret position to proper place
                //if the mouse is to the left of the text, set it to the begining.
                Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
                if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
                {
                    Position = 0;
                }//if the mouse is to the right of the text, set it to the end
                else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
                {
                    Position = getText().size();
                }
                else
                {
                    for(UInt32 i = 0; i <getText().size(); i++)
                    {        
                        calculateTextBounds(0,i, TopLeftText, BottomRightText);
                        calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                           && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                        {
                            Position = i;
                            break;
                        }
                    }
                }
                if(isPunctuationChar(getText()[Position]))
                {
                    EndWord = Position + 1;
                    BeginWord = Position;
                }
                else{
                    for(Int32 i = Position; i < getText().size(); i++)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            EndWord = i;
                            break;
                        }
                    }
                    for(Int32 i = Position; i >= 0; i--)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            BeginWord = i + 1;
                            break;
                        }
                    }
                }
                _TextSelectionEnd = EndWord;
                _TextSelectionStart = BeginWord;
                setCaretPosition(EndWord);
            }
        }
    }
    Inherited::mouseClicked(e);

}
Ejemplo n.º 21
0
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);
        }
    }
}
Ejemplo n.º 22
0
void Button::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //If I have a DrawObject then Draw it
    UIDrawObjectCanvasRefPtr DrawnDrawObject = getDrawnDrawObject();
    UIDrawObjectCanvasRefPtr BaseDrawObject = getBaseDrawObject();

    if(DrawnDrawObject != NULL)
    {
        //Get the Draw Object Size
        Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
        DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight);

        Pnt2f BaseDrawObjectTopLeft, BaseDrawObjectBottomRight;
        BaseDrawObject->getDrawObjectBounds(BaseDrawObjectTopLeft, BaseDrawObjectBottomRight);

        if(getText() != "" && getFont() != NULL)
        {
            //Draw both the text and Draw Object

            //Get the Text Size
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

            Vec2f InternalsSize;
            if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_LEFT_OF_TEXT || 
               getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT)
            {
                InternalsSize.setValues((TextBottomRight.x()-TextTopLeft.x()) + (DrawObjectBottomRight.x()-DrawObjectTopLeft.x()) + getDrawObjectToTextPadding(),
                                        osgMax((TextBottomRight.y()-TextTopLeft.y()), (DrawObjectBottomRight.y()-DrawObjectTopLeft.y())));
            }
            else
            {
                InternalsSize.setValues(osgMax((TextBottomRight.x()-TextTopLeft.x()), (DrawObjectBottomRight.x()-DrawObjectTopLeft.x())),
                                        (TextBottomRight.y()-TextTopLeft.y()) + (DrawObjectBottomRight.y()-DrawObjectTopLeft.y()) + getDrawObjectToTextPadding());
            }

            Pnt2f InternalAlignment;
            InternalAlignment = calculateAlignment(TopLeft, (BottomRight-TopLeft), InternalsSize,getAlignment().y(), getAlignment().x());

            //Draw Object Alignment
            Pnt2f DrawObjectAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),1.0f, 0.5);
                    break;
            }
            //If active then translate the Text by the Active Offset
            DrawObjectAlignedPosition = DrawObjectAlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( DrawObjectAlignedPosition );

            //Text Alignment
            Pnt2f TextAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),1.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.0f, 0.5);
                    break;
            }

            drawText(TheGraphics, TextAlignedPosition, Opacity);
        }
        else
        {
            //Just Draw the Draw Object
            Pnt2f AlignedPosition;
            AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),getAlignment().y(), getAlignment().x());

            //If active then translate the Text by the Active Offset
            AlignedPosition = AlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( AlignedPosition );
        }

        //Draw the DrawnDrawObject
        DrawnDrawObject->draw(TheGraphics, getOpacity()*Opacity);

    }
    else if(getText() != "" && getFont() != NULL)
    {
        //Just Draw the Text
        Pnt2f AlignedPosition;
        Pnt2f TextTopLeft, TextBottomRight;
        getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

        AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),getAlignment().y(), getAlignment().x());

        drawText(TheGraphics, AlignedPosition, Opacity);
    }
}