Skip to content

Commit

Permalink
fix drawing of map items with new Cairo
Browse files Browse the repository at this point in the history
  • Loading branch information
treellama committed Dec 29, 2015
1 parent e53391a commit 06bf8f4
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions gtk-sharp/CairoDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace Weland {
public class CairoDrawer : Drawer {
Context context;

public Context Context {
get { return context; }
}

public CairoDrawer(Gdk.Window window, bool antialias) {
context = Gdk.CairoHelper.Create(window);
if (!antialias) {
Expand Down
38 changes: 26 additions & 12 deletions gtk-sharp/MapDrawingArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,25 +560,39 @@ void DrawTriangle(Drawer.Color c, double X, double Y, double angle, bool highlig
void DrawImage(Gdk.Pixbuf image, double X, double Y, bool highlight) {
int x = (int) X - image.Width / 2;
int y = (int) Y - image.Height / 2;
if (highlight) {
Gdk.GC gc = new Gdk.GC(GdkWindow);
if (!PlatformDetection.IsMac) { // UGH
if (drawer is CairoDrawer) {
Cairo.Context context = ((CairoDrawer) drawer).Context;

if (highlight) {
List<Drawer.Point> points = new List<Drawer.Point>();
points.Add(new Drawer.Point(x - 1.5, y - 1.5));
points.Add(new Drawer.Point(x + image.Width + 0.5, y - 1.5));
points.Add(new Drawer.Point(x + image.Width + 0.5, y + image.Height + 0.5));
points.Add(new Drawer.Point(x - 1.5, y + image.Height + 0.5));
drawer.FillPolygon(new Drawer.Color(1, 1, 0), points);
}

Gdk.CairoHelper.SetSourcePixbuf(context, image, x, y);
context.Paint();
} else {
if (highlight) {
Gdk.GC gc = new Gdk.GC(GdkWindow);
Gdk.Pixmap mask = new Gdk.Pixmap(null, image.Width, image.Height, 1);
image.RenderThresholdAlpha(mask, 0, 0, 0, 0, -1, -1, 1);

gc.ClipMask = mask;
}

for (int i = -2; i <= 2; ++i) {
for (int j = -2; j <= 2; ++j) {
gc.SetClipOrigin(x + i, y + j);
gc.RgbFgColor = new Gdk.Color(255, 255, 0);
GdkWindow.DrawRectangle(gc, true, x + i, y + j, image.Width, image.Height);
for (int i = -2; i <= 2; ++i) {
for (int j = -2; j <= 2; ++j) {
gc.SetClipOrigin(x + i, y + j);
gc.RgbFgColor = new Gdk.Color(255, 255, 0);
GdkWindow.DrawRectangle(gc, true, x + i, y + j, image.Width, image.Height);
}
}
}

GdkWindow.DrawPixbuf(new Gdk.GC(GdkWindow), image, 0, 0, x, y, -1, -1, Gdk.RgbDither.Normal, 0, 0);
}

GdkWindow.DrawPixbuf(new Gdk.GC(GdkWindow), image, 0, 0, x, y, -1, -1, Gdk.RgbDither.Normal, 0, 0);
}

void DrawObject(MapObject obj, bool highlight) {
Expand Down
Binary file modified images/2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/alien-gun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ar-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ar-grenades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/flower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/fusion-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/fusion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/invinc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/keycard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/oxygen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/pistol-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/pistol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/powerup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/rl-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/shotgun-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/shotgun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/skull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/smg-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/smg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/sound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/tozt-ammo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/tozt.png
Binary file modified images/uplink-chip.png

0 comments on commit 06bf8f4

Please sign in to comment.