public Sprite (float dx, float dy, int color, int width, int height, Picture.Format pf) { x = window.width/2; y = window.height/2; this.dx = dx; this.dy = dy; this.color = color; this.width = width; this.height = height; pixmap = new Pixmap (display.default_root, width, height, pf.depth ()); picture = render.create_picture (pixmap, pf, Picture.Attributes.EMPTY); if (sprite_gc == null) sprite_gc = new GC (pixmap); sprite_gc.set_foreground (0); pixmap.rectangle (sprite_gc, 0, 0, width, height, true); sprite_gc.set_foreground (color); pixmap.arc (sprite_gc, 0, 0, width, height, 0, 360*64, true); for (int i=0; i<8; i++) { sprite_gc.set_foreground (divide_color (color, 1<<(7-i))); pixmap.arc (sprite_gc, i, i, width-2*i, height-2*i, 0, 360*64, true); } }
public TileRenderer(Gtk.Image draw, int pixelWidth, int pixelHeight) { _renderTo = draw; _tileCache = "null"; _levelPMap = new Pixmap(_renderTo.GdkWindow, pixelWidth, pixelHeight); _graphicsContext = new Gdk.GC(_renderTo.GdkWindow); }
public NatWidget() { map = new Pixmap (null, Diameter, Diameter, 24); image = new Gtk.Image (map, null); map.Colormap = Gdk.Colormap.System; PackStart (image); DoubleBuffered = true; Redraw (); }
public PreviewRenderer(Preview preview, Layout layout, Pixmap pixmap, GC gc) { _pixmap = pixmap; _gc = gc; _pw = preview.WidthRequest; _ph = preview.HeightRequest; _zoom = layout.Boundaries(_pw, _ph, out _offx, out _offy); }
protected void OnDrawCubeDragBegin(object o, Gtk.DragBeginArgs args) { Pixmap pix = new Pixmap(drawCube.GdkWindow, CubeItem.CubesH * CubePxSize, CubeItem.CubesV * CubePxSize); using (Context cr = Gdk.CairoHelper.Create(pix)) { CubeItem.DrawCube(cr, CubePxSize, true); } Gdk.Pixbuf pixbuf = Gdk.Pixbuf.FromDrawable(pix, Gdk.Colormap.System, 0, 0, 0, 0, CubeItem.CubesH * CubePxSize, CubeItem.CubesV * CubePxSize); ((Gtk.DrawingArea)o).GetPointer(out DragInfo.IconPosX, out DragInfo.IconPosY); Gtk.Drag.SetIconPixbuf(args.Context, pixbuf, DragInfo.IconPosX, DragInfo.IconPosY); DragInfo.FromList = true; DragInfo.cube = CubeItem; }
public ArrowWindow(DockToolbarFrame frame, Direction dir) : base(Gtk.WindowType.Popup) { SkipTaskbarHint = true; Decorated = false; TransientFor = frame.TopWindow; direction = dir; arrow = CreateArrow (); if (direction == Direction.Up || direction == Direction.Down) { width = PointerWidth; height = LineLength + PointerLength + 1; } else { height = PointerWidth; width = LineLength + PointerLength + 1; } // Create the mask for the arrow Gdk.Color black, white; black = new Gdk.Color (0, 0, 0); black.Pixel = 1; white = new Gdk.Color (255, 255, 255); white.Pixel = 0; Gdk.Pixmap pm = new Pixmap (this.GdkWindow, width, height, 1); Gdk.GC gc = new Gdk.GC (pm); gc.Background = white; gc.Foreground = white; pm.DrawRectangle (gc, true, 0, 0, width, height); gc.Foreground = black; pm.DrawPolygon (gc, false, arrow); pm.DrawPolygon (gc, true, arrow); this.ShapeCombineMask (pm, 0, 0); Realize (); redgc = new Gdk.GC (GdkWindow); redgc.RgbFgColor = new Gdk.Color (255, 0, 0); Resize (width, height); }
void CreateShape (int width, int height) { Gdk.Color black, white; black = new Gdk.Color (0, 0, 0); black.Pixel = 1; white = new Gdk.Color (255, 255, 255); white.Pixel = 0; Gdk.Pixmap pm = new Pixmap (this.GdkWindow, width, height, 1); Gdk.GC gc = new Gdk.GC (pm); gc.Background = white; gc.Foreground = white; pm.DrawRectangle (gc, true, 0, 0, width, height); gc.Foreground = black; pm.DrawRectangle (gc, false, 0, 0, width - 1, height - 1); pm.DrawRectangle (gc, false, 1, 1, width - 3, height - 3); this.ShapeCombineMask (pm, 0, 0); }
public Icon(Pixmap color, Pixmap mask) { this.color = color; this.mask = mask; }
public Texture newTexture(Pixmap pixmap) { return(newTexture(pixmap, pixmap.getFormat())); }
private void ActionPixmapCreateTexture(Pixmap pixmap) { Texture.CreateFromPixmap(pixmap); }
public static Gtk.Image GetIcon(object iconified, Color iconColor, int iconSize, bool decor = false) { IconRequest request = new IconRequest(iconified, iconColor, iconSize); if (iconCache.ContainsKey(request)) { return(new Gtk.Image(iconCache[request].color, iconCache[request].mask)); } double pixelSize = iconSize; double size = pixelSize * RESOLUTION_FACTOR; //Since 12 across is 0-11; we don't want to draw on 12 and lose pixels. Pixmap color = new Pixmap(MainWindow.main.GdkWindow, (int)size, (int)size); Pixmap mask = new Pixmap(MainWindow.main.GdkWindow, (int)size, (int)size); Gdk.GC colorGC = new Gdk.GC(color) { RgbFgColor = iconColor }; if (iconified is Threat) { color.DrawRectangle(colorGC, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)size, (int)size)); switch ((Threat)iconified) { case Threat.C: // a circle mask.DrawArc(visible, true, (int)(size * 0.225), (int)(size * 0.225), (int)(size * 0.55), (int)(size * 0.55), 0, FULL_CIRCLE); break; case Threat.B: // A square double squareSize = 0.55 * size; double margin = (size - squareSize) / 2; mask.DrawPolygon(visible, true, new Point[] { new Point((int)margin, (int)margin), new Point((int)(margin + squareSize), (int)margin), new Point((int)(margin + squareSize), (int)(margin + squareSize)), new Point((int)margin, (int)(margin + squareSize)) }); break; case Threat.A: // A triangle with the point upwards. double width = size * 0.75; double height = width * Math.Sqrt(3) / 2; mask.DrawPolygon(visible, true, new Point[] { new Point((int)(size * 0.1), (int)(size - height) / 2), new Point((int)(size * 0.9), (int)(size - height) / 2), new Point((int)(size / 2), (int)(size + height) / 2) }); break; case Threat.S: // A four-pointed star. mask.DrawPolygon(visible, true, new Point[] { new Point(0, (int)(size / 2)), new Point((int)(size / 3), (int)(size / 3)), new Point((int)(size / 2), 0), new Point((int)(size * 2 / 3), (int)(size / 3)), new Point((int)size, (int)(size / 2)), new Point((int)(size * 2 / 3), (int)(size * 2 / 3)), new Point((int)(size / 2), (int)size), new Point((int)(size / 3), (int)(size * 2 / 3)) }); break; case Threat.X: mask.DrawArc(visible, true, (int)(size * 0.05), (int)(size * 0.05), (int)(size * 0.9), (int)(size * 0.9), 0, FULL_CIRCLE); mask.DrawArc(invisible, true, (int)(size * 0.15), (int)(size * 0.15), (int)(size * 0.7), (int)(size * 0.7), 0, FULL_CIRCLE); mask.DrawArc(visible, true, (int)(size * 0.4), (int)(size * 0.4), (int)(size * 0.2), (int)(size * 0.2), 0, FULL_CIRCLE); mask.DrawPoint(visible, (int)(size / 2), (int)(size / 2)); break; } } else if (iconified is StructureType) { if (decor) { color.DrawRectangle(black, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawArc(translucent, true, 0, 0, (int)size, (int)size, 0, FULL_CIRCLE); } else { color.DrawRectangle(colorGC, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)size, (int)size)); } switch ((StructureType)iconified) { case StructureType.Tactical: double width = size * 0.7; double height = size * 0.75; double xMargin = (size - width) / 2; double yMargin = (size - height) / 2; double dipHeight = size * 0.1; double peakHeight = size * 0.3; Vector2 upperLeft = new Vector2(xMargin, yMargin); Vector2 upperRight = upperLeft + new Vector2(width, 0); Vector2 lowerLeft = upperLeft + new Vector2(0, height - peakHeight); Vector2 lowerRight = upperRight + new Vector2(0, height - peakHeight); Vector2 upperMiddle = new Vector2(size / 2, yMargin + dipHeight); Vector2 lowerMiddle = new Vector2(size / 2, size - yMargin); mask.DrawPolygon(visible, true, new Point[] { upperLeft.ToPoint(), upperMiddle.ToPoint(), upperRight.ToPoint(), lowerRight.ToPoint(), lowerMiddle.ToPoint(), lowerLeft.ToPoint() }); if (decor) { color.DrawPolygon(colorGC, true, new Point[] { upperLeft.ToPoint(), upperMiddle.ToPoint(), upperRight.ToPoint(), lowerRight.ToPoint(), lowerMiddle.ToPoint(), lowerLeft.ToPoint() }); } break; case StructureType.Economic: Vector2 center = new Vector2(size / 2, size / 2); double radii = 0.2 * size; double diameter = radii * 2; Vector2 topCenter = center - new Vector2(0, 2 * radii / Math.Sqrt(3)); Vector2 leftCenter = center + new Vector2(radii, Math.Sqrt(2) / 2 * radii); Vector2 rightCenter = center + new Vector2(-radii, Math.Sqrt(2) / 2 * radii); Vector2 topCorner = topCenter - new Vector2(radii, radii); Vector2 leftCorner = leftCenter - new Vector2(radii, radii); Vector2 rightCorner = rightCenter - new Vector2(radii, radii); mask.DrawArc(visible, true, (int)topCorner.x, (int)topCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); if (decor) { color.DrawArc(colorGC, true, (int)topCorner.x, (int)topCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); } mask.DrawArc(visible, true, (int)leftCorner.x, (int)leftCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); if (decor) { color.DrawArc(colorGC, true, (int)leftCorner.x, (int)leftCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); } mask.DrawArc(visible, true, (int)rightCorner.x, (int)rightCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); if (decor) { color.DrawArc(colorGC, true, (int)rightCorner.x, (int)rightCorner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); } break; case StructureType.Aesthetic: double radius1 = size * 0.4; double margin1 = size / 2 - radius1; double radius2 = radius1 * 0.75; double margin2 = size / 2 - radius2; mask.DrawArc(visible, true, (int)margin1, (int)margin1, (int)(radius1 * 2), (int)(radius1 * 2), 0, FULL_CIRCLE); if (decor) { color.DrawArc(colorGC, true, (int)margin1, (int)margin1, (int)(radius1 * 2), (int)(radius1 * 2), 0, FULL_CIRCLE); color.DrawArc(black, true, (int)margin2, (int)margin1, (int)(radius2 * 2), (int)(radius2 * 2), 0, FULL_CIRCLE); mask.DrawArc(translucent, true, (int)margin2, (int)margin1, (int)(radius2 * 2), (int)(radius2 * 2), 0, FULL_CIRCLE); } else { mask.DrawArc(invisible, true, (int)margin2, (int)margin1, (int)(radius2 * 2), (int)(radius2 * 2), 0, FULL_CIRCLE); } break; } } else if (iconified is IconTemplate) { color.DrawRectangle(colorGC, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)size, (int)size)); switch ((IconTemplate)iconified) { case IconTemplate.LeftArrow: mask.DrawPolygon(visible, true, new Point[] { new Point((int)size, 0), new Point(0, (int)(size / 2)), new Point((int)size, (int)size) }); break; case IconTemplate.RightArrow: mask.DrawPolygon(visible, true, new Point[] { new Point(0, 0), new Point((int)size, (int)(size / 2)), new Point(0, (int)size) }); break; case IconTemplate.X: int close = (int)(size / 6); int far = (int)(size * 5 / 6); int end = (int)size; mask.DrawPolygon(visible, true, new Point[] { new Point(close, 0), new Point(end, far), new Point(far, end), new Point(0, close) }); mask.DrawPolygon(visible, true, new Point[] { new Point(far, 0), new Point(0, far), new Point(close, end), new Point(end, close) }); break; } } /* * double radius = 0.55 * size; * double d = radius * 2; * double eyeballRadius = radius * 0.45; * double pupilRadius = eyeballRadius * 0.45; * Vector2 upCenter = new Vector2(size / 2, size / 2 - radius / 2); * Vector2 downCenter = new Vector2(size / 2, size / 2 + radius / 2); * Vector2 upCorner = upCenter - new Vector2(radius, radius); * Vector2 downCorner = downCenter - new Vector2(radius, radius); * mask.DrawArc(visible, true, (int)upCorner.x, (int)upCorner.y, (int)d, (int)d, -30 * 64, -120 * 64); * mask.DrawArc(visible, true, (int)downCorner.x, (int)downCorner.y, (int)d, (int)d, 30 * 64, 120 * 64); * mask.DrawArc(invisible, true, (int)(size / 2 - eyeballRadius), (int)(size / 2 - eyeballRadius), * (int)(eyeballRadius * 2), (int)(eyeballRadius * 2), 0, FULL_CIRCLE); * mask.DrawArc(visible, true, (int)(size / 2 - pupilRadius), (int)(size / 2 - pupilRadius), * (int)(pupilRadius * 2), (int)(pupilRadius * 2), 0, FULL_CIRCLE); */ Pixmap scaledColor = Scale(color, size, size, 0.1); Pixmap scaledMask = Scale(mask, size, size, 0.1); if (PlatformDetection.os == OS.Linux) { scaledMask = Bitmapize(scaledMask, 75); } iconCache.Add(request, new Icon(scaledColor, scaledMask)); return(new Gtk.Image(scaledColor, scaledMask)); }
private void OnFieldDimensionChanged(Field field) { pixmap = null; selection = null; creatingSelection = false; QueueDraw(); }
public static void InputShapeCombineMask (Widget w, Pixmap shape_mask, int offset_x, int offset_y) { gtk_widget_input_shape_combine_mask (w.Handle, shape_mask == null ? IntPtr.Zero : shape_mask.Handle, offset_x, offset_y); }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } DrawTechnique tech = mat.Technique.Res; LightingTechnique lightTech = tech as LightingTechnique; if (tech == null) { continue; } bool isDynamicLighting = lightTech != null || tech.PreferredVertexFormat == VertexC1P3T2A4.Declaration || tech.PreferredVertexFormat == VertexC1P3T4A4A1.Declaration; if (!isDynamicLighting) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { LightingSpriteRenderer sprite = convert.Result.OfType <LightingSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingSpriteRenderer>(); } if (sprite == null) { sprite = new LightingSpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { LightingAnimSpriteRenderer sprite = convert.Result.OfType <LightingAnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <LightingAnimSpriteRenderer>(); } if (sprite == null) { sprite = new LightingAnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
protected override bool OnConfigureEvent(EventConfigure evnt) { pixmap = null; return base.OnConfigureEvent (evnt); }
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; }
// opcode 93 - create cursor /** * @param mask possible: {@link Pixmap#NONE} * @see <a href="XCreatePixmapCursor.html">XCreatePixmapCursor</a> */ public Cursor(Pixmap src, Pixmap mask, int source_char, int mask_char, int fg_r, int fg_g, int fg_b, int bg_r, int bg_g, int bg_b, int x, int y) : base(src.display) { Request request = new Request (display, 93, 8); request.write4 (id); request.write4 (src.id); request.write4 (mask.id); request.write2 (fg_r); request.write2 (fg_g); request.write2 (fg_b); request.write2 (bg_r); request.write2 (bg_g); request.write2 (bg_b); request.write2 (x); request.write2 (y); display.send_request (request); }
public override CustomCursor newCustomCursor(Pixmap p1, Pixmap p2, int i1, int i2) { return(new MonoGameCustomCursor(p1, p2, i1, i2)); }
/** * @param p possible: * {@link Pixmap#NONE} (default) */ public void set_clip_mask(Pixmap p) { set(6, p.id); }
public void Apply(Pixmap pxs) { int len = pxs.Width * pxs.Height; _width = pxs.Width; _height = pxs.Height; _alpha = new int[len]; _red = new int[len]; _green = new int[len]; _blue = new int[len]; Pixel px; for (int i = 0; i < len; i++) { px = pxs[i]; _alpha[i] = px.A; _red[i] = px.R; _green[i] = px.G; _blue[i] = px.B; } // Process var newAlpha = new int[len]; var newRed = new int[len]; var newGreen = new int[len]; var newBlue = new int[len]; Parallel.Invoke( () => gaussBlur_4(_alpha, newAlpha, Radial), () => gaussBlur_4(_red, newRed, Radial), () => gaussBlur_4(_green, newGreen, Radial), () => gaussBlur_4(_blue, newBlue, Radial)); for (int i = 0; i < len; i++) { if (newAlpha[i] > 255) { newAlpha[i] = 255; } if (newRed[i] > 255) { newRed[i] = 255; } if (newGreen[i] > 255) { newGreen[i] = 255; } if (newBlue[i] > 255) { newBlue[i] = 255; } if (newAlpha[i] < 0) { newAlpha[i] = 0; } if (newRed[i] < 0) { newRed[i] = 0; } if (newGreen[i] < 0) { newGreen[i] = 0; } if (newBlue[i] < 0) { newBlue[i] = 0; } px.A = (byte)newAlpha[i]; px.R = (byte)newRed[i]; px.G = (byte)newGreen[i]; px.B = (byte)newBlue[i]; pxs[i] = px; } }
public void Apply(Pixmap lowerLayer, Pixmap topLayer) { throw new NotImplementedException(); }
public SetAtlasRectAction(Pixmap pixmap, int atlasIndex, Rect atlasRect) { this.pixmap = pixmap; this.atlasIndex = atlasIndex; this.rect = atlasRect; }
public static Pixbuf CreateColorSwatch (int size, Color color) { using (var pmap = new Pixmap (Screen.Default.RootWindow, size, size)) using (var gc = new Gdk.GC (pmap)) { gc.RgbFgColor = color; pmap.DrawRectangle (gc, true, 0, 0, size, size); gc.RgbFgColor = new Color (0, 0, 0); pmap.DrawRectangle (gc, false, 0, 0, (size - 1), (size - 1)); return Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, size, size); } }
public MonoGameCustomCursor(Pixmap upPixmap, Pixmap downPixmap, int xHotspot, int yHotspot) : base(upPixmap, downPixmap, xHotspot, yHotspot) { upCursor = MouseCursor.FromTexture2D(((MonoGameTexture)Mdx.graphics.newTexture(upPixmap)).texture2D, xHotspot, yHotspot); downCursor = MouseCursor.FromTexture2D(((MonoGameTexture)Mdx.graphics.newTexture(downPixmap)).texture2D, xHotspot, yHotspot); Mouse.SetCursor(upCursor); }
private void OnExposed(object o, ExposeEventArgs args) { Rectangle area = args.Event.Region.Clipbox; GdkWindow.DrawRectangle(Style.BackgroundGC(StateType.Normal), true, area.X, area.Y, area.Width, area.Height); if (field != null) { if (pixmap == null) { FieldRegion region; pixmap = new Pixmap(GdkWindow, (int) (field.Width * zoomLevel), (int) (field.Height * zoomLevel), -1); region = new FieldRegion(); region.Left = region.Bottom = 0; region.Right = field.Width - 1; region.Top = field.Height - 1; renderer.RenderToDrawable(pixmap, Style.BlackGC, region, null); } GdkWindow.DrawDrawable(Style.BlackGC, pixmap, area.X, area.Y, area.X, area.Y, area.Width, area.Height); if (selection != null) { renderer.RenderToDrawable(GdkWindow, Style.BlackGC, selection, selection); } } }
public override bool Convert(ConvertOperation convert) { List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); if (mainTex == null || basePixmap == null || basePixmap.AnimFrames == 0) { SpriteRenderer sprite = convert.Result.OfType <SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <SpriteRenderer>(); } if (sprite == null) { sprite = new SpriteRenderer(); } sprite.SharedMaterial = mat; if (mainTex != null) { sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, mainTex.PixelWidth, mainTex.PixelHeight); } convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } else { AnimSpriteRenderer sprite = convert.Result.OfType <AnimSpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <AnimSpriteRenderer>(); } if (sprite == null) { sprite = new AnimSpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, (mainTex.PixelWidth / basePixmap.AnimCols) - basePixmap.AnimFrameBorder * 2, (mainTex.PixelHeight / basePixmap.AnimRows) - basePixmap.AnimFrameBorder * 2); sprite.AnimDuration = 5.0f; sprite.AnimFrameCount = basePixmap.AnimFrames; convert.SuggestResultName(sprite, mat.Name); results.Add(sprite); } convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
void ShapeWindow() { Layout (); var bitmap = new Pixmap (GdkWindow, Allocation.Width, Allocation.Height, 1); Context g = CairoHelper.Create (bitmap); DrawShape (g, Allocation.Width, Allocation.Height); g.Dispose (); if (use_shape_ext) ShapeCombineMask (bitmap, 0, 0); else { Context rgba = CairoHelper.Create (GdkWindow); DrawShape (rgba, Allocation.Width, Allocation.Height); rgba.Dispose (); try { CompositeUtils.InputShapeCombineMask (this, bitmap, 0,0); } catch (EntryPointNotFoundException) { Log.Warning ("gtk+ version doesn't support input shapping"); } } bitmap.Dispose (); }
public void drawPixmap(Pixmap pixmap, int x, int y) { drawPixmap(pixmap, x, y, 0, 0, pixmap.getWidth(), pixmap.getHeight()); }
public override bool Convert(ConvertOperation convert) { // If we already have a renderer in the result set, consider generating // another one to be not the right course of action. if (convert.Result.OfType <ICmpRenderer>().Any()) { return(false); } List <object> results = new List <object>(); List <Material> availData = convert.Perform <Material>().ToList(); // Generate objects foreach (Material mat in availData) { if (convert.IsObjectHandled(mat)) { continue; } Texture mainTex = mat.MainTexture.Res; Pixmap basePixmap = (mainTex != null) ? mainTex.BasePixmap.Res : null; GameObject gameobj = convert.Result.OfType <GameObject>().FirstOrDefault(); bool hasAnimation = (mainTex != null && basePixmap != null && basePixmap.Atlas != null && basePixmap.Atlas.Count > 0); // Determine the size of the displayed sprite Vector2 spriteSize; if (hasAnimation) { Rect atlasRect = basePixmap.LookupAtlas(0); spriteSize = atlasRect.Size; } else if (mainTex != null) { spriteSize = mainTex.ContentSize; // If we're dealing with default content, clamp sprite size to // something easily visible in order to avoid 1x1 sprites for // default White / Black or similar fallback textures. if (mainTex.IsDefaultContent) { spriteSize = Vector2.Max(spriteSize, new Vector2(32.0f, 32.0f)); } } else { spriteSize = Pixmap.Checkerboard.Res.Size; } // Create a sprite Component in any case SpriteRenderer sprite = convert.Result.OfType <SpriteRenderer>().FirstOrDefault(); if (sprite == null && gameobj != null) { sprite = gameobj.GetComponent <SpriteRenderer>(); } if (sprite == null) { sprite = new SpriteRenderer(); } sprite.SharedMaterial = mat; sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X, spriteSize.Y); results.Add(sprite); // If we have animation data, create an animator component as well if (hasAnimation) { SpriteAnimator animator = convert.Result.OfType <SpriteAnimator>().FirstOrDefault(); if (animator == null && gameobj != null) { animator = gameobj.GetComponent <SpriteAnimator>(); } if (animator == null) { animator = new SpriteAnimator(); } animator.AnimDuration = 5.0f; animator.FrameCount = basePixmap.Atlas.Count; results.Add(animator); } convert.SuggestResultName(sprite, mat.Name); convert.MarkObjectHandled(mat); } convert.AddResult(results); return(false); }
public GenericGraphicResource RequestGraphicResource(string path, bool async = false) { GenericGraphicResource resource; if (!cachedGraphics.TryGetValue(path, out resource)) { #if UNCOMPRESSED_CONTENT string pathAbsolute = PathOp.Combine(DualityApp.DataDirectory, "Animations", path); #else string pathAbsolute = PathOp.Combine(DualityApp.DataDirectory, ".dz", "Animations", path); #endif SpriteJson json; using (Stream s = FileOp.Open(pathAbsolute + ".res", FileAccessMode.Read)) { lock (jsonParser) { json = jsonParser.Parse <SpriteJson>(s); } } resource = new GenericGraphicResource { FrameDimensions = new Point2(json.FrameSize[0], json.FrameSize[1]), FrameConfiguration = new Point2(json.FrameConfiguration[0], json.FrameConfiguration[1]), FrameDuration = (1f / json.FrameRate) * 5, FrameCount = json.FrameCount }; if (json.Hotspot != null) { resource.Hotspot = new Point2(json.Hotspot[0], json.Hotspot[1]); } if (json.Coldspot != null) { resource.Coldspot = new Point2(json.Coldspot[0], json.Coldspot[1]); resource.HasColdspot = true; } if (json.Gunspot != null) { resource.Gunspot = new Point2(json.Gunspot[0], json.Gunspot[1]); resource.HasGunspot = true; } PixelData pixelData; using (Stream s = FileOp.Open(pathAbsolute, FileAccessMode.Read)) { pixelData = imageCodec.Read(s); } // Use external palette if ((json.Flags & 0x01) != 0x00) { ColorRgba[] palette = paletteTexture.Res.BasePixmap.Res.PixelData[0].Data; ColorRgba[] data = pixelData.Data; Parallel.ForEach(Partitioner.Create(0, data.Length), range => { for (int i = range.Item1; i < range.Item2; i++) { int colorIdx = data[i].R; data[i] = palette[colorIdx].WithAlpha(palette[colorIdx].A * data[i].A / (255f * 255f)); // ToDo: Pinball sprites have strange palette (1-3 indices down), CandionV looks bad, other levels look different } }); } bool linearSampling = (json.Flags & 0x02) != 0x00; Pixmap map = new Pixmap(pixelData); map.GenerateAnimAtlas(resource.FrameConfiguration.X, resource.FrameConfiguration.Y, 0); if (async) { GenericGraphicResourceAsyncFinalize asyncFinalize = new GenericGraphicResourceAsyncFinalize(); asyncFinalize.TextureMap = map; string filenameNormal = pathAbsolute.Replace(".png", ".n.png"); if (FileOp.Exists(filenameNormal)) { asyncFinalize.TextureNormalMap = new Pixmap(imageCodec.Read(FileOp.Open(filenameNormal, FileAccessMode.Read))); } else { resource.TextureNormal = defaultNormalMap; } asyncFinalize.TextureWrap = json.TextureWrap; asyncFinalize.LinearSampling = linearSampling; resource.AsyncFinalize = asyncFinalize; } else { TextureMagFilter magFilter; TextureMinFilter minFilter; if (linearSampling) { magFilter = TextureMagFilter.Linear; minFilter = TextureMinFilter.LinearMipmapLinear; } else { magFilter = TextureMagFilter.Nearest; minFilter = TextureMinFilter.Nearest; } resource.Texture = new Texture(map, TextureSizeMode.NonPowerOfTwo, magFilter, minFilter, json.TextureWrap, json.TextureWrap); string filenameNormal = pathAbsolute.Replace(".png", ".n.png"); if (FileOp.Exists(filenameNormal)) { pixelData = imageCodec.Read(FileOp.Open(filenameNormal, FileAccessMode.Read)); resource.TextureNormal = new Texture(new Pixmap(pixelData), TextureSizeMode.NonPowerOfTwo, magFilter, minFilter, json.TextureWrap, json.TextureWrap); resource.TextureNormal.Res.DetachPixmap(); } else { resource.TextureNormal = defaultNormalMap; } } cachedGraphics[path] = resource; } resource.Referenced = true; return(resource); }
private void CreatePixmaps() { GCValues shapeGCV; //Create a 1 depth pixmap used as a shape //that will contain the info about transparency shape = new Pixmap (null, Gdk.Screen.Default.Width, Gdk.Screen.Default.Height, 1); shapeGC = new Gdk.GC (shape); shapeGCV = new GCValues (); shapeGC.GetValues (shapeGCV); transparent = shapeGCV.Foreground; opaque = shapeGCV.Background; shapeGC.Foreground = transparent; shape.DrawRectangle (shapeGC, true, 0, 0, Gdk.Screen.Default.Width, Gdk.Screen.Default.Height); shapeGC.Background = opaque; ShapeCombineMask (shape, 0, 0); //Create the pixmap that will contain the real drawing //Used on Expose event to redraw the drawing area pixmap = new Pixmap (drawingarea.GdkWindow, Gdk.Screen.Default.Width, Gdk.Screen.Default.Height); pixmap.DrawRectangle (drawingarea.Style.BlackGC, true, 0, 0, Gdk.Screen.Default.Width, Gdk.Screen.Default.Height); }
private static bool IsMatch(Pixmap source, Tileset target) { return (target.RenderConfig != null && target.RenderConfig.Any(config => config.SourceData == source)); }
public static Gtk.Image GetAlert(IBattleground battleground, int iconSize) { Color attackerColor = new Color(); Color defenderColor = new Color(); Color victorColor = new Color(); Color trim; if (battleground.attackers != null) { attackerColor = battleground.attackers.affiliation.color; } if (battleground.defenders != null) { defenderColor = battleground.defenders.affiliation.color; } if (battleground.battle != null) { victorColor = battleground.battle.victor.affiliation.color; } if (Battle.Relevant(battleground, Game.player)) { trim = new Color(0, 0, 0); } else { trim = new Color(50, 50, 50); attackerColor.Red = (ushort)((attackerColor.Red + 150) / 2); attackerColor.Green = (ushort)((attackerColor.Green + 150) / 2); attackerColor.Blue = (ushort)((attackerColor.Blue + 150) / 2); defenderColor.Red = (ushort)((defenderColor.Red + 150) / 2); defenderColor.Green = (ushort)((defenderColor.Green + 150) / 2); defenderColor.Blue = (ushort)((defenderColor.Blue + 150) / 2); } double pixelSize = iconSize; double size = pixelSize * RESOLUTION_FACTOR; //Since 12 across is 0-11; we don't want to draw on 12 and lose pixels. double margin = BLACK_TRIM_WIDTH * RESOLUTION_FACTOR; Pixmap color = new Pixmap(MainWindow.main.GdkWindow, (int)size, (int)size); Pixmap mask = new Pixmap(MainWindow.main.GdkWindow, (int)size, (int)size); color.DrawRectangle(new Gdk.GC(color) { RgbFgColor = trim }, true, new Rectangle(0, 0, (int)size, (int)size)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)size, (int)size)); Gdk.GC attacker = new Gdk.GC(color) { RgbFgColor = attackerColor }; Gdk.GC defender = new Gdk.GC(color) { RgbFgColor = defenderColor }; Gdk.GC victor = new Gdk.GC(color) { RgbFgColor = victorColor }; Gdk.GC swordsMask = battleground.battle == null ? visible : translucent; //blade constants double bsize = size * 0.15; //The antidiagonal size of the blade (width/sqrt(2)) double m2 = margin * Math.Sqrt(2); double m3 = m2 - margin; if (battleground.attackers != null) { Vector2 A = new Vector2(0, size - bsize); Vector2 B = new Vector2(bsize, size); Vector2 C = new Vector2(size - bsize, 0); Vector2 D = new Vector2(size, bsize); Vector2 E = new Vector2(size, 0); mask.DrawPolygon(swordsMask, true, new Point[] { A, B, D, E, C }); Vector2 P = new Vector2(0.05, 0.65) * size; Vector2 Q = new Vector2(0.2, 0.5) * size; Vector2 R = new Vector2(0.35, 0.95) * size; Vector2 S = new Vector2(0.5, 0.8) * size; mask.DrawPolygon(swordsMask, true, new Point[] { P, Q, S, R }); Vector2 A2 = A + new Vector2(m2, 0); Vector2 B2 = B - new Vector2(0, m2); Vector2 C2 = C + new Vector2(m3, margin); Vector2 D2 = D - new Vector2(margin, m3); Vector2 E2 = E - new Vector2(margin, -margin); color.DrawPolygon(attacker, true, new Point[] { A2, B2, D2, E2, C2 }); Vector2 P2 = P + new Vector2(m2, 0); Vector2 Q2 = Q + new Vector2(0, m2); Vector2 R2 = R - new Vector2(0, m2); Vector2 S2 = S - new Vector2(m2, 0); color.DrawPolygon(attacker, true, new Point[] { P2, Q2, S2, R2 }); } if (battleground.defenders != null) { Vector2 a = new Vector2(size, size - bsize); Vector2 b = new Vector2(size - bsize, size); Vector2 c = new Vector2(bsize, 0); Vector2 d = new Vector2(0, bsize); Vector2 e = new Vector2(0, 0); mask.DrawPolygon(swordsMask, true, new Point[] { a, b, d, e, c }); Vector2 p = new Vector2(0.95, 0.65) * size; Vector2 q = new Vector2(0.8, 0.5) * size; Vector2 r = new Vector2(0.65, 0.95) * size; Vector2 s = new Vector2(0.5, 0.8) * size; mask.DrawPolygon(swordsMask, true, new Point[] { p, q, s, r }); Vector2 a2 = a - new Vector2(m2, 0); Vector2 b2 = b - new Vector2(0, m2); Vector2 c2 = c + new Vector2(-m3, margin); Vector2 d2 = d - new Vector2(-margin, m3); Vector2 e2 = e + new Vector2(margin, margin); color.DrawPolygon(defender, true, new Point[] { a2, b2, d2, e2, c2 }); Vector2 p2 = p - new Vector2(m2, 0); Vector2 q2 = q + new Vector2(0, m2); Vector2 r2 = r - new Vector2(0, m2); Vector2 s2 = s + new Vector2(m2, 0); color.DrawPolygon(defender, true, new Point[] { p2, q2, s2, r2 }); } if (battleground.battle != null) { const double a = 0.95106; //sin 72 P const double b = 0.30902; //cos 72 / \ const double c = 0.58779; //sin 36 T__Z/ \U__Q const double d = 0.80902; //cos 36 \_ O _/ const double ml = 3.0457; //OP margin Y/ _ \V const double ms = 1.2183; //OU margin /_/ X \_\ // S R //The unit vectors in the directions of each of the points, with O as origin Vector2 nP = new Vector2(+0, -1); Vector2 nU = new Vector2(c, -d); Vector2 nQ = new Vector2(+a, -b); Vector2 nV = new Vector2(a, b); Vector2 nR = new Vector2(+c, +d); Vector2 nX = new Vector2(0, 1); Vector2 nS = new Vector2(-c, +d); Vector2 nY = new Vector2(-a, b); Vector2 nT = new Vector2(-a, -b); Vector2 nZ = new Vector2(-c, -d); //Scale them and translate by (size/2, size/2) to correct origin double r = size / 2; double r2 = size / 5; double ir = r - ml * margin; double ir2 = r2 - ms * margin; Vector2 center = new Vector2(r, r); Vector2 P = center + r * nP; Vector2 U = center + r2 * nU; Vector2 Q = center + r * nQ; Vector2 V = center + r2 * nV; Vector2 R = center + r * nR; Vector2 X = center + r2 * nX; Vector2 S = center + r * nS; Vector2 Y = center + r2 * nY; Vector2 T = center + r * nT; Vector2 Z = center + r2 * nZ; Vector2 iP = center + ir * nP; Vector2 iU = center + ir2 * nU; Vector2 iQ = center + ir * nQ; Vector2 iV = center + ir2 * nV; Vector2 iR = center + ir * nR; Vector2 iX = center + ir2 * nX; Vector2 iS = center + ir * nS; Vector2 iY = center + ir2 * nY; Vector2 iT = center + ir * nT; Vector2 iZ = center + ir2 * nZ; mask.DrawPolygon(visible, true, new Point[] { P, U, Q, V, R, X, S, Y, T, Z }); color.DrawPolygon(black, true, new Point[] { P, U, Q, V, R, X, S, Y, T, Z }); color.DrawPolygon(victor, true, new Point[] { iP, iU, iQ, iV, iR, iX, iS, iY, iT, iZ }); } /*The shaft * double width = size / 4.5; * double height = width * 3; * Vector2 corner = new Vector2(size / 2 - width / 2, 0); * double width2 = width - margin * 2; * double height2 = height - margin * 2; * Vector2 corner2 = corner + new Vector2(margin, margin); * mask.DrawRectangle(visible, true, new Rectangle((int)corner.x, (int)corner.y, (int)width, (int)height)); * color.DrawRectangle(attacker, true, new Rectangle((int)corner2.x, (int)corner2.y, (int)width2, (int)height2)); * //The bulb * double diameter = width; * double radius = diameter / 2; * corner = new Vector2(size / 2 - radius, size - diameter); * double diameter2 = diameter - margin * 2; * double radius2 = diameter2 / 2; * corner2 = corner + new Vector2(margin, margin); * mask.DrawArc(visible, true, (int)corner.x, (int)corner.y, (int)diameter, (int)diameter, 0, FULL_CIRCLE); * color.DrawArc(attacker, true, (int)corner2.x, (int)corner2.y, (int)diameter2, (int)diameter2, 0, FULL_CIRCLE); */ Pixmap scaledColor = Scale(color, size, size, 0.1); Pixmap scaledMask = Scale(mask, size, size, 0.1); if (PlatformDetection.os == OS.Linux) { scaledMask = Bitmapize(scaledMask, 75); } return(new Gtk.Image(scaledColor, scaledMask)); }
protected override bool OnConfigureEvent(EventConfigure evnt) { pixmap = null; return(base.OnConfigureEvent(evnt)); }
public static Gtk.Image GetLocationPin(Color pinColor, int pinWidth, int pinHeight) { double pixelWidth = pinWidth; double pixelHeight = pinHeight; //Independent quantities double w = pixelWidth * RESOLUTION_FACTOR; double r = w / 2; double h = pixelHeight * RESOLUTION_FACTOR; double m = BLACK_TRIM_WIDTH * RESOLUTION_FACTOR; //Dependent quantities double v = Math.Sqrt(h * h - h * w); double u = r / (h - r); Pixmap color = new Pixmap(MainWindow.main.GdkWindow, (int)w, (int)h); Pixmap mask = new Pixmap(MainWindow.main.GdkWindow, (int)w, (int)h); Gdk.GC markerShape = new Gdk.GC(color) { RgbFgColor = pinColor }; color.DrawRectangle(black, true, new Rectangle(0, 0, (int)w, (int)h)); mask.DrawRectangle(invisible, true, new Rectangle(0, 0, (int)w, (int)h)); color.DrawArc(markerShape, true, (int)m, (int)m, (int)(w - m * 2), (int)(w - m * 2), 0, FULL_CIRCLE); mask.DrawArc(visible, true, 0, 0, (int)w, (int)w, 0, FULL_CIRCLE); // The "triangle" here refers to the triangle formed by the bottom vertex, a tangent point and the bottom of the image. // // ------- --- Independent quantities: // / | \ | r = radius of circle // | |_____| | h = height of pin // | | r | | m = thickness of black trim // \ | /. h // \ | / . | Dependent quantities: // \ |θ /v . | θ = angle between axis of symmetry and the sides of the spear // \ |^/ . | u = sin θ // \|/..... _|_ v = hypotenuse of the spear // r // // [center] O___ // | ---___[innerRight] // | O--___ // |________/______--O [outerRight] // | / / // | / / // | / / // | / / // | / / // | / / // | / / // |/ / v // [innerBottom] O--___ / // | m --/ // | / // | / // | / // | / // |θ / // |^/ // |/ // [outerBottom] O Vector2 center = new Vector2(r, r); Vector2 outerBottom = new Vector2(w / 2, h); Vector2 innerBottom = new Vector2(r, h - m / u); Vector2 outerLeft = center + new Vector2(-u * v, u * r); Vector2 outerRight = center + new Vector2(u * v, u * r); Vector2 innerLeft = outerLeft - new Vector2(-m * u * v / r, u * m); Vector2 innerRight = outerRight - new Vector2(m * u * v / r, u * m); //u*v/r = cos θ. color.DrawPolygon(markerShape, true, new Point[] { innerBottom.ToPoint(), innerLeft.ToPoint(), innerRight.ToPoint() }); mask.DrawPolygon(visible, true, new Point[] { outerBottom.ToPoint(), outerLeft.ToPoint(), outerRight.ToPoint() }); double coreRadius = w / 5; double coreCenter = w / 2; color.DrawArc(black, true, (int)(coreCenter - coreRadius - m), (int)(coreCenter - coreRadius - m), (int)(coreRadius * 2 + m * 2), (int)(coreRadius * 2 + m * 2), 0, FULL_CIRCLE); mask.DrawArc(film, true, (int)(coreCenter - coreRadius), (int)(coreCenter - coreRadius), (int)(coreRadius * 2), (int)(coreRadius * 2), 0, FULL_CIRCLE); Pixmap scaledColor = Scale(color, w, h, 0.1); Pixmap scaledMask = Scale(mask, w, h, 0.1); if (PlatformDetection.os == OS.Linux) { scaledMask = Bitmapize(scaledMask, 128); } return(new Gtk.Image(scaledColor, scaledMask)); }
protected override bool OnExposeEvent(EventExpose evnt) { pixmap = new Pixmap(GdkWindow, Allocation.Width, Allocation.Height); Draw(); return(base.OnExposeEvent(evnt)); }
void OnConfigured(object o, ConfigureEventArgs args) { pixmap = new Pixmap (args.Event.Window, Allocation.Width, Allocation.Height); cairo = Gdk.CairoHelper.Create (pixmap); cairo.Rectangle (0, 0, Allocation.Width, Allocation.Height); cairo.Clip (); ArrayList oldlist = points; points = new ArrayList (); ComputePositions (); foreach (GraphPoint point in oldlist) { __AddGameInfo (point.info); } UpdatePixmap (); }
/// <summary> /// Triggered when the drawing area is configured. /// </summary> private void OnConfigure( object obj, ConfigureEventArgs args) { // Pull out some fields EventConfigure ev = args.Event; Window window = ev.Window; int width = Allocation.Width; int height = Allocation.Height; int min = Math.Min(width, height); viewport.Height = height; viewport.Width = width; // Create the backing pixmap pixmap = new Pixmap(window, width, height, -1); // Update the current pane if (Sprite != null) { Sprite.Height = Sprite.Width = ((int) (min * 0.75)); } // Mark ourselves as done args.RetVal = true; }
public AtlasSprite(Pixmap map, int index) { Pixmap = map; Index = index; }
// Create a new pixmap of the appropriate size to store our scribbles private void ScribbleConfigure (object o, ConfigureEventArgs args) { Widget widget = o as Widget; Rectangle allocation = widget.Allocation; pixmap = new Pixmap (widget.GdkWindow, allocation.Width, allocation.Height, -1); // Initialize the pixmap to white pixmap.DrawRectangle (widget.Style.WhiteGC, true, 0, 0, allocation.Width, allocation.Height); // We've handled the configure event, no need for further processing. args.RetVal = true; }
public static Pixbuf CreateTransparentColorSwatch (bool drawBorder) { var size = 16; using (var pmap = new Pixmap (Screen.Default.RootWindow, size, size)) using (var gc = new Gdk.GC (pmap)) { gc.RgbFgColor = new Color (255, 255, 255); pmap.DrawRectangle (gc, true, 0, 0, size, size); gc.RgbFgColor = new Color (200, 200, 200); pmap.DrawRectangle (gc, true, 0, 0, (size / 2), (size / 2)); pmap.DrawRectangle (gc, true, size / 2, size / 2, (size / 2), (size / 2)); if (drawBorder) { gc.RgbFgColor = new Color (0, 0, 0); pmap.DrawRectangle (gc, false, 0, 0, (size - 1), (size - 1)); } return Pixbuf.FromDrawable (pmap, pmap.Colormap, 0, 0, 0, 0, size, size); } }
/// <summary> /// Compiles a <see cref="Tileset"/> using its specified source data, in order to /// generate optimized target data for rendering and collision detection. /// </summary> public TilesetCompilerOutput Compile(TilesetCompilerInput input) { TilesetCompilerOutput output = input.ExistingOutput; output.TileData = output.TileData ?? new RawList <TileInfo>(input.TileInput.Count); output.RenderData = output.RenderData ?? new List <Texture>(); output.AutoTileData = output.AutoTileData ?? new List <TilesetAutoTileInfo>(); // Clear existing data, but keep the sufficiently big data structures output.TileData.Clear(); output.RenderData.Clear(); output.AutoTileData.Clear(); // Determine how many source tiles we have int sourceTileCount = int.MaxValue; for (int renderInputIndex = 0; renderInputIndex < input.RenderConfig.Count; renderInputIndex++) { TilesetRenderInput renderInput = input.RenderConfig[renderInputIndex] ?? DefaultRenderInput; PixelData sourceLayerData = (renderInput.SourceData.Res ?? Pixmap.Checkerboard.Res).MainLayer; LayerGeometry layerGeometry = this.CalculateLayerGeometry(renderInput, sourceLayerData); sourceTileCount = Math.Min(sourceTileCount, layerGeometry.SourceTileCount); } if (input.RenderConfig.Count == 0) { sourceTileCount = 0; } // Transform AutoTile data for (int autoTileIndex = 0; autoTileIndex < input.AutoTileConfig.Count; autoTileIndex++) { TilesetAutoTileInput autoTileInput = input.AutoTileConfig[autoTileIndex]; TilesetAutoTileInfo autoTileInfo = this.TransformAutoTileData( autoTileIndex, autoTileInput, output.TileData, sourceTileCount); output.AutoTileData.Add(autoTileInfo); } // Initialize all tiles to being visually empty. They will be subtractively updated // during output pixel data generation in the next step. { int tileDataCount = output.TileData.Count; TileInfo[] tileData = output.TileData.Data; for (int i = 0; i < tileDataCount; i++) { tileData[i].IsVisuallyEmpty = true; } } // Generate output pixel data for (int renderInputIndex = 0; renderInputIndex < input.RenderConfig.Count; renderInputIndex++) { TilesetRenderInput renderInput = input.RenderConfig[renderInputIndex] ?? DefaultRenderInput; PixelData sourceLayerData = (renderInput.SourceData.Res ?? Pixmap.Checkerboard.Res).MainLayer; // Determine overal geometry values for this layer, such as tile bounds and texture sizes LayerGeometry layerGeometry = this.CalculateLayerGeometry(renderInput, sourceLayerData); // Generate pixel data and atlas values for this layer's texture LayerPixelData targetLayerData = this.GenerateLayerPixelData( renderInput, sourceLayerData, layerGeometry, output.TileData); // Create the texture to be used for this rendering input using (Pixmap targetPixmap = new Pixmap(targetLayerData.PixelData)) { targetPixmap.Atlas = targetLayerData.Atlas; Texture targetTexture = new Texture( targetPixmap, TextureSizeMode.Enlarge, renderInput.TargetMagFilter, renderInput.TargetMinFilter, TextureWrapMode.Clamp, TextureWrapMode.Clamp, renderInput.TargetFormat); output.RenderData.Add(targetTexture); } } // Generate additional per-tile data this.TransformTileData(input.TileInput, output.TileData, output.RenderData); // Apply global tileset stats output.TileCount = sourceTileCount; return(output); }
protected override bool OnExposeEvent(EventExpose evnt) { pixmap = new Pixmap (GdkWindow, Allocation.Width, Allocation.Height); Draw (); return base.OnExposeEvent (evnt); }
/// <summary> /// Triggered when the drawing area is configured. /// </summary> private void OnConfigure( object obj, ConfigureEventArgs args) { // Pull out some fields and figure out the sizes EventConfigure ev = args.Event; Window window = ev.Window; int width = Allocation.Width; int height = Allocation.Height; int min = Math.Min(width, height); // Figure out the tile height tileSize = min / Game.Board.Size; log.Info("New tile size: {0}px", tileSize); // Adjust the viewport height viewport.Height = height; viewport.Width = width; // Create the backing pixmap pixmap = new Pixmap(window, width, height, -1); // We moved, so rapid move the tiles foreach (ISprite sprite in sprites) { ContainerSprite cs = sprite as ContainerSprite; if (cs != null) { cs.FireInvalidate(); cs.X = cs.TokenSprite.X = tileSize * cs.TokenSprite.Token.Column; cs.FireInvalidate(); } } // Mark ourselves as done QueueDraw(); args.RetVal = true; }
private void OnFieldBlockChanged(Field field) { pixmap = null; QueueDraw(); }
void DestroyBgBuffer () { if (curUpdate != null) curUpdate.RemoveHandler (); if (backgroundPixbuf != null) { backgroundPixbuf.Dispose (); backgroundBuffer.Dispose (); backgroundPixbuf = backgroundBuffer = null; curWidth = curHeight = -1; } }
protected void OnDrawCupboardDragBegin(object o, DragBeginArgs args) { int MousePosX, MousePosY; drawCupboard.GetPointer(out MousePosX, out MousePosY); int CubePosX = (MousePosX - OrderCupboard.CupboardZeroX) / CubePxSize; int CubePosY = (MousePosY - OrderCupboard.CupboardZeroY) / CubePxSize; Cube cube = OrderCupboard.GetCube(CubePosX, CubePosY); if(cube == null) { args.RetVal = false; Gdk.Drag.Abort(args.Context, args.Context.StartTime); return; } Pixmap pix = new Pixmap(drawCupboard.GdkWindow, cube.CubesH * CubePxSize, cube.CubesV * CubePxSize); using (Context cr = Gdk.CairoHelper.Create(pix)) { cube.DrawCube(cr, CubePxSize, true); } Gdk.Pixbuf pixbuf = Gdk.Pixbuf.FromDrawable(pix, Gdk.Colormap.System, 0, 0, 0, 0, cube.CubesH * CubePxSize, cube.CubesV * CubePxSize); CurrentDrag.IconPosX = MousePosX - OrderCupboard.CupboardZeroX - (cube.BoardPositionX * CubePxSize); CurrentDrag.IconPosY = MousePosY - OrderCupboard.CupboardZeroY - (cube.BoardPositionY * CubePxSize); Gtk.Drag.SetIconPixbuf(args.Context, pixbuf, CurrentDrag.IconPosX, CurrentDrag.IconPosY); CurrentDrag.FromList = false; CurrentDrag.cube = cube; }
void CreateBgBuffer () { DestroyBgBuffer (); curWidth = Allocation.Width; curHeight = Math.Max (Allocation.Height, (int)(lineHeight * TextEditor.GetTextEditorData ().VisibleLineCount)); if (GdkWindow == null || curWidth < 1 || curHeight < 1) return; backgroundPixbuf = new Pixmap (GdkWindow, curWidth, curHeight); backgroundBuffer = new Pixmap (GdkWindow, curWidth, curHeight); if (TextEditor.ColorStyle != null) { using (var cr = Gdk.CairoHelper.Create (backgroundPixbuf)) { cr.Rectangle (0, 0, curWidth, curHeight); cr.Color = TextEditor.ColorStyle.Default.CairoBackgroundColor; cr.Fill (); } } curUpdate = new BgBufferUpdate (this); }
public static extern Status XFreePixmap(IntPtr display, Pixmap pixmap);
public void DrawTiles(Graphics g, Point p, Rectangle terrainRectangle, Func <Point, int> terrain) { // Calculate and clip screen coordinates of terrain var sx1 = Math.Max(p.X + terrainRectangle.Left * TileSize, (int)g.ClipBounds.Left); var sy1 = Math.Max(p.Y + terrainRectangle.Top * TileSize, (int)g.ClipBounds.Top); var sx2 = Math.Min(p.X + terrainRectangle.Right * TileSize, (int)g.ClipBounds.Right); var sy2 = Math.Min(p.Y + terrainRectangle.Bottom * TileSize, (int)g.ClipBounds.Bottom); if (sx1 >= sx2 || sy1 >= sy2) { return; } // Calculate clipped terrain coordinates var tx1 = (sx1 - p.X) / TileSize; var ty1 = (sy1 - p.Y) / TileSize; var tx2 = (sx2 - p.X) / TileSize; var ty2 = (sy2 - p.Y) / TileSize; // Prepare pixmap; pixmap covers screen coordinates (sx1,sy1) to (sx2,sy2) if (_Pixmap == null || _Pixmap.Width != sx2 - sx1 || _Pixmap.Height != sy2 - sy1) { _Pixmap = new Pixmap(sx2 - sx1, sy2 - sy1); } // Prepare layers pixmaps if (_PixmapsTileSize != TileSize) { foreach (var layer in _Layers) { layer.CreatePixmaps(TileSize); } _PixmapsTileSize = TileSize; } // Prepare terrain cache int originX = tx1 - 1; int originY = ty1 - 1; int sizeX = tx2 - tx1 + 2 + 2; int sizeY = ty2 - ty1 + 2 + 2; if (_Terrain == null || _Terrain.Length != sizeX * sizeY) { _Terrain = new int[sizeX * sizeY]; } for (int y = 0; y < sizeY; ++y) { for (int x = 0; x < sizeX; ++x) { _Terrain[x + y * sizeX] = terrain(new Point(x + originX, y + originY)); } } // Draw all layers foreach (var layer in _Layers) { if (layer.Layout == LayerLayout.Corners) { // For all terrain locations to draw Parallel.For(ty1, ty2 + 2, ty => // for (int ty = ty1; ty < ty2 + 2; ++ty) { for (int tx = tx1; tx < tx2 + 2; ++tx) { // Get pixmap position of terrain location int px = tx * TileSize + p.X - sx1 - TileSize / 2; int py = ty * TileSize + p.Y - sy1 - TileSize / 2; // Get layers masks of surrounding terrain locations (corners) int cmask1 = _Terrain[(tx - originX - 1) + (ty - originY - 1) * sizeX]; int cmask2 = _Terrain[(tx - originX) + (ty - originY - 1) * sizeX]; int cmask3 = _Terrain[(tx - originX - 1) + (ty - originY) * sizeX]; int cmask4 = _Terrain[(tx - originX) + (ty - originY) * sizeX]; // Prepare seed for selecting random variations of tiles int seed = tx | (ty << 16); // Draw tile int code = 0; if ((cmask1 & layer.ConnectionsMask) != 0) { code += 1; } if ((cmask2 & layer.ConnectionsMask) != 0) { code += 2; } if ((cmask3 & layer.ConnectionsMask) != 0) { code += 4; } if ((cmask4 & layer.ConnectionsMask) != 0) { code += 8; } if (code != 0) { Point coords = layer.GetTileCoords(code, seed); var srcRect = new Rectangle(TileSize * coords.X, TileSize * coords.Y, TileSize, TileSize); if (layer.WrapPixmap != null) { Pixmap.Draw2(layer.TilesPixmap, layer.WrapPixmap, _Pixmap, srcRect, new Point(tx * TileSize, ty * TileSize), new Point(px, py)); } else { Pixmap.Draw(layer.TilesPixmap, _Pixmap, srcRect, px, py); } } } }); } else { // For all terrain locations to draw Parallel.For(ty1, ty2 + 1, ty => //for (int ty = ty1; ty < ty2 + 1; ++ty) { for (int tx = tx1; tx < tx2 + 1; ++tx) { // If location contains this layer int mask = terrain(new Point(tx, ty)); if ((mask & layer.Mask) != 0) { // Get pixmap position of terrain location int px = tx * TileSize + p.X - sx1; int py = ty * TileSize + p.Y - sy1; // Get layers masks of surrounding terrain locations (sides) //int lmask = terrain(new Point(tx - 1, ty)); //int umask = terrain(new Point(tx, ty - 1)); //int rmask = terrain(new Point(tx + 1, ty)); //int dmask = terrain(new Point(tx, ty + 1)); int lmask = _Terrain[(tx - originX - 1) + (ty - originY) * sizeX]; int umask = _Terrain[(tx - originX) + (ty - originY - 1) * sizeX]; int rmask = _Terrain[(tx - originX + 1) + (ty - originY) * sizeX]; int dmask = _Terrain[(tx - originX) + (ty - originY + 1) * sizeX]; // Prepare seed for selecting random variations of tiles int seed = tx | (ty << 16); // Draw tile int code = 0; if ((lmask & layer.ConnectionsMask) != 0) { code += 1; } if ((umask & layer.ConnectionsMask) != 0) { code += 2; } if ((rmask & layer.ConnectionsMask) != 0) { code += 4; } if ((dmask & layer.ConnectionsMask) != 0) { code += 8; } Point coords = layer.GetTileCoords(code, seed); var srcRect = new Rectangle(TileSize * coords.X, TileSize * coords.Y, TileSize, TileSize); if (layer.WrapPixmap != null) { Pixmap.Draw2(layer.TilesPixmap, layer.WrapPixmap, _Pixmap, srcRect, new Point(tx * TileSize, ty * TileSize), new Point(px, py)); } else { Pixmap.Draw(layer.TilesPixmap, _Pixmap, srcRect, px, py); } } } }); } } // Copy pixmap to graphics g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed; g.DrawImageUnscaled(_Pixmap.Bitmap, new Point(sx1, sy1)); }
public static void InputShapeCombineMask(Widget w, Pixmap shape_mask, int offset_x, int offset_y) { gtk_widget_input_shape_combine_mask(w.Handle, shape_mask == null ? IntPtr.Zero : shape_mask.Handle, offset_x, offset_y); }
/// <summary> /// Triggered when the drawing area is configured. /// </summary> private void OnConfigure( object obj, ConfigureEventArgs args) { // Pull out some fields EventConfigure ev = args.Event; Window window = ev.Window; int width = Allocation.Width; int height = Allocation.Height; // Create the backing pixmap pixmap = new Pixmap(window, width, height, -1); // Update the current pane // TODO, there is a bug with this and I don't know why if (currentPane != null) { currentPane.Configure(width, height - 50); } // Mark ourselves as done args.RetVal = true; }
private void OnWidgetDestroyed (object sender, EventArgs args) { if (!IsRealized) { return; } canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height); if (Platform.IsMac) { //FIXME: quick hack to make less ugly on Mac, because Mac GTK doesn't yet support offscreen drawing canvas.DrawRectangle (Style.BackgroundGC (State), true, 0, 0, widget_alloc.Width, widget_alloc.Height); } else { canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow, widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height); } if (AnimationState != AnimationState.Going) { WidgetDestroyed (this, args); } }
/// <summary> /// Compiles a <see cref="Tileset"/> using its specified source data, in order to /// generate optimized target data for rendering and collision detection. /// </summary> public TilesetCompilerOutput Compile(TilesetCompilerInput input) { // Clear private working data before beginning a new operation this.ClearWorkingData(); // Initialize private working data with the required space for our new input this.InitWorkingData(input); // Gather data on AutoTiles that are partially transformed from the input tileset, // and partially generated from existing tiles as part of the compilation. this.GatherAutoTileData(input.AutoTileConfig); // Generate metadata for scheduled tiles this.GenerateTileMetadata(); // Draw output pixel data for (int renderInputIndex = 0; renderInputIndex < input.RenderConfig.Count; renderInputIndex++) { TilesetRenderInput renderInput = input.RenderConfig[renderInputIndex] ?? DefaultRenderInput; PixelData sourceLayerData = (renderInput.SourceData.Res ?? Pixmap.Checkerboard.Res).MainLayer; // Determine overall geometry values for this layer, such as tile bounds and texture sizes LayerGeometry layerGeometry = this.CalculateLayerGeometry(renderInput, sourceLayerData); // Generate pixel data and atlas values for this layer's texture LayerPixelData targetLayerData = this.ComposeLayerPixelData( renderInput, sourceLayerData, layerGeometry); // Create the texture to be used for this rendering input using (Pixmap targetPixmap = new Pixmap(targetLayerData.PixelData)) { targetPixmap.Atlas = targetLayerData.Atlas; Texture targetTexture = new Texture( targetPixmap, TextureSizeMode.Enlarge, renderInput.TargetMagFilter, renderInput.TargetMinFilter, TextureWrapMode.Clamp, TextureWrapMode.Clamp, renderInput.TargetFormat); this.renderData.Add(targetTexture); } } // Retrieve texture atlas data for quick lookup during rendering if (this.renderData.Count > 0) { for (int i = 0; i < this.tiles.Count; i++) { this.renderData[0].LookupAtlas(i, out this.tiles.Data[i].TexCoord0); } } // Prepare output, keeping existing structures to avoid allocations TilesetCompilerOutput output = input.ExistingOutput; output.TileCount = this.outputTileCount; output.TileData = output.TileData ?? new RawList <TileInfo>(input.TileInput.Count); output.TileData.Clear(); this.tiles.CopyTo(output.TileData, 0, this.tiles.Count); output.RenderData = output.RenderData ?? new List <Texture>(this.renderData); output.RenderData.Clear(); output.RenderData.AddRange(this.renderData); output.AutoTileData = output.AutoTileData ?? new List <TilesetAutoTileInfo>(); output.AutoTileData.Clear(); this.TransformAutoTileData(output.AutoTileData); output.EmptyTileIndex = this.GetEmptyTileIndex(); this.ClearWorkingData(); return(output); }
void SwapBuffer () { var tmp = backgroundPixbuf; backgroundPixbuf = backgroundBuffer; backgroundBuffer = tmp; }
private void OnWidgetDestroyed (object sender, EventArgs args) { if (!IsRealized) { return; } canvas = new Pixmap (GdkWindow, widget_alloc.Width, widget_alloc.Height); canvas.DrawDrawable (Style.BackgroundGC (State), GdkWindow, widget_alloc.X, widget_alloc.Y, 0, 0, widget_alloc.Width, widget_alloc.Height); if (AnimationState != AnimationState.Going) { WidgetDestroyed (this, args); } }
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); }
public void ReimportFile(ContentRef <Resource> r, string srcFile) { Pixmap p = r.Res as Pixmap; p.LoadPixelData(srcFile); }
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 static extern Cursor XCreatePixmapCursor(IntPtr display, Pixmap source, Pixmap mask, ref XColor foreground_color, ref XColor background_color, uint x, uint y);