瀏覽代碼

Merge pull request #5 from ncannasse/master

sync
Mathieu Capdegelle 9 年之前
父節點
當前提交
b23bf05936

+ 2 - 2
h2d/Anim.hx

@@ -33,8 +33,8 @@ class Anim extends Drawable {
 		return curFrame;
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		var tile = getFrame();
 		if( tile != null ) addBounds(relativeTo, out, tile.dx, tile.dy, tile.width, tile.height);
 	}

+ 2 - 2
h2d/Bitmap.hx

@@ -15,8 +15,8 @@ class Bitmap extends Drawable {
 		return tileWrap = b;
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		if( tile != null ) addBounds(relativeTo, out, tile.dx, tile.dy, tile.width, tile.height);
 	}
 

+ 16 - 0
h2d/CdbLevel.hx

@@ -230,6 +230,22 @@ class CdbLevel extends Layers {
 		return layersMap.get(name);
 	}
 
+	public function buildIntProperty( name : String ) {
+		var collide = null;
+		for( l in layers ) {
+			var layer = l.buildIntProperty(name);
+			if( collide == null )
+				collide = layer;
+			else
+				for( i in 0...width	* height ) {
+					var v = layer[i];
+					if( v != 0 && v > collide[i] ) collide[i] = v;
+				}
+		}
+		if( collide == null ) collide = [for( i in 0...width * height ) 0];
+		return collide;
+	}
+
 	public function getTileset( file : String ) : LevelTileset {
 		return tilesets.get(file);
 	}

+ 28 - 29
h2d/Flow.hx

