diff --git a/hmm.json b/hmm.json index 8206675e3fa..32d2d37a249 100644 --- a/hmm.json +++ b/hmm.json @@ -8,7 +8,7 @@ { "name": "openfl", "type": "haxelib", - "version": null + "version": "9.2.1" }, { "name": "flixel", diff --git a/source/openfl/display/Bitmap.hx b/source/openfl/display/Bitmap.hx deleted file mode 100644 index 553cfd48d46..00000000000 --- a/source/openfl/display/Bitmap.hx +++ /dev/null @@ -1,246 +0,0 @@ -package openfl.display; - -#if !flash -import openfl.geom.Matrix; -import openfl.geom.Rectangle; -#if (js && html5) -import js.html.ImageElement; -#end - -/** - The Bitmap class represents display objects that represent bitmap images. - These can be images that you load with the `openfl.Assets` or - `openfl.display.Loader` classes, or they can be images that you - create with the `Bitmap()` constructor. - - The `Bitmap()` constructor allows you to create a Bitmap - object that contains a reference to a BitmapData object. After you create a - Bitmap object, use the `addChild()` or `addChildAt()` - method of the parent DisplayObjectContainer instance to place the bitmap on - the display list. - - A Bitmap object can share its BitmapData reference among several Bitmap - objects, independent of translation or rotation properties. Because you can - create multiple Bitmap objects that reference the same BitmapData object, - multiple display objects can use the same complex BitmapData object without - incurring the memory overhead of a BitmapData object for each display - object instance. - - A BitmapData object can be drawn to the screen by a Bitmap object in one - of two ways: by using the default hardware renderer with a single hardware surface, - or by using the slower software renderer when 3D acceleration is not available. - - If you would prefer to perform a batch rendering command, rather than using a - single surface for each Bitmap object, you can also draw to the screen using the - `openfl.display.Tilemap` class. - - **Note:** The Bitmap class is not a subclass of the InteractiveObject - class, so it cannot dispatch mouse events. However, you can use the - `addEventListener()` method of the display object container that - contains the Bitmap object. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display.BitmapData) -@:access(openfl.display.Graphics) -@:access(openfl.geom.ColorTransform) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Rectangle) -class Bitmap extends DisplayObject -{ - /** - The BitmapData object being referenced. - **/ - public var bitmapData(get, set):BitmapData; - - /** - Controls whether or not the Bitmap object is snapped to the nearest pixel. - This value is ignored in the native and HTML5 targets. - The PixelSnapping class includes possible values: - - * `PixelSnapping.NEVER` - No pixel snapping occurs. - * `PixelSnapping.ALWAYS` - The image is always snapped to - the nearest pixel, independent of transformation. - * `PixelSnapping.AUTO` - The image is snapped to the - nearest pixel if it is drawn with no rotation or skew and it is drawn at a - scale factor of 99.9% to 100.1%. If these conditions are satisfied, the - bitmap image is drawn at 100% scale, snapped to the nearest pixel. - When targeting Flash Player, this value allows the image to be drawn as fast - as possible using the internal vector renderer. - - **/ - public var pixelSnapping:PixelSnapping; - - /** - Controls whether or not the bitmap is smoothed when scaled. If - `true`, the bitmap is smoothed when scaled. If - `false`, the bitmap is not smoothed when scaled. - **/ - public var smoothing:Bool; - - #if (js && html5) - @:noCompletion private var __image:ImageElement; - #end - @:noCompletion private var __bitmapData:BitmapData; - @:noCompletion private var __imageVersion:Int; - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperty(Bitmap.prototype, "bitmapData", { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_bitmapData (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_bitmapData (v); }") - }); - } - #end - - /** - Initializes a Bitmap object to refer to the specified BitmapData object. - - @param bitmapData The BitmapData object being referenced. - @param pixelSnapping Whether or not the Bitmap object is snapped to the nearest pixel. - @param smoothing Whether or not the bitmap is smoothed when scaled. For example, the following examples - show the same bitmap scaled by a factor of 3, with `smoothing` set to `false` (left) and `true` (right): - - ![A bitmap without smoothing.](/images/bitmap_smoothing_off.jpg) ![A bitmap with smoothing.](bitmap_smoothing_on.jpg) - **/ - public function new(bitmapData:BitmapData = null, pixelSnapping:PixelSnapping = null, smoothing:Bool = false) - { - super(); - - __drawableType = BITMAP; - __bitmapData = bitmapData; - this.pixelSnapping = pixelSnapping; - this.smoothing = smoothing; - - if (pixelSnapping == null) - { - this.pixelSnapping = PixelSnapping.AUTO; - } - } - - @:noCompletion private override function __enterFrame(deltaTime:Float):Void - { - if (__bitmapData != null && __bitmapData.image != null && __bitmapData.image.version != __imageVersion) - { - __setRenderDirty(); - } - } - - @:noCompletion private override function __getBounds(rect:Rectangle, matrix:Matrix):Void - { - var bounds = Rectangle.__pool.get(); - if (__bitmapData != null) - { - bounds.setTo(0, 0, __bitmapData.width, __bitmapData.height); - } - else - { - bounds.setTo(0, 0, 0, 0); - } - - bounds.__transform(bounds, matrix); - rect.__expand(bounds.x, bounds.y, bounds.width, bounds.height); - Rectangle.__pool.release(bounds); - } - - @:noCompletion private override function __hitTest(x:Float, y:Float, shapeFlag:Bool, stack:Array, interactiveOnly:Bool, - hitObject:DisplayObject):Bool - { - if (!hitObject.visible || __isMask || __bitmapData == null) return false; - if (mask != null && !mask.__hitTestMask(x, y)) return false; - - __getRenderTransform(); - - var px = __renderTransform.__transformInverseX(x, y); - var py = __renderTransform.__transformInverseY(x, y); - - if (px > 0 && py > 0 && px <= __bitmapData.width && py <= __bitmapData.height) - { - if (__scrollRect != null && !__scrollRect.contains(px, py)) - { - return false; - } - - if (stack != null && !interactiveOnly) - { - stack.push(hitObject); - } - - return true; - } - - return false; - } - - @:noCompletion private override function __hitTestMask(x:Float, y:Float):Bool - { - if (__bitmapData == null) return false; - - __getRenderTransform(); - - var px = __renderTransform.__transformInverseX(x, y); - var py = __renderTransform.__transformInverseY(x, y); - - if (px > 0 && py > 0 && px <= __bitmapData.width && py <= __bitmapData.height) - { - return true; - } - - return false; - } - - // Get & Set Methods - @:noCompletion private function get_bitmapData():BitmapData - { - return __bitmapData; - } - - @:noCompletion private function set_bitmapData(value:BitmapData):BitmapData - { - __bitmapData = value; - smoothing = false; - - __setRenderDirty(); - - if (__filters != null) - { - // __updateFilters = true; - } - - __imageVersion = -1; - - return __bitmapData; - } - - @:noCompletion private override function set_height(value:Float):Float - { - if (__bitmapData != null) - { - scaleY = value / __bitmapData.height; // get_height(); - } - else - { - scaleY = 0; - } - return value; - } - - @:noCompletion private override function set_width(value:Float):Float - { - if (__bitmapData != null) - { - scaleX = value / __bitmapData.width; // get_width(); - } - else - { - scaleX = 0; - } - return value; - } -} -#else -typedef Bitmap = flash.display.Bitmap; -#end diff --git a/source/openfl/display/DisplayObject.hx b/source/openfl/display/DisplayObject.hx deleted file mode 100644 index e3f276be7e5..00000000000 --- a/source/openfl/display/DisplayObject.hx +++ /dev/null @@ -1,2354 +0,0 @@ -package openfl.display; - -#if !flash -import openfl.display._internal.IBitmapDrawableType; -import openfl.utils.ObjectPool; -import openfl.utils._internal.Lib; -import openfl.errors.TypeError; -import openfl.events.Event; -import openfl.events.EventDispatcher; -import openfl.events.EventPhase; -import openfl.events.EventType; -import openfl.events.MouseEvent; -import openfl.events.RenderEvent; -import openfl.events.TouchEvent; -import openfl.filters.BitmapFilter; -import openfl.geom.ColorTransform; -import openfl.geom.Matrix; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.geom.Transform; -import openfl.ui.MouseCursor; -import openfl.Vector; -#if lime -import lime.graphics.cairo.Cairo; -#end -#if (js && html5) -import js.html.CanvasElement; -import js.html.CanvasRenderingContext2D; -import js.html.CSSStyleDeclaration; -#end - -/** - The DisplayObject class is the base class for all objects that can be - placed on the display list. The display list manages all objects displayed - in openfl. Use the DisplayObjectContainer class to arrange the - display objects in the display list. DisplayObjectContainer objects can - have child display objects, while other display objects, such as Shape and - TextField objects, are "leaf" nodes that have only parents and siblings, no - children. - - The DisplayObject class supports basic functionality like the _x_ - and _y_ position of an object, as well as more advanced properties of - the object such as its transformation matrix. - - DisplayObject is an abstract base class; therefore, you cannot call - DisplayObject directly. Invoking `new DisplayObject()` throws an - `ArgumentError` exception. - - All display objects inherit from the DisplayObject class. - - The DisplayObject class itself does not include any APIs for rendering - content onscreen. For that reason, if you want create a custom subclass of - the DisplayObject class, you will want to extend one of its subclasses that - do have APIs for rendering content onscreen, such as the Shape, Sprite, - Bitmap, SimpleButton, TextField, or MovieClip class. - - The DisplayObject class contains several broadcast events. Normally, the - target of any particular event is a specific DisplayObject instance. For - example, the target of an `added` event is the specific - DisplayObject instance that was added to the display list. Having a single - target restricts the placement of event listeners to that target and in - some cases the target's ancestors on the display list. With broadcast - events, however, the target is not a specific DisplayObject instance, but - rather all DisplayObject instances, including those that are not on the - display list. This means that you can add a listener to any DisplayObject - instance to listen for broadcast events. In addition to the broadcast - events listed in the DisplayObject class's Events table, the DisplayObject - class also inherits two broadcast events from the EventDispatcher class: - `activate` and `deactivate`. - - Some properties previously used in the ActionScript 1.0 and 2.0 - MovieClip, TextField, and Button classes(such as `_alpha`, - `_height`, `_name`, `_width`, - `_x`, `_y`, and others) have equivalents in the - ActionScript 3.0 DisplayObject class that are renamed so that they no - longer begin with the underscore(_) character. - - For more information, see the "Display Programming" chapter of the - _ActionScript 3.0 Developer's Guide_. - - @event added Dispatched when a display object is added to the - display list. The following methods trigger this - event: - `DisplayObjectContainer.addChild()`, - `DisplayObjectContainer.addChildAt()`. - @event addedToStage Dispatched when a display object is added to the on - stage display list, either directly or through the - addition of a sub tree in which the display object - is contained. The following methods trigger this - event: - `DisplayObjectContainer.addChild()`, - `DisplayObjectContainer.addChildAt()`. - @event enterFrame [broadcast event] Dispatched when the playhead is - entering a new frame. If the playhead is not - moving, or if there is only one frame, this event - is dispatched continuously in conjunction with the - frame rate. This event is a broadcast event, which - means that it is dispatched by all display objects - with a listener registered for this event. - @event exitFrame [broadcast event] Dispatched when the playhead is - exiting the current frame. All frame scripts have - been run. If the playhead is not moving, or if - there is only one frame, this event is dispatched - continuously in conjunction with the frame rate. - This event is a broadcast event, which means that - it is dispatched by all display objects with a - listener registered for this event. - @event frameConstructed [broadcast event] Dispatched after the constructors - of frame display objects have run but before frame - scripts have run. If the playhead is not moving, or - if there is only one frame, this event is - dispatched continuously in conjunction with the - frame rate. This event is a broadcast event, which - means that it is dispatched by all display objects - with a listener registered for this event. - @event removed Dispatched when a display object is about to be - removed from the display list. Two methods of the - DisplayObjectContainer class generate this event: - `removeChild()` and - `removeChildAt()`. - - The following methods of a - DisplayObjectContainer object also generate this - event if an object must be removed to make room for - the new object: `addChild()`, - `addChildAt()`, and - `setChildIndex()`. - @event removedFromStage Dispatched when a display object is about to be - removed from the display list, either directly or - through the removal of a sub tree in which the - display object is contained. Two methods of the - DisplayObjectContainer class generate this event: - `removeChild()` and - `removeChildAt()`. - - The following methods of a - DisplayObjectContainer object also generate this - event if an object must be removed to make room for - the new object: `addChild()`, - `addChildAt()`, and - `setChildIndex()`. - @event render [broadcast event] Dispatched when the display list - is about to be updated and rendered. This event - provides the last opportunity for objects listening - for this event to make changes before the display - list is rendered. You must call the - `invalidate()` method of the Stage - object each time you want a `render` - event to be dispatched. `Render` events - are dispatched to an object only if there is mutual - trust between it and the object that called - `Stage.invalidate()`. This event is a - broadcast event, which means that it is dispatched - by all display objects with a listener registered - for this event. - - **Note: **This event is not dispatched if the - display is not rendering. This is the case when the - content is either minimized or obscured. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(lime.graphics.Image) -@:access(lime.graphics.ImageBuffer) -@:access(openfl.display3D._internal.Context3DState) -@:access(openfl.display._internal.Context3DGraphics) -@:access(openfl.events.Event) -@:access(openfl.display3D.Context3D) -@:access(openfl.display.Bitmap) -@:access(openfl.display.BitmapData) -@:access(openfl.display.DisplayObjectContainer) -@:access(openfl.display.Graphics) -@:access(openfl.display.Shader) -@:access(openfl.display.Stage) -@:access(openfl.filters.BitmapFilter) -@:access(openfl.geom.ColorTransform) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Rectangle) -@:access(openfl.geom.Transform) -class DisplayObject extends EventDispatcher implements IBitmapDrawable #if (openfl_dynamic && haxe_ver < "4.0.0") implements Dynamic #end -{ - @:noCompletion private static var __broadcastEvents:Map> = new Map(); - @:noCompletion private static var __initStage:Stage; - @:noCompletion private static var __instanceCount:Int = 0; - - @:noCompletion - private static #if !js inline #end var __supportDOM:Bool #if !js = false #end; - - @:noCompletion private static var __tempStack:ObjectPool> = new ObjectPool>(function() return - new Vector(), function(stack) stack.length = 0); - - #if false - /** - The current accessibility options for this display object. If you modify the `accessibilityProperties` - property or any of the fields within `accessibilityProperties`, you must call the - `Accessibility.updateProperties()` method to make your changes take effect. - - **Note:** For an object created in the Flash authoring environment, the value of `accessibilityProperties` - is prepopulated with any information you entered in the Accessibility panel for that object. - **/ - // @:noCompletion @:dox(hide) public var accessibilityProperties:openfl.accessibility.AccessibilityProperties; - #end - - /** - Indicates the alpha transparency value of the object specified. Valid - values are 0 (fully transparent) to 1 (fully opaque). The default value is 1. - Display objects with `alpha` set to 0 _are_ active, even though they are invisible. - **/ - @:keep public var alpha(get, set):Float; - - /** - A value from the BlendMode class that specifies which blend mode to use. A - bitmap can be drawn internally in two ways. If you have a blend mode - enabled or an external clipping mask, the bitmap is drawn by adding a - bitmap-filled square shape to the vector render. If you attempt to set - this property to an invalid value, Flash runtimes set the value to - `BlendMode.NORMAL`. - - The `blendMode` property affects each pixel of the display - object. Each pixel is composed of three constituent colors(red, green, - and blue), and each constituent color has a value between 0x00 and 0xFF. - Flash Player or Adobe AIR compares each constituent color of one pixel in - the movie clip with the corresponding color of the pixel in the - background. For example, if `blendMode` is set to - `BlendMode.LIGHTEN`, Flash Player or Adobe AIR compares the red - value of the display object with the red value of the background, and uses - the lighter of the two as the value for the red component of the displayed - color. - - The following table describes the `blendMode` settings. The - BlendMode class defines string values you can use. The illustrations in - the table show `blendMode` values applied to a circular display - object(2) superimposed on another display object(1). - - ![Square Number 1](/images/blendMode-0a.jpg) ![Circle Number 2](/images/blendMode-0b.jpg) - - | BlendMode Constant | Illustration | Description | - | --- | --- | --- | - | `BlendMode.NORMAL` | ![blend mode NORMAL](/images/blendMode-1.jpg) | The display object appears in front of the background. Pixel values of the display object override those of the background. Where the display object is transparent, the background is visible. | - | `BlendMode.LAYER` | ![blend mode LAYER](/images/blendMode-2.jpg) | Forces the creation of a transparency group for the display object. This means that the display object is pre-composed in a temporary buffer before it is processed further. This is done automatically if the display object is pre-cached using bitmap caching or if the display object is a display object container with at least one child object with a `blendMode` setting other than `BlendMode.NORMAL`. Not supported under GPU rendering. | - | `BlendMode.MULTIPLY` | ![blend mode MULTIPLY](/images/blendMode-3.jpg) | Multiplies the values of the display object constituent colors by the colors of the background color, and then normalizes by dividing by 0xFF, resulting in darker colors. This setting is commonly used for shadows and depth effects.
For example, if a constituent color (such as red) of one pixel in the display object and the corresponding color of the pixel in the background both have the value 0x88, the multiplied result is 0x4840. Dividing by 0xFF yields a value of 0x48 for that constituent color, which is a darker shade than the color of the display object or the color of the background. | - | `BlendMode.SCREEN` | ![blend mode SCREEN](/images/blendMode-4.jpg) | Multiplies the complement (inverse) of the display object color by the complement of the background color, resulting in a bleaching effect. This setting is commonly used for highlights or to remove black areas of the display object. | - | `BlendMode.LIGHTEN` | ![blend mode LIGHTEN](/images/blendMode-5.jpg) | Selects the lighter of the constituent colors of the display object and the color of the background (the colors with the larger values). This setting is commonly used for superimposing type.
For example, if the display object has a pixel with an RGB value of 0xFFCC33, and the background pixel has an RGB value of 0xDDF800, the resulting RGB value for the displayed pixel is 0xFFF833 (because 0xFF > 0xDD, 0xCC < 0xF8, and 0x33 > 0x00 = 33). Not supported under GPU rendering. | - | `BlendMode.DARKEN` | ![blend mode DARKEN](/images/blendMode-6.jpg) | Selects the darker of the constituent colors of the display object and the colors of the background (the colors with the smaller values). This setting is commonly used for superimposing type.
For example, if the display object has a pixel with an RGB value of 0xFFCC33, and the background pixel has an RGB value of 0xDDF800, the resulting RGB value for the displayed pixel is 0xDDCC00 (because 0xFF > 0xDD, 0xCC < 0xF8, and 0x33 > 0x00 = 33). Not supported under GPU rendering. | - | `BlendMode.DIFFERENCE` | ![blend mode DIFFERENCE](/images/blendMode-7.jpg) | Compares the constituent colors of the display object with the colors of its background, and subtracts the darker of the values of the two constituent colors from the lighter value. This setting is commonly used for more vibrant colors.
For example, if the display object has a pixel with an RGB value of 0xFFCC33, and the background pixel has an RGB value of 0xDDF800, the resulting RGB value for the displayed pixel is 0x222C33 (because 0xFF - 0xDD = 0x22, 0xF8 - 0xCC = 0x2C, and 0x33 - 0x00 = 0x33). | - | `BlendMode.ADD` | ![blend mode ADD](/images/blendMode-8.jpg) | Adds the values of the constituent colors of the display object to the colors of its background, applying a ceiling of 0xFF. This setting is commonly used for animating a lightening dissolve between two objects.
For example, if the display object has a pixel with an RGB value of 0xAAA633, and the background pixel has an RGB value of 0xDD2200, the resulting RGB value for the displayed pixel is 0xFFC833 (because 0xAA + 0xDD > 0xFF, 0xA6 + 0x22 = 0xC8, and 0x33 + 0x00 = 0x33). | - | `BlendMode.SUBTRACT` | ![blend mode SUBTRACT](/images/blendMode-9.jpg) | Subtracts the values of the constituent colors in the display object from the values of the background color, applying a floor of 0. This setting is commonly used for animating a darkening dissolve between two objects.
For example, if the display object has a pixel with an RGB value of 0xAA2233, and the background pixel has an RGB value of 0xDDA600, the resulting RGB value for the displayed pixel is 0x338400 (because 0xDD - 0xAA = 0x33, 0xA6 - 0x22 = 0x84, and 0x00 - 0x33 < 0x00). | - | `BlendMode.INVERT` | ![blend mode INVERT](/images/blendMode-10.jpg) | Inverts the background. | - | `BlendMode.ALPHA` | ![blend mode ALPHA](/images/blendMode-11.jpg) | Applies the alpha value of each pixel of the display object to the background. This requires the `blendMode` setting of the parent display object to be set to `BlendMode.LAYER`. For example, in the illustration, the parent display object, which is a white background, has `blendMode = BlendMode.LAYER`. Not supported under GPU rendering. | - | `BlendMode.ERASE` | ![blend mode ERASE](/images/blendMode-12.jpg) | Erases the background based on the alpha value of the display object. This requires the `blendMode` of the parent display object to be set to `BlendMode.LAYER`. For example, in the illustration, the parent display object, which is a white background, has `blendMode = BlendMode.LAYER`. Not supported under GPU rendering. | - | `BlendMode.OVERLAY` | ![blend mode OVERLAY](/images/blendMode-13.jpg) | Adjusts the color of each pixel based on the darkness of the background. If the background is lighter than 50% gray, the display object and background colors are screened, which results in a lighter color. If the background is darker than 50% gray, the colors are multiplied, which results in a darker color. This setting is commonly used for shading effects. Not supported under GPU rendering. | - | `BlendMode.HARDLIGHT` | ![blend mode HARDLIGHT](/images/blendMode-14.jpg) | Adjusts the color of each pixel based on the darkness of the display object. If the display object is lighter than 50% gray, the display object and background colors are screened, which results in a lighter color. If the display object is darker than 50% gray, the colors are multiplied, which results in a darker color. This setting is commonly used for shading effects. Not supported under GPU rendering. | - | `BlendMode.SHADER` | N/A | Adjusts the color using a custom shader routine. The shader that is used is specified as the Shader instance assigned to the blendShader property. Setting the blendShader property of a display object to a Shader instance automatically sets the display object's `blendMode` property to `BlendMode.SHADER`. If the `blendMode` property is set to `BlendMode.SHADER` without first setting the `blendShader` property, the `blendMode` property is set to `BlendMode.NORMAL`. Not supported under GPU rendering. | - **/ - public var blendMode(get, set):BlendMode; - - #if false - /** - Sets a shader that is used for blending the foreground and background. When the `blendMode` property is set - to `BlendMode.SHADER`, the specified Shader is used to create the blend mode output for the display object. - - Setting the `blendShader` property of a display object to a Shader instance automatically sets the display - object's `blendMode` property to `BlendMode.SHADER`. If the `blendShader` property is set (which sets the - `blendMode` property to `BlendMode.SHADER`), then the value of the `blendMode` property is changed, the - blend mode can be reset to use the blend shader simply by setting the `blendMode` property to - `BlendMode.SHADER`. The `blendShader` property does not need to be set again except to change the shader - that's used for the blend mode. - - The Shader assigned to the `blendShader` property must specify at least two `image4` inputs. The inputs do - not need to be specified in code using the associated ShaderInput objects' input properties. The background - display object is automatically used as the first input (the input with index 0). The foreground display - object is used as the second input (the input with index 1). A shader used as a blend shader can specify more - than two inputs. In that case, any additional input must be specified by setting its ShaderInput instance's - `input` property. - - When you assign a Shader instance to this property the shader is copied internally. The blend operation uses - that internal copy, not a reference to the original shader. Any changes made to the shader, such as changing - a parameter value, input, or bytecode, are not applied to the copied shader that's used for the blend mode. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var blendShader(null, default):Shader; - #end - - /** - All vector data for a display object that has a cached bitmap is drawn - to the bitmap instead of the main display. If - `cacheAsBitmapMatrix` is null or unsupported, the bitmap is - then copied to the main display as unstretched, unrotated pixels snapped - to the nearest pixel boundaries. Pixels are mapped 1 to 1 with the parent - object. If the bounds of the bitmap change, the bitmap is recreated - instead of being stretched. - - If `cacheAsBitmapMatrix` is non-null and supported, the - object is drawn to the off-screen bitmap using that matrix and the - stretched and/or rotated results of that rendering are used to draw the - object to the main display. - - No internal bitmap is created unless the `cacheAsBitmap` - property is set to `true`. - - After you set the `cacheAsBitmap` property to - `true`, the rendering does not change, however the display - object performs pixel snapping automatically. The animation speed can be - significantly faster depending on the complexity of the vector content. - - The `cacheAsBitmap` property is automatically set to - `true` whenever you apply a filter to a display object(when - its `filter` array is not empty), and if a display object has a - filter applied to it, `cacheAsBitmap` is reported as - `true` for that display object, even if you set the property to - `false`. If you clear all filters for a display object, the - `cacheAsBitmap` setting changes to what it was last set to. - - A display object does not use a bitmap even if the - `cacheAsBitmap` property is set to `true` and - instead renders from vector data in the following cases: - - * The bitmap is too large. In AIR 1.5 and Flash Player 10, the maximum - size for a bitmap image is 8,191 pixels in width or height, and the total - number of pixels cannot exceed 16,777,215 pixels.(So, if a bitmap image - is 8,191 pixels wide, it can only be 2,048 pixels high.) In Flash Player 9 - and earlier, the limitation is is 2880 pixels in height and 2,880 pixels - in width. - * The bitmap fails to allocate(out of memory error). - - The `cacheAsBitmap` property is best used with movie clips - that have mostly static content and that do not scale and rotate - frequently. With such movie clips, `cacheAsBitmap` can lead to - performance increases when the movie clip is translated(when its _x_ - and _y_ position is changed). - **/ - public var cacheAsBitmap(get, set):Bool; - - /** - If non-null, this Matrix object defines how a display object is rendered when `cacheAsBitmap` is set to - `true`. The application uses this matrix as a transformation matrix that is applied when rendering the - bitmap version of the display object. - - _Adobe AIR profile support:_ This feature is supported on mobile devices, but it is not supported on desktop - operating systems. It also has limited support on AIR for TV devices. Specifically, on AIR for TV devices, - supported transformations include scaling and translation, but not rotation and skewing. See - [AIR Profile Support](http://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html) - for more information regarding API support across multiple profiles. - - With `cacheAsBitmapMatrix` set, the application retains a cached bitmap image across various 2D - transformations, including translation, rotation, and scaling. If the application uses hardware acceleration, - the object will be stored in video memory as a texture. This allows the GPU to apply the supported - transformations to the object. The GPU can perform these transformations faster than the CPU. - - To use the hardware acceleration, set Rendering to GPU in the General tab of the iPhone Settings dialog box - in Flash Professional CS5. Or set the `renderMode` property to gpu in the application descriptor file. Note - that AIR for TV devices automatically use hardware acceleration if it is available. - - For example, the following code sends an untransformed bitmap representation of the display object to the GPU: - - ```haxe - var matrix:Matrix = new Matrix(); // creates an identity matrix - mySprite.cacheAsBitmapMatrix = matrix; - mySprite.cacheAsBitmap = true; - ``` - - Usually, the identity matrix (`new Matrix()`) suffices. However, you can use another matrix, such as a - scaled-down matrix, to upload a different bitmap to the GPU. For example, the following example applies a - `cacheAsBitmapMatrix` matrix that is scaled by 0.5 on the x and y axes. The bitmap object that the GPU uses - is smaller, however the GPU adjusts its size to match the `transform.matrix` property of the display object: - - ```haxe - var matrix:Matrix = new Matrix(); // creates an identity matrix - matrix.scale(0.5, 0.5); // scales the matrix - mySprite.cacheAsBitmapMatrix = matrix; - mySprite.cacheAsBitmap = true; - ``` - - Generally, you should choose to use a matrix that transforms the display object to the size that it will - appear in the application. For example, if your application displays the bitmap version of the sprite scaled - down by a half, use a matrix that scales down by a half. If you application will display the sprite larger - than its current dimensions, use a matrix that scales up by that factor. - - **Note:** The `cacheAsBitmapMatrix` property is suitable for 2D transformations. If you need to apply - transformations in 3D, you may do so by setting a 3D property of the object and manipulating its - `transform.matrix3D` property. If the application is packaged using GPU mode, this allows the 3D transforms - to be applied to the object by the GPU. The `cacheAsBitmapMatrix` is ignored for 3D objects. - **/ - public var cacheAsBitmapMatrix(get, set):Matrix; - - /** - An indexed array that contains each filter object currently associated - with the display object. The openfl.filters package contains several - classes that define specific filters you can use. - - Filters can be applied in Flash Professional at design time, or at run - time by using ActionScript code. To apply a filter by using ActionScript, - you must make a temporary copy of the entire `filters` array, - modify the temporary array, then assign the value of the temporary array - back to the `filters` array. You cannot directly add a new - filter object to the `filters` array. - - To add a filter by using ActionScript, perform the following steps - (assume that the target display object is named - `myDisplayObject`): - - 1. Create a new filter object by using the constructor method of your - chosen filter class. - 2. Assign the value of the `myDisplayObject.filters` array - to a temporary array, such as one named `myFilters`. - 3. Add the new filter object to the `myFilters` temporary - array. - 4. Assign the value of the temporary array to the - `myDisplayObject.filters` array. - - If the `filters` array is undefined, you do not need to use - a temporary array. Instead, you can directly assign an array literal that - contains one or more filter objects that you create. The first example in - the Examples section adds a drop shadow filter by using code that handles - both defined and undefined `filters` arrays. - - To modify an existing filter object, you must use the technique of - modifying a copy of the `filters` array: - - 1. Assign the value of the `filters` array to a temporary - array, such as one named `myFilters`. - 2. Modify the property by using the temporary array, - `myFilters`. For example, to set the quality property of the - first filter in the array, you could use the following code: - `myFilters[0].quality = 1;` - 3. Assign the value of the temporary array to the `filters` - array. - - At load time, if a display object has an associated filter, it is - marked to cache itself as a transparent bitmap. From this point forward, - as long as the display object has a valid filter list, the player caches - the display object as a bitmap. This source bitmap is used as a source - image for the filter effects. Each display object usually has two bitmaps: - one with the original unfiltered source display object and another for the - final image after filtering. The final image is used when rendering. As - long as the display object does not change, the final image does not need - updating. - - The openfl.filters package includes classes for filters. For example, to - create a DropShadow filter, you would write: - - @throws ArgumentError When `filters` includes a ShaderFilter - and the shader output type is not compatible with - this operation(the shader must specify a - `pixel4` output). - @throws ArgumentError When `filters` includes a ShaderFilter - and the shader doesn't specify any image input or - the first input is not an `image4` input. - @throws ArgumentError When `filters` includes a ShaderFilter - and the shader specifies an image input that isn't - provided. - @throws ArgumentError When `filters` includes a ShaderFilter, a - ByteArray or Vector. instance as a shader - input, and the `width` and - `height` properties aren't specified for - the ShaderInput object, or the specified values - don't match the amount of data in the input data. - See the `ShaderInput.input` property for - more information. - **/ - public var filters(get, set):Array; - - /** - Indicates the height of the display object, in pixels. The height is - calculated based on the bounds of the content of the display object. When - you set the `height` property, the `scaleY` property - is adjusted accordingly, as shown in the following code: - - Except for TextField and Video objects, a display object with no - content(such as an empty sprite) has a height of 0, even if you try to - set `height` to a different value. - **/ - @:keep public var height(get, set):Float; - - /** - Returns a LoaderInfo object containing information about loading the file - to which this display object belongs. The `loaderInfo` property - is defined only for the root display object of a SWF file or for a loaded - Bitmap(not for a Bitmap that is drawn with ActionScript). To find the - `loaderInfo` object associated with the SWF file that contains - a display object named `myDisplayObject`, use - `myDisplayObject.root.loaderInfo`. - - A large SWF file can monitor its download by calling - `this.root.loaderInfo.addEventListener(Event.COMPLETE, - func)`. - **/ - public var loaderInfo(get, never):LoaderInfo; - - /** - The calling display object is masked by the specified `mask` - object. To ensure that masking works when the Stage is scaled, the - `mask` display object must be in an active part of the display - list. The `mask` object itself is not drawn. Set - `mask` to `null` to remove the mask. - - To be able to scale a mask object, it must be on the display list. To - be able to drag a mask Sprite object(by calling its - `startDrag()` method), it must be on the display list. To call - the `startDrag()` method for a mask sprite based on a - `mouseDown` event being dispatched by the sprite, set the - sprite's `buttonMode` property to `true`. - - When display objects are cached by setting the - `cacheAsBitmap` property to `true` an the - `cacheAsBitmapMatrix` property to a Matrix object, both the - mask and the display object being masked must be part of the same cached - bitmap. Thus, if the display object is cached, then the mask must be a - child of the display object. If an ancestor of the display object on the - display list is cached, then the mask must be a child of that ancestor or - one of its descendents. If more than one ancestor of the masked object is - cached, then the mask must be a descendent of the cached container closest - to the masked object in the display list. - - **Note:** A single `mask` object cannot be used to mask - more than one calling display object. When the `mask` is - assigned to a second display object, it is removed as the mask of the - first object, and that object's `mask` property becomes - `null`. - **/ - public var mask(get, set):DisplayObject; - - /** - Indicates the x coordinate of the mouse or user input device position, in - pixels. - - **Note**: For a DisplayObject that has been rotated, the returned x - coordinate will reflect the non-rotated object. - **/ - public var mouseX(get, never):Float; - - /** - Indicates the y coordinate of the mouse or user input device position, in - pixels. - - **Note**: For a DisplayObject that has been rotated, the returned y - coordinate will reflect the non-rotated object. - **/ - public var mouseY(get, never):Float; - - /** - Indicates the instance name of the DisplayObject. The object can be - identified in the child list of its parent display object container by - calling the `getChildByName()` method of the display object - container. - - @throws IllegalOperationError If you are attempting to set this property - on an object that was placed on the timeline - in the Flash authoring tool. - **/ - public var name(get, set):String; - - /** - Specifies whether the display object is opaque with a certain background - color. A transparent bitmap contains alpha channel data and is drawn - transparently. An opaque bitmap has no alpha channel(and renders faster - than a transparent bitmap). If the bitmap is opaque, you specify its own - background color to use. - - If set to a number value, the surface is opaque(not transparent) with - the RGB background color that the number specifies. If set to - `null`(the default value), the display object has a - transparent background. - - The `opaqueBackground` property is intended mainly for use - with the `cacheAsBitmap` property, for rendering optimization. - For display objects in which the `cacheAsBitmap` property is - set to true, setting `opaqueBackground` can improve rendering - performance. - - The opaque background region is _not_ matched when calling the - `hitTestPoint()` method with the `shapeFlag` - parameter set to `true`. - - The opaque background region does not respond to mouse events. - **/ - public var opaqueBackground:Null; - - /** - Indicates the DisplayObjectContainer object that contains this display - object. Use the `parent` property to specify a relative path to - display objects that are above the current display object in the display - list hierarchy. - - You can use `parent` to move up multiple levels in the - display list as in the following: - - ```haxe - this.parent.parent.alpha = 20; - ``` - - @throws SecurityError The parent display object belongs to a security - sandbox to which you do not have access. You can - avoid this situation by having the parent movie call - the `Security.allowDomain()` method. - **/ - public var parent(default, null):DisplayObjectContainer; - - /** - For a display object in a loaded SWF file, the `root` property - is the top-most display object in the portion of the display list's tree - structure represented by that SWF file. For a Bitmap object representing a - loaded image file, the `root` property is the Bitmap object - itself. For the instance of the main class of the first SWF file loaded, - the `root` property is the display object itself. The - `root` property of the Stage object is the Stage object itself. - The `root` property is set to `null` for any display - object that has not been added to the display list, unless it has been - added to a display object container that is off the display list but that - is a child of the top-most display object in a loaded SWF file. - - For example, if you create a new Sprite object by calling the - `Sprite()` constructor method, its `root` property - is `null` until you add it to the display list(or to a display - object container that is off the display list but that is a child of the - top-most display object in a SWF file). - - For a loaded SWF file, even though the Loader object used to load the - file may not be on the display list, the top-most display object in the - SWF file has its `root` property set to itself. The Loader - object does not have its `root` property set until it is added - as a child of a display object for which the `root` property is - set. - **/ - public var root(get, never):DisplayObject; - - /** - Indicates the rotation of the DisplayObject instance, in degrees, from its - original orientation. Values from 0 to 180 represent clockwise rotation; - values from 0 to -180 represent counterclockwise rotation. Values outside - this range are added to or subtracted from 360 to obtain a value within - the range. For example, the statement `my_video.rotation = 450` - is the same as ` my_video.rotation = 90`. - **/ - @:keep public var rotation(get, set):Float; - - #if false - /** - Indicates the x-axis rotation of the DisplayObject instance, in degrees, from its original orientation - relative to the 3D parent container. Values from 0 to 180 represent clockwise rotation; values from 0 to - -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to - obtain a value within the range. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var rotationX:Float; - #end - - #if false - /** - Indicates the y-axis rotation of the DisplayObject instance, in degrees, from its original orientation - relative to the 3D parent container. Values from 0 to 180 represent clockwise rotation; values from 0 to - -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to - obtain a value within the range. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var rotationY:Float; - #end - - #if false - /** - Indicates the z-axis rotation of the DisplayObject instance, in degrees, from its original orientation - relative to the 3D parent container. Values from 0 to 180 represent clockwise rotation; values from 0 to - -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to - obtain a value within the range. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var rotationZ:Float; - #end - - /** - The current scaling grid that is in effect. If set to `null`, - the entire display object is scaled normally when any scale transformation - is applied. - - When you define the `scale9Grid` property, the display - object is divided into a grid with nine regions based on the - `scale9Grid` rectangle, which defines the center region of the - grid. The eight other regions of the grid are the following areas: - - * The upper-left corner outside of the rectangle - * The area above the rectangle - * The upper-right corner outside of the rectangle - * The area to the left of the rectangle - * The area to the right of the rectangle - * The lower-left corner outside of the rectangle - * The area below the rectangle - * The lower-right corner outside of the rectangle - - You can think of the eight regions outside of the center (defined by - the rectangle) as being like a picture frame that has special rules - applied to it when scaled. - - **Note:** Content that is not rendered through the `graphics` interface - of a display object will not be affected by the `scale9Grid` property. - - When the `scale9Grid` property is set and a display object - is scaled, all text and gradients are scaled normally; however, for other - types of objects the following rules apply: - - * Content in the center region is scaled normally. - * Content in the corners is not scaled. - * Content in the top and bottom regions is scaled horizontally only. - * Content in the left and right regions is scaled vertically only. - * All fills (including bitmaps, video, and gradients) are stretched to - fit their shapes. - - If a display object is rotated, all subsequent scaling is normal(and - the `scale9Grid` property is ignored). - - For example, consider the following display object and a rectangle that - is applied as the display object's `scale9Grid`: - - | | | - | --- | --- | - | ![display object image](/images/scale9Grid-a.jpg)
The display object. | ![display object scale 9 region](/images/scale9Grid-b.jpg)
The red rectangle shows the scale9Grid. | - - When the display object is scaled or stretched, the objects within the rectangle scale normally, but the - objects outside of the rectangle scale according to the `scale9Grid` rules: - - | | | - | --- | --- | - | Scaled to 75%: | ![display object at 75%](/images/scale9Grid-c.jpg) | - | Scaled to 50%: | ![display object at 50%](/images/scale9Grid-d.jpg) | - | Scaled to 25%: | ![display object at 25%](/images/scale9Grid-e.jpg) | - | Stretched horizontally 150%: | ![display stretched 150%](/images/scale9Grid-f.jpg) | - - A common use for setting `scale9Grid` is to set up a display - object to be used as a component, in which edge regions retain the same - width when the component is scaled. - - @throws ArgumentError If you pass an invalid argument to the method. - **/ - public var scale9Grid(get, set):Rectangle; - - /** - Indicates the horizontal scale (percentage) of the object as applied from - the registration point. The default registration point is (0,0). 1.0 - equals 100% scale. - - Scaling the local coordinate system changes the `x` and - `y` property values, which are defined in whole pixels. - **/ - @:keep public var scaleX(get, set):Float; - - /** - Indicates the vertical scale (percentage) of an object as applied from the - registration point of the object. The default registration point is (0,0). - 1.0 is 100% scale. - - Scaling the local coordinate system changes the `x` and - `y` property values, which are defined in whole pixels. - **/ - @:keep public var scaleY(get, set):Float; - - #if false - /** - Indicates the depth scale (percentage) of an object as applied from the registration point of the object. - The default registration point is (0,0). 1.0 is 100% scale. - - Scaling the local coordinate system changes the `x`, `y` and `z` property values, which are defined in whole - pixels. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var scaleZ:Float; - #end - - /** - The scroll rectangle bounds of the display object. The display object is - cropped to the size defined by the rectangle, and it scrolls within the - rectangle when you change the `x` and `y` properties - of the `scrollRect` object. - - The properties of the `scrollRect` Rectangle object use the - display object's coordinate space and are scaled just like the overall - display object. The corner bounds of the cropped window on the scrolling - display object are the origin of the display object(0,0) and the point - defined by the width and height of the rectangle. They are not centered - around the origin, but use the origin to define the upper-left corner of - the area. A scrolled display object always scrolls in whole pixel - increments. - - You can scroll an object left and right by setting the `x` - property of the `scrollRect` Rectangle object. You can scroll - an object up and down by setting the `y` property of the - `scrollRect` Rectangle object. If the display object is rotated - 90 and you scroll it left and right, the display object actually scrolls - up and down. - **/ - public var scrollRect(get, set):Rectangle; - - /** - **BETA** - - Applies a custom Shader object to use when rendering this display object (or its children) when using - hardware rendering. This occurs as a single-pass render on this object only, if visible. In order to - apply a post-process effect to multiple display objects at once, enable `cacheAsBitmap` or use the - `filters` property with a ShaderFilter - **/ - @:beta public var shader(get, set):Shader; - - /** - The Stage of the display object. A Flash runtime application has only one - Stage object. For example, you can create and load multiple display - objects into the display list, and the `stage` property of each - display object refers to the same Stage object(even if the display object - belongs to a loaded SWF file). - - If a display object is not added to the display list, its - `stage` property is set to `null`. - **/ - public var stage(default, null):Stage; - - /** - An object with properties pertaining to a display object's matrix, color - transform, and pixel bounds. The specific properties - matrix, - colorTransform, and three read-only properties - (`concatenatedMatrix`, `concatenatedColorTransform`, - and `pixelBounds`) - are described in the entry for the - Transform class. - - Each of the transform object's properties is itself an object. This - concept is important because the only way to set new values for the matrix - or colorTransform objects is to create a new object and copy that object - into the transform.matrix or transform.colorTransform property. - - For example, to increase the `tx` value of a display - object's matrix, you must make a copy of the entire matrix object, then - copy the new object into the matrix property of the transform object: - ` var myMatrix:Matrix = - myDisplayObject.transform.matrix; myMatrix.tx += 10; - myDisplayObject.transform.matrix = myMatrix; ` - - You cannot directly set the `tx` property. The following - code has no effect on `myDisplayObject`: - ` myDisplayObject.transform.matrix.tx += - 10; ` - - You can also copy an entire transform object and assign it to another - display object's transform property. For example, the following code - copies the entire transform object from `myOldDisplayObj` to - `myNewDisplayObj`: - `myNewDisplayObj.transform = myOldDisplayObj.transform;` - - The resulting display object, `myNewDisplayObj`, now has the - same values for its matrix, color transform, and pixel bounds as the old - display object, `myOldDisplayObj`. - - Note that AIR for TV devices use hardware acceleration, if it is - available, for color transforms. - **/ - @:keep public var transform(get, set):Transform; - - /** - Whether or not the display object is visible. Display objects that are not - visible are disabled. For example, if `visible=false` for an - InteractiveObject instance, it cannot be clicked. - **/ - public var visible(get, set):Bool; - - /** - Indicates the width of the display object, in pixels. The width is - calculated based on the bounds of the content of the display object. When - you set the `width` property, the `scaleX` property - is adjusted accordingly, as shown in the following code: - - Except for TextField and Video objects, a display object with no - content(such as an empty sprite) has a width of 0, even if you try to set - `width` to a different value. - **/ - @:keep public var width(get, set):Float; - - /** - Indicates the _x_ coordinate of the DisplayObject instance relative - to the local coordinates of the parent DisplayObjectContainer. If the - object is inside a DisplayObjectContainer that has transformations, it is - in the local coordinate system of the enclosing DisplayObjectContainer. - Thus, for a DisplayObjectContainer rotated 90 counterclockwise, the - DisplayObjectContainer's children inherit a coordinate system that is - rotated 90 counterclockwise. The object's coordinates refer to the - registration point position. - **/ - @:keep public var x(get, set):Float; - - /** - Indicates the _y_ coordinate of the DisplayObject instance relative - to the local coordinates of the parent DisplayObjectContainer. If the - object is inside a DisplayObjectContainer that has transformations, it is - in the local coordinate system of the enclosing DisplayObjectContainer. - Thus, for a DisplayObjectContainer rotated 90 counterclockwise, the - DisplayObjectContainer's children inherit a coordinate system that is - rotated 90 counterclockwise. The object's coordinates refer to the - registration point position. - **/ - @:keep public var y(get, set):Float; - - // @:noCompletion @:dox(hide) @:require(flash10) var z:Float; - @:noCompletion private var __alpha:Float; - @:noCompletion private var __blendMode:BlendMode; - @:noCompletion private var __cacheAsBitmap:Bool; - @:noCompletion private var __cacheAsBitmapMatrix:Matrix; - @:noCompletion private var __cacheBitmap:Bitmap; - @:noCompletion private var __cacheBitmapBackground:Null; - @:noCompletion private var __cacheBitmapColorTransform:ColorTransform; - @:noCompletion private var __cacheBitmapData:BitmapData; - @:noCompletion private var __cacheBitmapData2:BitmapData; - @:noCompletion private var __cacheBitmapData3:BitmapData; - @:noCompletion private var __cacheBitmapMatrix:Matrix; - @:noCompletion private var __cacheBitmapRenderer:DisplayObjectRenderer; - @SuppressWarnings("checkstyle:Dynamic") @:noCompletion private var __cairo:#if lime Cairo #else Dynamic #end; - @:noCompletion private var __children:Array; - @:noCompletion private var __customRenderClear:Bool; - @:noCompletion private var __customRenderEvent:RenderEvent; - @:noCompletion private var __drawableType:IBitmapDrawableType; - @:noCompletion private var __filters:Array; - @:noCompletion private var __graphics:Graphics; - @:noCompletion private var __interactive:Bool; - @:noCompletion private var __isCacheBitmapRender:Bool; - @:noCompletion private var __isMask:Bool; - @:noCompletion private var __loaderInfo:LoaderInfo; - @:noCompletion private var __mask:DisplayObject; - @:noCompletion private var __maskTarget:DisplayObject; - @:noCompletion private var __name:String; - @:noCompletion private var __objectTransform:Transform; - @:noCompletion private var __renderable:Bool; - @:noCompletion private var __renderDirty:Bool; - @:noCompletion private var __renderParent:DisplayObject; - @:noCompletion private var __renderTransform:Matrix; - @:noCompletion private var __renderTransformCache:Matrix; - @:noCompletion private var __renderTransformChanged:Bool; - @:noCompletion private var __rotation:Float; - @:noCompletion private var __rotationCosine:Float; - @:noCompletion private var __rotationSine:Float; - @:noCompletion private var __scale9Grid:Rectangle; - @:noCompletion private var __scaleX:Float; - @:noCompletion private var __scaleY:Float; - @:noCompletion private var __scrollRect:Rectangle; - @:noCompletion private var __shader:Shader; - @:noCompletion private var __tempPoint:Point; - @:noCompletion private var __transform:Matrix; - @:noCompletion private var __transformDirty:Bool; - @:noCompletion private var __visible:Bool; - @:noCompletion private var __worldAlpha:Float; - @:noCompletion private var __worldAlphaChanged:Bool; - @:noCompletion private var __worldBlendMode:BlendMode; - @:noCompletion private var __worldClip:Rectangle; - @:noCompletion private var __worldClipChanged:Bool; - @:noCompletion private var __worldColorTransform:ColorTransform; - @:noCompletion private var __worldShader:Shader; - @:noCompletion private var __worldScale9Grid:Rectangle; - @:noCompletion private var __worldTransform:Matrix; - @:noCompletion private var __worldVisible:Bool; - @:noCompletion private var __worldVisibleChanged:Bool; - @:noCompletion private var __worldTransformInvalid:Bool; - @:noCompletion private var __worldZ:Int; - #if (js && html5) - @:noCompletion private var __canvas:CanvasElement; - @:noCompletion private var __context:CanvasRenderingContext2D; - @:noCompletion private var __style:CSSStyleDeclaration; - #end - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(DisplayObject.prototype, { - "alpha": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_alpha (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_alpha (v); }") - }, - "blendMode": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_blendMode (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_blendMode (v); }") - }, - "cacheAsBitmap": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_cacheAsBitmap (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_cacheAsBitmap (v); }") - }, - "cacheAsBitmapMatrix": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_cacheAsBitmapMatrix (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_cacheAsBitmapMatrix (v); }") - }, - "filters": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_filters (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_filters (v); }") - }, - "height": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_height (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_height (v); }") - }, - "loaderInfo": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_loaderInfo (); }") - }, - "mask": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_mask (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_mask (v); }") - }, - "mouseX": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_mouseX (); }") - }, - "mouseY": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_mouseY (); }") - }, - "name": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_name (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_name (v); }") - }, - "root": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_root (); }") - }, - "rotation": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_rotation (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_rotation (v); }") - }, - "scaleX": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_scaleX (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_scaleX (v); }") - }, - "scaleY": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_scaleY (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_scaleY (v); }") - }, - "scrollRect": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_scrollRect (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_scrollRect (v); }") - }, - "shader": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_shader (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_shader (v); }") - }, - "transform": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_transform (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_transform (v); }") - }, - "visible": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_visible (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_visible (v); }") - }, - "width": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_width (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_width (v); }") - }, - "x": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_x (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_x (v); }") - }, - "y": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_y (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_y (v); }") - }, - }); - } - #end - - @:noCompletion private function new() - { - super(); - - __drawableType = DISPLAY_OBJECT; - - __alpha = 1; - __blendMode = NORMAL; - __cacheAsBitmap = false; - __transform = new Matrix(); - __visible = true; - - __rotation = 0; - __rotationSine = 0; - __rotationCosine = 1; - __scaleX = 1; - __scaleY = 1; - - __worldAlpha = 1; - __worldBlendMode = NORMAL; - __worldTransform = new Matrix(); - __worldColorTransform = new ColorTransform(); - __renderTransform = new Matrix(); - __worldVisible = true; - - name = "instance" + (++__instanceCount); - - if (__initStage != null) - { - this.stage = __initStage; - __initStage = null; - this.stage.addChild(this); - } - } - - @SuppressWarnings("checkstyle:Dynamic") - public override function addEventListener(type:EventType, listener:T->Void, useCapture:Bool = false, priority:Int = 0, - useWeakReference:Bool = false):Void - { - switch (type) - { - case Event.ACTIVATE, Event.DEACTIVATE, Event.ENTER_FRAME, Event.EXIT_FRAME, Event.FRAME_CONSTRUCTED, Event.RENDER: - if (!__broadcastEvents.exists(type)) - { - __broadcastEvents.set(type, []); - } - - var dispatchers = __broadcastEvents.get(type); - - if (dispatchers.indexOf(this) == -1) - { - dispatchers.push(this); - } - - case RenderEvent.CLEAR_DOM, RenderEvent.RENDER_CAIRO, RenderEvent.RENDER_CANVAS, RenderEvent.RENDER_DOM, RenderEvent.RENDER_OPENGL: - if (__customRenderEvent == null) - { - __customRenderEvent = new RenderEvent(null); - __customRenderEvent.objectColorTransform = new ColorTransform(); - __customRenderEvent.objectMatrix = new Matrix(); - __customRenderClear = true; - } - - default: - } - - super.addEventListener(type, listener, useCapture, priority, useWeakReference); - } - - public override function dispatchEvent(event:Event):Bool - { - if ((event is MouseEvent)) - { - var mouseEvent:MouseEvent = cast event; - mouseEvent.stageX = __getRenderTransform().__transformX(mouseEvent.localX, mouseEvent.localY); - mouseEvent.stageY = __getRenderTransform().__transformY(mouseEvent.localX, mouseEvent.localY); - } - else if ((event is TouchEvent)) - { - var touchEvent:TouchEvent = cast event; - touchEvent.stageX = __getRenderTransform().__transformX(touchEvent.localX, touchEvent.localY); - touchEvent.stageY = __getRenderTransform().__transformY(touchEvent.localX, touchEvent.localY); - } - - event.target = this; - - return __dispatchWithCapture(event); - } - - /** - Returns a rectangle that defines the area of the display object relative - to the coordinate system of the `targetCoordinateSpace` object. - Consider the following code, which shows how the rectangle returned can - vary depending on the `targetCoordinateSpace` parameter that - you pass to the method: - - **Note:** Use the `localToGlobal()` and - `globalToLocal()` methods to convert the display object's local - coordinates to display coordinates, or display coordinates to local - coordinates, respectively. - - The `getBounds()` method is similar to the - `getRect()` method; however, the Rectangle returned by the - `getBounds()` method includes any strokes on shapes, whereas - the Rectangle returned by the `getRect()` method does not. For - an example, see the description of the `getRect()` method. - - @param targetCoordinateSpace The display object that defines the - coordinate system to use. - @return The rectangle that defines the area of the display object relative - to the `targetCoordinateSpace` object's coordinate - system. - **/ - public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle - { - var matrix = Matrix.__pool.get(); - - if (targetCoordinateSpace != null && targetCoordinateSpace != this) - { - matrix.copyFrom(__getWorldTransform()); - - var targetMatrix = Matrix.__pool.get(); - - targetMatrix.copyFrom(targetCoordinateSpace.__getWorldTransform()); - targetMatrix.invert(); - - matrix.concat(targetMatrix); - - Matrix.__pool.release(targetMatrix); - } - else - { - matrix.identity(); - } - - var bounds = new Rectangle(); - __getBounds(bounds, matrix); - - Matrix.__pool.release(matrix); - - return bounds; - } - - /** - Returns a rectangle that defines the boundary of the display object, based - on the coordinate system defined by the `targetCoordinateSpace` - parameter, excluding any strokes on shapes. The values that the - `getRect()` method returns are the same or smaller than those - returned by the `getBounds()` method. - - **Note:** Use `localToGlobal()` and - `globalToLocal()` methods to convert the display object's local - coordinates to Stage coordinates, or Stage coordinates to local - coordinates, respectively. - - @param targetCoordinateSpace The display object that defines the - coordinate system to use. - @return The rectangle that defines the area of the display object relative - to the `targetCoordinateSpace` object's coordinate - system. - **/ - public function getRect(targetCoordinateSpace:DisplayObject):Rectangle - { - // should not account for stroke widths, but is that possible? - return getBounds(targetCoordinateSpace); - } - - /** - Converts the `point` object from the Stage(global) coordinates - to the display object's(local) coordinates. - - To use this method, first create an instance of the Point class. The - _x_ and _y_ values that you assign represent global coordinates - because they relate to the origin(0,0) of the main display area. Then - pass the Point instance as the parameter to the - `globalToLocal()` method. The method returns a new Point object - with _x_ and _y_ values that relate to the origin of the display - object instead of the origin of the Stage. - - @param point An object created with the Point class. The Point object - specifies the _x_ and _y_ coordinates as - properties. - @return A Point object with coordinates relative to the display object. - **/ - public function globalToLocal(pos:Point):Point - { - return __globalToLocal(pos, new Point()); - } - - // @:noCompletion @:dox(hide) @:require(flash10) public function globalToLocal3D (point:Point):Vector3D; - - /** - Evaluates the bounding box of the display object to see if it overlaps or - intersects with the bounding box of the `obj` display object. - - @param obj The display object to test against. - @return `true` if the bounding boxes of the display objects - intersect; `false` if not. - **/ - public function hitTestObject(obj:DisplayObject):Bool - { - if (obj != null && obj.parent != null && parent != null) - { - var currentBounds = getBounds(this); - var targetBounds = obj.getBounds(this); - - return currentBounds.intersects(targetBounds); - } - - return false; - } - - /** - Evaluates the display object to see if it overlaps or intersects with the - point specified by the `x` and `y` parameters. The - `x` and `y` parameters specify a point in the - coordinate space of the Stage, not the display object container that - contains the display object(unless that display object container is the - Stage). - - @param x The _x_ coordinate to test against this object. - @param y The _y_ coordinate to test against this object. - @param shapeFlag Whether to check against the actual pixels of the object - (`true`) or the bounding box - (`false`). - @return `true` if the display object overlaps or intersects - with the specified point; `false` otherwise. - **/ - public function hitTestPoint(x:Float, y:Float, shapeFlag:Bool = false):Bool - { - if (stage != null) - { - return __hitTest(x, y, shapeFlag, null, false, this); - } - else - { - return false; - } - } - - /** - Calling the `invalidate()` method signals to have the current object - redrawn the next time the object is eligible to be rendered. - **/ - public function invalidate():Void - { - __setRenderDirty(); - } - - /** - Converts the `point` object from the display object's(local) - coordinates to the Stage(global) coordinates. - - This method allows you to convert any given _x_ and _y_ - coordinates from values that are relative to the origin(0,0) of a - specific display object(local coordinates) to values that are relative to - the origin of the Stage(global coordinates). - - To use this method, first create an instance of the Point class. The - _x_ and _y_ values that you assign represent local coordinates - because they relate to the origin of the display object. - - You then pass the Point instance that you created as the parameter to - the `localToGlobal()` method. The method returns a new Point - object with _x_ and _y_ values that relate to the origin of the - Stage instead of the origin of the display object. - - @param point The name or identifier of a point created with the Point - class, specifying the _x_ and _y_ coordinates as - properties. - @return A Point object with coordinates relative to the Stage. - **/ - public function localToGlobal(point:Point):Point - { - return __getRenderTransform().transformPoint(point); - } - - // @:noCompletion @:dox(hide) @:require(flash10) public function local3DToGlobal (point3d:Vector3D):Point; - - @SuppressWarnings("checkstyle:Dynamic") - public override function removeEventListener(type:EventType, listener:T->Void, useCapture:Bool = false):Void - { - super.removeEventListener(type, listener, useCapture); - - switch (type) - { - case Event.ACTIVATE, Event.DEACTIVATE, Event.ENTER_FRAME, Event.EXIT_FRAME, Event.FRAME_CONSTRUCTED, Event.RENDER: - if (!hasEventListener(type)) - { - if (__broadcastEvents.exists(type)) - { - __broadcastEvents.get(type).remove(this); - } - } - - case RenderEvent.CLEAR_DOM, RenderEvent.RENDER_CAIRO, RenderEvent.RENDER_CANVAS, RenderEvent.RENDER_DOM, RenderEvent.RENDER_OPENGL: - if (!hasEventListener(RenderEvent.CLEAR_DOM) - && !hasEventListener(RenderEvent.RENDER_CAIRO) - && !hasEventListener(RenderEvent.RENDER_CANVAS) - && !hasEventListener(RenderEvent.RENDER_DOM) - && !hasEventListener(RenderEvent.RENDER_OPENGL)) - { - __customRenderEvent = null; - } - - default: - } - } - - @:noCompletion private static inline function __calculateAbsoluteTransform(local:Matrix, parentTransform:Matrix, target:Matrix):Void - { - target.a = local.a * parentTransform.a + local.b * parentTransform.c; - target.b = local.a * parentTransform.b + local.b * parentTransform.d; - target.c = local.c * parentTransform.a + local.d * parentTransform.c; - target.d = local.c * parentTransform.b + local.d * parentTransform.d; - target.tx = local.tx * parentTransform.a + local.ty * parentTransform.c + parentTransform.tx; - target.ty = local.tx * parentTransform.b + local.ty * parentTransform.d + parentTransform.ty; - } - - @:noCompletion private function __cleanup():Void - { - __cairo = null; - - #if (js && html5) - __canvas = null; - __context = null; - #end - - if (__graphics != null) - { - __graphics.__cleanup(); - } - - if (__cacheBitmap != null) - { - __cacheBitmap.__cleanup(); - __cacheBitmap = null; - } - - if (__cacheBitmapData != null) - { - __cacheBitmapData.dispose(); - __cacheBitmapData = null; - } - } - - @:noCompletion private function __dispatch(event:Event):Bool - { - if (__eventMap != null && hasEventListener(event.type)) - { - var result = super.__dispatchEvent(event); - - if (event.__isCanceled) - { - return true; - } - - return result; - } - - return true; - } - - @:noCompletion private function __dispatchChildren(event:Event):Void {} - - @:noCompletion private override function __dispatchEvent(event:Event):Bool - { - var parent = event.bubbles ? this.parent : null; - var result = super.__dispatchEvent(event); - - if (event.__isCanceled) - { - return true; - } - - if (parent != null && parent != this) - { - event.eventPhase = EventPhase.BUBBLING_PHASE; - - if (event.target == null) - { - event.target = this; - } - - parent.__dispatchEvent(event); - } - - return result; - } - - @:noCompletion private function __dispatchWithCapture(event:Event):Bool - { - if (event.target == null) - { - event.target = this; - } - - if (parent != null) - { - event.eventPhase = CAPTURING_PHASE; - - if (parent == stage) - { - parent.__dispatch(event); - } - else - { - var stack = __tempStack.get(); - var parent = parent; - var i = 0; - - while (parent != null) - { - stack[i] = parent; - parent = parent.parent; - i++; - } - - for (j in 0...i) - { - stack[i - j - 1].__dispatch(event); - } - - __tempStack.release(stack); - } - } - - event.eventPhase = AT_TARGET; - - return __dispatchEvent(event); - } - - @:noCompletion private function __enterFrame(deltaTime:Float):Void {} - - @:noCompletion private function __getBounds(rect:Rectangle, matrix:Matrix):Void - { - if (__graphics != null) - { - __graphics.__getBounds(rect, matrix); - } - } - - @:noCompletion private function __getCursor():MouseCursor - { - return null; - } - - @:noCompletion private function __getFilterBounds(rect:Rectangle, matrix:Matrix):Void - { - __getRenderBounds(rect, matrix); - - if (__filters != null) - { - var extension = Rectangle.__pool.get(); - - for (filter in __filters) - { - extension.__expand(-filter.__leftExtension, - -filter.__topExtension, filter.__leftExtension - + filter.__rightExtension, - filter.__topExtension - + filter.__bottomExtension); - } - - rect.width += extension.width; - rect.height += extension.height; - rect.x += extension.x; - rect.y += extension.y; - - Rectangle.__pool.release(extension); - } - } - - @:noCompletion private function __getInteractive(stack:Array):Bool - { - return false; - } - - @:noCompletion private function __getLocalBounds(rect:Rectangle):Void - { - // var cacheX = __transform.tx; - // var cacheY = __transform.ty; - // __transform.tx = __transform.ty = 0; - - __getBounds(rect, __transform); - - // __transform.tx = cacheX; - // __transform.ty = cacheY; - - rect.x -= __transform.tx; - rect.y -= __transform.ty; - } - - @:noCompletion private function __getRenderBounds(rect:Rectangle, matrix:Matrix):Void - { - if (__scrollRect == null) - { - __getBounds(rect, matrix); - } - else - { - // TODO: Should we have smaller bounds if scrollRect is larger than content? - - var r = Rectangle.__pool.get(); - r.copyFrom(__scrollRect); - r.__transform(r, matrix); - rect.__expand(r.x, r.y, r.width, r.height); - Rectangle.__pool.release(r); - } - } - - @:noCompletion private function __getRenderTransform():Matrix - { - __getWorldTransform(); - return __renderTransform; - } - - @:noCompletion private function __getWorldTransform():Matrix - { - var transformDirty = __transformDirty || __worldTransformInvalid; - - if (transformDirty) - { - var list = []; - var current = this; - - if (parent == null) - { - __update(true, false); - } - else - { - while (current != stage) - { - list.push(current); - current = current.parent; - - if (current == null) break; - } - } - - var i = list.length; - while (--i >= 0) - { - current = list[i]; - current.__update(true, false); - } - } - - return __worldTransform; - } - - @:noCompletion private function __globalToLocal(global:Point, local:Point):Point - { - __getRenderTransform(); - - if (global == local) - { - __renderTransform.__transformInversePoint(global); - } - else - { - local.x = __renderTransform.__transformInverseX(global.x, global.y); - local.y = __renderTransform.__transformInverseY(global.x, global.y); - } - - return local; - } - - @:noCompletion private function __hitTest(x:Float, y:Float, shapeFlag:Bool, stack:Array, interactiveOnly:Bool, hitObject:DisplayObject):Bool - { - if (__graphics != null) - { - if (!hitObject.__visible || __isMask) return false; - if (mask != null && !mask.__hitTestMask(x, y)) return false; - - if (__graphics.__hitTest(x, y, shapeFlag, __getRenderTransform())) - { - if (stack != null && !interactiveOnly) - { - stack.push(hitObject); - } - - return true; - } - } - - return false; - } - - @:noCompletion private function __hitTestMask(x:Float, y:Float):Bool - { - if (__graphics != null) - { - if (__graphics.__hitTest(x, y, true, __getRenderTransform())) - { - return true; - } - } - - return false; - } - - @:noCompletion private function __readGraphicsData(graphicsData:Vector, recurse:Bool):Void - { - if (__graphics != null) - { - __graphics.__readGraphicsData(graphicsData); - } - } - - @:noCompletion private function __setParentRenderDirty():Void - { - var renderParent = __renderParent != null ? __renderParent : parent; - if (renderParent != null && !renderParent.__renderDirty) - { - renderParent.__renderDirty = true; - renderParent.__setParentRenderDirty(); - } - } - - @:noCompletion private inline function __setRenderDirty():Void - { - if (!__renderDirty) - { - __renderDirty = true; - __setParentRenderDirty(); - } - } - - @:noCompletion private function __setStageReference(stage:Stage):Void - { - this.stage = stage; - } - - @:noCompletion private function __setTransformDirty():Void - { - if (!__transformDirty) - { - __transformDirty = true; - - __setWorldTransformInvalid(); - __setParentRenderDirty(); - } - } - - @:noCompletion private function __setWorldTransformInvalid():Void - { - __worldTransformInvalid = true; - } - - @:noCompletion private function __stopAllMovieClips():Void {} - - @:noCompletion private function __update(transformOnly:Bool, updateChildren:Bool):Void - { - var renderParent = __renderParent != null ? __renderParent : parent; - if (__isMask && renderParent == null) renderParent = __maskTarget; - __renderable = (__visible && __scaleX != 0 && __scaleY != 0 && !__isMask && (renderParent == null || !renderParent.__isMask)); - __updateTransforms(); - - // if (updateChildren && __transformDirty) { - - __transformDirty = false; - - // } - - __worldTransformInvalid = false; - - if (!transformOnly) - { - if (__supportDOM) - { - __renderTransformChanged = !__renderTransform.equals(__renderTransformCache); - - if (__renderTransformCache == null) - { - __renderTransformCache = __renderTransform.clone(); - } - else - { - __renderTransformCache.copyFrom(__renderTransform); - } - } - - if (renderParent != null) - { - if (__supportDOM) - { - var worldVisible = (renderParent.__worldVisible && __visible); - __worldVisibleChanged = (__worldVisible != worldVisible); - __worldVisible = worldVisible; - - var worldAlpha = alpha * renderParent.__worldAlpha; - __worldAlphaChanged = (__worldAlpha != worldAlpha); - __worldAlpha = worldAlpha; - } - else - { - __worldAlpha = alpha * renderParent.__worldAlpha; - } - - if (__objectTransform != null) - { - __worldColorTransform.__copyFrom(__objectTransform.__colorTransform); - __worldColorTransform.__combine(renderParent.__worldColorTransform); - } - else - { - __worldColorTransform.__copyFrom(renderParent.__worldColorTransform); - } - - if (__blendMode == null || __blendMode == NORMAL) - { - // TODO: Handle multiple blend modes better - __worldBlendMode = renderParent.__worldBlendMode; - } - else - { - __worldBlendMode = __blendMode; - } - - if (__shader == null) - { - __worldShader = renderParent.__shader; - } - else - { - __worldShader = __shader; - } - - if (__scale9Grid == null) - { - __worldScale9Grid = renderParent.__scale9Grid; - } - else - { - __worldScale9Grid = __scale9Grid; - } - } - else - { - __worldAlpha = alpha; - - if (__supportDOM) - { - __worldVisibleChanged = (__worldVisible != __visible); - __worldVisible = __visible; - - __worldAlphaChanged = (__worldAlpha != alpha); - } - - if (__objectTransform != null) - { - __worldColorTransform.__copyFrom(__objectTransform.__colorTransform); - } - else - { - __worldColorTransform.__identity(); - } - - __worldBlendMode = __blendMode; - __worldShader = __shader; - __worldScale9Grid = __scale9Grid; - } - - // if (updateChildren && __renderDirty) { - - // __renderDirty = false; - - // } - } - - if (updateChildren && mask != null) - { - mask.__update(transformOnly, true); - } - } - - @:noCompletion private function __updateTransforms(overrideTransform:Matrix = null):Void - { - var overrided = overrideTransform != null; - var local = overrided ? overrideTransform : __transform; - - if (__worldTransform == null) - { - __worldTransform = new Matrix(); - } - - if (__renderTransform == null) - { - __renderTransform = new Matrix(); - } - - var renderParent = __renderParent != null ? __renderParent : parent; - - if (!overrided && parent != null) - { - __calculateAbsoluteTransform(local, parent.__worldTransform, __worldTransform); - } - else - { - __worldTransform.copyFrom(local); - } - - if (!overrided && renderParent != null) - { - __calculateAbsoluteTransform(local, renderParent.__renderTransform, __renderTransform); - } - else - { - __renderTransform.copyFrom(local); - } - - if (__scrollRect != null) - { - __renderTransform.__translateTransformed(-__scrollRect.x, -__scrollRect.y); - } - } - - // Get & Set Methods - @:keep @:noCompletion private function get_alpha():Float - { - return __alpha; - } - - @:keep @:noCompletion private function set_alpha(value:Float):Float - { - if (value > 1.0) value = 1.0; - if (value < 0.0) value = 0.0; - - if (value != __alpha && !cacheAsBitmap) __setRenderDirty(); - return __alpha = value; - } - - @:noCompletion private function get_blendMode():BlendMode - { - return __blendMode; - } - - @:noCompletion private function set_blendMode(value:BlendMode):BlendMode - { - if (value == null) value = NORMAL; - - if (value != __blendMode) __setRenderDirty(); - return __blendMode = value; - } - - @:noCompletion private function get_cacheAsBitmap():Bool - { - return (__filters == null ? __cacheAsBitmap : true); - } - - @:noCompletion private function set_cacheAsBitmap(value:Bool):Bool - { - if (value != __cacheAsBitmap) - { - __setRenderDirty(); - } - - return __cacheAsBitmap = value; - } - - @:noCompletion private function get_cacheAsBitmapMatrix():Matrix - { - return __cacheAsBitmapMatrix; - } - - @:noCompletion private function set_cacheAsBitmapMatrix(value:Matrix):Matrix - { - __setRenderDirty(); - return __cacheAsBitmapMatrix = (value != null ? value.clone() : value); - } - - @:noCompletion private function get_filters():Array - { - if (__filters == null) - { - return new Array(); - } - else - { - return __filters.copy(); - } - } - - @:noCompletion private function set_filters(value:Array):Array - { - if (value != null && value.length > 0) - { - var clonedFilters:Array = []; - - for (filter in value) - { - var clonedFilter:BitmapFilter = filter.clone(); - - clonedFilter.__renderDirty = true; - clonedFilters.push(clonedFilter); - } - - __filters = clonedFilters; - // __updateFilters = true; - __setRenderDirty(); - } - else if (__filters != null) - { - __filters = null; - // __updateFilters = false; - __setRenderDirty(); - } - - return value; - } - - @:keep @:noCompletion private function get_height():Float - { - var rect = Rectangle.__pool.get(); - __getLocalBounds(rect); - var height = rect.height; - Rectangle.__pool.release(rect); - return height; - } - - @:keep @:noCompletion private function set_height(value:Float):Float - { - var rect = Rectangle.__pool.get(); - var matrix = Matrix.__pool.get(); - matrix.identity(); - - __getBounds(rect, matrix); - - if (value != rect.height) - { - scaleY = value / rect.height; - } - else - { - scaleY = 1; - } - - Rectangle.__pool.release(rect); - Matrix.__pool.release(matrix); - - return value; - } - - @:noCompletion private function get_loaderInfo():LoaderInfo - { - if (stage != null) - { - return Lib.current.__loaderInfo; - } - - return null; - } - - @:noCompletion private function get_mask():DisplayObject - { - return __mask; - } - - @:noCompletion private function set_mask(value:DisplayObject):DisplayObject - { - if (value == __mask) - { - return value; - } - - if (value != __mask) - { - __setTransformDirty(); - __setRenderDirty(); - } - - if (__mask != null) - { - __mask.__isMask = false; - __mask.__maskTarget = null; - __mask.__setTransformDirty(); - __mask.__setRenderDirty(); - } - - if (value != null) - { - value.__isMask = true; - value.__maskTarget = this; - value.__setWorldTransformInvalid(); - } - - if (__cacheBitmap != null && __cacheBitmap.mask != value) - { - __cacheBitmap.mask = value; - } - - return __mask = value; - } - - @:noCompletion private function get_mouseX():Float - { - var mouseX = (stage != null ? stage.__mouseX : Lib.current.stage.__mouseX); - var mouseY = (stage != null ? stage.__mouseY : Lib.current.stage.__mouseY); - - return __getRenderTransform().__transformInverseX(mouseX, mouseY); - } - - @:noCompletion private function get_mouseY():Float - { - var mouseX = (stage != null ? stage.__mouseX : Lib.current.stage.__mouseX); - var mouseY = (stage != null ? stage.__mouseY : Lib.current.stage.__mouseY); - - return __getRenderTransform().__transformInverseY(mouseX, mouseY); - } - - @:noCompletion private function get_name():String - { - return __name; - } - - @:noCompletion private function set_name(value:String):String - { - return __name = value; - } - - @:noCompletion private function get_root():DisplayObject - { - if (stage != null) - { - return Lib.current; - } - - return null; - } - - @:keep @:noCompletion private function get_rotation():Float - { - return __rotation; - } - - @:keep @:noCompletion private function set_rotation(value:Float):Float - { - if (value != __rotation) - { - __rotation = value; - var radians = __rotation * (Math.PI / 180); - __rotationSine = Math.sin(radians); - __rotationCosine = Math.cos(radians); - - __transform.a = __rotationCosine * __scaleX; - __transform.b = __rotationSine * __scaleX; - __transform.c = -__rotationSine * __scaleY; - __transform.d = __rotationCosine * __scaleY; - - __setTransformDirty(); - } - - return value; - } - - @:noCompletion private function get_scale9Grid():Rectangle - { - if (__scale9Grid == null) - { - return null; - } - - return __scale9Grid.clone(); - } - - @:noCompletion private function set_scale9Grid(value:Rectangle):Rectangle - { - if (value == null && __scale9Grid == null) return value; - if (value != null && __scale9Grid != null && __scale9Grid.equals(value)) return value; - - if (value != null) - { - if (__scale9Grid == null) __scale9Grid = new Rectangle(); - __scale9Grid.copyFrom(value); - } - else - { - __scale9Grid = null; - } - - __setRenderDirty(); - - return value; - } - - @:keep @:noCompletion private function get_scaleX():Float - { - return __scaleX; - } - - @:keep @:noCompletion private function set_scaleX(value:Float):Float - { - if (value != __scaleX) - { - __scaleX = value; - - if (__transform.b == 0) - { - if (value != __transform.a) __setTransformDirty(); - __transform.a = value; - } - else - { - var a = __rotationCosine * value; - var b = __rotationSine * value; - - if (__transform.a != a || __transform.b != b) - { - __setTransformDirty(); - } - - __transform.a = a; - __transform.b = b; - } - } - - return value; - } - - @:keep @:noCompletion private function get_scaleY():Float - { - return __scaleY; - } - - @:keep @:noCompletion private function set_scaleY(value:Float):Float - { - if (value != __scaleY) - { - __scaleY = value; - - if (__transform.c == 0) - { - if (value != __transform.d) __setTransformDirty(); - __transform.d = value; - } - else - { - var c = -__rotationSine * value; - var d = __rotationCosine * value; - - if (__transform.d != d || __transform.c != c) - { - __setTransformDirty(); - } - - __transform.c = c; - __transform.d = d; - } - } - - return value; - } - - @:noCompletion private function get_scrollRect():Rectangle - { - if (__scrollRect == null) - { - return null; - } - - return __scrollRect.clone(); - } - - @:noCompletion private function set_scrollRect(value:Rectangle):Rectangle - { - if (value == null && __scrollRect == null) return value; - if (value != null && __scrollRect != null && __scrollRect.equals(value)) return value; - - if (value != null) - { - if (__scrollRect == null) __scrollRect = new Rectangle(); - __scrollRect.copyFrom(value); - } - else - { - __scrollRect = null; - } - - __setTransformDirty(); - - if (__supportDOM) - { - __setRenderDirty(); - } - - return value; - } - - @:noCompletion private function get_shader():Shader - { - return __shader; - } - - @:noCompletion private function set_shader(value:Shader):Shader - { - __shader = value; - __setRenderDirty(); - return value; - } - - @:keep @:noCompletion private function get_transform():Transform - { - if (__objectTransform == null) - { - __objectTransform = new Transform(this); - } - - return __objectTransform; - } - - @:keep @:noCompletion private function set_transform(value:Transform):Transform - { - if (value == null) - { - throw new TypeError("Parameter transform must be non-null."); - } - - if (__objectTransform == null) - { - __objectTransform = new Transform(this); - } - - __setTransformDirty(); - __objectTransform.matrix = value.matrix; - - if (!__objectTransform.__colorTransform.__equals(value.__colorTransform, true) - || (!cacheAsBitmap && __objectTransform.__colorTransform.alphaMultiplier != value.__colorTransform.alphaMultiplier)) - { - __objectTransform.__colorTransform.__copyFrom(value.colorTransform); - __setRenderDirty(); - } - - return __objectTransform; - } - - @:noCompletion private function get_visible():Bool - { - return __visible; - } - - @:noCompletion private function set_visible(value:Bool):Bool - { - if (value != __visible) __setRenderDirty(); - return __visible = value; - } - - @:keep @:noCompletion private function get_width():Float - { - var rect = Rectangle.__pool.get(); - __getLocalBounds(rect); - var width = rect.width; - Rectangle.__pool.release(rect); - return width; - } - - @:keep @:noCompletion private function set_width(value:Float):Float - { - var rect = Rectangle.__pool.get(); - var matrix = Matrix.__pool.get(); - matrix.identity(); - - __getBounds(rect, matrix); - - if (value != rect.width) - { - scaleX = value / rect.width; - } - else - { - scaleX = 1; - } - - Rectangle.__pool.release(rect); - Matrix.__pool.release(matrix); - - return value; - } - - @:keep @:noCompletion private function get_x():Float - { - return __transform.tx; - } - - @:keep @:noCompletion private function set_x(value:Float):Float - { - if (value != __transform.tx) __setTransformDirty(); - return __transform.tx = value; - } - - @:keep @:noCompletion private function get_y():Float - { - return __transform.ty; - } - - @:keep @:noCompletion private function set_y(value:Float):Float - { - if (value != __transform.ty) __setTransformDirty(); - return __transform.ty = value; - } -} -#else -typedef DisplayObject = flash.display.DisplayObject; -#end diff --git a/source/openfl/display/DisplayObjectContainer.hx b/source/openfl/display/DisplayObjectContainer.hx deleted file mode 100644 index 8c5ca3fee44..00000000000 --- a/source/openfl/display/DisplayObjectContainer.hx +++ /dev/null @@ -1,1002 +0,0 @@ -package openfl.display; - -#if !flash -import openfl.errors.ArgumentError; -import openfl.errors.RangeError; -import openfl.errors.TypeError; -import openfl.events.Event; -import openfl.geom.Matrix; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.Vector; - -/** - The DisplayObjectContainer class is the base class for all objects that can - serve as display object containers on the display list. The display list - manages all objects displayed in the Flash runtimes. Use the - DisplayObjectContainer class to arrange the display objects in the display - list. Each DisplayObjectContainer object has its own child list for - organizing the z-order of the objects. The z-order is the front-to-back - order that determines which object is drawn in front, which is behind, and - so on. - - DisplayObject is an abstract base class; therefore, you cannot call - DisplayObject directly. Invoking `new DisplayObject()` throws an - `ArgumentError` exception. - The DisplayObjectContainer class is an abstract base class for all objects - that can contain child objects. It cannot be instantiated directly; calling - the `new DisplayObjectContainer()` constructor throws an - `ArgumentError` exception. - - For more information, see the "Display Programming" chapter of the - _ActionScript 3.0 Developer's Guide_. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.events.Event) -@:access(openfl.display.Graphics) -@:access(openfl.errors.Error) -@:access(openfl.geom.Point) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Rectangle) -class DisplayObjectContainer extends InteractiveObject -{ - /** - Determines whether or not the children of the object are mouse, or user - input device, enabled. If an object is enabled, a user can interact with - it by using a mouse or user input device. The default is - `true`. - - This property is useful when you create a button with an instance of - the Sprite class(instead of using the SimpleButton class). When you use a - Sprite instance to create a button, you can choose to decorate the button - by using the `addChild()` method to add additional Sprite - instances. This process can cause unexpected behavior with mouse events - because the Sprite instances you add as children can become the target - object of a mouse event when you expect the parent instance to be the - target object. To ensure that the parent instance serves as the target - objects for mouse events, you can set the `mouseChildren` - property of the parent instance to `false`. - - No event is dispatched by setting this property. You must use the - `addEventListener()` method to create interactive - functionality. - **/ - public var mouseChildren:Bool; - - /** - Returns the number of children of this object. - **/ - public var numChildren(get, never):Int; - - /** - Determines whether the children of the object are tab enabled. Enables or - disables tabbing for the children of the object. The default is - `true`. - - **Note:** Do not use the `tabChildren` property with - Flex. Instead, use the - `mx.core.UIComponent.hasFocusableChildren` property. - - @throws IllegalOperationError Calling this property of the Stage object - throws an exception. The Stage object does - not implement this property. - **/ - public var tabChildren(get, set):Bool; - - // @:noCompletion @:dox(hide) public var textSnapshot (default, never):openfl.text.TextSnapshot; - @:noCompletion private var __removedChildren:Vector; - @:noCompletion private var __tabChildren:Bool; - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperty(DisplayObjectContainer.prototype, "numChildren", { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_numChildren (); }") - }); - } - #end - - /** - Calling the `new DisplayObjectContainer()` constructor throws - an `ArgumentError` exception. You _can_, however, call - constructors for the following subclasses of DisplayObjectContainer: - - * `new Loader()` - * `new Sprite()` - * `new MovieClip()` - - **/ - @:noCompletion private function new() - { - super(); - - mouseChildren = true; - __tabChildren = true; - - __children = new Array(); - __removedChildren = new Vector(); - } - - /** - Adds a child DisplayObject instance to this DisplayObjectContainer - instance. The child is added to the front(top) of all other children in - this DisplayObjectContainer instance.(To add a child to a specific index - position, use the `addChildAt()` method.) - - If you add a child object that already has a different display object - container as a parent, the object is removed from the child list of the - other display object container. - - **Note:** The command `stage.addChild()` can cause - problems with a published SWF file, including security problems and - conflicts with other loaded SWF files. There is only one Stage within a - Flash runtime instance, no matter how many SWF files you load into the - runtime. So, generally, objects should not be added to the Stage, - directly, at all. The only object the Stage should contain is the root - object. Create a DisplayObjectContainer to contain all of the items on the - display list. Then, if necessary, add that DisplayObjectContainer instance - to the Stage. - - @param child The DisplayObject instance to add as a child of this - DisplayObjectContainer instance. - @return The DisplayObject instance that you pass in the `child` - parameter. - @throws ArgumentError Throws if the child is the same as the parent. Also - throws if the caller is a child(or grandchild etc.) - of the child being added. - @event added Dispatched when a display object is added to the display - list. - **/ - public function addChild(child:DisplayObject):DisplayObject - { - return addChildAt(child, numChildren); - } - - /** - Adds a child DisplayObject instance to this DisplayObjectContainer - instance. The child is added at the index position specified. An index of - 0 represents the back(bottom) of the display list for this - DisplayObjectContainer object. - - For example, the following example shows three display objects, labeled - a, b, and c, at index positions 0, 2, and 1, respectively: - - ![b over c over a](/images/DisplayObjectContainer_layers.jpg) - - If you add a child object that already has a different display object - container as a parent, the object is removed from the child list of the - other display object container. - - @param child The DisplayObject instance to add as a child of this - DisplayObjectContainer instance. - @param index The index position to which the child is added. If you - specify a currently occupied index position, the child object - that exists at that position and all higher positions are - moved up one position in the child list. - @return The DisplayObject instance that you pass in the `child` - parameter. - @throws ArgumentError Throws if the child is the same as the parent. Also - throws if the caller is a child(or grandchild etc.) - of the child being added. - @throws RangeError Throws if the index position does not exist in the - child list. - @event added Dispatched when a display object is added to the display - list. - **/ - public function addChildAt(child:DisplayObject, index:Int):DisplayObject - { - if (child == null) - { - var error = new TypeError("Error #2007: Parameter child must be non-null."); - error.errorID = 2007; - throw error; - } - #if ((haxe_ver >= "3.4.0") || !cpp) - else if (child.stage == child) - { - var error = new ArgumentError("Error #3783: A Stage object cannot be added as the child of another object."); - error.errorID = 3783; - throw error; - } - #end - - if (index > __children.length || index < 0) - { - throw "Invalid index position " + index; - } - - if (child.parent == this) - { - if (__children[index] != child) - { - __children.remove(child); - __children.insert(index, child); - - __setRenderDirty(); - } - } - else - { - if (child.parent != null) - { - child.parent.removeChild(child); - } - - __children.insert(index, child); - child.parent = this; - - var addedToStage = (stage != null && child.stage == null); - - if (addedToStage) - { - child.__setStageReference(stage); - } - - child.__setTransformDirty(); - child.__setRenderDirty(); - __setRenderDirty(); - - // #if !openfl_disable_event_pooling - // var event = Event.__pool.get(); - // event.type = Event.ADDED; - // #else - var event = new Event(Event.ADDED); - // #end - event.bubbles = true; - - event.target = child; - - child.__dispatchWithCapture(event); - - // #if !openfl_disable_event_pooling - // Event.__pool.release(event); - // #end - - if (addedToStage) - { - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.ADDED_TO_STAGE; - #else - event = new Event(Event.ADDED_TO_STAGE, false, false); - #end - - child.__dispatchWithCapture(event); - child.__dispatchChildren(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - } - - return child; - } - - /** - Indicates whether the security restrictions would cause any display - objects to be omitted from the list returned by calling the - `DisplayObjectContainer.getObjectsUnderPoint()` method with the - specified `point` point. By default, content from one domain - cannot access objects from another domain unless they are permitted to do - so with a call to the `Security.allowDomain()` method. For more - information, related to security, see the Flash Player Developer Center - Topic: [Security](http://www.adobe.com/go/devnet_security_en). - - The `point` parameter is in the coordinate space of the - Stage, which may differ from the coordinate space of the display object - container(unless the display object container is the Stage). You can use - the `globalToLocal()` and the `localToGlobal()` - methods to convert points between these coordinate spaces. - - @param point The point under which to look. - @return `true` if the point contains child display objects with - security restrictions. - **/ - public function areInaccessibleObjectsUnderPoint(point:Point):Bool - { - return false; - } - - /** - Determines whether the specified display object is a child of the - DisplayObjectContainer instance or the instance itself. The search - includes the entire display list including this DisplayObjectContainer - instance. Grandchildren, great-grandchildren, and so on each return - `true`. - - @param child The child object to test. - @return `true` if the `child` object is a child of - the DisplayObjectContainer or the container itself; otherwise - `false`. - **/ - public function contains(child:DisplayObject):Bool - { - while (child != this && child != null) - { - child = child.parent; - } - - return child == this; - } - - /** - Returns the child display object instance that exists at the specified - index. - - @param index The index position of the child object. - @return The child display object at the specified index position. - @throws RangeError Throws if the index does not exist in the child - list. - @throws SecurityError This child display object belongs to a sandbox to - which you do not have access. You can avoid this - situation by having the child movie call - `Security.allowDomain()`. - **/ - public function getChildAt(index:Int):DisplayObject - { - if (index >= 0 && index < __children.length) - { - return __children[index]; - } - - return null; - } - - /** - Returns the child display object that exists with the specified name. If - more that one child display object has the specified name, the method - returns the first object in the child list. - - The `getChildAt()` method is faster than the - `getChildByName()` method. The `getChildAt()` method - accesses a child from a cached array, whereas the - `getChildByName()` method has to traverse a linked list to - access a child. - - @param name The name of the child to return. - @return The child display object with the specified name. - @throws SecurityError This child display object belongs to a sandbox to - which you do not have access. You can avoid this - situation by having the child movie call the - `Security.allowDomain()` method. - **/ - public function getChildByName(name:String):DisplayObject - { - for (child in __children) - { - if (child.name == name) return child; - } - - return null; - } - - /** - Returns the index position of a `child` DisplayObject instance. - - @param child The DisplayObject instance to identify. - @return The index position of the child display object to identify. - @throws ArgumentError Throws if the child parameter is not a child of this - object. - **/ - public function getChildIndex(child:DisplayObject):Int - { - for (i in 0...__children.length) - { - if (__children[i] == child) return i; - } - - return -1; - } - - /** - Returns an array of objects that lie under the specified point and are - children(or grandchildren, and so on) of this DisplayObjectContainer - instance. Any child objects that are inaccessible for security reasons are - omitted from the returned array. To determine whether this security - restriction affects the returned array, call the - `areInaccessibleObjectsUnderPoint()` method. - - The `point` parameter is in the coordinate space of the - Stage, which may differ from the coordinate space of the display object - container(unless the display object container is the Stage). You can use - the `globalToLocal()` and the `localToGlobal()` - methods to convert points between these coordinate spaces. - - @param point The point under which to look. - @return An array of objects that lie under the specified point and are - children(or grandchildren, and so on) of this - DisplayObjectContainer instance. - **/ - public function getObjectsUnderPoint(point:Point):Array - { - var stack = new Array(); - __hitTest(point.x, point.y, false, stack, false, this); - stack.reverse(); - return stack; - } - - /** - Removes the specified `child` DisplayObject instance from the - child list of the DisplayObjectContainer instance. The `parent` - property of the removed child is set to `null` , and the object - is garbage collected if no other references to the child exist. The index - positions of any display objects above the child in the - DisplayObjectContainer are decreased by 1. - - The garbage collector reallocates unused memory space. When a variable - or object is no longer actively referenced or stored somewhere, the - garbage collector sweeps through and wipes out the memory space it used to - occupy if no other references to it exist. - - @param child The DisplayObject instance to remove. - @return The DisplayObject instance that you pass in the `child` - parameter. - @throws ArgumentError Throws if the child parameter is not a child of this - object. - **/ - public function removeChild(child:DisplayObject):DisplayObject - { - if (child != null && child.parent == this) - { - child.__setTransformDirty(); - child.__setRenderDirty(); - __setRenderDirty(); - - var event = new Event(Event.REMOVED, true); - child.__dispatchWithCapture(event); - - if (stage != null) - { - if (child.stage != null && stage.focus == child) - { - stage.focus = null; - } - - var event = new Event(Event.REMOVED_FROM_STAGE, false, false); - child.__dispatchWithCapture(event); - child.__dispatchChildren(event); - child.__setStageReference(null); - } - - child.parent = null; - __children.remove(child); - __removedChildren.push(child); - child.__setTransformDirty(); - } - - return child; - } - - /** - Removes a child DisplayObject from the specified `index` - position in the child list of the DisplayObjectContainer. The - `parent` property of the removed child is set to - `null`, and the object is garbage collected if no other - references to the child exist. The index positions of any display objects - above the child in the DisplayObjectContainer are decreased by 1. - - The garbage collector reallocates unused memory space. When a variable - or object is no longer actively referenced or stored somewhere, the - garbage collector sweeps through and wipes out the memory space it used to - occupy if no other references to it exist. - - @param index The child index of the DisplayObject to remove. - @return The DisplayObject instance that was removed. - @throws RangeError Throws if the index does not exist in the child - list. - @throws SecurityError This child display object belongs to a sandbox to - which the calling object does not have access. You - can avoid this situation by having the child movie - call the `Security.allowDomain()` method. - **/ - public function removeChildAt(index:Int):DisplayObject - { - if (index >= 0 && index < __children.length) - { - return removeChild(__children[index]); - } - - return null; - } - - /** - Removes all `child` DisplayObject instances from the child list of the DisplayObjectContainer - instance. The `parent` property of the removed children is set to `null`, and the objects are - garbage collected if no other references to the children exist. - - The garbage collector reallocates unused memory space. When a variable or object is no - longer actively referenced or stored somewhere, the garbage collector sweeps through and - wipes out the memory space it used to occupy if no other references to it exist. - @param beginIndex The beginning position. A value smaller than 0 throws a `RangeError`. - @param endIndex The ending position. A value smaller than 0 throws a `RangeError`. - **/ - public function removeChildren(beginIndex:Int = 0, endIndex:Int = 0x7FFFFFFF):Void - { - if (endIndex == 0x7FFFFFFF) - { - endIndex = __children.length - 1; - - if (endIndex < 0) - { - return; - } - } - - if (beginIndex > __children.length - 1) - { - return; - } - else if (endIndex < beginIndex || beginIndex < 0 || endIndex > __children.length) - { - throw new RangeError("The supplied index is out of bounds."); - } - - var numRemovals = endIndex - beginIndex; - while (numRemovals >= 0) - { - removeChildAt(beginIndex); - numRemovals--; - } - } - - @:noCompletion private function resolve(fieldName:String):DisplayObject - { - if (__children == null) return null; - - for (child in __children) - { - if (child.name == fieldName) - { - return child; - } - } - - return null; - } - - /** - Changes the position of an existing child in the display object container. - This affects the layering of child objects. For example, the following - example shows three display objects, labeled a, b, and c, at index - positions 0, 1, and 2, respectively: - - ![c over b over a](/images/DisplayObjectContainerSetChildIndex1.jpg) - - When you use the `setChildIndex()` method and specify an - index position that is already occupied, the only positions that change - are those in between the display object's former and new position. All - others will stay the same. If a child is moved to an index LOWER than its - current index, all children in between will INCREASE by 1 for their index - reference. If a child is moved to an index HIGHER than its current index, - all children in between will DECREASE by 1 for their index reference. For - example, if the display object container in the previous example is named - `container`, you can swap the position of the display objects - labeled a and b by calling the following code: - - ```haxe - container.setChildIndex(container.getChildAt(1), 0); - ``` - - This code results in the following arrangement of objects: - - ![c over a over b](/images/DisplayObjectContainerSetChildIndex2.jpg) - - @param child The child DisplayObject instance for which you want to change - the index number. - @param index The resulting index number for the `child` display - object. - @throws ArgumentError Throws if the child parameter is not a child of this - object. - @throws RangeError Throws if the index does not exist in the child - list. - **/ - public function setChildIndex(child:DisplayObject, index:Int):Void - { - if (index >= 0 && index <= __children.length && child.parent == this) - { - __children.remove(child); - __children.insert(index, child); - } - } - - /** - Recursively stops the timeline execution of all MovieClips rooted at this object. - - Child display objects belonging to a sandbox to which the excuting code does not - have access are ignored. - - **Note:** Streaming media playback controlled via a NetStream object will not be - stopped. - **/ - public function stopAllMovieClips():Void - { - __stopAllMovieClips(); - } - - /** - Swaps the z-order (front-to-back order) of the two specified child - objects. All other child objects in the display object container remain in - the same index positions. - - @param child1 The first child object. - @param child2 The second child object. - @throws ArgumentError Throws if either child parameter is not a child of - this object. - **/ - public function swapChildren(child1:DisplayObject, child2:DisplayObject):Void - { - if (child1.parent == this && child2.parent == this) - { - var index1 = __children.indexOf(child1); - var index2 = __children.indexOf(child2); - - __children[index1] = child2; - __children[index2] = child1; - - __setRenderDirty(); - } - } - - /** - Swaps the z-order (front-to-back order) of the child objects at the two - specified index positions in the child list. All other child objects in - the display object container remain in the same index positions. - - @param index1 The index position of the first child object. - @param index2 The index position of the second child object. - @throws RangeError If either index does not exist in the child list. - **/ - public function swapChildrenAt(index1:Int, index2:Int):Void - { - var swap:DisplayObject = __children[index1]; - __children[index1] = __children[index2]; - __children[index2] = swap; - swap = null; - __setRenderDirty(); - } - - @:noCompletion private override function __cleanup():Void - { - super.__cleanup(); - - for (child in __children) - { - child.__cleanup(); - } - - __cleanupRemovedChildren(); - } - - @:noCompletion private inline function __cleanupRemovedChildren():Void - { - for (orphan in __removedChildren) - { - if (orphan.stage == null) - { - orphan.__cleanup(); - } - } - - __removedChildren.length = 0; - } - - @:noCompletion private override function __dispatchChildren(event:Event):Void - { - if (__children != null) - { - for (child in __children) - { - event.target = child; - - if (!child.__dispatchWithCapture(event)) - { - break; - } - - child.__dispatchChildren(event); - } - } - } - - @:noCompletion private override function __enterFrame(deltaTime:Float):Void - { - for (child in __children) - { - child.__enterFrame(deltaTime); - } - } - - @:noCompletion private override function __getBounds(rect:Rectangle, matrix:Matrix):Void - { - super.__getBounds(rect, matrix); - - if (__children.length == 0) return; - - var childWorldTransform = Matrix.__pool.get(); - - for (child in __children) - { - if (child.__scaleX == 0 || child.__scaleY == 0) continue; - - DisplayObject.__calculateAbsoluteTransform(child.__transform, matrix, childWorldTransform); - - child.__getBounds(rect, childWorldTransform); - } - - Matrix.__pool.release(childWorldTransform); - } - - @:noCompletion private override function __getFilterBounds(rect:Rectangle, matrix:Matrix):Void - { - super.__getFilterBounds(rect, matrix); - if (__scrollRect != null) return; - - if (__children.length == 0) return; - - var childWorldTransform = Matrix.__pool.get(); - - for (child in __children) - { - if (child.__scaleX == 0 || child.__scaleY == 0 || child.__isMask) continue; - - DisplayObject.__calculateAbsoluteTransform(child.__transform, matrix, childWorldTransform); - - var childRect = Rectangle.__pool.get(); - - child.__getFilterBounds(childRect, childWorldTransform); - rect.__expand(childRect.x, childRect.y, childRect.width, childRect.height); - - Rectangle.__pool.release(childRect); - } - - Matrix.__pool.release(childWorldTransform); - } - - @:noCompletion private override function __getRenderBounds(rect:Rectangle, matrix:Matrix):Void - { - if (__scrollRect != null) - { - super.__getRenderBounds(rect, matrix); - return; - } - else - { - super.__getBounds(rect, matrix); - } - - if (__children.length == 0) return; - - var childWorldTransform = Matrix.__pool.get(); - - for (child in __children) - { - if (child.__scaleX == 0 || child.__scaleY == 0 || child.__isMask) continue; - - DisplayObject.__calculateAbsoluteTransform(child.__transform, matrix, childWorldTransform); - - child.__getRenderBounds(rect, childWorldTransform); - } - - Matrix.__pool.release(childWorldTransform); - } - - @:noCompletion private override function __hitTest(x:Float, y:Float, shapeFlag:Bool, stack:Array, interactiveOnly:Bool, - hitObject:DisplayObject):Bool - { - if (!hitObject.visible || __isMask || (interactiveOnly && !mouseEnabled && !mouseChildren)) return false; - if (mask != null && !mask.__hitTestMask(x, y)) return false; - - if (__scrollRect != null) - { - var point = Point.__pool.get(); - point.setTo(x, y); - __getRenderTransform().__transformInversePoint(point); - - if (!__scrollRect.containsPoint(point)) - { - Point.__pool.release(point); - return false; - } - - Point.__pool.release(point); - } - - var i = __children.length; - if (interactiveOnly) - { - if (stack == null || !mouseChildren) - { - while (--i >= 0) - { - if (__children[i].__hitTest(x, y, shapeFlag, null, true, cast __children[i])) - { - if (stack != null) - { - stack.push(hitObject); - } - - return true; - } - } - } - else if (stack != null) - { - var length = stack.length; - - var interactive = false; - var hitTest = false; - - while (--i >= 0) - { - interactive = __children[i].__getInteractive(null); - - if (interactive || (mouseEnabled && !hitTest)) - { - if (__children[i].__hitTest(x, y, shapeFlag, stack, true, cast __children[i])) - { - hitTest = true; - - if (interactive && stack.length > length) - { - break; - } - } - } - } - - if (hitTest) - { - stack.insert(length, hitObject); - return true; - } - } - } - else - { - var hitTest = false; - - while (--i >= 0) - { - if (__children[i].__hitTest(x, y, shapeFlag, stack, false, cast __children[i])) - { - hitTest = true; - if (stack == null) break; - } - } - - return hitTest; - } - - return false; - } - - @:noCompletion private override function __hitTestMask(x:Float, y:Float):Bool - { - var i = __children.length; - - while (--i >= 0) - { - if (__children[i].__hitTestMask(x, y)) - { - return true; - } - } - - return false; - } - - @:noCompletion private override function __readGraphicsData(graphicsData:Vector, recurse:Bool):Void - { - super.__readGraphicsData(graphicsData, recurse); - - if (recurse) - { - for (child in __children) - { - child.__readGraphicsData(graphicsData, recurse); - } - } - } - - @:noCompletion private override function __setStageReference(stage:Stage):Void - { - super.__setStageReference(stage); - - if (__children != null) - { - for (child in __children) - { - child.__setStageReference(stage); - } - } - } - - @:noCompletion private override function __setWorldTransformInvalid():Void - { - if (!__worldTransformInvalid) - { - __worldTransformInvalid = true; - - if (__children != null) - { - for (child in __children) - { - child.__setWorldTransformInvalid(); - } - } - } - } - - @:noCompletion private override function __stopAllMovieClips():Void - { - for (child in __children) - { - child.__stopAllMovieClips(); - } - } - - @:noCompletion private override function __tabTest(stack:Array):Void - { - super.__tabTest(stack); - - if (!tabChildren) return; - - var interactive = false; - var interactiveObject:InteractiveObject = null; - - for (child in __children) - { - interactive = child.__getInteractive(null); - - if (interactive) - { - interactiveObject = cast child; - interactiveObject.__tabTest(stack); - } - } - } - - @:noCompletion private override function __update(transformOnly:Bool, updateChildren:Bool):Void - { - super.__update(transformOnly, updateChildren); - - if (updateChildren) - { - for (child in __children) - { - child.__update(transformOnly, true); - } - } - } - - // Get & Set Methods - - @:noCompletion private function get_numChildren():Int - { - return __children.length; - } - - @:noCompletion private function get_tabChildren():Bool - { - return __tabChildren; - } - - @:noCompletion private function set_tabChildren(value:Bool):Bool - { - if (__tabChildren != value) - { - __tabChildren = value; - - dispatchEvent(new Event(Event.TAB_CHILDREN_CHANGE, true, false)); - } - - return __tabChildren; - } -} -#else -typedef DisplayObjectContainer = flash.display.DisplayObjectContainer; -#end diff --git a/source/openfl/display/MovieClip.hx b/source/openfl/display/MovieClip.hx deleted file mode 100644 index bcf001dfbf6..00000000000 --- a/source/openfl/display/MovieClip.hx +++ /dev/null @@ -1,597 +0,0 @@ -package openfl.display; - -#if !flash -import openfl.events.MouseEvent; - -/** - The MovieClip class inherits from the following classes: Sprite, - DisplayObjectContainer, InteractiveObject, DisplayObject, and - EventDispatcher. - - Unlike the Sprite object, a MovieClip object has a timeline. - - In Flash Professional, the methods for the MovieClip class provide the - same functionality as actions that target movie clips. Some additional - methods do not have equivalent actions in the Actions toolbox in the - Actions panel in the Flash authoring tool. - - Children instances placed on the Stage in Flash Professional cannot be - accessed by code from within the constructor of a parent instance since - they have not been created at that point in code execution. Before - accessing the child, the parent must instead either create the child - instance by code or delay access to a callback function that listens for - the child to dispatch its `Event.ADDED_TO_STAGE` event. - - If you modify any of the following properties of a MovieClip object that - contains a motion tween, the playhead is stopped in that MovieClip object: - `alpha`, `blendMode`, `filters`, - `height`, `opaqueBackground`, `rotation`, - `scaleX`, `scaleY`, `scale9Grid`, - `scrollRect`, `transform`, `visible`, - `width`, `x`, or `y`. However, it does not - stop the playhead in any child MovieClip objects of that MovieClip - object. - - **Note:**Flash Lite 4 supports the MovieClip.opaqueBackground - property only if FEATURE_BITMAPCACHE is defined. The default configuration - of Flash Lite 4 does not define FEATURE_BITMAPCACHE. To enable the - MovieClip.opaqueBackground property for a suitable device, define - FEATURE_BITMAPCACHE in your project. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display.Timeline) -@:access(openfl.geom.ColorTransform) -class MovieClip extends Sprite #if (openfl_dynamic && haxe_ver < "4.0.0") implements Dynamic #end -{ - /** - Specifies the number of the frame in which the playhead is located in the - timeline of the MovieClip instance. If the movie clip has multiple scenes, - this value is the frame number in the current scene. - **/ - public var currentFrame(get, never):Float; - - /** - The label at the current frame in the timeline of the MovieClip instance. - If the current frame has no label, `currentLabel` is - `null`. - **/ - public var currentFrameLabel(get, never):String; - - /** - The current label in which the playhead is located in the timeline of the - MovieClip instance. If the current frame has no label, - `currentLabel` is set to the name of the previous frame that - includes a label. If the current frame and previous frames do not include - a label, `currentLabel` returns `null`. - **/ - public var currentLabel(get, never):String; - - /** - Returns an array of FrameLabel objects from the current scene. If the - MovieClip instance does not use scenes, the array includes all frame - labels from the entire MovieClip instance. - **/ - public var currentLabels(get, never):Array; - - /** - The current scene in which the playhead is located in the timeline of - the MovieClip instance. - **/ - public var currentScene(get, never):Scene; - - /** - A Boolean value that indicates whether a movie clip is enabled. The - default value of `enabled` is `true`. If - `enabled` is set to `false`, the movie clip's Over, - Down, and Up frames are disabled. The movie clip continues to receive - events(for example, `mouseDown`, `mouseUp`, - `keyDown`, and `keyUp`). - - The `enabled` property governs only the button-like - properties of a movie clip. You can change the `enabled` - property at any time; the modified movie clip is immediately enabled or - disabled. If `enabled` is set to `false`, the object - is not included in automatic tab ordering. - **/ - public var enabled(get, set):Bool; - - /** - The number of frames that are loaded from a streaming SWF file. You can - use the `framesLoaded` property to determine whether the - contents of a specific frame and all the frames before it loaded and are - available locally in the browser. You can also use it to monitor the - downloading of large SWF files. For example, you might want to display a - message to users indicating that the SWF file is loading until a specified - frame in the SWF file finishes loading. - - If the movie clip contains multiple scenes, the - `framesLoaded` property returns the number of frames loaded for - _all_ scenes in the movie clip. - **/ - public var framesLoaded(get, never):Float; - - /** - A Boolean value that indicates whether a movie clip is curently playing. - **/ - public var isPlaying(get, never):Bool; - - /** - An array of Scene objects, each listing the name, the number of frames, - and the frame labels for a scene in the MovieClip instance. - **/ - public var scenes(get, never):Array; - - /** - The total number of frames in the MovieClip instance. - - If the movie clip contains multiple frames, the - `totalFrames` property returns the total number of frames in - _all_ scenes in the movie clip. - **/ - public var totalFrames(get, never):Float; - - // @:noCompletion @:dox(hide) public var trackAsMenu:Bool; - @:noCompletion private var __enabled:Bool; - @:noCompletion private var __hasDown:Bool; - @:noCompletion private var __hasOver:Bool; - @:noCompletion private var __hasUp:Bool; - @:noCompletion private var __mouseIsDown:Bool; - @:noCompletion private var __scene:Scene; - @:noCompletion private var __timeline:Timeline; - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(MovieClip.prototype, { - "currentFrame": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_currentFrame (); }")}, - "currentFrameLabel": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_currentFrameLabel (); }")}, - "currentLabel": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_currentLabel (); }")}, - "currentLabels": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_currentLabels (); }")}, - "enabled": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_enabled (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_enabled (v); }") - }, - "framesLoaded": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_framesLoaded (); }")}, - "isPlaying": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_isPlaying (); }")}, - "totalFrames": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_totalFrames (); }")}, - }); - } - #end - - /** - Creates a new MovieClip instance. After creating the MovieClip, call the - `addChild()` or `addChildAt()` method of a display - object container that is onstage. - **/ - public function new() - { - super(); - - __enabled = true; - // __type = MOVIE_CLIP; - } - - /** - Adds a new FrameScript to this MovieClip. - - The FrameScript will be executed automatically when the - MovieClip enters the specified frame. - - This is only functional if this MovieClip has an attached - Timeline. - - @param index A zero-based index referencing a frame - @param method A method to be called entering the requested frame. - **/ - public function addFrameScript(index:Int, method:Void->Void):Void - { - if (__timeline != null) - { - __timeline.__addFrameScript(index, method); - } - } - - /** - Attaches a Timeline to this MovieClip. - - MovieClips that contain a Timeline can play(), stop() and can - include FrameScripts. - - @param timeline A Timeline object - **/ - public function attachTimeline(timeline:Timeline):Void - { - __timeline = timeline; - if (timeline != null) - { - timeline.__attachMovieClip(this); - play(); - } - } - - /** - Creates a new MovieClip based upon a Timeline instance. - - @param timeline A Timeline object - @return A new Sprite - **/ - public static function fromTimeline(timeline:Timeline):MovieClip - { - var movieClip = new MovieClip(); - movieClip.attachTimeline(timeline); - return movieClip; - } - - /** - Starts playing the SWF file at the specified frame. This happens after all - remaining actions in the frame have finished executing. To specify a scene - as well as a frame, specify a value for the `scene` parameter. - - @param frame A number representing the frame number, or a string - representing the label of the frame, to which the playhead is - sent. If you specify a number, it is relative to the scene - you specify. If you do not specify a scene, the current scene - determines the global frame number to play. If you do specify - a scene, the playhead jumps to the frame number in the - specified scene. - @param scene The name of the scene to play. This parameter is optional. - **/ - public function gotoAndPlay(frame:#if (haxe_ver >= "3.4.2") Any #else Dynamic #end, scene:String = null):Void - { - if (__timeline != null) - { - __timeline.__gotoAndPlay(frame, scene); - } - } - - /** - Brings the playhead to the specified frame of the movie clip and stops it - there. This happens after all remaining actions in the frame have finished - executing. If you want to specify a scene in addition to a frame, specify - a `scene` parameter. - - @param frame A number representing the frame number, or a string - representing the label of the frame, to which the playhead is - sent. If you specify a number, it is relative to the scene - you specify. If you do not specify a scene, the current scene - determines the global frame number at which to go to and - stop. If you do specify a scene, the playhead goes to the - frame number in the specified scene and stops. - @param scene The name of the scene. This parameter is optional. - @throws ArgumentError If the `scene` or `frame` - specified are not found in this movie clip. - **/ - public function gotoAndStop(frame:#if (haxe_ver >= "3.4.2") Any #else Dynamic #end, scene:String = null):Void - { - if (__timeline != null) - { - __timeline.__gotoAndStop(frame, scene); - } - } - - /** - Sends the playhead to the next frame and stops it. This happens after all - remaining actions in the frame have finished executing. - - **/ - public function nextFrame():Void - { - if (__timeline != null) - { - __timeline.__nextFrame(); - } - } - - public function nextScene():Void - { - if (__timeline != null) - { - __timeline.__nextScene(); - } - } - - /** - Moves the playhead in the timeline of the movie clip. - **/ - public function play():Void - { - if (__timeline != null) - { - __timeline.__play(); - } - } - - /** - Sends the playhead to the previous frame and stops it. This happens after - all remaining actions in the frame have finished executing. - - **/ - public function prevFrame():Void - { - if (__timeline != null) - { - __timeline.__prevFrame(); - } - } - - public function prevScene():Void - { - if (__timeline != null) - { - __timeline.__prevScene(); - } - } - - /** - Stops the playhead in the movie clip. - - **/ - public function stop():Void - { - if (__timeline != null) - { - __timeline.__stop(); - } - } - - @:noCompletion private override function __enterFrame(deltaTime:Float):Void - { - if (__timeline != null) - { - __timeline.__enterFrame(Std.int(deltaTime)); - } - - for (child in __children) - { - child.__enterFrame(Std.int(deltaTime)); - } - } - - @:noCompletion private override function __stopAllMovieClips():Void - { - super.__stopAllMovieClips(); - stop(); - } - - @:noCompletion private override function __tabTest(stack:Array):Void - { - if (!__enabled) return; - super.__tabTest(stack); - } - - // Event Handlers - @:noCompletion private function __onMouseDown(event:MouseEvent):Void - { - if (__enabled && __hasDown) - { - gotoAndStop("_down"); - } - - __mouseIsDown = true; - - if (stage != null) - { - stage.addEventListener(MouseEvent.MOUSE_UP, __onMouseUp, true); - } - } - - @:noCompletion private function __onMouseUp(event:MouseEvent):Void - { - __mouseIsDown = false; - - if (stage != null) - { - stage.removeEventListener(MouseEvent.MOUSE_UP, __onMouseUp); - } - - if (!__buttonMode) - { - return; - } - - if (event.target == this && __enabled && __hasOver) - { - gotoAndStop("_over"); - } - else if (__enabled && __hasUp) - { - gotoAndStop("_up"); - } - } - - @:noCompletion private function __onRollOut(event:MouseEvent):Void - { - if (!__enabled) return; - - if (__mouseIsDown && __hasOver) - { - gotoAndStop("_over"); - } - else if (__hasUp) - { - gotoAndStop("_up"); - } - } - - @:noCompletion private function __onRollOver(event:MouseEvent):Void - { - if (__enabled && __hasOver) - { - gotoAndStop("_over"); - } - } - - // Getters & Setters - @:noCompletion private override function set_buttonMode(value:Bool):Bool - { - if (__buttonMode != value) - { - if (value) - { - __hasDown = false; - __hasOver = false; - __hasUp = false; - - for (frameLabel in currentLabels) - { - switch (frameLabel.name) - { - case "_up": - __hasUp = true; - case "_over": - __hasOver = true; - case "_down": - __hasDown = true; - default: - } - } - - if (__hasDown || __hasOver || __hasUp) - { - addEventListener(MouseEvent.ROLL_OVER, __onRollOver); - addEventListener(MouseEvent.ROLL_OUT, __onRollOut); - addEventListener(MouseEvent.MOUSE_DOWN, __onMouseDown); - } - } - else - { - removeEventListener(MouseEvent.ROLL_OVER, __onRollOver); - removeEventListener(MouseEvent.ROLL_OUT, __onRollOut); - removeEventListener(MouseEvent.MOUSE_DOWN, __onMouseDown); - } - - __buttonMode = value; - } - - return value; - } - - @:noCompletion private function get_currentFrame():Float - { - if (__timeline != null) - { - return __timeline.__currentFrame; - } - else - { - return 1; - } - } - - @:noCompletion private function get_currentFrameLabel():String - { - if (__timeline != null) - { - return __timeline.__currentFrameLabel; - } - else - { - return null; - } - } - - @:noCompletion private function get_currentLabel():String - { - if (__timeline != null) - { - return __timeline.__currentLabel; - } - else - { - return null; - } - } - - @:noCompletion private function get_currentLabels():Array - { - if (__timeline != null) - { - return __timeline.__currentLabels.copy(); - } - else - { - return []; - } - } - - @:noCompletion private function get_currentScene():Scene - { - if (__timeline != null) - { - return __timeline.__currentScene; - } - else - { - if (__scene == null) - { - __scene = new Scene("", [], 1); - } - return __scene; - } - } - - @:noCompletion private function get_enabled():Bool - { - return __enabled; - } - - @:noCompletion private function set_enabled(value:Bool):Bool - { - return __enabled = value; - } - - @:noCompletion private function get_framesLoaded():Float - { - if (__timeline != null) - { - return __timeline.__framesLoaded; - } - else - { - return 1; - } - } - - @:noCompletion private function get_isPlaying():Bool - { - if (__timeline != null) - { - return __timeline.__isPlaying; - } - else - { - return false; - } - } - - @:noCompletion private function get_scenes():Array - { - if (__timeline != null) - { - return __timeline.scenes.copy(); - } - else - { - return [currentScene]; - } - } - - @:noCompletion private function get_totalFrames():Float - { - if (__timeline != null) - { - return __timeline.__totalFrames; - } - else - { - return 1; - } - } -} -#else -typedef MovieClip = flash.display.MovieClip; -typedef MovieClip2 = flash.display.MovieClip.MovieClip2; -#end diff --git a/source/openfl/display/Stage.hx b/source/openfl/display/Stage.hx deleted file mode 100644 index 13f2b627627..00000000000 --- a/source/openfl/display/Stage.hx +++ /dev/null @@ -1,3729 +0,0 @@ -package openfl.display; - -#if !flash -import haxe.CallStack; -import haxe.ds.ArraySort; -import openfl.utils._internal.Log; -import openfl.utils._internal.TouchData; -import openfl.display3D.Context3D; -import openfl.display.Application as OpenFLApplication; -import openfl.errors.IllegalOperationError; -import openfl.events.Event; -import openfl.events.EventDispatcher; -import openfl.events.EventPhase; -import openfl.events.FocusEvent; -import openfl.events.FullScreenEvent; -import openfl.events.KeyboardEvent; -import openfl.events.MouseEvent; -import openfl.events.TextEvent; -import openfl.events.TouchEvent; -import openfl.events.UncaughtErrorEvent; -import openfl.events.UncaughtErrorEvents; -import openfl.geom.Matrix; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.geom.Transform; -import openfl.ui.GameInput; -import openfl.ui.Keyboard; -import openfl.ui.Mouse; -import openfl.ui.MouseCursor; -#if lime -import lime.app.Application; -import lime.app.IModule; -import lime.graphics.RenderContext; -import lime.graphics.RenderContextType; -import lime.ui.Touch; -import lime.ui.Gamepad; -import lime.ui.GamepadAxis; -import lime.ui.GamepadButton; -import lime.ui.KeyCode; -import lime.ui.KeyModifier; -import lime.ui.MouseCursor as LimeMouseCursor; -import lime.ui.MouseWheelMode; -import lime.ui.Window; -#end -#if hxtelemetry -import openfl.profiler.Telemetry; -#end -#if gl_stats -import openfl.display._internal.stats.Context3DStats; -#end -#if (js && html5) -import js.html.Element; -import js.Browser; -#elseif js -typedef Element = Dynamic; -#end - -/** - The Stage class represents the main drawing area. - - For SWF content running in the browser(in Flash® Player), - the Stage represents the entire area where Flash content is shown. For - content running in AIR on desktop operating systems, each NativeWindow - object has a corresponding Stage object. - - The Stage object is not globally accessible. You need to access it - through the `stage` property of a DisplayObject instance. - - The Stage class has several ancestor classes - DisplayObjectContainer, - InteractiveObject, DisplayObject, and EventDispatcher - from which it - inherits properties and methods. Many of these properties and methods are - either inapplicable to Stage objects, or require security checks when - called on a Stage object. The properties and methods that require security - checks are documented as part of the Stage class. - - In addition, the following inherited properties are inapplicable to - Stage objects. If you try to set them, an IllegalOperationError is thrown. - These properties may always be read, but since they cannot be set, they - will always contain default values. - - - * `accessibilityProperties` - * `alpha` - * `blendMode` - * `cacheAsBitmap` - * `contextMenu` - * `filters` - * `focusRect` - * `loaderInfo` - * `mask` - * `mouseEnabled` - * `name` - * `opaqueBackground` - * `rotation` - * `scale9Grid` - * `scaleX` - * `scaleY` - * `scrollRect` - * `tabEnabled` - * `tabIndex` - * `transform` - * `visible` - * `x` - * `y` - - - Some events that you might expect to be a part of the Stage class, such - as `enterFrame`, `exitFrame`, - `frameConstructed`, and `render`, cannot be Stage - events because a reference to the Stage object cannot be guaranteed to - exist in every situation where these events are used. Because these events - cannot be dispatched by the Stage object, they are instead dispatched by - every DisplayObject instance, which means that you can add an event - listener to any DisplayObject instance to listen for these events. These - events, which are part of the DisplayObject class, are called broadcast - events to differentiate them from events that target a specific - DisplayObject instance. Two other broadcast events, `activate` - and `deactivate`, belong to DisplayObject's superclass, - EventDispatcher. The `activate` and `deactivate` - events behave similarly to the DisplayObject broadcast events, except that - these two events are dispatched not only by all DisplayObject instances, - but also by all EventDispatcher instances and instances of other - EventDispatcher subclasses. For more information on broadcast events, see - the DisplayObject class. - - @event fullScreen Dispatched when the Stage object enters, or - leaves, full-screen mode. A change in - full-screen mode can be initiated through - ActionScript, or the user invoking a keyboard - shortcut, or if the current focus leaves the - full-screen window. - @event mouseLeave Dispatched by the Stage object when the - pointer moves out of the stage area. If the - mouse button is pressed, the event is not - dispatched. - @event orientationChange Dispatched by the Stage object when the stage - orientation changes. - - Orientation changes can occur when the - user rotates the device, opens a slide-out - keyboard, or when the - `setAspectRatio()` is called. - - **Note:** If the - `autoOrients` property is - `false`, then the stage - orientation does not change when a device is - rotated. Thus, StageOrientationEvents are - only dispatched for device rotation when - `autoOrients` is - `true`. - @event orientationChanging Dispatched by the Stage object when the stage - orientation begins changing. - - **Important:** orientationChanging - events are not dispatched on Android - devices. - - **Note:** If the - `autoOrients` property is - `false`, then the stage - orientation does not change when a device is - rotated. Thus, StageOrientationEvents are - only dispatched for device rotation when - `autoOrients` is - `true`. - @event resize Dispatched when the `scaleMode` - property of the Stage object is set to - `StageScaleMode.NO_SCALE` and the - SWF file is resized. - @event stageVideoAvailability Dispatched by the Stage object when the state - of the stageVideos property changes. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display3D.Context3D) -@:access(openfl.display.DisplayObjectRenderer) -@:access(openfl.display.LoaderInfo) -@:access(openfl.display.Sprite) -@:access(openfl.display.Stage3D) -@:access(openfl.events.Event) -@:access(openfl.events.UncaughtErrorEvents) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Point) -@:access(openfl.ui.GameInput) -@:access(openfl.ui.Keyboard) -@:access(openfl.ui.Mouse) -@:access(lime.ui.Window) -class Stage extends DisplayObjectContainer #if lime implements IModule #end -{ - /** - A value from the StageAlign class that specifies the alignment of the - stage in Flash Player or the browser. The following are valid values: - - The `align` property is only available to an object that is - in the same security sandbox as the Stage owner(the main SWF file). To - avoid this, the Stage owner can grant permission to the domain of the - calling object by calling the `Security.allowDomain()` method - or the `Security.alowInsecureDomain()` method. For more - information, see the "Security" chapter in the _ActionScript 3.0 - Developer's Guide_. - **/ - public var align:StageAlign; - - /** - Specifies whether this stage allows the use of the full screen mode - **/ - public var allowsFullScreen(default, null):Bool; - - /** - Specifies whether this stage allows the use of the full screen with text input mode - **/ - public var allowsFullScreenInteractive(default, null):Bool; - - /** - The associated Lime Application instance. - **/ - public var application(default, null):Application; - - // @:noCompletion @:dox(hide) @:require(flash15) public var browserZoomFactor (default, null):Float; - - /** - The window background color. - **/ - public var color(get, set):Null; - - #if false - /** - Controls Flash runtime color correction for displays. Color correction - works only if the main monitor is assigned a valid ICC color profile, - which specifies the device's particular color attributes. By default, - the Flash runtime tries to match the color correction of its host - (usually a browser). - Use the `Stage.colorCorrectionSupport` property to determine if color - correction is available on the current system and the default state. . - If color correction is available, all colors on the stage are assumed - to be in the sRGB color space, which is the most standard color space. - Source profiles of input devices are not considered during color - correction. No input color correction is applied; only the stage - output is mapped to the main monitor's ICC color profile. - - In general, the benefits of activating color management include - predictable and consistent color, better conversion, accurate proofing - and more efficient cross-media output. Be aware, though, that color - management does not provide perfect conversions due to devices having - a different gamut from each other or original images. Nor does color - management eliminate the need for custom or edited profiles. Color - profiles are dependent on browsers, operating systems (OS), OS - extensions, output devices, and application support. - - Applying color correction degrades the Flash runtime performance. A - Flash runtime's color correction is document style color correction - because all SWF movies are considered documents with implicit sRGB - profiles. Use the `Stage.colorCorrectionSupport` property to tell the - Flash runtime to correct colors when displaying the SWF file - (document) to the display color space. Flash runtimes only compensates - for differences between monitors, not for differences between input - devices (camera/scanner/etc.). - - The three possible values are strings with corresponding constants in - the openfl.display.ColorCorrection class: - - * `"default"`: Use the same color correction as the host system. - * `"on"`: Always perform color correction. - * `"off"`: Never perform color correction. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var colorCorrection:openfl.display.ColorCorrection; - #end - - #if false - /** - Specifies whether the Flash runtime is running on an operating system - that supports color correction and whether the color profile of the - main (primary) monitor can be read and understood by the Flash - runtime. This property also returns the default state of color - correction on the host system (usually the browser). Currently the - return values can be: - The three possible values are strings with corresponding constants in - the openfl.display.ColorCorrectionSupport class: - - * `"unsupported"`: Color correction is not available. - * `"defaultOn"`: Always performs color correction. - * `"defaultOff"`: Never performs color correction. - **/ - // @:noCompletion @:dox(hide) @:require(flash10) public var colorCorrectionSupport (default, null):openfl.display.ColorCorrectionSupport; - #end - - /** - Specifies the effective pixel scaling factor of the stage. This - value is 1 on standard screens and HiDPI (Retina display) - screens. When the stage is rendered on HiDPI screens the pixel - resolution is doubled; even if the stage scaling mode is set to - `StageScaleMode.NO_SCALE`. `Stage.stageWidth` and `Stage.stageHeight` - continue to be reported in classic pixel units. - **/ - public var contentsScaleFactor(get, never):Float; - - /** - **BETA** - - The current Context3D the default display renderer. - - This property is supported only when using hardware rendering. - **/ - public var context3D(default, null):Context3D; - - // @:noCompletion @:dox(hide) @:require(flash11) public var displayContextInfo (default, null):String; - - /** - A value from the StageDisplayState class that specifies which display - state to use. The following are valid values: - - * `StageDisplayState.FULL_SCREEN` Sets AIR application or - Flash runtime to expand the stage over the user's entire screen, with - keyboard input disabled. - * `StageDisplayState.FULL_SCREEN_INTERACTIVE` Sets the AIR - application to expand the stage over the user's entire screen, with - keyboard input allowed.(Not available for content running in Flash - Player.) - * `StageDisplayState.NORMAL` Sets the Flash runtime back to - the standard stage display mode. - - - The scaling behavior of the movie in full-screen mode is determined by - the `scaleMode` setting(set using the - `Stage.scaleMode` property or the SWF file's `embed` - tag settings in the HTML file). If the `scaleMode` property is - set to `noScale` while the application transitions to - full-screen mode, the Stage `width` and `height` - properties are updated, and the Stage dispatches a `resize` - event. If any other scale mode is set, the stage and its contents are - scaled to fill the new screen dimensions. The Stage object retains its - original `width` and `height` values and does not - dispatch a `resize` event. - - The following restrictions apply to SWF files that play within an HTML - page(not those using the stand-alone Flash Player or not running in the - AIR runtime): - - - * To enable full-screen mode, add the `allowFullScreen` - parameter to the `object` and `embed` tags in the - HTML page that includes the SWF file, with `allowFullScreen` - set to `"true"`, as shown in the following example: - * Full-screen mode is initiated in response to a mouse click or key - press by the user; the movie cannot change `Stage.displayState` - without user input. Flash runtimes restrict keyboard input in full-screen - mode. Acceptable keys include keyboard shortcuts that terminate - full-screen mode and non-printing keys such as arrows, space, Shift, and - Tab keys. Keyboard shortcuts that terminate full-screen mode are: Escape - (Windows, Linux, and Mac), Control+W(Windows), Command+W(Mac), and - Alt+F4. - - A Flash runtime dialog box appears over the movie when users enter - full-screen mode to inform the users they are in full-screen mode and that - they can press the Escape key to end full-screen mode. - - * Starting with Flash Player 9.0.115.0, full-screen works the same in - windowless mode as it does in window mode. If you set the Window Mode - (`wmode` in the HTML) to Opaque Windowless - (`opaque`) or Transparent Windowless - (`transparent`), full-screen can be initiated, but the - full-screen window will always be opaque. - - These restrictions are _not_ present for SWF content running in - the stand-alone Flash Player or in AIR. AIR supports an interactive - full-screen mode which allows keyboard input. - - For AIR content running in full-screen mode, the system screen saver - and power saving options are disabled while video content is playing and - until either the video stops or full-screen mode is exited. - - On Linux, setting `displayState` to - `StageDisplayState.FULL_SCREEN` or - `StageDisplayState.FULL_SCREEN_INTERACTIVE` is an asynchronous - operation. - - @throws SecurityError Calling the `displayState` property of a - Stage object throws an exception for any caller that - is not in the same security sandbox as the Stage - owner(the main SWF file). To avoid this, the Stage - owner can grant permission to the domain of the - caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - Trying to set the `displayState` property - while the settings dialog is displayed, without a - user response, or if the `param` or - `embed` HTML tag's - `allowFullScreen` attribute is not set to - `true` throws a security error. - **/ - public var displayState(get, set):StageDisplayState; - - #if commonjs - /** - The parent HTML element where this Stage is embedded. - **/ - public var element:Element; - #end - - /** - The interactive object with keyboard focus; or `null` if focus - is not set or if the focused object belongs to a security sandbox to which - the calling object does not have access. - - @throws Error Throws an error if focus cannot be set to the target. - **/ - public var focus(get, set):InteractiveObject; - - /** - Gets and sets the frame rate of the stage. The frame rate is defined as - frames per second. By default the rate is set to the frame rate of the - first SWF file loaded. Valid range for the frame rate is from 0.01 to 1000 - frames per second. - - **Note:** An application might not be able to follow high frame rate - settings, either because the target platform is not fast enough or the - player is synchronized to the vertical blank timing of the display device - (usually 60 Hz on LCD devices). In some cases, a target platform might - also choose to lower the maximum frame rate if it anticipates high CPU - usage. - - For content running in Adobe AIR, setting the `frameRate` - property of one Stage object changes the frame rate for all Stage objects - (used by different NativeWindow objects). - - @throws SecurityError Calling the `frameRate` property of a - Stage object throws an exception for any caller that - is not in the same security sandbox as the Stage - owner(the main SWF file). To avoid this, the Stage - owner can grant permission to the domain of the - caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var frameRate(get, set):Float; - - /** - Returns the height of the monitor that will be used when going to full - screen size, if that state is entered immediately. If the user has - multiple monitors, the monitor that's used is the monitor that most of - the stage is on at the time. - **Note**: If the user has the opportunity to move the browser from one - monitor to another between retrieving the value and going to full - screen size, the value could be incorrect. If you retrieve the value - in an event handler that sets `Stage.displayState` to - `StageDisplayState.FULL_SCREEN`, the value will be correct. - - This is the pixel height of the monitor and is the same as the stage - height would be if `Stage.align` is set to `StageAlign.TOP_LEFT` and - `Stage.scaleMode` is set to `StageScaleMode.NO_SCALE`. - **/ - public var fullScreenHeight(get, never):UInt; - - /** - Sets the Flash runtime to scale a specific region of the stage to - full-screen mode. If available, the Flash runtime scales in hardware, - which uses the graphics and video card on a user's computer, and - generally displays content more quickly than software scaling. - When this property is set to a valid rectangle and the `displayState` - property is set to full-screen mode, the Flash runtime scales the - specified area. The actual Stage size in pixels within ActionScript - does not change. The Flash runtime enforces a minimum limit for the - size of the rectangle to accommodate the standard "Press Esc to exit - full-screen mode" message. This limit is usually around 260 by 30 - pixels but can vary on platform and Flash runtime version. - - This property can only be set when the Flash runtime is not in - full-screen mode. To use this property correctly, set this property - first, then set the `displayState` property to full-screen mode, as - shown in the code examples. - - To enable scaling, set the `fullScreenSourceRect` property to a - rectangle object: - - ```haxe - // valid, will enable hardware scaling - stage.fullScreenSourceRect = new Rectangle(0,0,320,240); - ``` - - To disable scaling, set `fullScreenSourceRect=null`. - - ```haxe - stage.fullScreenSourceRect = null; - ``` - - The end user also can select within Flash Player Display Settings to - turn off hardware scaling, which is enabled by default. For more - information, see www.adobe.com/go/display_settings. - **/ - public var fullScreenSourceRect(get, set):Rectangle; - - /** - Returns the width of the monitor that will be used when going to full - screen size, if that state is entered immediately. If the user has - multiple monitors, the monitor that's used is the monitor that most of - the stage is on at the time. - **Note**: If the user has the opportunity to move the browser from one - monitor to another between retrieving the value and going to full - screen size, the value could be incorrect. If you retrieve the value - in an event handler that sets `Stage.displayState` to - `StageDisplayState.FULL_SCREEN`, the value will be correct. - - This is the pixel width of the monitor and is the same as the stage - width would be if `Stage.align` is set to `StageAlign.TOP_LEFT` and - `Stage.scaleMode` is set to `StageScaleMode.NO_SCALE`. - **/ - public var fullScreenWidth(get, never):UInt; - - // @:noCompletion @:dox(hide) @:require(flash11_2) public var mouseLock:Bool; - - /** - A value from the StageQuality class that specifies which rendering quality - is used. The following are valid values: - - * `StageQuality.LOW` - Low rendering quality. Graphics are - not anti-aliased, and bitmaps are not smoothed, but runtimes still use - mip-mapping. - * `StageQuality.MEDIUM` - Medium rendering quality. - Graphics are anti-aliased using a 2 x 2 pixel grid, bitmap smoothing is - dependent on the `Bitmap.smoothing` setting. Runtimes use - mip-mapping. This setting is suitable for movies that do not contain - text. - * `StageQuality.HIGH` - High rendering quality. Graphics - are anti-aliased using a 4 x 4 pixel grid, and bitmap smoothing is - dependent on the `Bitmap.smoothing` setting. Runtimes use - mip-mapping. This is the default rendering quality setting that Flash - Player uses. - * `StageQuality.BEST` - Very high rendering quality. - Graphics are anti-aliased using a 4 x 4 pixel grid. If - `Bitmap.smoothing` is `true` the runtime uses a high - quality downscale algorithm that produces fewer artifacts(however, using - `StageQuality.BEST` with `Bitmap.smoothing` set to - `true` slows performance significantly and is not a recommended - setting). - - - Higher quality settings produce better rendering of scaled bitmaps. - However, higher quality settings are computationally more expensive. In - particular, when rendering scaled video, using higher quality settings can - reduce the frame rate. - - In the desktop profile of Adobe AIR, `quality` can be set to - `StageQuality.BEST` or `StageQuality.HIGH`(and the - default value is `StageQuality.HIGH`). Attempting to set it to - another value has no effect(and the property remains unchanged). In the - moble profile of AIR, all four quality settings are available. The default - value on mobile devices is `StageQuality.MEDIUM`. - - For content running in Adobe AIR, setting the `quality` - property of one Stage object changes the rendering quality for all Stage - objects(used by different NativeWindow objects). - **_Note:_** The operating system draws the device fonts, which are - therefore unaffected by the `quality` property. - - @throws SecurityError Calling the `quality` property of a Stage - object throws an exception for any caller that is - not in the same security sandbox as the Stage owner - (the main SWF file). To avoid this, the Stage owner - can grant permission to the domain of the caller by - calling the `Security.allowDomain()` - method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var quality(get, set):StageQuality; - - /** - A value from the StageScaleMode class that specifies which scale mode to - use. The following are valid values: - - * `StageScaleMode.EXACT_FIT` - The entire application is - visible in the specified area without trying to preserve the original - aspect ratio. Distortion can occur, and the application may appear - stretched or compressed. - * `StageScaleMode.SHOW_ALL` - The entire application is - visible in the specified area without distortion while maintaining the - original aspect ratio of the application. Borders can appear on two sides - of the application. - * `StageScaleMode.NO_BORDER` - The entire application fills - the specified area, without distortion but possibly with some cropping, - while maintaining the original aspect ratio of the application. - * `StageScaleMode.NO_SCALE` - The entire application is - fixed, so that it remains unchanged even as the size of the player window - changes. Cropping might occur if the player window is smaller than the - content. - - - @throws SecurityError Calling the `scaleMode` property of a - Stage object throws an exception for any caller that - is not in the same security sandbox as the Stage - owner(the main SWF file). To avoid this, the Stage - owner can grant permission to the domain of the - caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var scaleMode(get, set):StageScaleMode; - - /** - Specifies whether to show or hide the default items in the Flash - runtime context menu. - If the `showDefaultContextMenu` property is set to `true` (the - default), all context menu items appear. If the - `showDefaultContextMenu` property is set to `false`, only the Settings - and About... menu items appear. - - @throws SecurityError Calling the `showDefaultContextMenu` property of - a Stage object throws an exception for any - caller that is not in the same security sandbox - as the Stage owner (the main SWF file). To avoid - this, the Stage owner can grant permission to - the domain of the caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. For - more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var showDefaultContextMenu:Bool; - - /** - The area of the stage that is currently covered by the software - keyboard. - The area has a size of zero (0,0,0,0) when the soft keyboard is not - visible. - - When the keyboard opens, the `softKeyboardRect` is set at the time the - softKeyboardActivate event is dispatched. If the keyboard changes size - while open, the runtime updates the `softKeyboardRect` property and - dispatches an additional softKeyboardActivate event. - - **Note:** On Android, the area covered by the keyboard is estimated - when the operating system does not provide the information necessary - to determine the exact area. This problem occurs in fullscreen mode - and also when the keyboard opens in response to an InteractiveObject - receiving focus or invoking the `requestSoftKeyboard()` method. - **/ - public var softKeyboardRect:Rectangle; - - /** - A list of Stage3D objects available for displaying 3-dimensional content. - - You can use only a limited number of Stage3D objects at a time. The number of - available Stage3D objects depends on the platform and on the available hardware. - - A Stage3D object draws in front of a StageVideo object and behind the OpenFL - display list. - **/ - public var stage3Ds(default, null):Vector; - - /** - Specifies whether or not objects display a glowing border when they have - focus. - - @throws SecurityError Calling the `stageFocusRect` property of - a Stage object throws an exception for any caller - that is not in the same security sandbox as the - Stage owner(the main SWF file). To avoid this, the - Stage owner can grant permission to the domain of - the caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var stageFocusRect:Bool; - - /** - The current height, in pixels, of the Stage. - - If the value of the `Stage.scaleMode` property is set to - `StageScaleMode.NO_SCALE` when the user resizes the window, the - Stage content maintains its size while the `stageHeight` - property changes to reflect the new height size of the screen area - occupied by the SWF file.(In the other scale modes, the - `stageHeight` property always reflects the original height of - the SWF file.) You can add an event listener for the `resize` - event and then use the `stageHeight` property of the Stage - class to determine the actual pixel dimension of the resized Flash runtime - window. The event listener allows you to control how the screen content - adjusts when the user resizes the window. - - Air for TV devices have slightly different behavior than desktop - devices when you set the `stageHeight` property. If the - `Stage.scaleMode` property is set to - `StageScaleMode.NO_SCALE` and you set the - `stageHeight` property, the stage height does not change until - the next frame of the SWF. - - **Note:** In an HTML page hosting the SWF file, both the - `object` and `embed` tags' `height` - attributes must be set to a percentage(such as `100%`), not - pixels. If the settings are generated by JavaScript code, the - `height` parameter of the `AC_FL_RunContent() ` - method must be set to a percentage, too. This percentage is applied to the - `stageHeight` value. - - @throws SecurityError Calling the `stageHeight` property of a - Stage object throws an exception for any caller that - is not in the same security sandbox as the Stage - owner(the main SWF file). To avoid this, the Stage - owner can grant permission to the domain of the - caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var stageHeight(default, null):Int; - - #if false - /** - A list of StageVideo objects available for playing external videos. - You can use only a limited number of StageVideo objects at a time. - When a SWF begins to run, the number of available StageVideo objects - depends on the platform and on available hardware. - - To use a StageVideo object, assign a member of the `stageVideos` - Vector object to a StageVideo variable. - - All StageVideo objects are displayed on the stage behind any display - objects. The StageVideo objects are displayed on the stage in the - order they appear in the `stageVideos` Vector object. For example, if - the `stageVideos` Vector object contains three entries: - - 1. The StageVideo object in the 0 index of the `stageVideos` Vector - object is displayed behind all StageVideo objects. - 2. The StageVideo object at index 1 is displayed in front of the - StageVideo object at index 0. - 3. The StageVideo object at index 2 is displayed in front of the - StageVideo object at index 1. - - Use the `StageVideo.depth` property to change this ordering. - - **Note:** AIR for TV devices support only one StageVideo object. - **/ - // @:noCompletion @:dox(hide) @:require(flash10_2) public var stageVideos (default, null):Vector; - #end - - /** - Specifies the current width, in pixels, of the Stage. - - If the value of the `Stage.scaleMode` property is set to - `StageScaleMode.NO_SCALE` when the user resizes the window, the - Stage content maintains its defined size while the `stageWidth` - property changes to reflect the new width size of the screen area occupied - by the SWF file.(In the other scale modes, the `stageWidth` - property always reflects the original width of the SWF file.) You can add - an event listener for the `resize` event and then use the - `stageWidth` property of the Stage class to determine the - actual pixel dimension of the resized Flash runtime window. The event - listener allows you to control how the screen content adjusts when the - user resizes the window. - - Air for TV devices have slightly different behavior than desktop - devices when you set the `stageWidth` property. If the - `Stage.scaleMode` property is set to - `StageScaleMode.NO_SCALE` and you set the - `stageWidth` property, the stage width does not change until - the next frame of the SWF. - - **Note:** In an HTML page hosting the SWF file, both the - `object` and `embed` tags' `width` - attributes must be set to a percentage(such as `100%`), not - pixels. If the settings are generated by JavaScript code, the - `width` parameter of the `AC_FL_RunContent() ` - method must be set to a percentage, too. This percentage is applied to the - `stageWidth` value. - - @throws SecurityError Calling the `stageWidth` property of a - Stage object throws an exception for any caller that - is not in the same security sandbox as the Stage - owner (the main SWF file). To avoid this, the Stage - owner can grant permission to the domain of the - caller by calling the - `Security.allowDomain()` method or the - `Security.allowInsecureDomain()` method. - For more information, see the "Security" chapter in - the _ActionScript 3.0 Developer's Guide_. - **/ - public var stageWidth(default, null):Int; - - /** - The associated Lime Window instance for this Stage. - **/ - public var window(default, null):Window; - - #if sys - /** - - **/ - public var nativeWindow(default, null):openfl.display.NativeWindow; - #end - - /** - Indicates whether GPU compositing is available and in use. The - `wmodeGPU` value is `true` _only_ when all three of the following - conditions exist: - * GPU compositing has been requested. - * GPU compositing is available. - * GPU compositing is in use. - - Specifically, the `wmodeGPU` property indicates one of the following: - - 1. GPU compositing has not been requested or is unavailable. In this - case, the `wmodeGPU` property value is `false`. - 2. GPU compositing has been requested (if applicable and available), - but the environment is operating in "fallback mode" (not optimal - rendering) due to limitations of the content. In this case, the - `wmodeGPU` property value is `true`. - 3. GPU compositing has been requested (if applicable and available), - and the environment is operating in the best mode. In this case, the - `wmodeGPU` property value is also `true`. - - In other words, the `wmodeGPU` property identifies the capability and - state of the rendering environment. For runtimes that do not support - GPU compositing, such as AIR 1.5.2, the value is always `false`, - because (as stated above) the value is `true` only when GPU - compositing has been requested, is available, and is in use. - - The `wmodeGPU` property is useful to determine, at runtime, whether or - not GPU compositing is in use. The value of `wmodeGPU` indicates if - your content is going to be scaled by hardware, or not, so you can - present graphics at the correct size. You can also determine if you're - rendering in a fast path or not, so that you can adjust your content - complexity accordingly. - - For Flash Player in a browser, GPU compositing can be requested by the - value of `gpu` for the `wmode` HTML parameter in the page hosting the - SWF file. For other configurations, GPU compositing can be requested - in the header of a SWF file (set using SWF authoring tools). - - However, the `wmodeGPU` property does not identify the current - rendering performance. Even if GPU compositing is "in use" the - rendering process might not be operating in the best mode. To adjust - your content for optimal rendering, use a Flash runtime debugger - version, and set the `DisplayGPUBlendsetting` in your mm.cfg file. - - **Note:** This property is always `false` when referenced from - ActionScript that runs before the runtime performs its first rendering - pass. For example, if you examine `wmodeGPU` from a script in Frame 1 - of Adobe Flash Professional, and your SWF file is the first SWF file - loaded in a new instance of the runtime, then the `wmodeGPU` value is - `false`. To get an accurate value, wait until at least one rendering - pass has occurred. If you write an event listener for the `exitFrame` - event of any `DisplayObject`, the `wmodeGPU` value at is the correct - value. - **/ - #if false - // @:noCompletion @:dox(hide) @:require(flash10_1) public var wmodeGPU (default, null):Bool; - #end - @:noCompletion private var __cacheFocus:InteractiveObject; - @:noCompletion private var __clearBeforeRender:Bool; - @:noCompletion private var __color:Int; - @:noCompletion private var __colorSplit:Array; - @:noCompletion private var __colorString:String; - @:noCompletion private var __contentsScaleFactor:Float; - @:noCompletion private var __currentTabOrderIndex:Int; - #if (commonjs && !nodejs) - @:noCompletion private var __cursor:LimeMouseCursor; - #end - @:noCompletion private var __deltaTime:Float; - @:noCompletion private var __dirty:Bool; - @:noCompletion private var __displayMatrix:Matrix; - @:noCompletion private var __displayRect:Rectangle; - @:noCompletion private var __displayState:StageDisplayState; - @:noCompletion private var __dragBounds:Rectangle; - @:noCompletion private var __dragObject:Sprite; - @:noCompletion private var __dragOffsetX:Float; - @:noCompletion private var __dragOffsetY:Float; - @:noCompletion private var __focus:InteractiveObject; - @:noCompletion private var __forceRender:Bool; - @:noCompletion private var __fullscreen:Bool; - @:noCompletion private var __fullScreenSourceRect:Rectangle; - @:noCompletion private var __invalidated:Bool; - @:noCompletion private var __lastClickTime:Int; - @:noCompletion private var __lastClickTarget:InteractiveObject; - @:noCompletion private var __logicalWidth:Int; - @:noCompletion private var __logicalHeight:Int; - @:noCompletion private var __macKeyboard:Bool; - @:noCompletion private var __mouseDownLeft:InteractiveObject; - @:noCompletion private var __mouseDownMiddle:InteractiveObject; - @:noCompletion private var __mouseDownRight:InteractiveObject; - @:noCompletion private var __mouseOutStack:Array; - @:noCompletion private var __mouseOverTarget:InteractiveObject; - @:noCompletion private var __mouseX:Float; - @:noCompletion private var __mouseY:Float; - @:noCompletion private var __pendingMouseEvent:Bool; - @:noCompletion private var __pendingMouseX:Int; - @:noCompletion private var __pendingMouseY:Int; - @:noCompletion private var __quality:StageQuality; - @:noCompletion private var __renderer:DisplayObjectRenderer; - @:noCompletion private var __rendering:Bool; - @:noCompletion private var __rollOutStack:Array; - @:noCompletion private var __scaleMode:StageScaleMode; - @:noCompletion private var __stack:Array; - @:noCompletion private var __touchData:Map; - @:noCompletion private var __transparent:Bool; - @:noCompletion private var __uncaughtErrorEvents:UncaughtErrorEvents; - @:noCompletion private var __wasDirty:Bool; - @:noCompletion private var __wasFullscreen:Bool; - #if lime - @:noCompletion private var __primaryTouch:Touch; - #end - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(Stage.prototype, { - "color": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_color (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_color (v); }") - }, - "contentsScaleFactor": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_contentsScaleFactor (); }") - }, - "displayState": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_displayState (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_displayState (v); }") - }, - "focus": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_focus (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_focus (v); }") - }, - "frameRate": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_frameRate (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_frameRate (v); }") - }, - "fullScreenHeight": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_fullScreenHeight (); }") - }, - "fullScreenWidth": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_fullScreenWidth (); }") - }, - "quality": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_quality (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_quality (v); }") - }, - "scaleMode": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_scaleMode (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_scaleMode (v); }") - }, - }); - } - #end - - public function new(#if commonjs width:Dynamic = 0, height:Dynamic = 0, color:Null = null, documentClass:Class = null, - windowAttributes:Dynamic = null #else window:Window, color:Null = null #end) - { - #if hxtelemetry - Telemetry.__initialize(); - #end - - super(); - - __drawableType = STAGE; - this.name = null; - - __color = 0xFFFFFFFF; - __colorSplit = [0xFF, 0xFF, 0xFF]; - __colorString = "#FFFFFF"; - __contentsScaleFactor = 1; - __currentTabOrderIndex = 0; - __deltaTime = 0; - __displayState = NORMAL; - __mouseX = 0; - __mouseY = 0; - __lastClickTime = 0; - __logicalWidth = 0; - __logicalHeight = 0; - __displayMatrix = new Matrix(); - __displayRect = new Rectangle(); - __renderDirty = true; - - stage3Ds = new Vector(); - for (i in 0...#if mobile 2 #else 4 #end) - { - stage3Ds.push(new Stage3D(this)); - } - - this.stage = this; - - align = StageAlign.TOP_LEFT; - allowsFullScreen = true; - allowsFullScreenInteractive = true; - __quality = StageQuality.HIGH; - __scaleMode = StageScaleMode.NO_SCALE; - showDefaultContextMenu = true; - softKeyboardRect = new Rectangle(); - stageFocusRect = true; - - #if mac - __macKeyboard = true; - #elseif (js && html5) - __macKeyboard = untyped #if haxe4 js.Syntax.code #else __js__ #end ("/AppleWebKit/.test (navigator.userAgent) && /Mobile\\/\\w+/.test (navigator.userAgent) || /Mac/.test (navigator.platform)"); - #end - - __clearBeforeRender = true; - __forceRender = false; - __stack = []; - __rollOutStack = []; - __mouseOutStack = []; - __touchData = new Map(); - - if (Lib.current.__loaderInfo == null) - { - Lib.current.__loaderInfo = LoaderInfo.create(null); - Lib.current.__loaderInfo.content = Lib.current; - } - - // TODO: Do not rely on Lib.current - __uncaughtErrorEvents = Lib.current.__loaderInfo.uncaughtErrorEvents; - - #if commonjs - if (windowAttributes == null) windowAttributes = {}; - var app = null; - - if (!Math.isNaN(width)) - { - var resizable = (width == 0 && width == 0); - - #if (js && html5) - if (windowAttributes.element != null) - { - element = windowAttributes.element; - } - else - { - element = Browser.document.createElement("div"); - } - - if (resizable) - { - element.style.width = "100%"; - element.style.height = "100%"; - } - #else - element = null; - #end - - windowAttributes.width = width; - windowAttributes.height = height; - windowAttributes.element = element; - windowAttributes.resizable = resizable; - - windowAttributes.stage = this; - - if (!Reflect.hasField(windowAttributes, "context")) windowAttributes.context = {}; - var contextAttributes = windowAttributes.context; - if (Reflect.hasField(windowAttributes, "renderer")) - { - var type = Std.string(windowAttributes.renderer); - if (type == "webgl1") - { - contextAttributes.type = RenderContextType.WEBGL; - contextAttributes.version = "1"; - } - else if (type == "webgl2") - { - contextAttributes.type = RenderContextType.WEBGL; - contextAttributes.version = "2"; - } - else - { - Reflect.setField(contextAttributes, "type", windowAttributes.renderer); - } - } - if (!Reflect.hasField(contextAttributes, "stencil")) contextAttributes.stencil = true; - if (!Reflect.hasField(contextAttributes, "depth")) contextAttributes.depth = true; - if (!Reflect.hasField(contextAttributes, "background")) contextAttributes.background = null; - - app = new OpenFLApplication(); - window = app.createWindow(windowAttributes); - - this.color = color; - } - else - { - this.window = cast width; - this.color = height; - } - #else - this.application = window.application; - this.window = window; - this.color = color; - #end - - __contentsScaleFactor = window.scale; - __wasFullscreen = window.fullscreen; - - __resize(); - - if (Lib.current.stage == null) - { - stage.addChild(Lib.current); - } - - #if commonjs - if (documentClass != null) - { - DisplayObject.__initStage = this; - var sprite:Sprite = cast Type.createInstance(documentClass, []); - // addChild (sprite); // done by init stage - sprite.dispatchEvent(new Event(Event.ADDED_TO_STAGE, false, false)); - } - - if (app != null) - { - app.addModule(this); - app.exec(); - } - #end - } - - /** - Calling the `invalidate()` method signals Flash runtimes to - alert display objects on the next opportunity it has to render the display - list(for example, when the playhead advances to a new frame). After you - call the `invalidate()` method, when the display list is next - rendered, the Flash runtime sends a `render` event to each - display object that has registered to listen for the `render` - event. You must call the `invalidate()` method each time you - want the Flash runtime to send `render` events. - - The `render` event gives you an opportunity to make changes - to the display list immediately before it is actually rendered. This lets - you defer updates to the display list until the latest opportunity. This - can increase performance by eliminating unnecessary screen updates. - - The `render` event is dispatched only to display objects - that are in the same security domain as the code that calls the - `stage.invalidate()` method, or to display objects from a - security domain that has been granted permission via the - `Security.allowDomain()` method. - - **/ - public override function invalidate():Void - { - __invalidated = true; - - // TODO: Should this not mark as dirty? - __renderDirty = true; - } - - // @:noCompletion @:dox(hide) public function isFocusInaccessible ():Bool; - public override function localToGlobal(pos:Point):Point - { - return pos.clone(); - } - - @SuppressWarnings("checkstyle:Dynamic") - @:noCompletion private function __broadcastEvent(event:Event):Void - { - if (DisplayObject.__broadcastEvents.exists(event.type)) - { - var dispatchers = DisplayObject.__broadcastEvents.get(event.type); - - for (dispatcher in dispatchers) - { - // TODO: Way to resolve dispatching occurring if object not on stage - // and there are multiple stage objects running in HTML5? - - if (dispatcher.stage == this || dispatcher.stage == null) - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - dispatcher.__dispatch(event); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - dispatcher.__dispatch(event); - } - } - } - } - } - - @:noCompletion private function __createRenderer():Void - { - #if lime - var windowWidth = Std.int(window.width * window.scale); - var windowHeight = Std.int(window.height * window.scale); - - switch (window.context.type) - { - case OPENGL, OPENGLES, WEBGL: - #if (!disable_cffi && (!html5 || !canvas)) - context3D = new Context3D(this); - #if openfl_dpi_aware - context3D.configureBackBuffer(windowWidth, windowHeight, 0, true, true, true); - #else - context3D.configureBackBuffer(stageWidth, stageHeight, 0, true, true, true); - #end - context3D.present(); - __renderer = new OpenGLRenderer(context3D); - #end - - case CANVAS: - #if (js && html5) - __renderer = new CanvasRenderer(window.context.canvas2D); - #end - - case DOM: - #if (js && html5) - __renderer = new DOMRenderer(window.context.dom); - #end - - case CAIRO: - #if lime_cairo - __renderer = new CairoRenderer(window.context.cairo); - #end - - default: - } - - if (__renderer != null) - { - __renderer.__allowSmoothing = (quality != LOW); - __renderer.__pixelRatio = #if openfl_disable_hdpi 1 #else window.scale #end; - __renderer.__worldTransform = __displayMatrix; - __renderer.__stage = this; - - #if (js && html5 && dom && !openfl_disable_hdpi) - __renderer.__pixelRatio = Browser.window.devicePixelRatio; - #end - - __renderer.__resize(windowWidth, windowHeight); - } - #end - } - - @SuppressWarnings(["checkstyle:Dynamic", "checkstyle:LeftCurly"]) - @:noCompletion private override function __dispatchEvent(event:Event):Bool - { - var result:Bool; - if (__uncaughtErrorEvents.__enabled) - { - try - { - result = super.__dispatchEvent(event); - } - catch (e:Dynamic) - { - __handleError(e); - result = false; - } - } - else - { - result = super.__dispatchEvent(event); - } - return result; - } - - @:noCompletion private function __dispatchPendingMouseEvent():Void - { - if (__pendingMouseEvent) - { - __onMouse(MouseEvent.MOUSE_MOVE, __pendingMouseX, __pendingMouseY, 0); - __pendingMouseEvent = false; - } - } - - @SuppressWarnings(["checkstyle:Dynamic", "checkstyle:LeftCurly"]) - @:noCompletion private function __dispatchStack(event:Event, stack:Array):Void - { - // TODO: Prevent repetition - if (__uncaughtErrorEvents.__enabled) - { - try - { - var target:DisplayObject; - var length = stack.length; - - if (length == 0) - { - event.eventPhase = EventPhase.AT_TARGET; - target = cast event.target; - target.__dispatch(event); - } - else - { - event.eventPhase = EventPhase.CAPTURING_PHASE; - event.target = stack[stack.length - 1]; - - for (i in 0...length - 1) - { - stack[i].__dispatch(event); - - if (event.__isCanceled) - { - return; - } - } - - event.eventPhase = EventPhase.AT_TARGET; - target = cast event.target; - target.__dispatch(event); - - if (event.__isCanceled) - { - return; - } - - if (event.bubbles) - { - event.eventPhase = EventPhase.BUBBLING_PHASE; - var i = length - 2; - - while (i >= 0) - { - stack[i].__dispatch(event); - - if (event.__isCanceled) - { - return; - } - - i--; - } - } - } - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - var target:DisplayObject; - var length = stack.length; - - if (length == 0) - { - event.eventPhase = EventPhase.AT_TARGET; - target = cast event.target; - target.__dispatch(event); - } - else - { - event.eventPhase = EventPhase.CAPTURING_PHASE; - event.target = stack[stack.length - 1]; - - for (i in 0...length - 1) - { - stack[i].__dispatch(event); - - if (event.__isCanceled) - { - return; - } - } - - event.eventPhase = EventPhase.AT_TARGET; - target = cast event.target; - target.__dispatch(event); - - if (event.__isCanceled) - { - return; - } - - if (event.bubbles) - { - event.eventPhase = EventPhase.BUBBLING_PHASE; - var i = length - 2; - - while (i >= 0) - { - stack[i].__dispatch(event); - - if (event.__isCanceled) - { - return; - } - - i--; - } - } - } - } - } - - @SuppressWarnings("checkstyle:Dynamic") - @:noCompletion private function __dispatchTarget(target:EventDispatcher, event:Event):Bool - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - return target.__dispatchEvent(event); - } - catch (e:Dynamic) - { - __handleError(e); - return false; - } - } - else - { - return target.__dispatchEvent(event); - } - } - - @:noCompletion private function __drag(mouse:Point):Void - { - var parent = __dragObject.parent; - if (parent != null) - { - parent.__getWorldTransform().__transformInversePoint(mouse); - } - - var x = mouse.x + __dragOffsetX; - var y = mouse.y + __dragOffsetY; - - if (__dragBounds != null) - { - if (x < __dragBounds.x) - { - x = __dragBounds.x; - } - else if (x > __dragBounds.right) - { - x = __dragBounds.right; - } - - if (y < __dragBounds.y) - { - y = __dragBounds.y; - } - else if (y > __dragBounds.bottom) - { - y = __dragBounds.bottom; - } - } - - __dragObject.x = x; - __dragObject.y = y; - } - - @:noCompletion private override function __getInteractive(stack:Array):Bool - { - if (stack != null) - { - stack.push(this); - } - - return true; - } - - @:noCompletion private override function __globalToLocal(global:Point, local:Point):Point - { - if (global != local) - { - local.copyFrom(global); - } - - return local; - } - - @SuppressWarnings("checkstyle:Dynamic") - @:noCompletion private function __handleError(e:Dynamic):Void - { - var event = new UncaughtErrorEvent(UncaughtErrorEvent.UNCAUGHT_ERROR, true, true, e); - - try - { - Lib.current.__loaderInfo.uncaughtErrorEvents.dispatchEvent(event); - } - catch (e:Dynamic) {} - - if (!event.__preventDefault) - { - // #if mobile - Log.println(CallStack.toString(CallStack.exceptionStack())); - Log.println(Std.string(e)); - // #end - - #if (cpp && !cppia) - untyped __cpp__("throw e"); - #elseif neko - neko.Lib.rethrow(e); - #elseif js - try - { - #if (haxe >= "4.1.0") - var exc = e; - #else - var exc = @:privateAccess haxe.CallStack.lastException; - #end - if (exc != null && Reflect.hasField(exc, "stack") && exc.stack != null && exc.stack != "") - { - untyped #if haxe4 js.Syntax.code #else __js__ #end ("console.log")(exc.stack); - e.stack = exc.stack; - } - else - { - var msg = CallStack.toString(CallStack.callStack()); - untyped #if haxe4 js.Syntax.code #else __js__ #end ("console.log")(msg); - } - } - catch (e2:Dynamic) {} - untyped #if haxe4 js.Syntax.code #else __js__ #end ("throw e"); - #elseif cs - throw e; - // cs.Lib.rethrow (e); - #elseif hl - hl.Api.rethrow(e); - #else - throw e; - #end - } - } - - #if lime - @:noCompletion private function __onKey(type:String, keyCode:KeyCode, modifier:KeyModifier):Void - { - __dispatchPendingMouseEvent(); - - MouseEvent.__altKey = modifier.altKey; - MouseEvent.__commandKey = modifier.metaKey; - MouseEvent.__controlKey = modifier.ctrlKey && !modifier.metaKey; - MouseEvent.__ctrlKey = modifier.ctrlKey; - MouseEvent.__shiftKey = modifier.shiftKey; - - var stack = new Array(); - - if (__focus == null) - { - __getInteractive(stack); - } - else - { - __focus.__getInteractive(stack); - } - - if (stack.length > 0) - { - var keyLocation = Keyboard.__getKeyLocation(keyCode); - var keyCode = Keyboard.__convertKeyCode(keyCode); - var charCode = Keyboard.__getCharCode(keyCode, modifier.shiftKey); - - if (type == KeyboardEvent.KEY_UP && (keyCode == Keyboard.SPACE || keyCode == Keyboard.ENTER) && (__focus is Sprite)) - { - var sprite = cast(__focus, Sprite); - if (sprite.buttonMode && sprite.focusRect == true) - { - var localPoint = Point.__pool.get(); - var targetPoint = Point.__pool.get(); - targetPoint.x = __mouseX; - targetPoint.y = __mouseY; - - #if openfl_pool_events - var clickEvent = MouseEvent.__pool.get(); - clickEvent.type = MouseEvent.CLICK; - clickEvent.stageX = __mouseX; - clickEvent.stageY = __mouseY; - var local = sprite.__globalToLocal(targetPoint, localPoint); - clickEvent.localX = local.x; - clickEvent.localY = local.y; - clickEvent.target = sprite; - #else - var clickEvent = MouseEvent.__create(MouseEvent.CLICK, 0, __mouseX, __mouseY, sprite.__globalToLocal(targetPoint, localPoint), sprite); - #end - - __dispatchStack(clickEvent, stack); - - if (clickEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(clickEvent); - #end - - Point.__pool.release(targetPoint); - Point.__pool.release(localPoint); - } - } - - // Flash Player events are not cancelable, should we make only some events (like APP_CONTROL_BACK) cancelable? - - var event = new KeyboardEvent(type, true, true, charCode, keyCode, keyLocation, - __macKeyboard ? (modifier.ctrlKey || modifier.metaKey) : modifier.ctrlKey, modifier.altKey, modifier.shiftKey, modifier.ctrlKey, - modifier.metaKey); - - stack.reverse(); - __dispatchStack(event, stack); - - if (event.__preventDefault) - { - if (type == KeyboardEvent.KEY_DOWN) - { - window.onKeyDown.cancel(); - } - else - { - window.onKeyUp.cancel(); - } - } - else - { - if (type == KeyboardEvent.KEY_DOWN && keyCode == Keyboard.TAB) - { - var tabStack = new Array(); - - __tabTest(tabStack); - - var nextIndex = -1; - var nextObject:InteractiveObject = null; - var nextOffset = modifier.shiftKey ? -1 : 1; - - if (tabStack.length > 1) - { - ArraySort.sort(tabStack, function(a, b) - { - return a.tabIndex - b.tabIndex; - }); - - if (tabStack[tabStack.length - 1].tabIndex != -1) - { - // if some tabIndices aren't equal to -1, remove all - // of the ones that are - var i = 0; - while (i < tabStack.length) - { - if (tabStack[i].tabIndex > -1) - { - if (i > 0) tabStack.splice(0, i); - break; - } - - i++; - } - } - - if (focus != null) - { - var current = focus; - var index = tabStack.indexOf(current); - while (index == -1 && current != null) - { - // if the current focus is not in the tab stack, - // try to find the nearest object in the display - // list that is in the stack - var currentParent = current.parent; - if (currentParent != null && currentParent.tabChildren) - { - var currentIndex = currentParent.getChildIndex(current); - if (currentIndex == -1) - { - current = currentParent; - continue; - } - var i = currentIndex + nextOffset; - while (modifier.shiftKey ? (i >= 0) : (i < currentParent.numChildren)) - { - var sibling = currentParent.getChildAt(i); - if ((sibling is InteractiveObject)) - { - var interactiveSibling = cast(sibling, InteractiveObject); - index = tabStack.indexOf(interactiveSibling); - if (index != -1) - { - nextOffset = 0; - break; - } - } - i += nextOffset; - } - } - else if (modifier.shiftKey) - { - index = tabStack.indexOf(currentParent); - if (index != -1) nextOffset = 0; - } - current = currentParent; - } - - if (index < 0) nextIndex = 0; - else - nextIndex = index + nextOffset; - } - else - { - nextIndex = __currentTabOrderIndex; - } - } - else if (tabStack.length == 1) - { - nextObject = tabStack[0]; - - if (focus == nextObject) nextObject = null; - } - - var cancelTab = nextIndex >= 0 && nextIndex < tabStack.length; - if (tabStack.length == 1 || tabStack.length == 0 && focus != null) - { - nextIndex = 0; - } - else if (tabStack.length > 1) - { - if (nextIndex < 0) nextIndex += tabStack.length; - - nextIndex %= tabStack.length; - nextObject = tabStack[nextIndex]; - - if (nextObject == focus) - { - nextIndex += nextOffset; - - if (nextIndex < 0) nextIndex += tabStack.length; - - nextIndex %= tabStack.length; - nextObject = tabStack[nextIndex]; - } - } - - var focusEvent = null; - - if (focus != null) - { - focusEvent = new FocusEvent(FocusEvent.KEY_FOCUS_CHANGE, true, true, nextObject, modifier.shiftKey, 0); - - stack = []; - - focus.__getInteractive(stack); - stack.reverse(); - - __dispatchStack(focusEvent, stack); - - if (focusEvent.isDefaultPrevented()) - { - window.onKeyDown.cancel(); - } - } - - if (focusEvent == null || !focusEvent.isDefaultPrevented()) - { - __currentTabOrderIndex = nextIndex; - if (nextObject != null) focus = nextObject; - if (cancelTab) - { - // ensure that the html5 target does not lose focus - // to the browser every time that tab is pressed - window.onKeyDown.cancel(); - } - - // TODO: handle border around focus - } - } - - // TODO: handle arrow keys changing the focus - } - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - } - #end - - #if lime - @:noCompletion private function __onLimeCreateWindow(window:Window):Void - { - if (this.window != window) return; - - window.onActivate.add(__onLimeWindowActivate.bind(window)); - window.onClose.add(__onLimeWindowClose.bind(window), false, -9000); - window.onDeactivate.add(__onLimeWindowDeactivate.bind(window)); - window.onDropFile.add(__onLimeWindowDropFile.bind(window)); - window.onEnter.add(__onLimeWindowEnter.bind(window)); - window.onExpose.add(__onLimeWindowExpose.bind(window)); - window.onFocusIn.add(__onLimeWindowFocusIn.bind(window)); - window.onFocusOut.add(__onLimeWindowFocusOut.bind(window)); - window.onFullscreen.add(__onLimeWindowFullscreen.bind(window)); - window.onKeyDown.add(__onLimeKeyDown.bind(window)); - window.onKeyUp.add(__onLimeKeyUp.bind(window)); - window.onLeave.add(__onLimeWindowLeave.bind(window)); - window.onMinimize.add(__onLimeWindowMinimize.bind(window)); - window.onMouseDown.add(__onLimeMouseDown.bind(window)); - window.onMouseMove.add(__onLimeMouseMove.bind(window)); - window.onMouseMoveRelative.add(__onLimeMouseMoveRelative.bind(window)); - window.onMouseUp.add(__onLimeMouseUp.bind(window)); - window.onMouseWheel.add(__onLimeMouseWheel.bind(window)); - window.onMove.add(__onLimeWindowMove.bind(window)); - window.onRender.add(__onLimeRender); - window.onRenderContextLost.add(__onLimeRenderContextLost); - window.onRenderContextRestored.add(__onLimeRenderContextRestored); - window.onResize.add(__onLimeWindowResize.bind(window)); - window.onRestore.add(__onLimeWindowRestore.bind(window)); - window.onTextEdit.add(__onLimeTextEdit.bind(window)); - window.onTextInput.add(__onLimeTextInput.bind(window)); - - __onLimeWindowCreate(window); - } - - @:noCompletion private function __onLimeGamepadAxisMove(gamepad:Gamepad, axis:GamepadAxis, value:Float):Void - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - GameInput.__onGamepadAxisMove(gamepad, axis, value); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - GameInput.__onGamepadAxisMove(gamepad, axis, value); - } - } - - @:noCompletion private function __onLimeGamepadButtonDown(gamepad:Gamepad, button:GamepadButton):Void - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - GameInput.__onGamepadButtonDown(gamepad, button); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - GameInput.__onGamepadButtonDown(gamepad, button); - } - } - - @:noCompletion private function __onLimeGamepadButtonUp(gamepad:Gamepad, button:GamepadButton):Void - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - GameInput.__onGamepadButtonUp(gamepad, button); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - GameInput.__onGamepadButtonUp(gamepad, button); - } - } - - @:noCompletion private function __onLimeGamepadConnect(gamepad:Gamepad):Void - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - GameInput.__onGamepadConnect(gamepad); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - GameInput.__onGamepadConnect(gamepad); - } - - gamepad.onAxisMove.add(__onLimeGamepadAxisMove.bind(gamepad)); - gamepad.onButtonDown.add(__onLimeGamepadButtonDown.bind(gamepad)); - gamepad.onButtonUp.add(__onLimeGamepadButtonUp.bind(gamepad)); - gamepad.onDisconnect.add(__onLimeGamepadDisconnect.bind(gamepad)); - } - - @:noCompletion private function __onLimeGamepadDisconnect(gamepad:Gamepad):Void - { - if (__uncaughtErrorEvents.__enabled) - { - try - { - GameInput.__onGamepadDisconnect(gamepad); - } - catch (e:Dynamic) - { - __handleError(e); - } - } - else - { - GameInput.__onGamepadDisconnect(gamepad); - } - } - - @:noCompletion private function __onLimeKeyDown(window:Window, keyCode:KeyCode, modifier:KeyModifier):Void - { - if (this.window == null || this.window != window) return; - - __onKey(KeyboardEvent.KEY_DOWN, keyCode, modifier); - } - - @:noCompletion private function __onLimeKeyUp(window:Window, keyCode:KeyCode, modifier:KeyModifier):Void - { - if (this.window == null || this.window != window) return; - - __onKey(KeyboardEvent.KEY_UP, keyCode, modifier); - } - - @:noCompletion private function __onLimeModuleExit(code:Int):Void - { - if (window != null) - { - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.DEACTIVATE; - #else - event = new Event(Event.DEACTIVATE); - #end - - __broadcastEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - } - - @:noCompletion private function __onLimeMouseDown(window:Window, x:Float, y:Float, button:Int):Void - { - if (this.window == null || this.window != window) return; - - __dispatchPendingMouseEvent(); - - var type = switch (button) - { - case 1: MouseEvent.MIDDLE_MOUSE_DOWN; - case 2: MouseEvent.RIGHT_MOUSE_DOWN; - default: MouseEvent.MOUSE_DOWN; - } - - __onMouse(type, Std.int(x * window.scale), Std.int(y * window.scale), button); - - if (!showDefaultContextMenu && button == 2) - { - window.onMouseDown.cancel(); - } - } - - @:noCompletion private function __onLimeMouseMove(window:Window, x:Float, y:Float):Void - { - if (this.window == null || this.window != window) return; - - #if openfl_always_dispatch_mouse_events - __onMouse(MouseEvent.MOUSE_MOVE, Std.int(x * window.scale), Std.int(y * window.scale), 0); - #else - __pendingMouseEvent = true; - __pendingMouseX = Std.int(x * window.scale); - __pendingMouseY = Std.int(y * window.scale); - #end - } - - @:noCompletion private function __onLimeMouseMoveRelative(window:Window, x:Float, y:Float):Void - { - // if (this.window == null || this.window != window) return; - } - - @:noCompletion private function __onLimeMouseUp(window:Window, x:Float, y:Float, button:Int):Void - { - if (this.window == null || this.window != window) return; - - __dispatchPendingMouseEvent(); - - var type = switch (button) - { - case 1: MouseEvent.MIDDLE_MOUSE_UP; - case 2: MouseEvent.RIGHT_MOUSE_UP; - default: MouseEvent.MOUSE_UP; - } - - __onMouse(type, Std.int(x * window.scale), Std.int(y * window.scale), button); - - if (!showDefaultContextMenu && button == 2) - { - window.onMouseUp.cancel(); - } - } - - @:noCompletion private function __onLimeMouseWheel(window:Window, deltaX:Float, deltaY:Float, deltaMode:MouseWheelMode):Void - { - if (this.window == null || this.window != window) return; - - __dispatchPendingMouseEvent(); - - if (deltaMode == PIXELS) - { - __onMouseWheel(Std.int(deltaX * window.scale), Std.int(deltaY * window.scale), deltaMode); - } - else - { - __onMouseWheel(Std.int(deltaX), Std.int(deltaY), deltaMode); - } - } - - @:noCompletion private function __renderAfterEvent():Void - { - #if (cpp || hl || neko) - // TODO: should Lime have a public API to force rendering? - window.__backend.render(); - #end - var cancelled = __render(window.context); - #if (cpp || hl || neko) - if (!cancelled) - { - window.__backend.contextFlip(); - } - #end - } - - @:noCompletion private function __render(context:RenderContext):Bool - { - var cancelled = false; - - var event:Event = null; - - var shouldRender = #if !openfl_disable_display_render (__renderer != null #if !openfl_always_render && (__renderDirty || __forceRender) #end) #else false #end; - - if (__invalidated && shouldRender) - { - __invalidated = false; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.RENDER; - #else - event = new Event(Event.RENDER); - #end - - __broadcastEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - - #if hxtelemetry - var stack = Telemetry.__unwindStack(); - Telemetry.__startTiming(TelemetryCommandName.RENDER); - #end - - __update(false, true); - - #if lime - if (__renderer != null) - { - if (context3D != null) - { - for (stage3D in stage3Ds) - { - context3D.__renderStage3D(stage3D); - } - - #if !openfl_disable_display_render - if (context3D.__present) shouldRender = true; - #end - } - - if (shouldRender) - { - if (__renderer.__type == CAIRO) - { - #if lime_cairo - cast(__renderer, CairoRenderer).cairo = context.cairo; - #end - } - - if (context3D == null) - { - __renderer.__clear(); - } - - __renderer.__render(this); - } - else if (context3D == null) - { - cancelled = true; - } - - if (context3D != null) - { - if (!context3D.__present) - { - cancelled = true; - } - else - { - if (!__renderer.__cleared) - { - __renderer.__clear(); - } - - context3D.__present = false; - context3D.__cleared = false; - } - } - - __renderer.__cleared = false; - } - #end - - #if hxtelemetry - Telemetry.__endTiming(TelemetryCommandName.RENDER); - Telemetry.__rewindStack(stack); - #end - - return cancelled; - } - - @:noCompletion private function __onLimeRender(context:RenderContext):Void - { - if (__rendering) return; - __rendering = true; - - #if hxtelemetry - Telemetry.__advanceFrame(); - #end - - #if gl_stats - Context3DStats.resetDrawCalls(); - #end - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.ENTER_FRAME; - - __broadcastEvent(event); - - Event.__pool.release(event); - event = Event.__pool.get(); - event.type = Event.FRAME_CONSTRUCTED; - - __broadcastEvent(event); - - Event.__pool.release(event); - event = Event.__pool.get(); - event.type = Event.EXIT_FRAME; - - __broadcastEvent(event); - - Event.__pool.release(event); - #else - __broadcastEvent(new Event(Event.ENTER_FRAME)); - __broadcastEvent(new Event(Event.FRAME_CONSTRUCTED)); - __broadcastEvent(new Event(Event.EXIT_FRAME)); - #end - - __renderable = true; - __enterFrame(__deltaTime); - __deltaTime = 0; - - var cancelled = __render(context); - if (cancelled) - { - window.onRender.cancel(); - } - - __rendering = false; - } - - @:noCompletion private function __onLimeRenderContextLost():Void - { - __renderer = null; - context3D = null; - - for (stage3D in stage3Ds) - { - stage3D.__lostContext(); - } - } - - @:noCompletion private function __onLimeRenderContextRestored(context:RenderContext):Void - { - __createRenderer(); - - for (stage3D in stage3Ds) - { - stage3D.__restoreContext(); - } - } - - @:noCompletion private function __onLimeTextEdit(window:Window, text:String, start:Int, length:Int):Void - { - // if (this.window == null || this.window != window) return; - } - - @:noCompletion private function __onLimeTextInput(window:Window, text:String):Void - { - if (this.window == null || this.window != window) return; - - var stack = new Array(); - - if (__focus == null) - { - __getInteractive(stack); - } - else - { - __focus.__getInteractive(stack); - } - - var event = new TextEvent(TextEvent.TEXT_INPUT, true, true, text); - if (stack.length > 0) - { - stack.reverse(); - __dispatchStack(event, stack); - } - else - { - __dispatchEvent(event); - } - - if (event.isDefaultPrevented()) - { - window.onTextInput.cancel(); - } - } - - @:noCompletion private function __onLimeTouchCancel(touch:Touch):Void - { - // TODO: Should we handle this differently? - var isPrimaryTouchPoint = __primaryTouch == touch; - if (isPrimaryTouchPoint) - { - __primaryTouch = null; - } - - __onTouch(TouchEvent.TOUCH_END, touch, isPrimaryTouchPoint); - } - - @:noCompletion private function __onLimeTouchMove(touch:Touch):Void - { - __onTouch(TouchEvent.TOUCH_MOVE, touch, __primaryTouch == touch); - } - - @:noCompletion private function __onLimeTouchEnd(touch:Touch):Void - { - var isPrimaryTouchPoint = __primaryTouch == touch; - if (isPrimaryTouchPoint) - { - __primaryTouch = null; - } - - __onTouch(TouchEvent.TOUCH_END, touch, isPrimaryTouchPoint); - } - - @:noCompletion private function __onLimeTouchStart(touch:Touch):Void - { - if (__primaryTouch == null) - { - __primaryTouch = touch; - } - - __onTouch(TouchEvent.TOUCH_BEGIN, touch, __primaryTouch == touch); - } - - @:noCompletion private function __onLimeUpdate(deltaTime:Float):Void - { - __deltaTime = deltaTime; - - __dispatchPendingMouseEvent(); - } - - @:noCompletion private function __onLimeWindowActivate(window:Window):Void - { - if (this.window == null || this.window != window) return; - - // __broadcastEvent (new Event (Event.ACTIVATE)); - } - - @:noCompletion private function __onLimeWindowClose(window:Window):Void - { - if (this.window == window) - { - this.window = null; - } - - __primaryTouch = null; - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.DEACTIVATE; - #else - event = new Event(Event.DEACTIVATE); - #end - - __broadcastEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - - @:noCompletion private function __onLimeWindowCreate(window:Window):Void - { - if (this.window == null || this.window != window) return; - - if (window.context != null) - { - __createRenderer(); - } - } - - @:noCompletion private function __onLimeWindowDeactivate(window:Window):Void - { - if (this.window == null || this.window != window) return; - - // __primaryTouch = null; - // __broadcastEvent (new Event (Event.DEACTIVATE)); - } - - @:noCompletion private function __onLimeWindowDropFile(window:Window, file:String):Void {} - - @:noCompletion private function __onLimeWindowEnter(window:Window):Void - { - // if (this.window == null || this.window != window) return; - } - - @:noCompletion private function __onLimeWindowExpose(window:Window):Void - { - if (this.window == null || this.window != window) return; - - __renderDirty = true; - } - - @:noCompletion private function __onLimeWindowFocusIn(window:Window):Void - { - if (this.window == null || this.window != window) return; - - #if !desktop - // TODO: Is this needed? - __renderDirty = true; - #end - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.ACTIVATE; - #else - event = new Event(Event.ACTIVATE); - #end - - __broadcastEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - - #if !desktop - focus = __cacheFocus; - #end - } - - @:noCompletion private function __onLimeWindowFocusOut(window:Window):Void - { - if (this.window == null || this.window != window) return; - - __primaryTouch = null; - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.DEACTIVATE; - #else - event = new Event(Event.DEACTIVATE); - #end - - __broadcastEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - - var currentFocus = focus; - focus = null; - __cacheFocus = currentFocus; - - MouseEvent.__altKey = false; - MouseEvent.__commandKey = false; - MouseEvent.__ctrlKey = false; - MouseEvent.__shiftKey = false; - } - - @:noCompletion private function __onLimeWindowFullscreen(window:Window):Void - { - if (this.window == null || this.window != window) return; - - __resize(); - - if (!__wasFullscreen) - { - __wasFullscreen = true; - if (__displayState == NORMAL) __displayState = FULL_SCREEN_INTERACTIVE; - __dispatchEvent(new FullScreenEvent(FullScreenEvent.FULL_SCREEN, false, false, true, true)); - } - } - - @:noCompletion private function __onLimeWindowLeave(window:Window):Void - { - if (this.window == null || this.window != window || MouseEvent.__buttonDown) return; - - __dispatchPendingMouseEvent(); - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.MOUSE_LEAVE; - #else - event = new Event(Event.MOUSE_LEAVE); - #end - - __dispatchEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - - @:noCompletion private function __onLimeWindowMinimize(window:Window):Void - { - if (this.window == null || this.window != window) return; - - // __primaryTouch = null; - // __broadcastEvent (new Event (Event.DEACTIVATE)); - } - - @:noCompletion private function __onLimeWindowMove(window:Window, x:Float, y:Float):Void - { - // if (this.window == null || this.window != window) return; - } - - @:noCompletion private function __onLimeWindowResize(window:Window, width:Int, height:Int):Void - { - if (this.window == null || this.window != window) return; - - __resize(); - - #if android - // workaround for newer behavior - __forceRender = true; - Lib.setTimeout(function() - { - __forceRender = false; - }, 500); - #end - - if (__wasFullscreen && !window.fullscreen) - { - __wasFullscreen = false; - __displayState = NORMAL; - __dispatchEvent(new FullScreenEvent(FullScreenEvent.FULL_SCREEN, false, false, false, true)); - } - } - - @:noCompletion private function __onLimeWindowRestore(window:Window):Void - { - if (this.window == null || this.window != window) return; - - if (__wasFullscreen && !window.fullscreen) - { - __wasFullscreen = false; - __displayState = NORMAL; - __dispatchEvent(new FullScreenEvent(FullScreenEvent.FULL_SCREEN, false, false, false, true)); - } - } - #end - - @:noCompletion private function __onMouse(type:String, x:Float, y:Float, button:Int):Void - { - if (button > 2) return; - - var targetPoint = Point.__pool.get(); - targetPoint.setTo(x, y); - __displayMatrix.__transformInversePoint(targetPoint); - - __mouseX = targetPoint.x; - __mouseY = targetPoint.y; - - var stack = []; - var target:InteractiveObject = null; - - if (__hitTest(__mouseX, __mouseY, true, stack, true, this)) - { - target = cast stack[stack.length - 1]; - } - else - { - target = this; - stack = [this]; - } - - if (target == null) target = this; - - var clickType = null; - - switch (type) - { - case MouseEvent.MOUSE_DOWN: - if (focus != null) - { - if (focus != target) - { - var focusEvent = new FocusEvent(FocusEvent.MOUSE_FOCUS_CHANGE, true, true, target, false, 0); - focus.dispatchEvent(focusEvent); - - if (!focusEvent.isDefaultPrevented()) - { - if (target.__allowMouseFocus()) - { - focus = target; - } - else - { - focus = null; - } - } - } - } - else - { - if (target.__allowMouseFocus()) - { - focus = target; - } - else - { - focus = null; - } - } - - __mouseDownLeft = target; - MouseEvent.__buttonDown = true; - - case MouseEvent.MIDDLE_MOUSE_DOWN: - __mouseDownMiddle = target; - - case MouseEvent.RIGHT_MOUSE_DOWN: - __mouseDownRight = target; - - case MouseEvent.MOUSE_UP: - if (__mouseDownLeft != null) - { - MouseEvent.__buttonDown = false; - - if (__mouseDownLeft == target) - { - clickType = MouseEvent.CLICK; - } - else - { - var event:MouseEvent = null; - - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = MouseEvent.RELEASE_OUTSIDE; - event.stageX = __mouseX; - event.stageY = __mouseY; - event.localX = __mouseX; - event.localY = __mouseY; - event.target = this; - #else - event = MouseEvent.__create(MouseEvent.RELEASE_OUTSIDE, 1, __mouseX, __mouseY, new Point(__mouseX, __mouseY), this); - #end - - __mouseDownLeft.dispatchEvent(event); - - #if openfl_pool_events - MouseEvent.__pool.release(event); - #end - } - - __mouseDownLeft = null; - } - - case MouseEvent.MIDDLE_MOUSE_UP: - if (__mouseDownMiddle == target) - { - clickType = MouseEvent.MIDDLE_CLICK; - } - - __mouseDownMiddle = null; - - case MouseEvent.RIGHT_MOUSE_UP: - if (__mouseDownRight == target) - { - clickType = MouseEvent.RIGHT_CLICK; - } - - __mouseDownRight = null; - - default: - } - - var localPoint = Point.__pool.get(); - var event:MouseEvent = null; - - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = type; - event.stageX = __mouseX; - event.stageY = __mouseY; - var local = target.__globalToLocal(targetPoint, localPoint); - event.localX = local.x; - event.localY = local.y; - event.target = target; - #else - event = MouseEvent.__create(type, button, __mouseX, __mouseY, target.__globalToLocal(targetPoint, localPoint), target); - #end - - __dispatchStack(event, stack); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(event); - #end - - if (clickType != null) - { - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = clickType; - event.stageX = __mouseX; - event.stageY = __mouseY; - var local = target.__globalToLocal(targetPoint, localPoint); - event.localX = local.x; - event.localY = local.y; - event.target = target; - #else - event = MouseEvent.__create(clickType, button, __mouseX, __mouseY, target.__globalToLocal(targetPoint, localPoint), target); - #end - - __dispatchStack(event, stack); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(event); - #end - - if (type == MouseEvent.MOUSE_UP && target.doubleClickEnabled) - { - var currentTime = Lib.getTimer(); - if (currentTime - __lastClickTime < 500 && target == __lastClickTarget) - { - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = MouseEvent.DOUBLE_CLICK; - event.stageX = __mouseX; - event.stageY = __mouseY; - var local = target.__globalToLocal(targetPoint, localPoint); - event.localX = local.x; - event.localY = local.y; - event.target = target; - #else - event = MouseEvent.__create(MouseEvent.DOUBLE_CLICK, button, __mouseX, __mouseY, target.__globalToLocal(targetPoint, localPoint), target); - #end - - __dispatchStack(event, stack); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(event); - #end - - __lastClickTime = 0; - __lastClickTarget = null; - } - else - { - __lastClickTarget = target; - __lastClickTime = currentTime; - } - } - } - - if (Mouse.__cursor == MouseCursor.AUTO && !Mouse.__hidden) - { - var cursor = null; - - if (__mouseDownLeft != null) - { - cursor = __mouseDownLeft.__getCursor(); - } - else - { - for (target in stack) - { - cursor = target.__getCursor(); - - if (cursor != null && window != null) - { - window.cursor = cursor; - break; - } - } - } - - if (cursor == null && window != null) - { - window.cursor = ARROW; - } - } - - var event; - - if (target != __mouseOverTarget) - { - if (__mouseOverTarget != null) - { - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = MouseEvent.MOUSE_OUT; - event.stageX = __mouseX; - event.stageY = __mouseY; - var local = __mouseOverTarget.__globalToLocal(targetPoint, localPoint); - event.localX = local.x; - event.localY = local.y; - event.target = __mouseOverTarget; - #else - event = MouseEvent.__create(MouseEvent.MOUSE_OUT, button, __mouseX, __mouseY, __mouseOverTarget.__globalToLocal(targetPoint, localPoint), - cast __mouseOverTarget); - #end - - __dispatchStack(event, __mouseOutStack); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(cast event); - #end - } - } - - var item, i = 0; - while (i < __rollOutStack.length) - { - item = __rollOutStack[i]; - if (stack.indexOf(item) == -1) - { - __rollOutStack.remove(item); - - #if openfl_pool_events - event = MouseEvent.__pool.get(); - event.type = MouseEvent.ROLL_OUT; - event.stageX = __mouseX; - event.stageY = __mouseY; - var local = __mouseOverTarget.__globalToLocal(targetPoint, localPoint); - event.localX = local.x; - event.localY = local.y; - event.target = item; - #else - event = MouseEvent.__create(MouseEvent.ROLL_OUT, button, __mouseX, __mouseY, __mouseOverTarget.__globalToLocal(targetPoint, localPoint), - cast item); - #end - event.bubbles = false; - - __dispatchTarget(item, event); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(cast event); - #end - } - else - { - i++; - } - } - - for (item in stack) - { - if (__rollOutStack.indexOf(item) == -1 && __mouseOverTarget != null) - { - if (item.hasEventListener(MouseEvent.ROLL_OVER)) - { - #if openfl_pool_events - var mouseEvent = MouseEvent.__pool.get(); - mouseEvent.type = MouseEvent.ROLL_OVER; - mouseEvent.stageX = __mouseX; - mouseEvent.stageY = __mouseY; - var local = __mouseOverTarget.__globalToLocal(targetPoint, localPoint); - mouseEvent.localX = local.x; - mouseEvent.localY = local.y; - mouseEvent.target = item; - event = mouseEvent; - #else - event = MouseEvent.__create(MouseEvent.ROLL_OVER, button, __mouseX, __mouseY, __mouseOverTarget.__globalToLocal(targetPoint, localPoint), - cast item); - #end - event.bubbles = false; - - __dispatchTarget(item, event); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(cast event); - #end - } - - if (item.hasEventListener(MouseEvent.ROLL_OUT) || item.hasEventListener(MouseEvent.ROLL_OVER)) - { - __rollOutStack.push(item); - } - } - } - - if (target != __mouseOverTarget) - { - if (target != null) - { - #if openfl_pool_events - var mouseEvent = MouseEvent.__pool.get(); - mouseEvent.type = MouseEvent.MOUSE_OVER; - mouseEvent.stageX = __mouseX; - mouseEvent.stageY = __mouseY; - var local = target.__globalToLocal(targetPoint, localPoint); - mouseEvent.localX = local.x; - mouseEvent.localY = local.y; - mouseEvent.target = target; - event = mouseEvent; - #else - event = MouseEvent.__create(MouseEvent.MOUSE_OVER, button, __mouseX, __mouseY, target.__globalToLocal(targetPoint, localPoint), cast target); - #end - - __dispatchStack(event, stack); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - #if openfl_pool_events - MouseEvent.__pool.release(cast event); - #end - } - - __mouseOverTarget = target; - __mouseOutStack = stack; - } - - if (__dragObject != null) - { - __drag(targetPoint); - - var dropTarget = null; - - if (__mouseOverTarget == __dragObject) - { - var cacheMouseEnabled = __dragObject.mouseEnabled; - var cacheMouseChildren = __dragObject.mouseChildren; - - __dragObject.mouseEnabled = false; - __dragObject.mouseChildren = false; - - var stack = []; - - if (__hitTest(__mouseX, __mouseY, true, stack, true, this)) - { - dropTarget = stack[stack.length - 1]; - } - - __dragObject.mouseEnabled = cacheMouseEnabled; - __dragObject.mouseChildren = cacheMouseChildren; - } - else if (__mouseOverTarget != this) - { - dropTarget = __mouseOverTarget; - } - - __dragObject.dropTarget = dropTarget; - } - - Point.__pool.release(targetPoint); - Point.__pool.release(localPoint); - } - - #if lime - @:noCompletion private function __onMouseWheel(deltaX:Float, deltaY:Float, deltaMode:MouseWheelMode):Void - { - var x = __mouseX; - var y = __mouseY; - - var stack = []; - var target:InteractiveObject = null; - - if (__hitTest(__mouseX, __mouseY, true, stack, true, this)) - { - target = cast stack[stack.length - 1]; - } - else - { - target = this; - stack = [this]; - } - - if (target == null) target = this; - var targetPoint = Point.__pool.get(); - targetPoint.setTo(x, y); - __displayMatrix.__transformInversePoint(targetPoint); - var delta = Std.int(deltaY); - - var event = MouseEvent.__create(MouseEvent.MOUSE_WHEEL, 0, __mouseX, __mouseY, target.__globalToLocal(targetPoint, targetPoint), target, delta); - event.cancelable = true; - __dispatchStack(event, stack); - if (event.isDefaultPrevented()) window.onMouseWheel.cancel(); - - if (event.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - Point.__pool.release(targetPoint); - } - #end - - #if lime - @:noCompletion private function __onTouch(type:String, touch:Touch, isPrimaryTouchPoint:Bool):Void - { - var targetPoint = Point.__pool.get(); - targetPoint.setTo(Math.round(touch.x * window.width * window.scale), Math.round(touch.y * window.height * window.scale)); - __displayMatrix.__transformInversePoint(targetPoint); - - var touchX = targetPoint.x; - var touchY = targetPoint.y; - - var stack = []; - var target:InteractiveObject = null; - - if (__hitTest(touchX, touchY, false, stack, true, this)) - { - target = cast stack[stack.length - 1]; - } - else - { - target = this; - stack = [this]; - } - - if (target == null) target = this; - - var touchId:Int = touch.id; - var touchData:TouchData = null; - - if (__touchData.exists(touchId)) - { - touchData = __touchData.get(touchId); - } - else - { - touchData = TouchData.__pool.get(); - touchData.reset(); - touchData.touch = touch; - __touchData.set(touchId, touchData); - } - - var touchType = null; - var releaseTouchData:Bool = false; - - switch (type) - { - case TouchEvent.TOUCH_BEGIN: - touchData.touchDownTarget = target; - - case TouchEvent.TOUCH_END: - if (touchData.touchDownTarget == target) - { - touchType = TouchEvent.TOUCH_TAP; - } - - touchData.touchDownTarget = null; - releaseTouchData = true; - - default: - } - - var localPoint = Point.__pool.get(); - var touchEvent = TouchEvent.__create(type, null, touchX, touchY, target.__globalToLocal(targetPoint, localPoint), cast target); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.pressure = touch.pressure; - - __dispatchStack(touchEvent, stack); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - - if (touchType != null) - { - touchEvent = TouchEvent.__create(touchType, null, touchX, touchY, target.__globalToLocal(targetPoint, localPoint), cast target); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.pressure = touch.pressure; - - __dispatchStack(touchEvent, stack); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - - var touchOverTarget = touchData.touchOverTarget; - - if (target != touchOverTarget && touchOverTarget != null) - { - touchEvent = TouchEvent.__create(TouchEvent.TOUCH_OUT, null, touchX, touchY, touchOverTarget.__globalToLocal(targetPoint, localPoint), - cast touchOverTarget); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.pressure = touch.pressure; - - __dispatchTarget(touchOverTarget, touchEvent); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - - var touchOutStack = touchData.rollOutStack; - var item, i = 0; - while (i < touchOutStack.length) - { - item = touchOutStack[i]; - if (stack.indexOf(item) == -1) - { - touchOutStack.remove(item); - - touchEvent = TouchEvent.__create(TouchEvent.TOUCH_ROLL_OUT, null, touchX, touchY, touchOverTarget.__globalToLocal(targetPoint, localPoint), - cast touchOverTarget); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.bubbles = false; - touchEvent.pressure = touch.pressure; - - __dispatchTarget(item, touchEvent); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - else - { - i++; - } - } - - for (item in stack) - { - if (touchOutStack.indexOf(item) == -1) - { - if (item.hasEventListener(TouchEvent.TOUCH_ROLL_OVER)) - { - touchEvent = TouchEvent.__create(TouchEvent.TOUCH_ROLL_OVER, null, touchX, touchY, - touchOverTarget.__globalToLocal(targetPoint, localPoint), cast item); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.bubbles = false; - touchEvent.pressure = touch.pressure; - - __dispatchTarget(item, touchEvent); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - - if (item.hasEventListener(TouchEvent.TOUCH_ROLL_OUT)) - { - touchOutStack.push(item); - } - } - } - - if (target != touchOverTarget) - { - if (target != null) - { - touchEvent = TouchEvent.__create(TouchEvent.TOUCH_OVER, null, touchX, touchY, target.__globalToLocal(targetPoint, localPoint), cast target); - touchEvent.touchPointID = touchId; - touchEvent.isPrimaryTouchPoint = isPrimaryTouchPoint; - touchEvent.bubbles = true; - touchEvent.pressure = touch.pressure; - - __dispatchTarget(target, touchEvent); - - if (touchEvent.__updateAfterEventFlag) - { - __renderAfterEvent(); - } - } - - touchData.touchOverTarget = target; - } - - Point.__pool.release(targetPoint); - Point.__pool.release(localPoint); - - if (releaseTouchData) - { - __touchData.remove(touchId); - touchData.reset(); - TouchData.__pool.release(touchData); - } - } - #end - - #if lime - @:noCompletion private function __registerLimeModule(application:Application):Void - { - application.onCreateWindow.add(__onLimeCreateWindow); - application.onUpdate.add(__onLimeUpdate); - application.onExit.add(__onLimeModuleExit, false, 0); - - for (gamepad in Gamepad.devices) - { - __onLimeGamepadConnect(gamepad); - } - - Gamepad.onConnect.add(__onLimeGamepadConnect); - Touch.onStart.add(__onLimeTouchStart); - Touch.onMove.add(__onLimeTouchMove); - Touch.onEnd.add(__onLimeTouchEnd); - Touch.onCancel.add(__onLimeTouchCancel); - } - #end - - @:noCompletion private function __resize():Void - { - var cacheWidth = stageWidth; - var cacheHeight = stageHeight; - - var windowWidth = Std.int(window.width * window.scale); - var windowHeight = Std.int(window.height * window.scale); - - __displayMatrix.identity(); - - // Assuming `fullScreenSourceRect` ignores `stageScaleMode` - - if (fullScreenSourceRect != null && window.fullscreen) - { - // Should stageWidth / stageHeight be changed? - - stageWidth = Std.int(fullScreenSourceRect.width); - stageHeight = Std.int(fullScreenSourceRect.height); - - var displayScaleX = windowWidth / stageWidth; - var displayScaleY = windowHeight / stageHeight; - - __displayMatrix.translate(-fullScreenSourceRect.x, -fullScreenSourceRect.y); - __displayMatrix.scale(displayScaleX, displayScaleY); - - __displayRect.setTo(fullScreenSourceRect.left, fullScreenSourceRect.right, fullScreenSourceRect.top, fullScreenSourceRect.bottom); - } - else - { - if (__logicalWidth == 0 || __logicalHeight == 0 || scaleMode == NO_SCALE || windowWidth == 0 || windowHeight == 0) - { - #if openfl_dpi_aware - stageWidth = windowWidth; - stageHeight = windowHeight; - #else - stageWidth = Math.round(windowWidth / window.scale); - stageHeight = Math.round(windowHeight / window.scale); - - __displayMatrix.scale(window.scale, window.scale); - #end - - __displayRect.setTo(0, 0, stageWidth, stageHeight); - } - else - { - stageWidth = __logicalWidth; - stageHeight = __logicalHeight; - - switch (scaleMode) - { - case EXACT_FIT: - var displayScaleX = windowWidth / stageWidth; - var displayScaleY = windowHeight / stageHeight; - - __displayMatrix.scale(displayScaleX, displayScaleY); - __displayRect.setTo(0, 0, stageWidth, stageHeight); - - case NO_BORDER: - var scaleX = windowWidth / stageWidth; - var scaleY = windowHeight / stageHeight; - - var scale = Math.max(scaleX, scaleY); - - var scaledWidth = stageWidth * scale; - var scaledHeight = stageHeight * scale; - - var visibleWidth = stageWidth - Math.round((scaledWidth - windowWidth) / scale); - var visibleHeight = stageHeight - Math.round((scaledHeight - windowHeight) / scale); - var visibleX = Math.round((stageWidth - visibleWidth) / 2); - var visibleY = Math.round((stageHeight - visibleHeight) / 2); - - __displayMatrix.translate(-visibleX, -visibleY); - __displayMatrix.scale(scale, scale); - - __displayRect.setTo(visibleX, visibleY, visibleWidth, visibleHeight); - - default: // SHOW_ALL - - var scaleX = windowWidth / stageWidth; - var scaleY = windowHeight / stageHeight; - - var scale = Math.min(scaleX, scaleY); - - var scaledWidth = stageWidth * scale; - var scaledHeight = stageHeight * scale; - - var visibleWidth = stageWidth - Math.round((scaledWidth - windowWidth) / scale); - var visibleHeight = stageHeight - Math.round((scaledHeight - windowHeight) / scale); - var visibleX = Math.round((stageWidth - visibleWidth) / 2); - var visibleY = Math.round((stageHeight - visibleHeight) / 2); - - __displayMatrix.translate(-visibleX, -visibleY); - __displayMatrix.scale(scale, scale); - - __displayRect.setTo(visibleX, visibleY, visibleWidth, visibleHeight); - } - } - } - - if (context3D != null) - { - #if openfl_dpi_aware - context3D.configureBackBuffer(windowWidth, windowHeight, 0, true, true, true); - #else - context3D.configureBackBuffer(stageWidth, stageHeight, 0, true, true, true); - #end - } - - for (stage3D in stage3Ds) - { - stage3D.__resize(windowWidth, windowHeight); - } - - if (__renderer != null) - { - __renderer.__resize(windowWidth, windowHeight); - } - - __renderDirty = true; - - if (stageWidth != cacheWidth || stageHeight != cacheHeight) - { - __setTransformDirty(); - - var event:Event = null; - - #if openfl_pool_events - event = Event.__pool.get(); - event.type = Event.RESIZE; - #else - event = new Event(Event.RESIZE); - #end - - __dispatchEvent(event); - - #if openfl_pool_events - Event.__pool.release(event); - #end - } - } - - @:noCompletion private function __setLogicalSize(width:Int, height:Int):Void - { - __logicalWidth = width; - __logicalHeight = height; - - __resize(); - } - - @:noCompletion private function __startDrag(sprite:Sprite, lockCenter:Bool, bounds:Rectangle):Void - { - if (bounds == null) - { - __dragBounds = null; - } - else - { - __dragBounds = new Rectangle(); - - var right = bounds.right; - var bottom = bounds.bottom; - __dragBounds.x = right < bounds.x ? right : bounds.x; - __dragBounds.y = bottom < bounds.y ? bottom : bounds.y; - __dragBounds.width = Math.abs(bounds.width); - __dragBounds.height = Math.abs(bounds.height); - } - - __dragObject = sprite; - - if (__dragObject != null) - { - if (lockCenter) - { - __dragOffsetX = 0; - __dragOffsetY = 0; - } - else - { - var mouse = Point.__pool.get(); - mouse.setTo(mouseX, mouseY); - var parent = __dragObject.parent; - - if (parent != null) - { - parent.__getWorldTransform().__transformInversePoint(mouse); - } - - __dragOffsetX = __dragObject.x - mouse.x; - __dragOffsetY = __dragObject.y - mouse.y; - Point.__pool.release(mouse); - } - } - } - - @:noCompletion private function __stopDrag(sprite:Sprite):Void - { - __dragBounds = null; - __dragObject = null; - } - - @:noCompletion private function __unregisterLimeModule(application:Application):Void - { - #if lime - application.onCreateWindow.remove(__onLimeCreateWindow); - application.onUpdate.remove(__onLimeUpdate); - application.onExit.remove(__onLimeModuleExit); - - Gamepad.onConnect.remove(__onLimeGamepadConnect); - Touch.onStart.remove(__onLimeTouchStart); - Touch.onMove.remove(__onLimeTouchMove); - Touch.onEnd.remove(__onLimeTouchEnd); - Touch.onCancel.remove(__onLimeTouchCancel); - #end - } - - @:noCompletion private override function __update(transformOnly:Bool, updateChildren:Bool):Void - { - if (transformOnly) - { - if (__transformDirty) - { - super.__update(true, updateChildren); - - if (updateChildren) - { - __transformDirty = false; - // __dirty = true; - } - } - } - else - { - if (__transformDirty || __renderDirty) - { - super.__update(false, updateChildren); - - if (updateChildren) - { - // #if dom - if (DisplayObject.__supportDOM) - { - __wasDirty = true; - } - - // #end - - // __dirty = false; - } - } - /* - #if dom - **/ - else if (!__renderDirty && __wasDirty) - { - // If we were dirty last time, we need at least one more - // update in order to clear "changed" properties - - super.__update(false, updateChildren); - - if (updateChildren) - { - __wasDirty = false; - } - } - /* - #end - **/ - } - } - - // Get & Set Methods - @:noCompletion private function get_color():Null - { - return __color; - } - - @:noCompletion private function set_color(value:Null):Null - { - if (value == null) - { - __transparent = true; - value = 0x000000; - } - else - { - __transparent = false; - } - - if (__color != value) - { - var r = (value & 0xFF0000) >>> 16; - var g = (value & 0x00FF00) >>> 8; - var b = (value & 0x0000FF); - - __colorSplit[0] = r / 0xFF; - __colorSplit[1] = g / 0xFF; - __colorSplit[2] = b / 0xFF; - __colorString = "#" + StringTools.hex(value & 0xFFFFFF, 6); - __renderDirty = true; - __color = (0xFF << 24) | (value & 0xFFFFFF); - } - - return value; - } - - @:noCompletion private function get_contentsScaleFactor():Float - { - return __contentsScaleFactor; - } - - @:noCompletion private function get_displayState():StageDisplayState - { - return __displayState; - } - - @:noCompletion private function set_displayState(value:StageDisplayState):StageDisplayState - { - if (window != null) - { - switch (value) - { - case NORMAL: - if (window.fullscreen) - { - // window.minimized = false; - window.fullscreen = false; - } - - default: - if (!window.fullscreen) - { - // window.minimized = false; - window.fullscreen = true; - } - } - } - - return __displayState = value; - } - - @:noCompletion private function get_focus():InteractiveObject - { - return __focus; - } - - @:noCompletion private function set_focus(value:InteractiveObject):InteractiveObject - { - if (value != __focus) - { - var oldFocus = __focus; - __focus = value; - __cacheFocus = value; - - if (oldFocus != null) - { - var event = new FocusEvent(FocusEvent.FOCUS_OUT, true, false, value, false, 0); - var stack = new Array(); - oldFocus.__getInteractive(stack); - stack.reverse(); - __dispatchStack(event, stack); - } - - if (value != null) - { - var event = new FocusEvent(FocusEvent.FOCUS_IN, true, false, oldFocus, false, 0); - var stack = new Array(); - value.__getInteractive(stack); - stack.reverse(); - __dispatchStack(event, stack); - } - } - - return value; - } - - @:noCompletion private function get_frameRate():Float - { - if (window != null) - { - return window.frameRate; - } - - return 0; - } - - @:noCompletion private function set_frameRate(value:Float):Float - { - if (window != null) - { - return window.frameRate = value; - } - - return value; - } - - @:noCompletion private function get_fullScreenHeight():UInt - { - return Math.ceil(window.display.currentMode.height * window.scale); - } - - @:noCompletion private function get_fullScreenSourceRect():Rectangle - { - return __fullScreenSourceRect == null ? null : __fullScreenSourceRect.clone(); - } - - @:noCompletion private function set_fullScreenSourceRect(value:Rectangle):Rectangle - { - if (value == null) - { - if (__fullScreenSourceRect != null) - { - __fullScreenSourceRect = null; - __resize(); - } - } - else if (!value.equals(__fullScreenSourceRect)) - { - __fullScreenSourceRect = value.clone(); - __resize(); - } - - return value; - } - - @:noCompletion private function get_fullScreenWidth():UInt - { - return Math.ceil(window.display.currentMode.width * window.scale); - } - - @:noCompletion private override function set_height(value:Float):Float - { - return this.height; - } - - @:noCompletion private override function get_mouseX():Float - { - return __mouseX; - } - - @:noCompletion private override function get_mouseY():Float - { - return __mouseY; - } - - @:noCompletion private function get_quality():StageQuality - { - return __quality; - } - - @:noCompletion private function set_quality(value:StageQuality):StageQuality - { - __quality = value; - - if (__renderer != null) - { - __renderer.__allowSmoothing = (quality != LOW); - } - - return value; - } - - @:noCompletion private override function set_rotation(value:Float):Float - { - return 0; - } - - @:noCompletion private function get_scaleMode():StageScaleMode - { - return __scaleMode; - } - - @:noCompletion private function set_scaleMode(value:StageScaleMode):StageScaleMode - { - if (value != __scaleMode) - { - __scaleMode = value; - __resize(); - } - - return value; - } - - @:noCompletion private override function set_scaleX(value:Float):Float - { - return 0; - } - - @:noCompletion private override function set_scaleY(value:Float):Float - { - return 0; - } - - @:noCompletion private override function get_tabEnabled():Bool - { - return false; - } - - @:noCompletion private override function set_tabEnabled(value:Bool):Bool - { - throw new IllegalOperationError("Error: The Stage class does not implement this property or method."); - } - - @:noCompletion private override function get_tabIndex():Int - { - return -1; - } - - @:noCompletion private override function set_tabIndex(value:Int):Int - { - throw new IllegalOperationError("Error: The Stage class does not implement this property or method."); - } - - @:noCompletion private override function set_transform(value:Transform):Transform - { - return this.transform; - } - - @:noCompletion private override function set_width(value:Float):Float - { - return this.width; - } - - @:noCompletion private override function set_x(value:Float):Float - { - return 0; - } - - @:noCompletion private override function set_y(value:Float):Float - { - return 0; - } -} -#else -typedef Stage = flash.display.Stage; -#end diff --git a/source/openfl/display/Tilemap.hx b/source/openfl/display/Tilemap.hx deleted file mode 100644 index 00e20ac6b9c..00000000000 --- a/source/openfl/display/Tilemap.hx +++ /dev/null @@ -1,514 +0,0 @@ -package openfl.display; - -import openfl.display._internal.FlashRenderer; -import openfl.display._internal.FlashTilemap; -import openfl.geom.Matrix; -import openfl.geom.Rectangle; -#if !flash -import openfl.display._internal.Context3DBuffer; -#end - -/** - The Tilemap class represents a "quad batch", or series of objects that are - rendered from the same bitmap. The Tilemap class is designed to encourage - the use of a single Tileset reference for best performance, but it is possible - to use unique Tileset references for each Tile or TileContainer within a - Tilemap. - - On software renderered platforms, the Tilemap class uses a rendering method - similar to BitmapData `copyPixels`, so it will perform fastest if tile objects - do not use rotation or scale. - - On hardware rendered platforms, the Tilemap class uses a rendering method - that is fast even with transforms, and allows support for additional features, - such as custom `shader` references, and color transform. Using multiple Shader - or Tileset references will require a new draw call each time there is a change. - - **Note:** The Tilemap class is not a subclass of the InteractiveObject - class, so it cannot dispatch mouse events. However, you can use the - `addEventListener()` method of the display object container that - contains the Tilemap object. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display.Tile) -@:access(openfl.geom.ColorTransform) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Rectangle) -class Tilemap extends #if !flash DisplayObject #else Bitmap implements IDisplayObject #end implements ITileContainer -{ - /** - Returns the number of tiles of this object. - **/ - public var numTiles(get, never):Int; - - /** - Enable or disable support for the `alpha` property of contained tiles. Disabling - this property can improve performance on certain renderers. - **/ - public var tileAlphaEnabled:Bool; - - /** - Enable or disable support for the `blendMode` property of contained tiles. - Disabling this property can improve performance on certain renderers. - **/ - public var tileBlendModeEnabled:Bool; - - /** - Enable or disable support for the `colorTransform` property of contained tiles. - Disabling this property can improve performance on certain renderers. - **/ - public var tileColorTransformEnabled:Bool; - - /** - Optionally define a default Tileset to be used for all contained tiles. Tile - instances that do not have their `tileset` property defined will use this value. - - If a Tile object does not have a Tileset set, either using this property or using - the Tile `tileset` property, it will not be rendered. - **/ - public var tileset(get, set):Tileset; - - #if !flash - /** - Controls whether or not the tilemap is smoothed when scaled. If - `true`, the bitmap is smoothed when scaled. If `false`, the tilemap is not - smoothed when scaled. - **/ - public var smoothing:Bool; - #end - - @:noCompletion private var __group:TileContainer; - @:noCompletion private var __tileset:Tileset; - #if !flash - @:noCompletion private var __buffer:Context3DBuffer; - @:noCompletion private var __bufferDirty:Bool; - @:noCompletion private var __height:Int; - @:noCompletion private var __width:Int; - #end - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(Tilemap.prototype, { - "numTiles": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_numTiles (); }")}, - "tileset": { - get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_tileset (); }"), - set: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function (v) { return this.set_tileset (v); }") - } - }); - } - #end - - /** - Creates a new Tilemap object. - - @param width The width of the tilemap in pixels. - @param height The height of the tilemap in pixels. - @param tileset A Tileset being referenced. - @param smoothing Whether or not the tilemap is smoothed when scaled. For example, the following examples - show the same tilemap scaled by a factor of 3, with `smoothing` set to `false` (left) and `true` (right): - - ![A bitmap without smoothing.](/images/bitmap_smoothing_off.jpg) ![A bitmap with smoothing.](/images/bitmap_smoothing_on.jpg) - **/ - public function new(width:Int, height:Int, tileset:Tileset = null, smoothing:Bool = true) - { - super(); - - #if !flash - __drawableType = TILEMAP; - #end - __tileset = tileset; - this.smoothing = smoothing; - - tileAlphaEnabled = true; - tileBlendModeEnabled = true; - tileColorTransformEnabled = true; - - __group = new TileContainer(); - __group.tileset = tileset; - #if !flash - __width = width; - __height = height; - #else - bitmapData = new BitmapData(width, height, true, 0); - this.smoothing = smoothing; - FlashRenderer.register(this); - #end - } - - /** - Adds a Tile instance to this Tilemap instance. The tile is - added to the front (top) of all other tiles in this Tilemap - instance. (To add a tile to a specific index position, use the `addTileAt()` - method.) - - @param tile The Tile instance to add to this Tilemap instance. - @return The Tile instance that you pass in the `tile` parameter. - **/ - public function addTile(tile:Tile):Tile - { - return __group.addTile(tile); - } - - /** - Adds a Tile instance to this Tilemap instance. The tile is added - at the index position specified. An index of 0 represents the back (bottom) - of the rendered list for this Tilemap object. - - For example, the following example shows three tiles, labeled - a, b, and c, at index positions 0, 2, and 1, respectively: - - ![b over c over a](/images/DisplayObjectContainer_layers.jpg) - - @param tile The Tile instance to add to this Tilemap instance. - @param index The index position to which the tile is added. If you - specify a currently occupied index position, the tile object - that exists at that position and all higher positions are - moved up one position in the tile list. - @return The Tile instance that you pass in the `tile` parameter. - **/ - public function addTileAt(tile:Tile, index:Int):Tile - { - return __group.addTileAt(tile, index); - } - - /** - Adds an Array of Tile instances to this Tilemap instance. The tiles - are added to the front (top) of all other tiles in this Tilemap - instance. - - @param tiles The Tile instances to add to this Tilemap instance. - @return The Tile Array that you pass in the `tiles` parameter. - **/ - public function addTiles(tiles:Array):Array - { - return __group.addTiles(tiles); - } - - /** - Determines whether the specified tile is contained within the - Tilemap instance. The search includes the entire tile list including - this Tilemap instance. Grandchildren, great-grandchildren, and so on - each return `true`. - - @param tile The tile object to test. - @return `true` if the `tile` object is contained within the Tilemap; - otherwise `false`. - **/ - public function contains(tile:Tile):Bool - { - return __group.contains(tile); - } - - /** - Returns the tile instance that exists at the specified index. - - @param index The index position of the tile object. - @return The tile object at the specified index position. - **/ - public function getTileAt(index:Int):Tile - { - return __group.getTileAt(index); - } - - /** - Returns the index position of a contained Tile instance. - - @param child The Tile instance to identify. - @return The index position of the tile object to identify. - **/ - public function getTileIndex(tile:Tile):Int - { - return __group.getTileIndex(tile); - } - - /** - Returns a TileContainer with each of the tiles contained within this - Tilemap. - - @return A new TileContainer with the same Tile references as this Tilemap - **/ - public function getTiles():TileContainer - { - return __group.clone(); - } - - /** - Removes the specified Tile instance from the tile list of the Tilemap - instance. The index positions of any tile objects above the tile in the - Tilemap are decreased by 1. - - @param tile The Tile instance to remove. - @return The Tile instance that you pass in the `tile` parameter. - **/ - public function removeTile(tile:Tile):Tile - { - return __group.removeTile(tile); - } - - /** - Removes a Tile from the specified `index` position in the tile list of the - Tilemap. The index positions of any tile objects above the tile in - the Tilemap are decreased by 1. - - @param index The index of the Tile to remove. - @return The Tile instance that was removed. - **/ - public function removeTileAt(index:Int):Tile - { - return __group.removeTileAt(index); - } - - /** - Removes all Tile instances from the tile list of the ITileContainer instance. - - @param beginIndex The beginning position. - @param endIndex The ending position. - **/ - public function removeTiles(beginIndex:Int = 0, endIndex:Int = 0x7fffffff):Void - { - return __group.removeTiles(beginIndex, endIndex); - } - - /** - Changes the position of an existing tile in the tile container. - This affects the layering of tile objects. For example, the following - example shows three tile objects, labeled a, b, and c, at index - positions 0, 1, and 2, respectively: - - ![c over b over a](/images/DisplayObjectContainerSetChildIndex1.jpg) - - When you use the `setTileIndex()` method and specify an - index position that is already occupied, the only positions that change - are those in between the tile object's former and new position. All - others will stay the same. If a tile is moved to an index LOWER than its - current index, all tiles in between will INCREASE by 1 for their index - reference. If a tile is moved to an index HIGHER than its current index, - all tiles in between will DECREASE by 1 for their index reference. For - example, if the tile container in the previous example is named - `container`, you can swap the position of the tile objects - labeled a and b by calling the following code: - - ```haxe - container.setTileIndex(container.getTileAt(1), 0); - ``` - - This code results in the following arrangement of objects: - - ![c over a over b](/images/DisplayObjectContainerSetChildIndex2.jpg) - - @param tile The Tile instance for which you want to change the index - number. - @param index The resulting index number for the `tile` object. - **/ - public function setTileIndex(tile:Tile, index:Int):Void - { - __group.setTileIndex(tile, index); - } - - /** - Sets all the Tile instances of this Tilemap instance. - - @param beginIndex The beginning position. - @param endIndex The ending position. - **/ - public function setTiles(group:TileContainer):Void - { - for (tile in __group.__tiles) - { - removeTile(tile); - } - - for (tile in group.__tiles) - { - addTile(tile); - } - } - - /** - Sorts the z-order (front-to-back order) of all the tile objects in this - container based on a comparison function. - - A comparison function should take two arguments to compare. Given the elements - A and B, the result of `compareFunction` can have a negative, 0, or positive value: - - * A negative return value specifies that A appears before B in the sorted sequence. - * A return value of 0 specifies that A and B have the same sort order. - * A positive return value specifies that A appears after B in the sorted sequence. - - The sort operation is not guaranteed to be stable, which means that the - order of equal elements may not be retained. - - @param compareFunction A comparison function to use when sorting. - **/ - public function sortTiles(compareFunction:Tile->Tile->Int):Void - { - __group.sortTiles(compareFunction); - } - - /** - Swaps the z-order (front-to-back order) of the two specified tile - objects. All other tile objects in the tile container remain in - the same index positions. - - @param child1 The first tile object. - @param child2 The second tile object. - **/ - public function swapTiles(tile1:Tile, tile2:Tile):Void - { - __group.swapTiles(tile1, tile2); - } - - /** - Swaps the z-order (front-to-back order) of the tile objects at the two - specified index positions in the tile list. All other tile objects in - the tile container remain in the same index positions. - - @param index1 The index position of the first tile object. - @param index2 The index position of the second tile object. - **/ - public function swapTilesAt(index1:Int, index2:Int):Void - { - __group.swapTilesAt(index1, index2); - } - - #if !flash - @:noCompletion private override function __enterFrame(deltaTime:Float):Void - { - if (__group.__dirty) - { - __setRenderDirty(); - } - } - #end - - #if !flash - @:noCompletion private override function __getBounds(rect:Rectangle, matrix:Matrix):Void - { - var bounds = Rectangle.__pool.get(); - bounds.setTo(0, 0, __width, __height); - bounds.__transform(bounds, matrix); - - rect.__expand(bounds.x, bounds.y, bounds.width, bounds.height); - - Rectangle.__pool.release(bounds); - } - #end - - #if !flash - @:noCompletion private override function __hitTest(x:Float, y:Float, shapeFlag:Bool, stack:Array, interactiveOnly:Bool, - hitObject:DisplayObject):Bool - { - if (!hitObject.visible || __isMask) return false; - if (mask != null && !mask.__hitTestMask(x, y)) return false; - - __getRenderTransform(); - - var px = __renderTransform.__transformInverseX(x, y); - var py = __renderTransform.__transformInverseY(x, y); - - if (px > 0 && py > 0 && px <= __width && py <= __height) - { - if (stack != null && !interactiveOnly) - { - stack.push(hitObject); - } - - return true; - } - - return false; - } - #end - - @:noCompletion private function __renderFlash():Void - { - FlashTilemap.render(this); - } - - // Get & Set Methods - #if !flash - @:noCompletion private override function get_height():Float - { - return __height * Math.abs(scaleY); - } - #end - - #if !flash - @:noCompletion private override function set_height(value:Float):Float - { - __height = Std.int(value); - return __height * Math.abs(scaleY); - } - #else - #if (haxe_ver >= 4.3) override #else @:setter(height) #end private function set_height(value:Float):#if (haxe_ver >= 4.3) Float #else Void #end - { - if (value != bitmapData.height) - { - var cacheSmoothing = smoothing; - bitmapData = new BitmapData(bitmapData.width, Std.int(value), true, 0); - smoothing = cacheSmoothing; - } - #if (haxe_ver >= 4.3) - return bitmapData.height; - #end - } - #end - - @:noCompletion private function get_numTiles():Int - { - return __group.__length; - } - - @:noCompletion private function get_tileset():Tileset - { - return __tileset; - } - - @:noCompletion private function set_tileset(value:Tileset):Tileset - { - if (value != __tileset) - { - __tileset = value; - __group.tileset = value; - __group.__dirty = true; - - #if !flash - __setRenderDirty(); - #end - } - - return value; - } - - #if !flash - @:noCompletion private override function get_width():Float - { - return __width * Math.abs(__scaleX); - } - #end - - #if !flash - @:noCompletion private override function set_width(value:Float):Float - { - __width = Std.int(value); - return __width * Math.abs(__scaleX); - } - #else - #if (haxe_ver >= 4.3) override #else @:setter(width) #end private function set_width(value:Float):#if (haxe_ver >= 4.3) Float #else Void #end - { - if (value != bitmapData.width) - { - var cacheSmoothing = smoothing; - bitmapData = new BitmapData(Std.int(value), bitmapData.height, true, 0); - smoothing = cacheSmoothing; - } - #if (haxe_ver >= 4.3) - return bitmapData.width; - #end - } - #end -} diff --git a/source/openfl/display/Timeline.hx b/source/openfl/display/Timeline.hx deleted file mode 100644 index f4d08b4408c..00000000000 --- a/source/openfl/display/Timeline.hx +++ /dev/null @@ -1,401 +0,0 @@ -package openfl.display; - -import openfl.errors.ArgumentError; - -/** - Provides support for MovieClip animations (or a single frame Sprite) when - this class is overridden. - - For example, the OpenFL SWF library provides a Timeline generated from SWF - assets. However, any editor that may provide UI or display elements could - be used to generate assets for OpenFL timelines. - - To implement a custom Timeline, please override this class. Each Timeline - can set their original animation frame rate, and can also provide Scenes or - FrameScripts. OpenFL will automatically execute FrameScripts and request frame - updates. - - There are currently three internal methods which should not be called by the user, - which can be overridden to implement a new type of Timeline: - - attachMovieClip(); - enterFrame(); - initializeSprite(); -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -class Timeline -{ - /** - The original frame rate for this Timeline. - **/ - public var frameRate:Null; - - /** - An Array of Scenes contained within this Timeline. - - Scenes are assumed to occur in order, so if the first Scene - contains 10 frames, then the beginning of the second Scene will - be treated as frame 11 when setting FrameScripts or implementing - enterFrame(). - **/ - public var scenes:Array; - - /** - An optional array of frame scripts to be executed. - **/ - public var scripts:Array; - - @:noCompletion private var __currentFrame:Float; - @:noCompletion private var __currentFrameLabel:String; - @:noCompletion private var __currentLabel:String; - @:noCompletion private var __currentLabels:Array; - @:noCompletion private var __currentScene:Scene; - @:noCompletion private var __frameScripts:MapVoid>; - @:noCompletion private var __framesLoaded:Float; - @:noCompletion private var __frameTime:Float; - @:noCompletion private var __isPlaying:Bool; - @:noCompletion private var __lastFrameScriptEval:Float; - @:noCompletion private var __lastFrameUpdate:Float; - @:noCompletion private var __scope:MovieClip; - @:noCompletion private var __timeElapsed:Float; - @:noCompletion private var __totalFrames:Float; - - private function new() - { - __framesLoaded = 1; - __totalFrames = 1; - __currentLabels = []; - - __currentFrame = 1; - - __lastFrameScriptEval = -1; - __lastFrameUpdate = -1; - } - - /** - OpenFL will call this method automatically. - - If you are making your own Timeline type, please override this method - and implement the first frame initialization for a MovieClip. - - OpenFL will expect to use one Timeline instance per MovieClip. - - Please initialize the first frame in this method. Afterward enterFrame() - will be called automatically when it is time to enter a different frame. - **/ - @:noCompletion public function attachMovieClip(movieClip:MovieClip):Void {} - - /** - OpenFL will call this method automatically for MovieClips with - attached timelines. - - Please update your attached MovieClip instance to the requested frame - when this method is called. - **/ - @:noCompletion public function enterFrame(frame:Float):Void {} - - /** - OpenFL will call this method automatically. - - If you are making your own Timeline type, please override this method - and implement the initialization of a Sprite. - - Sprites do not use frame scripts, or enter multiple frames. In other - words, they will be similar to the first frame of a MovieClip. - - enterFrame() will not be called, and this Timeline object might be - re-used again. - **/ - @:noCompletion public function initializeSprite(sprite:Sprite):Void {} - - @:noCompletion private function __addFrameScript(index:Int, method:Void->Void):Void - { - if (index < 0) return; - - var frame = index + 1; - - if (method != null) - { - if (__frameScripts == null) - { - __frameScripts = new Map(); - } - - __frameScripts.set(frame, function(scope) - { - method(); - }); - } - else if (__frameScripts != null) - { - __frameScripts.remove(frame); - } - } - - @:noCompletion private function __attachMovieClip(movieClip:MovieClip):Void - { - __scope = movieClip; - - __totalFrames = 0; - __framesLoaded = 0; - - if (scenes != null && scenes.length > 0) - { - for (scene in scenes) - { - __totalFrames += scene.numFrames; - __framesLoaded += scene.numFrames; - if (scene.labels != null) - { - // TODO: Handle currentLabels properly for multiple scenes - __currentLabels = __currentLabels.concat(scene.labels); - } - } - - __currentScene = scenes[0]; - } - - if (scripts != null && scripts.length > 0) - { - __frameScripts = new Map(); - for (script in scripts) - { - if (__frameScripts.exists(script.frame)) - { - // TODO: Does this merging code work? - var existing = __frameScripts.get(script.frame); - var append = script.script; - __frameScripts.set(script.frame, function(clip:MovieClip) - { - existing(clip); - append(clip); - }); - } - else - { - __frameScripts.set(script.frame, script.script); - } - } - } - - attachMovieClip(movieClip); - } - - @:noCompletion private function __enterFrame(deltaTime:Float):Void - { - if (__isPlaying) - { - var nextFrame = __getNextFrame(deltaTime); - - if (__lastFrameScriptEval == nextFrame) - { - return; - } - - if (__frameScripts != null) - { - if (nextFrame < __currentFrame) - { - if (!__evaluateFrameScripts(__totalFrames)) - { - return; - } - - __currentFrame = 1; - } - - if (!__evaluateFrameScripts(nextFrame)) - { - return; - } - } - else - { - __currentFrame = nextFrame; - } - } - - __updateSymbol(__currentFrame); - } - - @:noCompletion private function __evaluateFrameScripts(advanceToFrame:Float):Bool - { - if (__frameScripts == null) return true; - - for (frame in Std.int(__currentFrame)...Std.int(advanceToFrame) + 1) - { - if (frame == Std.int(__lastFrameScriptEval)) continue; - - __lastFrameScriptEval = frame; - __currentFrame = frame; - - if (__frameScripts.exists(frame)) - { - __updateSymbol(frame); - var script = __frameScripts.get(frame); - script(__scope); - - if (__currentFrame != frame) - { - return false; - } - } - - if (!__isPlaying) - { - return false; - } - } - - return true; - } - - @:noCompletion private function __getNextFrame(deltaTime:Float):Float - { - var nextFrame:Float = 0; - - if (frameRate != null) - { - __timeElapsed += deltaTime; - nextFrame = __currentFrame + Math.floor(__timeElapsed / __frameTime); - if (nextFrame < 1) nextFrame = 1; - if (nextFrame > __totalFrames) nextFrame = Math.floor((nextFrame - 1) % __totalFrames) + 1; - __timeElapsed = (__timeElapsed % __frameTime); - } - else - { - nextFrame = __currentFrame + 1; - if (nextFrame > __totalFrames) nextFrame = 1; - } - - return nextFrame; - } - - @:noCompletion private function __goto(frame:Float):Void - { - if (frame < 1) frame = 1; - else if (frame > __totalFrames) frame = __totalFrames; - - __lastFrameScriptEval = -1; - __currentFrame = frame; - - __updateSymbol(__currentFrame); - __evaluateFrameScripts(__currentFrame); - } - - @:noCompletion private function __gotoAndPlay(frame:#if (haxe_ver >= "3.4.2") Any #else Dynamic #end, scene:String = null):Void - { - __play(); - __goto(__resolveFrameReference(frame)); - } - - @:noCompletion private function __gotoAndStop(frame:#if (haxe_ver >= "3.4.2") Any #else Dynamic #end, scene:String = null):Void - { - __stop(); - __goto(__resolveFrameReference(frame)); - } - - @:noCompletion private function __nextFrame():Void - { - __stop(); - __goto(__currentFrame + 1); - } - - @:noCompletion private function __nextScene():Void - { - // TODO - } - - @:noCompletion private function __play():Void - { - if (__isPlaying || __totalFrames < 2) return; - - __isPlaying = true; - - if (frameRate != null) - { - __frameTime = Std.int(1000 / frameRate); - __timeElapsed = 0; - } - } - - @:noCompletion private function __prevFrame():Void - { - __stop(); - __goto(__currentFrame - 1); - } - - @:noCompletion private function __prevScene():Void - { - // TODO - } - - @:noCompletion private function __stop():Void - { - __isPlaying = false; - } - - @:noCompletion private function __resolveFrameReference(frame:#if (haxe_ver >= "3.4.2") Any #else Dynamic #end):Float - { - if ((frame is Float)) - { - return cast frame; - } - else if ((frame is String)) - { - var label:String = cast frame; - - for (frameLabel in __currentLabels) - { - if (frameLabel.name == label) - { - return frameLabel.frame; - } - } - - throw new ArgumentError("Error #2109: Frame label " + label + " not found in scene."); - } - else - { - throw "Invalid type for frame " + Type.getClassName(frame); - } - } - - @:noCompletion private function __updateFrameLabel():Void - { - __currentLabel = null; - __currentFrameLabel = null; - - // TODO: Update without looping so much - - for (label in __currentLabels) - { - if (label.frame < __currentFrame) - { - __currentLabel = label.name; - } - else if (label.frame == __currentFrame) - { - __currentLabel = label.name; - __currentFrameLabel = label.name; - } - else - { - break; - } - } - } - - @:noCompletion private function __updateSymbol(targetFrame:Float):Void - { - if (__currentFrame != __lastFrameUpdate) - { - __updateFrameLabel(); - enterFrame(targetFrame); - __lastFrameUpdate = __currentFrame; - } - } -} diff --git a/source/openfl/media/Video.hx b/source/openfl/media/Video.hx deleted file mode 100644 index 09a863285a9..00000000000 --- a/source/openfl/media/Video.hx +++ /dev/null @@ -1,503 +0,0 @@ -package openfl.media; - -#if !flash -import openfl.display3D._internal.GLBuffer; -import openfl.display3D.textures.RectangleTexture; -import openfl.display3D.Context3D; -import openfl.display3D.IndexBuffer3D; -import openfl.display3D.VertexBuffer3D; -import openfl.display.DisplayObject; -import openfl.geom.ColorTransform; -import openfl.geom.Matrix; -import openfl.geom.Point; -import openfl.geom.Rectangle; -import openfl.net.NetStream; -import openfl.utils._internal.Float32Array; -import openfl.utils._internal.UInt16Array; -#if lime -import lime.graphics.RenderContext; -#end - -/** - The Video class displays live or recorded video in an application without - embedding the video in your SWF file. This class creates a Video object - that plays either of the following kinds of video: recorded video files - stored on a server or locally, or live video captured by the user. A Video - object is a display object on the application's display list and - represents the visual space in which the video runs in a user interface. - When used with Flash Media Server, the Video object allows you to send - live video captured by a user to the server and then broadcast it from the - server to other users. Using these features, you can develop media - applications such as a simple video player, a video player with multipoint - publishing from one server to another, or a video sharing application for - a user community. - - Flash Player 9 and later supports publishing and playback of FLV files - encoded with either the Sorenson Spark or On2 VP6 codec and also supports - an alpha channel. The On2 VP6 video codec uses less bandwidth than older - technologies and offers additional deblocking and deringing filters. See - the openfl.net.NetStream class for more information about video playback - and supported formats. - - Flash Player 9.0.115.0 and later supports mipmapping to optimize runtime - rendering quality and performance. For video playback, Flash Player uses - mipmapping optimization if you set the Video object's `smoothing` property - to `true`. - - As with other display objects on the display list, you can control various - properties of Video objects. For example, you can move the Video object - around on the Stage by using its `x` and `y` properties, you can change - its size using its `height` and `width` properties, and so on. - - To play a video stream, use `attachCamera()` or `attachNetStream()` to - attach the video to the Video object. Then, add the Video object to the - display list using `addChild()`. - - If you are using Flash Professional, you can also place the Video object - on the Stage rather than adding it with `addChild()`, like this: - - 1. If the Library panel isn't visible, select Window > Library to display - it. - 2. Add an embedded Video object to the library by clicking the Options menu - on the right side of the Library panel title bar and selecting New Video. - 3. In the Video Properties dialog box, name the embedded Video object for - use in the library and click OK. - 4. Drag the Video object to the Stage and use the Property Inspector to - give it a unique instance name, such as `my_video`. (Do not name it - Video.) - - In AIR applications on the desktop, playing video in fullscreen mode - disables any power and screen saving features (when allowed by the - operating system). - - **Note:** The Video class is not a subclass of the InteractiveObject - class, so it cannot dispatch mouse events. However, you can call the - `addEventListener()` method on the display object container that contains - the Video object. -**/ -#if !openfl_debug -@:fileXml('tags="haxe,release"') -@:noDebug -#end -@:access(openfl.display3D.textures.TextureBase) -@:access(openfl.display3D.Context3D) -@:access(openfl.geom.ColorTransform) -@:access(openfl.geom.Matrix) -@:access(openfl.geom.Point) -@:access(openfl.geom.Rectangle) -@:access(openfl.net.NetStream) -class Video extends DisplayObject -{ - @:noCompletion private static inline var VERTEX_BUFFER_STRIDE:Int = 5; - - /** - Indicates the type of filter applied to decoded video as part of - post-processing. The default value is 0, which lets the video - compressor apply a deblocking filter as needed. - Compression of video can result in undesired artifacts. You can use - the `deblocking` property to set filters that reduce blocking and, for - video compressed using the On2 codec, ringing. - - _Blocking_ refers to visible imperfections between the boundaries of - the blocks that compose each video frame. _Ringing_ refers to - distorted edges around elements within a video image. - - Two deblocking filters are available: one in the Sorenson codec and - one in the On2 VP6 codec. In addition, a deringing filter is available - when you use the On2 VP6 codec. To set a filter, use one of the - following values: - - * 0—Lets the video compressor apply the deblocking filter as needed. - * 1—Does not use a deblocking filter. - * 2—Uses the Sorenson deblocking filter. - * 3—For On2 video only, uses the On2 deblocking filter but no - deringing filter. - * 4—For On2 video only, uses the On2 deblocking and deringing - filter. - * 5—For On2 video only, uses the On2 deblocking and a - higher-performance On2 deringing filter. - - If a value greater than 2 is selected for video when you are using the - Sorenson codec, the Sorenson decoder defaults to 2. - - Using a deblocking filter has an effect on overall playback - performance, and it is usually not necessary for high-bandwidth video. - If a user's system is not powerful enough, the user may experience - difficulties playing back video with a deblocking filter enabled. - **/ - public var deblocking:Int; - - /** - Specifies whether the video should be smoothed (interpolated) when it - is scaled. For smoothing to work, the runtime must be in high-quality - mode (the default). The default value is `false` (no smoothing). - For video playback using Flash Player 9.0.115.0 and later versions, - set this property to `true` to take advantage of mipmapping image - optimization. - **/ - public var smoothing:Bool; - - /** - An integer specifying the height of the video stream, in pixels. For - live streams, this value is the same as the `Camera.height` property - of the Camera object that is capturing the video stream. For recorded - video files, this value is the height of the video. - You may want to use this property, for example, to ensure that the - user is seeing the video at the same size at which it was captured, - regardless of the actual size of the Video object on the Stage. - **/ - public var videoHeight(get, never):Int; - - /** - An integer specifying the width of the video stream, in pixels. For - live streams, this value is the same as the `Camera.width` property of - the Camera object that is capturing the video stream. For recorded - video files, this value is the width of the video. - You may want to use this property, for example, to ensure that the - user is seeing the video at the same size at which it was captured, - regardless of the actual size of the Video object on the Stage. - **/ - public var videoWidth(get, never):Int; - - @:noCompletion private var __active:Bool; - @:noCompletion private var __buffer:GLBuffer; - @:noCompletion private var __bufferAlpha:Float; - @:noCompletion private var __bufferColorTransform:ColorTransform; - @:noCompletion private var __bufferContext:#if lime RenderContext #else Dynamic #end; - @:noCompletion private var __bufferData:Float32Array; - @:noCompletion private var __currentWidth:Float; - @:noCompletion private var __currentHeight:Float; - @:noCompletion private var __dirty:Bool; - @:noCompletion private var __height:Float; - @:noCompletion private var __indexBuffer:IndexBuffer3D; - @:noCompletion private var __indexBufferContext:#if lime RenderContext #else Dynamic #end; - @:noCompletion private var __indexBufferData:UInt16Array; - @:noCompletion private var __stream:NetStream; - @:noCompletion private var __texture:RectangleTexture; - @:noCompletion private var __textureTime:Float; - @:noCompletion private var __uvRect:Rectangle; - @:noCompletion private var __vertexBuffer:VertexBuffer3D; - @:noCompletion private var __vertexBufferContext:#if lime RenderContext #else Dynamic #end; - @:noCompletion private var __vertexBufferData:Float32Array; - @:noCompletion private var __width:Float; - - #if openfljs - @:noCompletion private static function __init__() - { - untyped Object.defineProperties(Video.prototype, { - "videoHeight": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_videoHeight (); }")}, - "videoWidth": {get: untyped #if haxe4 js.Syntax.code #else __js__ #end ("function () { return this.get_videoWidth (); }")}, - }); - } - #end - - /** - Creates a new Video instance. If no values for the `width` and - `height` parameters are supplied, the default values are used. You can - also set the width and height properties of the Video object after the - initial construction, using `Video.width` and `Video.height`. When a - new Video object is created, values of zero for width or height are - not allowed; if you pass zero, the defaults will be applied. - After creating the Video, call the `DisplayObjectContainer.addChild()` - or `DisplayObjectContainer.addChildAt()` method to add the Video - object to a parent DisplayObjectContainer object. - - @param width The width of the video, in pixels. - @param height The height of the video, in pixels. - **/ - public function new(width:Int = 320, height:Int = 240):Void - { - super(); - - __drawableType = VIDEO; - __width = width; - __height = height; - - __textureTime = -1; - - smoothing = false; - deblocking = 0; - } - - #if false - /** - Specifies a video stream from a camera to be displayed within the - boundaries of the Video object in the application. - Use this method to attach live video captured by the user to the Video - object. You can play the live video locally on the same computer or - device on which it is being captured, or you can send it to Flash - Media Server and use the server to stream it to other users. - - **Note:** In an iOS AIR application, camera video cannot be displayed - when the application uses GPU rendering mode. - - @param camera A Camera object that is capturing video data. To drop - the connection to the Video object, pass `null`. - **/ - // function attachCamera(camera : Camera) : Void; - #end - - /** - Specifies a video stream to be displayed within the boundaries of the - Video object in the application. The video stream is either a video - file played with `NetStream.play()`, a Camera object, or `null`. If - you use a video file, it can be stored on the local file system or on - Flash Media Server. If the value of the `netStream` argument is - `null`, the video is no longer played in the Video object. - You do not need to use this method if a video file contains only - audio; the audio portion of video files is played automatically when - you call `NetStream.play()`. To control the audio associated with a - video file, use the `soundTransform` property of the NetStream object - that plays the video file. - - @param netStream A NetStream object. To drop the connection to the - Video object, pass `null`. - **/ - public function attachNetStream(netStream:NetStream):Void - { - __stream = netStream; - - #if (js && html5) - if (__stream != null && __stream.__video != null && !__stream.__closed) - { - __stream.__video.play(); - } - #end - } - - /** - Clears the image currently displayed in the Video object (not the - video stream). This method is useful for handling the current image. - For example, you can clear the last image or display standby - information without hiding the Video object. - - **/ - public function clear():Void {} - - @:noCompletion private override function __enterFrame(deltaTime:Float):Void - { - #if (js && html5) - if (__renderable && __stream != null) - { - __setRenderDirty(); - } - #end - } - - @:noCompletion private override function __getBounds(rect:Rectangle, matrix:Matrix):Void - { - var bounds = Rectangle.__pool.get(); - bounds.setTo(0, 0, __width, __height); - bounds.__transform(bounds, matrix); - - rect.__expand(bounds.x, bounds.y, bounds.width, bounds.height); - - Rectangle.__pool.release(bounds); - } - - @:noCompletion private function __getIndexBuffer(context:Context3D):IndexBuffer3D - { - #if (lime || js) - var gl = context.gl; - - if (__indexBuffer == null || __indexBufferContext != context.__context) - { - // TODO: Use shared buffer on context - - __indexBufferData = new UInt16Array(6); - __indexBufferData[0] = 0; - __indexBufferData[1] = 1; - __indexBufferData[2] = 2; - __indexBufferData[3] = 2; - __indexBufferData[4] = 1; - __indexBufferData[5] = 3; - - __indexBufferContext = context.__context; - __indexBuffer = context.createIndexBuffer(6); - __indexBuffer.uploadFromTypedArray(__indexBufferData); - } - #end - - return __indexBuffer; - } - - @:noCompletion private function __getTexture(context:Context3D):RectangleTexture - { - #if (js && html5) - if (__stream == null || __stream.__video == null) return null; - - var gl = context.__context.webgl; - var internalFormat = gl.RGBA; - var format = gl.RGBA; - - if (!__stream.__closed && __stream.__video.currentTime != __textureTime) - { - if (__texture == null) - { - __texture = context.createRectangleTexture(__stream.__video.videoWidth, __stream.__video.videoHeight, BGRA, false); - } - - context.__bindGLTexture2D(__texture.__textureID); - gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, format, gl.UNSIGNED_BYTE, __stream.__video); - - __textureTime = __stream.__video.currentTime; - } - - return __texture; - #else - return null; - #end - } - - @:noCompletion private function __getVertexBuffer(context:Context3D):VertexBuffer3D - { - #if (lime || js) - var gl = context.gl; - - if (__vertexBuffer == null - || __vertexBufferContext != context.__context - || __currentWidth != width - || __currentHeight != height) - { - __currentWidth = width; - __currentHeight = height; - #if openfl_power_of_two - var newWidth = 1; - var newHeight = 1; - - while (newWidth < width) - { - newWidth <<= 1; - } - - while (newHeight < height) - { - newHeight <<= 1; - } - - var uvWidth = width / newWidth; - var uvHeight = height / newHeight; - #else - var uvWidth = 1; - var uvHeight = 1; - #end - - __vertexBufferData = new Float32Array(VERTEX_BUFFER_STRIDE * 4); - - __vertexBufferData[0] = width; - __vertexBufferData[1] = height; - __vertexBufferData[3] = uvWidth; - __vertexBufferData[4] = uvHeight; - __vertexBufferData[VERTEX_BUFFER_STRIDE + 1] = height; - __vertexBufferData[VERTEX_BUFFER_STRIDE + 4] = uvHeight; - __vertexBufferData[VERTEX_BUFFER_STRIDE * 2] = width; - __vertexBufferData[VERTEX_BUFFER_STRIDE * 2 + 3] = uvWidth; - - __vertexBufferContext = context.__context; - __vertexBuffer = context.createVertexBuffer(3, VERTEX_BUFFER_STRIDE); - __vertexBuffer.uploadFromTypedArray(__vertexBufferData); - } - #end - - return __vertexBuffer; - } - - @:noCompletion private override function __hitTest(x:Float, y:Float, shapeFlag:Bool, stack:Array, interactiveOnly:Bool, - hitObject:DisplayObject):Bool - { - if (!hitObject.visible || __isMask) return false; - if (mask != null && !mask.__hitTestMask(x, y)) return false; - - __getRenderTransform(); - - var px = __renderTransform.__transformInverseX(x, y); - var py = __renderTransform.__transformInverseY(x, y); - - if (px > 0 && py > 0 && px <= __width && py <= __height) - { - if (stack != null && !interactiveOnly) - { - stack.push(hitObject); - } - - return true; - } - - return false; - } - - @:noCompletion private override function __hitTestMask(x:Float, y:Float):Bool - { - var point = Point.__pool.get(); - point.setTo(x, y); - - __globalToLocal(point, point); - - var hit = (point.x > 0 && point.y > 0 && point.x <= __width && point.y <= __height); - - Point.__pool.release(point); - return hit; - } - - // Get & Set Methods - @:noCompletion private override function get_height():Float - { - return __height * scaleY; - } - - @:noCompletion private override function set_height(value:Float):Float - { - if (scaleY != 1 || value != __height) - { - __setTransformDirty(); - __dirty = true; - } - - scaleY = 1; - return __height = value; - } - - @:noCompletion private function get_videoHeight():Int - { - #if (js && html5) - if (__stream != null && __stream.__video != null) - { - return Std.int(__stream.__video.videoHeight); - } - #end - - return 0; - } - - @:noCompletion private function get_videoWidth():Int - { - #if (js && html5) - if (__stream != null && __stream.__video != null) - { - return Std.int(__stream.__video.videoWidth); - } - #end - - return 0; - } - - @:noCompletion private override function get_width():Float - { - return __width * __scaleX; - } - - @:noCompletion private override function set_width(value:Float):Float - { - if (__scaleX != 1 || __width != value) - { - __setTransformDirty(); - __dirty = true; - } - - scaleX = 1; - return __width = value; - } -} -#else -typedef Video = flash.media.Video; -#end