[Laszlo-checkins] r13289 - openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9

bargull@openlaszlo.org bargull at openlaszlo.org
Sat Mar 14 17:24:41 PDT 2009


Author: bargull
Date: 2009-03-14 17:24:38 -0700 (Sat, 14 Mar 2009)
New Revision: 13289

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
Log:
Change 20090314-bargull-GHI by bargull at dell--p4--2-53 on 2009-03-14 19:31:57
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: add support for 'native' swf9 cursors

New Features: LPP-7912 (SWF9: support for default cursors)

Bugs Fixed:

Technical Reviewer: hminsky
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
With this change the 'native' swf9 cursors (eg. hand- and ibeam-cursor) can be used for lz.Cursor.setCursorGlobal() and lz.view#cursor.
    

Tests:
testcase at bugreport



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as	2009-03-15 00:22:27 UTC (rev 13288)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as	2009-03-15 00:24:38 UTC (rev 13289)
@@ -15,6 +15,7 @@
     import flash.events.Event;
     import flash.events.MouseEvent;
     import flash.ui.Mouse;
+    import flash.ui.MouseCursor;
     }#
 
 
@@ -50,13 +51,13 @@
             LFCApplication.stage.addEventListener(Event.MOUSE_LEAVE, __mouseLeaveHandler);
             __listeneradded = true;
         }
-    }    
+    }
 
     // Handles global mouse events
     static function __mouseHandler(event:MouseEvent):void {
         var eventname:String = 'on' + event.type.toLowerCase();
         if (eventname == 'onmouseup' && __lastMouseDown != null) {
-            // call mouseup on the sprite that got the last mouse down  
+            // call mouseup on the sprite that got the last mouse down
             __lastMouseDown.__globalmouseup(event);
             __lastMouseDown = null;
         } else {
@@ -96,13 +97,30 @@
     }
 
     static var __amLocked:Boolean = false;
+    static var useBuiltinCursor:Boolean = false;
     static var cursorSprite:Sprite = null;
     static var globalCursorResource:String = null;
     static var lastCursorResource:String = null;
 
+    #passthrough {
+        private static var __builtinCursors:Object = null;
+        static function get builtinCursors () :Object {
+            if (__builtinCursors == null) {
+                var cursors:Object = {};
+                cursors[MouseCursor.ARROW] = true;
+                cursors[MouseCursor.AUTO] = true;
+                cursors[MouseCursor.BUTTON] = true;
+                cursors[MouseCursor.HAND] = true;
+                cursors[MouseCursor.IBEAM] = true;
+                __builtinCursors = cursors;
+            }
+            return __builtinCursors;
+        }
+    }#
+
     /**
     * Sets the cursor to a resource
-    * @param String what: The resource to use as the cursor. 
+    * @param String what: The resource to use as the cursor.
     */
     static function setCursorGlobal (what:String) :void {
         globalCursorResource = what;
@@ -111,45 +129,66 @@
 
     static function setCursorLocal (what:String) :void {
         if ( __amLocked ) { return; }
-        Mouse.hide();
-        cursorSprite.x = LFCApplication.stage.mouseX;
-        cursorSprite.y = LFCApplication.stage.mouseY;
-        LFCApplication.setChildIndex(cursorSprite, LFCApplication._sprite.numChildren-1);
-        if (lastCursorResource != what) {
-            if (cursorSprite.numChildren > 0) {
-                cursorSprite.removeChildAt(0);
+        if (what == null) {
+            // null is invalid, maybe call restoreCursor()?
+            return;
+        } else if (lastCursorResource != what) {
+            var resourceSprite:Sprite = getCursorResource(what);
+            if (resourceSprite != null) {
+                if (cursorSprite.numChildren > 0) {
+                    cursorSprite.removeChildAt(0);
+                }
+                cursorSprite.addChild( resourceSprite );
+                useBuiltinCursor = false;
+            } else if (builtinCursors[what] != null) {
+                useBuiltinCursor = true;
+            } else {
+                // invalid cursor?
+                return;
             }
-            var resourceSprite:Sprite = getCursorResource(what);
-            cursorSprite.addChild( resourceSprite );
             lastCursorResource = what;
         }
-        // respond to mouse move events
-        cursorSprite.startDrag();
-        LFCApplication.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
-        cursorSprite.visible = true;
+        if (useBuiltinCursor) {
+            Mouse.cursor = what;
+            cursorSprite.stopDrag();
+            cursorSprite.visible = false;
+            LFCApplication.stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
+            Mouse.show();
+        } else {
+            Mouse.hide();
+            cursorSprite.x = LFCApplication.stage.mouseX;
+            cursorSprite.y = LFCApplication.stage.mouseY;
+            LFCApplication.setChildIndex(cursorSprite, LFCApplication._sprite.numChildren-1);
+            // respond to mouse move events
+            cursorSprite.startDrag();
+            LFCApplication.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
+            cursorSprite.visible = true;
+        }
     }
 
     static function mouseLeaveHandler(evt:Event):void {
         cursorSprite.visible = false;
     }
 
+    static function getCursorResource (resource:String):Sprite {
+          if (! (LzAsset.isMovieClipAsset(resource) || LzAsset.isMovieClipLoaderAsset(resource))) {
+              // only swf cursors are supported
+              return null;
+          }
 
-    static function getCursorResource (resource:String):Sprite {
           var resinfo:Object = LzResourceLibrary[resource];
           var assetclass:Class;
-          var frames:Array = resinfo.frames;
-          var asset:Sprite;
           // single frame resources get an entry in LzResourceLibrary which has
           // 'assetclass' pointing to the resource Class object.
           if (resinfo.assetclass is Class) {
               assetclass = resinfo.assetclass;
           } else {
               // Multiframe resources have an array of Class objects in frames[]
+              var frames:Array = resinfo.frames;
               assetclass = frames[0];
           }
 
-          if (! assetclass) return null;
-          asset = new assetclass();
+          var asset:Sprite = new assetclass();
           asset.scaleX = 1.0;
           asset.scaleY = 1.0;
           //Debug.write('cursor asset', asset);
@@ -159,14 +198,16 @@
     /**
     * This function restores the default cursor if there is no locked cursor on
     * the screen.
-    * 
+    *
     * @access private
     */
     static function restoreCursor () :void {
         if ( __amLocked ) { return; }
         cursorSprite.stopDrag();
         cursorSprite.visible = false;
+        LFCApplication.stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
         globalCursorResource = null;
+        Mouse.cursor = MouseCursor.AUTO;
         Mouse.show();
     }
 
@@ -185,7 +226,7 @@
 
     /**
     * Prevents the cursor from being changed until unlock is called.
-    * 
+    *
     */
     static function lock () :void {
         __amLocked = true;
@@ -193,11 +234,11 @@
 
     /**
     * Restores the default cursor.
-    * 
+    *
     */
     static function unlock () :void {
         __amLocked = false;
-        restoreCursor(); 
+        restoreCursor();
     }
 
     static function initCursor () :void {



More information about the Laszlo-checkins mailing list