static void RenderPlaceholderText_internal(Gtk.Widget widget, Gtk.ExposeEventArgs args, string placeHolderText, ref Pango.Layout layout, float xalign, float yalign, int xpad, int ypad) { if (layout == null) { layout = new Pango.Layout(widget.PangoContext); layout.FontDescription = widget.PangoContext.FontDescription.Copy(); } int wh, ww; args.Event.Window.GetSize(out ww, out wh); int width, height; layout.SetText(placeHolderText); layout.GetPixelSize(out width, out height); int x = xpad + (int)((ww - width) * xalign); int y = ypad + (int)((wh - height) * yalign); using (var gc = new Gdk.GC(args.Event.Window)) { gc.Copy(widget.Style.TextGC(Gtk.StateType.Normal)); Xwt.Drawing.Color color_a = widget.Style.Base(Gtk.StateType.Normal).ToXwtValue(); Xwt.Drawing.Color color_b = widget.Style.Text(Gtk.StateType.Normal).ToXwtValue(); gc.RgbFgColor = color_b.BlendWith(color_a, 0.5).ToGtkValue(); args.Event.Window.DrawLayout(gc, x, y, layout); } }
public void drag(object obj, DragBeginArgs args) { TreeModel model; var paths = this.Selection.GetSelectedRows(out model); if (paths.Length > 0) { var icons = paths.Select(x => this.CreateRowDragIcon(x)); int height = (icons.Select(x => PixmapSizeGetHelper(x).Item2).Sum() - 2 * icons.Count()) + 2; int width = icons.Select(x => PixmapSizeGetHelper(x).Item1).Max(); var final = new Pixmap(this.GdkWindow, width, height); var gc = new Gdk.GC(final); gc.Copy(this.Style.ForegroundGC(StateType.Normal)); gc.Colormap = this.GdkWindow.Colormap; int count_y = 1; var size = PixmapSizeGetHelper(icons.First()); foreach (Pixmap icon in icons) { size = PixmapSizeGetHelper(icon); final.DrawDrawable(gc, icon, 1, 1, 1, count_y, size.Item1 - 2, size.Item2 - 2); count_y += (size.Item2 - 2); } Gtk.Drag.SetIconPixmap(args.Context, GdkWindow.Colormap, final, null, 0, 0); } }
void RealizeHanlder(object o, EventArgs sender) { white_gc = Style.WhiteGC; bkgr_gc = Style.BackgroundGC(StateType.Normal); selection_gc = new Gdk.GC(GdkWindow); selection_gc.Copy(Style.BackgroundGC(StateType.Normal)); Gdk.Color fgcol = new Gdk.Color(); fgcol.Pixel = 0x000077ee; selection_gc.Foreground = fgcol; selection_gc.SetLineAttributes(3, LineStyle.Solid, CapStyle.NotLast, JoinStyle.Round); }
protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) { return; } if (diffMode) { if (path.Equals(selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize(out w, out maxy); if (DrawLeft) { cell_area.Width += cell_area.X - leftSpace; cell_area.X = leftSpace; } var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; cell_area.Width -= RightPadding; window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, cell_area.Y, cell_area.Width - 1, cell_area.Height); Gdk.GC normalGC = widget.Style.TextGC(StateType.Normal); Gdk.GC removedGC = new Gdk.GC(window); removedGC.Copy(normalGC); removedGC.RgbFgColor = Styles.LogView.DiffRemoveBackgroundColor.AddLight(-0.3).ToGdkColor(); Gdk.GC addedGC = new Gdk.GC(window); addedGC.Copy(normalGC); addedGC.RgbFgColor = Styles.LogView.DiffAddBackgroundColor.AddLight(-0.3).ToGdkColor(); Gdk.GC infoGC = new Gdk.GC(window); infoGC.Copy(normalGC); infoGC.RgbFgColor = widget.Style.Text(StateType.Normal).AddLight(0.2); Cairo.Context ctx = CairoHelper.Create(window); // Rendering is done in two steps: // 1) Get a list of blocks to render // 2) render the blocks int y = cell_area.Y + 2; // cline keeps track of the current source code line (the one to jump to when double clicking) int cline = 1; bool inHeader = true; BlockInfo currentBlock = null; List <BlockInfo> blocks = new List <BlockInfo> (); for (int n = 0; n < lines.Length; n++, y += lineHeight) { string line = lines [n]; if (line.Length == 0) { currentBlock = null; y -= lineHeight; continue; } char tag = line [0]; if (line.StartsWith("---", StringComparison.Ordinal) || line.StartsWith("+++", StringComparison.Ordinal)) { // Ignore this part of the header. currentBlock = null; y -= lineHeight; continue; } if (tag == '@') { int l = ParseCurrentLine(line); if (l != -1) { cline = l - 1; } inHeader = false; } else if (tag == '+' && !inHeader) { cline++; } BlockType type; switch (tag) { case '-': type = BlockType.Removed; break; case '+': type = BlockType.Added; break; case '@': type = BlockType.Info; break; default: type = BlockType.Unchanged; break; } if (currentBlock == null || type != currentBlock.Type) { if (y > maxy) { break; } // Starting a new block. Mark section ends between a change block and a normal code block if (currentBlock != null && IsChangeBlock(currentBlock.Type) && !IsChangeBlock(type)) { currentBlock.SectionEnd = true; } currentBlock = new BlockInfo() { YStart = y, FirstLine = n, Type = type, SourceLineStart = cline, SectionStart = (blocks.Count == 0 || !IsChangeBlock(blocks[blocks.Count - 1].Type)) && IsChangeBlock(type) }; blocks.Add(currentBlock); } // Include the line in the current block currentBlock.YEnd = y + lineHeight; currentBlock.LastLine = n; } // Now render the blocks // The y position of the highlighted line int selectedLineRowTop = -1; BlockInfo lastCodeSegmentStart = null; BlockInfo lastCodeSegmentEnd = null; foreach (BlockInfo block in blocks) { if (block.Type == BlockType.Info) { // Finished drawing the content of a code segment. Now draw the segment border and label. if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } lastCodeSegmentStart = block; } lastCodeSegmentEnd = block; if (block.YEnd < 0) { continue; } // Draw the block background DrawBlockBg(ctx, cell_area.X + 1, cell_area.Width - 2, block); // Get all text for the current block StringBuilder sb = new StringBuilder(); for (int n = block.FirstLine; n <= block.LastLine; n++) { string s = ProcessLine(lines [n]); if (n > block.FirstLine) { sb.Append('\n'); } if (block.Type != BlockType.Info && s.Length > 0) { sb.Append(s, 1, s.Length - 1); } else { sb.Append(s); } } // Draw a special background for the selected line if (block.Type != BlockType.Info && p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= block.YStart && p.Value.Y <= block.YEnd) { int row = (p.Value.Y - block.YStart) / lineHeight; double yrow = block.YStart + lineHeight * row; double xrow = cell_area.X + LeftPaddingBlock; int wrow = cell_area.Width - 1 - LeftPaddingBlock; if (block.Type == BlockType.Added) { ctx.SetSourceColor(Styles.LogView.DiffAddBackgroundColor.AddLight(0.1).ToCairoColor()); } else if (block.Type == BlockType.Removed) { ctx.SetSourceColor(Styles.LogView.DiffRemoveBackgroundColor.AddLight(0.1).ToCairoColor()); } else { ctx.SetSourceColor(Styles.LogView.DiffHighlightColor.ToCairoColor()); xrow -= LeftPaddingBlock; wrow += LeftPaddingBlock; } ctx.Rectangle(xrow, yrow, wrow, lineHeight); ctx.Fill(); selectedLine = block.SourceLineStart + row; selctedPath = path; selectedLineRowTop = (int)yrow; } // Draw the line text. Ignore header blocks, since they are drawn as labels in DrawCodeSegmentBorder if (block.Type != BlockType.Info) { layout.SetMarkup(""); layout.SetText(sb.ToString()); Gdk.GC gc; switch (block.Type) { case BlockType.Removed: gc = removedGC; break; case BlockType.Added: gc = addedGC; break; case BlockType.Info: gc = infoGC; break; default: gc = normalGC; break; } window.DrawLayout(gc, cell_area.X + 2 + LeftPaddingBlock, block.YStart, layout); } // Finally draw the change symbol at the left margin DrawChangeSymbol(ctx, widget, cell_area.X + 1, cell_area.Width - 2, block); } // Finish the drawing of the code segment if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } // Draw the source line number at the current selected line. It must be done at the end because it must // be drawn over the source code text and segment borders. if (selectedLineRowTop != -1) { DrawLineBox(normalGC, ctx, ((Gtk.TreeView)widget).VisibleRect.Right - 4, selectedLineRowTop, selectedLine, widget, window); } ((IDisposable)ctx).Dispose(); removedGC.Dispose(); addedGC.Dispose(); infoGC.Dispose(); } else { // Rendering a normal text row int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout(widget.Style.TextGC(GetState(widget, flags)), cell_area.X, y, layout); } }
void RealizeHanlder (object o, EventArgs sender) { white_gc = Style.WhiteGC; bkgr_gc = Style.BackgroundGC (StateType.Normal); selection_gc = new Gdk.GC (GdkWindow); selection_gc.Copy (Style.BackgroundGC (StateType.Normal)); Gdk.Color fgcol = new Gdk.Color (); fgcol.Pixel = 0x000077ee; selection_gc.Foreground = fgcol; selection_gc.SetLineAttributes (3, LineStyle.Solid, CapStyle.NotLast, JoinStyle.Round); }
protected override void Render (Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) return; if (diffMode) { if (path.Equals (selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize (out w, out maxy); if (DrawLeft) { cell_area.Width += cell_area.X - leftSpace; cell_area.X = leftSpace; } var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; cell_area.Width -= RightPadding; window.DrawRectangle (widget.Style.BaseGC (Gtk.StateType.Normal), true, cell_area.X, cell_area.Y, cell_area.Width - 1, cell_area.Height); Gdk.GC normalGC = widget.Style.TextGC (StateType.Normal); Gdk.GC removedGC = new Gdk.GC (window); removedGC.Copy (normalGC); removedGC.RgbFgColor = baseRemoveColor.AddLight (-0.3); Gdk.GC addedGC = new Gdk.GC (window); addedGC.Copy (normalGC); addedGC.RgbFgColor = baseAddColor.AddLight (-0.3); Gdk.GC infoGC = new Gdk.GC (window); infoGC.Copy (normalGC); infoGC.RgbFgColor = widget.Style.Text (StateType.Normal).AddLight (0.2); Cairo.Context ctx = CairoHelper.Create (window); Gdk.Color bgColor = new Gdk.Color (0,0,0); // Rendering is done in two steps: // 1) Get a list of blocks to render // 2) render the blocks int y = cell_area.Y + 2; // cline keeps track of the current source code line (the one to jump to when double clicking) int cline = 1; bool inHeader = true; BlockInfo currentBlock = null; List<BlockInfo> blocks = new List<BlockInfo> (); for (int n=0; n<lines.Length; n++, y += lineHeight) { string line = lines [n]; if (line.Length == 0) { currentBlock = null; y -= lineHeight; continue; } char tag = line [0]; if (line.StartsWith ("---") || line.StartsWith ("+++")) { // Ignore this part of the header. currentBlock = null; y -= lineHeight; continue; } if (tag == '@') { int l = ParseCurrentLine (line); if (l != -1) cline = l - 1; inHeader = false; } else if (tag != '-' && !inHeader) cline++; BlockType type; bool hasBg = false; switch (tag) { case '-': type = BlockType.Removed; break; case '+': type = BlockType.Added; break; case '@': type = BlockType.Info; break; default: type = BlockType.Unchanged; break; } if (currentBlock == null || type != currentBlock.Type) { if (y > maxy) break; // Starting a new block. Mark section ends between a change block and a normal code block if (currentBlock != null && IsChangeBlock (currentBlock.Type) && !IsChangeBlock (type)) currentBlock.SectionEnd = true; currentBlock = new BlockInfo () { YStart = y, FirstLine = n, Type = type, SourceLineStart = cline, SectionStart = (blocks.Count == 0 || !IsChangeBlock (blocks[blocks.Count - 1].Type)) && IsChangeBlock (type) }; blocks.Add (currentBlock); } // Include the line in the current block currentBlock.YEnd = y + lineHeight; currentBlock.LastLine = n; } // Now render the blocks // The y position of the highlighted line int selectedLineRowTop = -1; BlockInfo lastCodeSegmentStart = null; BlockInfo lastCodeSegmentEnd = null; foreach (BlockInfo block in blocks) { if (block.Type == BlockType.Info) { // Finished drawing the content of a code segment. Now draw the segment border and label. if (lastCodeSegmentStart != null) DrawCodeSegmentBorder (infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); lastCodeSegmentStart = block; } lastCodeSegmentEnd = block; if (block.YEnd < 0) continue; // Draw the block background DrawBlockBg (ctx, cell_area.X + 1, cell_area.Width - 2, block); // Get all text for the current block StringBuilder sb = new StringBuilder (); for (int n=block.FirstLine; n <= block.LastLine; n++) { string s = ProcessLine (lines [n]); if (sb.Length > 0) sb.Append ('\n'); if (block.Type != BlockType.Info && s.Length > 0) sb.Append (s, 1, s.Length - 1); else sb.Append (s); } // Draw a special background for the selected line if (block.Type != BlockType.Info && p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= block.YStart && p.Value.Y <= block.YEnd) { int row = (p.Value.Y - block.YStart) / lineHeight; double yrow = block.YStart + lineHeight * row + 0.5; double xrow = cell_area.X + LeftPaddingBlock + 0.5; int wrow = cell_area.Width - 1 - LeftPaddingBlock; if (block.Type == BlockType.Added) ctx.Color = baseAddColor.AddLight (0.1).ToCairoColor (); else if (block.Type == BlockType.Removed) ctx.Color = baseRemoveColor.AddLight (0.1).ToCairoColor (); else { ctx.Color = widget.Style.Base (Gtk.StateType.Prelight).AddLight (0.1).ToCairoColor (); xrow -= LeftPaddingBlock; wrow += LeftPaddingBlock; } ctx.Rectangle (xrow, yrow, wrow, lineHeight); ctx.Fill (); selectedLine = block.SourceLineStart + row; selctedPath = path; selectedLineRowTop = (int)yrow; } // Draw the line text. Ignore header blocks, since they are drawn as labels in DrawCodeSegmentBorder if (block.Type != BlockType.Info) { layout.SetMarkup (""); layout.SetText (sb.ToString ()); Gdk.GC gc; switch (block.Type) { case BlockType.Removed: gc = removedGC; break; case BlockType.Added: gc = addedGC; break; case BlockType.Info: gc = infoGC; break; default: gc = normalGC; break; } window.DrawLayout (gc, cell_area.X + 2 + LeftPaddingBlock, block.YStart, layout); } // Finally draw the change symbol at the left margin DrawChangeSymbol (ctx, cell_area.X + 1, cell_area.Width - 2, block); } // Finish the drawing of the code segment if (lastCodeSegmentStart != null) DrawCodeSegmentBorder (infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); // Draw the source line number at the current selected line. It must be done at the end because it must // be drawn over the source code text and segment borders. if (selectedLineRowTop != -1) DrawLineBox (normalGC, ctx, ((Gtk.TreeView)widget).VisibleRect.Right - 4, selectedLineRowTop, selectedLine, widget, window); ((IDisposable)ctx).Dispose (); removedGC.Dispose (); addedGC.Dispose (); infoGC.Dispose (); } else { // Rendering a normal text row int y = cell_area.Y + (cell_area.Height - height)/2; window.DrawLayout (widget.Style.TextGC (GetState(flags)), cell_area.X, y, layout); } }
protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) { return; } try { if (diffMode) { int w, maxy; window.GetSize(out w, out maxy); int recty = cell_area.Y; int recth = cell_area.Height - 1; if (recty < 0) { recth += recty + 1; recty = -1; } if (recth > maxy + 2) { recth = maxy + 2; } window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, recty, cell_area.Width - 1, recth); Gdk.GC normalGC = widget.Style.TextGC(StateType.Normal); Gdk.GC removedGC = new Gdk.GC(window); removedGC.Copy(normalGC); removedGC.RgbFgColor = new Color(255, 0, 0); Gdk.GC addedGC = new Gdk.GC(window); addedGC.Copy(normalGC); addedGC.RgbFgColor = new Color(0, 0, 255); Gdk.GC infoGC = new Gdk.GC(window); infoGC.Copy(normalGC); infoGC.RgbFgColor = new Color(0xa5, 0x2a, 0x2a); int y = cell_area.Y + 2; for (int n = 0; n < lines.Length; n++, y += lineHeight) { if (y + lineHeight < 0) { continue; } if (y > maxy) { break; } string line = lines[n]; if (line.Length == 0) { continue; } Gdk.GC gc; switch (line[0]) { case '-': gc = removedGC; break; case '+': gc = addedGC; break; case '@': gc = infoGC; break; default: gc = normalGC; break; } layout.SetText(line); window.DrawLayout(gc, cell_area.X + 2, y, layout); } window.DrawRectangle(widget.Style.DarkGC(Gtk.StateType.Prelight), false, cell_area.X, recty, cell_area.Width - 1, recth); removedGC.Dispose(); addedGC.Dispose(); infoGC.Dispose(); } else { int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout(widget.Style.TextGC(GetState(flags)), cell_area.X, y, layout); } } catch (Exception e) { Console.WriteLine(e); } }
protected override void Render (Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) return; if (diffMode) { if (path.Equals (selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize (out w, out maxy); var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; int recty = cell_area.Y; int recth = cell_area.Height - 1; if (recty < 0) { recth += recty + 1; recty = -1; } if (recth > maxy + 2) recth = maxy + 2; window.DrawRectangle (widget.Style.BaseGC (Gtk.StateType.Normal), true, cell_area.X, recty, cell_area.Width - 1, recth); Gdk.GC normalGC = widget.Style.TextGC (StateType.Normal); Gdk.GC removedGC = new Gdk.GC (window); removedGC.Copy (normalGC); removedGC.RgbFgColor = new Color (255, 0, 0); Gdk.GC addedGC = new Gdk.GC (window); addedGC.Copy (normalGC); addedGC.RgbFgColor = new Color (0, 0, 255); Gdk.GC infoGC = new Gdk.GC (window); infoGC.Copy (normalGC); infoGC.RgbFgColor = new Color (0xa5, 0x2a, 0x2a); int y = cell_area.Y + 2; int cline = 1; bool inHeader = true; for (int n=0; n<lines.Length; n++, y += lineHeight) { string line = lines [n]; if (line.Length == 0) continue; char tag = line [0]; // Keep track of the real file line int thisLine = cline; if (tag == '@') { int l = ParseCurrentLine (line); if (l != -1) cline = thisLine = l; inHeader = false; } else if (tag != '-' && !inHeader) cline++; if (y + lineHeight < 0) continue; if (y > maxy) break; Gdk.GC gc; switch (tag) { case '-': gc = removedGC; break; case '+': gc = addedGC; break; case '@': gc = infoGC; break; default: gc = normalGC; break; } if (p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= y && p.Value.Y < y + lineHeight) { window.DrawRectangle (widget.Style.BaseGC (Gtk.StateType.Prelight), true, cell_area.X, y, cell_area.Width - 1, lineHeight); selectedLine = thisLine; selctedPath = path; } layout.SetText (line); window.DrawLayout (gc, cell_area.X + 2, y, layout); } window.DrawRectangle (widget.Style.DarkGC (Gtk.StateType.Prelight), false, cell_area.X, recty, cell_area.Width - 1, recth); removedGC.Dispose (); addedGC.Dispose (); infoGC.Dispose (); } else { int y = cell_area.Y + (cell_area.Height - height)/2; window.DrawLayout (widget.Style.TextGC (GetState(flags)), cell_area.X, y, layout); } }
protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) { return; } if (diffMode) { if (path.Equals(selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize(out w, out maxy); if (DrawLeft) { cell_area.Width += cell_area.X - leftSpace; cell_area.X = leftSpace; } var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; cell_area.Width -= RightPadding; window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, cell_area.Y, cell_area.Width - 1, cell_area.Height); Gdk.GC normalGC = widget.Style.TextGC(StateType.Normal); Gdk.GC removedGC = new Gdk.GC(window); removedGC.Copy(normalGC); removedGC.RgbFgColor = Styles.LogView.DiffRemoveBackgroundColor.AddLight(-0.3).ToGdkColor(); Gdk.GC addedGC = new Gdk.GC(window); addedGC.Copy(normalGC); addedGC.RgbFgColor = Styles.LogView.DiffAddBackgroundColor.AddLight(-0.3).ToGdkColor(); Gdk.GC infoGC = new Gdk.GC(window); infoGC.Copy(normalGC); infoGC.RgbFgColor = widget.Style.Text(StateType.Normal).AddLight(0.2); Cairo.Context ctx = CairoHelper.Create(window); // Rendering is done in two steps: // 1) Get a list of blocks to render // 2) render the blocks var blocks = CalculateBlocks(maxy, cell_area.Y + 2); // Now render the blocks // The y position of the highlighted line int selectedLineRowTop = -1; BlockInfo lastCodeSegmentStart = null; BlockInfo lastCodeSegmentEnd = null; foreach (BlockInfo block in blocks) { if (block.Type == BlockType.Info) { // Finished drawing the content of a code segment. Now draw the segment border and label. if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } lastCodeSegmentStart = block; } lastCodeSegmentEnd = block; if (block.YEnd < 0) { continue; } // Draw the block background DrawBlockBg(ctx, cell_area.X + 1, cell_area.Width - 2, block); // Get all text for the current block StringBuilder sb = new StringBuilder(); for (int n = block.FirstLine; n <= block.LastLine; n++) { string s = ProcessLine(lines [n]); if (n > block.FirstLine) { sb.Append('\n'); } if ((block.Type == BlockType.Added || block.Type == BlockType.Removed) && s.Length > 0) { sb.Append(' '); sb.Append(s, 1, s.Length - 1); } else { sb.Append(s); } } // Draw a special background for the selected line if (block.Type != BlockType.Info && p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= block.YStart && p.Value.Y <= block.YEnd) { int row = (p.Value.Y - block.YStart) / lineHeight; double yrow = block.YStart + lineHeight * row; double xrow = cell_area.X + LeftPaddingBlock; int wrow = cell_area.Width - 1 - LeftPaddingBlock; if (block.Type == BlockType.Added) { ctx.SetSourceColor(Styles.LogView.DiffAddBackgroundColor.AddLight(0.1).ToCairoColor()); } else if (block.Type == BlockType.Removed) { ctx.SetSourceColor(Styles.LogView.DiffRemoveBackgroundColor.AddLight(0.1).ToCairoColor()); } else { ctx.SetSourceColor(Styles.LogView.DiffHighlightColor.ToCairoColor()); xrow -= LeftPaddingBlock; wrow += LeftPaddingBlock; } ctx.Rectangle(xrow, yrow, wrow, lineHeight); ctx.Fill(); selectedLine = block.SourceLineStart + row; selctedPath = path; selectedLineRowTop = (int)yrow; } // Draw the line text. Ignore header blocks, since they are drawn as labels in DrawCodeSegmentBorder if (block.Type != BlockType.Info) { layout.SetMarkup(""); layout.SetText(sb.ToString()); Gdk.GC gc; switch (block.Type) { case BlockType.Removed: gc = removedGC; break; case BlockType.Added: gc = addedGC; break; case BlockType.Info: gc = infoGC; break; default: gc = normalGC; break; } window.DrawLayout(gc, cell_area.X + 2 + LeftPaddingBlock, block.YStart, layout); } // Finally draw the change symbol at the left margin DrawChangeSymbol(ctx, widget, cell_area.X + 1, cell_area.Width - 2, block); } // Finish the drawing of the code segment if (lastCodeSegmentStart != null) { DrawCodeSegmentBorder(infoGC, ctx, cell_area.X, cell_area.Width, lastCodeSegmentStart, lastCodeSegmentEnd, lines, widget, window); } // Draw the source line number at the current selected line. It must be done at the end because it must // be drawn over the source code text and segment borders. if (selectedLineRowTop != -1) { DrawLineBox(normalGC, ctx, ((Gtk.TreeView)widget).VisibleRect.Right - 4, selectedLineRowTop, selectedLine, widget, window); } ((IDisposable)ctx).Dispose(); removedGC.Dispose(); addedGC.Dispose(); infoGC.Dispose(); } else { // Rendering a normal text row int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout(widget.Style.TextGC(GetState(widget, flags)), cell_area.X, y, layout); } }
protected override void Render (Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) return; try { if (diffMode) { int w, maxy; window.GetSize (out w, out maxy); int recty = cell_area.Y; int recth = cell_area.Height - 1; if (recty < 0) { recth += recty + 1; recty = -1; } if (recth > maxy + 2) recth = maxy + 2; window.DrawRectangle (widget.Style.BaseGC (Gtk.StateType.Normal), true, cell_area.X, recty, cell_area.Width - 1, recth); Gdk.GC normalGC = widget.Style.TextGC (StateType.Normal); Gdk.GC removedGC = new Gdk.GC (window); removedGC.Copy (normalGC); removedGC.RgbFgColor = new Color (255, 0, 0); Gdk.GC addedGC = new Gdk.GC (window); addedGC.Copy (normalGC); addedGC.RgbFgColor = new Color (0, 0, 255); Gdk.GC infoGC = new Gdk.GC (window); infoGC.Copy (normalGC); infoGC.RgbFgColor = new Color (0xa5, 0x2a, 0x2a); int y = cell_area.Y + 2; for (int n = 0; n < lines.Length; n++,y += lineHeight) { if (y + lineHeight < 0) continue; if (y > maxy) break; string line = lines[n]; if (line.Length == 0) continue; Gdk.GC gc; switch (line[0]) { case '-': gc = removedGC; break; case '+': gc = addedGC; break; case '@': gc = infoGC; break; default: gc = normalGC; break; } layout.SetText (line); window.DrawLayout (gc, cell_area.X + 2, y, layout); } window.DrawRectangle (widget.Style.DarkGC (Gtk.StateType.Prelight), false, cell_area.X, recty, cell_area.Width - 1, recth); removedGC.Dispose (); addedGC.Dispose (); infoGC.Dispose (); } else { int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout (widget.Style.TextGC (GetState (flags)), cell_area.X, y, layout); } } catch (Exception e) { Console.WriteLine (e); } }
protected override void Render(Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (isDisposed) { return; } if (diffMode) { if (path.Equals(selctedPath)) { selectedLine = -1; selctedPath = null; } int w, maxy; window.GetSize(out w, out maxy); var treeview = widget as FileTreeView; var p = treeview != null? treeview.CursorLocation : null; int recty = cell_area.Y; int recth = cell_area.Height - 1; if (recty < 0) { recth += recty + 1; recty = -1; } if (recth > maxy + 2) { recth = maxy + 2; } window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Normal), true, cell_area.X, recty, cell_area.Width - 1, recth); Gdk.GC normalGC = widget.Style.TextGC(StateType.Normal); Gdk.GC removedGC = new Gdk.GC(window); removedGC.Copy(normalGC); removedGC.RgbFgColor = new Color(255, 0, 0); Gdk.GC addedGC = new Gdk.GC(window); addedGC.Copy(normalGC); addedGC.RgbFgColor = new Color(0, 0, 255); Gdk.GC infoGC = new Gdk.GC(window); infoGC.Copy(normalGC); infoGC.RgbFgColor = new Color(0xa5, 0x2a, 0x2a); int y = cell_area.Y + 2; int cline = 1; bool inHeader = true; for (int n = 0; n < lines.Length; n++, y += lineHeight) { string line = lines [n]; if (line.Length == 0) { continue; } char tag = line [0]; // Keep track of the real file line int thisLine = cline; if (tag == '@') { int l = ParseCurrentLine(line); if (l != -1) { cline = thisLine = l; } inHeader = false; } else if (tag != '-' && !inHeader) { cline++; } if (y + lineHeight < 0) { continue; } if (y > maxy) { break; } Gdk.GC gc; switch (tag) { case '-': gc = removedGC; break; case '+': gc = addedGC; break; case '@': gc = infoGC; break; default: gc = normalGC; break; } if (p.HasValue && p.Value.X >= cell_area.X && p.Value.X <= cell_area.Right && p.Value.Y >= y && p.Value.Y < y + lineHeight) { window.DrawRectangle(widget.Style.BaseGC(Gtk.StateType.Prelight), true, cell_area.X, y, cell_area.Width - 1, lineHeight); selectedLine = thisLine; selctedPath = path; } layout.SetText(line); window.DrawLayout(gc, cell_area.X + 2, y, layout); } window.DrawRectangle(widget.Style.DarkGC(Gtk.StateType.Prelight), false, cell_area.X, recty, cell_area.Width - 1, recth); removedGC.Dispose(); addedGC.Dispose(); infoGC.Dispose(); } else { int y = cell_area.Y + (cell_area.Height - height) / 2; window.DrawLayout(widget.Style.TextGC(GetState(flags)), cell_area.X, y, layout); } }
static void RenderPlaceholderText_internal (Gtk.Widget widget, Gtk.ExposeEventArgs args, string placeHolderText, ref Pango.Layout layout, float xalign, float yalign, int xpad, int ypad) { if (layout == null) { layout = new Pango.Layout (widget.PangoContext); layout.FontDescription = widget.PangoContext.FontDescription.Copy (); } int wh, ww; args.Event.Window.GetSize (out ww, out wh); int width, height; layout.SetText (placeHolderText); layout.GetPixelSize (out width, out height); int x = xpad + (int)((ww - width) * xalign); int y = ypad + (int)((wh - height) * yalign); using (var gc = new Gdk.GC (args.Event.Window)) { gc.Copy (widget.Style.TextGC (Gtk.StateType.Normal)); Xwt.Drawing.Color color_a = widget.Style.Base (Gtk.StateType.Normal).ToXwtValue (); Xwt.Drawing.Color color_b = widget.Style.Text (Gtk.StateType.Normal).ToXwtValue (); gc.RgbFgColor = color_b.BlendWith (color_a, 0.5).ToGtkValue (); args.Event.Window.DrawLayout (gc, x, y, layout); } }
protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { if (source == null) { return; } view = widget as SourceView; bool path_selected = view != null && view.Selection.PathIsSelected (path); StateType state = RendererStateToWidgetState (widget, flags); RenderSelection (drawable, background_area, path_selected, state); int title_layout_width = 0, title_layout_height = 0; int count_layout_width = 0, count_layout_height = 0; int max_title_layout_width; bool hide_counts = source.Count <= 0; Pixbuf icon = SourceIconResolver.ResolveIcon (source, RowHeight); if (state == StateType.Insensitive) { // Code ported from gtk_cell_renderer_pixbuf_render() var icon_source = new IconSource () { Pixbuf = icon, Size = IconSize.SmallToolbar, SizeWildcarded = false }; icon = widget.Style.RenderIcon (icon_source, widget.Direction, state, (IconSize)(-1), widget, "SourceRowRenderer"); } FontDescription fd = widget.PangoContext.FontDescription.Copy (); fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source ? Pango.Weight.Bold : Pango.Weight.Normal; if (view != null && source == view.NewPlaylistSource) { fd.Style = Pango.Style.Italic; hide_counts = true; } Pango.Layout title_layout = new Pango.Layout (widget.PangoContext); Pango.Layout count_layout = null; if (!hide_counts) { count_layout = new Pango.Layout (widget.PangoContext); count_layout.FontDescription = fd; count_layout.SetMarkup (String.Format ("<span size=\"small\">{0}</span>", source.Count)); count_layout.GetPixelSize (out count_layout_width, out count_layout_height); } max_title_layout_width = cell_area.Width - (icon == null ? 0 : icon.Width) - count_layout_width - 10; if (!hide_counts && max_title_layout_width < 0) { hide_counts = true; } title_layout.FontDescription = fd; title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale); title_layout.Ellipsize = EllipsizeMode.End; title_layout.SetText (source.Name); title_layout.GetPixelSize (out title_layout_width, out title_layout_height); Gdk.GC main_gc = widget.Style.TextGC (state); drawable.DrawLayout (main_gc, cell_area.X + (icon == null ? 0 : icon.Width) + 6, Middle (cell_area, title_layout_height), title_layout); if (icon != null) { drawable.DrawPixbuf (main_gc, icon, 0, 0, cell_area.X, Middle (cell_area, icon.Height), icon.Width, icon.Height, RgbDither.None, 0, 0); } if (hide_counts) { return; } Gdk.GC mod_gc = widget.Style.TextGC (state); if (state == StateType.Normal || (view != null && state == StateType.Prelight)) { Gdk.Color fgcolor = widget.Style.Base (state); Gdk.Color bgcolor = widget.Style.Text (state); mod_gc = new Gdk.GC (drawable); mod_gc.Copy (widget.Style.TextGC (state)); mod_gc.RgbFgColor = Hyena.Gui.GtkUtilities.ColorBlend (fgcolor, bgcolor); mod_gc.RgbBgColor = fgcolor; } drawable.DrawLayout (mod_gc, cell_area.X + cell_area.Width - count_layout_width - 2, Middle (cell_area, count_layout_height), count_layout); }
private void DrawMove(Gdk.Window window) { Gdk.GC gc = Style.ForegroundGC (StateType.Normal); if (info.stage == MoveStage.Start) { int x = start_x + info.start.x * (space + size); int y = start_y + info.start.y * (space + size); window.DrawRectangle (gc, false, x, y, size, size); } if (info.cursorVisible) { Gdk.GC tempGC = new Gdk.GC (window); tempGC.Copy (gc); tempGC.SetLineAttributes (1, LineStyle. OnOffDash, 0, 0); int x = start_x + info.cursor.x * (space + size); int y = start_y + info.cursor.y * (space + size); window.DrawRectangle (tempGC, false, x, y, size, size); } return; }
protected virtual void DrawLastMove(Gdk.Window window) { if (lastMove == null) return; int i = -1, j = -1; string letters = "abcdefgh"; string numbers = "87654321"; int k = lastMove.Length - 2; while (k >= 0) { i = letters.IndexOf (lastMove[k]); j = numbers.IndexOf (lastMove[k + 1]); if (i >= 0 && j >= 0) break; k--; } if (i == -1 || j == -1) return; Gdk.GC gc = Style.ForegroundGC (StateType.Normal); Gdk.GC tempGC = new Gdk.GC (window); tempGC.Copy (gc); tempGC.SetLineAttributes (2, LineStyle.OnOffDash, CapStyle.Round, 0); if (side) { i = 7 - i; j = 7 - j; } int x = start_x + i * (space + size); int y = start_y + j * (space + size); window.DrawRectangle (tempGC, false, x, y, size, size); }
// FIXME: draw the whole line using Pango float DrawDocumentWord(Gdk.Drawable g, string word, PointF position, Pango.FontDescription font, System.Drawing.Color foreColor, Gdk.GC gc) { if (word == null || word.Length == 0) { return 0f; } float wordWidth = MeasureString(font, word); g.DrawRectangle(gc, true, new Gdk.Rectangle((int) Math.Abs(position.X), (int) position.Y, (int) Math.Abs(wordWidth), (int) Math.Abs(FontHeight))); using (Gdk.GC tgc = new Gdk.GC(g)) { tgc.Copy(gc); tgc.RgbFgColor = new Gdk.Color(foreColor); return DrawString(g, tgc, position.X, position.Y, word); } }
float DrawEOLMarker(Gdk.Drawable g, System.Drawing.Color color, Gdk.GC gc, float x, float y) { //string EOLMarker = "\u00B6"; string EOLMarker = "|"; float width = MeasureString(FontContainer.DefaultFont, EOLMarker); g.DrawRectangle(gc, true, new Gdk.Rectangle((int)Math.Round(x), (int) Math.Round(y), (int) Math.Round(width), fontHeight)); HighlightColor eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EolMarker"); //g.DrawString("\u00B6", eolMarkerColor.Font, new SolidBrush(color), x, y, measureStringFormat); using (Gdk.GC tgc = new Gdk.GC(g)) { tgc.Copy(gc); tgc.RgbFgColor = new Gdk.Color(eolMarkerColor.Color); return DrawString(g, tgc, x, y, EOLMarker); } }