Exemple #1
0
void SplitPanel::dividerDragMouseDragged(MouseEventDetails* const e)
{
    UInt32 AxisIndex(0);
    if(getOrientation() != SplitPanel::HORIZONTAL_ORIENTATION ) AxisIndex = 1;

    if(e->getButton() == MouseEventDetails::BUTTON1)
    {
        Pnt2f temp = ViewportToComponent(e->getLocation(), this, e->getViewport());
        if (getDividerPosition() <= 1.0)
        {
            if (temp[AxisIndex] >= 0) // this ensures it stays as a percentage position
            {
                Pnt2f TopLeft, BottomRight;
                getInsideBorderBounds(TopLeft, BottomRight);
                Vec2f BorderSize(BottomRight - TopLeft);
                setDividerPosition((Real32)temp[AxisIndex]/(Real32)BorderSize[AxisIndex]);
            }
        }
        else
        {
            if (temp[AxisIndex] > 1) // this ensures it stays absolute position
            {
                setDividerPosition(temp[AxisIndex]);
            }
        }
        //updateLayout();
    }
}
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);
      }

   }
}
void BoolFieldEditor::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    _EditingCheckbox->setPosition(TopLeft);
    _EditingCheckbox->setSize(BottomRight - TopLeft);
}
void GenericMultiFieldEditor::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    _FieldElementsScrollPanel->setPosition(Pnt2f(0.0f,0.0f));
    _FieldElementsScrollPanel->setSize(BottomRight - TopLeft);
}
void GenericFieldEditor::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    _EditingTextField->setPosition(TopLeft);
    _EditingTextField->setSize(BottomRight - TopLeft);
}
void TextFieldEditor::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    _EditingTextAreaScrollPanel->setPosition(TopLeft);
    _EditingTextAreaScrollPanel->setSize(BottomRight - TopLeft);
}
void Component::drawForeground(Graphics* const TheGraphics, const Layer* Foreground, Real32 Opacity) const
{
    //Draw the Foreground on the Inside of my border
    if(Foreground != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        getInsideBorderBounds(TopLeft, BottomRight);
        Foreground->draw(TheGraphics, TopLeft, BottomRight, getOpacity()*Opacity);
    }
}
Vec2f Component::getBorderingLength(void) const
{
    Pnt2f BoundsTopLeft, BoundsBottomRight;
    Pnt2f InsideBorderTopLeft, InsideBorderBottomRight;

    getBounds(BoundsTopLeft, BoundsBottomRight);
    getInsideBorderBounds(InsideBorderTopLeft, InsideBorderBottomRight);

    return (BoundsBottomRight - BoundsTopLeft) - (InsideBorderBottomRight - InsideBorderTopLeft);
}
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);
}
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);
}
Exemple #11
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);
	}
}
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);
}
Exemple #13
0
void ProgressBar::setupProgressBar(void)
{

    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);
   
	if(getIndeterminate())
	{
		Real32 Pos;
		if(_IndeterminateBarPosition > 1.0)
		{
			Pos = 2.0 - _IndeterminateBarPosition;
		}
		else
		{
			Pos = _IndeterminateBarPosition;
		}
			switch(getOrientation())
			{
			case ProgressBar::HORIZONTAL_ORIENTATION:
                _ProgressBarPosition.setValues((BottomRight.x() - TopLeft.x())*Pos*(1.0-getIndeterminateBarSize()), TopLeft.y());
                _ProgressBarSize.setValues( (BottomRight.x() - TopLeft.x())*getIndeterminateBarSize(),BottomRight.y() - TopLeft.y());
				break;
			case ProgressBar::VERTICAL_ORIENTATION:
			default:
                _ProgressBarPosition.setValues( Pos*(BottomRight.x() - TopLeft.x())*(1.0-getIndeterminateBarSize()), TopLeft.y());
                _ProgressBarSize.setValues( TopLeft.x(), Pos*(BottomRight.y() - TopLeft.y())*(1.0-getIndeterminateBarSize()));
				break;
			}
	}
	else
	{
		if(getRangeModel() == NULL) {return;}

		Real32 Percent(getPercentComplete());

        _ProgressBarPosition = TopLeft;
		switch(getOrientation())
		{
		case ProgressBar::HORIZONTAL_ORIENTATION:
            _ProgressBarSize.setValues( (BottomRight.x() - TopLeft.x())*Percent,BottomRight.y() - TopLeft.y());
			break;
		case ProgressBar::VERTICAL_ORIENTATION:
		default:
            _ProgressBarSize.setValues( BottomRight.x() - TopLeft.x(),(BottomRight.y() - TopLeft.y())*Percent);
			break;
		}
	}
}
Exemple #14
0
void ComponentMenuItem::updateComponentBounds(void)
{
    if(getComponent() != NULL)
    {
        Pnt2f InsideBorderTopLeft, InsideBorderBottomRight;
        getInsideBorderBounds(InsideBorderTopLeft, InsideBorderBottomRight);

        if(getComponent()->getPosition() != InsideBorderTopLeft)
        {
            getComponent()->setPosition(InsideBorderTopLeft);
        }
        Vec2f Size(InsideBorderBottomRight - InsideBorderTopLeft);
        if(getComponent()->getSize() != Size)
        {
            getComponent()->setSize(Size);
        }
    }
}
void FCPtrFieldEditor::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //Menu Button
    _EditingMenuButton->setSize(Vec2f(_EditingMenuButton->getPreferredSize().x(),BottomRight.y() - TopLeft.y()));
    _EditingMenuButton->setPosition(BottomRight - _EditingMenuButton->getSize());

    //Editing Text Field
    _EditingTextField->setPosition(Pnt2f(BottomRight.x() - _EditingTextField->getPreferredSize().x() - _EditingMenuButton->getPreferredSize().x(), TopLeft.y()));
    _EditingTextField->setSize(Vec2f(_EditingTextField->getPreferredSize().x(), BottomRight.y() - TopLeft.y()));

    //Name/Type Label
    _NameTypeLabel->setPosition(TopLeft);
    _NameTypeLabel->setSize(Vec2f(_EditingTextField->getPosition().x() - TopLeft.x(), BottomRight.y() - TopLeft.y()));
    
}
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);
        }
    }
}
Exemple #17
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);
    }
}
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);
    }
}
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);

}
Exemple #20
0
void SplitPanel::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);
    Vec2f BorderSize(BottomRight - TopLeft);

    UInt32 AxisIndex(0);
    if(getOrientation() != SplitPanel::HORIZONTAL_ORIENTATION ) AxisIndex = 1;

    Vec2f minSize(0,0);
    Vec2f maxSize(0,0);
    Vec2f divSize(0,0);
    Pnt2f minPos(0,0);
    Pnt2f maxPos(0,0);
    Pnt2f divPos(0,0);

    if (getDividerPosition() < 0.0)
        setDividerPosition(0.5);
    if (getMinDividerPosition() < 0.0)
        setMinDividerPosition(0.0);
    if (getMaxDividerPosition() < 0.0)
        setMaxDividerPosition(1.0);

    UInt32 dividerPosition(getDividerPosition());
    if (getDividerPosition() <= 1.0)
        dividerPosition = BorderSize[AxisIndex] * getDividerPosition();

    // check the divider's min and max
    if (getMinDividerPosition() <= 1.0)
    {
        if (dividerPosition < getMinDividerPosition() * BorderSize[AxisIndex])
            dividerPosition = getMinDividerPosition() * BorderSize[AxisIndex];
    }
    else
    {
        if (dividerPosition < getMinDividerPosition())
            dividerPosition = getMinDividerPosition();
    }
    if (getMaxDividerPosition() <= 1.0)
    {
        if (dividerPosition > getMaxDividerPosition() * BorderSize[AxisIndex])
            dividerPosition = getMaxDividerPosition() * BorderSize[AxisIndex];
    }
    else
    {
        if (dividerPosition > getMaxDividerPosition())
            dividerPosition = getMaxDividerPosition();
    }

    // set the minimum component's size
    minSize[AxisIndex] = dividerPosition - getDividerSize()/2;

    // check its min and max
    if (getMinComponent() != NULL)
    {
        if (minSize[AxisIndex] < getMinComponent()->getMinSize()[AxisIndex])
        {
            dividerPosition -= getMinComponent()->getMinSize()[AxisIndex] - minSize[AxisIndex];
            minSize[AxisIndex] = getMinComponent()->getMinSize()[AxisIndex];
        }
        if (minSize[AxisIndex] > getMinComponent()->getMaxSize()[AxisIndex])
        {
            dividerPosition += minSize[AxisIndex] - getMinComponent()->getMaxSize()[AxisIndex];
            minSize[AxisIndex] = getMinComponent()->getMaxSize()[AxisIndex];
        }
    }

    // set the maximum component's size
    maxSize[AxisIndex] = BorderSize[AxisIndex] - minSize[AxisIndex] - getDividerSize();

    // check its min and max
    if (getMaxComponent() != NULL)
    {
        if (maxSize[AxisIndex] < getMaxComponent()->getMinSize()[AxisIndex])
        {
            dividerPosition -= getMaxComponent()->getMinSize()[AxisIndex] - maxSize[AxisIndex];
            minSize[AxisIndex] -= getMaxComponent()->getMinSize()[AxisIndex] - maxSize[AxisIndex];
            maxSize[AxisIndex] = getMaxComponent()->getMinSize()[AxisIndex];
        }
        if (maxSize[AxisIndex] > getMaxComponent()->getMaxSize()[AxisIndex])
        {
            dividerPosition += maxSize[AxisIndex] - getMaxComponent()->getMaxSize()[AxisIndex];
            minSize[AxisIndex] += maxSize[AxisIndex] - getMaxComponent()->getMaxSize()[AxisIndex];
            maxSize[AxisIndex] = getMaxComponent()->getMaxSize()[AxisIndex];
        }
    }

    // set the minor axis' size and max's position
    minSize[(AxisIndex+1)%2] = maxSize[(AxisIndex+1)%2] = BorderSize[(AxisIndex+1)%2];
    maxPos[AxisIndex] = minSize[AxisIndex] + getDividerSize();

    // set the divider's size and position
    divSize[AxisIndex] = getDividerSize();
    divSize[(AxisIndex+1)%2] = BorderSize[(AxisIndex+1)%2];
    divPos[AxisIndex] = dividerPosition - getDividerSize()/2;

    // set the components to the right size and positions
    if (getMinComponent() != NULL)
    {
        if(getMinComponent()->getSize() != minSize)
        {
            getMinComponent()->setSize(minSize);
        }
        if(getMinComponent()->getPosition() != minPos)
        {
            getMinComponent()->setPosition(minPos);
        }
    }
    if (getMaxComponent() != NULL)
    {
        if(getMaxComponent()->getSize() != maxSize)
        {
            getMaxComponent()->setSize(maxSize);
        }
        if(getMaxComponent()->getPosition() != maxPos)
        {
            getMaxComponent()->setPosition(maxPos);
        }
    }
    if (getDividerDrawObject() != NULL)
    {
        if(getDividerDrawObject()->getSize() != divSize)
        {
            getDividerDrawObject()->setSize(divSize);
        }
        if(getDividerDrawObject()->getPosition() != divPos)
        {
            getDividerDrawObject()->setPosition(divPos);
        }
    }
}
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);
    }
}
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();
			}
		}
	}
}