From f81ab02e67506806c86fe9abe5cc85784e019e8d Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 11 Feb 2020 22:46:47 +0300 Subject: [PATCH] [geom] addd --- src/main/haxework/app/LinuxIcon.hx | 29 ++++++++ src/main/haxework/geom/IntPoint.hx | 35 ++++++++++ src/main/haxework/geom/Point.hx | 40 +++++++++++ src/main/haxework/geom/Rectangle.hx | 102 ++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 src/main/haxework/app/LinuxIcon.hx create mode 100644 src/main/haxework/geom/IntPoint.hx create mode 100644 src/main/haxework/geom/Point.hx create mode 100644 src/main/haxework/geom/Rectangle.hx diff --git a/src/main/haxework/app/LinuxIcon.hx b/src/main/haxework/app/LinuxIcon.hx new file mode 100644 index 0000000..a6b7f39 --- /dev/null +++ b/src/main/haxework/app/LinuxIcon.hx @@ -0,0 +1,29 @@ +package ru.m.puzzlez; + +import flash.display.BitmapData; +import flash.filters.ColorMatrixFilter; +import flash.geom.Point; +import flash.Lib; + +class LinuxIcon { + + public static var value(default, set):BitmapData; + + private static function set_value(value:BitmapData):BitmapData { + LinuxIcon.value = value; + Lib.current.stage.window.setIcon(prepareIcon(value).image); + return LinuxIcon.value; + } + + private static function prepareIcon(bitmap:BitmapData):BitmapData { + var matrix:Array = []; + matrix = matrix.concat([0, 0, 1, 0, 0]); + matrix = matrix.concat([0, 1, 0, 0, 0]); + matrix = matrix.concat([1, 0, 0, 0, 0]); + matrix = matrix.concat([0, 0, 0, 1, 0]); + var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix); + var bitmap:BitmapData = bitmap.clone(); + bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf); + return bitmap; + } +} diff --git a/src/main/haxework/geom/IntPoint.hx b/src/main/haxework/geom/IntPoint.hx new file mode 100644 index 0000000..8ffd54e --- /dev/null +++ b/src/main/haxework/geom/IntPoint.hx @@ -0,0 +1,35 @@ +package haxework.geom; + +abstract IntPoint(Array) { + public var x(get, set):Int; + public var y(get, set):Int; + + public function new(x:Int, y:Int) { + this = [x, y]; + } + + private inline function get_x() return this[0]; + + private inline function set_x(value) return this[0] = value; + + private inline function get_y() return this[1]; + + private inline function set_y(value) return this[1] = value; + + public function clone():IntPoint { + return new IntPoint(x, y); + } + + public function toString():String { + return 'IntPoint{x=$x,y=$y}'; + } + + @:to inline public function toInt():Int { + return (x << 16) + y; + } + + @:to inline public function toPoint():Point { + return new Point(x, y); + } +} + diff --git a/src/main/haxework/geom/Point.hx b/src/main/haxework/geom/Point.hx new file mode 100644 index 0000000..856d816 --- /dev/null +++ b/src/main/haxework/geom/Point.hx @@ -0,0 +1,40 @@ +package haxework.geom; + +import flash.geom.Point as FlashPoint; + +abstract Point(Array) { + public var x(get, set):Float; + public var y(get, set):Float; + + public function new(x:Float, y:Float) { + this = [x, y]; + } + + private inline function get_x() return this[0]; + + private inline function set_x(value) return this[0] = value; + + private inline function get_y() return this[1]; + + private inline function set_y(value) return this[1] = value; + + public function add(point:Point):Point { + return new Point(x + point.x, y + point.y); + } + + public function subtract(point:Point):Point { + return new Point(x - point.x, y - point.y); + } + + public function clone():Point { + return new Point(x, y); + } + + public function toString():String { + return 'Point{x=$x,y=$y}'; + } + + @:from public static function fromFlashPoint(value:FlashPoint):Point { + return new Point(value.x, value.y); + } +} diff --git a/src/main/haxework/geom/Rectangle.hx b/src/main/haxework/geom/Rectangle.hx new file mode 100644 index 0000000..fae3fb7 --- /dev/null +++ b/src/main/haxework/geom/Rectangle.hx @@ -0,0 +1,102 @@ +package haxework.geom; + +abstract Rectangle(Array) { + public var x(get, set):Float; + public var y(get, set):Float; + public var width(get, set):Float; + public var height(get, set):Float; + public var center(get, set):Point; + public var size(get, set):Point; + public var left(get, never):Float; + public var right(get, never):Float; + public var top(get, never):Float; + public var bottom(get, never):Float; + public var position(get, set):Point; + + public function new(x:Float = 0, y:Float = 0, width:Float = 0, height:Float = 0) { + this = [x, y, width, height]; + } + + private inline function get_x() return this[0]; + + private inline function set_x(value) return this[0] = value; + + private inline function get_y() return this[1]; + + private inline function set_y(value) return this[1] = value; + + private inline function get_width() return this[2]; + + private inline function set_width(value) return this[2] = value; + + private inline function get_height() return this[3]; + + private inline function set_height(value) return this[3] = value; + + private function get_center():Point { + return new Point(x + width / 2, y + height / 2); + } + + private function set_center(value:Point):Point { + x = value.x - width / 2; + y = value.y - height / 2; + return value; + } + + private function get_size():Point { + return new Point(width, height); + } + + private function set_size(value:Point):Point { + width = value.x; + height = value.y; + return value; + } + + public function contain(point:Point):Bool { + return point.x >= left && point.y >= top && point.x <= right && point.y <= bottom; + } + + public function intersection(rect:Rectangle):Bool { + return !( + rect.left > right || + rect.right < left || + rect.top > bottom || + rect.bottom < top + ); + } + + public function clone():Rectangle { + return new Rectangle(x, y, width, height); + } + + public function toString():String { + return 'Rectangle{x=$x,y=$y,width=$width,height=$height}'; + } + + private function get_left():Float { + return x; + } + + private function get_right():Float { + return x + width; + } + + private function get_top():Float { + return y; + } + + private function get_bottom():Float { + return y + height; + } + + private function get_position():Point { + return new Point(x, y); + } + + private function set_position(position:Point):Point { + x = position.x; + y = position.y; + return position; + } +}