/// <summary>
        /// Renders the GUISpinButton.
        /// </summary>
        public override void Render(float timePassed)
        {
            // Do not render if not visible.
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }

            // The GUISpinButton has the focus
            if (Focus)
            {
                //render the focused image
                _imageFocused.Render(timePassed);
            }
            else
            {
                //render the non-focused image
                _imageNonFocused.Render(timePassed);
            }

            // Compute with of label so that the text does not overlap the spin controls.
            int labelWidth = _width - (2 * _textOffsetX) - (2 * _spinWidth) - _textOffsetX;

            if (labelWidth <= 0)
            {
                base.Render(timePassed);
                return;
            }
            _labelControl.Width = labelWidth;

            // render the text on the button
            if (_labelControl is GUILabelControl)
            {
                ((GUILabelControl)_labelControl).TextAlignment  = _textAlignment;
                ((GUILabelControl)_labelControl).TextVAlignment = _textVAlignment;
                ((GUILabelControl)_labelControl).Label          = _label;
                ((GUILabelControl)_labelControl).TextColor      = Disabled ? _disabledColor : Focus?_textColor : _textColorNoFocus;
            }
            else
            {
                ((GUIFadeLabel)_labelControl).TextAlignment  = _textAlignment;
                ((GUIFadeLabel)_labelControl).TextVAlignment = _textVAlignment;
                ((GUIFadeLabel)_labelControl).Label          = _label;
                ((GUIFadeLabel)_labelControl).TextColor      = Disabled ? _disabledColor : Focus?_textColor : _textColorNoFocus;
            }

            int x = 0;
            int y = 0;

            switch (_textAlignment)
            {
            case Alignment.ALIGN_LEFT:
                x = _textOffsetX + _positionX;
                break;

            case Alignment.ALIGN_RIGHT:
                x = _positionX + _width - _textOffsetX;
                break;

            case Alignment.ALIGN_CENTER:
                x = _positionX + ((_width / 2) - (labelWidth / 2));
                break;
            }

            switch (_textVAlignment)
            {
            case VAlignment.ALIGN_TOP:
                y = _textOffsetY + _positionY;
                break;

            case VAlignment.ALIGN_BOTTOM:
                y = _positionY + _height - _textOffsetY;
                break;

            case VAlignment.ALIGN_MIDDLE:
                y = _positionY + ((_height / 2) - (_labelControl.Height / 2));
                break;
            }

            _labelControl.SetPosition(x, y);
            _labelControl.Render(timePassed);

            x = 0;
            y = 0;

            switch (_spinAlignment)
            {
            case Alignment.ALIGN_LEFT:
                x = _spinOffsetX + _positionX;
                break;

            case Alignment.ALIGN_RIGHT:
                x = _positionX + _width - _spinOffsetX - _spinControl.Width;
                break;

            case Alignment.ALIGN_CENTER:
                x = _positionX + ((_width / 2) - (_spinControl.Width / 2));
                break;
            }

            switch (_spinVAlignment)
            {
            case VAlignment.ALIGN_TOP:
                y = _spinOffsetY + _positionY;
                break;

            case VAlignment.ALIGN_BOTTOM:
                y = _positionY + _height - _spinOffsetY - _spinControl.Height;
                break;

            case VAlignment.ALIGN_MIDDLE:
                y = _positionY + ((_height / 2) - (_spinControl.Height / 2));
                break;
            }

            _spinControl.SetPosition(x, y);
            _spinControl.Render(timePassed);
            base.Render(timePassed);
        }
