protected override void Render (Drawable window, Widget widget, Rectangle background_area, Rectangle cell_area, Rectangle expose_area, CellRendererState flags) { int width = 0, height = 0, x_offset = 0, y_offset = 0; StateType state; GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); if (widget.HasFocus) state = StateType.Active; else state = StateType.Normal; width -= (int) this.Xpad * 2; height -= (int) this.Ypad * 2; //FIXME: Style.PaintBox needs some customization so that if you pass it //a Gdk.Rectangle.Zero it gives a clipping area big enough to draw //everything Gdk.Rectangle clipping_area = new Gdk.Rectangle ((int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), width - 1, height - 1); Style.PaintBox (widget.Style, (Gdk.Window) window, StateType.Normal, ShadowType.In, clipping_area, widget, "trough", (int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), width - 1, height - 1); Gdk.Rectangle clipping_area2 = new Gdk.Rectangle ((int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), (int) (width * Percentage), height - 1); Style.PaintBox (widget.Style, (Gdk.Window) window, state, ShadowType.Out, clipping_area2, widget, "bar", (int) (cell_area.X + x_offset + this.Xpad), (int) (cell_area.Y + y_offset + this.Ypad), (int) (width * Percentage), height - 1); }
protected override void OnSizeAllocated (Rectangle allocation) { base.OnSizeAllocated (allocation); if (child != null) child.Allocation = allocation; }
public EditSession StartEditing (Rectangle cellArea, StateType state) { IPropertyEditor ed = CreateEditor (cellArea, state); if (ed == null) return null; return new EditSession (container, context, ed); }
protected override void OnSizeAllocated (Rectangle allocation) { Requisition headerReq; Rectangle childAlloc; base.OnSizeAllocated (allocation); headerReq = header.ChildRequisition; childAlloc.X = allocation.X + (int)BorderWidth; childAlloc.Width = allocation.Width - (int)BorderWidth; childAlloc.Y = allocation.Y + (int)BorderWidth; childAlloc.Height = headerReq.Height; header.Allocation = childAlloc; // Indent the tiles by the same distance as the height of the header. childAlloc.X += headerReq.Height; childAlloc.Width -= headerReq.Height; foreach (Widget w in VisibleTiles) { childAlloc.Y += childAlloc.Height; childAlloc.Height = w.ChildRequisition.Height; w.Allocation = childAlloc; } }
public Face (uint id, Gdk.Rectangle r) : base (id) { rect = r; photo_id = 0; tag_id = 0; tag = null; }
public BlockProcessor(Rectangle area, int step) { this.area = area; rect = new Gdk.Rectangle (area.X, area.Y, Math.Min (step, area.Width), Math.Min (step, area.Height)); }
protected override void OnSizeAllocated (Rectangle allocation) { if (Child != null) { Child.SizeAllocate (allocation); } base.OnSizeAllocated (allocation); }
public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo) { string text = GetRenderText (photo); var layout = new Pango.Layout (widget.PangoContext); layout.SetText (text); Rectangle layout_bounds; layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height); layout_bounds.Y = cell_area.Y; layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2; if (layout_bounds.IntersectsWith (expose_area)) { Style.PaintLayout (widget.Style, window, cell_state, true, expose_area, widget, "IconView", layout_bounds.X, layout_bounds.Y, layout); } }
private IEnumerator DragRect(Gdk.Point[] p) { var i = Array.FindLastIndex (rects, x => x.Contains (p [0])); if (i < 0) { i = rects.Length; Array.Resize(ref rects, i + 1); rects[i] = new Gdk.Rectangle(p[0].X, p[0].Y, 3, 3); } var start = rects [i]; var move = p [0].X < start.Right - 5 && p [0].Y < start.Bottom - 5; for (;;) { yield return null; var r = rects [i]; var movedX = p [1].X - p [0].X; var movedY = p [1].Y - p [0].Y; if (move) { rects [i].X = start.X + movedX; rects [i].Y = start.Y + movedY; } else { rects [i].Width = Math.Max (3, start.Width + movedX); rects [i].Height = Math.Max (3, start.Height + movedY); } r = r.Union (rects [i]); QueueDrawArea (r.X, r.Y, r.Width + 1, r.Height + 1); } }
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { #if false Surface = new ImageSurface (Format.RGB24, allocation.Width, allocation.Height); Context ctx = new Context (Surface); #else Console.WriteLine ("source status = {0}", info.Surface.Status); Surface = info.Surface.CreateSimilar (Content.Color, allocation.Width, allocation.Height); System.Console.WriteLine ("status = {1} pointer = {0}", Surface.Handle.ToString (), Surface.Status); Context ctx = new Context (Surface); #endif Bounds = allocation; ctx.Matrix = info.Fill (allocation); Pattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); ((IDisposable)ctx).Dispose (); p.Destroy (); }
public override void GetSize (Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); if (CategoryIcon != null) { height = (int)CategoryIcon.Height + ((int)Ypad * 2) + topLevelTemplateHeadingTotalYPadding; } }
public Face (uint id, uint ph, uint tg, Gdk.Rectangle r) : base (id) { TagStore tag_store = FSpot.Core.Database.Tags; rect = r; photo_id = ph; tag_id = tg; tag = tag_store.GetTagById((int)tag_id); }
protected override void OnSizeAllocated (Rectangle allocation) { base.OnSizeAllocated (allocation); radius = allocation.Height / 2; center = new Cairo.PointD(allocation.Width / 2, allocation.Height / 2); hourLength = allocation.Height / 3 / 1.65F; minuteLength = allocation.Height / 3 / 1.20F; secondLength = allocation.Height / 3 / 1.15F; }
public override void GetSize (Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); if (TemplateIcon != null) { height = (int)TemplateIcon.Height + ((int)Ypad * 2); } else { height += groupTemplateHeadingTotalYPadding; } }
public override void GetSize(Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { Rectangle result; Father.OnMeasureItem( ItemIndex, widget, ref cell_area, out result ); x_offset = result.X; y_offset = result.Y; width = result.Width; height = result.Height; }
public Face (Gdk.Rectangle r) : base (0) { rect = r; //id = 0; photo_id = 0; tag_id = 0; tag= null; }
public override void GetSize (Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); if (editor != null) { Gtk.Requisition req = editor.SizeRequest (); if (req.Height > height) height = req.Height; } }
public bool Step(out Rectangle region) { rect.Intersect (area, out region); rect.X += rect.Width; if (rect.X >= area.Right) { rect.X = area.X; rect.Y += rect.Height; } return !region.IsEmpty; }
public DrawItemEventArgs( int ItemIndex, Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags ) { this.itemIndex = ItemIndex; this.drawable = window; this.widget = widget; this.backgroundArea = background_area; this.cellArea = cell_area; this.exposeArea = expose_area; this.cellFlags = flags; }
public BounceFadePopupWindow (TextEditor editor, Rectangle bounds) : base (Gtk.WindowType.Popup) { this.Decorated = false; this.BorderWidth = 0; this.HasFrame = true; this.editor = editor; this.bounds = bounds; this.Duration = 500; ExpandWidth = 12; ExpandHeight = 2; BounceEasing = Easing.Sine; }
protected override void Render(Drawable window, Widget widget, Rectangle backgroundArea, Rectangle cellArea, Rectangle exposeArea, CellRendererState flags) { CellState state = (CellState)flags; using (IContext context = new CairoContext (window)) { Area bkg = new Area (new Point (backgroundArea.X, backgroundArea.Y), backgroundArea.Width, backgroundArea.Height); Area cell = new Area (new Point (cellArea.X, cellArea.Y), cellArea.Width, cellArea.Height); PlayslistCellRenderer.Render (Item, Project, Count, IsExpanded, App.Current.DrawingToolkit, context, bkg, cell, state); } }
public override void GetSize(Widget widget, ref Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { x_offset = 0; y_offset = 0; width = StyleConf.ListSelectedWidth + StyleConf.ListRowSeparator + StyleConf.ListTextWidth; height = StyleConf.ListCategoryHeight; if (Item is TimelineEventLongoMatch) { TimelineEventLongoMatch evt = Item as TimelineEventLongoMatch; if (evt.Miniature != null) { width += StyleConf.ListImageWidth + StyleConf.ListRowSeparator; } width += (StyleConf.ListImageWidth + StyleConf.ListRowSeparator) * (evt.Players.Count + evt.Teams.Count); } }
static void DrawBrush (double x, double y, bool black) { Gdk.Rectangle update_rect = new Gdk.Rectangle (); update_rect.X = (int) x - 5; update_rect.Y = (int) y - 5; update_rect.Width = 10; update_rect.Height = 10; pixmap.DrawRectangle (black ? darea.Style.BlackGC : darea.Style.WhiteGC, true, update_rect.X, update_rect.Y, update_rect.Width, update_rect.Height); darea.QueueDrawArea (update_rect.X, update_rect.Y, update_rect.Width, update_rect.Height); }
public IrregularSurface(Cairo.ImageSurface source, Rectangle[] roi) { this.placedSurfaces = new List<PlacedSurface> (roi.Length); foreach (Rectangle rect in roi) { Rectangle ri = Rectangle.Intersect (source.GetBounds (), rect); if (!ri.IsEmpty) this.placedSurfaces.Add (new PlacedSurface (source, ri)); } this.region = Utility.RectanglesToRegion (roi); this.region.Intersect (Region.Rectangle (source.GetBounds ())); }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { Cairo.Surface similar = CairoUtils.CreateSurface (w.GdkWindow); Bounds = bounds; Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height); Context ctx = new Context (Surface); ctx.Matrix = info.Fill (Bounds); Pattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); ((IDisposable)ctx).Dispose (); p.Destroy (); }
protected override void Render (Drawable window, Widget widget, Rectangle background_area, Rectangle cell_area, Rectangle expose_area, CellRendererState flags) { int iconTextPadding = iconTextXPadding; int textYOffset = 0; Rectangle iconRect = GetIconRect (cell_area); if (CategoryIcon != null) { iconRect = DrawIcon (window, widget, cell_area, flags); iconTextPadding = topLevelIconTextXPadding; textYOffset = topLevelTemplateHeadingYOffset; } DrawTemplateCategoryText (window, widget, cell_area, iconRect, iconTextPadding, textYOffset, flags); }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { using (var similar = CairoUtils.CreateSurface (w.GdkWindow)) { Bounds = bounds; Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height); var ctx = new Context (Surface); ctx.Matrix = info.Fill (Bounds); Pattern p = new SurfacePattern (info.Surface); ctx.SetSource (p); ctx.Paint (); ctx.Dispose (); p.Dispose (); } }
protected override void OnSizeAllocated (Rectangle allocation) { Requisition headerReq, tileReq; Rectangle childAlloc; int col, i, tilesWidth, maxcols; IList<Tile> tiles = VisibleTiles; base.OnSizeAllocated (allocation); headerReq = header.ChildRequisition; childAlloc.X = allocation.X + (int)BorderWidth; childAlloc.Width = allocation.Width - (int)BorderWidth; childAlloc.Y = allocation.Y + (int)BorderWidth; childAlloc.Height = headerReq.Height; header.Allocation = childAlloc; if (tiles.Count == 0) return; tileReq = ((Gtk.Widget)tiles[0]).ChildRequisition; if (tileReq.Width == 0) return; tilesWidth = allocation.Width - (int)(2 * BorderWidth) - headerReq.Height; maxcols = tilesWidth / tileReq.Width; if (maxcols != Columns) { Columns = maxcols; QueueResize (); return; } childAlloc.X += headerReq.Height; childAlloc.Y += childAlloc.Height; childAlloc.Width = tileReq.Width; childAlloc.Height = tileReq.Height; for (i = col = 0; i < tiles.Count; i++) { ((Gtk.Widget)tiles[i]).Allocation = childAlloc; col = (col + 1) % Columns; if (col == 0) { childAlloc.X = (int)BorderWidth + headerReq.Height; childAlloc.Y += childAlloc.Height; } else childAlloc.X += childAlloc.Width; } }
/// <summary> /// Provides a default implementation for performing dst = F(lhs, rhs) over some rectangle of interest. /// </summary> /// <param name="dst">The Surface to write pixels to.</param> /// <param name="dstOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the dst Surface.</param> /// <param name="lhs">The Surface to read pixels from for the lhs parameter given to the method <b>ColorBgra Apply(ColorBgra, ColorBgra)</b>.</param> /// <param name="lhsOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the lhs Surface.</param> /// <param name="rhs">The Surface to read pixels from for the rhs parameter given to the method <b>ColorBgra Apply(ColorBgra, ColorBgra)</b></param> /// <param name="rhsOffset">The pixel offset that defines the upper-left of the rectangle-of-interest for the rhs Surface.</param> /// <param name="roiSize">The size of the rectangles-of-interest for all Surfaces.</param> public void Apply (Cairo.ImageSurface dst, Point dstOffset, Cairo.ImageSurface lhs, Point lhsOffset, Cairo.ImageSurface rhs, Point rhsOffset, Size roiSize) { // Bounds checking only enabled in Debug builds. #if DEBUG // Create bounding rectangles for each Surface Rectangle dstRect = new Rectangle (dstOffset, roiSize); Rectangle lhsRect = new Rectangle (lhsOffset, roiSize); Rectangle rhsRect = new Rectangle (rhsOffset, roiSize); // Clip those rectangles to those Surface's bounding rectangles Rectangle dstClip = Rectangle.Intersect (dstRect, dst.GetBounds ()); Rectangle lhsClip = Rectangle.Intersect (lhsRect, lhs.GetBounds ()); Rectangle rhsClip = Rectangle.Intersect (rhsRect, rhs.GetBounds ()); // If any of those Rectangles actually got clipped, then throw an exception if (dstRect != dstClip) { throw new ArgumentOutOfRangeException ("roiSize", "Destination roi out of bounds"); } if (lhsRect != lhsClip) { throw new ArgumentOutOfRangeException ("roiSize", "lhs roi out of bounds"); } if (rhsRect != rhsClip) { throw new ArgumentOutOfRangeException ("roiSize", "rhs roi out of bounds"); } #endif // Cache the width and height properties int width = roiSize.Width; int height = roiSize.Height; // Do the work. unsafe { for (int row = 0; row < height; ++row) { ColorBgra* dstPtr = dst.GetPointAddress (dstOffset.X, dstOffset.Y + row); ColorBgra* lhsPtr = lhs.GetPointAddress (lhsOffset.X, lhsOffset.Y + row); ColorBgra* rhsPtr = rhs.GetPointAddress (rhsOffset.X, rhsOffset.Y + row); Apply (dstPtr, lhsPtr, rhsPtr, width); } } }
protected override void Render (Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { try{ Gdk.Rectangle text_area1 = new Gdk.Rectangle(); Gdk.Rectangle text_area2 = new Gdk.Rectangle(); Gdk.Rectangle text_area3 = new Gdk.Rectangle(); text_area1.Y= cell_area.Y; text_area2.Y= cell_area.Y+33; text_area3.X = cell_area.Width-20; text_area3.Y= cell_area.Y+33; text_area3.Width = 75; Pango.Layout text_l1 = new Pango.Layout(widget.PangoContext); text_l1.FontDescription = Pango.FontDescription.FromString ("Meiryo,Arial 10.5"); text_l1.SetText(text1); Pango.Layout text_l2 = new Pango.Layout(widget.PangoContext); text_l2.FontDescription = Pango.FontDescription.FromString ("Meiryo,MS Gothic,Arial 8"); text_l2.SetText(text2); text_l2.Alignment = Pango.Alignment.Right; Pango.Layout text_l3 = new Pango.Layout(widget.PangoContext); text_l3.Width = Pango.Units.FromPixels(text_area3.Width); text_l3.FontDescription = Pango.FontDescription.FromString ("Meiryo,MS Gothic,Arial 8"); text_l3.Alignment = Pango.Alignment.Right; text_l3.SetText(text3); text_l2.Width = Pango.Units.FromPixels(cell_area.Width-text_l3.Text.Length*8-13); StateType state = flags.HasFlag(CellRendererState.Selected) ? widget.IsFocus ? StateType.Selected : StateType.Active : StateType.Normal; text_l3.SetMarkup("<span color=" + (char)34 + "grey" + (char)34 + ">" + text_l3.Text + "</span>");; window.DrawLayout(widget.Style.TextGC(state), 55, text_area1.Y, text_l1); window.DrawLayout(widget.Style.TextGC(state), 55, text_area2.Y, text_l2); window.DrawLayout(widget.Style.TextGC(state), text_area3.X, text_area3.Y, text_l3); text_l1.Dispose (); text_l2.Dispose (); text_l3.Dispose (); }catch(Exception e){ Console.WriteLine (e); } }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); Resize(allocation); }
public abstract void DrawHeaderBackground(Cairo.Context cr, Gdk.Rectangle alloc);
public abstract void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x);
protected override bool OnKeyPressEvent(Gdk.EventKey evnt) { Item nextItem; // Handle keyboard toolip popup if ((evnt.Key == Gdk.Key.F1 && (evnt.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)) { if (this.SelectedItem != null) { int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0); Gdk.Rectangle rect = GetItemExtends(SelectedItem); ShowTooltip(SelectedItem, 0, rect.X, rect.Bottom - vadjustment); } return(true); } switch (evnt.Key) { case Gdk.Key.KP_Enter: case Gdk.Key.Return: if (this.SelectedItem != null) { this.OnActivateSelectedItem(EventArgs.Empty); } return(true); case Gdk.Key.KP_Up: case Gdk.Key.Up: if (this.listMode || this.SelectedItem is Category) { this.SelectedItem = GetPrevItem(this.SelectedItem); } else { nextItem = GetItemAbove(this.SelectedItem); this.SelectedItem = nextItem != this.SelectedItem ? nextItem : GetCategory(this.SelectedItem); } this.QueueDraw(); return(true); case Gdk.Key.KP_Down: case Gdk.Key.Down: if (this.listMode || this.SelectedItem is Category) { this.SelectedItem = GetNextItem(this.SelectedItem); } else { nextItem = GetItemBelow(this.SelectedItem); if (nextItem == this.SelectedItem) { Category category = GetCategory(this.SelectedItem); nextItem = GetNextCategory(category); if (nextItem == category) { nextItem = this.SelectedItem; } } this.SelectedItem = nextItem; } this.QueueDraw(); return(true); case Gdk.Key.KP_Left: case Gdk.Key.Left: if (this.SelectedItem is Category) { SetCategoryExpanded((Category)this.SelectedItem, false); } else { if (this.listMode) { this.SelectedItem = GetCategory(this.SelectedItem); } else { this.SelectedItem = GetItemLeft(this.SelectedItem); } } this.QueueDraw(); return(true); case Gdk.Key.KP_Right: case Gdk.Key.Right: if (this.SelectedItem is Category) { Category selectedCategory = ((Category)this.SelectedItem); if (selectedCategory.IsExpanded) { if (selectedCategory.ItemCount > 0) { this.SelectedItem = selectedCategory.Items[0]; } } else { SetCategoryExpanded(selectedCategory, true); } } else { if (this.listMode) { // nothing } else { this.SelectedItem = GetItemRight(this.SelectedItem); } } this.QueueDraw(); return(true); } return(false); }
protected override bool OnExposeEvent(EventExpose evnt) { Gdk.Rectangle focusRect = new Gdk.Rectangle(0, 0, 0, 0); using (var ctx = Gdk.CairoHelper.Create(GdkWindow)) { int index = 0; ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height); ctx.SetSourceColor(Styles.BreadcrumbBackgroundColor.ToCairoColor()); ctx.Fill(); if (widths == null) { return(true); } // Calculate the total required with, and the reduction to be applied in case it doesn't fit the available space bool widthReduced; var currentWidths = GetCurrentWidths(out widthReduced); // Render the paths int textTopPadding = topPadding + (height - textHeight) / 2; int xpos = leftPadding, ypos = topPadding; for (int i = 0; i < leftPath.Length; i++, index++) { bool last = i == leftPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i]; int x = xpos; xpos += itemWidth; SetAccessibilityFrame(leftPath [i], x, itemWidth); if (hoverIndex >= 0 && hoverIndex < Path.Length && leftPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } if (index == focusedPathIndex) { focusRect = new Gdk.Rectangle(x - padding, 0, itemWidth + (padding * 2), 0); } int textOffset = 0; if (leftPath [i].DarkIcon != null) { int iy = (height - (int)leftPath [i].DarkIcon.Height) / 2 + topPadding; ctx.DrawImage(this, leftPath [i].DarkIcon, x, iy); textOffset += (int)leftPath [i].DarkIcon.Width + iconSpacing; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); layout.SetMarkup(GetFirstLineFromMarkup(leftPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); if (!last) { xpos += arrowLeftPadding; if (leftPath [i].IsPathEnd) { Style.PaintVline(Style, GdkWindow, State, evnt.Area, this, "", ypos, ypos + height, xpos - arrowSize / 2); } else { int arrowH = Math.Min(height, arrowSize); int arrowY = ypos + (height - arrowH) / 2; DrawPathSeparator(ctx, xpos, arrowY, arrowH); } xpos += arrowSize + arrowRightPadding; } } int xposRight = Allocation.Width - rightPadding; for (int i = 0; i < rightPath.Length; i++, index++) { // bool last = i == rightPath.Length - 1; // Reduce the item size when required int itemWidth = currentWidths [i + leftPath.Length]; xposRight -= itemWidth; xposRight -= arrowSize; int x = xposRight; SetAccessibilityFrame(rightPath [i], x, itemWidth); if (hoverIndex >= 0 && hoverIndex < Path.Length && rightPath [i] == Path [hoverIndex] && (menuVisible || pressed || hovering)) { DrawButtonBorder(ctx, x - padding, itemWidth + padding + padding); } if (index == focusedPathIndex) { focusRect = new Gdk.Rectangle(x - padding, 0, itemWidth + (padding * 2), 0); } int textOffset = 0; if (rightPath [i].DarkIcon != null) { ctx.DrawImage(this, rightPath [i].DarkIcon, x, ypos); textOffset += (int)rightPath [i].DarkIcon.Width + padding; } layout.Attributes = (i == activeIndex) ? boldAtts : null; layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11); layout.SetMarkup(GetFirstLineFromMarkup(rightPath [i].Markup)); ctx.Save(); // If size is being reduced, ellipsize it bool showText = true; if (widthReduced) { int w = itemWidth - textOffset; if (w > 0) { ctx.Rectangle(x + textOffset, textTopPadding, w, height); ctx.Clip(); } else { showText = false; } } else { layout.Width = -1; } if (showText) { // Text ctx.SetSourceColor(Styles.BreadcrumbTextColor.ToCairoColor()); ctx.MoveTo(x + textOffset, textTopPadding); Pango.CairoHelper.ShowLayout(ctx, layout); } ctx.Restore(); } ctx.MoveTo(0, Allocation.Height - 0.5); ctx.RelLineTo(Allocation.Width, 0); ctx.SetSourceColor(Styles.BreadcrumbBottomBorderColor.ToCairoColor()); ctx.LineWidth = 1; ctx.Stroke(); if (HasFocus) { int focusY = topPadding - buttonPadding; int focusHeight = Allocation.Height - topPadding - bottomPadding + buttonPadding * 2; Gtk.Style.PaintFocus(Style, GdkWindow, State, Allocation, this, "label", focusRect.X, focusY, focusRect.Width, focusHeight); } } return(true); }
public static Gdk.Point Center(this Gdk.Rectangle rect) { return(new Gdk.Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2)); }
public void Draw(Gdk.Rectangle cliprect) { if (surface == null) { return; } Surface sm = surface; Surface st = (surfaceTop != null)?(surfaceTop):(surface); Surface sb = (surfaceBottom != null)?(surfaceBottom):(surface); // TODO: // * Clip images that are partially outside the sector to make the edges // "neat"? How? // This is quite a hack, since we can't get our parent sector. // However we will only draw if we are the current sector, thus // we get the size from the Application. Gdk.Rectangle sectorbounds = new Gdk.Rectangle(0, 0, (int)Application.EditorApplication.CurrentSector.Width * 32, (int)Application.EditorApplication.CurrentSector.Height * 32); int minX; int maxX; if (Alignment == Alignments.none) { // Calc min and max *tiles*, including one *tile* overlap on both sides. minX = -((int)this.X / (int)st.Width) - 1; // Fix rounding with integer division... if (this.X > 0) { minX--; } maxX = Math.Abs(sectorbounds.Width - (int)this.X) / (int)st.Width; int minY = -((int)this.Y / (int)st.Height) - 1; // Fix rounding with integer division... if (this.Y > 0) { minY--; } int maxY = -1; //tile position 0 belongs to middle surface for (int tileX = minX; tileX <= maxX; tileX++) { for (int tileY = minY; tileY <= maxY; tileY++) { st.Draw(new Vector(X + st.Width * tileX, Y + st.Height * tileY)); } } } // Calc min and max *tiles*, including one *tile* overlap on both sides. minX = -((int)this.X / (int)sm.Width) - 1; // Fix rounding with integer division... if (this.X > 0) { minX--; } maxX = Math.Abs(sectorbounds.Width - (int)this.X) / (int)sm.Width; for (int tileX = minX; tileX <= maxX; tileX++) { sm.Draw(new Vector(X + sm.Width * tileX, Y)); } if (Alignment == Alignments.none) { // Calc min and max *tiles*, including one *tile* overlap on both sides. minX = -((int)this.X / (int)sb.Width) - 1; // Fix rounding with integer division... if (this.X > 0) { minX--; } maxX = Math.Abs(sectorbounds.Width - (int)this.X) / (int)sb.Width; int maxY = Math.Abs(sectorbounds.Height - (int)this.Y - (int)sm.Height) / (int)sb.Height; for (int tileX = minX; tileX <= maxX; tileX++) { for (int tileY = 0; tileY <= maxY; tileY++) { sb.Draw(new Vector(X + sb.Width * tileX, Y + sm.Height + sb.Height * tileY)); } } } }
public void SetAllocation(Gtk.Widget w, Gdk.Rectangle rect) { children [w] = rect; QueueResize(); }
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 || source is SourceManager.GroupSource) { return; } view = widget as SourceView; bool selected = view != null && view.Selection.IterIsSelected(iter); StateType state = RendererStateToWidgetState(widget, flags); RenderSelection(drawable, background_area, 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; int img_padding = 6; int expander_icon_spacing = 3; int x = cell_area.X; bool np_etc = (source.Order + Depth * 100) < 40; if (!np_etc) { x += Depth * img_padding + (int)Xpad; } else { // Don't indent NowPlaying and Play Queue as much x += Math.Max(0, (int)Xpad - 2); } Gdk.GC main_gc = widget.Style.TextGC(state); // Draw the expander if the source has children double exp_h = (cell_area.Height - 2.0 * Ypad) / 3.2; double exp_w = exp_h * 1.6; if (view != null && view.Cr != null && source.Children != null && source.Children.Count > 0) { var r = new Gdk.Rectangle(x, cell_area.Y + (int)((cell_area.Height - exp_h) / 2.0), (int)exp_w, (int)exp_h); view.Theme.DrawArrow(view.Cr, r, source.Expanded ? Math.PI / 2.0 : 0.0); } if (!np_etc) { x += (int)exp_w; x += 2; // a little spacing after the expander expander_right_x = x; } // Draw icon Pixbuf icon = SourceIconResolver.ResolveIcon(source, RowHeight); bool dispose_icon = false; 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"); dispose_icon = true; icon_source.Dispose(); } if (icon != null) { x += expander_icon_spacing; drawable.DrawPixbuf(main_gc, icon, 0, 0, x, Middle(cell_area, icon.Height), icon.Width, icon.Height, RgbDither.None, 0, 0); x += icon.Width; if (dispose_icon) { icon.Dispose(); } } // Setup font info for the title/count, and see if we should show the count bool hide_count = source.EnabledCount <= 0 || source.Properties.Get <bool> ("SourceView.HideCount"); 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_count = true; } Pango.Layout title_layout = new Pango.Layout(widget.PangoContext); Pango.Layout count_layout = null; // If we have a count to draw, setup its fonts and see how wide it is to see if we have room if (!hide_count) { count_layout = new Pango.Layout(widget.PangoContext); count_layout.FontDescription = fd; count_layout.SetMarkup(String.Format("<span size=\"small\">{0}</span>", source.EnabledCount)); count_layout.GetPixelSize(out count_layout_width, out count_layout_height); } // Hide the count if the title has no space max_title_layout_width = cell_area.Width - x - count_layout_width;//(icon == null ? 0 : icon.Width) - count_layout_width - 10; if (!hide_count && max_title_layout_width <= 0) { hide_count = true; } // Draw the source Name 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); x += img_padding; drawable.DrawLayout(main_gc, x, Middle(cell_area, title_layout_height), title_layout); title_layout.Dispose(); // Draw the count if (!hide_count) { if (view != null && view.Cr != null) { view.Cr.Color = state == StateType.Normal || (view != null && state == StateType.Prelight) ? view.Theme.TextMidColor : view.Theme.Colors.GetWidgetColor(GtkColorClass.Text, state); view.Cr.MoveTo( cell_area.X + cell_area.Width - count_layout_width - 2, cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0); PangoCairoHelper.ShowLayout(view.Cr, count_layout); } count_layout.Dispose(); } fd.Dispose(); }
public abstract void DrawFrameBorderFocused(Cairo.Context cr, Gdk.Rectangle alloc);
private int Middle(Gdk.Rectangle area, int height) { return(area.Y + (int)Math.Round((double)(area.Height - height) / 2.0, MidpointRounding.AwayFromZero)); }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); this.AllocatedWidth = allocation.Width; this.AllocatedHeight = allocation.Height; }
protected override bool OnExposeEvent(Gdk.EventExpose ev) { Gdk.Window win = ev.Window; Gdk.Rectangle rect = ev.Area; Gdk.GC gc = this.Style.BaseGC(StateType.Normal); lock (this.drawLock){ if (this.toDraw != null) { //Raise events for the symbols... bool gotSymbol = false; //See if there's a new symbol if (this.symbols != null) { foreach (Symbol s in this.symbols) { if (s.Count > 0 && this.data != s.ToString()) { this.data = s.ToString(); //Don't raise it inside the expose event :) GLib.IdleHandler raiser = delegate(){ if (this.BarScanned != null) { this.BarScanned(this, new BarScannedArgs(s)); } return(false); }; GLib.Idle.Add(raiser); gotSymbol = true; } } } //Avoid beeping more than once.. if (gotSymbol) { if (!this.Mute) { System.Media.SystemSounds.Beep.Play(); } if (this.overlayingFrames == 0) { GLib.TimeoutHandler hdl = delegate(){ this.QueueDraw(); this.overlayingFrames -= 1; return(this.overlayingFrames > 0); }; GLib.Timeout.Add(35, hdl); } //Start drawing an overlay this.overlayingFrames = overlayFrameCount; } this.symbols = null; //Symbols have been handled //See if we want to request a resize if (this.reqHeight != this.toDrawHeight || this.reqWidth != this.toDrawWidth) { this.reqHeight = this.toDrawHeight; this.reqWidth = this.toDrawWidth; this.QueueResize(); } //Draw the gray image int w = Math.Min(rect.Size.Width, this.toDrawWidth); int h = Math.Min(rect.Size.Height, this.toDrawHeight); //Draw the image win.DrawGrayImage(gc, 0, 0, w, h, Gdk.RgbDither.Normal, this.toDraw, this.toDrawWidth); if (this.overlayingFrames > 0) { Pixbuf overlay_tmp = overlay; if (this.overlay.Width > w * 0.8 || this.overlay.Height > h * 0.8) { int overlayMaxSize = Math.Min(h * 80 / 100, w * 80 / 100); overlay_tmp = overlay.ScaleSimple(overlayMaxSize, overlayMaxSize, InterpType.Bilinear); } w = Math.Min(this.toDrawWidth, (int)overlay_tmp.Width); h = Math.Min(this.toDrawHeight, (int)overlay_tmp.Height); using (Gdk.Pixbuf pix = new Pixbuf(Colorspace.Rgb, true, 8, w, h)){ pix.Fill(0x00000000); //Fill with invisibility :) overlay_tmp.Composite(pix, 0, 0, w, h, 0, 0, 1, 1, InterpType.Bilinear, 255 / 35 * this.overlayingFrames); win.DrawPixbuf(gc, pix, 0, 0, (this.toDrawWidth - w) / 2, (this.toDrawHeight - h) / 2, w, h, RgbDither.Normal, 0, 0); } } } else { win.DrawRectangle(gc, true, rect); int w = Math.Min(this.toDrawWidth, (int)this.sourceMissing.Width); int h = Math.Min(this.toDrawHeight, (int)this.sourceMissing.Height); Rectangle img = new Rectangle((this.toDrawWidth - w) / 2, (this.toDrawHeight - h) / 2, w, h); Rectangle target = Rectangle.Intersect(img, rect); if (target != Rectangle.Zero) { win.DrawPixbuf(gc, this.sourceMissing, Math.Max(target.X - img.X, 0), Math.Max(target.Y - img.Y, 0), target.X, target.Y, target.Width, target.Height, RgbDither.Normal, 0, 0); } } } return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Cairo.Context cr = Gdk.CairoHelper.Create(e.Window); Gdk.Rectangle area = e.Area; if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage)) { Pango.Layout messageLayout = new Pango.Layout(this.PangoContext); messageLayout.Alignment = Pango.Alignment.Center; messageLayout.Width = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale); if (!string.IsNullOrEmpty(CustomMessage)) { messageLayout.SetText(CustomMessage); } else { messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document.")); } cr.MoveTo(Allocation.Width * 1 / 6, 12); cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); Pango.CairoHelper.ShowLayout(cr, messageLayout); messageLayout.Dispose(); ((IDisposable)cr).Dispose(); return(true); } var backColor = Style.Base(StateType.Normal).ToCairoColor(); cr.SetSourceColor(backColor); cr.Rectangle(area.X, area.Y, area.Width, area.Height); cr.Fill(); int xpos = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0); int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0); int ypos = -vadjustment; Category lastCategory = null; int lastCategoryYpos = 0; cr.LineWidth = 1; Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) { const int foldSegmentHeight = 8; ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension))) { return(true); } cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.SetSourceColor(Ide.Gui.Styles.PadCategoryBackgroundColor.ToCairoColor()); cr.Fill(); if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand) { cr.MoveTo(xpos, ypos + 0.5); cr.LineTo(itemDimension.Width, ypos + 0.5); } cr.MoveTo(0, ypos + itemDimension.Height - 0.5); cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5); cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor()); cr.Stroke(); headerLayout.SetMarkup(category.Text); int width, height; cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryLabelColor.ToCairoColor()); layout.GetPixelSize(out width, out height); cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2))); Pango.CairoHelper.ShowLayout(cr, headerLayout); var img = category.IsExpanded ? discloseUp : discloseDown; cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2)); lastCategory = category; lastCategoryYpos = ypos + itemDimension.Height; return(true); }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) { if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension))) { return(true); } var icon = item.Icon; if (!icon.HasFixedSize) { var maxIconSize = Math.Min(itemDimension.Width, itemDimension.Height); var fittingIconSize = maxIconSize > 32 ? Xwt.IconSize.Large : maxIconSize > 16 ? Xwt.IconSize.Medium : Xwt.IconSize.Small; icon = item.Icon.WithSize(fittingIconSize); } if (item == SelectedItem) { icon = icon.WithStyles("sel"); cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.Fill(); } if (listMode || !curCategory.CanIconizeItems) { cr.DrawImage(this, icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - icon.Height) / 2)); layout.SetMarkup(item.Text); int width, height; layout.GetPixelSize(out width, out height); cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor()); cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2))); Pango.CairoHelper.ShowLayout(cr, layout); } else { cr.DrawImage(this, icon, xpos + Math.Round((itemDimension.Width - icon.Width) / 2), ypos + Math.Round((itemDimension.Height - icon.Height) / 2)); } if (item == mouseOverItem) { cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor()); cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1); cr.Stroke(); } return(true); }); ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (lastCategory != null && lastCategory.AnimatingExpand) { // Closing line when animating the last group of the toolbox cr.MoveTo(area.X, ypos + 0.5); cr.RelLineTo(area.Width, 0); cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor()); cr.Stroke(); } ((IDisposable)cr).Dispose(); return(true); }
public abstract void DrawArrow(Cairo.Context cr, Gdk.Rectangle alloc, SortType type);
void Resize(Gdk.Rectangle alloc) { textEditor.MoveTopLevelWidget(this, (textEditor.Allocation.Width - alloc.Width) / 2, textEditor.Allocation.Height - alloc.Height - 8); }
public void DrawFrame(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color) { DrawFrameBackground(cr, alloc, color); DrawFrameBorder(cr, alloc); }
public abstract void DrawListBackground(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
private void ResizeProjectionMatrix(Gdk.Rectangle rect) { GL.Viewport(0, 0, rect.Width, rect.Height); ShadersCommonProperties.projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(cam.FieldOfView, rect.Width / (float)rect.Height, 0.01f, 500f); }
void ProcessExpandAnimation(Cairo.Context cr, Category lastCategory, int lastCategoryYpos, Cairo.Color backColor, Gdk.Rectangle area, ref int ypos) { if (lastCategory != null && lastCategory.AnimatingExpand) { int newypos = lastCategory.IsExpanded ? lastCategoryYpos + lastCategory.AnimationHeight : ypos + lastCategory.AnimationHeight; if (newypos < lastCategoryYpos) { newypos = lastCategoryYpos; StopExpandAnimation(lastCategory); } if (newypos > ypos) { newypos = ypos; StopExpandAnimation(lastCategory); } // Clear the area where the category will be drawn since it will be // drawn over the items being hidden/shown cr.SetSourceColor(backColor); cr.Rectangle(area.X, newypos, area.Width, ypos - lastCategoryYpos); cr.Fill(); ypos = newypos; } }
public abstract void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
static void SizeAllocatedHandler(object obj, SizeAllocatedArgs args) { rect = args.Allocation; }
public void DrawColumnHighlight(Cairo.Context cr, Gdk.Rectangle alloc) { DrawColumnHighlight(cr, alloc, colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected)); }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); SetAdjustments(false); }
public void DrawListBackground(Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor) { DrawListBackground(cr, alloc, baseColor ? colors.GetWidgetColor(GtkColorClass.Base, StateType.Normal) : colors.GetWidgetColor(GtkColorClass.Background, StateType.Normal)); }
protected override void OnSizeAllocated(Gdk.Rectangle allocation) { base.OnSizeAllocated(allocation); box.SizeRequest(); box.Allocation = allocation; }
public abstract void DrawColumnHeaderFocus(Cairo.Context cr, Gdk.Rectangle alloc);
public override CellEditable StartEditing(Gdk.Event ev, Widget widget, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags) { if (property == null || editorCell == null || !sensitive) { return(null); } StateType state = GetState(flags); EditSession session = editorCell.StartEditing(cell_area, state); if (session == null) { return(null); } Gtk.Widget propEditor = (Gtk.Widget)session.Editor; propEditor.Show(); HackEntry e = new HackEntry(session, propEditor); e.Show(); session.Changed += delegate { ((InternalTree)widget).PropertyTree.NotifyChanged(); }; TreeIter it; ((InternalTree)widget).Model.GetIterFromString(out it, path); ((InternalTree)widget).EditingIter = it; return(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); 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); // 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; 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.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); } }
/// <summary> /// Create a cursor icon with a shape that visually represents the tool's thickness. /// </summary> /// <param name="imgName">A string containing the name of the tool's icon image to use.</param> /// <param name="shape">The shape to draw.</param> /// <param name="shapeWidth">The width of the shape.</param> /// <param name="imgToShapeX">The horizontal distance between the image's top-left corner and the shape center.</param> /// <param name="imgToShapeY">The verical distance between the image's top-left corner and the shape center.</param> /// <param name="shapeX">The X position in the returned Pixbuf that will be the center of the shape.</param> /// <param name="shapeY">The Y position in the returned Pixbuf that will be the center of the shape.</param> /// <returns>The new cursor icon with an shape that represents the tool's thickness.</returns> protected Gdk.Pixbuf CreateIconWithShape(string imgName, CursorShape shape, int shapeWidth, int imgToShapeX, int imgToShapeY, out int shapeX, out int shapeY) { Gdk.Pixbuf img = PintaCore.Resources.GetIcon(imgName); double zoom = 1d; if (PintaCore.Workspace.HasOpenDocuments) { zoom = Math.Min(30d, PintaCore.Workspace.ActiveDocument.Workspace.Scale); } shapeWidth = (int)Math.Min(800d, ((double)shapeWidth) * zoom); int halfOfShapeWidth = shapeWidth / 2; // Calculate bounding boxes around the both image and shape // relative to the image top-left corner. Gdk.Rectangle imgBBox = new Gdk.Rectangle(0, 0, img.Width, img.Height); Gdk.Rectangle shapeBBox = new Gdk.Rectangle( imgToShapeX - halfOfShapeWidth, imgToShapeY - halfOfShapeWidth, shapeWidth, shapeWidth); // Inflate shape bounding box to allow for anti-aliasing shapeBBox.Inflate(2, 2); // To determine required size of icon, // find union of the image and shape bounding boxes // (still relative to image top-left corner) Gdk.Rectangle iconBBox = imgBBox.Union(shapeBBox); // Image top-left corner in icon co-ordinates int imgX = imgBBox.Left - iconBBox.Left; int imgY = imgBBox.Top - iconBBox.Top; // Shape center point in icon co-ordinates shapeX = imgToShapeX - iconBBox.Left; shapeY = imgToShapeY - iconBBox.Top; using (ImageSurface i = new ImageSurface(Format.ARGB32, iconBBox.Width, iconBBox.Height)) { using (Context g = new Context(i)) { // Don't show shape if shapeWidth less than 3, if (shapeWidth > 3) { int diam = Math.Max(1, shapeWidth - 2); Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth, shapeY - halfOfShapeWidth, diam, diam); Cairo.Color outerColor = new Cairo.Color(255, 255, 255, 0.75); Cairo.Color innerColor = new Cairo.Color(0, 0, 0); switch (shape) { case CursorShape.Ellipse: g.DrawEllipse(shapeRect, outerColor, 2); shapeRect = shapeRect.Inflate(-1, -1); g.DrawEllipse(shapeRect, innerColor, 1); break; case CursorShape.Rectangle: g.DrawRectangle(shapeRect, outerColor, 1); shapeRect = shapeRect.Inflate(-1, -1); g.DrawRectangle(shapeRect, innerColor, 1); break; } } // Draw the image g.DrawPixbuf(img, new Cairo.Point(imgX, imgY)); } return(CairoExtensions.ToPixbuf(i)); } }