/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="name"></param> protected ItemView(string type, string name) : base(type, name) { d_itemModel = null; d_textColourRect = new ColourRect(DefaultTextColour); _selectionTextColourRect = new ColourRect(DefaultTextColour); d_selectionColourRect = new ColourRect(DefaultSelectionColour); d_isDirty = true; d_needsFullRender = true; d_lastSelectedIndex = null; d_selectionBrush = null; d_vertScrollbarDisplayMode = ScrollbarDisplayMode.WhenNeeded; d_horzScrollbarDisplayMode = ScrollbarDisplayMode.WhenNeeded; d_isItemTooltipsEnabled = false; d_isMultiSelectEnabled = false; d_sortMode = ViewSortMode.None; d_isAutoResizeHeightEnabled = false; d_isAutoResizeWidthEnabled = false; d_renderedMaxWidth = 0; d_renderedTotalHeight = 0; // TODO: d_eventChildrenAddedConnection = null; // TODO: d_eventChildrenRemovedConnection = null; AddItemViewProperties(); }
/// <summary> /// Return a ColourRect object describing the colours in \a cols after having their alpha /// component modulated by the value \a alpha. /// </summary> /// <param name="cols"></param> /// <param name="alpha"></param> /// <returns></returns> protected ColourRect GetModulateAlphaColourRect(ColourRect cols, float alpha) { return(new ColourRect(CalculateModulatedAlphaColour(cols.d_top_left, alpha), CalculateModulatedAlphaColour(cols.d_top_right, alpha), CalculateModulatedAlphaColour(cols.d_bottom_left, alpha), CalculateModulatedAlphaColour(cols.d_bottom_right, alpha))); }
/// <summary> /// Constructor /// </summary> /// <param name="text"></param> /// <param name="itemId"></param> /// <param name="itemData"></param> /// <param name="disabled"></param> /// <param name="autoDelete"></param> public ListboxTextItem(string text, int itemId = 0, object itemData = null, bool disabled = false, bool autoDelete = true) : base(text, itemId, itemData, disabled, autoDelete) { _textCols = new ColourRect(DefaultTextColour); _font = null; _renderedStringValid = false; _textParsingEnabled = true; }
/// <summary> /// Set the given ColourRect to the colour(s) fetched from the named /// property if it exists, else the default colour of black. /// </summary> /// <param name="propertyName"> /// String object holding the name of the property to be accessed if it /// exists. /// </param> /// <param name="colourRect"> /// Reference to a ColourRect that will be set. /// </param> public void SetColourRectToOptionalPropertyColour(string propertyName, ref ColourRect colourRect) { if (Window.IsPropertyPresent(propertyName)) { colourRect = Window.GetProperty <ColourRect>(propertyName); } else { colourRect.SetColours(new Colour(0)); } }
/// <summary> /// Draw the tree item in its current state /// </summary> /// <param name="geometryBuffers"></param> /// <param name="targetRect"></param> /// <param name="alpha"> /// Alpha value to be used when rendering the item (between 0.0f and 1.0f). /// </param> /// <param name="clipper"> /// Rect object describing the clipping rectangle for the draw operation. /// </param> public virtual IEnumerable <GeometryBuffer> Draw(Rectf targetRect, float alpha, Rectf?clipper) { var geometryBuffers = new List <GeometryBuffer>(); var finalRect = targetRect; var imgRenderSettings = new ImageRenderSettings(finalRect, clipper, true, new ColourRect(0xffffffff), alpha); if (d_iconImage != null) { var finalPos = finalRect; finalPos.Width = targetRect.Height; // xdinos ??? finalPos.Height = targetRect.Height; imgRenderSettings.DestArea = finalPos; geometryBuffers.AddRange(d_iconImage.CreateRenderGeometry(imgRenderSettings)); finalRect.d_min.X += targetRect.Height; } imgRenderSettings.DestArea = finalRect; if (d_selected && d_selectBrush != null) { imgRenderSettings.MultiplyColours = d_selectCols; geometryBuffers.AddRange(d_selectBrush.CreateRenderGeometry(imgRenderSettings)); } var font = GetFont(); if (font == null) { return(geometryBuffers); } var draw_pos = finalRect.Position; draw_pos.Y -= (font.GetLineSpacing() - font.GetBaseline()) * 0.5f; if (!d_renderedStringValid) { ParseTextString(); } var final_colours = new ColourRect(0xFFFFFFFF); for (var i = 0; i < d_renderedString.GetLineCount(); ++i) { //d_renderedString.Draw(d_owner, i, geometryBuffers, draw_pos, final_colours, clipper, 0.0f); geometryBuffers.AddRange(d_renderedString.CreateRenderGeometry(d_owner, i, draw_pos, final_colours, clipper, 0.0f)); draw_pos.Y += d_renderedString.GetPixelSize(d_owner, i).Height; } return(geometryBuffers); }
private void AppendSubstring(RenderedString rs, string @string, Font initialFont, ColourRect initialColours) { var rstc = new RenderedStringTextComponent(@string, initialFont); if (initialColours != null) { rstc.SetColours(initialColours); } rs.AppendComponent(rstc); }
/// <summary> /// Constructor /// </summary> /// <param name="type"></param> public FalagardStaticText(string type) : base(type) { _horzFormatting = HorizontalTextFormatting.LeftAligned; _vertFormatting = VerticalTextFormatting.CentreAligned; _textCols = new ColourRect(0xFFFFFFFF); _enableVertScrollbar = false; _enableHorzScrollbar = false; _formattedRenderedString = null; _formatValid = false; DefineProperty( "TextColours", "Property to get/set the text colours for the FalagardStaticText widget. Value is \"tl:[aarrggbb] tr:[aarrggbb] bl:[aarrggbb] br:[aarrggbb]\".", (w, v) => w.SetTextColours(v), w => w.GetTextColours(), new ColourRect(0xFFFFFFFF)); DefineProperty( "HorzFormatting", "Property to get/set the horizontal formatting mode. Value is one of the HorzFormatting strings.", (w, v) => w.SetHorizontalFormatting(v), w => w.GetHorizontalFormatting(), HorizontalTextFormatting.LeftAligned); DefineProperty( "VertFormatting", "Property to get/set the vertical formatting mode. Value is one of the VertFormatting strings.", (w, v) => w.SetVerticalFormatting(v), w => w.GetVerticalFormatting(), VerticalTextFormatting.CentreAligned); DefineProperty( "VertScrollbar", "Property to get/set the setting for the vertical scroll bar. Value is either \"True\" or \"False\".", (w, v) => w.SetVerticalScrollbarEnabled(v), w => w.IsVerticalScrollbarEnabled(), false); DefineProperty( "HorzScrollbar", "Property to get/set the setting for the horizontal scroll bar. Value is either \"True\" or \"False\".", (w, v) => w.SetHorizontalScrollbarEnabled(v), w => w.IsHorizontalScrollbarEnabled(), false); DefineProperty( "HorzExtent", "Property to get the current horizontal extent of the formatted text string. Value is a float indicating the pixel extent.", null, w => w.GetHorizontalTextExtent(), 0); DefineProperty( "VertExtent", "Property to get the current vertical extent of the formatted text string. Value is a float indicating the pixel extent.", null, w => w.GetVerticalTextExtent(), 0); }
/// <summary> /// base class constructor /// </summary> /// <param name="text"></param> /// <param name="itemId"></param> /// <param name="itemData"></param> /// <param name="disabled"></param> /// <param name="autoDelete"></param> public TreeItem(string text, int itemId = 0, object itemData = null, bool disabled = false, bool autoDelete = true) { d_bidiVisualMapping = new NBidiVisualMapping(); d_bidiDataValid = false; d_itemId = itemId; d_itemData = itemData; d_selected = false; d_disabled = disabled; d_autoDelete = autoDelete; d_buttonLocation = Rectf.Zero; d_owner = null; d_selectCols = new ColourRect(DefaultSelectionColour); d_selectBrush = null; d_textCols = new ColourRect(DefaultTextColour); d_font = null; d_iconImage = null; d_isOpen = false; d_renderedStringValid = false; SetText(text); }
/// <summary> /// base class constructor /// </summary> /// <param name="text"></param> /// <param name="itemId"></param> /// <param name="itemData"></param> /// <param name="disabled"></param> /// <param name="autoDelete"></param> protected ListboxItem(string text, int itemId = 0, object itemData = null, bool disabled = false, bool autoDelete = true) { #if CEGUI_BIDI_SUPPORT _bidiVisualMapping = new NBidiVisualMapping(); #else _bidiVisualMapping = null; #endif _itemId = itemId; _itemData = itemData; Selected = false; _disabled = disabled; _autoDelete = autoDelete; Owner = null; SelectCols = new ColourRect(DefaultSelectionColour); SelectBrush = null; SetText(text); }
public override List <GeometryBuffer> CreateRenderGeometry(Rectf targetRect, float alpha, Rectf?clipper) { var geomBuffers = new List <GeometryBuffer>(); if (Selected && SelectBrush != null) { var imgRenderSettings = new ImageRenderSettings(targetRect, clipper, true, SelectCols, alpha); geomBuffers.AddRange(SelectBrush.CreateRenderGeometry(imgRenderSettings)); } var font = GetFont(); if (font == null) { return(geomBuffers); } var drawPos = targetRect.Position; drawPos.Y += CoordConverter.AlignToPixels((font.GetLineSpacing() - font.GetFontHeight()) * 0.5f); if (!_renderedStringValid) { ParseTextString(); } var finalColours = new ColourRect(0xFFFFFFFF); for (var i = 0; i < _renderedString.GetLineCount(); ++i) { geomBuffers.AddRange(_renderedString.CreateRenderGeometry(Owner, i, drawPos, finalColours, clipper, 0.0f)); drawPos.Y += _renderedString.GetPixelSize(Owner, i).Height; } return(geomBuffers); }
public RenderedString Parse(string inputString, Font initialFont, ColourRect initialColours) { var rs = new RenderedString(); int epos, spos = 0; while ((epos = inputString.IndexOf('\n', spos)) != -1) { AppendSubstring(rs, inputString.CEGuiSubstring(spos, epos - spos), initialFont, initialColours); rs.AppendLineBreak(); // set new start position (skipping the previous \n we found) spos = epos + 1; } if (spos < inputString.Length) { AppendSubstring(rs, inputString.Substring(spos), initialFont, initialColours); } return(rs); }
/// <summary> /// set the given ColourRect to the colours to be used for rendering the /// selection highlight when the editbox is inactive. /// </summary> /// <param name="colourRect"></param> protected void SetColourRectToInactiveSelectionColour(ref ColourRect colourRect) { SetColourRectToOptionalPropertyColour(InactiveSelectionColourPropertyName, ref colourRect); }
/// <summary> /// Render text lines. /// </summary> /// <param name="destArea"></param> protected void CacheTextLines(Rectf destArea) { var w = (MultiLineEditbox)Window; // text is already formatted, we just grab the lines and // create the render geometry for them with the required alignment. var drawArea = destArea; var vertScrollPos = w.GetVertScrollbar().GetScrollPosition(); drawArea.Offset(new Lunatics.Mathematics.Vector2(-w.GetHorzScrollbar().GetScrollPosition(), -vertScrollPos)); var fnt = w.GetFont(); if (fnt != null) { // calculate final colours to use. var alpha = w.GetEffectiveAlpha(); var normalTextCol = new ColourRect(); SetColourRectToUnselectedTextColour(ref normalTextCol); normalTextCol.ModulateAlpha(alpha); var selectTextCol = new ColourRect(); SetColourRectToSelectedTextColour(ref selectTextCol); selectTextCol.ModulateAlpha(alpha); var selectBrushCol = new ColourRect(); if (w.HasInputFocus()) { SetColourRectToActiveSelectionColour(ref selectBrushCol); } else { SetColourRectToInactiveSelectionColour(ref selectBrushCol); } selectBrushCol.ModulateAlpha(alpha); var lines = w.GetFormattedLines(); var numLines = lines.Count; // calculate the range of visible lines var sidx = (int)(vertScrollPos / fnt.GetLineSpacing()); var eidx = 1 + sidx + (int)(destArea.Height / fnt.GetLineSpacing()); eidx = Math.Min(eidx, numLines); drawArea.d_min.Y += fnt.GetLineSpacing() * sidx; // for each formatted line. for (var i = sidx; i < eidx; ++i) { var lineRect = drawArea; var currLine = lines[i]; var lineText = w.GetTextVisual().CEGuiSubstring(currLine.d_startIdx, currLine.d_length); // offset the font little down so that it's centered within its own spacing var oldTop = lineRect.Top; lineRect.d_min.Y += (fnt.GetLineSpacing() - fnt.GetFontHeight()) * 0.5f; // if it is a simple 'no selection area' case ColourRect colours; if ((currLine.d_startIdx >= w.GetSelectionEndIndex()) || ((currLine.d_startIdx + currLine.d_length) <= w.GetSelectionStartIndex()) || (w.GetSelectionBrushImage() == null)) { colours = normalTextCol; // Create Geometry buffers for the text and add to the Window var nextGlyphPos = 0.0f; var textGeomBuffers = fnt.CreateRenderGeometryForText(lineText, out nextGlyphPos, lineRect.Position, destArea, true, colours); w.AppendGeometryBuffers(textGeomBuffers); } else // we have at least some selection highlighting to do { // Start of actual rendering section. String sect; int sectIdx = 0, sectLen; float selStartOffset = 0.0f; // Create the render geometry for any text prior to selected region of line. if (currLine.d_startIdx < w.GetSelectionStartIndex()) { // calculate length of text section sectLen = w.GetSelectionStartIndex() - currLine.d_startIdx; // get text for this section sect = lineText.CEGuiSubstring(sectIdx, sectLen); sectIdx += sectLen; // get the pixel offset to the beginning of the selection area highlight. selStartOffset = fnt.GetTextAdvance(sect); // Create the render geometry for this portion of the text colours = normalTextCol; var geomBuffers = fnt.CreateRenderGeometryForText(sect, lineRect.Position, destArea, true, colours); // set position ready for next portion of text lineRect.d_min.X += selStartOffset; } // calculate the length of the selected section sectLen = Math.Min(w.GetSelectionEndIndex() - currLine.d_startIdx, currLine.d_length) - sectIdx; // get the text for this section sect = lineText.CEGuiSubstring(sectIdx, sectLen); sectIdx += sectLen; // get the extent to use as the width of the selection area highlight var selAreaWidth = fnt.GetTextAdvance(sect); var textTop = lineRect.Top; lineRect.Top = oldTop; // calculate area for the selection brush on this line lineRect.Left = drawArea.Left + selStartOffset; lineRect.Right = lineRect.Left + selAreaWidth; lineRect.Bottom = lineRect.Top + fnt.GetLineSpacing(); // Create the render geometry for the selection area brush for this line colours = selectBrushCol; var renderSettings = new ImageRenderSettings(lineRect, destArea, true, colours); var selectionGeomBuffers = w.GetSelectionBrushImage().CreateRenderGeometry(renderSettings); w.AppendGeometryBuffers(selectionGeomBuffers); // Create the render geometry for the text for this section colours = selectTextCol; var textGeomBuffers = fnt.CreateRenderGeometryForText(sect, lineRect.Position, destArea, true, colours); w.AppendGeometryBuffers(textGeomBuffers); lineRect.Top = textTop; // Create the render geometry for any text beyond selected region of line if (sectIdx < currLine.d_length) { // update render position to the end of the selected area. lineRect.d_min.X += selAreaWidth; // calculate length of this section sectLen = currLine.d_length - sectIdx; // get the text for this section sect = lineText.CEGuiSubstring(sectIdx, sectLen); // render the text for this section. colours = normalTextCol; var textAfterSelectionGeomBuffers = fnt.CreateRenderGeometryForText(sect, lineRect.Position, destArea, true, colours); w.AppendGeometryBuffers(textAfterSelectionGeomBuffers); } } // update master position for next line in paragraph. drawArea.d_min.Y += fnt.GetLineSpacing(); } } }
/// <summary> /// Set the given ColourRect to the colour to be used for rendering Editbox /// text falling within the selected region. /// </summary> /// <param name="colourRect"></param> protected void SetColourRectToSelectedTextColour(ref ColourRect colourRect) { SetColourRectToOptionalPropertyColour(SelectedTextColourPropertyName, ref colourRect); }
public void SetSelectionTextColourRect(ColourRect colourRect) { _selectionTextColourRect = colourRect; }
/// <summary> /// Sets the colour used for highlighting the selection. /// </summary> /// <param name="colourRect"></param> public void SetSelectionColourRect(ColourRect colourRect) { d_selectionColourRect = colourRect; }
/// <summary> /// Set the colours used for text rendering. /// </summary> /// <param name="cols"> /// ColourRect object describing the colours to be used. /// </param> public void SetTextColours(ColourRect cols) { _textCols = cols; }
/// <summary> /// Sets the colour used for rendering the text. /// </summary> /// <param name="colourRect"></param> public void SetTextColourRect(ColourRect colourRect) { d_textColourRect = colourRect; }
protected void CreateRenderGeometryForTextWithoutBidi(WidgetLookFeel wlf, string text, Rectf textArea, float textOffset) { var font = Window.GetFont(); // setup initial rect for text formatting var textPartRect = textArea; // allow for scroll position textPartRect.d_min.X += textOffset; // centre text vertically within the defined text area textPartRect.d_min.Y += (textArea.Height - font.GetFontHeight()) * 0.5f; var alphaComp = Window.GetEffectiveAlpha(); // get unhighlighted text colour (saves accessing property twice) var unselectedColours = new ColourRect(); SetColourRectToUnselectedTextColour(ref unselectedColours); // see if the editbox is active or inactive. var w = (Editbox)Window; var active = EditboxIsFocussed(); if (w.GetSelectionLength() != 0) { // calculate required start and end offsets of selection imagery. var selStartOffset = font.GetTextAdvance(text.CEGuiSubstring(0, w.GetSelectionStart())); var selEndOffset = font.GetTextAdvance(text.CEGuiSubstring(0, w.GetSelectionEnd())); // calculate area for selection imagery. Rectf hlarea = textArea; hlarea.d_min.X += textOffset + selStartOffset; hlarea.d_max.X = hlarea.d_min.X + (selEndOffset - selStartOffset); // create render geometry for the selection imagery. wlf.GetStateImagery(active ? "ActiveSelection" : "InactiveSelection").Render(w, hlarea, null, textArea); } // create render geometry for pre-highlight text var sect = text.CEGuiSubstring(0, w.GetSelectionStart()); var colours = unselectedColours; colours.ModulateAlpha(alphaComp); var preHighlightTextGeomBuffers = font.CreateRenderGeometryForText(sect, out textPartRect.d_min.X, textPartRect.Position, textArea, true, colours); w.AppendGeometryBuffers(preHighlightTextGeomBuffers); // create render geometry for highlight text sect = text.CEGuiSubstring(w.GetSelectionStart(), w.GetSelectionLength()); SetColourRectToSelectedTextColour(ref colours); colours.ModulateAlpha(alphaComp); var highlitTextGeomBuffers = font.CreateRenderGeometryForText(sect, out textPartRect.d_min.X, textPartRect.Position, textArea, true, colours); w.AppendGeometryBuffers(highlitTextGeomBuffers); // create render geometry for post-highlight text sect = text.Substring(w.GetSelectionEnd()); colours = unselectedColours; colours.ModulateAlpha(alphaComp); var postHighlitTextGeomBuffers = font.CreateRenderGeometryForText(sect, out textPartRect.d_min.X, textPartRect.Position, textArea, true, colours); w.AppendGeometryBuffers(postHighlitTextGeomBuffers); }
protected void CreateRenderGeometryForTextWithBidi(WidgetLookFeel wlf, string text, Rectf textArea, float textOffset) { var font = Window.GetFont(); // setup initial rect for text formatting var textPartRect = textArea; // allow for scroll position textPartRect.d_min.X += textOffset; // centre text vertically within the defined text area textPartRect.d_min.Y += (textArea.Height - font.GetFontHeight()) * 0.5f; var colours = new ColourRect(); var alphaComp = Window.GetEffectiveAlpha(); // get unhighlighted text colour (saves accessing property twice) var unselectedColour = new ColourRect(); SetColourRectToUnselectedTextColour(ref unselectedColour); // see if the editbox is active or inactive. var w = (Editbox)Window; var active = EditboxIsFocussed(); if (w.GetSelectionLength() == 0) { // no highlighted text - we can draw the whole thing colours = unselectedColour; w.AppendGeometryBuffers(font.CreateRenderGeometryForText(text, out textPartRect.d_min.X, textPartRect.Position, textArea, true, colours)); } else { // there is highlighted text - because of the Bidi support - the // highlighted area can be in some cases nonconsecutive. // So - we need to draw it char by char (I guess we can optimize it more // but this is not that big performance hit because it only happens if // we have highlighted text - not that common...) for (var i = 0; i < text.Length; i++) { // get the char var currChar = text[i]; var realPos = 0; // get he visual pos of the char if (w.GetBidiVisualMapping().GetV2lMapping().Count > i) { realPos = w.GetBidiVisualMapping().GetV2lMapping()[i]; } // check if it is in the highlighted region var highlighted = realPos >= w.GetSelectionStart() && realPos < w.GetSelectionStart() + w.GetSelectionLength(); var charAdvance = font.GetGlyphData(currChar).GetAdvance(); if (highlighted) { SetColourRectToSelectedTextColour(ref colours); colours.ModulateAlpha(alphaComp); { // calculate area for selection imagery. var hlarea = textArea; hlarea.d_min.X = textPartRect.d_min.X; hlarea.d_max.X = textPartRect.d_min.X + charAdvance; // render the selection imagery. wlf.GetStateImagery(active ? "ActiveSelection" :"InactiveSelection").Render(w, hlarea, null, textArea); } } else { colours = unselectedColour; colours.ModulateAlpha(alphaComp); } w.AppendGeometryBuffers(font.CreateRenderGeometryForText(currChar.ToString(CultureInfo.InvariantCulture), textPartRect.Position, textArea, true, colours)); // adjust rect for next section textPartRect.d_min.X += charAdvance; } } }
public override void AddToRenderGeometry(GeometryBuffer geomBuffer, ref Rectf renderArea, ref Rectf?clipArea, ColourRect colours) { throw new NotImplementedException(); }
/// <summary> /// Set the given ColourRect to the colour to be used for rendering Editbox /// text oustside of the selected region. /// </summary> /// <param name="colourRect"></param> public void SetColourRectToUnselectedTextColour(ref ColourRect colourRect) { SetColourRectToOptionalPropertyColour(UnselectedTextColourPropertyName, ref colourRect); }
/*! * \brief * Set the colours used for text rendering. * * \param cols * ColourRect object describing the colours to be used. * * \return * Nothing. */ void setTextColours(ColourRect cols) { d_textCols = cols; d_renderedStringValid = false; }
/// <summary> /// Sets the colours to be applied when rendering the text. /// </summary> /// <param name="colours"></param> public void SetTextColours(ColourRect colours) { _textCols = colours; Window.Invalidate(false); }
/// <summary> /// Set the colours used for selection highlighting. /// </summary> /// <param name="cols"> /// ColourRect object describing the colours to be used. /// </param> public void SetSelectionColours(ColourRect cols) { SelectCols = cols; }