// Wraps the calls to the GUIFont. This provides opportunity to shadow the text if requested. public void DrawTextWidth(float xpos, float ypos, string label, float fMaxWidth) { long c = (uint)_textColor; if (Dimmed) { c &= (DimColor); } c = GUIGraphicsContext.MergeAlpha((uint)c); if (Shadow) { long sc = (uint)_shadowColor; if (Dimmed) { sc &= DimColor; } sc = GUIGraphicsContext.MergeAlpha((uint)sc); _font.DrawShadowTextWidth(xpos, ypos, c, label, Alignment.ALIGN_LEFT, _shadowAngle, _shadowDistance, sc, fMaxWidth); } else { _font.DrawTextWidth(xpos, ypos, c, label, fMaxWidth, Alignment.ALIGN_LEFT); } }
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(); } }
public override void Render(float timePassed) { if (null == _font) { return; } if (GUIGraphicsContext.EditMode == false) { if (!IsVisible) { base.Render(timePassed); return; } } if (_containsProperty) { string strText = GUIPropertyManager.Parse(_property); strText = strText.Replace("\\r", "\r"); if (strText != _previousProperty) { _offset = 0; _itemList.DisposeAndClearList(); _previousProperty = strText; SetText(strText); } } int dwPosY = _positionY; for (int i = 0; i < _itemsPerPage; i++) { int dwPosX = _positionX; if (i + _offset < _itemList.Count) { // render item GUIListItem item = (GUIListItem)_itemList[i + _offset]; string strLabel1 = item.Label; string strLabel2 = item.Label2; string wszText1 = String.Format("{0}", strLabel1); int dMaxWidth = _width + 16; float x = 0; if (strLabel2.Length > 0) { string wszText2; float fTextWidth = 0, fTextHeight = 0; wszText2 = String.Format("{0}", strLabel2); _font.GetTextExtent(wszText2, ref fTextWidth, ref fTextHeight); dMaxWidth -= (int)(fTextWidth); uint color = (uint)_textColor; color = GUIGraphicsContext.MergeAlpha(color); if (Shadow) { uint sc = (uint)_shadowColor; sc = GUIGraphicsContext.MergeAlpha(sc); _font.DrawShadowTextWidth((float)dwPosX + dMaxWidth, (float)dwPosY + 2, color, wszText2, _textAlignment, _shadowAngle, _shadowDistance, sc, (float)fTextWidth); } else { _font.DrawTextWidth((float)dwPosX + dMaxWidth, (float)dwPosY + 2, color, wszText2, (float)fTextWidth, _textAlignment); } } switch (_textAlignment) { case Alignment.ALIGN_RIGHT: x = (float)dwPosX + _width; break; default: x = (float)dwPosX; break; } { uint color = (uint)_textColor; color = GUIGraphicsContext.MergeAlpha(color); if (Shadow) { uint sc = (uint)_shadowColor; sc = GUIGraphicsContext.MergeAlpha(sc); _font.DrawShadowTextWidth(x, (float)dwPosY + 2, color, wszText1, _textAlignment, _shadowAngle, _shadowDistance, sc, (float)dMaxWidth); } else { _font.DrawTextWidth(x, (float)dwPosY + 2, color, wszText1, (float)dMaxWidth, _textAlignment); } dwPosY += (int)(_itemHeight * _lineSpacing); } } } if (_upDownEnabled) { int iPages = _itemList.Count / _itemsPerPage; if ((_itemList.Count % _itemsPerPage) != 0) { iPages++; } if (iPages > 1) { _upDownControl.Render(timePassed); } } base.Render(timePassed); }
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()); } }