protected override void Press(char k)
        {
            ClearLabelAsInitialText();

            // Don't add more than the maximum characters, and don't allow
            // text to exceed the width of the text entry field
            if (_textEntered.Length < MAX_CHARS)
            {
                float fWidth = 0, fHeight = 0;
                _fontSearchText.GetTextExtent(_textEntered, ref fWidth, ref fHeight);

                if (fWidth < (GUIGraphicsContext.ScaleHorizontal((int)fTextBoxWidth)))
                {
                    if (_position >= _textEntered.Length)
                    {
                        _textEntered += k.ToString();
                        OnTextChanged();
                    }
                    else
                    {
                        _textEntered = _textEntered.Insert(_position, k.ToString());
                        OnTextChanged();
                    }
                    ++_position; // move the caret
                }
            }

            // Unstick the shift key
            _shiftTurnedOn = false;
        }
        /// <summary>
        /// Renders the control.
        /// </summary>
        public override void Render(float timePassed)
        {
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
            }
            string  strValue = "";
            float   fRange = 0.0f;
            float   fPos = 0.0f;
            float   fPercent = 0.0f;
            float   fTextWidth = 0, fTextHeight = 0;
            GUIFont _font = GUIFontManager.GetFont(_valueFont);

            switch (_spinType)
            {
            // Float based slider
            case GUISpinControl.SpinType.SPIN_CONTROL_TYPE_FLOAT:
                if (null != _font && _showValue)
                {
                    strValue = String.Format("{0}", _floatValue);
                    _font.DrawText((float)_positionX, (float)_positionY,
                                   _textColor, strValue, Alignment.ALIGN_LEFT, -1);
                    _font.GetTextExtent(strValue, ref fTextWidth, ref fTextHeight);
                    _imageBackGround.SetPosition(_positionX + (int)fTextWidth + 10, _positionY);
                }

                fRange      = (float)(_floatEndValue - _floatStartValue);
                fPos        = (float)(_floatValue - _floatStartValue);
                fPercent    = (fPos / fRange) * 100.0f;
                _percentage = (int)fPercent;
                break;

            // Integer based slider
            case GUISpinControl.SpinType.SPIN_CONTROL_TYPE_INT:
                if (null != _font && _showValue)
                {
                    strValue = String.Format("{0}/{1}", _intValue, _intEndValue);
                    _font.DrawText((float)_positionX, (float)_positionY,
                                   _textColor, strValue, Alignment.ALIGN_LEFT, -1);
                    _font.GetTextExtent(strValue, ref fTextWidth, ref fTextHeight);
                    _imageBackGround.SetPosition(_positionX + (int)fTextWidth + 10, _positionY);
                }

                fRange      = (float)(_intEndValue - _intStartValue);
                fPos        = (float)(_intValue - _intStartValue);
                _percentage = (int)((fPos / fRange) * 100.0f);
                break;
            }

            int iWidthBackGround = _imageBackGround.TextureWidth;
            int iWidthMidFocus   = _imageMidFocus.TextureWidth;
            int iWidthMid        = _imageMid.TextureWidth;

            int iHeightBackGround = _imageBackGround.TextureHeight;
            int iHeightMidFocus   = _imageMidFocus.TextureHeight;
            int iHeightMid        = _imageMid.TextureHeight;

            GUIGraphicsContext.ScaleHorizontal(ref iWidthBackGround);
            GUIGraphicsContext.ScaleHorizontal(ref iWidthMidFocus);
            GUIGraphicsContext.ScaleHorizontal(ref iWidthMid);

            GUIGraphicsContext.ScaleVertical(ref iHeightBackGround);
            GUIGraphicsContext.ScaleVertical(ref iHeightMidFocus);
            GUIGraphicsContext.ScaleVertical(ref iHeightMid);

            _imageBackGround.Width  = iWidthBackGround;
            _imageBackGround.Height = iHeightBackGround;

            _imageMidFocus.Width  = iWidthMidFocus;
            _imageMidFocus.Height = iHeightMidFocus;

            _imageMid.Width  = iWidthMid;
            _imageMid.Height = iHeightMid;

            _imageBackGround.Render(timePassed);

            float fWidth = (float)(_imageBackGround.Width - _imageMid.Width); //-20.0f;

            fPos  = (float)_percentage;
            fPos /= 100.0f;
            fPos *= fWidth;
            fPos += (float)_imageBackGround.XPosition;
            //fPos += 10.0f;
            if ((int)fWidth > 1)
            {
                if (Focus)
                {
                    _imageMidFocus.SetPosition((int)fPos, _imageBackGround.YPosition);
                    _imageMidFocus.Render(timePassed);
                }
                else
                {
                    _imageMid.SetPosition((int)fPos, _imageBackGround.YPosition);
                    _imageMid.Render(timePassed);
                }
            }
            base.Render(timePassed);
        }
