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; } }
DockySurface LoadIcon(string icon, int size) { bool monochrome = icon.StartsWith("[monochrome]"); if (monochrome) { icon = icon.Substring("[monochrome]".Length); } Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon(icon, size); DockySurface surface = LoadIcon(pbuf, size); pbuf.Dispose(); if (monochrome) { surface.Context.Operator = Operator.Atop; double v = TextColor.GetValue(); // reduce value by 20% surface.Context.Color = TextColor.SetValue(v * .8); surface.Context.Paint(); surface.ResetContext(); } return(surface); }
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(); } }
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]); }
static DockySurface[] GetSlices(DockySurface model) { if (slices != null) { return(slices); } DockySurface main = new DockySurface(3 * AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight, model); using (Gdk.Pixbuf pixbuf = DockServices.Drawing.LoadIcon(DockServices.Theme.TooltipSvg)) { Gdk.CairoHelper.SetSourcePixbuf(main.Context, pixbuf, 0, 0); main.Context.Paint(); } DockySurface[] results = new DockySurface[3]; results[0] = main.CreateSlice(new Gdk.Rectangle(0, 0, AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight)); results[1] = main.CreateSlice(new Gdk.Rectangle(AbstractDockItem.HoverTextHeight / 2, 0, AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight)); results[2] = main.CreateSlice(new Gdk.Rectangle(AbstractDockItem.HoverTextHeight, 0, AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight)); slices = results; main.Dispose(); return(slices); }
void HandleWindowExposeEvent(object o, ExposeEventArgs args) { using (Cairo.Context cr = Gdk.CairoHelper.Create(args.Event.Window)) { cr.Operator = Operator.Source; if (currentSurface == null || currentSurface.Internal == null) { cr.Color = new Cairo.Color(1, 1, 1, 0); } else { if (background_buffer == null) { background_buffer = new DockySurface(currentSurface.Width, currentSurface.Height, cr.Target); DrawBackground(background_buffer); } background_buffer.Internal.Show(cr, 0, 0); cr.Operator = Operator.Over; cr.SetSource(currentSurface.Internal); } cr.Paint(); (cr.Target as IDisposable).Dispose(); } }
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 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(); } }
void DrawRoundedLine(DockySurface surface, double x, double y, double width, double height, bool roundLeft, bool roundRight, Gradient stroke, Gradient fill) { double leftRadius = roundLeft ? height / 2.0 : 0.0; double rightRadius = roundRight ? height / 2.0 : 0.0; surface.Context.MoveTo(x + width - rightRadius, y); surface.Context.LineTo(x + leftRadius, y); if (roundLeft) { surface.Context.ArcNegative(x + leftRadius, y + height / 2.0, leftRadius, -Math.PI / 2.0, Math.PI / 2.0); } else { surface.Context.LineTo(x, y + height); } surface.Context.LineTo(x + width - rightRadius, y + height); if (roundRight) { surface.Context.ArcNegative(x + width - rightRadius, y + height / 2.0, rightRadius, Math.PI / 2.0, -Math.PI / 2.0); } else { surface.Context.LineTo(x + width, y); } surface.Context.ClosePath(); if (fill != null) { surface.Context.Pattern = fill; surface.Context.FillPreserve(); } surface.Context.Pattern = stroke; surface.Context.Stroke(); }
/// <summary> /// Resets the buffers of the item, forcing them to be redrawn the next time the item is shown /// </summary> public void ResetBuffers() { for (int i = 0; i < icon_buffers.Length; i++) { icon_buffers [i] = ResetBuffer(icon_buffers [i]); } text_buffer = ResetBuffer(text_buffer); }
void ResetBackgroundBuffer() { if (background_buffer != null) { background_buffer.Dispose(); background_buffer = null; } }
void DrawBackground(DockySurface surface) { DockySurface[] slices = GetSlices(surface); surface.DrawSlice(slices[0], new Gdk.Rectangle(0, 0, AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight)); surface.DrawSlice(slices[1], new Gdk.Rectangle(AbstractDockItem.HoverTextHeight / 2, 0, Math.Max(0, surface.Width - AbstractDockItem.HoverTextHeight), AbstractDockItem.HoverTextHeight)); surface.DrawSlice(slices[2], new Gdk.Rectangle(surface.Width - AbstractDockItem.HoverTextHeight / 2, 0, AbstractDockItem.HoverTextHeight / 2, AbstractDockItem.HoverTextHeight)); }
protected void OnHoverTextChanged() { text_buffer = ResetBuffer(text_buffer); if (HoverTextChanged != null) { HoverTextChanged(this, EventArgs.Empty); } }
void ResetButtons() { if (buttonBuffer != null) { buttonBuffer.Dispose(); buttonBuffer = null; } }
void ResetBuffer() { if (surface != null) { surface.Dispose(); surface = null; } }
protected override void PostProcessIconSurface(DockySurface surface) { if (Atom.State != GMailState.Error && !Atom.HasUnread) { surface.Context.Color = new Cairo.Color(0, 0, 0, 0); surface.Context.Operator = Operator.Source; surface.Context.PaintWithAlpha(.5); } }
DockySurface ResetBuffer(DockySurface buffer) { if (buffer != null) { buffer.Dispose(); } return(null); }
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); }
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); }
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); }
protected override DockySurface CreateIconBuffer(DockySurface model, int size) { if (Square) { return(base.CreateIconBuffer(model, size)); } else { return(new DockySurface(2 * size, size, model)); } }
void PaintMessagesSurface(DockySurface surface) { int pos = 0; for (int i = 0; i < MaxMessages; i++) { if (!string.IsNullOrEmpty(messages [i])) { PaintMessage(surface, messageIcons [i], messages [i], MaxMessages - 1 - pos++); } } }
public void SetSurfaceAtPoint(DockySurface surface, Gdk.Point point) { if (surface == currentSurface && point == currentPoint) { window.QueueDraw(); return; } ResetBackgroundBuffer(); currentSurface = surface; currentPoint = point; if (surface == null) { Hide(); return; } window.SetSizeRequest(surface.Width, surface.Height); Gdk.Point center = Gdk.Point.Zero; int padding = 5; switch (Gravity) { case DockPosition.Top: center = new Gdk.Point(point.X - surface.Width / 2, point.Y + padding); break; case DockPosition.Left: center = new Gdk.Point(point.X + padding, point.Y - surface.Height / 2); break; case DockPosition.Right: center = new Gdk.Point(point.X - surface.Width - padding, point.Y - surface.Height / 2); break; case DockPosition.Bottom: center = new Gdk.Point(point.X - surface.Width / 2, point.Y - surface.Height - padding); break; } Gdk.Rectangle monitor_geo = window.Screen.GetMonitorGeometry(Monitor); center.X = Math.Max(monitor_geo.X, Math.Min(center.X, monitor_geo.X + monitor_geo.Width - surface.Width)); center.Y = Math.Max(monitor_geo.Y, Math.Min(center.Y, monitor_geo.Y + monitor_geo.Height - surface.Height)); if (Visible) { window.QueueDraw(); } window.Move(center.X, center.Y); }
/// <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; } }
protected override void PostProcessIconSurface(DockySurface surface) { if (Status == WeatherDockletStatus.Error) { return; } if (Status == WeatherDockletStatus.Initializing) { return; } int size = Math.Min(surface.Width, surface.Height); 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; Pango.Rectangle inkRect, logicalRect; layout.Width = Pango.Units.FromPixels(size); layout.SetText(WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit); if (IsSmall) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 2.5)); } else { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 3.5)); } layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((size - inkRect.Width) / 2, size - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color(0, 0, 0, 0.8); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
public DockySurface GetSurface(DockySurface similar) { if (surface == null || surface.Width != Allocation.Width || surface.Height != Allocation.Height) { ResetBuffer(); surface = new DockySurface(Allocation.Width, Allocation.Height, similar); } if (paint_needed) { PaintSurface(surface); paint_needed = false; } return(surface); }
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); }; }
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 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)); }