@@ -52,16 +52,6 @@ class Flow extends Sprite {
 	public var maxWidth(default, set) : Null<Int>;
 	public var maxHeight(default, set) : Null<Int>;
 
-	/**
-		The calculated width based on the flow elements.
-	**/
-	public var calculatedWidth(get, null) = 0.;
-
-	/**
-		The calculated height based on the flow elements.
-	**/
-	public var calculatedHeight(get, null) = 0.;
-
 	/**
 		Will set all padding values at the same time.
 	**/
@@ -106,18 +96,22 @@ class Flow extends Sprite {
 	**/
 	public var isVertical(default, set) : Bool;
 
+	/**
+		When isInline is set to true, the flow size will be reported based on the size of the elements instead of their bounds.
+		This is useful if you want to include flows in other flows while keeping the text aligned.
+	**/
+	public var isInline = false;
+
 	var background : h2d.ScaleGrid;
 	var properties : Array<FlowProperties> = [];
 
+	var calculatedWidth : Float = 0.;
+	var calculatedHeight : Float = 0.;
+
 	public function new(?parent) {
 		super(parent);
 	}
 
-	override public function getBounds(?relativeTo:Sprite, ?out:h2d.col.Bounds):h2d.col.Bounds {
-		reflow();
-		return super.getBounds(relativeTo, out);
-	}
-
 	/**
 		Get the per-element properties. Returns null if the element is not currently part of the flow.
 	**/
@@ -184,13 +178,15 @@ class Flow extends Sprite {
 		return paddingBottom = v;
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
 		if( needReflow ) reflow();
-		var cw = calculatedWidth;
-		var ch = calculatedHeight;
-		if( cw != 0 || ch != 0 )
-			addBounds(relativeTo, out, 0, 0, cw, ch);
+		if( forSize ) {
+			if( !isInline )
+				super.getBoundsRec(relativeTo, out, false);
+			else if( calculatedWidth != 0 )
+				addBounds(relativeTo, out, 0, 0, calculatedWidth, calculatedHeight);
+		} else
+			super.getBoundsRec(relativeTo, out, forSize);
 	}
 
 	override function addChildAt( s, pos ) {
@@ -357,10 +353,7 @@ class Flow extends Sprite {
 
 				if( p.align == Absolute ) continue;
 
-				c.x = 0;
-				c.y = 0;
-				var b = c.getBounds(this, tmpBounds);
-
+				var b = c.getSize(tmpBounds);
 				p.calculatedWidth = b.xMax + p.paddingLeft + p.paddingRight;
 				p.calculatedHeight = b.yMax + p.paddingTop + p.paddingBottom;
 				if( p.minWidth != null && p.calculatedWidth < p.minWidth ) p.calculatedWidth = p.minWidth;
@@ -417,12 +410,11 @@ class Flow extends Sprite {
 
 				if( p.align == Absolute ) continue;
 
-				c.x = 0;
-				c.y = 0;
+				// use getBounds instead of getSize for vertical align
 				var b = c.getBounds(this, tmpBounds);
 
-				p.calculatedWidth = b.xMax + p.paddingLeft + p.paddingRight;
-				p.calculatedHeight = b.yMax + p.paddingTop + p.paddingBottom;
+				p.calculatedWidth = b.xMax - c.x + p.paddingLeft + p.paddingRight;
+				p.calculatedHeight = b.yMax - c.y + p.paddingTop + p.paddingBottom;
 				if( p.minWidth != null && p.calculatedWidth < p.minWidth ) p.calculatedWidth = p.minWidth;
 				if( p.minHeight != null && p.calculatedHeight < p.minHeight ) p.calculatedHeight = p.minHeight;
 
@@ -462,6 +454,13 @@ class Flow extends Sprite {
 		calculatedWidth = cw;
 		calculatedHeight = ch;
 		needReflow = false;
+		onReflow();
+	}
+
+	/**
+		Called each time a reflow() was done.
+	**/
+	public dynamic function onReflow() {
 	}
 
 }

+ 2 - 2
h2d/Graphics.hx

@@ -148,8 +148,8 @@ class Graphics extends Drawable {
 		xMax = Math.NEGATIVE_INFINITY;
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		if( tile != null ) addBounds(relativeTo, out, xMin, yMin, xMax - xMin, yMax - yMin);
 	}
 

+ 12 - 2
h2d/HtmlText.hx

@@ -42,10 +42,16 @@ class HtmlText extends Text {
 		xPos = 0;
 		yPos = 0;
 		xMax = 0;
+		calcYMin = 0;
 		var doc = try Xml.parse(text) catch( e : Dynamic ) throw "Could not parse " + text + " (" + e +")";
 		for( e in doc )
 			addNode(e, rebuild);
-		return cachedSize = { width : xPos > xMax ? xPos : xMax, height : xPos > 0 ? yPos + (font.lineHeight + lineSpacing) : yPos };
+
+		var x = xPos, y = yPos;
+		calcWidth = x > xMax ? x : xMax;
+		calcHeight = y > 0 && x == 0 ? y - lineSpacing : y + font.lineHeight;
+		calcSizeHeight = y > 0 && x == 0 ? y + (font.baseLine - font.lineHeight - lineSpacing) : y + font.baseLine;
+		calcDone = true;
 	}
 
 	function addNode( e : Xml, rebuild : Bool ) {
@@ -74,10 +80,13 @@ class HtmlText extends Text {
 					xPos = 0;
 					yPos += font.lineHeight + lineSpacing;
 				}
+				var py = yPos + font.baseLine - i.height;
+				if( py + i.dy < calcYMin )
+					calcYMin = py + i.dy;
 				if( rebuild ) {
 					var b = new Bitmap(i, this);
 					b.x = xPos;
-					b.y = yPos + font.baseLine - i.height;
+					b.y = py;
 					images.push(b);
 				}
 				xPos += i.width + letterSpacing;
@@ -102,6 +111,7 @@ class HtmlText extends Text {
 				var e = font.getChar(cc);
 				xPos += e.getKerningOffset(prevChar);
 				if( rebuild ) glyphs.add(xPos, yPos, e.t);
+				if( yPos == 0 && e.t.dy < calcYMin ) calcYMin = e.t.dy;
 				xPos += e.width + letterSpacing;
 				prevChar = cc;
 			}

+ 2 - 12
h2d/Interactive.hx

@@ -36,8 +36,8 @@ class Interactive extends Drawable {
 		if( backgroundColor != null ) emitTile(ctx, h2d.Tile.fromColor(backgroundColor, Std.int(width), Std.int(height), (backgroundColor>>>24)/255 ));
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		if( backgroundColor != null ) addBounds(relativeTo, out, 0, 0, Std.int(width), Std.int(height));
 	}
 
@@ -48,16 +48,6 @@ class Interactive extends Drawable {
 		}
 	}
 
-	override function calcAbsPos() {
-		super.calcAbsPos();
-		// force a move event if we update the current over interactive
-		if( scene != null && scene.currentOver == this ) {
-			var stage = hxd.Stage.getInstance();
-			var e = new hxd.Event(EMove, stage.mouseX, stage.mouseY);
-			@:privateAccess scene.onEvent(e);
-		}
-	}
-
 	override function onDelete() {
 		if( scene != null ) {
 			scene.removeEventTarget(this);

+ 2 - 2
h2d/Mask.hx

@@ -11,8 +11,8 @@ class Mask extends Sprite {
 		this.height = height;
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		var xMin = out.xMin, yMin = out.yMin, xMax = out.xMax, yMax = out.yMax;
 		out.empty();
 		addBounds(relativeTo, out, 0, 0, width, height);

+ 2 - 2
h2d/ScaleGrid.hx

@@ -37,9 +37,9 @@ class ScaleGrid extends h2d.TileGroup {
 		return h;
 	}
 
-	override function getBoundsRec(relativeTo, out) {
+	override function getBoundsRec(relativeTo, out, forSize) {
 		if( content.isEmpty() ) updateContent();
-		super.getBoundsRec(relativeTo, out);
+		super.getBoundsRec(relativeTo, out, forSize);
 	}
 
 	function updateContent() {

+ 12 - 1
h2d/Scene.hx

@@ -25,6 +25,7 @@ class Scene extends Layers implements h3d.IDrawable {
 	var pushList : Array<Interactive>;
 	var currentDrag : { f : hxd.Event -> Void, onCancel : Void -> Void, ref : Null<Int> };
 	var eventListeners : Array< hxd.Event -> Void >;
+	var fakeMove : hxd.Event;
 
 	public function new() {
 		super(null);
@@ -231,7 +232,7 @@ class Scene extends Layers implements h3d.IDrawable {
 			event.kind = EMove;
 			currentOver = null;
 		}
-		if( !handled ) {
+		if( !handled && event != fakeMove ) {
 			if( event.kind == EPush )
 				pushList.push(null);
 			dispatchListeners(event);
@@ -252,10 +253,12 @@ class Scene extends Layers implements h3d.IDrawable {
 		if( old.length == 0 )
 			return;
 		pendingEvents = null;
+		var checkMoved = false;
 		for( e in old ) {
 			var ox = e.relX, oy = e.relY;
 			e.relX = screenXToLocal(ox);
 			e.relY = screenYToLocal(oy);
+			if( e.kind == EMove ) checkMoved = true;
 
 			if( currentDrag != null && (currentDrag.ref == null || currentDrag.ref == e.touchId) ) {
 				currentDrag.f(e);
@@ -291,6 +294,14 @@ class Scene extends Layers implements h3d.IDrawable {
 			e.relX = ox;
 			e.relY = oy;
 		}
+
+		if( !checkMoved && currentDrag == null ) {
+			if( fakeMove == null ) fakeMove = new hxd.Event(EMove);
+			fakeMove.relX = mouseX;
+			fakeMove.relY = mouseY;
+			emitEvent(fakeMove);
+		}
+
 		if( hasEvents() )
 			pendingEvents = new Array();
 	}

+ 27 - 4
h2d/Sprite.hx

@@ -43,13 +43,19 @@ class Sprite {
 			parent.addChild(this);
 	}
 
+	/**
+		Returns the bounds of the sprite for its whole content, recursively.
+		If relativeTo is null, it will return the bounds in the absolute coordinates.
+		If not, it will return the bounds relative to the specified sprite coordinates.
+		You can pass an already allocated bounds or getBounds will allocate one for you and return it.
+	**/
 	public function getBounds( ?relativeTo : Sprite, ?out : h2d.col.Bounds ) : h2d.col.Bounds {
 		if( out == null ) out = new h2d.col.Bounds();
 		if( relativeTo != null )
 			relativeTo.syncPos();
 		if( relativeTo != this )
 			syncPos();
-		getBoundsRec(relativeTo, out);
+		getBoundsRec(relativeTo, out, false);
 		if( out.isEmpty() ) {
 			addBounds(relativeTo, out, -1, -1, 2, 2);
 			out.xMax = out.xMin = (out.xMax + out.xMin) * 0.5;
@@ -58,7 +64,24 @@ class Sprite {
 		return out;
 	}
 
-	function getBoundsRec( relativeTo : Sprite, out : h2d.col.Bounds ) {
+	/**
+		This is similar to getBounds(parent), but instead of the full content, it will return
+		the size based on the alignement of the Sprite. For instance for a text, getBounds will returns
+		the full glyphs size whereas getSize() will ignore the pixels under the baseline.
+	**/
+	public function getSize( ?out : h2d.col.Bounds ) : h2d.col.Bounds {
+		if( out == null ) out = new h2d.col.Bounds();
+		getBoundsRec(parent, out, true);
+		if( out.isEmpty() ) {
+			addBounds(parent, out, -1, -1, 2, 2);
+			out.xMax = out.xMin = (out.xMax + out.xMin) * 0.5;
+			out.yMax = out.yMin = (out.yMax + out.yMin) * 0.5;
+		}
+		out.offset( -x, -y);
+		return out;
+	}
+
+	function getBoundsRec( relativeTo : Sprite, out : h2d.col.Bounds, forSize : Bool ) {
 		if( posChanged ) {
 			calcAbsPos();
 			for( c in childs )
@@ -72,14 +95,14 @@ class Sprite {
 		}
 		if( n == 1 ) {
 			var c = childs[0];
-			if( c.visible ) c.getBounds(relativeTo, out) else out.empty();
+			if( c.visible ) c.getBoundsRec(relativeTo, out,forSize) else out.empty();
 			return;
 		}
 		var xmin = hxd.Math.POSITIVE_INFINITY, ymin = hxd.Math.POSITIVE_INFINITY;
 		var xmax = hxd.Math.NEGATIVE_INFINITY, ymax = hxd.Math.NEGATIVE_INFINITY;
 		for( c in childs ) {
 			if( !c.visible ) continue;
-			c.getBoundsRec(relativeTo, out);
+			c.getBoundsRec(relativeTo, out, forSize);
 			if( out.xMin < xmin ) xmin = out.xMin;
 			if( out.yMin < ymin ) ymin = out.yMin;
 			if( out.xMax > xmax ) xmax = out.xMax;

+ 2 - 2
h2d/SpriteBatch.hx

@@ -138,8 +138,8 @@ class SpriteBatch extends Drawable {
 		}
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		var e = first;
 		while( e != null ) {
 			var t = e.t;

+ 44 - 28
h2d/Text.hx

@@ -21,7 +21,12 @@ class Text extends Drawable {
 	public var lineSpacing(default,set) : Int;
 
 	var glyphs : TileGroup;
-	var cachedSize : { width : Int, height : Int };
+
+	var calcDone:Bool;
+	var calcYMin:Int;
+	var calcWidth:Int;
+	var calcHeight:Int;
+	var calcSizeHeight:Int;
 
 	public function new( font : Font, ?parent ) {
 		super(parent);
@@ -102,15 +107,25 @@ class Text extends Drawable {
 	}
 
 	function rebuild() {
-		cachedSize = null;
+		calcDone = false;
 		if( allocated && text != null && font != null ) initGlyphs(text);
 	}
 
 	public function calcTextWidth( text : String ) {
-		var old = cachedSize;
-		var w = initGlyphs(text,false).width;
-		cachedSize = old;
-		return w;
+		if( calcDone ) {
+			var ow = calcWidth, oh = calcHeight, osh = calcSizeHeight, oy = calcYMin;
+			initGlyphs(text, false);
+			var w = calcWidth;
+			calcWidth = ow;
+			calcHeight = oh;
+			calcSizeHeight = osh;
+			calcYMin = oy;
+			return w;
+		} else {
+			initGlyphs(text, false);
+			calcDone = false;
+			return calcWidth;
+		}
 	}
 
 	public function splitText( text : String, leftMargin = 0 ) {
@@ -164,15 +179,15 @@ class Text extends Drawable {
 		return lines.join("\n");
 	}
 
-	function initGlyphs( text : String, rebuild = true, lines : Array<Int> = null ) : { width : Int, height : Int } {
+	function initGlyphs( text : String, rebuild = true, lines : Array<Int> = null ) : Void {
 		if( rebuild ) glyphs.clear();
 		var x = 0, y = 0, xMax = 0, prevChar = -1;
 		var align = rebuild ? textAlign : Left;
 		switch( align ) {
 		case Center, Right:
 			lines = [];
-			var inf = initGlyphs(text, false, lines);
-			var max = maxWidth == null ? inf.width : Std.int(maxWidth);
+			initGlyphs(text, false, lines);
+			var max = maxWidth == null ? calcWidth : Std.int(maxWidth);
 			var k = align == Center ? 1 : 0;
 			for( i in 0...lines.length )
 				lines[i] = (max - lines[i]) >> k;
@@ -181,6 +196,7 @@ class Text extends Drawable {
 		}
 		var dl = font.lineHeight + lineSpacing;
 		var calcLines = !rebuild && lines != null;
+		var yMin = 0;
 		for( i in 0...text.length ) {
 			var cc = text.charCodeAt(i);
 			var e = font.getChar(cc);
@@ -205,6 +221,7 @@ class Text extends Drawable {
 			}
 			if( e != null ) {
 				if( rebuild ) glyphs.add(x, y, e.t);
+				if( y == 0 && e.t.dy < yMin ) yMin = e.t.dy;
 				x += esize + letterSpacing;
 			}
 			if( newline ) {
@@ -225,17 +242,26 @@ class Text extends Drawable {
 				prevChar = cc;
 		}
 		if( calcLines ) lines.push(x);
-		return cachedSize = { width : x > xMax ? x : xMax, height : x > 0 ? y + dl : y > 0 ? y : dl };
+
+		calcYMin = yMin;
+		calcWidth = x > xMax ? x : xMax;
+		calcHeight = y > 0 && x == 0 ? y - lineSpacing : y + font.lineHeight;
+		calcSizeHeight = y > 0 && x == 0 ? y + (font.baseLine - dl) : y + font.baseLine;
+		calcDone = true;
+	}
+
+	inline function updateSize() {
+		if( !calcDone ) initGlyphs(text, false);
 	}
 
 	function get_textHeight() {
-		if( cachedSize != null ) return cachedSize.height;
-		return initGlyphs(text,false).height;
+		updateSize();
+		return calcHeight;
 	}
 
 	function get_textWidth() {
-		if( cachedSize != null ) return cachedSize.width;
-		return initGlyphs(text,false).width;
+		updateSize();
+		return calcWidth;
 	}
 
 	function set_maxWidth(w) {
@@ -254,20 +280,10 @@ class Text extends Drawable {
 		return c;
 	}
 
-	override function getBoundsRec( relativeTo : Sprite, out : h2d.col.Bounds ) {
-		if( !allocated ) {
-			// if not on scene, the text is not yet built !
-			super.getBoundsRec(relativeTo, out);
-			var size = cachedSize == null ? initGlyphs(text, false) : cachedSize;
-			addBounds(relativeTo, out, 0, 0, size.width, size.height);
-		} else {
-			if( glyphs != null ) glyphs.visible = true;
-			super.getBoundsRec(relativeTo, out);
-			if( glyphs != null )
-				glyphs.visible = false;
-			else
-				addBounds(relativeTo, out, 0, 0, 16, 16);
-		}
+	override function getBoundsRec( relativeTo : Sprite, out : h2d.col.Bounds, forSize : Bool ) {
+		super.getBoundsRec(relativeTo, out, forSize);
+		updateSize();
+		addBounds(relativeTo, out, 0, forSize ? 0 : calcYMin, calcWidth, forSize ? calcSizeHeight : calcHeight - calcYMin);
 	}
 
 }

+ 2 - 2
h2d/TileGroup.hx

@@ -326,8 +326,8 @@ class TileGroup extends Drawable {
 		content = new TileLayerContent();
 	}
 
-	override function getBoundsRec( relativeTo, out ) {
-		super.getBoundsRec(relativeTo, out);
+	override function getBoundsRec( relativeTo, out, forSize ) {
+		super.getBoundsRec(relativeTo, out, forSize);
 		addBounds(relativeTo, out, content.xMin, content.yMin, content.xMax - content.xMin, content.yMax - content.yMin);
 	}
 

+ 2 - 1
h3d/impl/Stage3dDriver.hx

@@ -50,7 +50,8 @@ private class CompiledShader {
 
 class Stage3dDriver extends Driver {
 
-	public static var PROFILE = #if flash14 cast "standard" #else flash.display3D.Context3DProfile.BASELINE #end;
+	// standard profile was introduced with Flash14 but it causes problems with filters, only enable it for flash15+
+	public static var PROFILE = #if flash15 cast "standard" #else flash.display3D.Context3DProfile.BASELINE #end;
 
 	var s3d : flash.display.Stage3D;
 	var ctx : flash.display3D.Context3D;

+ 1 - 1
hxd/WaitEvent.hx

@@ -25,7 +25,7 @@ class WaitEvent {
 	}
 
 	public function wait( time : Float, callb ) {
-		function tmp(dt) {
+		function tmp(dt:Float) {
 			time -= dt / hxd.Timer.wantedFPS;
 			if( time < 0 ) {
 				callb();

+ 71 - 94
hxd/clipper/Clipper.hx

@@ -170,7 +170,8 @@ private class TEdge {
 	public var bot : Point;
 	public var curr : Point;
 	public var top : Point;
-	public var delta : Point;
+	public var deltaX : Int;
+	public var deltaY : Int;
 	public var dx : Float;
 	public var polyType : PolyType;
 	public var side : EdgeSide;
@@ -189,7 +190,6 @@ private class TEdge {
 		bot = new Point();
 		curr = new Point();
 		top = new Point();
-		delta = new Point();
 	}
 }
 
@@ -265,7 +265,7 @@ private class ClipperBase
 
 	//------------------------------------------------------------------------------
 	public function isHorizontal(e : TEdge) {
-		return e.delta.y == 0;
+		return e.deltaY == 0;
 	}
 
 	inline function abs(i:Int):Int {
@@ -315,18 +315,13 @@ private class ClipperBase
 	//------------------------------------------------------------------------------
 
 	inline function SlopesEqual(e1:TEdge, e2:TEdge) {
-		return e1.delta.y * e2.delta.x == e1.delta.x * e2.delta.y;
+		return e1.deltaY * e2.deltaX == e1.deltaX * e2.deltaY;
 	}
 	//------------------------------------------------------------------------------
 
 	inline function SlopesEqual3(pt1:Point, pt2:Point, pt3:Point) {
 		return (pt1.y - pt2.y) * (pt2.x - pt3.x) - (pt1.x - pt2.x) * (pt2.y - pt3.y) == 0;
 	}
-	//------------------------------------------------------------------------------
-
-	inline function SlopesEqual4(pt1:Point, pt2:Point, pt3:Point, pt4:Point) {
-		return (pt1.y - pt2.y) * (pt3.x - pt4.x) - (pt1.x - pt2.x) * (pt3.y - pt4.y) == 0;
-	}
 
 	//------------------------------------------------------------------------------
 
@@ -391,7 +386,7 @@ private class ClipperBase
 			i--;
 		}
 
-		//remove ducplicate vertices and collinear edges
+		//remove duplicate vertices and collinear edges
 		var eStart = edges[0];
 		var eStop = eStart;
 		var e = eStart;
@@ -499,7 +494,7 @@ private class ClipperBase
 	function InitEdge(e:TEdge, eNext:TEdge, ePrev:TEdge, pt:Point) {
       e.next = eNext;
       e.prev = ePrev;
-      e.curr = pt;
+      e.curr = pt.clone();
       e.outIdx = UNASSIGNED;
 	}
 
@@ -690,10 +685,10 @@ private class ClipperBase
 
 	private function SetDx(e:TEdge)
 	{
-		e.delta.x = (e.top.x - e.bot.x);
-		e.delta.y = (e.top.y - e.bot.y);
-		if (e.delta.y == 0) e.dx = HORIZONTAL;
-		else e.dx = e.delta.x / e.delta.y;
+		e.deltaX = (e.top.x - e.bot.x);
+		e.deltaY = (e.top.y - e.bot.y);
+		if (e.deltaY == 0) e.dx = HORIZONTAL;
+		else e.dx = e.deltaX / e.deltaY;
 	}
 	//---------------------------------------------------------------------------
 
@@ -803,11 +798,6 @@ enum NodeType {
 @:allow(hxd.clipper)
 class Clipper extends ClipperBase {
 
-	//InitOptions that can be passed to the constructor ...
-	public var ioReverseSolution = 1;
-	public var ioStrictlySimple = 2;
-	public var ioPreserveCollinear = 4;
-
 	public var strictlySimple : Bool;
 	public var reverseSolution : Bool;
 
@@ -824,7 +814,7 @@ class Clipper extends ClipperBase {
 	var m_GhostJoins : Array<Join>;
 	var m_UsingPolyTree : Bool;
 
-	public function new(initOptions = 0)
+	public function new()
 	{
 		super();
 		m_Scanbeam = null;
@@ -837,9 +827,9 @@ class Clipper extends ClipperBase {
 		m_Joins = [];
 		m_GhostJoins = [];
 
-		reverseSolution = (ioReverseSolution & initOptions) != 0;
-		strictlySimple = (ioStrictlySimple & initOptions) != 0;
-		preserveCollinear = (ioPreserveCollinear & initOptions) != 0;
+		reverseSolution = false;
+		strictlySimple = false;
+		preserveCollinear = false;
 	}
 
 	inline function xor(a, b) {
@@ -927,14 +917,6 @@ class Clipper extends ClipperBase {
 		DisposeAllPolyPts();
 		m_ExecuteLocked = false;
 
-		/*
-		trace("------------");
-		for(s in solution) {
-			trace(s.length);
-			for(p in s)
-				trace(p);
-		}*/
-
 		return solution;
 	}
 	//------------------------------------------------------------------------------
@@ -988,7 +970,6 @@ class Clipper extends ClipperBase {
 			botY = topY;
 		} while (m_Scanbeam != null || m_CurrentLM != null);
 
-
 		//fix orientations ...
 		for( outRec in m_PolyOuts ) {
 			if(outRec.pts == null) continue;
@@ -2435,7 +2416,7 @@ class Clipper extends ClipperBase {
 			return ip;
 		}
 
-		if (edge1.delta.x == 0)
+		if (edge1.deltaX == 0)
 		{
 			ip.x = edge1.bot.x;
 			if (isHorizontal(edge2))
@@ -2448,7 +2429,7 @@ class Clipper extends ClipperBase {
 				ip.y = Round(ip.y / edge2.dx + b2);
 			}
 		}
-		else if (edge2.delta.x == 0)
+		else if (edge2.deltaX == 0)
 		{
 			ip.x = edge2.bot.x;
 			if (isHorizontal(edge1))
@@ -3297,55 +3278,55 @@ class Clipper extends ClipperBase {
 		var i:Int = 0;
 		while (i < m_PolyOuts.length)
 		{
-		var outrec:OutRec = m_PolyOuts[i++];
-		var op:OutPt = outrec.pts;
-		if (op == null) continue;
-		do //for each Pt in Polygon until duplicate found do
-		{
-			var op2 = op.next;
-			while (op2 != outrec.pts)
-			{
-			if (op.pt == op2.pt && op2.next != op && op2.prev != op)
+			var outrec:OutRec = m_PolyOuts[i++];
+			var op:OutPt = outrec.pts;
+			if (op == null) continue;
+			do //for each Pt in Polygon until duplicate found do
 			{
-				//split the polygon into two
-				var op3 = op.prev;
-				var op4 = op2.prev;
-				op.prev = op4;
-				op4.next = op;
-				op2.prev = op3;
-				op3.next = op2;
-
-				outrec.pts = op;
-				var outrec2 = CreateOutRec();
-				outrec2.pts = op2;
-				UpdateOutPtIdxs(outrec2);
-				if (Poly2ContainsPoly1(outrec2.pts, outrec.pts))
-				{
-					//OutRec2 is contained by OutRec1
-					outrec2.isHole = !outrec.isHole;
-					outrec2.firstLeft = outrec;
-				}
-				else
-				if (Poly2ContainsPoly1(outrec.pts, outrec2.pts))
-				{
-					//OutRec1 is contained by OutRec2
-					outrec2.isHole = outrec.isHole;
-					outrec.isHole = !outrec2.isHole;
-					outrec2.firstLeft = outrec.firstLeft;
-					outrec.firstLeft = outrec2;
-				} else
+				var op2 = op.next;
+				while (op2 != outrec.pts)
 				{
-					//the 2 polygons are separate
-					outrec2.isHole = outrec.isHole;
-					outrec2.firstLeft = outrec.firstLeft;
+					if (op.pt == op2.pt && op2.next != op && op2.prev != op)
+					{
+						//split the polygon into two
+						var op3 = op.prev;
+						var op4 = op2.prev;
+						op.prev = op4;
+						op4.next = op;
+						op2.prev = op3;
+						op3.next = op2;
+
+						outrec.pts = op;
+						var outrec2 = CreateOutRec();
+						outrec2.pts = op2;
+						UpdateOutPtIdxs(outrec2);
+						if (Poly2ContainsPoly1(outrec2.pts, outrec.pts))
+						{
+							//OutRec2 is contained by OutRec1
+							outrec2.isHole = !outrec.isHole;
+							outrec2.firstLeft = outrec;
+						}
+						else
+						if (Poly2ContainsPoly1(outrec.pts, outrec2.pts))
+						{
+							//OutRec1 is contained by OutRec2
+							outrec2.isHole = outrec.isHole;
+							outrec.isHole = !outrec2.isHole;
+							outrec2.firstLeft = outrec.firstLeft;
+							outrec.firstLeft = outrec2;
+						} else
+						{
+							//the 2 polygons are separate
+							outrec2.isHole = outrec.isHole;
+							outrec2.firstLeft = outrec.firstLeft;
+						}
+						op2 = op; //ie get ready for the next iteration
+					}
+					op2 = op2.next;
 				}
-				op2 = op; //ie get ready for the next iteration
+				op = op.next;
 			}
-			op2 = op2.next;
-			}
-			op = op.next;
-		}
-		while (op != outrec.pts);
+			while (op != outrec.pts);
 		}
 	}
 
@@ -3529,9 +3510,8 @@ class Clipper extends ClipperBase {
       }
       //------------------------------------------------------------------------------
 
-      static function Minkowski(pattern : Polygon, path : Polygon , IsSum : Bool, IsClosed : Bool)
+      static function Minkowski(pattern : Polygon, path : Polygon , IsSum : Bool)
       {
-        var delta = (IsClosed ? 1 : 0);
         var polyCnt = pattern.length;
         var pathCnt = path.length;
         var result = new Polygons();
@@ -3553,7 +3533,7 @@ class Clipper extends ClipperBase {
           }
 
         var quads = new Polygons();
-        for (i in 0...pathCnt - 1 + delta)
+        for (i in 0...pathCnt)
           for (j in 0...polyCnt)
           {
             var quad = new Polygon();
@@ -3569,9 +3549,9 @@ class Clipper extends ClipperBase {
 
       //------------------------------------------------------------------------------
 
-      public static function MinkowskiSum(pattern : Polygon, path : Polygon, pathIsClosed : Bool)
+      public static function MinkowskiSum(pattern : Polygon, pol : Polygon)
       {
-        var paths = Minkowski(pattern, path, true, pathIsClosed);
+        var paths = Minkowski(pattern, pol, true);
         var c = new Clipper();
         c.addPolygons(paths, PolyType.Subject);
         return c.execute(ClipType.Union, PolyFillType.NonZero, PolyFillType.NonZero);
@@ -3588,18 +3568,15 @@ class Clipper extends ClipperBase {
       }
       //------------------------------------------------------------------------------
 
-      public static function MinkowskiSums(pattern : Polygon, paths : Polygons, pathIsClosed : Bool)
+      public static function MinkowskiSums(pattern : Polygon, pols : Polygons)
       {
         var c = new Clipper();
-        for (i in 0...paths.length)
+        for (i in 0...pols.length)
         {
-          var tmp = Minkowski(pattern, paths[i], true, pathIsClosed);
+          var tmp = Minkowski(pattern, pols[i], true);
           c.addPolygons(tmp, PolyType.Subject);
-          if (pathIsClosed)
-          {
-            var path = TranslatePath(paths[i], pattern[0]);
-            c.addPolygon(path, PolyType.Clip);
-          }
+          var path = TranslatePath(pols[i], pattern[0]);
+          c.addPolygon(path, PolyType.Clip);
         }
         return c.execute(ClipType.Union, PolyFillType.NonZero, PolyFillType.NonZero);
       }
@@ -3607,7 +3584,7 @@ class Clipper extends ClipperBase {
 
       public static function MinkowskiDiff(poly1 : Polygon, poly2 : Polygon)
       {
-        var paths = Minkowski(poly1, poly2, false, true);
+        var paths = Minkowski(poly1, poly2, false);
         var c = new Clipper();
         c.addPolygons(paths, PolyType.Subject);
         return c.execute(ClipType.Union, PolyFillType.NonZero, PolyFillType.NonZero);

+ 7 - 7
samples/2d/2d_ogl.hxml

@@ -1,7 +1,7 @@
--cpp bin
--main Main
--lib heaps
--dce full
--D resourcesPath=../res
---macro include('h2d')
--lib hxsdl
+-cpp bin
+-main Main
+-lib heaps
+-dce full
+-D resourcesPath=../res
+--macro include('h2d',['h2d.CdbLevel'])
+-lib hxsdl

+ 52 - 52
samples/2d/2d_ogl.hxproj

@@ -1,53 +1,53 @@
-<?xml version="1.0" encoding="utf-8"?>
-<project version="2">
-  <!-- Output SWF options -->
-  <output>
-    <movie outputType="Application" />
-    <movie input="" />
-    <movie path="bin" />
-    <movie fps="60" />
-    <movie width="800" />
-    <movie height="600" />
-    <movie version="1" />
-    <movie minorVersion="0" />
-    <movie platform="C++" />
-    <movie background="#FFFFFF" />
-  </output>
-  <!-- Other classes to be compiled into your SWF -->
-  <classpaths>
-    <!-- example: <class path="..." /> -->
-  </classpaths>
-  <!-- Build options -->
-  <build>
-    <option directives="" />
-    <option flashStrict="False" />
-    <option noInlineOnDebug="False" />
-    <option mainClass="Main" />
-    <option enabledebug="False" />
-    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;--macro include('h2d')&#xA;-lib hxsdl" />
-  </build>
-  <!-- haxelib libraries -->
-  <haxelib>
-    <!-- example: <library name="..." /> -->
-  </haxelib>
-  <!-- Class files to compile (other referenced classes will automatically be included) -->
-  <compileTargets>
-    <!-- example: <compile path="..." /> -->
-  </compileTargets>
-  <!-- Paths to exclude from the Project Explorer tree -->
-  <hiddenPaths>
-    <hidden path="obj" />
-  </hiddenPaths>
-  <!-- Executed before build -->
-  <preBuildCommand />
-  <!-- Executed after build -->
-  <postBuildCommand alwaysRun="False" />
-  <!-- Other project options -->
-  <options>
-    <option showHiddenPaths="False" />
-    <option testMovie="OpenDocument" />
-    <option testMovieCommand="bin\Main-debug.exe" />
-  </options>
-  <!-- Plugin storage -->
-  <storage />
+<?xml version="1.0" encoding="utf-8"?>
+<project version="2">
+  <!-- Output SWF options -->
+  <output>
+    <movie outputType="Application" />
+    <movie input="" />
+    <movie path="bin" />
+    <movie fps="60" />
+    <movie width="800" />
+    <movie height="600" />
+    <movie version="0" />
+    <movie minorVersion="0" />
+    <movie platform="C++" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <!-- example: <class path="..." /> -->
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option directives="" />
+    <option flashStrict="False" />
+    <option noInlineOnDebug="False" />
+    <option mainClass="Main" />
+    <option enabledebug="False" />
+    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;--macro include('h2d',['h2d.CdbLevel'])&#xA;-lib hxsdl" />
+  </build>
+  <!-- haxelib libraries -->
+  <haxelib>
+    <!-- example: <library name="..." /> -->
+  </haxelib>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <!-- example: <compile path="..." /> -->
+  </compileTargets>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <hidden path="obj" />
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand />
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="OpenDocument" />
+    <option testMovieCommand="bin\Main-debug.exe" />
+  </options>
+  <!-- Plugin storage -->
+  <storage />
 </project>

+ 1 - 1
samples/2d/2d_swf.hxml

@@ -6,4 +6,4 @@
 -dce full
 -D resourcesPath=../res
 -D source-map-content
---macro include('h2d')
+--macro include('h2d',['h2d.CdbLevel'])

+ 2 - 1
samples/2d/2d_swf.hxproj

@@ -21,9 +21,10 @@
   <build>
     <option directives="" />
     <option flashStrict="False" />
+    <option noInlineOnDebug="False" />
     <option mainClass="Main" />
     <option enabledebug="False" />
-    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;-D source-map-content&#xA;--macro include('h2d')" />
+    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;-D source-map-content&#xA;--macro include('h2d',['h2d.CdbLevel'])" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>

+ 1 - 1
samples/2d/2d_wgl.hxml

@@ -4,4 +4,4 @@
 -dce full
 -D resourcesPath=../res
 -D source-map-content
---macro include('h2d')
+--macro include('h2d',['h2d.CdbLevel'])

+ 3 - 2
samples/2d/2d_wgl.hxproj

@@ -8,7 +8,7 @@
     <movie fps="60" />
     <movie width="800" />
     <movie height="600" />
-    <movie version="1" />
+    <movie version="0" />
     <movie minorVersion="0" />
     <movie platform="JavaScript" />
     <movie background="#FFFFFF" />
@@ -21,9 +21,10 @@
   <build>
     <option directives="" />
     <option flashStrict="False" />
+    <option noInlineOnDebug="False" />
     <option mainClass="Main" />
     <option enabledebug="False" />
-    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;-D source-map-content&#xA;--macro include('h2d')" />
+    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;-D source-map-content&#xA;--macro include('h2d',['h2d.CdbLevel'])" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>