private void CairoDraw(EventExpose evnt, int height, int width) { Time time = new Time(); width = Math.Min(width, this.Allocation.Width); using (Cairo.Context g = Gdk.CairoHelper.Create(evnt.Window)) { Cairo.Color color = new Cairo.Color(0, 0, 0); /* Drawing position triangle */ CairoUtils.DrawTriangle(g, CurrentFrame / pixelRatio - Scroll, height, 10, 15, color); /* Draw '0' */ CairoUtils.DrawLine(g, 0 - Scroll, height, width, height, 2, color); g.MoveTo(new PointD(0 - Scroll, height - 20)); g.ShowText("0"); for (int i = 10 * FrameRate; i <= frames / pixelRatio;) { CairoUtils.DrawLine(g, i - Scroll, height, i - Scroll, height - 10, 2, color); g.MoveTo(new PointD(i - Scroll - 13, height - 20)); time.Seconds = (int)(i / FrameRate * pixelRatio); g.ShowText(time.ToSecondsString()); i = i + 10 * FrameRate; } for (int i = 0; i <= frames / pixelRatio;) { CairoUtils.DrawLine(g, i - Scroll, height, i - Scroll, height - 5, 1, color); i = i + FrameRate; } } }
private void ShapeWindow() { Layout(); Gdk.Pixmap bitmap = new Gdk.Pixmap(GdkWindow, Allocation.Width, Allocation.Height, 1); Context g = CairoUtils.CreateContext(bitmap); DrawShape(g, Allocation.Width, Allocation.Height); ((IDisposable)g).Dispose(); if (use_shape_ext) { ShapeCombineMask(bitmap, 0, 0); } else { Context rgba = CairoUtils.CreateContext(GdkWindow); DrawShape(rgba, Allocation.Width, Allocation.Height); ((IDisposable)rgba).Dispose(); try { CompositeUtils.InputShapeCombineMask(this, bitmap, 0, 0); } catch (EntryPointNotFoundException) { System.Console.WriteLine("Warning: gtk+ version doesn't support input shapping"); } } bitmap.Dispose(); }
public StatsWidget(Stat stat, Stat category, SubCategoryStat subcat, int textSize) { /* For subcategories, parent is the parent Category */ this.stat = stat; this.category = category; HomeColor = CairoUtils.ColorFromRGB(0xFF, 0x33, 0); AwayColor = CairoUtils.ColorFromRGB(0, 0x99, 0xFF); layout = new Pango.Layout(PangoContext); layout.Wrap = Pango.WrapMode.Char; layout.Alignment = Pango.Alignment.Center; ModifyText(StateType.Normal, LongoMatch.Gui.Helpers.Misc.ToGdkColor(Config.Style.PaletteText)); this.textSize = textSize; name_tpl = "{0}"; count_tpl = "{0} ({1}%)"; if (category == null) { name_tpl = "<b>" + name_tpl + "</b>"; count_tpl = "<b>" + count_tpl + "</b>"; HeightRequest = 25; } else { if (subcat != null) { name_tpl = GLib.Markup.EscapeText(subcat.Name); name_tpl += name_tpl == "" ? "{0}" : ": {0}"; } HeightRequest = 18; } }
protected override bool OnExposeEvent(Gdk.EventExpose args) { int round = 12; Context g = CairoUtils.CreateContext(GdkWindow); g.Operator = Operator.Source; g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, 0)); g.Paint(); g.Operator = Operator.Over; #if true g.Source = new SolidPattern(new Cairo.Color(0, 0, 0, .7)); g.MoveTo(round, 0); //g.LineTo (Allocation.Width - round, 0); g.Arc(Allocation.Width - round, round, round, -Math.PI * 0.5, 0); //g.LineTo (Allocation.Width, Allocation.Height - round); g.Arc(Allocation.Width - round, Allocation.Height - round, round, 0, Math.PI * 0.5); //g.LineTo (round, Allocation.Height); g.Arc(round, Allocation.Height - round, round, Math.PI * 0.5, Math.PI); g.Arc(round, round, round, Math.PI, Math.PI * 1.5); g.ClosePath(); g.Fill(); #endif ((IDisposable)g).Dispose(); return(base.OnExposeEvent(args)); }
public StatsWidget(Stat stat, Stat category, SubCategoryStat subcat, int textSize) { /* For subcategories, parent is the parent Category */ this.stat = stat; this.category = category; HomeColor = CairoUtils.ColorFromRGB(0xFF, 0x33, 0); AwayColor = CairoUtils.ColorFromRGB(0, 0x99, 0xFF); layout = new Pango.Layout(PangoContext); layout.Wrap = Pango.WrapMode.Char; layout.Alignment = Pango.Alignment.Center; this.textSize = textSize; name_tpl = "{0}"; count_tpl = "{0} ({1}%)"; if (category == null) { name_tpl = "<b>" + name_tpl + "</b>"; count_tpl = "<b>" + count_tpl + "</b>"; HeightRequest = 25; } else { if (subcat != null) { name_tpl = GLib.Markup.EscapeText(subcat.Name) + ": {0}"; } HeightRequest = 18; } }
public bool Convert(FilterRequest req) { string source = req.Current.LocalPath; Uri dest = req.TempUri(Path.GetExtension(source)); using (ImageFile img = ImageFile.Create(source)) { using (Pixbuf pixbuf = img.Load()) { using (ImageInfo info = new ImageInfo(pixbuf)) { MemorySurface surface = new MemorySurface(Format.Argb32, pixbuf.Width, pixbuf.Height); Context ctx = new Context(surface); ctx.Matrix = info.Fill(info.Bounds, angle); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); using (Pixbuf result = CairoUtils.CreatePixbuf(surface)) { using (Stream output = File.OpenWrite(dest.LocalPath)) { img.Save(result, output); } } surface.Flush(); info.Dispose(); req.Current = dest; return(true); } } } }
public Texture(Gdk.Pixbuf pixbuf) : this(pixbuf.Width, pixbuf.Height) { MemorySurface surface = CairoUtils.CreateSurface(pixbuf); CopyFromSurface(surface); surface.Destroy(); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { Context g = CairoUtils.CreateContext(GdkWindow); DrawShape(g, Allocation.Width, Allocation.Height); //base.OnExposeEvent (args); ((IDisposable)g).Dispose(); return(false); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { bool ret = base.OnExposeEvent(args); Graphics g = CairoUtils.CreateDrawable(GdkWindow); g.Color = new Cairo.Color(0, 0, 0, .5); g.Operator = Operator.DestOut; g.Rectangle(0, 0, Allocation.Width * .5, Allocation.Height); g.Paint(); return(ret); }
protected override bool OnExposeEvent(Gdk.EventExpose args) { Gdk.Color c = Style.Background(State); Context cr = CairoUtils.CreateContext(GdkWindow); ShapeSurface(cr, new Cairo.Color(c.Red / (double)ushort.MaxValue, c.Blue / (double)ushort.MaxValue, c.Green / (double)ushort.MaxValue, 0.8)); ((IDisposable)cr).Dispose(); return(base.OnExposeEvent(args)); }
void DrawTimeNodes(Gdk.Window win) { bool hasSelectedTimeNode = false; using (Cairo.Context g = Gdk.CairoHelper.Create(win)) { int height; int width; win.Resize((int)(frames / pixelRatio), Allocation.Height); win.GetSize(out width, out height); g.Operator = Operator.Over; foreach (T tn in list) { if (filter != null && !filter.IsVisible(tn)) { continue; } if (!tn.Equals(selected)) { Cairo.Color borderColor = new Cairo.Color(color.R + 0.1, color.G + 0.1, color.B + 0.1, 1); CairoUtils.DrawRoundedRectangle(g, tn.StartFrame / pixelRatio, 3, tn.TotalFrames / pixelRatio, height - 6, SECTION_HEIGHT / 7, color, borderColor); } else { hasSelectedTimeNode = true; } } //Then we draw the selected TimeNode over the others if (hasSelectedTimeNode) { Cairo.Color borderColor = new Cairo.Color(0, 0, 0, 1); CairoUtils.DrawRoundedRectangle(g, selected.StartFrame / pixelRatio, 3, selected.TotalFrames / pixelRatio, height - 6, SECTION_HEIGHT / 7, color, borderColor); if (selected.HasDrawings) { g.MoveTo(selected.KeyFrame / pixelRatio, 3); g.LineTo(selected.KeyFrame / pixelRatio, SECTION_HEIGHT - 3); g.StrokePreserve(); } } DrawLines(win, g, height, width); } }
void DrawLines(Gdk.Window win, Cairo.Context g, int height, int width) { if (Environment.OSVersion.Platform == PlatformID.Unix) { Cairo.Color color = new Cairo.Color(0, 0, 0); CairoUtils.DrawLine(g, currentFrame / pixelRatio, 0, currentFrame / pixelRatio, height, 1, color); CairoUtils.DrawLine(g, 0, 0, width, 0, 1, color); CairoUtils.DrawLine(g, 0, height, width, height, 1, color); } else { win.DrawLine(Style.DarkGC(StateType.Normal), 0, 0, width, 0); win.DrawLine(Style.DarkGC(StateType.Normal), (int)(currentFrame / pixelRatio), 0, (int)(currentFrame / pixelRatio), height); } }
private void ShapeWindow() { if (composited) { return; } Gdk.Pixmap bitmap = new Gdk.Pixmap(GdkWindow, Allocation.Width, Allocation.Height, 1); Context cr = CairoUtils.CreateContext(bitmap); ShapeCombineMask(bitmap, 0, 0); ShapeSurface(cr, new Cairo.Color(1, 1, 1)); ShapeCombineMask(bitmap, 0, 0); ((IDisposable)cr).Dispose(); bitmap.Dispose(); }
private void DrawCategories(Gdk.Window win) { int i = 0; if (labelsDict.Count == 0) { return; } using (Cairo.Context g = Gdk.CairoHelper.Create(win)) { foreach (Label label in labelsDict.Keys) { Cairo.Color color; Category cat; int y; cat = labelsDict[label]; y = LINE_WIDTH / 2 + i * SECTION_HEIGHT - (int)Scroll; if (cat != null) { if (filter != null && !filter.VisibleCategories.Contains(cat)) { continue; } color = CairoUtils.RGBToCairoColor(Helpers.Misc.ToGdkColor(cat.Color)); } else { color = new Cairo.Color(0, 0, 0); } CairoUtils.DrawRoundedRectangle(g, 2, y + 3, Allocation.Width - 3, SECTION_HEIGHT - 3, SECTION_HEIGHT / 7, color, color); DrawCairoText(label.Text, 0 + 3, y + SECTION_HEIGHT / 2 - 5); i++; } } }
private void DrawCategories(Gdk.Window win) { int i = 0; if (labelsDict.Count == 0) { return; } using (Cairo.Context g = Gdk.CairoHelper.Create(win)) { foreach (String label in labelsDict.Keys) { int y = LINE_WIDTH / 2 + i * SECTION_HEIGHT - (int)Scroll; CairoUtils.DrawRoundedRectangle(g, 2, y + 3, Allocation.Width - 3, SECTION_HEIGHT - 3, SECTION_HEIGHT / 7, CairoUtils.RGBToCairoColor(labelsDict[label]), CairoUtils.RGBToCairoColor(labelsDict[label])); DrawCairoText(label, 0 + 3, y + SECTION_HEIGHT / 2 - 5); i++; } } }
static Gdk.Pixbuf CreatePixbuf(ImageSurface s) { return(CairoUtils.PixbufFromSurface(s)); }
protected override bool OnExposeEvent(EventExpose evnt) { int width, height, center, lCenter, vCenter, totalCount; double localPercent, visitorPercent; this.GdkWindow.Clear(); width = Allocation.Width; center = width / 2; lCenter = center - textSize / 2; vCenter = center + textSize / 2; width = width - textSize - 10; height = Allocation.Height; if (category != null) { totalCount = category.TotalCount; } else { totalCount = stat.TotalCount; } if (totalCount != 0) { localPercent = (double)stat.LocalTeamCount / totalCount; visitorPercent = (double)stat.VisitorTeamCount / totalCount; } else { localPercent = 0; visitorPercent = 0; } using (Cairo.Context g = Gdk.CairoHelper.Create(this.GdkWindow)) { int localW, visitorW; localW = (int)(width / 2 * localPercent); visitorW = (int)(width / 2 * visitorPercent); /* Home bar */ CairoUtils.DrawRoundedRectangle(g, lCenter - localW, 0, localW, height, 0, HomeColor, HomeColor); /* Away bar */ CairoUtils.DrawRoundedRectangle(g, vCenter, 0, visitorW, height, 0, AwayColor, AwayColor); /* Category name */ layout.Width = Pango.Units.FromPixels(textSize); layout.Alignment = Pango.Alignment.Center; layout.SetMarkup(String.Format(name_tpl, GLib.Markup.EscapeText(stat.Name))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), center - textSize / 2, 0, layout); /* Home count */ layout.Width = Pango.Units.FromPixels(COUNT_WIDTH); layout.Alignment = Pango.Alignment.Right; layout.SetMarkup(String.Format(count_tpl, stat.LocalTeamCount, (localPercent * 100).ToString("f2"))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), lCenter - (COUNT_WIDTH + 3), 0, layout); /* Away count */ layout.Width = Pango.Units.FromPixels(COUNT_WIDTH); layout.Alignment = Pango.Alignment.Left; layout.SetMarkup(String.Format(count_tpl, stat.VisitorTeamCount, (visitorPercent * 100).ToString("f2"))); GdkWindow.DrawLayout(Style.TextGC(StateType.Normal), vCenter + 3, 0, layout); } return(true); }