Пример #2
0
        public override void Render(float timePassed)
        {
            if (null == _font)
            {
                return;
            }
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }

            if (_containsProperty)
            {
                string strText = GUIPropertyManager.Parse(_property);

                strText = strText.Replace("\\r", "\r");
                if (strText != _previousProperty)
                {
                    _offset = 0;
                    _itemList.DisposeAndClearList();

                    _previousProperty = strText;
                    SetText(strText);
                }
            }

            int dwPosY = _positionY;

            for (int i = 0; i < _itemsPerPage; i++)
            {
                int dwPosX = _positionX;
                if (i + _offset < _itemList.Count)
                {
                    // render item
                    GUIListItem item      = (GUIListItem)_itemList[i + _offset];
                    string      strLabel1 = item.Label;
                    string      strLabel2 = item.Label2;

                    string wszText1  = String.Format("{0}", strLabel1);
                    int    dMaxWidth = _width + 16;
                    float  x         = 0;
                    if (strLabel2.Length > 0)
                    {
                        string wszText2;
                        float  fTextWidth = 0, fTextHeight = 0;
                        wszText2 = String.Format("{0}", strLabel2);
                        _font.GetTextExtent(wszText2, ref fTextWidth, ref fTextHeight);
                        dMaxWidth -= (int)(fTextWidth);
                        uint color = (uint)_textColor;
                        color = GUIGraphicsContext.MergeAlpha(color);
                        if (Shadow)
                        {
                            uint sc = (uint)_shadowColor;
                            sc = GUIGraphicsContext.MergeAlpha(sc);
                            _font.DrawShadowTextWidth((float)dwPosX + dMaxWidth, (float)dwPosY + 2, color, wszText2, _textAlignment,
                                                      _shadowAngle, _shadowDistance, sc, (float)fTextWidth);
                        }
                        else
                        {
                            _font.DrawTextWidth((float)dwPosX + dMaxWidth, (float)dwPosY + 2, color, wszText2, (float)fTextWidth,
                                                _textAlignment);
                        }
                    }
                    switch (_textAlignment)
                    {
                    case Alignment.ALIGN_RIGHT:
                        x = (float)dwPosX + _width;
                        break;

                    default:
                        x = (float)dwPosX;
                        break;
                    }
                    {
                        uint color = (uint)_textColor;
                        color = GUIGraphicsContext.MergeAlpha(color);
                        if (Shadow)
                        {
                            uint sc = (uint)_shadowColor;
                            sc = GUIGraphicsContext.MergeAlpha(sc);
                            _font.DrawShadowTextWidth(x, (float)dwPosY + 2, color, wszText1, _textAlignment,
                                                      _shadowAngle, _shadowDistance, sc, (float)dMaxWidth);
                        }
                        else
                        {
                            _font.DrawTextWidth(x, (float)dwPosY + 2, color, wszText1, (float)dMaxWidth, _textAlignment);
                        }
                        dwPosY += (int)(_itemHeight * _lineSpacing);
                    }
                }
            }
            if (_upDownEnabled)
            {
                int iPages = _itemList.Count / _itemsPerPage;
                if ((_itemList.Count % _itemsPerPage) != 0)
                {
                    iPages++;
                }

                if (iPages > 1)
                {
                    _upDownControl.Render(timePassed);
                }
            }
            base.Render(timePassed);
        }
        /// <summary>
        /// Renders the GUIButtonControl.
        /// </summary>
        public override void Render(float timePassed)
        {
            // Do not render if not visible.
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }
            base.Render(timePassed);

            // The GUIButtonControl has the focus
            if (Focus)
            {
                //render the focused image
                _imageFocused.Render(timePassed);
                GUIPropertyManager.SetProperty("#highlightedbutton", Label);
            }
            else
            {
                //render the non-focused image
                _imageNonFocused.Render(timePassed);
            }

            // render the text on the button
            if (Disabled)
            {
                if (_labelControl is GUILabelControl)
                {
                    ((GUILabelControl)_labelControl).Label     = _label;
                    ((GUILabelControl)_labelControl).TextColor = _disabledColor;
                }
                else
                {
                    ((GUIFadeLabel)_labelControl).Label     = _label;
                    ((GUIFadeLabel)_labelControl).TextColor = _disabledColor;
                }
                _labelControl.SetPosition(_textOffsetX + _positionX, _textOffsetY + _positionY);
                _labelControl.Render(timePassed);
            }
            else
            {
                if (_labelControl is GUILabelControl)
                {
                    ((GUILabelControl)_labelControl).Label     = _label;
                    ((GUILabelControl)_labelControl).TextColor = _disabledColor;
                }
                else
                {
                    ((GUIFadeLabel)_labelControl).Label     = _label;
                    ((GUIFadeLabel)_labelControl).TextColor = _textColor;
                }
                _labelControl.SetPosition(_textOffsetX + _positionX, _textOffsetY + _positionY);
                _labelControl.Render(timePassed);
            }
            base.Render(timePassed);
            if (_spinControl != null)
            {
                int off = 5;
                GUIGraphicsContext.ScaleHorizontal(ref off);
                _spinControl.SetPosition(_imageNonFocused.XPosition + _imageNonFocused.Width - off - 2 * _spinControlWidth,
                                         _imageNonFocused.YPosition + (_imageNonFocused.Height - _spinControlHeight) / 2);
                _spinControl.Render(timePassed);
            }
            //base.Render(timePassed);
        }