Пример #1
0
        /// <summary>
        /// Renders the GUICheckButton.
        /// </summary>
        public override void Render(float timePassed)
        {
            string labelText = _label;

            // Do not render if not visible.
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }

            // Set the selection based on the user specified condition.
            if (_selected.Length != 0)
            {
                try
                {
                    Selected = bool.Parse(GUIPropertyManager.Parse(_selected, GUIExpressionManager.ExpressionOptions.EVALUATE_ALWAYS));
                }
                catch (System.Exception)
                {
                    Log.Debug("GUICheckButton: id={0} <selected> expression does not return a boolean value", GetID);
                }
            }

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

            int labelWidth = _width - 2 * _textOffsetX;

            if (_textPadding > 0)
            {
                labelWidth -= GUIGraphicsContext.ScaleHorizontal(_textPadding);
            }

            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          = labelText;
                ((GUILabelControl)_labelControl).TextColor      = Disabled ? _disabledColor : Focus?_textColor : _textColorNoFocus;
            }
            else
            {
                ((GUIFadeLabel)_labelControl).TextAlignment  = _textAlignment;
                ((GUIFadeLabel)_labelControl).TextVAlignment = _textVAlignment;
                ((GUIFadeLabel)_labelControl).Label          = labelText;
                ((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 (_markAlignment)
            {
            case Alignment.ALIGN_LEFT:
                x = _markOffsetX + _positionX;
                break;

            case Alignment.ALIGN_RIGHT:
                x = _positionX + _width - _markOffsetX - checkMark.Width;
                break;

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

            switch (_markVAlignment)
            {
            case VAlignment.ALIGN_TOP:
                y = _markOffsetY + _positionY;
                break;

            case VAlignment.ALIGN_BOTTOM:
                y = _positionY + _height - _markOffsetY - checkMark.Height;
                break;

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

            checkMark.SetPosition(x, y);
            checkMark.Render(timePassed);
            base.Render(timePassed);
        }
Пример #2
0
        /// <summary>
        /// Renders the GUICheckButton.
        /// </summary>
        public override void Render(float timePassed)
        {
            // Do not render if not visible.
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }

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

            int labelWidth = _width - 2 * _textOffsetX;

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

            // render the text on the button
            _labelControl.TextAlignment  = _textAlignment;
            _labelControl.TextVAlignment = _textVAlignment;
            _labelControl.Label          = _label;
            _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 (_markAlignment)
            {
            case Alignment.ALIGN_LEFT:
                x = _markOffsetX + _positionX;
                break;

            case Alignment.ALIGN_RIGHT:
                x = _positionX + _width - _markOffsetX - checkMark.Width;
                break;

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

            switch (_markVAlignment)
            {
            case VAlignment.ALIGN_TOP:
                y = _markOffsetY + _positionY;
                break;

            case VAlignment.ALIGN_BOTTOM:
                y = _positionY + _height - _markOffsetY - checkMark.Height;
                break;

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

            checkMark.SetPosition(x, y);
            checkMark.Render(timePassed);
            base.Render(timePassed);
        }