// Class: openfl._internal.renderer.DrawCommandBuffer

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../../hxClasses_stub").default;
var $import = require("./../../../import_stub").default;
function openfl__$internal_renderer_DrawCommandReader() {return require("./../../../openfl/_internal/renderer/DrawCommandReader");}
function Type() {return require("./../../../Type");}
function openfl__$internal_renderer_DrawCommandType() {return require("./../../../openfl/_internal/renderer/DrawCommandType");}

// Constructor

var DrawCommandBuffer = function() {
	if(DrawCommandBuffer.empty == null) {
		this.types = [];
		this.b = [];
		this.i = [];
		this.f = [];
		this.o = [];
		this.ff = [];
		this.ii = [];
		this.copyOnWrite = true;
	} else {
		this.clear();
	}
}

// Meta

DrawCommandBuffer.__name__ = ["openfl","_internal","renderer","DrawCommandBuffer"];
DrawCommandBuffer.prototype = {
	append: function(other) {
		if(this.get_length() == 0) {
			this.types = other.types;
			this.b = other.b;
			this.i = other.i;
			this.f = other.f;
			this.o = other.o;
			this.ff = other.ff;
			this.ii = other.ii;
			this.copyOnWrite = other.copyOnWrite = true;
			return other;
		}
		var data = new (openfl__$internal_renderer_DrawCommandReader().default)(other);
		var _g = 0;
		var _g1 = other.types;
		while(_g < _g1.length) {
			var type = _g1[_g];
			++_g;
			switch((Type().default).enumIndex(type)) {
			case 0:
				var c = data.readBeginBitmapFill();
				this.beginBitmapFill(c.obj(0),c.obj(1),c.bool(0),c.bool(1));
				break;
			case 1:
				var c1 = data.readBeginFill();
				this.beginFill(c1["int"](0),c1["float"](0));
				break;
			case 2:
				var c2 = data.readBeginGradientFill();
				this.beginGradientFill(c2.obj(0),c2.iArr(0),c2.fArr(0),c2.iArr(1),c2.obj(1),c2.obj(2),c2.obj(3),c2["float"](0));
				break;
			case 3:
				var c3 = data.readCubicCurveTo();
				this.cubicCurveTo(c3["float"](0),c3["float"](1),c3["float"](2),c3["float"](3),c3["float"](4),c3["float"](5));
				break;
			case 4:
				var c4 = data.readCurveTo();
				this.curveTo(c4["float"](0),c4["float"](1),c4["float"](2),c4["float"](3));
				break;
			case 5:
				var c5 = data.readDrawCircle();
				this.drawCircle(c5["float"](0),c5["float"](1),c5["float"](2));
				break;
			case 6:
				var c6 = data.readDrawEllipse();
				this.drawEllipse(c6["float"](0),c6["float"](1),c6["float"](2),c6["float"](3));
				break;
			case 7:
				var c7 = data.readDrawRect();
				this.drawRect(c7["float"](0),c7["float"](1),c7["float"](2),c7["float"](3));
				break;
			case 8:
				var c8 = data.readDrawRoundRect();
				this.drawRoundRect(c8["float"](0),c8["float"](1),c8["float"](2),c8["float"](3),c8["float"](4),c8.obj(0));
				break;
			case 10:
				var c9 = data.readDrawTriangles();
				this.drawTriangles(c9.obj(0),c9.obj(1),c9.obj(2),c9.obj(3));
				break;
			case 11:
				var c10 = data.readEndFill();
				this.endFill();
				break;
			case 12:
				var c11 = data.readLineBitmapStyle();
				this.lineBitmapStyle(c11.obj(0),c11.obj(1),c11.bool(0),c11.bool(1));
				break;
			case 13:
				var c12 = data.readLineGradientStyle();
				this.lineGradientStyle(c12.obj(0),c12.iArr(0),c12.fArr(0),c12.iArr(1),c12.obj(1),c12.obj(2),c12.obj(3),c12["float"](0));
				break;
			case 14:
				var c13 = data.readLineStyle();
				this.lineStyle(c13.obj(0),c13["int"](0),c13["float"](0),c13.bool(0),c13.obj(1),c13.obj(2),c13.obj(3),c13["float"](1));
				break;
			case 15:
				var c14 = data.readLineTo();
				this.lineTo(c14["float"](0),c14["float"](1));
				break;
			case 16:
				var c15 = data.readMoveTo();
				this.moveTo(c15["float"](0),c15["float"](1));
				break;
			case 17:
				var c16 = data.readOverrideMatrix();
				this.overrideMatrix(c16.obj(0));
				break;
			case 18:
				var c17 = data.readWindingEvenOdd();
				this.windingEvenOdd();
				break;
			case 19:
				var c18 = data.readWindingNonZero();
				this.windingNonZero();
				break;
			default:
			}
		}
		data.destroy();
		return other;
	},
	beginBitmapFill: function(bitmap,matrix,repeat,smooth) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).BEGIN_BITMAP_FILL);
		this.o.push(bitmap);
		this.o.push(matrix);
		this.b.push(repeat);
		this.b.push(smooth);
	},
	beginFill: function(color,alpha) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).BEGIN_FILL);
		this.i.push(color);
		this.f.push(alpha);
	},
	beginGradientFill: function(type,colors,alphas,ratios,matrix,spreadMethod,interpolationMethod,focalPointRatio) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).BEGIN_GRADIENT_FILL);
		this.o.push(type);
		this.ii.push(colors);
		this.ff.push(alphas);
		this.ii.push(ratios);
		this.o.push(matrix);
		this.o.push(spreadMethod);
		this.o.push(interpolationMethod);
		this.f.push(focalPointRatio);
	},
	clear: function() {
		this.types = DrawCommandBuffer.empty.types;
		this.b = DrawCommandBuffer.empty.b;
		this.i = DrawCommandBuffer.empty.i;
		this.f = DrawCommandBuffer.empty.f;
		this.o = DrawCommandBuffer.empty.o;
		this.ff = DrawCommandBuffer.empty.ff;
		this.ii = DrawCommandBuffer.empty.ii;
		this.copyOnWrite = true;
	},
	copy: function() {
		var copy = new DrawCommandBuffer();
		copy.append(this);
		return copy;
	},
	cubicCurveTo: function(controlX1,controlY1,controlX2,controlY2,anchorX,anchorY) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).CUBIC_CURVE_TO);
		this.f.push(controlX1);
		this.f.push(controlY1);
		this.f.push(controlX2);
		this.f.push(controlY2);
		this.f.push(anchorX);
		this.f.push(anchorY);
	},
	curveTo: function(controlX,controlY,anchorX,anchorY) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).CURVE_TO);
		this.f.push(controlX);
		this.f.push(controlY);
		this.f.push(anchorX);
		this.f.push(anchorY);
	},
	destroy: function() {
		this.clear();
		this.types = null;
		this.b = null;
		this.i = null;
		this.f = null;
		this.o = null;
		this.ff = null;
		this.ii = null;
	},
	drawCircle: function(x,y,radius) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).DRAW_CIRCLE);
		this.f.push(x);
		this.f.push(y);
		this.f.push(radius);
	},
	drawEllipse: function(x,y,width,height) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).DRAW_ELLIPSE);
		this.f.push(x);
		this.f.push(y);
		this.f.push(width);
		this.f.push(height);
	},
	drawRect: function(x,y,width,height) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).DRAW_RECT);
		this.f.push(x);
		this.f.push(y);
		this.f.push(width);
		this.f.push(height);
	},
	drawRoundRect: function(x,y,width,height,ellipseWidth,ellipseHeight) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).DRAW_ROUND_RECT);
		this.f.push(x);
		this.f.push(y);
		this.f.push(width);
		this.f.push(height);
		this.f.push(ellipseWidth);
		this.o.push(ellipseHeight);
	},
	drawTriangles: function(vertices,indices,uvtData,culling) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).DRAW_TRIANGLES);
		this.o.push(vertices);
		this.o.push(indices);
		this.o.push(uvtData);
		this.o.push(culling);
	},
	endFill: function() {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).END_FILL);
	},
	lineBitmapStyle: function(bitmap,matrix,repeat,smooth) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).LINE_BITMAP_STYLE);
		this.o.push(bitmap);
		this.o.push(matrix);
		this.b.push(repeat);
		this.b.push(smooth);
	},
	lineGradientStyle: function(type,colors,alphas,ratios,matrix,spreadMethod,interpolationMethod,focalPointRatio) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).LINE_GRADIENT_STYLE);
		this.o.push(type);
		this.ii.push(colors);
		this.ff.push(alphas);
		this.ii.push(ratios);
		this.o.push(matrix);
		this.o.push(spreadMethod);
		this.o.push(interpolationMethod);
		this.f.push(focalPointRatio);
	},
	lineStyle: function(thickness,color,alpha,pixelHinting,scaleMode,caps,joints,miterLimit) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).LINE_STYLE);
		this.o.push(thickness);
		this.i.push(color);
		this.f.push(alpha);
		this.b.push(pixelHinting);
		this.o.push(scaleMode);
		this.o.push(caps);
		this.o.push(joints);
		this.f.push(miterLimit);
	},
	lineTo: function(x,y) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).LINE_TO);
		this.f.push(x);
		this.f.push(y);
	},
	moveTo: function(x,y) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).MOVE_TO);
		this.f.push(x);
		this.f.push(y);
	},
	prepareWrite: function() {
		if(this.copyOnWrite) {
			this.types = this.types.slice();
			this.b = this.b.slice();
			this.i = this.i.slice();
			this.f = this.f.slice();
			this.o = this.o.slice();
			this.ff = this.ff.slice();
			this.ii = this.ii.slice();
			this.copyOnWrite = false;
		}
	},
	overrideMatrix: function(matrix) {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).OVERRIDE_MATRIX);
		this.o.push(matrix);
	},
	windingEvenOdd: function() {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).WINDING_EVEN_ODD);
	},
	windingNonZero: function() {
		this.prepareWrite();
		this.types.push((openfl__$internal_renderer_DrawCommandType().default).WINDING_NON_ZERO);
	},
	get_length: function() {
		return this.types.length;
	}
};
DrawCommandBuffer.prototype.__class__ = $hxClasses["openfl._internal.renderer.DrawCommandBuffer"] = DrawCommandBuffer;

// Init



// Statics


DrawCommandBuffer.empty = new DrawCommandBuffer()

// Export

exports.default = DrawCommandBuffer;