예제 #3
0
        public override void Render(float timePassed)
        {
            try
            {
                _invalidate = false;
                // Nothing visibile - save CPU cycles
                if (null == _font)
                {
                    base.Render(timePassed);
                    return;
                }
                if (GUIGraphicsContext.EditMode == false)
                {
                    if (!IsVisible)
                    {
                        base.Render(timePassed);
                        return;
                    }
                }

                int dwPosY = _positionY;

                _timeElapsed += timePassed;
                if (_frameLimiter < GUIGraphicsContext.MaxFPS)
                {
                    _frameLimiter++;
                }
                else
                {
                    _frameLimiter = 1;
                }

                var strText = _containsProperty ? GUIPropertyManager.Parse(_property) : _property;

                strText = strText.Replace("\\r", "\r");
                if (strText != _previousProperty)
                {
                    // Reset the scrolling position - e.g. if we switch in TV Guide between various items
                    ClearOffsets();

                    _previousProperty = strText;
                    SetText(strText);
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    _offset = 0;
                }
                if (_listItems.Count > _itemsPerPage)
                {
                    // rest before we start scrolling
                    if ((int)_timeElapsed > _scrollStartDelay)
                    {
                        _invalidate = true;
                        // apply user scroll speed setting. 1 = slowest / 10 = fastest
                        //int userSpeed = 11 - GUIGraphicsContext.ScrollSpeedVertical;           //  10 - 1

                        //if (_frameLimiter % (6 - GUIGraphicsContext.ScrollSpeedVertical) == 0)
                        //  _yPositionScroll++;
                        //_yPositionScroll = _yPositionScroll + GUIGraphicsContext.ScrollSpeedVertical;

                        int vScrollSpeed = (6 - GUIGraphicsContext.ScrollSpeedVertical);
                        if (vScrollSpeed == 0)
                        {
                            vScrollSpeed = 1;
                        }

                        _yPositionScroll += (1.0 / vScrollSpeed) * _lineSpacing; // faster scrolling, if there is bigger linespacing

                        dwPosY -= (int)((_yPositionScroll - _scrollOffset));
                        // Log.Debug("*** _frameLimiter: {0}, dwPosY: {1}, _scrollOffset: {2}, _yPositionScroll: {3}", _frameLimiter, dwPosY, _scrollOffset, _yPositionScroll);

                        if (_positionY - dwPosY >= _itemHeight * _lineSpacing)
                        {
                            // one line has been scrolled away entirely
                            dwPosY        += (int)(_itemHeight * _lineSpacing);
                            _scrollOffset += (_itemHeight * _lineSpacing);
                            _offset++;
                            if (_offset >= _listItems.Count)
                            {
                                // restart with the first line
                                if (Seperator.Length > 0)
                                {
                                    if (_offset >= _listItems.Count + 1)
                                    {
                                        _offset = 0;
                                    }
                                }
                                else
                                {
                                    _offset = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        _scrollOffset = 0.0f;
                        _frameLimiter = 1;
                        _offset       = 0;
                    }
                }
                else
                {
                    _scrollOffset = 0.0f;
                    _frameLimiter = 1;
                    _offset       = 0;
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    GUIGraphicsContext.graphics.SetClip(new Rectangle(_positionX, _positionY, _width, _height));
                }
                else
                {
                    if (_width < 1 || _height < 1)
                    {
                        base.Render(timePassed);
                        return;
                    }

                    Rectangle clipRect = new Rectangle(_positionX, _positionY, _width, _height);
                    GUIGraphicsContext.BeginClip(clipRect);
                }
                long color = _textColor;
                if (Dimmed)
                {
                    color &= DimColor;
                }
                for (int i = 0; i < 2 + _itemsPerPage; i++) // add one as the itemsPerPage might be almost one less than actual height plus one for the "incoming" item
                {
                    // skip half lines - enable, if only full lines should be visible on initial view (before scrolling starts)
                    // if (!_invalidate && i >= _itemsPerPage) continue;

                    // render each line
                    int dwPosX    = _positionX;
                    int iItem     = i + _offset;
                    int iMaxItems = _listItems.Count;
                    if (_listItems.Count > _itemsPerPage && Seperator.Length > 0)
                    {
                        iMaxItems++;
                    }

                    if (iItem >= iMaxItems)
                    {
                        if (iMaxItems > _itemsPerPage)
                        {
                            iItem -= iMaxItems;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (iItem >= 0 && iItem < iMaxItems)
                    {
                        // render item
                        string strLabel1 = "", strLabel2 = "";
                        if (iItem < _listItems.Count)
                        {
                            GUIListItem item = (GUIListItem)_listItems[iItem];
                            if (_font.containsOutOfBoundsChar(item.Label))
                            {
                                // Will hold clipped coordinates
                                float xpos = (float)dwPosX;
                                float ypos = (float)dwPosY;

                                // Get the clip rectangle.
                                Rectangle clipRect = new Rectangle(_positionX, _positionY, _width, _height);
                                float     minX     = clipRect.Left;
                                float     minY     = clipRect.Top;
                                float     maxX     = clipRect.Right;
                                float     maxY     = clipRect.Bottom;

                                // A clip rectangle is defined.  Determine if the character is inside the clip rectangle.
                                // If the character is inside the clip rectangle then clip it as necessary at the clip rectangle boundary.
                                // If the character is not inside the clip rectangle then move on to the next character (continue).
                                if (xpos < maxX && xpos >= minX && ypos < maxY && ypos >= minY)
                                {
                                }
                                else
                                {
                                    dwPosY += (int)(_itemHeight * _lineSpacing);
                                    continue;
                                }
                            }
                            strLabel1 = item.Label;
                            strLabel2 = item.Label2;
                        }
                        else
                        {
                            strLabel1 = Seperator;
                        }

                        int ixoff = _xOffset;
                        int ioffy = _yOffset;
                        GUIGraphicsContext.ScaleVertical(ref ioffy);
                        GUIGraphicsContext.ScaleHorizontal(ref ixoff);
                        string wszText1  = String.Format("{0}", strLabel1);
                        int    dMaxWidth = _width + ixoff;
                        float  x         = dwPosX;
                        if (strLabel2.Length > 0)
                        {
                            string wszText2;
                            float  fTextWidth = 0, fTextHeight = 0;
                            wszText2 = String.Format("{0}", strLabel2);
                            _font.GetTextExtent(wszText2.Trim(), ref fTextWidth, ref fTextHeight);
                            dMaxWidth -= (int)(fTextWidth);

                            switch (_textAlignment)
                            {
                            case Alignment.ALIGN_LEFT:
                            case Alignment.ALIGN_CENTER:
                                x = dwPosX + dMaxWidth;
                                break;

                            case Alignment.ALIGN_RIGHT:
                                x = dwPosX + dMaxWidth + _width;
                                break;
                            }

                            uint aColor = GUIGraphicsContext.MergeAlpha((uint)color);
                            if (Shadow)
                            {
                                uint sColor = GUIGraphicsContext.MergeAlpha((uint)_shadowColor);
                                _font.DrawShadowTextWidth(x, (float)dwPosY + ioffy,
                                                          (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor), wszText2.Trim(),
                                                          _textAlignment,
                                                          _shadowAngle, _shadowDistance, sColor, (float)dMaxWidth);
                            }
                            else
                            {
                                _font.DrawTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                    wszText2.Trim(), fTextWidth, _textAlignment);
                            }
                        }

                        switch (_textAlignment)
                        {
                        case Alignment.ALIGN_CENTER:
                        case Alignment.ALIGN_LEFT:
                            x = dwPosX;
                            break;

                        case Alignment.ALIGN_RIGHT:
                            x = dwPosX + _width;
                            break;
                        }
                        {
                            uint aColor = GUIGraphicsContext.MergeAlpha((uint)color);
                            if (Shadow)
                            {
                                uint sColor = GUIGraphicsContext.MergeAlpha((uint)_shadowColor);
                                _font.DrawShadowTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                          wszText1.Trim(), _textAlignment,
                                                          _shadowAngle, _shadowDistance, sColor, (float)dMaxWidth);
                            }
                            else
                            {
                                _font.DrawTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                    wszText1.Trim(), (float)dMaxWidth, _textAlignment);
                            }

                            // Log.Info("dw _positionY, dwPosY, _yPositionScroll, _scrollOffset: {0} {1} {2} {3} - wszText1.Trim() {4}", _positionY, dwPosY, _yPositionScroll, _scrollOffset, wszText1.Trim());

                            dwPosY += (int)(_itemHeight * _lineSpacing);
                        }
                    }
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    GUIGraphicsContext.graphics.SetClip(new Rectangle(0, 0, GUIGraphicsContext.Width, GUIGraphicsContext.Height));
                }
                else
                {
                    GUIGraphicsContext.EndClip();
                }
                base.Render(timePassed);
            }
            catch (Exception ex)
            {
                Log.Error("GUITextScrollUpControl: Error during the render process - maybe a threading issue. {0}",
                          ex.ToString());
                GUIGraphicsContext.EndClip();
            }
        }
예제 #4
0
        protected override void RenderLabel(float timePassed, int buttonNr, int dwPosX, int dwPosY, bool gotFocus)
        {
            if (buttonNr < 0 || buttonNr >= _listButtons.Count)
            {
                return;
            }

            GUIListItem pItem = _listItems[buttonNr + _offset];
            long        dwColor;

            dwPosX += _textOffsetX;
            bool bSelected = buttonNr == _cursorX && IsFocused && _listType == ListType.CONTROL_LIST;

            GUIPlayListButtonControl btn = (GUIPlayListButtonControl)_listButtons[buttonNr];
            int dMaxWidth = (_width - _imageWidth - PinIconOffsetX - GUIGraphicsContext.ScaleHorizontal(8));

            if (btn != null)
            {
                dMaxWidth = (_upBtnXOffset - _imageWidth - PinIconOffsetX - GUIGraphicsContext.ScaleHorizontal(8));
            }

            if (_text2Visible && pItem.Label2.Length > 0)
            {
                if (_textOffsetY == _textOffsetY2)
                {
                    dwColor = _textColor2;
                    if (pItem.Selected)
                    {
                        dwColor = _selectedColor2;
                    }
                    if (pItem.IsRemote)
                    {
                        dwColor = _remoteColor;
                        if (pItem.IsDownloading)
                        {
                            dwColor = _downloadColor;
                        }
                    }

                    if (pItem.IsBdDvdFolder)
                    {
                        dwColor = _bdDvdDirectoryColor;
                    }

                    int xpos;
                    int ypos = dwPosY;

                    if (0 == _textOffsetX2)
                    {
                        xpos = _positionX + _upBtnXOffset - GUIGraphicsContext.ScaleHorizontal(8);
                    }
                    else
                    {
                        xpos = _positionX + _textOffsetX2;
                    }

                    if (_labelControls2 != null)
                    {
                        if (buttonNr >= 0 && buttonNr < _labelControls2.Count)
                        {
                            GUILabelControl label2 = _labelControls2[buttonNr];
                            if (label2 != null)
                            {
                                label2.SetPosition(xpos, ypos + GUIGraphicsContext.ScaleVertical(2) + _textOffsetY2);
                                label2.TextColor     = gotFocus ? dwColor : Color.FromArgb(_unfocusedAlpha, Color.FromArgb((int)dwColor)).ToArgb();
                                label2.Label         = pItem.Label2;
                                label2.TextAlignment = Alignment.ALIGN_RIGHT;
                                label2.FontName      = _fontName2Name;
                                dMaxWidth            = label2._positionX - dwPosX - label2.TextWidth - GUIGraphicsContext.ScaleHorizontal(20);
                            }
                        }
                    }
                }
            }

            if (_text1Visible)
            {
                dwColor = _textColor;
                if (pItem.Selected)
                {
                    dwColor = _selectedColor;
                }

                if (pItem.IsRemote)
                {
                    dwColor = _remoteColor;
                    if (pItem.IsDownloading)
                    {
                        dwColor = _downloadColor;
                    }
                }

                if (pItem.IsBdDvdFolder)
                {
                    dwColor = _bdDvdDirectoryColor;
                }

                if (!gotFocus)
                {
                    dwColor = Color.FromArgb(_unfocusedAlpha, Color.FromArgb((int)dwColor)).ToArgb();
                }

                int maxWidth = dMaxWidth;
                if (_textPadding > 0)
                {
                    maxWidth -= GUIGraphicsContext.ScaleHorizontal(_textPadding);
                }

                if (maxWidth <= 0)
                {
                    base.Render(timePassed);
                }
                else
                {
                    RenderText(timePassed, buttonNr, dwPosX, (float)dwPosY + GUIGraphicsContext.ScaleVertical(2) + _textOffsetY, maxWidth, dwColor, pItem.Label, bSelected);
                }
            }

            if (pItem.Label2.Length > 0)
            {
                dwColor = _textColor2;
                if (pItem.Selected)
                {
                    dwColor = _selectedColor2;
                }

                if (pItem.IsRemote)
                {
                    dwColor = _remoteColor;
                    if (pItem.IsDownloading)
                    {
                        dwColor = _downloadColor;
                    }
                }

                if (pItem.IsBdDvdFolder)
                {
                    dwColor = _bdDvdDirectoryColor;
                }

                if (_textOffsetX2 == 0)
                {
                    dwPosX = _positionX + _upBtnXOffset - GUIGraphicsContext.ScaleHorizontal(8);
                }
                else
                {
                    dwPosX = _positionX + _textOffsetX2;
                }

                if (_text2Visible)
                {
                    if (_labelControls2 != null && (buttonNr >= 0 && buttonNr < _labelControls2.Count))
                    {
                        GUILabelControl label2 = _labelControls2[buttonNr];
                        if (label2 != null)
                        {
                            label2.SetPosition(dwPosX, dwPosY + GUIGraphicsContext.ScaleVertical(2) + _textOffsetY2);
                            label2.TextColor = gotFocus
                                   ? dwColor
                                   : Color.FromArgb(_unfocusedAlpha, Color.FromArgb((int)dwColor)).ToArgb();
                            label2.Label         = pItem.Label2;
                            label2.TextAlignment = Alignment.ALIGN_RIGHT;
                            label2.FontName      = _fontName2Name;

                            float width  = label2.Width;
                            float height = label2.Height;
                            _font.GetTextExtent(label2.Label, ref width, ref height);
                            label2.Width  = (int)width + 1;
                            label2.Height = (int)height;

                            if (_textPadding2 > 0)
                            {
                                label2.Width -= GUIGraphicsContext.ScaleHorizontal(_textPadding2);
                            }

                            if (label2.Width > 0)
                            {
                                label2.Render(timePassed);
                            }
                        }
                    }
                }
            }

            if (pItem.Label3.Length > 0)
            {
                dwColor = _textColor3;
                if (pItem.Selected)
                {
                    dwColor = _selectedColor3;
                }

                if (pItem.IsRemote)
                {
                    dwColor = _remoteColor;
                    if (pItem.IsDownloading)
                    {
                        dwColor = _downloadColor;
                    }
                }

                if (pItem.IsBdDvdFolder)
                {
                    dwColor = _bdDvdDirectoryColor;
                }

                if (0 == _textOffsetX3)
                {
                    dwPosX = _positionX + _textOffsetX;
                }
                else
                {
                    dwPosX = _positionX + _textOffsetX3;
                }

                int ypos = dwPosY;

                if (0 == _textOffsetY3)
                {
                    ypos += _textOffsetY2;
                }
                else
                {
                    ypos += _textOffsetY3;
                }

                if (_text3Visible)
                {
                    if (_labelControls3 != null)
                    {
                        if (buttonNr >= 0 && buttonNr < _labelControls3.Count)
                        {
                            GUILabelControl label3 = _labelControls3[buttonNr];

                            if (label3 != null)
                            {
                                label3.SetPosition(dwPosX, ypos);

                                label3.TextColor     = gotFocus ? dwColor : Color.FromArgb(_unfocusedAlpha, Color.FromArgb((int)dwColor)).ToArgb();
                                label3.Label         = pItem.Label3;
                                label3.TextAlignment = Alignment.ALIGN_LEFT;
                                label3.FontName      = _fontName2Name;

                                float width  = label3.Width;
                                float height = label3.Height;
                                _font.GetTextExtent(label3.Label, ref width, ref height);
                                label3.Width  = (int)width + 1;
                                label3.Height = (int)height;

                                if (_textPadding3 > 0)
                                {
                                    label3.Width -= GUIGraphicsContext.ScaleHorizontal(_textPadding3);
                                }

                                if (label3.Width > 0)
                                {
                                    label3.Render(timePassed);
                                }
                            }
                        }
                    }
                }
            }
        }
        public override void Render(float timePassed)
        {
            try
            {
                _invalidate = false;
                // Nothing visibile - save CPU cycles
                if (null == _font)
                {
                    base.Render(timePassed);
                    return;
                }
                if (GUIGraphicsContext.EditMode == false)
                {
                    if (!IsVisible)
                    {
                        base.Render(timePassed);
                        return;
                    }
                }

                int dwPosY = _positionY;

                _timeElapsed += timePassed;
                if (_frameLimiter < GUIGraphicsContext.MaxFPS)
                {
                    _frameLimiter++;
                }
                else
                {
                    _frameLimiter = 1;
                }

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

                    strText = strText.Replace("\\r", "\r");
                    if (strText != _previousProperty)
                    {
                        // Reset the scrolling position - e.g. if we switch in TV Guide between various items
                        ClearOffsets();

                        _previousProperty = strText;
                        SetText(strText);
                    }
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    _offset = 0;
                }
                if (_listItems.Count > _itemsPerPage)
                {
                    // rest before we start scrolling
                    if ((int)_timeElapsed > _scrollStartDelay)
                    {
                        _invalidate = true;
                        // apply user scroll speed setting. 1 = slowest / 10 = fastest
                        //int userSpeed = 11 - GUIGraphicsContext.ScrollSpeedVertical;           //  10 - 1

                        if (_frameLimiter % (6 - GUIGraphicsContext.ScrollSpeedVertical) == 0)
                        {
                            _yPositionScroll++;
                        }
                        //_yPositionScroll = _yPositionScroll + GUIGraphicsContext.ScrollSpeedVertical;

                        dwPosY -= (int)((_yPositionScroll - _scrollOffset) * _lineSpacing);
                        // Log.Debug("*** _frameLimiter: {0}, dwPosY: {1}, _scrollOffset: {2}", _frameLimiter, dwPosY, _scrollOffset);

                        if (_positionY - dwPosY >= _itemHeight)
                        {
                            // one line has been scrolled away entirely
                            dwPosY        += (int)(_itemHeight * _lineSpacing);
                            _scrollOffset += _itemHeight;
                            _offset++;
                            if (_offset >= _listItems.Count)
                            {
                                // restart with the first line
                                if (Seperator.Length > 0)
                                {
                                    if (_offset >= _listItems.Count + 1)
                                    {
                                        _offset = 0;
                                    }
                                }
                                else
                                {
                                    _offset = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        _scrollOffset = 0.0f;
                        _frameLimiter = 1;
                        _offset       = 0;
                    }
                }
                else
                {
                    _scrollOffset = 0.0f;
                    _frameLimiter = 1;
                    _offset       = 0;
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    GUIGraphicsContext.graphics.SetClip(new Rectangle(_positionX, _positionY,
                                                                      _width, (int)(_itemsPerPage * _itemHeight * _lineSpacing)));
                }
                else
                {
                    if (_width < 1)
                    {
                        base.Render(timePassed);
                        return;
                    }
                    if (_height < 1)
                    {
                        base.Render(timePassed);
                        return;
                    }

                    Rectangle clipRect = new Rectangle();
                    clipRect.X      = _positionX;
                    clipRect.Y      = _positionY;
                    clipRect.Width  = _width;
                    clipRect.Height = (int)(_height * _lineSpacing);
                    GUIGraphicsContext.BeginClip(clipRect);
                }
                long color = _textColor;
                if (Dimmed)
                {
                    color &= DimColor;
                }
                for (int i = 0; i < 1 + _itemsPerPage; i++)
                {
                    // render each line
                    int dwPosX    = _positionX;
                    int iItem     = i + _offset;
                    int iMaxItems = _listItems.Count;
                    if (_listItems.Count > _itemsPerPage && Seperator.Length > 0)
                    {
                        iMaxItems++;
                    }

                    if (iItem >= iMaxItems)
                    {
                        if (iMaxItems > _itemsPerPage)
                        {
                            iItem -= iMaxItems;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (iItem >= 0 && iItem < iMaxItems)
                    {
                        // render item
                        string strLabel1 = "", strLabel2 = "";
                        if (iItem < _listItems.Count)
                        {
                            GUIListItem item = (GUIListItem)_listItems[iItem];
                            strLabel1 = item.Label;
                            strLabel2 = item.Label2;
                        }
                        else
                        {
                            strLabel1 = Seperator;
                        }

                        int ixoff = _xOffset;
                        int ioffy = 2;
                        GUIGraphicsContext.ScaleVertical(ref ioffy);
                        GUIGraphicsContext.ScaleHorizontal(ref ixoff);
                        string wszText1  = String.Format("{0}", strLabel1);
                        int    dMaxWidth = _width + ixoff;
                        float  x         = dwPosX;
                        if (strLabel2.Length > 0)
                        {
                            string wszText2;
                            float  fTextWidth = 0, fTextHeight = 0;
                            wszText2 = String.Format("{0}", strLabel2);
                            _font.GetTextExtent(wszText2.Trim(), ref fTextWidth, ref fTextHeight);
                            dMaxWidth -= (int)(fTextWidth);

                            switch (_textAlignment)
                            {
                            case Alignment.ALIGN_LEFT:
                            case Alignment.ALIGN_CENTER:
                                x = dwPosX + dMaxWidth;
                                break;

                            case Alignment.ALIGN_RIGHT:
                                x = dwPosX + dMaxWidth + _width;
                                break;
                            }

                            uint aColor = GUIGraphicsContext.MergeAlpha((uint)color);
                            if (Shadow)
                            {
                                uint sColor = GUIGraphicsContext.MergeAlpha((uint)_shadowColor);
                                _font.DrawShadowTextWidth(x, (float)dwPosY + ioffy,
                                                          (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor), wszText2.Trim(),
                                                          _textAlignment,
                                                          _shadowAngle, _shadowDistance, sColor, (float)dMaxWidth);
                            }
                            else
                            {
                                _font.DrawTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                    wszText2.Trim(), fTextWidth, _textAlignment);
                            }
                        }

                        switch (_textAlignment)
                        {
                        case Alignment.ALIGN_CENTER:
                        case Alignment.ALIGN_LEFT:
                            x = dwPosX;
                            break;

                        case Alignment.ALIGN_RIGHT:
                            x = dwPosX + _width;
                            break;
                        }
                        {
                            uint aColor = GUIGraphicsContext.MergeAlpha((uint)color);
                            if (Shadow)
                            {
                                uint sColor = GUIGraphicsContext.MergeAlpha((uint)_shadowColor);
                                _font.DrawShadowTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                          wszText1.Trim(), _textAlignment,
                                                          _shadowAngle, _shadowDistance, sColor, (float)dMaxWidth);
                            }
                            else
                            {
                                _font.DrawTextWidth(x, (float)dwPosY + ioffy, (uint)GUIGraphicsContext.MergeAlpha((uint)_textColor),
                                                    wszText1.Trim(), (float)dMaxWidth, _textAlignment);
                            }

                            //            Log.Info("dw _positionY, dwPosY, _yPositionScroll, _scrollOffset: {0} {1} {2} {3}", _positionY, dwPosY, _yPositionScroll, _scrollOffset);
                            //            Log.Info("dw wszText1.Trim() {0}", wszText1.Trim());

                            dwPosY += (int)(_itemHeight * _lineSpacing);
                        }
                    }
                }

                if (GUIGraphicsContext.graphics != null)
                {
                    GUIGraphicsContext.graphics.SetClip(new Rectangle(0, 0, GUIGraphicsContext.Width, GUIGraphicsContext.Height));
                }
                else
                {
                    GUIGraphicsContext.EndClip();
                }
                base.Render(timePassed);
            }
            catch (Exception ex)
            {
                Log.Error("GUITextScrollUpControl: Error during the render process - maybe a threading issue. {0}",
                          ex.ToString());
            }
        }
        protected override void RenderKeyboardLatin(float timePassed)
        {
            // Compute the width and height of the keyboard (not including the input text box)
            int keyboardWidth  = _modeKeyWidth + _modeKeySpacing + (_keyWidth * 10) + (_keyHorizontalSpacing * 9);
            int keyboardHeight = (_keyHeight * 5);

            keyboardX = _keyboardPosX;
            keyboardY = _keyboardPosY;

            if (_keyboardPosX < 0)
            {
                keyboardX = (GUIGraphicsContext.SkinSize.Width - keyboardWidth) / 2;
            }
            if (_keyboardPosY < 0)
            {
                keyboardY = (GUIGraphicsContext.SkinSize.Height - keyboardHeight) / 2;
            }

            GUIGraphicsContext.ScalePosToScreenResolution(ref keyboardX, ref keyboardY);

            int x1, y1, x2, y2;

            // Skip drawing the label if there is no text or it should be used as initial text.
            if (_labelText != "" && !_showLabelAsInitialText)
            {
                // Show the label
                x1 = _labelBoxPosX;
                y1 = _labelBoxPosY;
                x2 = x1 + _labelBoxWidth;
                y2 = _labelBoxPosY + _labelBoxHeight;

                // Negative value for the label box width indicates that it should be calculated to be the same width as the keyboard.
                if (_labelBoxWidth < 0)
                {
                    int modeKeyWidth = _modeKeyWidth;
                    if (_useSearchLayout)
                    {
                        modeKeyWidth = _searchModeKeyWidth;
                    }
                    x2 = x1 + keyboardWidth;
                }
                fLabelBoxWidth = (float)(x2 - x1);

                DrawLabelBox(timePassed, x1, y1, x2, y2);

                // Show text input and caret
                switch (_labelAlign)
                {
                case GUIControl.Alignment.ALIGN_LEFT:
                    x1 = _labelBoxPosX + _labelOffX;
                    y1 = _labelBoxPosY + _labelOffY;
                    break;

                case GUIControl.Alignment.ALIGN_CENTER:
                    x1 = _labelBoxPosX + (int)(fLabelBoxWidth / 2.0);
                    y1 = _labelBoxPosY + _labelOffY;
                    break;

                case GUIControl.Alignment.ALIGN_RIGHT:
                    x1 = _labelBoxPosX + (int)fLabelBoxWidth - _labelOffX;
                    y1 = _labelBoxPosY + _labelOffY;
                    break;
                }

                DrawLabel(timePassed, x1, y1);
            }

            // Show the text input box
            x1 = _inputTextBoxPosX;
            y1 = _inputTextBoxPosY;
            x2 = x1 + _inputTextBoxWidth;
            y2 = _inputTextBoxPosY + _inputTextBoxHeight;

            // Negative value for the text box width indicates that it shold be calculated to be the same width as the keyboard.
            if (_inputTextBoxWidth < 0)
            {
                int modeKeyWidth = _modeKeyWidth;
                if (_useSearchLayout)
                {
                    modeKeyWidth = _searchModeKeyWidth;
                }
                x2 = x1 + keyboardWidth;
            }
            fTextBoxWidth = (float)(x2 - x1 - 2 * _inputTextOffX);

            DrawTextBox(timePassed, x1, y1, x2, y2);

            // Show text input and caret
            switch (_inputTextAlign)
            {
            case GUIControl.Alignment.ALIGN_LEFT:
                x1 = _inputTextBoxPosX + _inputTextOffX;
                y1 = _inputTextBoxPosY + _inputTextOffY;
                break;

            case GUIControl.Alignment.ALIGN_CENTER:
                x1 = _inputTextBoxPosX + (int)(fTextBoxWidth / 2.0);
                y1 = _inputTextBoxPosY + _inputTextOffY;
                break;

            case GUIControl.Alignment.ALIGN_RIGHT:
                x1 = _inputTextBoxPosX + (int)fTextBoxWidth - _inputTextOffX;
                y1 = _inputTextBoxPosY + _inputTextOffY;
                break;
            }

            DrawText(timePassed, x1, y1);

            x1 = keyboardX;
            y1 = keyboardY;

            // Draw each row
            float     fY       = y1;
            ArrayList keyBoard = (ArrayList)_keyboardList[(int)_currentKeyboard];

            for (int row = 0; row < _maxRows; ++row, fY += (_keyHeightScaled + _keyVerticalSpacing))
            {
                float     fX        = x1;
                float     fWidthSum = 0.0f;
                ArrayList keyRow    = (ArrayList)keyBoard[row];
                int       dwIndex   = 0;
                for (int i = 0; i < keyRow.Count; i++)
                {
                    // Determine key name
                    Key  key          = (Key)keyRow[i];
                    long selKeyColor  = 0xffffffff;
                    long selTextColor = _keyFontColor;

                    // Handle special key coloring
                    switch (key.xKey)
                    {
                    case Xkey.XK_SHIFT:
                        switch (_currentKeyboard)
                        {
                        case KeyboardTypes.TYPE_ALPHABET:
                        case KeyboardTypes.TYPE_ACCENTS:
                            if (_shiftTurnedOn)
                            {
                                selKeyColor = _keyPressedColor;
                            }
                            break;

                        case KeyboardTypes.TYPE_SYMBOLS:
                            selKeyColor  = _keyDisabledColor;
                            selTextColor = _keyDisabledFontColor;
                            break;
                        }
                        break;

                    case Xkey.XK_CAPSLOCK:
                        switch (_currentKeyboard)
                        {
                        case KeyboardTypes.TYPE_ALPHABET:
                        case KeyboardTypes.TYPE_ACCENTS:
                            if (_capsLockTurnedOn)
                            {
                                selKeyColor = _keyPressedColor;
                            }
                            break;

                        case KeyboardTypes.TYPE_SYMBOLS:
                            selKeyColor  = _keyDisabledColor;
                            selTextColor = _keyDisabledFontColor;
                            break;
                        }
                        break;

                    case Xkey.XK_SMS:
                        if (SmsStyleText)
                        {
                            selKeyColor = _keyPressedColor;
                            //key.name = "SMS";
                        }
                        else
                        {
                            //key.name = "STANDARD";
                        }
                        break;
                    }

                    // Highlight the current key
                    key.inFocus = false;
                    if (row == _currentRow && dwIndex == _currentKey)
                    {
                        selKeyColor  = _keyHighlightColor;
                        selTextColor = _keySelFontColor;
                        key.inFocus  = true;
                    }

                    RenderKey(timePassed, fX + fWidthSum, fY, key, selKeyColor, selTextColor);

                    int width = key.dwWidth;
                    GUIGraphicsContext.ScaleHorizontal(ref width);
                    fWidthSum += width;

                    // There's a slightly larger gap between the leftmost keys (mode keys) and the main keyboard
                    if (dwIndex == 0)
                    {
                        width = _modeKeySpacing;
                    }
                    else
                    {
                        width = _keyHorizontalSpacing;
                    }
                    GUIGraphicsContext.ScaleHorizontal(ref width);
                    fWidthSum += width;

                    ++dwIndex;
                }
            }
        }
        /// <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 * _spinWidth) - _textOffsetX;

            if (_textOffsetXHasMargin)
            {
                labelWidth = _width - (2 * _textOffsetX) - (2 * _spinWidth) - _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          = _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);
        }
        /// <summary>
        /// Renders the progress control.
        /// </summary>
        public override void Render(float timePassed)
        {
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
                if (Disabled)
                {
                    base.Render(timePassed);
                    return;
                }
            }

            if (_containsProperty)
            {
                string m_strText = GUIPropertyManager.Parse(_property);
                if (m_strText != string.Empty)
                {
                    float p;
                    Single.TryParse(m_strText, out p);
                    Percentage = p;
                }
            }

            // Render the background
            int iBkgHeight = _height;

            //GUIGraphicsContext.ScaleVertical(ref iBkgHeight); // fixing scaling bug
            _imageBackGround.Height = iBkgHeight;
            _imageBackGround.SetPosition(_imageBackGround.XPosition, _imageBackGround.YPosition);
            _imageBackGround.Render(timePassed);

            int iWidthLeft  = _imageLeft.TextureWidth;
            int iHeightLeft = (_innerheight != -1) ? _innerheight : _imageLeft.TextureHeight;
            // Legacy skin don't use innerheight
            int iWidthRight  = _imageRight.TextureWidth;
            int iHeightRight = (_innerheight != -1) ? _innerheight : _imageRight.TextureHeight;

            GUIGraphicsContext.ScaleHorizontal(ref iWidthLeft);
            GUIGraphicsContext.ScaleHorizontal(ref iWidthRight);
            GUIGraphicsContext.ScaleVertical(ref iHeightLeft);
            GUIGraphicsContext.ScaleVertical(ref iHeightRight);

            int offset = (_offset != -1) ? _offset : 12; // Legacy offset

            GUIGraphicsContext.ScaleHorizontal(ref offset);

            int iWidthMid  = (_midWidth != 0) ? _midWidth : _imageMid.TextureWidth;
            int iHeightMid = (_midHeight != 0) ? _midHeight : _imageMid.TextureHeight;

            GUIGraphicsContext.ScaleHorizontal(ref iWidthMid);
            GUIGraphicsContext.ScaleVertical(ref iHeightMid);

            int midOffsetX = (_midOffsetX != -1) ? _midOffsetX : 0;
            int midOffsetY = (_midOffsetY != -1) ? _midOffsetY : 0;

            GUIGraphicsContext.ScaleHorizontal(ref midOffsetX);
            GUIGraphicsContext.ScaleVertical(ref midOffsetY);

            float fWidth = _percentage;

            if (fWidth > 100.0f)
            {
                fWidth = 100.0f;
            }

            if (_onlyMidTexture)
            {
                fWidth *= (float)(iWidthMid);
                fWidth /= 100.0f;

                int iXPos = _imageBackGround.XPosition + midOffsetX;
                int iYPos = _imageBackGround.YPosition + midOffsetY;

                if (_percentage > 0 && fWidth > 1)
                {
                    _imageMid.SetPosition(iXPos, iYPos);
                    _imageMid.Height = iHeightMid;
                    _imageMid.Width  = (int)Math.Abs(fWidth);
                    _imageMid.SetPosition(iXPos, iYPos);
                    _imageMid.Render(timePassed);
                }
            }
            else
            {
                fWidth *= (float)(_imageBackGround.Width - 2 * offset - iWidthLeft - iWidthRight);
                fWidth /= 100.0f;

                int iXPos = offset + _imageBackGround.XPosition;

                int iYPos = _imageBackGround.YPosition + (iBkgHeight - iHeightLeft) / 2;

                _imageLeft.SetPosition(iXPos, iYPos);
                _imageLeft.Height = iHeightLeft;
                _imageLeft.Width  = iWidthLeft;
                _imageLeft.SetPosition(iXPos, iYPos);
                _imageLeft.Render(timePassed);

                iXPos += iWidthLeft;
                if (_percentage > 0 && fWidth > 1)
                {
                    _imageMid.SetPosition(iXPos, iYPos);
                    _imageMid.Height = iHeightLeft;
                    _imageMid.Width  = (int)Math.Abs(fWidth);
                    _imageMid.SetPosition(iXPos, iYPos);
                    _imageMid.Render(timePassed);
                    iXPos += (int)fWidth;
                }

                _imageRight.SetPosition(iXPos, iYPos);
                _imageRight.Height = iHeightRight;
                _imageRight.Width  = iWidthRight;
                _imageRight.SetPosition(iXPos, iYPos);
                _imageRight.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);
        }
예제 #10
0
        /// <summary>
        /// Renders the progress control.
        /// </summary>
        public override void Render(float timePassed)
        {
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
                if (Disabled)
                {
                    base.Render(timePassed);
                    return;
                }
            }
            int tb = 0;

            try
            {
                tb = Int32.Parse(GUIPropertyManager.Parse("#statusbarTB"));
            }
            catch (Exception ex)
            {
                Log.Error("GUIStatusbarControl render: " + ex.Message);
            }

            if (_containsProperty)
            {
                string m_strText = GUIPropertyManager.Parse(_property);
                if (m_strText != string.Empty)
                {
                    try
                    {
                        Percentage = Int32.Parse(m_strText);
                        if (Percentage <= -1)
                        {
                            base.Render(timePassed);
                            return;
                        }
                        if (Percentage > 100)
                        {
                            Percentage = 100;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("GUIStatusbarControl render2: " + ex.Message);
                    }
                }
            }

            int yPosTop = 0;

            try
            {
                yPosTop = Convert.ToInt16(_top);
            }
            catch (Exception ex)
            {
                Log.Error("GUIStatusbarControl render3: " + ex.Message);
            }

            // Render the background
            int iBkgHeight = _height;

            _imageBackground.Height = iBkgHeight;
            if (tb == 1)
            {
                _imageBackground.SetPosition(_imageBackground.XPosition, yPosTop);
            }
            else
            {
                _imageBackground.SetPosition(_imageBackground.XPosition, _imageBackground.YPosition);
            }
            _imageBackground.Render(timePassed);

            int iWidthLeft   = _imageLeft.TextureWidth;
            int iHeightLeft  = _imageLeft.TextureHeight;
            int iWidthRight  = _imageRight.TextureWidth;
            int iHeightRight = _imageRight.TextureHeight;

            GUIGraphicsContext.ScaleHorizontal(ref iWidthLeft);
            GUIGraphicsContext.ScaleHorizontal(ref iWidthRight);
            GUIGraphicsContext.ScaleVertical(ref iHeightLeft);
            GUIGraphicsContext.ScaleVertical(ref iHeightRight);
            //iHeight=20;
            float fWidth = (float)_percentage;

            fWidth /= 100.0f;
            fWidth *= (float)(_imageBackground.Width - 24 - iWidthLeft - iWidthRight);

            int off = 12;

            GUIGraphicsContext.ScaleHorizontal(ref off);
            int iXPos = off + _imageBackground.XPosition;

            int iYPos = 0;

            if (tb == 1)
            {
                // top
                iYPos = yPosTop + (iBkgHeight - iHeightLeft) / 2;
            }
            else
            {
                // bottom
                iYPos = _imageBackground.YPosition + (iBkgHeight - iHeightLeft) / 2;
            }
            //_imageLeft.SetHeight(iHeight);
            _imageLeft.SetPosition(iXPos, iYPos);
            _imageLeft.Height = iHeightLeft;
            _imageLeft.Width  = iWidthLeft;
            _imageLeft.SetPosition(iXPos, iYPos);
            _imageLeft.Render(timePassed);

            iXPos += iWidthLeft;
            if (_percentage > 0 && (int)fWidth > 1)
            {
                _imageMid.SetPosition(iXPos, iYPos);
                _imageMid.Height = iHeightLeft; //_imageMid.TextureHeight;
                _imageMid.Width  = (int)fWidth;
                _imageMid.SetPosition(iXPos, iYPos);
                _imageMid.Render(timePassed);
                iXPos += (int)fWidth;
            }
            //_imageRight.SetHeight(iHeight);
            _imageRight.SetPosition(iXPos, iYPos);
            _imageRight.Height = iHeightRight;
            _imageRight.Width  = iWidthRight;
            _imageRight.SetPosition(iXPos, iYPos);
            _imageRight.Render(timePassed);
            base.Render(timePassed);
        }
예제 #11
0
        public override void Render(float timePassed)
        {
            if (GUIGraphicsContext.EditMode == false)
            {
                if (!IsVisible)
                {
                    base.Render(timePassed);
                    return;
                }
                if (Disabled)
                {
                    base.Render(timePassed);
                    return;
                }
            }
            if (_propertyLabel.Length > 0)
            {
                string m_strText = GUIPropertyManager.Parse(_propertyLabel);
                if (m_strText.Length > 0 && !m_strText.Contains(@"#"))
                {
                    try
                    {
                        Percentage1 = float.Parse(m_strText);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("GUITVProgressControl: Render() {0}", ex.Message);
                    }
                    if (Percentage1 < 0 || Percentage1 > 100)
                    {
                        Percentage1 = 0;
                    }
                }
            }
            if (Label1.Length > 0)
            {
                string strText = GUIPropertyManager.Parse(Label1);
                if (strText.Length > 0 && !strText.Contains(@"#"))
                {
                    try
                    {
                        Percentage1 = float.Parse(strText);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("GUITVProgressControl: Render2() {0}", ex.Message);
                    }

                    if (Percentage1 < 0 || Percentage1 > 100)
                    {
                        Percentage1 = 0;
                    }
                }
            }

            if (Label2.Length > 0)
            {
                string strText = GUIPropertyManager.Parse(Label2);
                if (strText.Length > 0 && !strText.Contains(@"#"))
                {
                    try
                    {
                        Percentage2 = float.Parse(strText);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("GUITVProgressControl: Render3() {0}", ex.Message);
                    }
                    if (Percentage2 < 0 || Percentage2 > 100)
                    {
                        Percentage2 = 0;
                    }
                }
            }
            if (Label3.Length > 0)
            {
                string strText = GUIPropertyManager.Parse(Label3);
                if (strText.Length > 0 && !strText.Contains(@"#"))
                {
                    try
                    {
                        Percentage3 = float.Parse(strText);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("GUITVProgressControl: Render4() {0}", ex.Message);
                    }
                    if (Percentage3 < 0 || Percentage3 > 100)
                    {
                        Percentage3 = 0;
                    }
                }
            }

            //parse labels for markers
            //only going to parse if the values are different than the current value
            string tempStarts = GUIPropertyManager.Parse(LabelMarkerStarts);
            string tempEnds   = GUIPropertyManager.Parse(LabelMarkerEnds);

            if (_markerStarts != tempStarts || _markerEnds != tempEnds)
            {
                parseMarkerValues(tempStarts, tempEnds);
                _markerStarts = tempStarts;
                _markerEnds   = tempEnds;
            }

            int iWidthLeft   = _imageLeft.TextureWidth;
            int iHeightLeft  = _imageLeft.TextureHeight;
            int iWidthRight  = _imageRight.TextureWidth;
            int iHeightRight = _imageRight.TextureHeight;

            GUIGraphicsContext.ScaleHorizontal(ref iWidthLeft);
            GUIGraphicsContext.ScaleHorizontal(ref iWidthRight);
            GUIGraphicsContext.ScaleVertical(ref iHeightLeft);
            GUIGraphicsContext.ScaleVertical(ref iHeightRight);

            int xPos = _positionX;

            _imageLeft.SetPosition(xPos, _positionY);

            _imageLeft.Height = iHeightLeft;
            _imageLeft.Width  = iWidthLeft;

            xPos = _positionX + iWidthLeft;
            _imageMid.SetPosition(xPos, _positionY);

            int iWidth = _width - (iWidthLeft + iWidthRight);

            _imageMid.Width = iWidth;

            xPos = iWidth + _positionX + iWidthLeft;
            _imageRight.SetPosition(xPos, _positionY);

            _imageRight.Height = iHeightRight;
            _imageRight.Width  = iWidthRight;

            _imageLeft.Render(timePassed);
            _imageRight.Render(timePassed);
            _imageMid.Render(timePassed);

            int iWidth1 = 0, iWidth2 = 0, iWidth3 = 0;

            iWidth -= 2 * _fillBackgroundOffsetX;
            float fWidth  = iWidth;
            int   iCurPos = 0;

            // render fillbkg

            xPos = _positionX + iWidthLeft + _fillBackgroundOffsetX;
            _imageFillBackground.Width  = iWidth;
            _imageFillBackground.Height = _imageMid.TextureHeight - _fillBackgroundOffsetY * 2;
            _imageFillBackground.SetPosition(xPos, _positionY + _fillBackgroundOffsetY);
            _imageFillBackground.Render(timePassed);


            int xoff = GUIGraphicsContext.ScaleHorizontal(3);

            xPos = _positionX + iWidthLeft + _fillBackgroundOffsetX + xoff;
            int yPos = _imageFillBackground.YPosition + (_imageFillBackground.Height / 2) - (_fillBackgroundHeight / 2);

            iWidth -= 2 * xoff;
            if (yPos < _positionY)
            {
                yPos = _positionY;
            }
            //render commercial markers
            fWidth  = (float)iWidth;
            fWidth /= 100.0f;
            calculateMarkerSizeAndPosition(xPos, yPos, fWidth);
            for (int i = 0; i < _markerYPositions.Count || i < _markerXPositions.Count || i < _markerWidths.Count; i++)
            {
                _imageFillMarker.Width = _markerWidths[i];
                _imageFillMarker.SetPosition(_markerXPositions[i], _markerYPositions[i]);
                _imageFillMarker.Render(timePassed);
            }

            //render first color
            xPos    = _positionX + _imageLeft.TextureWidth + _fillBackgroundOffsetX + xoff;
            fWidth  = (float)iWidth;
            fWidth /= 100.0f;
            fWidth *= (float)Percentage1;
            iWidth1 = (int)Math.Floor(fWidth);
            if (iWidth1 > 0)
            {
                _imageFill1.Height = _fillBackgroundHeight;
                _imageFill1.Width  = iWidth1;
                _imageFill1.SetPosition(xPos, yPos);
                _imageFill1.Render(timePassed); // red
            }
            iCurPos = iWidth1 + xPos;

            //render 2nd color
            float fPercent;

            if (Percentage2 >= Percentage1)
            {
                fPercent = Percentage2 - Percentage1;
            }
            else
            {
                fPercent = 0;
            }
            fWidth  = (float)iWidth;
            fWidth /= 100.0f;
            fWidth *= (float)fPercent;
            iWidth2 = (int)Math.Floor(fWidth);
            if (iWidth2 > 0)
            {
                _imageFill2.Width  = iWidth2;
                _imageFill2.Height = _fillBackgroundHeight;
                _imageFill2.SetPosition(iCurPos, yPos);
                _imageFill2.Render(timePassed);
            }
            iCurPos = iWidth1 + iWidth2 + xPos;

            if (Percentage3 >= Percentage2)
            {
                //render 3th color
                fPercent = Percentage3 - Percentage2;
            }
            else
            {
                fPercent = 0;
            }
            fWidth  = (float)iWidth;
            fWidth /= 100.0f;
            fWidth *= (float)fPercent;
            iWidth3 = (int)Math.Floor(fWidth);
            if (iWidth3 > 0)
            {
                _imageFill3.Width  = iWidth3;
                _imageFill3.Height = _fillBackgroundHeight;
                _imageFill3.SetPosition(iCurPos, yPos);
                _imageFill3.Render(timePassed);
            }

            // render ticks
            _imageTick.Height = _imageTick.TextureHeight;
            _imageTick.Width  = _imageTick.TextureWidth;
            int posx1 = 10;
            int posx2 = 20;
            int posy1 = 3;

            GUIGraphicsContext.ScaleHorizontal(ref posx1);
            GUIGraphicsContext.ScaleHorizontal(ref posx2);
            GUIGraphicsContext.ScaleVertical(ref posy1);
            for (int i = 0; i <= 100; i += 10)
            {
                float fpos = (float)_positionX + iWidthLeft + posx1;
                fWidth  = (float)(iWidth - posx2);
                fWidth /= 100.0f;
                fWidth *= (float)i;
                _imageTick.SetPosition((int)(fpos + fWidth), (int)_positionY + posy1);
                _imageTick.Render(timePassed);
            }

            // render top
            _imageTop.Height = GUIGraphicsContext.ScaleVertical(_imageTop.TextureHeight);
            _imageTop.Width  = GUIGraphicsContext.ScaleHorizontal(_imageTop.TextureWidth);

            xPos = iCurPos - (_imageTop.Width / 2);
            _imageTop.SetPosition(xPos,
                                  _positionY - _imageTop.Height + _topTextureOffsetY - GUIGraphicsContext.ScaleVertical(1));
            _imageTop.Render(timePassed);

            //render tick @ current position
            _imageTick.Height = _imageFillBackground.TextureHeight;
            _imageTick.Width  = _imageTick.TextureWidth * 2;
            _imageTick.SetPosition((int)(_imageTop.XPosition + (_imageTop.TextureWidth / 2) - (_imageTick.Width / 2)),
                                   (int)_imageFillBackground.YPosition);
            _imageTick.Render(timePassed);

            // render bottom
            _imageBottom.Height = GUIGraphicsContext.ScaleVertical(_imageBottom.TextureHeight);
            _imageBottom.Width  = GUIGraphicsContext.ScaleHorizontal(_imageBottom.TextureWidth);

            xPos = _imageTop.XPosition + (_imageTop.Width / 2) - (_imageBottom.Width / 2);
            _imageBottom.SetPosition(xPos, _positionY + _imageMid.Height);
            _imageBottom.Render(timePassed);


            //render logo
            _imageLogo.Height = GUIGraphicsContext.ScaleVertical(_imageLogo.TextureHeight);
            _imageLogo.Width  = GUIGraphicsContext.ScaleHorizontal(_imageLogo.TextureWidth);
            float fx = (float)_imageBottom.XPosition;

            fx += (((float)_imageBottom.Width) / 2f);
            fx -= (((float)_imageLogo.TextureWidth) / 2f);

            float fy = (float)_imageBottom.YPosition;

            fy += (((float)_imageBottom.Height) / 2f);
            fy -= (((float)_imageLogo.Height) / 2f);
            _imageLogo.SetPosition((int)fx, (int)fy);
            _imageLogo.Render(timePassed);

            if (_font != null)
            {
                float  fW = 0, fH = 0;
                float  fHeight = 0;
                string strText = "";

                // render top text
                if (_labelTop.Length > 0)
                {
                    strText = GUIPropertyManager.Parse(_labelTop);
                    _font.GetTextExtent(strText, ref fW, ref fH);
                    fW      /= 2.0f;
                    fH      /= 2.0f;
                    fWidth   = ((float)_imageTop.Width) / 2.0f;
                    fHeight  = ((float)_imageTop.Height) / 2.0f;
                    fWidth  -= fW;
                    fHeight -= fH;
                    _font.DrawText((float)_imageTop.XPosition + fWidth, (float)2 + _imageTop.YPosition + fHeight, _textColor,
                                   strText, Alignment.ALIGN_LEFT, -1);
                }


                // render left text
                if (_labelLeft.Length > 0)
                {
                    strText = GUIPropertyManager.Parse(_labelLeft);
                    _font.GetTextExtent(strText, ref fW, ref fH);
                    fW      /= 2.0f;
                    fH      /= 2.0f;
                    fWidth   = ((float)iWidthLeft) / 2.0f;
                    fHeight  = ((float)iHeightLeft) / 2.0f;
                    fWidth  -= fW;
                    fHeight -= fH;
                    _font.DrawText((float)_positionX + fWidth, (float)_positionY + fHeight, _textColor, strText,
                                   Alignment.ALIGN_LEFT, -1);
                }

                // render right text
                if (_labelRight.Length > 0)
                {
                    strText = GUIPropertyManager.Parse(_labelRight);
                    _font.GetTextExtent(strText, ref fW, ref fH);
                    fW      /= 2.0f;
                    fH      /= 2.0f;
                    fWidth   = ((float)iWidthRight) / 2.0f;
                    fHeight  = ((float)iHeightRight) / 2.0f;
                    fWidth  -= fW;
                    fHeight -= fH;
                    _font.DrawText((float)_imageRight.XPosition + fWidth, (float)_imageRight.YPosition + fHeight, _textColor,
                                   strText, Alignment.ALIGN_LEFT, -1);
                }
            }
            base.Render(timePassed);
        }