From 7eadb3f990d046d1e7fa7da3c40b4e651671246c Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 22 Apr 2014 15:51:50 +0400 Subject: [PATCH] - --- haxework/gui/View.hx | 4 ++-- haxework/gui/utils/DrawUtil.hx | 21 +++++++++------- haxework/log/SocketLogger.hx | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) create mode 100755 haxework/log/SocketLogger.hx diff --git a/haxework/gui/View.hx b/haxework/gui/View.hx index 8326714..1c0c2e3 100755 --- a/haxework/gui/View.hx +++ b/haxework/gui/View.hx @@ -121,7 +121,7 @@ class View implements IView { private function set_w(value:Float):Float { if (w != value) { w = value; - if (!Math.isNaN(r)) h = w / r; + if (!Math.isNaN(r) && r > 0) h = w / r; invalidate(); } return w; @@ -129,7 +129,7 @@ class View implements IView { private function set_h(value:Float):Float { if (h != value) { h = value; - if (!Math.isNaN(r)) w = h * r; + if (!Math.isNaN(r) && r > 0) w = h * r; invalidate(); } return h; diff --git a/haxework/gui/utils/DrawUtil.hx b/haxework/gui/utils/DrawUtil.hx index 07227ca..fb1e86e 100755 --- a/haxework/gui/utils/DrawUtil.hx +++ b/haxework/gui/utils/DrawUtil.hx @@ -11,6 +11,7 @@ import flash.display.Graphics; COVER; CONTAIN; REPEAT; + STRETCH; } class DrawUtil { @@ -24,7 +25,8 @@ class DrawUtil { graphics.endFill(); } var m:Matrix = new Matrix(); - var s:Float = 1.0; + var sx:Float = 1.0; + var sy:Float = 1.0; switch (fillType) { case FillType.REPEAT: graphics.beginBitmapFill(image, m, true, false); @@ -38,19 +40,22 @@ class DrawUtil { return; case FillType.DEFAULT: case FillType.CONTAIN: - s = Math.min(rect.width / image.width, rect.height / image.height); + sx = sy = Math.min(rect.width / image.width, rect.height / image.height); case FillType.COVER: - s = Math.max(rect.width / image.width, rect.height / image.height); + sx = sy = Math.max(rect.width / image.width, rect.height / image.height); + case FillType.STRETCH: + sx = rect.width / image.width; + sy = rect.height / image.height; } - m.scale(s, s); - var dx:Float = (rect.width - image.width * s) / 2; - var dy:Float = (rect.height - image.height * s) / 2; + m.scale(sx, sy); + var dx:Float = (rect.width - image.width * sx) / 2; + var dy:Float = (rect.height - image.height * sy) / 2; m.translate(dx, dy); graphics.beginBitmapFill(image, m, false, true); rect.x = Math.max(rect.x, m.tx); rect.y = Math.max(rect.y, m.ty); - rect.width = Math.min(rect.width, image.width * s); - rect.height = Math.min(rect.height, image.height * s); + rect.width = Math.min(rect.width, image.width * sx); + rect.height = Math.min(rect.height, image.height * sy); graphics.drawRect(rect.x, rect.y, rect.width, rect.height); graphics.endFill(); } diff --git a/haxework/log/SocketLogger.hx b/haxework/log/SocketLogger.hx new file mode 100755 index 0000000..fcab5fc --- /dev/null +++ b/haxework/log/SocketLogger.hx @@ -0,0 +1,44 @@ +package haxework.log; + +import haxework.log.BaseLogger; +#if flash +import flash.net.Socket; +import flash.events.IOErrorEvent; +import flash.events.SecurityErrorEvent; +#else +import sys.net.Host; +import sys.net.Socket; +#end + +class SocketLogger extends BaseLogger { + + private var socket:Socket; + + public function new() { + super(); + socket = new Socket(); + #if flash + socket.addEventListener(IOErrorEvent.IO_ERROR, function(error):Void { + L.e("SocketLogger", "", error); + }); + socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, function(error):Void { + L.e("SocketLogger", "", error); + }); + socket.connect(CompilationOption.get("debug.address"), Std.parseInt(CompilationOption.get("debug.port"))); + #else + socket.connect(new Host(CompilationOption.get("debug.address")), Std.parseInt(CompilationOption.get("debug.port"))); + #end + } + + override private function write(text:String, ?p:haxe.PosInfos):Void { + try { + var s:String = p.fileName + ":" + p.lineNumber + ":" + text + "\n"; + #if flash + socket.writeUTF(s); + socket.flush(); + #else + socket.write(s); + #end + } catch (error:Dynamic) {} + } +} \ No newline at end of file