void drawTechBorder1 (Cairo.Context gr){ Rectangle r = ClientRectangle; double l1 = Math.Round(0.2 * Math.Min (r.Width, r.Height)) + 0.5; Foreground.SetAsSource (gr); gr.LineWidth = 6.0; gr.MoveTo (r.Left + 1.5, r.Top + l1); gr.LineTo (r.Left + 1.5, r.Top + 1.5); gr.LineTo (r.Left + l1, r.Top + 1.5); gr.MoveTo (r.Left + r.Width * 0.65, r.Bottom - 1.5); gr.LineTo (r.Left + r.Width * 0.85, r.Bottom - 1.5); gr.Stroke (); gr.MoveTo (r.Left + 2.5, r.Top + 2.5); gr.LineTo (r.Left + 2.5, r.Bottom - l1); gr.LineTo (r.Left + l1, r.Bottom - 2.5); gr.LineTo (r.Right - 2.5, r.Bottom - 2.5); gr.LineTo (r.Right - 2.5, r.Top + l1); gr.LineTo (r.Right - l1, r.Top + 2.5); gr.ClosePath (); if (ClipToClientRect) //clip to client zone gr.ClipPreserve (); Background.SetAsSource (gr); gr.FillPreserve (); gr.LineWidth = 1.0; Foreground.SetAsSource (gr); gr.Stroke (); }
protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd) { Rectangle r = ClientRectangle; Foreground.SetAsSource(gr); gr.LineWidth = 2; gr.MoveTo(pStart); gr.LineTo(pEnd); gr.Stroke(); gr.LineWidth = 1; double sst = unity * SmallIncrement; double bst = unity * LargeIncrement; PointD vBar = new PointD(0, sst); for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement) { double lineLength = r.Height / 3; if (x % LargeIncrement != 0) { lineLength /= 3; } PointD p = new PointD(pStart.X + x * unity, pStart.Y); gr.MoveTo(p); gr.LineTo(new PointD(p.X, p.Y + lineLength)); } gr.Stroke(); }
protected override void onDraw(Context gr) { base.onDraw(gr); Rectangle r = ClientRectangle; Foreground.SetAsSource(gr, r); gr.Rectangle(r, 0.1); gr.Stroke(); r.Width = _pic.Dimensions.Width * zoom / 100; r.Height = _pic.Dimensions.Height * zoom / 100; gr.Save(); editorMutex.EnterReadLock(); gr.Translate(-ScrollX, -ScrollY); if (_pic != null) { _pic.Paint(gr, r); } editorMutex.ExitReadLock(); gr.Restore(); }
protected override void onDraw(Cairo.Context gr) { gr.Save(); int spacing = (Parent as TabView).Spacing; gr.MoveTo(0.5, TabTitle.Slot.Bottom - 0.5); gr.LineTo(TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom - 0.5); gr.CurveTo( TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom - 0.5, TabTitle.Slot.Left - spacing / 2, 0.5, TabTitle.Slot.Left, 0.5); gr.LineTo(TabTitle.Slot.Right, 0.5); gr.CurveTo( TabTitle.Slot.Right + spacing / 2, 0.5, TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom - 0.5, TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, TabTitle.Slot.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, Slot.Height - 0.5); gr.LineTo(0.5, Slot.Height - 0.5); gr.ClosePath(); gr.LineWidth = 2; Foreground.SetAsSource(gr); gr.StrokePreserve(); gr.Clip(); base.onDraw(gr); gr.Restore(); }
protected override void onDraw(Cairo.Context gr) { Rectangle rBack = new Rectangle(Slot.Size); //rBack.Inflate (-Margin); // if (BorderWidth > 0) // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill(); if (BorderWidth > 0) { Foreground.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); } gr.Save(); if (ClipToClientRect) { //clip to client zone CairoHelpers.CairoRectangle(gr, ClientRectangle, Math.Max(0.0, CornerRadius - Margin)); gr.Clip(); } if (child != null) { child.Paint(ref gr); } gr.Restore(); }
protected override void onDraw(Context gr) { gr.Save(); TabView tv = Parent as TabView; Rectangle r = TabTitle.Slot; r.Width = TabWidth; gr.MoveTo(0.5, r.Bottom - 0.5); gr.LineTo(r.Left - tv.LeftSlope, r.Bottom - 0.5); gr.CurveTo( r.Left - tv.LeftSlope / 2, r.Bottom - 0.5, r.Left - tv.LeftSlope / 2, 0.5, r.Left, 0.5); gr.LineTo(r.Right, 0.5); gr.CurveTo( r.Right + tv.RightSlope / 2, 0.5, r.Right + tv.RightSlope / 2, r.Bottom - 0.5, r.Right + tv.RightSlope, r.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, r.Bottom - 0.5); gr.LineTo(Slot.Width - 0.5, Slot.Height - 0.5); gr.LineTo(0.5, Slot.Height - 0.5); gr.ClosePath(); gr.LineWidth = 1; Foreground.SetAsSource(gr); gr.StrokePreserve(); gr.Clip(); base.onDraw(gr); gr.Restore(); }
protected override void onDraw(Context gr) { base.onDraw(gr); Rectangle r = ClientRectangle; if (Foreground != null) //TODO:test if null should be removed { Foreground.SetAsSource(gr, r); CairoHelpers.CairoRectangle(gr, r, CornerRadius); gr.Fill(); } Crow.Gradient grad = new Gradient(Gradient.Type.Horizontal); grad.Stops.Add(new Gradient.ColorStop(0, new Color(1, 1, 1, 1))); grad.Stops.Add(new Gradient.ColorStop(1, new Color(1, 1, 1, 0))); grad.SetAsSource(gr, r); CairoHelpers.CairoRectangle(gr, r, CornerRadius); gr.Fill(); grad = new Gradient(Gradient.Type.Vertical); grad.Stops.Add(new Gradient.ColorStop(0, new Color(0, 0, 0, 0))); grad.Stops.Add(new Gradient.ColorStop(1, new Color(0, 0, 0, 1))); grad.SetAsSource(gr, r); CairoHelpers.CairoRectangle(gr, r, CornerRadius); gr.Fill(); }
protected virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd) { Foreground.SetAsSource(gr); gr.LineWidth = 1; gr.MoveTo(pStart); gr.LineTo(pEnd); gr.Stroke(); }
protected override void onDraw(Context gr) { base.onDraw(gr); Rectangle rBack = ClientRectangle; rBack.Width = (int)((double)rBack.Width / Maximum * Value); Foreground.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill(); }
protected override void onDraw(Context gr) { base.onDraw(gr); Rectangle r = ClientRectangle; int height = r.Height / 100 * level; r.Y += r.Height - height; r.Height = height; Foreground.SetAsSource(gr); gr.Rectangle(r); gr.Fill(); }
void drawborder1(Context gr) { Rectangle rBack = new Rectangle(Slot.Size); //rBack.Inflate (-Margin); // if (BorderWidth > 0) // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill(); double bw = _borderWidth; double crad = CornerRadius; if (bw > 0) { if (BorderStyle == BorderStyle.Normal) { Foreground.SetAsSource(gr, rBack); } else { if (BorderStyle == BorderStyle.Sunken) { gr.SetSourceColor(raisedColor); } else { gr.SetSourceColor(sunkenColor); } CairoHelpers.CairoRectangle(gr, rBack, crad, bw); if (BorderStyle == BorderStyle.Sunken) { gr.SetSourceColor(sunkenColor); } else { gr.SetSourceColor(raisedColor); } bw /= 2.0; rBack.Width -= (int)Math.Round(bw); rBack.Height -= (int)Math.Round(bw); } CairoHelpers.CairoRectangle(gr, rBack, crad, bw); } }
protected override void onDraw(Context gr) { gr.Save(); if (ClipToClientRect) { //clip to client zone CairoHelpers.CairoRectangle(gr, ClientRectangle, CornerRadius); gr.Clip(); } Rectangle r = ClientRectangle; double radius = 0, cx = r.Width / 2.0 + r.X, cy = r.Height / 2.0 + r.Y; if (r.Width > r.Height) { radius = r.Height / 2.0; } else { radius = r.Width / 2.0; } double dx = Math.Sin(pi3) * radius; double dy = Math.Cos(pi3) * radius; gr.MoveTo(cx - radius, cy); gr.LineTo(cx - dy, cy - dx); gr.LineTo(cx + dy, cy - dx); gr.LineTo(cx + radius, cy); gr.LineTo(cx + dy, cy + dx); gr.LineTo(cx - dy, cy + dx); gr.ClosePath(); gr.LineWidth = 1; Background.SetAsSource(gr); gr.FillPreserve(); Foreground.SetAsSource(gr); gr.Stroke(); if (child != null) { if (child.Visible) { child.Paint(ref gr); } } gr.Restore(); }
protected override void onDraw(Context gr) { // if (!System.Threading.Monitor.TryEnter (buffer.EditMutex)) { // RegisterForGraphicUpdate (); // return; // } base.onDraw(gr); gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; Rectangle cb = ClientRectangle; Foreground.SetAsSource(gr); lock (buffer.EditMutex) { #region draw text cursor if (buffer.SelectionInProgress) { selStartCol = getTabulatedColumn(buffer.SelectionStart); selEndCol = getTabulatedColumn(buffer.SelectionEnd); } else if (HasFocus) { gr.LineWidth = 1.0; double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance + leftMargin; gr.MoveTo(0.5 + cursorX, cb.Y + (printedCurrentLine) * fe.Height); gr.LineTo(0.5 + cursorX, cb.Y + (printedCurrentLine + 1) * fe.Height); gr.Stroke(); } #endregion if (PrintedLines != null) { for (int i = 0; i < visibleLines; i++) { if (i + ScrollY >= buffer.UnfoldedLines) //TODO:need optimize { break; } drawLine(gr, cb, i); } } } //System.Threading.Monitor.Exit (buffer.EditMutex); }
protected override void onDraw (Cairo.Context gr) { base.onDraw (gr); if (lines == null) return; gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); Rectangle r = ClientRectangle; Foreground.SetAsSource (gr); double y = ClientRectangle.Y; double x = ClientRectangle.X; Fill errorFill = new SolidColor (Color.Carmine); for (int i = 0; i < visibleLines; i++) { if (i + Scroll >= Lines.Count) break; if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) { errorFill.SetAsSource (gr); gr.Rectangle (x, y, (double)r.Width, fe.Height); gr.Fill (); Foreground.SetAsSource (gr); } gr.MoveTo (x, y + fe.Ascent); gr.ShowText (lines[i+Scroll] as string); y += fe.Height; gr.Fill (); } if (Lines.Count <= visibleLines) return; Rectangle scrBar = ClientRectangle; scrBar.X += ClientRectangle.Width - scrBarWidth; scrBar.Width = scrBarWidth; new SolidColor (Color.LightGray.AdjustAlpha(0.5)).SetAsSource (gr); CairoHelpers.CairoRectangle(gr, scrBar, 2.0); gr.Fill (); new SolidColor (Color.BlueCrayola.AdjustAlpha(0.7)).SetAsSource (gr); scrBar.Y += (int)((double)scrBar.Height * (double)Scroll / (double)Lines.Count); scrBar.Height = (int)((double)scrBar.Height * (double)visibleLines / (double)Lines.Count); CairoHelpers.CairoRectangle(gr, scrBar, 2.0); gr.Fill (); }
protected override void onDraw(Context gr) { if (string.IsNullOrEmpty(path)) { return; } Rectangle r = ClientRectangle; executePath(gr); Background.SetAsSource(gr, r); gr.FillPreserve(); gr.LineWidth = strokeWidth; Foreground.SetAsSource(gr, r); gr.Stroke(); }
protected override void onDraw(Context gr) { base.onDraw(gr); if (values.Count == 0) { return; } Rectangle r = ClientRectangle; int i = values.Count - 1; double ptrX = (double)r.Right; double scaleY = (double)r.Height / (Maximum - Minimum); double stepX = (double)r.Width / (double)(nbValues - 1); gr.LineWidth = 1.0; gr.SetDash(new double[] { 1.0 }, 0.0); LowThresholdFill.SetAsSource(gr); gr.MoveTo(r.Left, r.Bottom - LowThreshold * scaleY); gr.LineTo(r.Right, r.Bottom - LowThreshold * scaleY); // gr.Rectangle (r.Left, r.Bottom - LowThreshold * scaleY, r.Width, LowThreshold * scaleY); gr.Stroke(); HighThresholdFill.SetAsSource(gr); gr.MoveTo(r.Left, (Maximum - HighThreshold) * scaleY); gr.LineTo(r.Right, (Maximum - HighThreshold) * scaleY); // gr.Rectangle (r.Left, r.Top, r.Width, (Maximum - HighThreshold) * scaleY); gr.Stroke(); gr.MoveTo(ptrX, values [i] * scaleY); Foreground.SetAsSource(gr); gr.SetDash(new double[] { }, 0.0); while (i >= 0) { gr.LineTo(ptrX, r.Bottom - values [i] * scaleY); ptrX -= stepX; i--; } gr.Stroke(); }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); Foreground.SetAsSource(gr); Rectangle r = ClientRectangle; double x = r.Center.X - 0.5; double y; gr.LineWidth = 1; gr.MoveTo(x, r.Y); gr.LineTo(x, r.Bottom - 8); for (y = 8.5 + r.Y; y < r.Bottom; y += 18) { gr.MoveTo(x, y); gr.LineTo(x * 2, y); } gr.Stroke(); }
protected override void onDraw(Context gr) { base.onDraw(gr); gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; Rectangle cb = ClientRectangle; Foreground.SetAsSource(gr); buffer.editMutex.EnterReadLock(); editorMutex.EnterReadLock(); #region draw text cursor if (buffer.SelectionInProgress) { selStartCol = getTabulatedColumn(buffer.SelectionStart); selEndCol = getTabulatedColumn(buffer.SelectionEnd); } else if (HasFocus && CurrentLine >= 0) { gr.LineWidth = 1.0; double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance; double cursorY = cb.Y + (buffer.CurrentLine - ScrollY) * (fe.Ascent + fe.Descent); gr.MoveTo(0.5 + cursorX, cursorY); gr.LineTo(0.5 + cursorX, cursorY + fe.Ascent + fe.Descent); gr.Stroke(); } #endregion drawLines(gr, cb); editorMutex.ExitReadLock(); buffer.editMutex.ExitReadLock(); }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); if (lines == null) { return; } gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); Rectangle r = ClientRectangle; Foreground.SetAsSource(gr); double y = ClientRectangle.Y; double x = ClientRectangle.X; for (int i = 0; i < visibleLines; i++) { if (i + ScrollY >= Lines.Count) { break; } //if ((lines [i + Scroll] as string).StartsWith ("error", StringComparison.OrdinalIgnoreCase)) { // errorFill.SetAsSource (gr); // gr.Rectangle (x, y, (double)r.Width, fe.Height); // gr.Fill (); // Foreground.SetAsSource (gr); //} gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lines[i + ScrollY] as string); y += fe.Height; gr.Fill(); } }
protected override void onDraw(Context gr) { base.onDraw(gr); Rectangle r = ClientRectangle; Point m = r.Center; gr.Save(); double aUnit = Math.PI * 2.0 / (Maximum - Minimum); gr.Translate(m.X, r.Height * 1.1); gr.Rotate(Value / 4.0 * aUnit - Math.PI / 4.0); gr.Translate(-m.X, -m.Y); gr.LineWidth = 2; Foreground.SetAsSource(gr); gr.MoveTo(m.X, 0.0); gr.LineTo(m.X, -m.Y * 0.5); gr.Stroke(); gr.Restore(); }
protected override void onDraw(Context gr) { base.onDraw(gr); /*gr.FontFace = Font.Name; * gr.FontSize = (uint)Font.Size;*/ FontExtents fe = gr.FontExtents; Rectangle r = ClientRectangle; r.Inflate(-(int)fe.Height); double gridSize; double gridX = r.X; double gridY = r.Y; if (r.Width > r.Height) { gridX += (r.Width - r.Height) / 2; gridSize = r.Height; } else { gridY += (r.Height - r.Width) / 2; gridSize = r.Width; } Fill white = new SolidColor(Colors.Ivory); white.SetAsSource(IFace, gr); gr.Rectangle(gridX, gridY, gridSize, gridSize); gr.Fill(); double cellSize = gridSize / 8; Fill black = new SolidColor(Colors.Grey); black.SetAsSource(IFace, gr); for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if ((x + y) % 2 != 0) { gr.Rectangle(gridX + x * cellSize, gridY + y * cellSize, cellSize, cellSize); } } } gr.Fill(); Foreground.SetAsSource(IFace, gr); for (int x = 0; x < 8; x++) { string L = new string(new char[] { (char)(x + 97) }); gr.MoveTo(gridX + x * cellSize - gr.TextExtents(L).XAdvance / 2 + cellSize / 2, gridY + gridSize + fe.Ascent + 1); gr.ShowText(L); } for (int y = 0; y < 8; y++) { string L = (y + 1).ToString(); gr.MoveTo(gridX - gr.TextExtents(L).XAdvance - 1, gridY + fe.Ascent + cellSize * (7 - y) + cellSize / 2 - fe.Height / 2); gr.ShowText(L); } gr.Fill(); if (board == null) { return; } for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (board [x, y] == null) { continue; } string spriteName; if (board [x, y].Player == ChessColor.White) { spriteName = "w"; } else { spriteName = "b"; } switch (board[x, y].Type) { case PieceType.Pawn: spriteName += "p"; break; case PieceType.Rook: spriteName += "r"; break; case PieceType.Knight: spriteName += "k"; break; case PieceType.Bishop: spriteName += "b"; break; case PieceType.King: spriteName += "K"; break; case PieceType.Queen: spriteName += "q"; break; } sprites.Paint(IFace, gr, new Rectangle( (int)(gridX + x * cellSize), (int)(gridY + (7 - y) * cellSize), (int)cellSize, (int)cellSize), spriteName); } } }
protected override void onDraw(Context gr) { base.onDraw(gr); gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; Rectangle cb = ClientRectangle; Foreground.SetAsSource(gr); buffer.editMutex.EnterReadLock(); editorMutex.EnterReadLock(); #region draw text cursor if (buffer.SelectionInProgress) { selStartCol = getTabulatedColumn(buffer.SelectionStart); selEndCol = getTabulatedColumn(buffer.SelectionEnd); } else if (HasFocus && printedCurrentLine >= 0) { gr.LineWidth = 1.0; double cursorX = cb.X + (getTabulatedColumn(buffer.CurrentPosition) - ScrollX) * fe.MaxXAdvance + leftMargin; gr.MoveTo(0.5 + cursorX, cb.Y + (printedCurrentLine) * (fe.Ascent + fe.Descent)); gr.LineTo(0.5 + cursorX, cb.Y + (printedCurrentLine + 1) * (fe.Ascent + fe.Descent)); gr.Stroke(); } #endregion if (PrintedLines?.Count > 0) { int unfoldedLines = buffer.UnfoldedLines; currentNode = null; CodeLine cl = PrintedLines[0]; int idx0 = buffer.IndexOf(cl); int li = idx0 - 1; while (li >= 0) { if (buffer [li].IsFoldable && !buffer [li].IsFolded) { if (buffer.IndexOf(buffer [li].SyntacticNode.EndLine) > idx0) { currentNode = buffer [li].SyntacticNode; break; } } li--; } for (int i = 0; i < visibleLines; i++) { if (i + ScrollY >= unfoldedLines) //TODO:need optimize { break; } drawLine(gr, cb, i); } } editorMutex.ExitReadLock(); buffer.editMutex.ExitReadLock(); }
protected override void onDraw(Context gr) { base.onDraw(gr); gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Antialias.Subpixel; rText = new Rectangle(new Size( measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); rText.Width -= 2 * Margin; rText.Height -= 2 * Margin; widthRatio = 1f; heightRatio = 1f; Rectangle cb = ClientRectangle; //ignore text alignment if size to content = true //or if text size is larger than client bounds if (Width < 0 || Height < 0 || rText.Width > cb.Width) { rText.X = cb.X; rText.Y = cb.Y; } else { if (horizontalStretch) { widthRatio = (float)cb.Width / rText.Width; if (!verticalStretch) { heightRatio = widthRatio; } } if (verticalStretch) { heightRatio = (float)cb.Height / rText.Height; if (!horizontalStretch) { widthRatio = heightRatio; } } rText.Width = (int)(widthRatio * cb.Width); rText.Height = (int)(heightRatio * cb.Height); switch (TextAlignment) { case Alignment.TopLeft: //ok rText.X = cb.X; rText.Y = cb.Y; break; case Alignment.Top: //ok rText.Y = cb.Y; rText.X = cb.X + cb.Width / 2 - rText.Width / 2; break; case Alignment.TopRight: //ok rText.Y = cb.Y; rText.X = cb.Right - rText.Width; break; case Alignment.Left: //ok rText.X = cb.X; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Right: //ok rText.X = cb.X + cb.Width - rText.Width; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Bottom: //ok rText.X = cb.Width / 2 - rText.Width / 2; rText.Y = cb.Height - rText.Height; break; case Alignment.BottomLeft: //ok rText.X = cb.X; rText.Y = cb.Bottom - rText.Height; break; case Alignment.BottomRight: //ok rText.Y = cb.Bottom - rText.Height; rText.X = cb.Right - rText.Width; break; case Alignment.Center: //ok rText.X = cb.X + cb.Width / 2 - rText.Width / 2; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; } } gr.FontMatrix = new Matrix(widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); int curLineCount = 0; for (int i = 0; i < lines.Count; i++) { string l = lines [i].Replace("\t", new String(' ', Interface.TabSize)); List <string> wl = new List <string> (); int lineLength = (int)gr.TextExtents(l).XAdvance; if (wordWrap && lineLength > cb.Width) { string tmpLine = ""; int curChar = 0; while (curChar < l.Length) { tmpLine += l [curChar]; if ((int)gr.TextExtents(tmpLine).XAdvance > cb.Width) { tmpLine = tmpLine.Remove(tmpLine.Length - 1); wl.Add(tmpLine); tmpLine = ""; continue; } curChar++; } wl.Add(tmpLine); } else { wl.Add(l); } foreach (string ll in wl) { lineLength = (int)gr.TextExtents(ll).XAdvance; if (string.IsNullOrWhiteSpace(ll)) { curLineCount++; continue; } Foreground.SetAsSource(gr); gr.MoveTo(rText.X, rText.Y + fe.Ascent + fe.Height * curLineCount); gr.ShowText(ll); gr.Fill(); curLineCount++; } } }
void drawborder2(Context gr) { Rectangle rBack = new Rectangle(Slot.Size); //rBack.Inflate (-Margin); // if (BorderWidth > 0) // rBack.Inflate (-BorderWidth / 2); Background.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius); gr.Fill(); if (BorderStyle == BorderStyle.Normal) { if (BorderWidth > 0) { Foreground.SetAsSource(gr, rBack); CairoHelpers.CairoRectangle(gr, rBack, CornerRadius, BorderWidth); } } else { gr.LineWidth = 1.0; if (CornerRadius > 0.0) { double radius = CornerRadius; if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0)) { radius = Math.Min(rBack.Height / 2.0, rBack.Width / 2.0); } gr.SetSourceColor(sunkenColor); gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); gr.ArcNegative(0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); gr.MoveTo(0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); gr.LineTo(0.5 + rBack.Left, 0.5 + rBack.Top + radius); gr.Arc(0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius, Math.PI, Math.PI * 1.5); gr.LineTo(-0.5 + rBack.Right - radius, 0.5 + rBack.Top); gr.Arc(-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, Math.PI * 1.5, Math.PI * 1.75); gr.Stroke(); if (BorderStyle == BorderStyle.Raised) { gr.MoveTo(-1.5 + rBack.Right, 1.5 + rBack.Top + radius); gr.ArcNegative(-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, 0, -Math.PI * 0.25); gr.MoveTo(-1.5 + rBack.Right, 1.5 + rBack.Top + radius); gr.LineTo(-1.5 + rBack.Right, -1.5 + rBack.Bottom - radius); gr.Arc(-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius - 1.0, 0, Math.PI / 2.0); gr.LineTo(1.5 + rBack.Left + radius, -1.5 + rBack.Bottom); gr.Arc(0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke(); gr.SetSourceColor(raisedColor); gr.MoveTo(1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); gr.ArcNegative(0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75); gr.MoveTo(1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); gr.LineTo(1.5 + rBack.Left, 1.5 + rBack.Top + radius); gr.Arc(0.5 + rBack.Left + radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI, Math.PI * 1.5); gr.LineTo(-1.5 + rBack.Right - radius, 1.5 + rBack.Top); gr.Arc(-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75); } else { gr.Stroke(); gr.SetSourceColor(raisedColor); } gr.MoveTo(-0.5 + rBack.Right, 0.5 + rBack.Top + radius); gr.ArcNegative(-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25); gr.MoveTo(-0.5 + rBack.Right, 0.5 + rBack.Top + radius); gr.LineTo(-0.5 + rBack.Right, -0.5 + rBack.Bottom - radius); gr.Arc(-0.5 + rBack.Right - radius, -0.5 + rBack.Bottom - radius, radius, 0, Math.PI / 2.0); gr.LineTo(0.5 + rBack.Left + radius, -0.5 + rBack.Bottom); gr.Arc(0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke(); } else { gr.SetSourceColor(sunkenColor); gr.MoveTo(0.5 + rBack.Left, rBack.Bottom); gr.LineTo(0.5 + rBack.Left, 0.5 + rBack.Y); gr.LineTo(rBack.Right, 0.5 + rBack.Y); if (BorderStyle == BorderStyle.Raised) { gr.MoveTo(-1.5 + rBack.Right, 2.0 + rBack.Y); gr.LineTo(-1.5 + rBack.Right, -1.5 + rBack.Bottom); gr.LineTo(2.0 + rBack.Left, -1.5 + rBack.Bottom); gr.Stroke(); gr.SetSourceColor(raisedColor); gr.MoveTo(1.5 + rBack.Left, -1.0 + rBack.Bottom); gr.LineTo(1.5 + rBack.Left, 1.5 + rBack.Y); gr.LineTo(rBack.Right, 1.5 + rBack.Y); } else { gr.Stroke(); gr.SetSourceColor(raisedColor); } gr.MoveTo(-0.5 + rBack.Right, 1.5 + rBack.Y); gr.LineTo(-0.5 + rBack.Right, -0.5 + rBack.Bottom); gr.LineTo(1.0 + rBack.Left, -0.5 + rBack.Bottom); gr.Stroke(); } } }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); Rectangle cb = new Rectangle(0, 0, designWidth, designHeight); gr.Save(); double z = zoom / 100.0; gr.Scale(z, z); if (drawGrid) { double gridLineWidth = 0.2 / z; double glhw = gridLineWidth / 2.0; int nbLines = cb.Width / gridSpacing; double d = cb.Left + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(d - glhw, cb.Y); gr.LineTo(d - glhw, cb.Bottom); d += gridSpacing; } nbLines = cb.Height / gridSpacing; d = cb.Top + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(cb.X, d - glhw); gr.LineTo(cb.Right, d - glhw); d += gridSpacing; } gr.LineWidth = gridLineWidth; Foreground.SetAsSource(gr, cb); gr.Stroke(); } lock (imlVE.RenderMutex) { gr.SetSourceSurface(imlVE.surf, cb.Left, cb.Top); gr.Paint(); imlVE.IsDirty = false; } /*if (Error == null) { * gr.SetSourceColor (Color.Black); * gr.Rectangle (cb, 1.0 / z); * } else { * gr.SetSourceColor (Color.LavenderBlush); * gr.Rectangle (cb, 2.0 / z); * string[] lerrs = Error.ToString ().Split ('\n'); * Point p = cb.Center; * p.Y -= lerrs.Length * 20; * foreach (string le in lerrs) { * drawCenteredTextLine(gr, p, le); * p.Y += 20; * * } * } * gr.Stroke ();*/ Rectangle hr; if (SelectedItem?.Parent != null) { gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; Widget g = SelectedItem; hr = g.ScreenCoordinates(g.getSlot()); // Rectangle rIcons = new Rectangle (iconSize); // rIcons.Width *= 4; // rIcons.Top = hr.Bottom; // rIcons.Left = hr.Right - rIcons.Width + iconSize.Width; Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize); // Rectangle rIcoStyle = rIcoMove; // rIcoStyle.Left += iconSize.Width + 4; using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(mask)) { ctx.Save(); ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4); ctx.Paint(); ctx.Rectangle(hr); ctx.Operator = Operator.Clear; ctx.Fill(); } gr.SetSourceSurface(mask, 0, 0); gr.Paint(); using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(ol)) { ctx.SetSourceColor(Colors.Black); drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5); } gr.SetSourceSurface(ol, 0, 0); gr.Paint(); } drawIcon(gr, icoMove, rIcoMove); //drawIcon (gr, icoStyle, rIcoStyle); } } if (HoverWidget != null) { hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot()); gr.SetSourceColor(Colors.SkyBlue); //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0); gr.Rectangle(hr, 0.4 / z); } gr.Restore(); }
protected override void onDraw(Cairo.Context gr) { if (datas == null) { return; } lock (mutex) { gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); Crow.Rectangle scrBar = ClientRectangle; if (datas?.Count > visibleLines) { scrBar.X += ClientRectangle.Width - scrBarWidth; scrBar.Width = scrBarWidth; } Crow.Rectangle r = ClientRectangle; r.Width -= scrBarWidth; int diffScroll = lastScroll - scroll; int diffVisible = visibleLines - lastVisibleLines; int limInf = 0; int limSup = diffScroll + diffVisible; if (diffScroll < 0) { limInf = lastVisibleLines + diffScroll; limSup = visibleLines; } gr.Save(); gr.ResetClip(); gr.Rectangle(r.X, r.Y + limInf * fe.Height, r.Width, (limSup - limInf) * fe.Height); if (lastHoverIndex != HoverIndex) { if (lastHoverIndex >= 0) { gr.Rectangle(r.X, r.Y + (lastHoverIndex - Scroll) * fe.Height, r.Width, fe.Height); } if (HoverIndex >= 0) { gr.Rectangle(r.X, r.Y + (HoverIndex - Scroll) * fe.Height, r.Width, fe.Height); } } if (lastSelectedIndex != SelectedIndex) { if (lastSelectedIndex >= 0) { gr.Rectangle(r.X, r.Y + (lastSelectedIndex - Scroll) * fe.Height, r.Width, fe.Height); } if (selectedIndex >= 0) { gr.Rectangle(r.X, r.Y + (SelectedIndex - Scroll) * fe.Height, r.Width, fe.Height); } } if (datas?.Count > visibleLines && diffScroll != 0) { gr.Rectangle(scrBar); } gr.ClipPreserve(); gr.Operator = Operator.Clear; gr.Fill(); gr.Operator = Operator.Over; base.onDraw(gr); Foreground.SetAsSource(gr); int i = limInf; while (i < limSup) { if (i + Scroll >= Datas.Count) { break; } drawDataLine(gr, i + Scroll, r.X, r.Y + i * fe.Height, (double)r.Width, fe.Height); i++; } int redrawnLines = limSup - limInf; System.Diagnostics.Debug.WriteLine("draw {0} lines from {1} to {2}", redrawnLines, limInf, limSup - 1); if (lastHoverIndex != HoverIndex) { if (lastHoverIndex >= 0 && (redrawnLines == 0 || (lastHoverIndex < limInf + Scroll || lastHoverIndex >= limSup + Scroll))) { drawDataLine(gr, lastHoverIndex, r.X, r.Y + (lastHoverIndex - Scroll) * fe.Height, (double)r.Width, fe.Height); } if (HoverIndex >= 0 && (redrawnLines == 0 || (HoverIndex < limInf + Scroll || HoverIndex >= limSup + Scroll))) { drawDataLine(gr, HoverIndex, r.X, r.Y + (HoverIndex - Scroll) * fe.Height, (double)r.Width, fe.Height); } } if (lastSelectedIndex != SelectedIndex) { if (lastSelectedIndex >= 0 && (redrawnLines == 0 || (lastSelectedIndex < limInf + Scroll || lastSelectedIndex >= limSup + Scroll))) { drawDataLine(gr, lastSelectedIndex, r.X, r.Y + (lastSelectedIndex - Scroll) * fe.Height, (double)r.Width, fe.Height); } if (SelectedIndex >= 0 && (redrawnLines == 0 || (SelectedIndex < limInf + Scroll || SelectedIndex >= limSup + Scroll))) { drawDataLine(gr, SelectedIndex, r.X, r.Y + (SelectedIndex - Scroll) * fe.Height, (double)r.Width, fe.Height); } } double x = ClientRectangle.X; gr.LineWidth = 1; for (i = 0; i < cols.Length; i++) { x += (double)r.Width * cols [i]; gr.MoveTo(Math.Floor(x) + 0.5, 0); gr.LineTo(Math.Floor(x) + 0.5, r.Height); } gr.Stroke(); lastScroll = Scroll; lastHoverIndex = HoverIndex; lastSelectedIndex = SelectedIndex; lastVisibleLines = visibleLines; if (Datas?.Count <= visibleLines) { gr.Restore(); return; } if (mouseScrolling) { new SolidColor(Crow.Color.Jet.AdjustAlpha(0.5)).SetAsSource(gr); } else { new SolidColor(Crow.Color.LightGray.AdjustAlpha(0.5)).SetAsSource(gr); } CairoHelpers.CairoRectangle(gr, scrBar, 0.0); gr.Fill(); new SolidColor(Crow.Color.BlueCrayola.AdjustAlpha(0.7)).SetAsSource(gr); scrBar.Y += (int)((double)scrBar.Height * (double)Scroll / (double)Datas.Count); scrBar.Height = (int)((double)scrBar.Height * (double)visibleLines / (double)Datas.Count); CairoHelpers.CairoRectangle(gr, scrBar, 2.0); gr.Fill(); gr.Restore(); } }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); if (!drawGrid) { return; } Rectangle cb = ClientRectangle; const double gridLineWidth = 0.1; double glhw = gridLineWidth / 2.0; int nbLines = cb.Width / gridSpacing; double d = cb.Left + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(d - glhw, cb.Y); gr.LineTo(d - glhw, cb.Bottom); d += gridSpacing; } nbLines = cb.Height / gridSpacing; d = cb.Top + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(cb.X, d - glhw); gr.LineTo(cb.Right, d - glhw); d += gridSpacing; } gr.LineWidth = gridLineWidth; Foreground.SetAsSource(gr, cb); gr.Stroke(); lock (imlVE.RenderMutex) { using (Cairo.Surface surf = new Cairo.ImageSurface(imlVE.bmp, Cairo.Format.Argb32, imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) { gr.SetSourceSurface(surf, cb.Left, cb.Top); gr.Paint(); } imlVE.IsDirty = false; } Rectangle hr; if (imlVE.HoverWidget != null) { hr = imlVE.HoverWidget.ScreenCoordinates(imlVE.HoverWidget.getSlot()); // gr.SetSourceColor (Color.LightGray); // gr.DrawCote (new Cairo.PointD (hr.X, hr.Center.Y), new Cairo.PointD (hr.Right, hr.Center.Y)); // gr.DrawCote (new Cairo.PointD (hr.Center.X, hr.Y), new Cairo.PointD (hr.Center.X, hr.Bottom)); //hr.Inflate (2); gr.SetSourceColor(Color.LightGray); gr.SetDash(new double[] { 3.0, 3.0 }, 0.0); gr.Rectangle(hr, 1.0); } if (SelectedItem == null) { return; } hr = SelectedItem.ScreenCoordinates(SelectedItem.getSlot()); hr.Inflate(1); gr.SetSourceColor(Color.Yellow); gr.SetDash(new double[] { 5.0, 3.0 }, 0.0); gr.Rectangle(hr, 1.0); }
protected override void onDraw(Context gr) { base.onDraw(gr); gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; rText = new Rectangle(new Size( measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); rText.Width -= 2 * Margin; rText.Height -= 2 * Margin; widthRatio = 1f; heightRatio = 1f; Rectangle cb = ClientRectangle; rText.X = cb.X; rText.Y = cb.Y; if (horizontalStretch) { widthRatio = (float)cb.Width / (float)rText.Width; if (!verticalStretch) { heightRatio = widthRatio; } } if (verticalStretch) { heightRatio = (float)cb.Height / (float)rText.Height; if (!horizontalStretch) { widthRatio = heightRatio; } } rText.Width = (int)(widthRatio * (float)rText.Width); rText.Height = (int)(heightRatio * (float)rText.Height); switch (TextAlignment) { case Alignment.TopLeft: //ok rText.X = cb.X; rText.Y = cb.Y; break; case Alignment.Top: //ok rText.Y = cb.Y; rText.X = cb.X + cb.Width / 2 - rText.Width / 2; break; case Alignment.TopRight: //ok rText.Y = cb.Y; rText.X = cb.Right - rText.Width; break; case Alignment.Left: //ok rText.X = cb.X; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Right: //ok rText.X = cb.X + cb.Width - rText.Width; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; case Alignment.Bottom: //ok rText.X = cb.Width / 2 - rText.Width / 2; rText.Y = cb.Height - rText.Height; break; case Alignment.BottomLeft: //ok rText.X = cb.X; rText.Y = cb.Bottom - rText.Height; break; case Alignment.BottomRight: //ok rText.Y = cb.Bottom - rText.Height; rText.X = cb.Right - rText.Width; break; case Alignment.Center: //ok rText.X = cb.X + cb.Width / 2 - rText.Width / 2; rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2; break; } gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0); fe = gr.FontExtents; #region draw text cursor if (HasFocus && Selectable) { if (mouseLocalPos >= 0) { computeTextCursor(gr); if (SelectionInProgress) { if (SelBegin < 0) { SelBegin = new Point(CurrentColumn, CurrentLine); SelStartCursorPos = textCursorPos; SelRelease = -1; } else { SelRelease = new Point(CurrentColumn, CurrentLine); if (SelRelease == SelBegin) { SelRelease = -1; } else { SelEndCursorPos = textCursorPos; } } } else { computeTextCursorPosition(gr); } } else { computeTextCursorPosition(gr); } Foreground.SetAsSource(gr); gr.LineWidth = 1.0; gr.MoveTo(0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height); gr.LineTo(0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height); gr.Stroke(); } #endregion //****** debug selection ************* // if (SelRelease >= 0) { // new SolidColor(Color.DarkGreen).SetAsSource(gr); // Rectangle R = new Rectangle ( // rText.X + (int)SelEndCursorPos - 3, // rText.Y + (int)(SelRelease.Y * fe.Height), // 6, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); // } // if (SelBegin >= 0) { // new SolidColor(Color.DarkRed).SetAsSource(gr); // Rectangle R = new Rectangle ( // rText.X + (int)SelStartCursorPos - 3, // rText.Y + (int)(SelBegin.Y * fe.Height), // 6, // (int)fe.Height); // gr.Rectangle (R); // gr.Fill (); // } //******************* for (int i = 0; i < lines.Count; i++) { string l = lines [i].Replace("\t", new String(' ', Interface.TabSize)); int lineLength = (int)gr.TextExtents(l).XAdvance; Rectangle lineRect = new Rectangle( rText.X, rText.Y + (int)Math.Ceiling(i * fe.Height), lineLength, (int)Math.Ceiling(fe.Height)); // if (TextAlignment == Alignment.Center || // TextAlignment == Alignment.Top || // TextAlignment == Alignment.Bottom) // lineRect.X += (rText.Width - lineLength) / 2; // else if (TextAlignment == Alignment.Right || // TextAlignment == Alignment.TopRight || // TextAlignment == Alignment.BottomRight) // lineRect.X += (rText.Width - lineLength); if (string.IsNullOrWhiteSpace(l)) { continue; } Foreground.SetAsSource(gr); gr.MoveTo(lineRect.X, rText.Y + fe.Ascent + fe.Height * i); gr.ShowText(l); gr.Fill(); if (Selectable) { if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { gr.SetSourceColor(selBackground); Rectangle selRect = lineRect; int cpStart = (int)SelStartCursorPos, cpEnd = (int)SelEndCursorPos; if (SelBegin.Y > SelRelease.Y) { cpStart = cpEnd; cpEnd = (int)SelStartCursorPos; } if (i == selectionStart.Y) { selRect.Width -= cpStart; selRect.Left += cpStart; } if (i == selectionEnd.Y) { selRect.Width -= (lineLength - cpEnd); } gr.Rectangle(selRect); gr.FillPreserve(); gr.Save(); gr.Clip(); gr.SetSourceColor(SelectionForeground); gr.MoveTo(lineRect.X, rText.Y + fe.Ascent + fe.Height * i); gr.ShowText(l); gr.Fill(); gr.Restore(); } } } }