<commit_before>﻿package net.flashpunk
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Transform;
	
	/**
	 * Container for the main screen buffer. Can be used to transform the screen.
	 */
	public class Screen
	{
		/**
		 * Constructor.
		 */
		public function Screen() 
		{
			// create screen buffers
			_bitmap[0] = new Bitmap(new BitmapData(FP.width, FP.height, false, 0), PixelSnapping.NEVER);
			_bitmap[1] = new Bitmap(new BitmapData(FP.width, FP.height, false, 0), PixelSnapping.NEVER);
			FP.engine.addChild(_sprite);
			_sprite.addChild(_bitmap[0]).visible = true;
			_sprite.addChild(_bitmap[1]).visible = false;
			FP.buffer = _bitmap[0].bitmapData;
			_width = FP.width;
			_height = FP.height;
			update();
		}
		
		/**
		 * Swaps screen buffers.
		 */
		public function swap():void
		{
			_current = 1 - _current;
			FP.buffer = _bitmap[_current].bitmapData;
		}
		
		/**
		 * Refreshes the screen.
		 */
		internal function refresh():void
		{
			// refreshes the screen
			FP.buffer.fillRect(FP.bounds, _color);
		}
		
		/**
		 * Redraws the screen.
		 */
		internal function redraw():void
		{
			// refresh the buffers
			_bitmap[_current].visible = true;
			_bitmap[1 - _current].visible = false;
		}
		
		/** @private Re-applies transformation matrix. */
		private function update():void
		{
			_matrix.b = _matrix.c = 0;
			_matrix.a = _scaleX * _scale;
			_matrix.d = _scaleY * _scale;
			_matrix.tx = -_originX * _matrix.a;
			_matrix.ty = -_originY * _matrix.d;
			if (_angle != 0) _matrix.rotate(_angle);
			_matrix.tx += _originX + _x;
			_matrix.ty += _originY + _y;
			_sprite.transform.matrix = _matrix;
		}
		
		/**
		 * Refresh color of the screen.
		 */
		public function get color():uint { return _color; }
		public function set color(value:uint):void { _color = 0xFF000000 | value; }
		
		/**
		 * X offset of the screen.
		 */
		public function get x():int { return _x; }
		public function set x(value:int):void
		{
			if (_x == value) return;
			_x = value;
			update();
		}
		
		/**
		 * Y offset of the screen.
		 */
		public function get y():int { return _y; }
		public function set y(value:int):void
		{
			if (_y == value) return;
			_y = value;
			update();
		}
		
		/**
		 * X origin of transformations.
		 */
		public function get originX():int { return _originX; }
		public function set originX(value:int):void
		{
			if (_originX == value) return;
			_originX = value;
			update();
		}
		
		/**
		 * Y origin of transformations.
		 */
		public function get originY():int { return _originY; }
		public function set originY(value:int):void
		{
			if (_originY == value) return;
			_originY = value;
			update();
		}
		
		/**
		 * X scale of the screen.
		 */
		public function get scaleX():Number { return _scaleX; }
		public function set scaleX(value:Number):void
		{
			if (_scaleX == value) return;
			_scaleX = value;
			update();
		}
		
		/**
		 * Y scale of the screen.
		 */
		public function get scaleY():Number { return _scaleY; }
		public function set scaleY(value:Number):void
		{
			if (_scaleY == value) return;
			_scaleY = value;
			update();
		}
		
		/**
		 * Scale factor of the screen. Final scale is scaleX * scale by scaleY * scale, so
		 * you can use this factor to scale the screen both horizontally and vertically.
		 */
		public function get scale():Number { return _scale; }
		public function set scale(value:Number):void
		{
			if (_scale == value) return;
			_scale = value;
			update();
		}
		
		/**
		 * Rotation of the screen, in degrees.
		 */
		public function get angle():Number { return _angle * FP.DEG; }
		public function set angle(value:Number):void
		{
			if (_angle == value) return;
			_angle = value * FP.RAD;
			update();
		}
		
		/**
		 * Whether screen smoothing should be used or not.
		 */
		public function get smoothing():Boolean { return _bitmap[0].smoothing; }
		public function set smoothing(value:Boolean):void { _bitmap[0].smoothing = _bitmap[1].smoothing = value; }
		
		/**
		 * Width of the screen.
		 */
		public function get width():uint { return _width; }
		
		/**
		 * Height of the screen.
		 */
		public function get height():uint { return _height; }
		
		/**
		 * X position of the mouse on the screen.
		 */
		public function get mouseX():int { return (FP.stage.mouseX - _x) / (_scaleX * _scale); }
		
		/**
		 * Y position of the mouse on the screen.
		 */
		public function get mouseY():int { return (FP.stage.mouseY - _y) / (_scaleY * _scale); }
		
		// Screen infromation.
		/** @private */ private var _sprite:Sprite = new Sprite;
		/** @private */ private var _bitmap:Vector.<Bitmap> = new Vector.<Bitmap>(2);
		/** @private */ private var _current:int = 0;
		/** @private */ private var _matrix:Matrix = new Matrix;
		/** @private */ private var _x:int;
		/** @private */ private var _y:int;
		/** @private */ private var _width:uint;
		/** @private */ private var _height:uint;
		/** @private */ private var _originX:int;
		/** @private */ private var _originY:int;
		/** @private */ private var _scaleX:Number = 1;
		/** @private */ private var _scaleY:Number = 1;
		/** @private */ private var _scale:Number = 1;
		/** @private */ private var _angle:Number = 0;
		/** @private */ private var _color:uint = 0x202020;
	}
}<commit_msg>Fixed screen offset to adhere to current scale.<commit_after>﻿package net.flashpunk
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Transform;
	
	/**
	 * Container for the main screen buffer. Can be used to transform the screen.
	 */
	public class Screen
	{
		/**
		 * Constructor.
		 */
		public function Screen() 
		{
			// create screen buffers
			_bitmap[0] = new Bitmap(new BitmapData(FP.width, FP.height, false, 0), PixelSnapping.NEVER);
			_bitmap[1] = new Bitmap(new BitmapData(FP.width, FP.height, false, 0), PixelSnapping.NEVER);
			FP.engine.addChild(_sprite);
			_sprite.addChild(_bitmap[0]).visible = true;
			_sprite.addChild(_bitmap[1]).visible = false;
			FP.buffer = _bitmap[0].bitmapData;
			_width = FP.width;
			_height = FP.height;
			update();
		}
		
		/**
		 * Swaps screen buffers.
		 */
		public function swap():void
		{
			_current = 1 - _current;
			FP.buffer = _bitmap[_current].bitmapData;
		}
		
		/**
		 * Refreshes the screen.
		 */
		internal function refresh():void
		{
			// refreshes the screen
			FP.buffer.fillRect(FP.bounds, _color);
		}
		
		/**
		 * Redraws the screen.
		 */
		internal function redraw():void
		{
			// refresh the buffers
			_bitmap[_current].visible = true;
			_bitmap[1 - _current].visible = false;
		}
		
		/** @private Re-applies transformation matrix. */
		private function update():void
		{
			_matrix.b = _matrix.c = 0;
			_matrix.a = _scaleX * _scale;
			_matrix.d = _scaleY * _scale;
			_matrix.tx = -_originX * _matrix.a;
			_matrix.ty = -_originY * _matrix.d;
			if (_angle != 0) _matrix.rotate(_angle);
			_matrix.tx += _originX * _scaleX * _scale + _x;
			_matrix.ty += _originY * _scaleX * _scale + _y;
			_sprite.transform.matrix = _matrix;
		}
		
		/**
		 * Refresh color of the screen.
		 */
		public function get color():uint { return _color; }
		public function set color(value:uint):void { _color = 0xFF000000 | value; }
		
		/**
		 * X offset of the screen.
		 */
		public function get x():int { return _x; }
		public function set x(value:int):void
		{
			if (_x == value) return;
			_x = value;
			update();
		}
		
		/**
		 * Y offset of the screen.
		 */
		public function get y():int { return _y; }
		public function set y(value:int):void
		{
			if (_y == value) return;
			_y = value;
			update();
		}
		
		/**
		 * X origin of transformations.
		 */
		public function get originX():int { return _originX; }
		public function set originX(value:int):void
		{
			if (_originX == value) return;
			_originX = value;
			update();
		}
		
		/**
		 * Y origin of transformations.
		 */
		public function get originY():int { return _originY; }
		public function set originY(value:int):void
		{
			if (_originY == value) return;
			_originY = value;
			update();
		}
		
		/**
		 * X scale of the screen.
		 */
		public function get scaleX():Number { return _scaleX; }
		public function set scaleX(value:Number):void
		{
			if (_scaleX == value) return;
			_scaleX = value;
			update();
		}
		
		/**
		 * Y scale of the screen.
		 */
		public function get scaleY():Number { return _scaleY; }
		public function set scaleY(value:Number):void
		{
			if (_scaleY == value) return;
			_scaleY = value;
			update();
		}
		
		/**
		 * Scale factor of the screen. Final scale is scaleX * scale by scaleY * scale, so
		 * you can use this factor to scale the screen both horizontally and vertically.
		 */
		public function get scale():Number { return _scale; }
		public function set scale(value:Number):void
		{
			if (_scale == value) return;
			_scale = value;
			update();
		}
		
		/**
		 * Rotation of the screen, in degrees.
		 */
		public function get angle():Number { return _angle * FP.DEG; }
		public function set angle(value:Number):void
		{
			if (_angle == value) return;
			_angle = value * FP.RAD;
			update();
		}
		
		/**
		 * Whether screen smoothing should be used or not.
		 */
		public function get smoothing():Boolean { return _bitmap[0].smoothing; }
		public function set smoothing(value:Boolean):void { _bitmap[0].smoothing = _bitmap[1].smoothing = value; }
		
		/**
		 * Width of the screen.
		 */
		public function get width():uint { return _width; }
		
		/**
		 * Height of the screen.
		 */
		public function get height():uint { return _height; }
		
		/**
		 * X position of the mouse on the screen.
		 */
		public function get mouseX():int { return (FP.stage.mouseX - _x) / (_scaleX * _scale); }
		
		/**
		 * Y position of the mouse on the screen.
		 */
		public function get mouseY():int { return (FP.stage.mouseY - _y) / (_scaleY * _scale); }
		
		// Screen infromation.
		/** @private */ private var _sprite:Sprite = new Sprite;
		/** @private */ private var _bitmap:Vector.<Bitmap> = new Vector.<Bitmap>(2);
		/** @private */ private var _current:int = 0;
		/** @private */ private var _matrix:Matrix = new Matrix;
		/** @private */ private var _x:int;
		/** @private */ private var _y:int;
		/** @private */ private var _width:uint;
		/** @private */ private var _height:uint;
		/** @private */ private var _originX:int;
		/** @private */ private var _originY:int;
		/** @private */ private var _scaleX:Number = 1;
		/** @private */ private var _scaleY:Number = 1;
		/** @private */ private var _scale:Number = 1;
		/** @private */ private var _angle:Number = 0;
		/** @private */ private var _color:uint = 0x202020;
	}
}
{'fraction_non_alphanumeric': 0.13809261300992282, 'fraction_numerical': 0.006247703050349137, 'mean_word_length': 2.8260105448154658, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5796030', 'n_tokens_mistral': 4187, 'n_tokens_neox': 3460, 'n_words': 1017}