private void Draw(Cairo.Context context, bool needClip) { if (needClip) { context.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); context.Clip(); } foreach (var entry in this.entries) { if (entry.horizontalStretchFactor != 0 || entry.verticalStretchFactor != 0) { context.FillRectangle(entry.rect, CairoEx.ColorLightBlue); context.StrokeRectangle(entry.rect, CairoEx.ColorBlack); } else { context.FillRectangle(entry.rect, CairoEx.ColorPink); context.StrokeRectangle(entry.rect, CairoEx.ColorBlack); } var innerGroup = entry as Group; if (innerGroup != null) { innerGroup.Draw(context, needClip); } } if (needClip) { context.ResetClip(); } }
/// <summary> /// Method which paints cells /// </summary> /// <param name="evnt"> /// Expose event parameters <see cref="Gdk.EventExpose"/> /// </param> /// <param name="aContext"> /// Cairo context <see cref="Cairo.Context"/> /// </param> protected virtual void PaintCells(Gdk.EventExpose evnt, Gdk.Drawable aDrawable, Cairo.Context aContext, CellRectangle aArea) { if (box.IsVisible == false) { return; } System.Console.WriteLine("Paint"); box.Area.Clip(aContext); // aContext.Rectangle (box.Area); // aContext.Clip(); // Cairo.Rectangle cliprect = new Cairo.Rectangle (0, 0, Allocation.Width, Allocation.Height); CellRectangle cliprect = new CellRectangle(evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height); // box.Paint (evnt, aContext, cliprect, box.Area); // box.Paint (new CellExposeEventArgs (evnt, aContext, evnt.Window, cliprect, box.Area)); CellExposeEventArgs args = new CellExposeEventArgs(evnt, aContext, aDrawable, cliprect, box.Area); args.WidgetInRenderer = IsCellRenderer; args.Widget = this; args.ForceRecalculation = true; box.Arguments.Start(CellAction.Paint, args); box.Paint(args); box.Arguments.Stop(); args.Disconnect(); args = null; aContext.ResetClip(); }
/// <summary> /// Pushes a clip rectange. /// </summary> /// <param name="clip">The clip rectangle.</param> /// <returns>A disposable used to undo the clip rectangle.</returns> public IDisposable PushClip(Rect clip) { _context.Rectangle(clip.ToCairo()); _context.Clip(); return(Disposable.Create(() => _context.ResetClip())); }
private void PaintHeader(Rectangle clip) { Rectangle rect = header_rendering_alloc; rect.Height += Theme.BorderWidth; clip.Intersect(rect); cairo_context.Rectangle(clip.X, clip.Y, clip.Width, clip.Height); cairo_context.Clip(); Theme.DrawHeaderBackground(cairo_context, header_rendering_alloc); Rectangle cell_area = new Rectangle(); cell_area.Y = header_rendering_alloc.Y; cell_area.Height = header_rendering_alloc.Height; cell_context.Clip = clip; cell_context.Sensitive = true; cell_context.TextAsForeground = true; for (int ci = 0; ci < column_cache.Length; ci++) { if (!column_cache [ci].Column.Visible) { continue; } if (pressed_column_is_dragging && pressed_column_index == ci) { continue; } cell_area.X = column_cache [ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - (int)hadjustment.Value; cell_area.Width = column_cache [ci].Width; PaintHeaderCell(cell_area, ci, false); } if (pressed_column_is_dragging && pressed_column_index >= 0) { cell_area.X = pressed_column_x_drag + Allocation.X - (int)hadjustment.Value; cell_area.Width = column_cache [pressed_column_index].Width; PaintHeaderCell(cell_area, pressed_column_index, true); } cairo_context.ResetClip(); }
void PaintHeader(Rectangle clip) { var rect = header_rendering_alloc; rect.Height += Theme.BorderWidth; clip.Intersect(rect); cairo_context.Rectangle(clip.X, clip.Y, clip.Width, clip.Height); cairo_context.Clip(); Theme.DrawHeaderBackground(cairo_context, header_rendering_alloc); var cell_area = new Rectangle { Y = header_rendering_alloc.Y, Height = header_rendering_alloc.Height }; cell_context.Clip = clip; cell_context.Opaque = true; cell_context.TextAsForeground = true; bool have_drawn_separator = false; for (int ci = 0; ci < column_cache.Length; ci++) { if (pressed_column_is_dragging && pressed_column_index == ci) { continue; } cell_area.X = column_cache[ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - HadjustmentValue; cell_area.Width = column_cache[ci].Width; PaintHeaderCell(cell_area, ci, false, ref have_drawn_separator); } if (pressed_column_is_dragging && pressed_column_index >= 0) { cell_area.X = pressed_column_x_drag + Allocation.X - HadjustmentValue; cell_area.Width = column_cache[pressed_column_index].Width; PaintHeaderCell(cell_area, pressed_column_index, true, ref have_drawn_separator); } cairo_context.ResetClip(); }
private static void MakeReflection(Cairo.Context context, Cairo.ImageSurface source, int w, int h) { context.ResetClip(); context.SetSourceSurface(source, 2, 2); context.Paint(); double alpha = -0.3; double step = 1.0 / (double)source.Height; context.Translate(0, h); context.Scale(1, -1); context.SetSourceSurface(source, 2, 2); for (int i = 0; i < source.Height; i++) { context.Rectangle(0, i + 2, w, 1); context.Clip(); alpha += step; context.PaintWithAlpha(Math.Max(Math.Min(alpha, 0.7), 0.0)); context.ResetClip(); } }
private void PaintView(Cairo.Context cr, Rect clip) { clip.Intersect((Rect)list_rendering_alloc); cr.Rectangle((Cairo.Rectangle)clip); cr.Clip(); cell_context.Clip = (Gdk.Rectangle)clip; cell_context.TextAsForeground = false; selected_rows.Clear(); for (int layout_index = 0; layout_index < ViewLayout.ChildCount; layout_index++) { var layout_child = ViewLayout[layout_index]; var child_allocation = layout_child.Allocation; if (!child_allocation.IntersectsWith(clip) || ViewLayout.GetModelIndex(layout_child) >= Model.Count) { continue; } if (Selection != null && Selection.Contains(ViewLayout.GetModelIndex(layout_child))) { selected_rows.Add(ViewLayout.GetModelIndex(layout_child)); var selection_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Selected)); if (!HasFocus || HeaderFocused) { selection_color = CairoExtensions.ColorShade(selection_color, 1.1); } Theme.DrawRowSelection(cr, (int)child_allocation.X, (int)child_allocation.Y, (int)child_allocation.Width, (int)child_allocation.Height, true, true, selection_color, CairoCorners.All); cell_context.State = StateFlags.Selected; } else { cell_context.State = StateFlags.Normal; } //cr.Save (); //cr.Translate (child_allocation.X, child_allocation.Y); //cr.Rectangle (0, 0, child_allocation.Width, child_allocation.Height); //cr.Clip (); layout_child.Render(cell_context); //cr.Restore (); } cr.ResetClip(); }
void DrawTabs(Pango.Layout la, Gdk.Window win, Gdk.GC gc, Cairo.Context cairo, int currentTab) { int tx = ALeft + Xpad; int ty = ATop + Ypad; float left = 0; for (int i = 0; i < mTabs.Count(); i++) { var t = mTabs.ElementAt(i); int x1 = (int)(tx + left + 0.5f); var cliprect = new Gdk.Rectangle(x1, 0, (int)(t.CurrentWidth + 0.5f), Allocation.Height); gc.ClipRectangle = cliprect; cairo.Rectangle(cliprect.ToCairoRect()); cairo.Clip(); Color color; if (i == ActiveIndex && t.DockItemTitleTab.Active) { color = Style.Background(StateType.Selected); } else if (i == currentTab) { color = Style.Background(StateType.Normal); } else { color = Style.Mid(StateType.Normal); } DrawRectangle(cairo, cliprect.X, cliprect.Y, cliprect.Width, cliprect.Height, color.ToCairo(), true); x1 += space; if (t.Image != null) { win.DrawPixbuf(gc, t.Image, 0, 0, x1, (Allocation.Height - t.Image.Height + Ypad) / 2, -1, -1, Gdk.RgbDither.None, 0, 0); x1 += t.Image.Width; x1 += space; } la.SetMarkup(t.Label); DrawText(win, gc, x1, ty, System.Drawing.Color.Black.ToGdk(), la); left += t.CurrentWidth; gc.ClipRectangle = new Gdk.Rectangle(0, 0, Allocation.Width, Allocation.Height); cairo.ResetClip(); } }
private void PaintHeader(Cairo.Context cr) { Rectangle clip = header_rendering_alloc; clip.Height += Theme.BorderWidth; clip.Intersect(new Gdk.Rectangle(0, 0, Allocation.Width, Allocation.Height)); cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height); cr.Clip(); Theme.DrawHeaderBackground(cr, header_rendering_alloc); Rectangle cell_area = new Rectangle(); cell_area.Y = header_rendering_alloc.Y; cell_area.Height = header_rendering_alloc.Height; cell_context.Clip = clip; cell_context.Opaque = true; cell_context.TextAsForeground = true; bool have_drawn_separator = false; for (int ci = 0; ci < column_cache.Length; ci++) { if (pressed_column_is_dragging && pressed_column_index == ci) { continue; } cell_area.X = column_cache[ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - HadjustmentValue; cell_area.Width = column_cache[ci].Width; PaintHeaderCell(cr, cell_area, ci, false, ref have_drawn_separator); } if (pressed_column_is_dragging && pressed_column_index >= 0) { cell_area.X = pressed_column_x_drag - HadjustmentValue; cell_area.Width = column_cache[pressed_column_index].Width; PaintHeaderCell(cr, cell_area, pressed_column_index, true, ref have_drawn_separator); } cr.ResetClip(); }
protected override bool OnDamageEvent(Gdk.EventExpose evnt) { if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped) { return(true); } Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window); context.Context = cr; for (int i = 0; i < evnt.Region.NumRectangles; i++) { var damage = evnt.Region.GetRectangle(i); cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height); cr.Clip(); cr.Translate(Allocation.X, Allocation.Y); canvas_child.Render(context); cr.Translate(-Allocation.X, -Allocation.Y); if (Debug) { cr.LineWidth = 1.0; cr.SetSourceColor(CairoExtensions.RgbToColor( (uint)(rand = rand ?? new Random()).Next(0, 0xffffff))); cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke(); } cr.ResetClip(); } CairoExtensions.DisposeContext(cr); if (fps.Update()) { // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond); } return(true); }
private void PaintView(Cairo.Context cr, Rect clip) { clip.Intersect((Rect)list_rendering_alloc); cr.Rectangle((Cairo.Rectangle)clip); cr.Clip(); cell_context.Clip = (Gdk.Rectangle)clip; cell_context.TextAsForeground = false; selected_rows.Clear(); for (int layout_index = 0; layout_index < ViewLayout.ChildCount; layout_index++) { var layout_child = ViewLayout[layout_index]; var child_allocation = layout_child.Allocation; if (!child_allocation.IntersectsWith(clip) || ViewLayout.GetModelIndex(layout_child) >= Model.Count) { continue; } if (Selection != null && Selection.Contains(ViewLayout.GetModelIndex(layout_child))) { selected_rows.Add(ViewLayout.GetModelIndex(layout_child)); PaintRowSelection(cr, (int)child_allocation.X, (int)child_allocation.Y, (int)child_allocation.Width, (int)child_allocation.Height); cell_context.Selected = true; } else { cell_context.Selected = false; } layout_child.Render(cell_context); } cr.ResetClip(); }
/// <summary> /// Method which paints cells /// </summary> /// <param name="aDrawable"> /// Window drawable <see cref="Gdk.Drawable"/> /// </param> /// <param name="aContext"> /// Cairo context <see cref="Cairo.Context"/> /// </param> /// <param name="aArea"> /// Area <see cref="CellRectangle"/> /// </param> /// <param name="aFlags"> /// Flags <see cref="CellRendererState"/> /// </param> protected virtual void PaintCells(Gdk.Drawable aDrawable, Cairo.Context aContext, CellRectangle aArea, CellRendererState aFlags) { if (box.IsVisible == false) { return; } box.Area.Clip(aContext); CellRectangle cliprect = aArea.Copy(); CellExposeEventArgs args = new CellExposeEventArgs(null, aContext, aDrawable, cliprect, box.Area); args.Widget = MasterWidget; args.Renderer = this; args.Flags = aFlags; args.ForceRecalculation = true; MainBox.Arguments.Start(CellAction.Paint, args); box.Paint(args); MainBox.Arguments.Stop(); args.Disconnect(); args = null; aContext.ResetClip(); }
// Used by the workspace drawing area expose render loop. // Takes care of the clipping. public void RenderLivePreviewLayer(Cairo.Context ctx, double opacity) { if (!IsEnabled) { throw new InvalidOperationException("Tried to render a live preview after live preview has ended."); } // TODO remove seam around selection during live preview. ctx.Save(); if (selection_path != null) { // Paint area outsize of the selection path, with the pre-effect image. var imageSize = PintaCore.Workspace.ImageSize; ctx.Rectangle(0, 0, imageSize.Width, imageSize.Height); ctx.AppendPath(selection_path); ctx.Clip(); ctx.SetSourceSurface(layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y); ctx.PaintWithAlpha(opacity); ctx.ResetClip(); // Paint area inside the selection path, with the post-effect image. ctx.AppendPath(selection_path); ctx.Clip(); ctx.SetSourceSurface(live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y); ctx.PaintWithAlpha(opacity); ctx.AppendPath(selection_path); ctx.FillRule = Cairo.FillRule.EvenOdd; ctx.Clip(); } else { ctx.SetSourceSurface(live_preview_surface, (int)layer.Offset.X, (int)layer.Offset.Y); ctx.PaintWithAlpha(opacity); } ctx.Restore(); }
protected override bool OnDrawn(Cairo.Context cr) { if (canvas_child == null || !canvas_child.Visible || !Visible || !IsMapped) { return(true); } foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles()) { cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height); cr.Clip(); cr.Translate(Allocation.X, Allocation.Y); canvas_child.Render(cr); cr.Translate(-Allocation.X, -Allocation.Y); if (Debug) { cr.LineWidth = 1.0; cr.Color = CairoExtensions.RgbToColor( (uint)(rand = rand ?? new Random()).Next(0, 0xffffff)); cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke(); } cr.ResetClip(); } CairoExtensions.DisposeContext(cr); if (fps.Update()) { // Console.WriteLine ("FPS: {0}", fps.FramesPerSecond); } return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { cr.LineWidth = Math.Max(1.0, widget.Editor.Options.Zoom); cr.Rectangle(leftSpacer, 0, Allocation.Width, Allocation.Height); cr.SetSourceRGB(0.95, 0.95, 0.95); cr.Fill(); int startLine = widget.Editor.YToLine((int)widget.Editor.VAdjustment.Value); double startY = widget.Editor.LineToY(startLine); while (startLine > 1 && startLine < annotations.Count && annotations[startLine - 1] != null && annotations[startLine] != null && annotations[startLine - 1].Revision == annotations[startLine].Revision) { startLine--; startY -= widget.Editor.GetLineHeight(widget.Editor.Document.GetLine(startLine)); } double curY = startY - widget.Editor.VAdjustment.Value; int line = startLine; while (curY < Allocation.Bottom && line <= widget.Editor.LineCount) { double curStart = curY; // widget.JumpOverFoldings (ref line); int lineStart = line; int authorWidth = 0, revisionWidth = 0, dateWidth = 0, h = 16; Annotation ann = line <= annotations.Count ? annotations[line - 1] : null; if (ann != null) { do { widget.JumpOverFoldings(ref line); line++; } while (line <= annotations.Count && annotations[line - 1] != null && annotations[line - 1].Revision == ann.Revision); double nextY = widget.editor.LineToY(line) - widget.editor.VAdjustment.Value; if (highlightAnnotation != null && highlightAnnotation.Revision == ann.Revision && curStart <= highlightPositon && highlightPositon < nextY) { cr.Rectangle(leftSpacer, curStart + cr.LineWidth, Allocation.Width - leftSpacer, nextY - curStart - cr.LineWidth); cr.SetSourceRGB(1, 1, 1); cr.Fill(); } // use a fixed size revision to get a approx. revision width layout.SetText("88888888"); layout.GetPixelSize(out revisionWidth, out h); layout.SetText(TruncRevision(ann.Revision)); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); const int dateRevisionSpacing = 16; if (ann.HasDate) { string dateTime = ann.Date.ToShortDateString(); // use a fixed size date to get a approx. date width layout.SetText(new DateTime(1999, 10, 10).ToShortDateString()); layout.GetPixelSize(out dateWidth, out h); layout.SetText(dateTime); e.Window.DrawLayout(Style.BlackGC, Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing, (int)(curY + (widget.Editor.LineHeight - h) / 2), layout); } using (var authorLayout = PangoUtil.CreateLayout(this)) { var description = Pango.FontDescription.FromString("Tahoma " + (int)(10 * widget.Editor.Options.Zoom)); authorLayout.FontDescription = description; authorLayout.SetText(ann.Author); authorLayout.GetPixelSize(out authorWidth, out h); var maxWidth = Allocation.Width - revisionWidth - margin - revisionWidth - dateRevisionSpacing; /* if (authorWidth > maxWidth) { * int idx = ann.Author.IndexOf ('<'); * if (idx > 0) * authorLayout.SetText (ann.Author.Substring (0, idx) + Environment.NewLine + ann.Author.Substring (idx)); * authorLayout.GetPixelSize (out authorWidth, out h); * }*/ cr.Save(); cr.Rectangle(0, 0, maxWidth, Allocation.Height); cr.Clip(); cr.Translate(leftSpacer + margin, (int)(curY + (widget.Editor.LineHeight - h) / 2)); cr.SetSourceRGB(0, 0, 0); cr.ShowLayout(authorLayout); cr.ResetClip(); cr.Restore(); } curY = nextY; } else { curY += widget.Editor.GetLineHeight(line); line++; widget.JumpOverFoldings(ref line); } if (ann != null && line - lineStart > 1) { string msg = GetCommitMessage(lineStart, false); if (!string.IsNullOrEmpty(msg)) { msg = Revision.FormatMessage(msg); layout.SetText(msg); layout.Width = (int)(Allocation.Width * Pango.Scale.PangoScale); using (var gc = new Gdk.GC(e.Window)) { gc.RgbFgColor = Style.Dark(State); gc.ClipRectangle = new Rectangle(0, (int)curStart, Allocation.Width, (int)(curY - curStart)); e.Window.DrawLayout(gc, (int)(leftSpacer + margin), (int)(curStart + h), layout); } } } cr.Rectangle(0, curStart, leftSpacer, curY - curStart); if (ann != null && ann != locallyModified && !string.IsNullOrEmpty(ann.Author)) { double a; if (ann != null && (maxDate - minDate).TotalHours > 0) { a = 1 - (ann.Date - minDate).TotalHours / (maxDate - minDate).TotalHours; } else { a = 1; } HslColor color = new Cairo.Color(0.90, 0.90, 1); color.L = 0.4 + a / 2; color.S = 1 - a / 2; cr.SetSourceColor(color); } else { cr.SetSourceColor(ann != null ? new Cairo.Color(1, 1, 0) : new Cairo.Color(0.95, 0.95, 0.95)); } cr.Fill(); if (ann != null) { cr.MoveTo(0, curY + 0.5); cr.LineTo(Allocation.Width, curY + 0.5); cr.SetSourceRGB(0.6, 0.6, 0.6); cr.Stroke(); } } } return(true); }
private void Redraw(Cairo.Context cr) { // Clear the background cr.Rectangle(0, 0, Allocation.Width, Allocation.Height); Gdk.CairoHelper.SetSourceColor(cr, Style.Base(State)); cr.Fill(); if (model == null) { if (hadj != null) { hadj.Upper = hadj.Lower = 0; hadj.Change(); } if (vadj != null) { vadj.Upper = 0; vadj.Change(); } return; } if (rows == 0 || cols == 0) { return; } Gdk.Rectangle background_area = cell_size; background_area.Width += padding; background_area.Height += padding; TreeIter iter; if (model.GetIterFirst(out iter)) { do { TreePath path = model.GetPath(iter); int x, y; GetCellPosition(path.Indices[0], out x, out y); if (hadj != null && (x + cell_size.Width < hadj.Value || x > hadj.Value + hadj.PageSize)) { continue; } if (vadj != null && (y + cell_size.Height < vadj.Value || y > vadj.Value + vadj.PageSize)) { continue; } if (data_func != null) { data_func(this, renderer, model, iter); } cell_size.X = x; cell_size.Y = y; if (hadj != null) { cell_size.X -= (int)hadj.Value; } if (vadj != null) { cell_size.Y -= (int)vadj.Value; } background_area.X = cell_size.X - (padding / 2); background_area.Y = cell_size.Y - (padding / 2); cr.Rectangle(background_area.X, background_area.Y, background_area.Width, background_area.Height); cr.Clip(); renderer.Render(cr, this, background_area, cell_size, GetCellState(path)); cr.ResetClip(); } while (model.IterNext(ref iter)); } if (have_rubberband_selection) { int hadj_val = (hadj != null) ? (int)hadj.Value : 0; int vadj_val = (vadj != null) ? (int)vadj.Value : 0; cr.Rectangle(sel_rect.X - hadj_val + 0.5f, sel_rect.Y - vadj_val + 0.5f, sel_rect.Width, sel_rect.Height); Cairo.Color sel_cairo_color = CairoHelper.GetCairoColor(Style.Background(StateType.Selected)); //cr.Color = sel_cairo_color; cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A); cr.LineWidth = 1.0f; cr.StrokePreserve(); sel_cairo_color.A = 0.3f; //cr.Color = sel_cairo_color; cr.SetSourceRGBA(sel_cairo_color.R, sel_cairo_color.G, sel_cairo_color.B, sel_cairo_color.A); cr.Fill(); } }
public void ResetClip(object backend) { Cairo.Context ctx = ((CairoContextBackend)backend).Context; ctx.ResetClip(); }
private void RenderBackground(Cairo.Context cr) { rand = rand ?? new Random(); if (circles == null) { for (int i = 0, n = rand.Next(100, 150); i < n; i++) { circles = circles ?? new Circle[n]; circles[i] = new Circle { X = rand.Next(0, Screen.Width), Y = rand.Next(0, Screen.Height), R = rand.Next(10, 70), A = rand.NextDouble() * 0.08 }; } } Gdk.Rectangle damage = new Gdk.Rectangle(); cr.RenderDamage(damage); //cr.Rectangle (damage.X, damage.Y, damage.Width, damage.Height); //cr.Clip (); cr.Translate(Allocation.X, Allocation.Y); cr.Rectangle(0, 0, Allocation.Width, Allocation.Height); if (render_gradient) { var grad = new Cairo.LinearGradient(0, 0, 0, Allocation.Height); grad.AddColorStop(0.7, CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Prelight))); grad.AddColorStop(1, CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Normal))); cr.SetSource(grad); cr.Fill(); grad.Dispose(); foreach (var circle in circles) { cr.SetSourceColor(new Cairo.Color(0, 0, 0, circle.A)); cr.Arc(circle.X + circle.R, circle.Y + circle.R, circle.R, 0, 2 * Math.PI); cr.Fill(); } } else { cr.SetSourceColor(new Cairo.Color(1, 1, 1)); cr.Fill(); } if (window_decorator != null) { window_decorator.Render(cr); } if (render_debug) { cr.LineWidth = 1.0; cr.SetSourceColor(CairoExtensions.RgbToColor( (uint)rand.Next(0, 0xffffff))); cr.Rectangle(damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke(); } cr.ResetClip(); }
protected override void Redraw(Cairo.Context cr) { // no axes, or have we not been SizeAllocated yet? if (axis_requisitions.Count <= 0) { return; } // remember, Gdk.Rectangle is a ValueType. Gdk.Rectangle alloc = plot_alloc; // render the field style_prov.DrawField(cr, alloc.X, alloc.Y, alloc.Width, alloc.Height); Gdk.Rectangle inner_alloc = alloc; inner_alloc.X += style_prov.FieldLineThickness; inner_alloc.Y += style_prov.FieldLineThickness; inner_alloc.Width -= (style_prov.FieldLineThickness * 2); inner_alloc.Height -= (style_prov.FieldLineThickness * 2); // create an ArrayList of axes for each location ArrayList[] axes_by_location = new ArrayList[4]; foreach (IAxis axis in axes) { if (!axis.Visible) { continue; } ArrayList list = axes_by_location[(int)axis.Location]; if (list == null) { list = new ArrayList(); } list.Add(axis); axes_by_location[(int)axis.Location] = list; } for (int i = 0; i < 4; i++) { int x = 0, y = 0; AxisLocation l = (AxisLocation)i; switch (l) { case AxisLocation.Top: y = alloc.Y; break; case AxisLocation.Bottom: y = alloc.Y + alloc.Height; break; case AxisLocation.Left: x = alloc.X; break; case AxisLocation.Right: x = alloc.X + alloc.Width; break; } ArrayList list = axes_by_location[i]; if (list == null) { continue; } foreach (IAxis axis in list) { if (!axis_requisitions.ContainsKey(axis)) { // hasn't been size requested. we'll get it next redraw continue; } Requisition req = (Requisition)axis_requisitions[axis]; Gdk.Rectangle a = new Gdk.Rectangle(); switch ((AxisLocation)i) { case AxisLocation.Top: a.X = alloc.X; a.Y = y - req.Height; a.Width = alloc.Width; a.Height = req.Height; y -= a.Height; break; case AxisLocation.Bottom: a.X = alloc.X; a.Y = y; a.Width = alloc.Width; a.Height = req.Height; y += a.Height; break; case AxisLocation.Left: a.X = x - req.Width; a.Y = alloc.Y; a.Width = req.Width; a.Height = alloc.Height; x -= a.Width; break; case AxisLocation.Right: a.X = x; a.Y = alloc.Y; a.Width = req.Width; a.Height = alloc.Height; x += a.Width; break; } if (a.Width > 0 && a.Height > 0) { cr.Rectangle(a.X, a.Y, a.Width, a.Height); cr.Clip(); axis.DrawTicks(a, cr); cr.ResetClip(); } if (draw_grid_lines) { cr.Rectangle(inner_alloc.X - 0.5f, inner_alloc.Y - 0.5f, inner_alloc.Width + 0.5f, inner_alloc.Height + 0.5f); cr.Clip(); axis.DrawGridLines(inner_alloc, cr); cr.ResetClip(); } } } // clip drawing to plot_alloc cr.Rectangle(inner_alloc.X - 0.5f, inner_alloc.Y, inner_alloc.Width, inner_alloc.Height); cr.Clip(); // draw all plots foreach (IPlot plot in plots) { plot.SizeAllocate(plot_alloc); plot.Draw(cr); } // draw selection rect if (selection_started) { style_prov.DrawSelectionRectangle(cr, sel_rect.X, sel_rect.Y, sel_rect.Width, sel_rect.Height); } cr.ResetClip(); }
private void PaintList(Cairo.Context cr, Rectangle clip) { if (ChildSize.Height <= 0) { return; } // TODO factor this out? // Render the sort effect to the GdkWindow. if (sort_column_index != -1 && (!pressed_column_is_dragging || pressed_column_index != sort_column_index)) { CachedColumn col = column_cache[sort_column_index]; StyleContext.AddRegion("column", RegionFlags.Sorted); StyleContext.RenderBackground(cr, list_rendering_alloc.X + col.X1 - HadjustmentValue, header_rendering_alloc.Bottom + Theme.BorderWidth, col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2); StyleContext.RemoveRegion("column"); } clip.Intersect(list_rendering_alloc); cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height); cr.Clip(); cell_context.Clip = clip; cell_context.TextAsForeground = false; int vadjustment_value = VadjustmentValue; int first_row = vadjustment_value / ChildSize.Height; int last_row = Math.Min(model.Count, first_row + RowsInView); int offset = list_rendering_alloc.Y - vadjustment_value % ChildSize.Height; Rectangle selected_focus_alloc = Rectangle.Zero; Rectangle single_list_alloc = new Rectangle(); single_list_alloc.X = list_rendering_alloc.X - HadjustmentValue; single_list_alloc.Y = offset; single_list_alloc.Width = list_rendering_alloc.Width + HadjustmentValue; single_list_alloc.Height = ChildSize.Height; int selection_height = 0; int selection_y = 0; selected_rows.Clear(); for (int ri = first_row; ri < last_row; ri++) { if (Selection != null && Selection.Contains(ri)) { if (selection_height == 0) { selection_y = single_list_alloc.Y; } selection_height += single_list_alloc.Height; selected_rows.Add(ri); if (Selection.FocusedIndex == ri) { selected_focus_alloc = single_list_alloc; } } else { StyleContext.AddClass("cell"); if (rules_hint) // TODO: check also gtk_widget_style_get(widget,"allow-rules",&allow_rules,NULL); { StyleContext.AddRegion("row", ri % 2 != 0 ? RegionFlags.Odd : RegionFlags.Even); } StyleContext.RenderBackground(cr, single_list_alloc.X, single_list_alloc.Y, single_list_alloc.Width, single_list_alloc.Height); StyleContext.RemoveRegion("row"); StyleContext.RemoveClass("cell"); PaintReorderLine(cr, ri, single_list_alloc); if (Selection != null && Selection.FocusedIndex == ri && !Selection.Contains(ri) && HasFocus) { CairoCorners corners = CairoCorners.All; if (Selection.Contains(ri - 1)) { corners &= ~(CairoCorners.TopLeft | CairoCorners.TopRight); } if (Selection.Contains(ri + 1)) { corners &= ~(CairoCorners.BottomLeft | CairoCorners.BottomRight); } if (HasFocus && !HeaderFocused) // Cursor out of selection. { Theme.DrawRowCursor(cr, single_list_alloc.X, single_list_alloc.Y, single_list_alloc.Width, single_list_alloc.Height, CairoExtensions.ColorShade(CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetBackgroundColor(StateFlags.Selected)), 0.85)); } } if (selection_height > 0) { StyleContext.AddClass("cell"); var bg_selected_color = StyleContext.GetBackgroundColor(StateFlags.Selected); if (bg_selected_color.Equals(StyleContext.GetBackgroundColor(StateFlags.Normal))) { // see https://bugs.launchpad.net/bugs/1211831 Hyena.Log.Warning("Buggy CSS theme: same background-color for .cell:selected and .cell"); StyleContext.RemoveClass("cell"); bg_selected_color = StyleContext.GetBackgroundColor(StateFlags.Selected); StyleContext.AddClass("cell"); } Cairo.Color selection_color = CairoExtensions.GdkRGBAToCairoColor(bg_selected_color); if (!HasFocus || HeaderFocused) { selection_color = CairoExtensions.ColorShade(selection_color, 1.1); } Theme.DrawRowSelection(cr, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height, true, true, selection_color, CairoCorners.All); StyleContext.RemoveClass("cell"); selection_height = 0; } PaintRow(cr, ri, single_list_alloc, StateFlags.Normal); } single_list_alloc.Y += single_list_alloc.Height; } // In case the user is dragging to the end of the list PaintReorderLine(cr, last_row, single_list_alloc); if (selection_height > 0) { Theme.DrawRowSelection(cr, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height); } if (Selection != null && Selection.Count > 1 && !selected_focus_alloc.Equals(Rectangle.Zero) && HasFocus && !HeaderFocused) // Cursor inside selection. // Use entry to get text color { StyleContext.Save(); StyleContext.AddClass("entry"); Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor(StyleContext.GetColor(StateFlags.Selected)); StyleContext.Restore(); Theme.DrawRowCursor(cr, selected_focus_alloc.X, selected_focus_alloc.Y, selected_focus_alloc.Width, selected_focus_alloc.Height, text_color); } foreach (int ri in selected_rows) { single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height); PaintRow(cr, ri, single_list_alloc, StateFlags.Selected); } cr.ResetClip(); }