protected override void DrawStyle(Style style, float opacity) { base.DrawStyle(style, opacity); var texture = Gui.Renderer.GetTexture(Texture); if (texture < 0) { return; } if (ColorByTint) { Color = style.Tint; } var color = Color; if (Tint != -1) { color = ColorInt.Blend(Tint, color); } color = ColorInt.FromArgb(opacity, color); if (TextureRect.IsEmpty()) { var texsize = Gui.Renderer.GetTextureSize(texture); TextureRect = new Rectangle(Point.Zero, texsize); } //bool atlas = SpriteBatch.AutoAtlas; //if (ExcludeFromAtlas) // SpriteBatch.AutoAtlas = false; if (Tiling == TextureMode.Grid || Tiling == TextureMode.GridRepeat) { SliceTexture(texture, Tiling, TextureRect, Grid, opacity, color); } else if (Tiling == TextureMode.Stretch) { Gui.Renderer.DrawTexture(texture, Location.X + Inset.Left, Location.Y + Inset.Top, Size.X - (Inset.Left + Inset.Right), Size.Y - (Inset.Top + Inset.Bottom), TextureRect, color); } else if (Tiling == TextureMode.Center) { var center = Location + Size / 2; var rectsize = new Point(TextureRect.Width, TextureRect.Height); var pos = center - rectsize / 2; Gui.Renderer.DrawTexture(texture, pos.X, pos.Y, rectsize.X, rectsize.Y, TextureRect, color); } else { RepeatTexture(texture, Location, TextureRect, Tiling, opacity, color); } //if (ExcludeFromAtlas) // SpriteBatch.AutoAtlas = atlas; }
protected override void DrawText(Style style, float opacity) { if (_isDirty) { UpdateText(style); } if (_lines.Count == 0) { return; } int font; Point p1, p2, size; foreach (var line in _lines) { foreach (var element in line.Elements) { if (element.Linebreak) { continue; } font = Gui.Renderer.GetFont(element.Font); size = element.Size; p2 = element.Position + Location; element.Rectangle = new Rectangle(p2, size); if (!element.Rectangle.Intersects(ClipRect)) { continue; } if (element.IsControl) { continue; } if (element.IsLink) { Gui.Renderer.DrawBox(p2.X, p2.Y + size.Y, size.X - 1, 1, ColorInt.FromArgb(opacity, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor))); } //if (element.IsLink && element.Href == ActiveHref) // Gui.Renderer.DrawBox(p2.x, p2.y, size.x - 1, size.y, ColorInt.FromArgb(opacity, LinkColor)); if (UseTextColor) { Gui.Renderer.DrawText(element.Text, p2.X, p2.Y, font, ColorInt.FromArgb(opacity, TextColor)); } else { Gui.Renderer.DrawText(element.Text, p2.X, p2.Y, font, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor)); } } } }
public override void DrawRect(double left, double top, double width, double height) { //BitmapExt if (this.RenderQuality == RenderQualtity.Fast) { if (this._orientation == DrawBoardOrientation.LeftBottom) { this._bxt.DrawRectangle( (int)Math.Round(left), (int)Math.Round(top), (int)Math.Round(left + width), (int)Math.Round(top + height), ColorInt.FromArgb(this.strokeColor.ToARGB())); } else { //TODO: review here throw new NotSupportedException(); //int canvasH = this.Height; ////_simpleRectVxsGen.SetRect(left + 0.5, canvasH - (bottom + 0.5 + height), right - 0.5, canvasH - (top - 0.5 + height)); //this._bmpBuffer.DrawRectangle( //(int)Math.Round(left), //(int)Math.Round(top), //(int)Math.Round(left + width), //(int)Math.Round(top + height), //ColorInt.FromArgb(this.strokeColor.ToARGB())); } return; //exit } //---------------------------------------------------------- //Agg if (this._orientation == DrawBoardOrientation.LeftBottom) { double right = left + width; double bottom = top + height; _simpleRectVxsGen.SetRect(left + 0.5, bottom + 0.5, right - 0.5, top - 0.5); } else { double right = left + width; double bottom = top - height; int canvasH = this.Height; //_simpleRectVxsGen.SetRect(left + 0.5, canvasH - (bottom + 0.5), right - 0.5, canvasH - (top - 0.5)); _simpleRectVxsGen.SetRect(left + 0.5, canvasH - (bottom + 0.5 + height), right - 0.5, canvasH - (top - 0.5 + height)); } var v1 = GetFreeVxs(); var v2 = GetFreeVxs(); // _aggsx.Render(stroke.MakeVxs(_simpleRectVxsGen.MakeVxs(v1), v2), this.strokeColor); // ReleaseVxs(ref v1); ReleaseVxs(ref v2); }
public override void FillRect(double left, double top, double width, double height) { //---------------------------------------------------------- //BitmapExt if (this._renderQuality == RenderQualtity.Fast) { this._bxt.FillRectangle( (int)Math.Round(left), (int)Math.Round(top), (int)Math.Round(left + width), (int)Math.Round(top + height), ColorInt.FromArgb(this.fillColor.ToARGB())); return; } //Agg //---------------------------------------------------------- if (this._orientation == DrawBoardOrientation.LeftBottom) { double right = left + width; double bottom = top - height; if (right < left || top < bottom) { #if DEBUG throw new ArgumentException(); #else return; #endif } _simpleRectVxsGen.SetRect(left + 0.5, (bottom + 0.5) + height, right - 0.5, (top - 0.5) + height); } else { double right = left + width; double bottom = top - height; if (right < left || top < bottom) { #if DEBUG throw new ArgumentException(); #else return; #endif } int canvasH = this.Height; _simpleRectVxsGen.SetRect(left + 0.5, canvasH - (bottom + 0.5 + height), right - 0.5, canvasH - (top - 0.5 + height)); } var v1 = GetFreeVxs(); _aggsx.Render(_simpleRectVxsGen.MakeVertexSnap(v1), this.fillColor); ReleaseVxs(ref v1); }
protected override void DrawBefore() { if (Modal) { SetScissor(0, 0, Desktop.Size.X, Desktop.Size.Y); Gui.Renderer.DrawBox(0, 0, Desktop.Size.X, Desktop.Size.Y, ColorInt.FromArgb(GetOpacity(1), Desktop.ModalColor)); ResetScissor(); } base.DrawBefore(); }
public Plant() { this.Tension = 1f; this.rand = new Random(); this.BranchLenMin = 150; this.BranchLenMax = 200; this.GrowthRate = 0.007f; this.BranchPoints = new List <BranchPoint>(); this.BranchAngleVariance = 10; this.MaxGenerations = int.MaxValue; //this.BranchDegression = 0; this.Color = ColorInt.FromArgb(255, 100, 150, 0); this.Start = Vector.Zero; this.Scale = Vector.One; this.BendingFactor = 0.4f; this.MaxBranchesPerGeneration = int.MaxValue; this.branchesPerGen = new Dictionary <int, int>(); }
public ColorInt ToColor() { double q = 0; if (L < .5) { q = L * (1 + S); } else { q = L + S - (L * S); } double p = (2 * L) - q; double hk = H / 360; double r = getComponent(norm(hk + (1.0 / 3.0)), p, q); double g = getComponent(norm(hk), p, q); double b = getComponent(norm(hk - (1.0 / 3.0)), p, q); return(ColorInt.FromArgb(PctToByte(A), PctToByte(r), PctToByte(g), PctToByte(b))); }
public override void DrawImage(Image img, params AffinePlan[] affinePlans) { MemBitmap memBmp = img as MemBitmap; if (memBmp == null) { //? TODO return; } if (_renderQuality == RenderQuality.Fast) { //todo, review here again TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp); BitmapBuffer srcBmp = new BitmapBuffer(img.Width, img.Height, tmp.Ptr, tmp.LengthInBytes); if (affinePlans != null && affinePlans.Length > 0) { _bxt.BlitRender(srcBmp, false, 1, new BitmapBufferEx.MatrixTransform(affinePlans)); } else { //_bxt.BlitRender(srcBmp, false, 1, null); _bxt.Blit(0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, srcBmp, 0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, ColorInt.FromArgb(255, 255, 255, 255), BitmapBufferExtensions.BlendMode.Alpha); } return; } bool useSubPix = UseSubPixelLcdEffect; //save, restore later... //before render an image we turn off vxs subpixel rendering this.UseSubPixelLcdEffect = false; _aggsx.Render(memBmp, affinePlans); //restore... this.UseSubPixelLcdEffect = useSubPix; }
protected override void DrawText(Style style, float opacity) { if (_isDirty) { UpdateText(style); } int font; var total = 0; var numLine = 0; Point p1, p2, size; var align = TextAlign != Alignment.Inherit ? TextAlign : style.TextAlign; var drawCaret = _hasFocus && _doBlink > 0; if (_lines.Count == 0) { if (drawCaret) { p1 = Location; font = Gui.Renderer.GetFont(style.Font); if (align == Alignment.TopLeft || align == Alignment.TopCenter || align == Alignment.TopRight) { p1.Y += style.TextPadding.Top; } if (align == Alignment.BottomLeft || align == Alignment.BottomCenter || align == Alignment.BottomRight) { p1.Y += Size.Y - _textSize.Y; } if (align == Alignment.MiddleLeft || align == Alignment.MiddleCenter || align == Alignment.MiddleRight) { p1.Y += (Size.Y - (_textSize.Y - (style.TextPadding.Top + style.TextPadding.Bottom))) / 2; } if (align == Alignment.TopLeft || align == Alignment.MiddleLeft || align == Alignment.BottomLeft) { p1.X += style.TextPadding.Left; } if (align == Alignment.TopRight || align == Alignment.MiddleRight || align == Alignment.BottomRight) { p1.X += Size.X - style.TextPadding.Right; } if (align == Alignment.TopCenter || align == Alignment.MiddleCenter || align == Alignment.BottomCenter) { p1.X += Size.X / 2; } var subsize = Gui.Renderer.GetTextSize(" ", font); Gui.Renderer.DrawBox(p1.X, p1.Y, 2, subsize.Y, ColorInt.FromArgb(opacity, BlinkColor)); } return; } foreach (var line in _lines) { var perline = 0; foreach (var element in line.Elements) { //if (element.Linebreak) // continue; font = Gui.Renderer.GetFont(element.Font); if (element.Linebreak) { total++; } else { total += element.Text.Length; } size = element.Size; p1 = Location; if (align == Alignment.TopLeft || align == Alignment.TopCenter || align == Alignment.TopRight) { p1.Y += style.TextPadding.Top; } if (align == Alignment.BottomLeft || align == Alignment.BottomCenter || align == Alignment.BottomRight) { p1.Y += Size.Y - _textSize.Y; } if (align == Alignment.MiddleLeft || align == Alignment.MiddleCenter || align == Alignment.MiddleRight) { p1.Y += (Size.Y - (_textSize.Y - (style.TextPadding.Top + style.TextPadding.Bottom))) / 2; } if (align == Alignment.TopLeft || align == Alignment.MiddleLeft || align == Alignment.BottomLeft) { p1.X += style.TextPadding.Left; } if (align == Alignment.TopRight || align == Alignment.MiddleRight || align == Alignment.BottomRight) { p1.X += Size.X - line.Width - style.TextPadding.Right; } if (align == Alignment.TopCenter || align == Alignment.MiddleCenter || align == Alignment.BottomCenter) { p1.X += (Size.X - line.Width) / 2; } p2 = element.Position + p1; element.Rectangle = new Rectangle(p2, size); if (element.IsLink && element.Href == _activeHref) { Gui.Renderer.DrawBox(p2.X, p2.Y, size.X - 1, size.Y, ColorInt.FromArgb(opacity, LinkColor)); } if (drawCaret && total >= _caret) { drawCaret = false; if (string.IsNullOrEmpty(element.Text)) { var subsize = Gui.Renderer.GetTextSize(" ", font); Gui.Renderer.DrawBox(p2.X, p2.Y, 2, subsize.Y, ColorInt.FromArgb(opacity, BlinkColor)); } else { var substr = element.Text.Substring(0, element.Text.Length - (total - _caret)); if (string.IsNullOrEmpty(substr)) { var subsize = Gui.Renderer.GetTextSize(" ", font); Gui.Renderer.DrawBox(p2.X, p2.Y, 2, subsize.Y, ColorInt.FromArgb(opacity, BlinkColor)); } else { var subsize = Gui.Renderer.GetTextSize(substr, font); Gui.Renderer.DrawBox(p2.X + subsize.X, p2.Y, 2, subsize.Y, ColorInt.FromArgb(opacity, BlinkColor)); } } } if (UseTextColor) { Gui.Renderer.DrawText(element.Text, p2.X, p2.Y, font, ColorInt.FromArgb(opacity, TextColor)); } else { Gui.Renderer.DrawText(element.Text, p2.X, p2.Y, font, ColorInt.FromArgb(opacity, element.Color.HasValue ? (int)element.Color : style.TextColor)); } // Gui.Renderer.DrawBox(element.Rectangle.Left, element.Rectangle.Top, element.Rectangle.Width, element.Rectangle.Height, -1); if (IsSelection && total >= SelectionStart && perline < SelectionEnd && !element.Linebreak) { var start = SelectionStart; var end = SelectionEnd; var color = ColorInt.FromArgb(0.5f, -1); //int origin = perline - element.Text.Length; //start = Math.Max(0, origin - start); //if (string.IsNullOrEmpty(element.Text)) //{ // Point subsize = Gui.Renderer.GetTextSize(" ", font); // Gui.Renderer.DrawBox(p2.x, p2.y, subsize.x, subsize.y, ColorInt.FromArgb(opacity, BlinkColor)); //} //else //{ var begin = element.Text.Length - (total - start); if (begin < 0) { begin = 0; } var len = element.Text.Length - begin - (total - end); if (len < 0) { len = 0; } if (len > element.Text.Length) { len = element.Text.Length; } if (begin + len > element.Text.Length) { len = element.Text.Length - begin; } var strOffset = element.Text.Substring(0, begin); var strSelected = element.Text.Substring(begin, len); var offset = Gui.Renderer.GetTextSize(strOffset, font); var selection = Gui.Renderer.GetTextSize(strSelected, font); Gui.Renderer.DrawBox(p2.X + offset.X, p2.Y, selection.X, selection.Y, ColorInt.FromArgb(opacity, SelectionColor)); //} } if (!string.IsNullOrEmpty(element.Text)) { perline += element.Text.Length; } else { perline++; } } numLine++; } }
public override void FillRect(double left, double top, double width, double height) { //---------------------------------------------------------- //BitmapExt if (_useDefaultBrush && this._renderQuality == RenderQualtity.Fast) { this._bxt.FillRectangle( (int)Math.Round(left), (int)Math.Round(top), (int)Math.Round(left + width), (int)Math.Round(top + height), ColorInt.FromArgb(this.fillColor.ToARGB())); return; } //Agg //---------------------------------------------------------- if (this._orientation == DrawBoardOrientation.LeftBottom) { double right = left + width; double bottom = top - height; if (right < left || top < bottom) { #if DEBUG throw new ArgumentException(); #else return; #endif } _simpleRectVxsGen.SetRect(left + 0.5, (bottom + 0.5) + height, right - 0.5, (top - 0.5) + height); } else { double right = left + width; double bottom = top - height; if (right < left || top < bottom) { #if DEBUG throw new ArgumentException(); #else return; #endif } int canvasH = this.Height; _simpleRectVxsGen.SetRect(left + 0.5, canvasH - (bottom + 0.5 + height), right - 0.5, canvasH - (top - 0.5 + height)); } var v1 = GetFreeVxs(); //---------------------------------------------------------- if (!_useDefaultBrush) { Brush br = _curBrush; switch (br.BrushKind) { case BrushKind.LinearGradient: { //fill linear gradient brush //.... //check resolved object for br //if not then create a new one //------------------------------------------- //original agg's gradient fill _aggGradientBrush.ResolveBrush((LinearGradientBrush)br); _aggGradientBrush.SetOffset((float)-left, (float)-top); Fill(_simpleRectVxsGen.MakeVxs(v1), _aggGradientBrush); } break; case BrushKind.CircularGraident: { _circularGradBrush.ResolveBrush((CircularGradientBrush)br); _circularGradBrush.SetOffset((float)-left, (float)-top); Fill(_simpleRectVxsGen.MakeVxs(v1), _circularGradBrush); } break; default: { _aggsx.Render(_simpleRectVxsGen.MakeVertexSnap(v1), this.fillColor); } break; } } else { _aggsx.Render(_simpleRectVxsGen.MakeVertexSnap(v1), this.fillColor); } ReleaseVxs(ref v1); }
protected override void DrawText(Style style, float opacity) { if (_text == null) { _text = string.Empty; } var masked = _text; if (IsPassword) { masked = new string(PasswordChar, masked.Length); } var font = Gui.Renderer.GetFont(style.Font); if (font < 0) { return; } var p = AlignText(masked, Alignment.MiddleLeft, style.TextPadding, font); var clip = new Rectangle(Location, Size); clip.Left += style.TextPadding.Left; clip.Right -= style.TextPadding.Right - 1; clip = Clip(clip); if (clip.Width < 1 || clip.Height < 1) { return; } SetScissor(clip.Left, clip.Top, clip.Width, clip.Height); if (_caret > masked.Length) { _caret = masked.Length; } if (Desktop.FocusedControl == this) { var rect = new Rectangle(Location, Size); var s1 = Gui.Renderer.GetTextSize(masked, font); var s2 = Gui.Renderer.GetTextSize(masked.Substring(0, _caret), font); if (string.IsNullOrEmpty(masked)) { s2.Y = Gui.Renderer.GetTextSize(" ", font).Y; p = AlignText(" ", Alignment.MiddleLeft, style.TextPadding, font); } else if (s2.Y == 0) { s2.Y = Gui.Renderer.GetTextSize(" ", font).Y; } var carex = p.X + _offset + s2.X; var lim1 = rect.Left + style.TextPadding.Left; var lim2 = rect.Right - style.TextPadding.Right; if (carex < lim1) { _offset += lim1 - carex; } if (carex > lim2) { _offset += lim2 - carex; } if (_offset < 0) { if (p.X + _offset + s1.X < lim2) { _offset += lim2 - (p.X + _offset + s1.X); } } p.X += _offset; Gui.Renderer.DrawText(masked, p.X, p.Y, font, ColorInt.FromArgb(opacity, UseTextColor ? TextColor : style.TextColor)); if (!ReadOnly && _doBlink > 0) { Gui.Renderer.DrawBox(p.X + s2.X, p.Y, 1, s2.Y, ColorInt.FromArgb(opacity, BlinkColor)); } if (IsSelection) { var start = Math.Min(_selectStart, _selectEnd); var end = Math.Max(_selectStart, _selectEnd); var color = ColorInt.FromArgb(0.5f, SelectionColor); var text = masked.Substring(0, start); var text2 = masked.Substring(start, end - start); var size1 = Gui.Renderer.GetTextSize(text, font); var size2 = Gui.Renderer.GetTextSize(text2, font); Gui.Renderer.DrawBox(p.X + size1.X, p.Y, size2.X, size2.Y, ColorInt.FromArgb(opacity, color)); } } else { _hasFocus = false; _offset = 0; Gui.Renderer.DrawText(masked, p.X, p.Y, font, ColorInt.FromArgb(opacity, style.TextColor)); } ResetScissor(); }