void Draw() { if (pixmap == null) { return; } Style style = Style; StateType state = Sensitive ? StateType.Normal : StateType.Insensitive; if (width <= 0 || height <= 0) { return; } //clear the pixmap GtkBeans.Style.PaintFlatBox(style, pixmap, StateType.Normal, ShadowType.None, null, this, "curve_bg", 0, 0, Allocation.Width, Allocation.Height); //draw the grid lines for (int i = 0; i < 5; i++) { pixmap.DrawLine(style.DarkGC(state), x_offset, i * (int)(height / 4.0) + y_offset, width + x_offset, i * (int)(height / 4.0) + y_offset); pixmap.DrawLine(style.DarkGC(state), i * (int)(width / 4.0) + x_offset, y_offset, i * (int)(width / 4.0) + x_offset, height + y_offset); } //draw the curve pixmap.DrawPoints(style.ForegroundGC(state), Interpolate(width, height)); //draw the bullets if (CurveType != CurveType.Free) { foreach (var keyval in points) { if (keyval.Key < MinX) { continue; } int x = Project(keyval.Key, MinX, MaxX, width); int y = height - Project(keyval.Value, MinY, MaxY, height); pixmap.DrawArc(style.ForegroundGC(state), true, x, y, radius * 2, radius * 2, 0, 360 * 64); } } GdkWindow.DrawDrawable(style.ForegroundGC(state), pixmap, 0, 0, 0, 0, Allocation.Width, Allocation.Height); }
public static Pixbuf LoadIcon(Widget widget, string name, IconSize size) { var res = widget.RenderIcon(name, size, null); if (res != null) { return(res); } int sz; int sy; Icon.SizeLookup(size, out sz, out sy); try { return(IconTheme.Default.LoadIcon(name, sz, 0)); } catch (Exception) { if (name != "gtk-missing-image") { return(LoadIcon(widget, "gtk-missing-image", size)); } var pmap = new Pixmap(Screen.Default.RootWindow, sz, sz); var gc = new GC(pmap) { RgbFgColor = new Color(255, 255, 255) }; pmap.DrawRectangle(gc, true, 0, 0, sz, sz); gc.RgbFgColor = new Color(0, 0, 0); pmap.DrawRectangle(gc, false, 0, 0, sz - 1, sz - 1); gc.SetLineAttributes(3, LineStyle.Solid, CapStyle.Round, JoinStyle.Round); gc.RgbFgColor = new Color(255, 0, 0); pmap.DrawLine(gc, sz / 4, sz / 4, (sz - 1) - (sz / 4), (sz - 1) - (sz / 4)); pmap.DrawLine(gc, (sz - 1) - (sz / 4), sz / 4, sz / 4, (sz - 1) - (sz / 4)); return(Pixbuf.FromDrawable(pmap, pmap.Colormap, 0, 0, 0, 0, sz, sz)); } }
private void RenderBubbles(Gdk.Window win, Gdk.Rectangle size, out Pixbuf pbactive, out Pixbuf pbinactive, out Gdk.Pixmap pbpm) { int pmHeight, pmWidth; Gdk.Pixmap daPixmap; Gdk.Pixmap daOtherPixmap; pmHeight = size.Height - (wbsize * 2); pmWidth = size.Width - (wbsize * 2); Gdk.GC gc = new Gdk.GC(win); Gdk.Pixmap pm = new Pixmap(win, size.Width, size.Height, -1); gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawRectangle(gc, true, 0, 0, size.Width, size.Height); gc.RgbFgColor = new Gdk.Color(249, 253, 202); Gdk.Point[] roundedSquare = CalculateRect(wbsize, wbsize, pmWidth, pmHeight); pm.DrawPolygon(gc, true, roundedSquare); Gdk.Point[] roundedborder = CalculateRect(wbsize, wbsize, pmWidth - 1, pmHeight - 1); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawPolygon(gc, false, roundedborder); Gdk.Point[] balloonptr = CalcPointerMoveWindow( size.Width, size.Height ); gc.RgbFgColor = new Gdk.Color(249, 253, 202); pm.DrawPolygon(gc, true, balloonptr); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawLine(gc, balloonptr[0].X, balloonptr[0].Y-1, balloonptr[1].X, balloonptr[1].Y); pm.DrawLine(gc, balloonptr[1].X, balloonptr[1].Y, balloonptr[2].X, balloonptr[2].Y-1); Gdk.Pixbuf pb = new Pixbuf(Gdk.Colorspace.Rgb, false, 8, size.Width, size.Height); pb = Pixbuf.FromDrawable( pm, pm.Colormap, 0, 0, 0, 0, size.Width, size.Height); pb = pb.AddAlpha(true, 255, 255,255); RenderPixmapAndMask(pb, out daPixmap, out daOtherPixmap, 2); pbactive = pb; pbpm = daOtherPixmap; gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawRectangle(gc, true, 0, 0, size.Width, size.Height); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawPolygon(gc, false, roundedborder); gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawPolygon(gc, true, balloonptr); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawLine(gc, balloonptr[0].X, balloonptr[0].Y-1, balloonptr[1].X, balloonptr[1].Y); pm.DrawLine(gc, balloonptr[1].X, balloonptr[1].Y, balloonptr[2].X, balloonptr[2].Y - 1); pb = Pixbuf.FromDrawable( pm, pm.Colormap, 0, 0, 0, 0, size.Width, size.Height); pbinactive = pb; }
public void DrawChart(object obj, SizeAllocatedArgs args) { int width = args.Allocation.Width; int height = args.Allocation.Height; int size = Math.Min(width, height); //If this is true, then we don't need to update. if (size == currentSize) { return; } currentSize = size; currentSize = size; int chartRadius = size; int labelRadius = 0; color = new Pixmap(MainWindow.main.GdkWindow, size, size); mask = new Pixmap(MainWindow.main.GdkWindow, size, size); Gdk.GC visible = new Gdk.GC(mask) { RgbFgColor = new Color(255, 255, 255) }; Gdk.GC invisible = new Gdk.GC(mask) { RgbFgColor = new Color(0, 0, 0) }; Gdk.GC white = new Gdk.GC(color) { RgbFgColor = new Color(255, 255, 255) }; // for marking the mask. Gdk.GC lightGrey = new Gdk.GC(color) { RgbFgColor = new Color(200, 200, 200) }; // for the axes Gdk.GC grey = new Gdk.GC(color) { RgbFgColor = new Color(125, 125, 125) }; // for the axis markings Gdk.GC darkGrey = new Gdk.GC(color) { RgbFgColor = new Color(100, 100, 100) }; // for the axis labels Gdk.GC[] wrapperColors = { new Gdk.GC(color) { RgbFgColor = new Gdk.Color(170, 140, 0) }, //Regular new Gdk.GC(color) { RgbFgColor = new Color(0, 0, 200) }, //Tinker new Gdk.GC(color) { RgbFgColor = new Color(0, 150, 0) }, //Master new Gdk.GC(color) { RgbFgColor = new Color(0, 0, 0) }, //Breaker }; color.DrawRectangle(white, true, new Rectangle(0, 0, size, size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, size, size)); //The eight directions in which vertices lie Vector2[] directions = { new Vector2(0, -1), new Vector2(Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2), new Vector2(1, 0), new Vector2(Math.Sqrt(2) / 2, Math.Sqrt(2) / 2), new Vector2(0, 1), new Vector2(-Math.Sqrt(2) / 2, Math.Sqrt(2) / 2), new Vector2(-1, 0), new Vector2(-Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2) }; IntVector2 center = new IntVector2(size / 2, size / 2); //Compute magnitudes int[] indexMap = { 0, 1, 5, 3, 7, 0, 4, 6, 2 }; //old[0] -> new[1], old[1] -> new[5] etc. int[] reverseIndexMap = { 5, 1, 8, 3, 6, 2, 7, 4 }; //old[0] -> new[1], old[1] -> new[5] etc. float[] magnitudes = new float[8]; //Magnitudes of the positions of the vertices float[,] fractions = new float[8, 3]; //Fractional contribution of each wrapper of each rating classification for (int i = 1; i <= 8; i++) { int j = indexMap[i]; magnitudes[j] = values[4, i] > 0 ? values[4, i] : 0; if (o_vals[4, i] != 0) { fractions[j, 0] = (float)o_vals[0, i] / o_vals[4, i]; fractions[j, 1] = (float)(o_vals[0, i] + o_vals[1, i]) / o_vals[4, i]; fractions[j, 2] = (float)(o_vals[0, i] + o_vals[1, i] + o_vals[2, i]) / o_vals[4, i]; } } float greatestMagnitude = 0; for (int i = 0; i < 8; i++) { if (magnitudes[i] > greatestMagnitude) { greatestMagnitude = magnitudes[i]; } } if (greatestMagnitude < 0.01) { return; } //Determing text radius and preload labels; Pango.Layout[] labels = new Pango.Layout[8]; IntVector2[] labelSizes = new IntVector2[8]; for (int i = 0; i < 8; i++) { //Label labels[i] = new Pango.Layout(PangoContext) { Alignment = Pango.Alignment.Center }; if (multipliers == null) { labels[i].SetText(Ratings.symbols[reverseIndexMap[i]]); } else { labels[i].SetMarkup(Ratings.symbols[reverseIndexMap[i]] + "\n<small>×" + multipliers[reverseIndexMap[i]].ToString("0.0") + "</small>"); } labels[i].GetSize(out int labelWidth, out int labelHeight); labelSizes[i] = new IntVector2(labelWidth, labelHeight) / Pango.Scale.PangoScale; int thisLabelRadius = Math.Max(labelSizes[i].x, labelSizes[i].y); if (thisLabelRadius > labelRadius) { labelRadius = thisLabelRadius; chartRadius = size / 2 - labelRadius * 2; } } for (int i = 0; i < 8; i++) { IntVector2 textPoint = directions[i] * (chartRadius + labelRadius) + (Vector2)center - (Vector2)labelSizes[i] / 2; color.DrawLayout(darkGrey, textPoint.x, textPoint.y, labels[i]); mask.DrawLayout(visible, textPoint.x, textPoint.y, labels[i]); //Line IntVector2 endPoint = (directions[i] * chartRadius) + (Vector2)center; color.DrawLine(lightGrey, center.x, center.y, endPoint.x, endPoint.y); mask.DrawLine(visible, center.x, center.y, endPoint.x, endPoint.y); } //Draw circles and axis markings float theoreticalPtInterval = (size / 6 + 20) / 2; float theoreticalRatingInterval = theoreticalPtInterval / chartRadius * greatestMagnitude; //(between 20pt markings) int ratingInterval = (int)Math.Round(theoreticalRatingInterval); //Round it off for neatness float ptInterval = ratingInterval / greatestMagnitude * chartRadius; //Now what's the pt interval for that? for (int i = 1; ptInterval * i < chartRadius; i++) { //Circle int radius = (int)(ptInterval * i); color.DrawArc(lightGrey, false, center.x - radius, center.y - radius, radius * 2, radius * 2, 0, 23040); //Angles are in 1/64th degrees, 23040 = 360*64 = full circle. mask.DrawArc(visible, false, center.x - radius, center.y - radius, radius * 2, radius * 2, 0, 23040); //Axis marking Pango.Layout mark = new Pango.Layout(PangoContext); mark.SetText("" + ratingInterval * i); mark.GetSize(out int markWidth, out int markHeight); IntVector2 markSize = new IntVector2(markWidth, markHeight) / Pango.Scale.PangoScale; IntVector2 markCenter = (Vector2)center + directions[2] * ptInterval * i; mask.DrawArc(invisible, true, markCenter.x - markSize.x / 2, markCenter.y - markSize.y / 2, markSize.x, markSize.y, 0, 23040); //Clears a circular space for the mark color.DrawLayout(grey, markCenter.x - markSize.x / 2, markCenter.y - markSize.y / 2, mark); //Actually mask.DrawLayout(visible, markCenter.x - markSize.x / 2, markCenter.y - markSize.y / 2, mark); //draw the mark. } //Compute vertices IntVector2[,] vertices = new IntVector2[4, 8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) { vertices[j, i] = directions[i] * (chartRadius / greatestMagnitude) * magnitudes[i] * fractions[i, j] + (Vector2)center; } vertices[3, i] = directions[i] * (chartRadius / greatestMagnitude) * magnitudes[i] + (Vector2)center; } //Bump vertices by a pixel if they overlap. bool changed = true; while (changed) { changed = false; for (int i = 3; i > 1; i--) { for (int j = 0; j < 8; j++) { if (vertices[i, j] == vertices[i - 1, j]) { vertices[i, j] += (IntVector2)directions[j]; changed = true; } } } } //Draw polygons for (int i = 0; i < 4; i++) { for (int j = 0; j < 7; j++) //j=7 is excluded as we need to connect it to vertex 0 manually. { color.DrawLine(wrapperColors[i], vertices[i, j].x, vertices[i, j].y, //This point vertices[i, j + 1].x, vertices[i, j + 1].y); //Next point mask.DrawLine(visible, vertices[i, j].x, vertices[i, j].y, //This point vertices[i, j + 1].x, vertices[i, j + 1].y); //Next point } color.DrawLine(wrapperColors[i], vertices[i, 7].x, vertices[i, 7].y, //Point 7 vertices[i, 0].x, vertices[i, 0].y); //Point 0 mask.DrawLine(visible, vertices[i, 7].x, vertices[i, 7].y, //Point 7 vertices[i, 0].x, vertices[i, 0].y); //Point 0 } if (metamultipliers != null) { int currentY = size - 5; for (int i = 3; i >= 0; i--) { Pango.Layout label = new Pango.Layout(PangoContext) { Alignment = Pango.Alignment.Center }; label.SetMarkup("<small>x" + metamultipliers[i].ToString("0.0") + "</small>"); label.GetSize(out int labelWidth, out int labelHeight); labelWidth = (int)(labelWidth / Pango.Scale.PangoScale); labelHeight = (int)(labelHeight / Pango.Scale.PangoScale); currentY -= labelHeight; color.DrawLayout(wrapperColors[i], size - labelWidth - 5, currentY, label); mask.DrawLayout(visible, size - labelWidth - 5, currentY, label); } } SetFromPixmap(color, mask); }
private void RenderBubbles(Gdk.Window win, Gdk.Rectangle size, out Pixbuf pbactive, out Pixbuf pbinactive, out Gdk.Pixmap pbpm) { int pmHeight, pmWidth; Gdk.Pixmap daPixmap; Gdk.Pixmap daOtherPixmap; pmHeight = size.Height - (wbsize * 2); pmWidth = size.Width - (wbsize * 2); Gdk.GC gc = new Gdk.GC(win); // Build active Pixbuf // Gdk.Pixmap pm = new Pixmap(win, pmWidth, pmHeight, -1); Gdk.Pixmap pm = new Pixmap(win, size.Width, size.Height, -1); // Paint the background white gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawRectangle(gc, true, 0, 0, size.Width, size.Height); /*********************************** * draw painted oval window ***********************************/ // Paint the inside of the window gc.RgbFgColor = new Gdk.Color(249, 253, 202); Gdk.Point[] roundedSquare = CalculateRect(wbsize, wbsize, pmWidth, pmHeight); pm.DrawPolygon(gc, true, roundedSquare); // Paint the border of the window Gdk.Point[] roundedborder = CalculateRect(wbsize, wbsize, pmWidth - 1, pmHeight - 1); gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawPolygon(gc, false, roundedborder); /*********************************** * add tab to bitmap ***********************************/ Gdk.Point[] balloonptr = CalcPointerMoveWindow(size.Width, size.Height); // Draw colored pointer gc.RgbFgColor = new Gdk.Color(249, 253, 202); pm.DrawPolygon(gc, true, balloonptr); gc.RgbFgColor = new Gdk.Color(0, 0, 0); // subtract one because the fill above used and extra line pm.DrawLine(gc, balloonptr[0].X, balloonptr[0].Y - 1, balloonptr[1].X, balloonptr[1].Y); pm.DrawLine(gc, balloonptr[1].X, balloonptr[1].Y, balloonptr[2].X, balloonptr[2].Y - 1); Gdk.Pixbuf pb = new Pixbuf(Gdk.Colorspace.Rgb, false, 8, size.Width, size.Height); pb = Pixbuf.FromDrawable(pm, pm.Colormap, 0, 0, 0, 0, size.Width, size.Height); pb = pb.AddAlpha(true, 255, 255, 255); RenderPixmapAndMask(pb, out daPixmap, out daOtherPixmap, 2); pbactive = pb; pbpm = daOtherPixmap; // Reset backgound to white and get next bitmap gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawRectangle(gc, true, 0, 0, size.Width, size.Height); // Paint the border of the window gc.RgbFgColor = new Gdk.Color(0, 0, 0); pm.DrawPolygon(gc, false, roundedborder); // Draw white pointer gc.RgbFgColor = new Gdk.Color(255, 255, 255); pm.DrawPolygon(gc, true, balloonptr); gc.RgbFgColor = new Gdk.Color(0, 0, 0); // subtract one because the fill above used and extra line pm.DrawLine(gc, balloonptr[0].X, balloonptr[0].Y - 1, balloonptr[1].X, balloonptr[1].Y); pm.DrawLine(gc, balloonptr[1].X, balloonptr[1].Y, balloonptr[2].X, balloonptr[2].Y - 1); pb = Pixbuf.FromDrawable(pm, pm.Colormap, 0, 0, 0, 0, size.Width, size.Height); pbinactive = pb; }