public static void ShowAtEdge(this DockySurface self, DockySurface target, PointD point, DockPosition position) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; double x = point.X; double y = point.Y; switch (position) { case DockPosition.Top: x -= self.Width / 2; break; case DockPosition.Left: y -= self.Height / 2; break; case DockPosition.Right: x -= self.Width; y -= self.Height / 2; break; case DockPosition.Bottom: x -= self.Width / 2; y -= self.Height; break; } cr.SetSource(self.Internal, (int)x, (int)y); cr.Paint(); }
protected override void DrawPageOnSurface (int page, DockySurface surface) { DateTime[] months = new DateTime[3]; months [0] = months [1] = months [2] = CalendarStartDate; switch (page) { default: case 0: months [2] = CalendarStartDate.AddMonths (-1); months [1] = CalendarStartDate.AddMonths (1); break; case 1: months [0] = CalendarStartDate.AddMonths (-1); months [2] = CalendarStartDate.AddMonths (1); break; case 2: months [1] = CalendarStartDate.AddMonths (-1); months [0] = CalendarStartDate.AddMonths (1); break; } DrawMonth (surface.Context, months [page]); }
public DockySurface(int width, int height, DockySurface model) : this(width, height) { if (model != null) { EnsureSurfaceModel(model.Internal); } }
public void DrawSlice(DockySurface slice, Gdk.Rectangle area) { // simple case goes here if (area.Width == slice.Width && area.Height == slice.Height) { slice.Internal.Show(Context, area.X, area.Y); return; } int columns = (area.Width / slice.Width) + 1; int rows = (area.Height / slice.Height) + 1; Context.Rectangle(area.X, area.Y, area.Width, area.Height); Context.Clip(); for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { int x = area.X + c * slice.Width; int y = area.Y + r * slice.Height; Context.SetSource(slice.Internal, x, y); Context.Rectangle(x, y, slice.Width, slice.Height); Context.Fill(); } } Context.ResetClip(); }
public static void ShowWithOptions(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; double cos, sin; cos = Math.Cos(rotation); sin = Math.Sin(rotation); Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y); cr.Transform(m); if (zoom != 1) { cr.Scale(zoom, zoom); } cr.SetSource(self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha(opacity); cr.IdentityMatrix(); }
protected override void PaintIconSurface (DockySurface surface) { surface.Context.LineWidth = 1; surface.Context.MoveTo ((surface.Width / 2) - 0.5, 0); surface.Context.LineTo ((surface.Width / 2) - 0.5, surface.Height); RadialGradient rg = new RadialGradient (surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2); rg.AddColorStop (0, new Cairo.Color (1, 1, 1, .5)); rg.AddColorStop (1, new Cairo.Color (1, 1, 1, 0)); surface.Context.Pattern = rg; surface.Context.Stroke (); rg.Destroy (); surface.Context.MoveTo ((surface.Width / 2) + 0.5, 0); surface.Context.LineTo ((surface.Width / 2) + 0.5, surface.Height); rg = new RadialGradient (surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2); rg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.5)); rg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0)); surface.Context.Pattern = rg; surface.Context.Stroke (); rg.Destroy (); }
protected override void PaintIconSurface (DockySurface surface) { if (device == null) return; Context cr = surface.Context; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { layout.FontDescription = new Gtk.Style ().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Alignment = Pango.Alignment.Center; int fontSize = surface.Height / 5; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (fontSize); layout.SetText (device.name); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents (out inkRect, out logicalRect); cr.MoveTo ((surface.Width - logicalRect.Width) / 2, 1); Pango.CairoHelper.LayoutPath (cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color (0, 0, 0, 0.5); cr.StrokePreserve (); cr.Color = new Cairo.Color (1, 1, 1, 0.8); cr.Fill (); layout.FontDescription.Dispose (); layout.Context.Dispose (); } }
public static void ShowAsReflection(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity, double height, DockPosition position) { if (target == null) { throw new ArgumentNullException("target"); } Cairo.Context cr = target.Context; switch (position) { case DockPosition.Left: point.X -= self.Width * zoom + height; break; case DockPosition.Top: point.Y -= self.Height * zoom + height; break; case DockPosition.Right: point.X += self.Width * zoom + height; break; case DockPosition.Bottom: point.Y += self.Height * zoom + height; break; } double cos, sin; cos = Math.Cos(rotation); sin = Math.Sin(rotation); Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y); cr.Transform(m); if (zoom != 1) { cr.Scale(zoom, zoom); } if (position == DockPosition.Left || position == DockPosition.Right) { cr.Scale(-1, 1); } else { cr.Scale(1, -1); } cr.SetSource(self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha(opacity * .3); cr.IdentityMatrix(); }
public DockySurface CreateSlice(Gdk.Rectangle area) { DockySurface result = new DockySurface(area.Width, area.Height, this); Internal.Show(result.Context, -area.X, -area.Y); return(result); }
public ProxyMenuItem (AbstractDockItem item) : base () { this.item = item; Bold = false; Text = item.HoverText; Disabled = false; using (DockySurface surface = new DockySurface (ICON_SIZE, ICON_SIZE)) { ForcePixbuf = item.IconSurface (surface, ICON_SIZE, ICON_SIZE, 0).LoadToPixbuf (); } Clicked += delegate { this.item.Clicked (1, Gdk.ModifierType.None, 0, 0); }; }
public static void ShowAsReflection (this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity, double height, DockPosition position) { if (target == null) throw new ArgumentNullException ("target"); Cairo.Context cr = target.Context; switch (position) { case DockPosition.Left: point.X -= self.Width * zoom + height; break; case DockPosition.Top: point.Y -= self.Height * zoom + height; break; case DockPosition.Right: point.X += self.Width * zoom + height; break; case DockPosition.Bottom: point.Y += self.Height * zoom + height; break; } double cos, sin; cos = Math.Cos (rotation); sin = Math.Sin (rotation); Matrix m = new Matrix (cos, sin, -sin, cos, point.X, point.Y); cr.Transform (m); if (zoom != 1) cr.Scale (zoom, zoom); if (position == DockPosition.Left || position == DockPosition.Right) cr.Scale (-1, 1); else cr.Scale (1, -1); cr.SetSource (self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha (opacity * .3); cr.IdentityMatrix (); }
public DockySurface DeepCopy() { if (disposed) { return(null); } Surface copy = Internal.CreateSimilar(Content.ColorAlpha, Width, Height); using (Cairo.Context cr = new Cairo.Context(copy)) { Internal.Show(cr, 0, 0); (cr.Target as IDisposable).Dispose(); } DockySurface result = new DockySurface(Width, Height); result.Internal = copy; return(result); }
protected override void DrawPageOnSurface (int page, DockySurface surface) { switch (page) { default: case 0: if (IsVertical) DrawVertCurrentCondition (surface.Context); else DrawCurrentCondition (surface.Context); break; case 1: if (IsVertical) DrawVertForecast (surface.Context); else DrawForecast (surface.Context); break; case 2: DrawTempGraph (surface.Context); break; } }
public static void ShowWithOptions (this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity) { if (target == null) throw new ArgumentNullException ("target"); Cairo.Context cr = target.Context; double cos, sin; cos = Math.Cos (rotation); sin = Math.Sin (rotation); Matrix m = new Matrix (cos, sin, -sin, cos, point.X, point.Y); cr.Transform (m); if (zoom != 1) cr.Scale (zoom, zoom); cr.SetSource (self.Internal, -self.Width / 2, -self.Height / 2); cr.PaintWithAlpha (opacity); cr.IdentityMatrix (); }
protected override void PaintIconSurface3d (DockySurface surface, int height) { surface.Context.LineCap = LineCap.Round; surface.Context.LineWidth = 1; // Calculate the line count depending on the available height int num_seps = (int) Math.Round (0.04 * surface.Height + 1.5); for (int i = 1; i <= num_seps; i++) { // Create some perspective illusion: lines are getting closer to eachother at the top double vertOffset = (int) (surface.Height + height * ((double) (num_seps - i) / num_seps - 1)); double offset = 0.8 * (i - 1); surface.Context.Color = new Cairo.Color (1, 1, 1, 0.5); surface.Context.MoveTo (offset, vertOffset + 0.5); surface.Context.LineTo (surface.Width - offset, vertOffset + 0.5); surface.Context.Stroke (); surface.Context.Color = new Cairo.Color (0, 0, 0, 0.5); surface.Context.MoveTo (offset, vertOffset - 0.5); surface.Context.LineTo (surface.Width - offset, vertOffset - 0.5); surface.Context.Stroke (); } }
DockySurface ResetBuffer (DockySurface buffer) { if (buffer != null) buffer.Dispose (); return null; }
void ItemIconChanged (object sender, EventArgs e) { if (icon_surface != null) icon_surface.Dispose (); icon_surface = null; QueueDraw (); }
protected sealed override void PaintSurface (DockySurface surface) { surface.Clear (); lock (buffers) { if (slideCounter > 0 && slideCounter < slideSteps) { double offset = Allocation.Width * Math.Log (slideCounter) / Math.Log (slideSteps); if (MovedLeft) { ShowBuffer (surface, Page, offset - Allocation.Width); ShowBuffer (surface, LastPage, offset); } else { ShowBuffer (surface, Page, Allocation.Width - offset); ShowBuffer (surface, LastPage, -offset); } // fade out the edges during a slide Gradient linpat = new LinearGradient (0, surface.Height / 2, surface.Width, surface.Height / 2); linpat.AddColorStop (0, new Color(1, 1, 1, 1)); linpat.AddColorStop (2 * (double) BUTTON_SIZE / surface.Width, new Color(1, 1, 1, 0)); linpat.AddColorStop (1 - 2 * (double) BUTTON_SIZE / surface.Width, new Color(1, 1, 1, 0)); linpat.AddColorStop (1, new Color(1, 1, 1, 1)); surface.Context.Save (); surface.Context.Operator = Operator.Source; surface.Context.Color = new Cairo.Color (0, 0, 0, 0); surface.Context.Mask (linpat); surface.Context.PaintWithAlpha (0); surface.Context.Restore (); linpat.Destroy (); } else { ShowBuffer (surface, Page, 0); } } // overlay the prev/next arrow buttons if (buttonBuffer != null && (buttonBuffer.Width != surface.Width || buttonBuffer.Height != surface.Height)) ResetButtons (); if (buttonBuffer == null) { buttonBuffer = new DockySurface (surface.Width, surface.Height, surface); DrawButtonsBuffer (); } buttonBuffer.Internal.Show (surface.Context, 0, 0); }
protected override void PaintIconSurface (DockySurface surface) { if (ShowMilitary) HoverText = DateTime.Now.ToString ("ddd, MMM dd HH:mm"); else HoverText = DateTime.Now.ToString ("ddd, MMM dd h:mm tt"); if (!ShowDigital) MakeAnalogIcon (surface.Context, Math.Min (surface.Width, surface.Height)); else if (Square) MakeSquareDigitalIcon (surface); else MakeRectangularDigitalIcon (surface); }
static DockySurface[] GetSlices (DockySurface model) { if (menu_slices != null) return menu_slices; DockySurface main = new DockySurface (TotalWidth, TotalHeight, model); using (Gdk.Pixbuf pixbuf = DockServices.Drawing.LoadIcon (DockServices.Theme.MenuSvg)) { Gdk.CairoHelper.SetSourcePixbuf (main.Context, pixbuf, ShadowSize, ShadowSize); main.Context.Paint (); } Gdk.Rectangle extents; if (ShadowSize > 0) using (DockySurface shadow = main.CreateMask (0, out extents)) { shadow.GaussianBlur (ShadowSize); shadow.Context.Operator = Operator.DestOut; for (int i = 0; i < 4; i++) { shadow.Context.SetSource (main.Internal); shadow.Context.Paint (); } main.Context.Operator = Operator.DestOver; main.Context.SetSource (shadow.Internal); main.Context.PaintWithAlpha (1); main.Context.Operator = Operator.Over; } int middleWidth = TotalWidth - 2 * SliceSize; int middleHeight = TotalHeight - 2 * SliceSize - TailHeight; int tailSliceSize = TailHeight + SliceSize; int tailSideSize = (middleWidth - TailWidth) / 2; DockySurface[] results = new DockySurface[11]; results[(int) Slice.TopLeft] = main.CreateSlice (new Gdk.Rectangle ( 0, 0, SliceSize, SliceSize)); results[(int) Slice.Top] = main.CreateSlice (new Gdk.Rectangle ( SliceSize, 0, middleWidth, SliceSize)); results[(int) Slice.TopRight] = main.CreateSlice (new Gdk.Rectangle ( TotalWidth - SliceSize, 0, SliceSize, SliceSize)); results[(int) Slice.Left] = main.CreateSlice (new Gdk.Rectangle ( 0, SliceSize, SliceSize, middleHeight)); results[(int) Slice.Center] = main.CreateSlice (new Gdk.Rectangle ( SliceSize, SliceSize, middleWidth, middleHeight)); results[(int) Slice.Right] = main.CreateSlice (new Gdk.Rectangle ( TotalWidth - SliceSize, SliceSize, SliceSize, middleHeight)); results[(int) Slice.BottomLeft] = main.CreateSlice (new Gdk.Rectangle ( 0, TotalHeight - tailSliceSize, SliceSize, tailSliceSize)); results[(int) Slice.TailLeft] = main.CreateSlice (new Gdk.Rectangle ( SliceSize, TotalHeight - tailSliceSize, tailSideSize, tailSliceSize)); results[(int) Slice.Tail] = main.CreateSlice (new Gdk.Rectangle ( SliceSize + tailSideSize, TotalHeight - tailSliceSize, TailWidth, tailSliceSize)); results[(int) Slice.TailRight] = main.CreateSlice (new Gdk.Rectangle ( SliceSize + middleWidth - tailSideSize, TotalHeight - tailSliceSize, tailSideSize, tailSliceSize)); results[(int) Slice.BottomRight] = main.CreateSlice (new Gdk.Rectangle ( SliceSize + middleWidth, TotalHeight - tailSliceSize, SliceSize, tailSliceSize)); menu_slices = results; main.Dispose (); return menu_slices; }
void DrawBackground (DockySurface surface) { // This method is just annoying enough to turn into a loop that its hardly worth it DockySurface[] slices = GetSlices (surface); int middle = surface.Width / 2; // left to right int left = 0; int right = surface.Width; int leftMiddle = left + SliceSize; int rightMiddle = right - SliceSize; int leftTailMiddle = middle - (TailWidth / 2) - tailOffset; int rightTailMiddle = middle + (TailWidth / 2) - tailOffset; // keep the tail on the menu if (leftTailMiddle < SliceSize) { leftTailMiddle = SliceSize; rightTailMiddle = leftTailMiddle + TailWidth; } if (rightTailMiddle > right - SliceSize) { rightTailMiddle = right - SliceSize; leftTailMiddle = rightTailMiddle - TailWidth; } // top to bottom int top = 0; int bottom = surface.Height; int topMiddle = top + SliceSize; int bottomMiddle = bottom - (SliceSize + TailHeight); int yTop = top; int yBottom = topMiddle - top; int xLeft = left; int xRight = leftMiddle; surface.DrawSlice (slices[(int) Slice.TopLeft], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = leftMiddle; xRight = rightMiddle; surface.DrawSlice (slices[(int) Slice.Top], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = rightMiddle; xRight = right; surface.DrawSlice (slices[(int) Slice.TopRight], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = left; xRight = leftMiddle; yTop = topMiddle; yBottom = bottomMiddle; surface.DrawSlice (slices[(int) Slice.Left], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = leftMiddle; xRight = rightMiddle; surface.DrawSlice (slices[(int) Slice.Center], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = rightMiddle; xRight = right; surface.DrawSlice (slices[(int) Slice.Right], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = left; xRight = leftMiddle; yTop = bottomMiddle; yBottom = bottom; surface.DrawSlice (slices[(int) Slice.BottomLeft], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = leftMiddle; xRight = leftTailMiddle; surface.DrawSlice (slices[(int) Slice.TailLeft], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = leftTailMiddle; xRight = rightTailMiddle; surface.DrawSlice (slices[(int) Slice.Tail], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = rightTailMiddle; xRight = rightMiddle; surface.DrawSlice (slices[(int) Slice.TailRight], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); xLeft = rightMiddle; xRight = right; surface.DrawSlice (slices[(int) Slice.BottomRight], new Gdk.Rectangle ( xLeft, yTop, xRight - xLeft, yBottom - yTop)); }
protected override DockySurface CreateIconBuffer (DockySurface model, int size) { if (Square) return base.CreateIconBuffer (model, size); else return new DockySurface (2 * size, size, model); }
protected override bool OnExposeEvent (EventExpose evnt) { if (!IsRealized) return false; Gdk.Rectangle allocation = Allocation; int pixbufSize = allocation.Height - IconBuffer * 2; if (item.ShowIcons && (icon_surface == null || (icon_surface.Height != pixbufSize && icon_surface.Width != pixbufSize))) { if (icon_surface != null) icon_surface.Dispose (); if (emblem_surface != null) emblem_surface.Dispose (); if (item.ForcePixbuf == null) icon_surface = LoadIcon (item.Icon, pixbufSize); else icon_surface = LoadIcon (item.ForcePixbuf, pixbufSize); if (!string.IsNullOrEmpty (item.Emblem)) emblem_surface = LoadIcon (item.Emblem, pixbufSize); } using (Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window)) { if (Selected && !item.Disabled) { cr.Rectangle (allocation.X, allocation.Y, allocation.Width, allocation.Height); cr.Color = TextColor.SetAlpha (.1); cr.Fill (); } if (item.ShowIcons) { PlaceSurface (cr, icon_surface, allocation); cr.PaintWithAlpha (item.Disabled ? 0.5 : 1); if (item.Bold) { cr.Operator = Operator.Add; PlaceSurface (cr, icon_surface, allocation); cr.PaintWithAlpha (.8); cr.Operator = Operator.Over; } if (!string.IsNullOrEmpty (item.Emblem)) { PlaceSurface (cr, emblem_surface, allocation); cr.Paint (); } } using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { char accel; string text = GLib.Markup.EscapeText (item.Text.Replace ("\n", "")); if (item.Mnemonic.HasValue) layout.SetMarkupWithAccel (text, '_', out accel); else layout.SetMarkup (text); layout.Width = Pango.Units.FromPixels (TextWidth); layout.FontDescription = Style.FontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (FontSize); layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle logical, ink; layout.GetPixelExtents (out ink, out logical); int offset = Padding; if (MenuShowingIcons) offset += MenuHeight + Padding; cr.MoveTo (allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2); Pango.CairoHelper.LayoutPath (cr, layout); cr.Color = TextColor.SetAlpha (item.Disabled ? 0.5 : 1); cr.Fill (); layout.Context.Dispose (); } (cr.Target as IDisposable).Dispose (); } return true; }
protected override void PaintIconSurface (DockySurface surface) { Context cr = surface.Context; int size = Math.Min (surface.Width, surface.Height); RenderSvgOnContext (cr, BottomSvg + "@" + GetType ().Assembly.FullName, size); if (RoundedCapacity > 0) RenderSvgOnContext (cr, string.Format (InsideSvg, RoundedCapacity) + "@" + GetType ().Assembly.FullName, size); RenderSvgOnContext (cr, TopSvg + "@" + GetType ().Assembly.FullName, size); if (!DockServices.System.OnBattery) RenderSvgOnContext (cr, PluggedSvg + "@" + GetType ().Assembly.FullName, size); }
protected abstract void DrawPageOnSurface (int page, DockySurface surface);
public override DockySurface IconSurface (DockySurface model, int size, int iconSize, int threeDimHeight) { return currentItem.IconSurface (model, size, iconSize, threeDimHeight); }
protected override void PaintIconSurface (DockySurface surface) { // do nothing, this should never be called }
protected override void PaintIconSurface (DockySurface surface) { Context cr = surface.Context; int size = Math.Min (surface.Width, surface.Height); double center = size / 2.0; // set from the svg files double svgWidth = 48.0; double centerRadius = 16; using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon ("base.svg@" + GetType ().Assembly.FullName, size)) { Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, (surface.Width - pbuf.Width) / 2, (surface.Height - pbuf.Height) / 2); cr.Paint (); } cr.Translate (0, size / svgWidth); Gdk.Color gtkColor = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (100); Cairo.Color color = new Cairo.Color ((double) gtkColor.Red / ushort.MaxValue, (double) gtkColor.Green / ushort.MaxValue, (double) gtkColor.Blue / ushort.MaxValue, 1.0); double percent = (double) Remaining / (double) Length; if (Running) percent -= ((double) (DateTime.UtcNow - LastRender).TotalMilliseconds / 1000.0) / (double) Length; if (Remaining > 0) { cr.MoveTo (center, center); cr.Arc (center, center, size * centerRadius / svgWidth, -Math.PI / 2.0, Math.PI * 2.0 * percent - Math.PI / 2.0); cr.LineTo (center, center); cr.Color = color; } else { cr.Arc (center, center, size * centerRadius / svgWidth, 0, 2.0 * Math.PI); cr.Color = color.AddHue (150).SetSaturation (1); } cr.Fill (); cr.Save (); using (DockySurface hand = new DockySurface (surface.Width, surface.Height, surface)) { using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon ("hand.svg@" + GetType ().Assembly.FullName, size)) { Gdk.CairoHelper.SetSourcePixbuf (hand.Context, pbuf, (surface.Width - pbuf.Width) / 2, (surface.Height - pbuf.Height) / 2); hand.Context.Paint (); } cr.Translate (hand.Width / 2.0, hand.Height / 2.0 + 1); cr.Rotate (2.0 * Math.PI * percent); cr.Translate (- hand.Width / 2.0, - (hand.Height / 2.0 + 1)); cr.SetSource (hand.Internal); cr.Paint (); } cr.Restore (); cr.Translate (0, size / -svgWidth); using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon ("overlay.svg@" + GetType ().Assembly.FullName, size)) { Gdk.CairoHelper.SetSourcePixbuf (cr, pbuf, (surface.Width - pbuf.Width) / 2, (surface.Height - pbuf.Height) / 2); cr.Paint (); } }
void PlaceSurface (Context cr, DockySurface surface, Gdk.Rectangle allocation) { int iconSize = allocation.Height - IconBuffer * 2; int x = allocation.X + Padding + ((iconSize - surface.Width) / 2); int y = allocation.Y + IconBuffer + ((iconSize - surface.Height) / 2); cr.SetSource (surface.Internal, x, y); }
public static DockySurface CreateMask(this DockySurface self, double cutOff, out Gdk.Rectangle extents) { ImageSurface original = new ImageSurface(Format.ARGB32, self.Width, self.Height); using (Cairo.Context cr = new Cairo.Context(original)) { cr.Operator = Operator.Source; cr.SetSource(self.Internal); cr.Paint(); } int width = original.Width; int height = original.Height; byte slice = (byte)(byte.MaxValue * cutOff); int left = width; int right = 0; int top = height; int bottom = 0; unsafe { byte *dataPtr = (byte *)original.DataPtr; int src; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { src = (y * width + x) * 4; bool mask = dataPtr[src + 3] > slice; dataPtr[src + 0] = 0; dataPtr[src + 1] = 0; dataPtr[src + 2] = 0; dataPtr[src + 3] = mask ? byte.MaxValue : (byte)0; if (mask) { if (y < top) { top = y; } if (y > bottom) { bottom = y; } if (x < left) { left = x; } if (x > right) { right = x; } } } } } extents = new Gdk.Rectangle(left, top, right - left, bottom - top); return(new DockySurface(original)); }
DockySurface LoadIcon (Pixbuf icon, int size) { DockySurface surface; using (Gdk.Pixbuf pixbuf = icon.Copy ().ARScale (size, size)) { surface = new DockySurface (pixbuf.Width, pixbuf.Height); Gdk.CairoHelper.SetSourcePixbuf (surface.Context, pixbuf, 0, 0); surface.Context.Paint (); } return surface; }
public unsafe static void GaussianBlur(this DockySurface self, int size) { // Note: This method is wickedly slow int gaussWidth = size * 2 + 1; double[] kernel = BuildGaussianKernel(gaussWidth); ImageSurface original = new ImageSurface(Format.Argb32, self.Width, self.Height); using (Cairo.Context cr = new Cairo.Context(original)) self.Internal.Show(cr, 0, 0); double gaussSum = 0; foreach (double d in kernel) { gaussSum += d; } for (int i = 0; i < kernel.Length; i++) { kernel[i] = kernel[i] / gaussSum; } int width = self.Width; int height = self.Height; byte[] src = original.Data; double[] xbuffer = new double[original.Data.Length]; double[] ybuffer = new double[original.Data.Length]; int dest, dest2, shift, source; byte *srcPtr = (byte *)original.DataPtr; fixed(double *xbufferPtr = xbuffer) fixed(double *ybufferPtr = ybuffer) fixed(double *kernelPtr = kernel) { // Horizontal Pass for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { dest = y * width + x; dest2 = dest * 4; for (int k = 0; k < gaussWidth; k++) { shift = k - size; source = dest + shift; if (x + shift <= 0 || x + shift >= width) { source = dest; } source = source * 4; xbufferPtr[dest2 + 0] = xbufferPtr[dest2 + 0] + (srcPtr[source + 0] * kernelPtr[k]); xbufferPtr[dest2 + 1] = xbufferPtr[dest2 + 1] + (srcPtr[source + 1] * kernelPtr[k]); xbufferPtr[dest2 + 2] = xbufferPtr[dest2 + 2] + (srcPtr[source + 2] * kernelPtr[k]); xbufferPtr[dest2 + 3] = xbufferPtr[dest2 + 3] + (srcPtr[source + 3] * kernelPtr[k]); } } } // Vertical Pass for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { dest = y * width + x; dest2 = dest * 4; for (int k = 0; k < gaussWidth; k++) { shift = k - size; source = dest + shift * width; if (y + shift <= 0 || y + shift >= height) { source = dest; } source = source * 4; ybufferPtr[dest2 + 0] = ybufferPtr[dest2 + 0] + (xbufferPtr[source + 0] * kernelPtr[k]); ybufferPtr[dest2 + 1] = ybufferPtr[dest2 + 1] + (xbufferPtr[source + 1] * kernelPtr[k]); ybufferPtr[dest2 + 2] = ybufferPtr[dest2 + 2] + (xbufferPtr[source + 2] * kernelPtr[k]); ybufferPtr[dest2 + 3] = ybufferPtr[dest2 + 3] + (xbufferPtr[source + 3] * kernelPtr[k]); } } } for (int i = 0; i < src.Length; i++) { srcPtr[i] = (byte)ybufferPtr[i]; } } self.Context.Operator = Operator.Source; self.Context.SetSource(original); self.Context.Paint(); (original as IDisposable).Dispose(); original.Destroy(); }
public override void Dispose () { if (icon_surface != null) icon_surface.Dispose (); icon_surface = null; if (emblem_surface != null) emblem_surface.Dispose (); emblem_surface = null; item.IconChanged -= ItemIconChanged; item.TextChanged -= ItemTextChanged; item.DisabledChanged -= ItemDisabledChanged; item = null; base.Dispose (); }
/// <summary> /// Emitted on the drag source when drag is started /// </summary> void HandleDragBegin (object o, DragBeginArgs args) { Owner.CursorTracker.RequestHighResolution (this); InternalDragActive = true; Keyboard.Grab (Owner.GdkWindow, true, Gtk.Global.CurrentEventTime); drag_canceled = false; if (proxy_window != null) { EnableDragTo (); proxy_window = null; } Gdk.Pixbuf pbuf; drag_item = Owner.HoveredItem; original_item_pos.Clear (); // If we are in Reposition Mode or over a non-draggable item // dont drag it! if (drag_item is INonPersistedItem || RepositionMode) drag_item = null; if (drag_item != null) { foreach (AbstractDockItem adi in ProviderForItem (drag_item).Items) original_item_pos [adi] = adi.Position; using (DockySurface surface = new DockySurface ((int) (1.2 * Owner.ZoomedIconSize), (int) (1.2 * Owner.ZoomedIconSize))) { pbuf = Owner.HoveredItem.IconSurface (surface, (int) (1.2 * Owner.ZoomedIconSize), Owner.IconSize, 0).LoadToPixbuf (); } } else { pbuf = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, 1, 1); } Gtk.Drag.SetIconPixbuf (args.Context, pbuf, pbuf.Width / 2, pbuf.Height / 2); pbuf.Dispose (); // Set up a cursor tracker so we can move the window on the fly if (RepositionMode) Owner.CursorTracker.CursorPositionChanged += HandleCursorPositionChanged; }
void ResetBackgroundBuffer () { if (background_buffer != null) { background_buffer.Dispose (); background_buffer = null; } }
public unsafe static void ExponentialBlur(this DockySurface self, int radius) { self.ExponentialBlur(radius, new Gdk.Rectangle(0, 0, self.Width, self.Height)); }
protected override bool OnExposeEvent (EventExpose evnt) { if (!IsRealized) return false; using (Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window)) { if (background_buffer == null) { if (Orientation == DockPosition.Bottom || Orientation == DockPosition.Top) { background_buffer = new DockySurface (allocation.Width, allocation.Height, cr.Target); } else { // switch width and height so we can rotate it later background_buffer = new DockySurface (allocation.Height, allocation.Width, cr.Target); } DrawBackground (background_buffer); } switch (Orientation) { case DockPosition.Top: cr.Scale (1, -1); cr.Translate (0, -background_buffer.Height); break; case DockPosition.Left: cr.Rotate (Math.PI * .5); cr.Translate (0, -background_buffer.Height); break; case DockPosition.Right: cr.Rotate (Math.PI * -0.5); cr.Translate (-background_buffer.Width, 0); break; } cr.Operator = Operator.Source; background_buffer.Internal.Show (cr, 0, 0); (cr.Target as IDisposable).Dispose (); } return base.OnExposeEvent (evnt); }
public unsafe static void ExponentialBlur(this DockySurface self, int radius, Gdk.Rectangle area) { if (radius < 1) { return; } area.Intersect(new Gdk.Rectangle(0, 0, self.Width, self.Height)); int alpha = (int)((1 << AlphaPrecision) * (1.0 - Math.Exp(-2.3 / (radius + 1.0)))); int height = self.Height; int width = self.Width; ImageSurface original; bool owned; if (self.Internal is ImageSurface) { original = self.Internal as ImageSurface; owned = true; } else { original = new ImageSurface(Format.Argb32, width, height); owned = false; } if (!owned) { using (Cairo.Context cr = new Cairo.Context(original)) { cr.Operator = Operator.Source; cr.SetSource(self.Internal); cr.Paint(); (cr.Target as IDisposable).Dispose(); } } byte *pixels = (byte *)original.DataPtr; // Process Rows Thread th = new Thread((ThreadStart) delegate { ExponentialBlurRows(pixels, width, height, 0, height / 2, area.X, area.Right, alpha); }); th.Start(); ExponentialBlurRows(pixels, width, height, height / 2, height, area.X, area.Right, alpha); th.Join(); // Process Columns th = new Thread((ThreadStart) delegate { ExponentialBlurColumns(pixels, width, height, 0, width / 2, area.Y, area.Bottom, alpha); }); th.Start(); ExponentialBlurColumns(pixels, width, height, width / 2, width, area.Y, area.Bottom, alpha); th.Join(); original.MarkDirty(); if (!owned) { self.Context.Operator = Operator.Source; self.Context.SetSource(original); self.Context.Paint(); self.Context.Operator = Operator.Over; (original as IDisposable).Dispose(); original.Destroy(); } }
void ShowBuffer (DockySurface surface, int page, double x) { // ensure the buffer size matches if (buffers [page] != null && (surface.Width != buffers [page].Width || surface.Height != buffers [page].Height)) ResetBuffers (); // the buffer is empty if (buffers [page] == null) { buffers [page] = new DockySurface (surface.Width, surface.Height, surface); DrawPageOnSurface (page, buffers [page]); } buffers [page].Internal.Show (surface.Context, x, 0); }
void MakeRectangularDigitalIcon (DockySurface surface) { Context cr = surface.Context; // useful sizes int timeSize = surface.Height / 3; int dateSize = surface.Height / 4; int ampmSize = surface.Height / 4; int spacing = timeSize / 2; // shared by all text using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout ()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels (surface.Width); // draw the time, outlined layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (timeSize); if (ShowMilitary) layout.SetText (DateTime.Now.ToString ("HH:mm")); else layout.SetText (DateTime.Now.ToString ("h:mm")); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents (out inkRect, out logicalRect); int timeYOffset = timeSize / 2; if (!ShowDate) timeYOffset += timeSize / 2; cr.MoveTo ((surface.Width - inkRect.Width) / 2, timeYOffset); Pango.CairoHelper.LayoutPath (cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color (0, 0, 0, 0.5); cr.StrokePreserve (); cr.Color = new Cairo.Color (1, 1, 1, 0.8); cr.Fill (); // draw the date, outlined if (ShowDate) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (dateSize); layout.SetText (DateTime.Now.ToString ("MMM dd")); layout.GetPixelExtents (out inkRect, out logicalRect); cr.MoveTo ((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); Pango.CairoHelper.LayoutPath (cr, layout); cr.Color = new Cairo.Color (0, 0, 0, 0.5); cr.StrokePreserve (); cr.Color = new Cairo.Color (1, 1, 1, 0.8); cr.Fill (); } if (!ShowMilitary) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (ampmSize); if (DateTime.Now.Hour < 12) layout.SetText ("am"); else layout.SetText ("pm"); layout.GetPixelExtents (out inkRect, out logicalRect); int yOffset = timeSize; if (!ShowDate) yOffset += timeSize / 2; cr.MoveTo (surface.Width - logicalRect.Width, yOffset - inkRect.Height); Pango.CairoHelper.LayoutPath (cr, layout); cr.Color = new Cairo.Color (1, 1, 1, 0.8); cr.Fill (); } layout.FontDescription.Dispose (); layout.Context.Dispose (); } }
void ResetButtons () { if (buttonBuffer != null) { buttonBuffer.Dispose (); buttonBuffer = null; } }
public static void TileOntoSurface(this DockySurface self, DockySurface target, Gdk.Rectangle area, int edgeBuffer, double tilt, DockPosition orientation) { if (orientation == DockPosition.Left || orientation == DockPosition.Right) { int x = area.X; if (orientation == DockPosition.Left) { x -= self.Width - area.Width; } Cairo.Context cr = target.Context; // draw left edge cr.Rectangle(area.X, area.Y, area.Width, edgeBuffer); cr.SetSource(self.Internal, x, area.Y); cr.Fill(); int maxMiddleMove = self.Height - 2 * edgeBuffer; int position = area.Y + edgeBuffer; int edgeTarget = area.Y + area.Height - edgeBuffer; while (position < edgeTarget) { int height = Math.Min(edgeTarget - position, maxMiddleMove); cr.Rectangle(area.X, position, area.Width, height); cr.SetSource(self.Internal, x, position - edgeBuffer); cr.Fill(); position += height; } cr.Rectangle(area.X, position, area.Width, edgeBuffer); cr.SetSource(self.Internal, x, area.Y + area.Height - self.Height); cr.Fill(); } else { if (tilt != 1) { area.Y += (int)(area.Height * tilt); area.Height -= (int)(area.Height * tilt); } int y = area.Y; if (orientation == DockPosition.Top) { y -= self.Height - area.Height; } Cairo.Context cr = target.Context; cr.Rectangle(area.X - 100, area.Y, edgeBuffer + 100, area.Height); Matrix m = new Matrix(1, 0, -tilt, 1, 0, y); cr.Transform(m); // draw left edge cr.SetSource(self.Internal, area.X, 0); cr.Fill(); cr.IdentityMatrix(); int maxMiddleMove = self.Width - 2 * edgeBuffer; int position = area.X + edgeBuffer; int edgeTarget = area.X + area.Width - edgeBuffer; while (position < edgeTarget) { int width = Math.Min(edgeTarget - position, maxMiddleMove); cr.Rectangle(position, area.Y, width, area.Height); cr.SetSource(self.Internal, position - edgeBuffer, y); cr.Fill(); position += width; } cr.Rectangle(position, area.Y, edgeBuffer + 100, area.Height); m = new Matrix(1, 0, tilt, 1, 0, y); cr.Transform(m); cr.SetSource(self.Internal, area.X + area.Width - self.Width, 0); cr.Fill(); cr.IdentityMatrix(); } }