Ejemplo n.º 1
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();
            }
        }