[Laszlo-checkins] r10747 - in openlaszlo/trunk/WEB-INF/lps/lfc: kernel/swf9 services views
hqm@openlaszlo.org
hqm at openlaszlo.org
Sat Aug 23 13:50:33 PDT 2008
Author: hqm
Date: 2008-08-23 13:50:30 -0700 (Sat, 23 Aug 2008)
New Revision: 10747
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
openlaszlo/trunk/WEB-INF/lps/lfc/services/LzGlobalMouse.lzs
openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.lzs
Log:
Change 20080823-hqm-9 by hqm at badtzmaru.home on 2008-08-23 00:36:37 EDT
in /Users/hqm/openlaszlo/trunk/WEB-INF/lps/lfc
for http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/lfc
Summary: implement cursor services for swf9
New Features:
Bugs Fixed: LPP-6853
Technical Reviewer: max
QA Reviewer: pbr
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
+ Implemented global "use hand cursor" behavior: added flag "LzMouseKernel.showhandcursor", and
added check for it in the LzSprite mouse event handler __mouseEvent().
+ Implemented global cursor in LzMouseKernel. This instantiates an LzSprite
with the specified resource. We might want to cache that sprite instead of instatiating
it each time.
+ Implemented LzSprite.setCursor
+ properly restore the user-defined global cursor set by the last call to LzMouseKernel.setCursorGlobal, if any, when you move out of a view that has a custom cursor
NOTE: there is an issue with cursors which are PNG files and their
"hot spot". If the images are stored as PNG files, how do we specify
the the location of the "hot spot"??
NOTE: there is something not quite right about the double arrow cursor which is displayed
in the grid example "stretcher" controls; it appears to have it's left side clipped off. This
seems to be a bug in the LzSprite bitmap conversion we are doing, to get around the
spurious mouseout events that happen with addChild of a swf resource
Tests:
test/cursors.lzx
examples/components/grid_example.lzx when moving mouse over the column stretching
controls, the column stretcher cursor is active (double arrow)
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as 2008-08-23 12:51:59 UTC (rev 10746)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LFCApplication.as 2008-08-23 20:50:30 UTC (rev 10747)
@@ -26,24 +26,28 @@
}#
// The application sprite
- public var _sprite:Sprite;
+ static public var _sprite:Sprite;
- public function addChild(child:DisplayObject):DisplayObject {
+ public static function addChild(child:DisplayObject):DisplayObject {
_sprite.addChild(child);
}
+ public static function removeChild(child:DisplayObject):DisplayObject {
+ _sprite.removeChild(child);
+ }
+
// Allow anyone access to the stage object (see ctor below)
public static var stage:Stage = null;
// Allow anyone access to write to the debugger
public static var write:Function;
-
+
public function LFCApplication (sprite:Sprite) {
- _sprite = sprite;
+ LFCApplication._sprite = sprite;
// Allow anyone to access the stage object
- LFCApplication.stage = _sprite.stage;
+ LFCApplication.stage = LFCApplication._sprite.stage;
LFCApplication.write = this.write;
// trace("LFCApplication.stage = " + LFCApplication.stage);
@@ -79,8 +83,15 @@
LzKeyboardKernel.setCallback(lz.Keys, '__keyEvent');
- ////////////////////////////////////////////////////////////////
// cheapo debug console
+ makeDebuggerFields();
+
+
+
+ }
+
+ // A simple debugger output and input field
+ function makeDebuggerFields () {
lzconsole = this;
var tfield:TextField = new TextField();
tfield.visible = false;
@@ -110,29 +121,11 @@
ci.type = TextFieldType.INPUT;
ci.addEventListener(KeyboardEvent.KEY_DOWN, consoleInputHandler);
-
- /* var allFonts:Array = Font.enumerateFonts(true);
- allFonts.sortOn("fontName", Array.CASEINSENSITIVE);
-
- var embeddedFonts:Array = Font.enumerateFonts(false);
- embeddedFonts.sortOn("fontName", Array.CASEINSENSITIVE);
-
- */
-
-
var newFormat:TextFormat = new TextFormat();
newFormat.size = 11;
newFormat.font = "Verdana";
ci.defaultTextFormat = newFormat;
consoletext.defaultTextFormat = newFormat;
-
- ////////////////////////////////////////////////////////////////
-
-
- ////////////////////////////////////////////////////////////////
- // Testing runtime code loading
- ////////////////////////////////////////////////////////////////
-
}
// Debugger loader completion handler
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as 2008-08-23 12:51:59 UTC (rev 10746)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as 2008-08-23 20:50:30 UTC (rev 10747)
@@ -28,13 +28,19 @@
static var __lastMouseDown = null;
static var __listeneradded:Boolean = false ;
+ /**
+ * Shows or hides the hand cursor for all clickable views.
+ */
+ static var showhandcursor:Boolean = true;
+
static function setCallback (scope, funcname) {
LzMouseKernel.__scope = scope;
LzMouseKernel.__callback = funcname;
if (LzMouseKernel.__listeneradded == false) {
LFCApplication.stage.addEventListener(MouseEvent.MOUSE_MOVE, __mouseHandler);
- LFCApplication.stage.addEventListener(MouseEvent.MOUSE_UP, __mouseHandler);
+ LFCApplication.stage.addEventListener(MouseEvent.MOUSE_UP, __mouseHandler);
LFCApplication.stage.addEventListener(MouseEvent.MOUSE_DOWN, __mouseHandler);
+ LFCApplication.stage.addEventListener(Event.MOUSE_LEAVE, __mouseLeavesHandler);
LzMouseKernel.__listeneradded = true;
}
}
@@ -53,22 +59,50 @@
}
}
+ // handles MOUSE_LEAVES event
+ static function __mouseLeavesHandler(event:Event):void {
+ var eventname = 'on' + event.type.toLowerCase();
+ LzMouseKernel.__sendEvent(null, eventname);
+ }
+
+
/**
* Shows or hides the hand cursor for all clickable views.
* @param Boolean show: true shows the hand cursor for buttons, false hides it
*/
static function showHandCursor (show) {
- Debug.info("LzMouseKernel.showHandCursor not yet implemented.")
+ LzMouseKernel.showhandcursor = show;
}
static var __amLocked:Boolean = false;
+
+ static var cursorSprite:LzSprite = null;
+ static var globalCursorResource:String = null;
+
/**
* Sets the cursor to a resource
* @param String what: The resource to use as the cursor.
*/
- static function setCursorGlobal ( what ){
+ static function setCursorGlobal ( what:String ){
+ globalCursorResource = what;
+ setCursorLocal(what);
+ }
+
+ static function setCursorLocal ( what:String ) {
if ( LzMouseKernel.__amLocked ) { return; }
- Debug.info("LzMouseKernel.setCursorGlobal not yet implemented.")
+ if (cursorSprite != null) {
+ cursorSprite.stopDrag();
+ LFCApplication.removeChild(cursorSprite);
+ cursorSprite = null;
+ }
+ cursorSprite = new LzSprite();
+ cursorSprite.setResource(what);
+ // Add the cursor DisplayObject to the root sprite
+ LFCApplication.addChild(cursorSprite);
+ cursorSprite.x = cursorSprite.mouseX;
+ cursorSprite.y = cursorSprite.mouseY;
+ cursorSprite.startDrag(true);
+ Mouse.hide();
}
/**
@@ -79,9 +113,28 @@
*/
static function restoreCursor ( ){
if ( LzMouseKernel.__amLocked ) { return; }
- Debug.info("LzMouseKernel.restoreCursor not yet implemented.")
+ if (cursorSprite != null) {
+ cursorSprite.stopDrag();
+ LFCApplication.removeChild(cursorSprite);
+ cursorSprite = null;
+ globalCursorResource = null;
+ }
+ Mouse.show();
}
+ /** Called by LzSprite to restore cursor to global value.
+ */
+ static function restoreCursorLocal ( ){
+ if ( LzMouseKernel.__amLocked ) { return; }
+ if (globalCursorResource == null) {
+ // Restore to system default pointer
+ restoreCursor();
+ } else {
+ // Restore to the last value set by setCursorGlobal
+ setCursorLocal(globalCursorResource);
+ }
+ }
+
/**
* Prevents the cursor from being changed until unlock is called.
*
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-08-23 12:51:59 UTC (rev 10746)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2008-08-23 20:50:30 UTC (rev 10747)
@@ -46,6 +46,11 @@
public var resourceheight:Number = 0;
public var isroot:Boolean = false;
+ // If null, the handcursor visibility is set to the value of LzMouseKernel.showhandcursor
+ // whenevent a mouseover event happens.
+ public var showhandcursor:* = null;
+ public var cursorSprite:Sprite = null;
+
public var fontsize:String = "11";
public var fontstyle:String = "plain";
public var fontname:String = "Verdana";
@@ -101,7 +106,7 @@
public function init (v:Boolean = true):void {
this.setVisible(v);
- if (this.isroot) {
+ if (this.isroot && DojoExternalInterface.available) {
// Expose your methods
DojoExternalInterface.addCallback("getCanvasAttribute", lz.History, lz.History.getCanvasAttribute);
DojoExternalInterface.addCallback("setCanvasAttribute", lz.History, lz.History.setCanvasAttribute);
@@ -178,7 +183,9 @@
this.resourcewidth = res.width;
this.resourceheight = res.height;
- this.owner.resourceevent('totalframes', res.frames.length);
+ if (this.owner != null) {
+ this.owner.resourceevent('totalframes', res.frames.length);
+ }
if (this.resourceObj == null) {
this.createResourceBitmap()
}
@@ -306,6 +313,7 @@
public function __mouseEvent( e:MouseEvent ){
var skipevent = false;
var eventname = 'on' + e.type.toLowerCase();
+
if (eventname == 'onmousedown') {
// cancel mousedown event bubbling...
e.stopPropagation();
@@ -327,8 +335,8 @@
if (skipevent == true || ! this.owner.mouseevent) return;
// send dragin/out events if the mouse is currently down
- if (LzMouseKernel.__lastMouseDown) {
- if (eventname == 'onmouseover' || eventname == 'onmouseout') {
+ if (LzMouseKernel.__lastMouseDown &&
+ (eventname == 'onmouseover' || eventname == 'onmouseout')) {
// only send mouseover/out if the mouse went down on this sprite
if (LzMouseKernel.__lastMouseDown == this) {
LzMouseKernel.__sendEvent(this.owner, eventname);
@@ -336,11 +344,17 @@
var dragname = eventname == 'onmouseover' ? 'onmousedragin' : 'onmousedragout';
LzMouseKernel.__sendEvent(this.owner, dragname);
- return;
- }
+ } else {
+ LzMouseKernel.__sendEvent(this.owner, eventname);
}
- LzMouseKernel.__sendEvent(this.owner, eventname);
+ // If this.showhandcursor is null, inherit value from LzMouseKernel.showhandcursor
+ if (this.clickable) {
+ this.clickbutton.useHandCursor = (showhandcursor == null) ? LzMouseKernel.showhandcursor : showhandcursor;
+ }
+
+
+
}
/** setClickable( Boolean:clickable )
@@ -364,7 +378,7 @@
this.clickbutton = cb = new SimpleButton();
addChild(cb);
}
- cb.useHandCursor = true;
+ cb.useHandCursor = (showhandcursor == null) ? LzMouseKernel.showhandcursor : showhandcursor;
cb.tabEnabled = false;
var cr = new Shape();
this.clickregion = cr;
@@ -510,7 +524,7 @@
}
public function setColorTransform(o=null) {
- trace('LzSrpite.setColorTransform not yet implemented');
+ trace('LzSprite.setColorTransform not yet implemented');
}
public function setFontName ( fname:String, prop=null ):void{
@@ -874,13 +888,42 @@
function sendResourceLoad(skiponload = false) {
// skiponload is true for resources/setResource() calls
- this.owner.resourceload({width: this.resourcewidth, height: this.resourceheight, resource: this.resource, skiponload: skiponload});
+ if (this.owner != null) {
+ this.owner.resourceload({width: this.resourcewidth, height: this.resourceheight, resource: this.resource, skiponload: skiponload});
+ }
}
- function setCursor ( c ){
- trace('setCursor not currently implemented in swf9.');
+ var cursorResource:String = null;
+
+ /**
+ * CURSOR is a string naming the resource to be used as the mouse pointer
+ */
+ function setCursor ( cursor:String ){
+ if (cursor == null) return;
+ if (cursor != '') {
+ this.cursorResource = cursor;
+ addEventListener(MouseEvent.MOUSE_OVER, cursorGotMouseover, true);
+ addEventListener(MouseEvent.MOUSE_OUT, cursorGotMouseout, true);
+ this.mouseEnabled = true;
+ } else {
+ LzMouseKernel.restoreCursorLocal();
+ removeEventListener(MouseEvent.MOUSE_OVER, cursorGotMouseover, true);
+ removeEventListener(MouseEvent.MOUSE_OUT, cursorGotMouseout, true);
+ this.cursorResource = null;
+ }
}
+ /** @access private */
+ function cursorGotMouseover (event:MouseEvent) {
+ LzMouseKernel.setCursorLocal(this.cursorResource);
+ }
+
+ /** @access private */
+ function cursorGotMouseout (event:MouseEvent) {
+ LzMouseKernel.restoreCursorLocal();
+ }
+
+
function setVolume (v) {
trace('setVolume not currently implemented in swf9.');
}
@@ -897,8 +940,11 @@
trace('getPan not currently implemented in swf9.');
}
- function setShowHandCursor ( s ){
- trace('setShowHandCursor not currently implemented in swf9.');
+ /**
+
+ */
+ function setShowHandCursor ( s:* ){
+ this.showhandcursor = s;
}
function setAAActive(s) {
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzGlobalMouse.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzGlobalMouse.lzs 2008-08-23 12:51:59 UTC (rev 10746)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzGlobalMouse.lzs 2008-08-23 20:50:30 UTC (rev 10747)
@@ -149,6 +149,12 @@
*/
var onmousedragout = LzDeclaredEvent;
+ /** Sent whenever the mouse is dragged out of the application window
+ * @access public
+ * @lzxtype event
+ */
+ var onmouseleave = LzDeclaredEvent;
+
/** Sent whenever the mouse button is clicked
* @access public
* @lzxtype event
@@ -166,6 +172,7 @@
/** @access private */
function __mouseEvent (eventname, view) {
+ if (eventname == 'onmouseleave') { canvas.onmouseleave.sendEvent(); }
if (eventname == 'onmousemove') { this.__movecounter++; }
var ev = this[eventname];
if (ev) {
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.lzs 2008-08-23 12:51:59 UTC (rev 10746)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloCanvas.lzs 2008-08-23 20:50:30 UTC (rev 10747)
@@ -395,6 +395,8 @@
}
}
+var onmouseleave = LzDeclaredEvent;
+
/** Sent whenever the number of created nodes changes
* @lzxtype event
*/
More information about the Laszlo-checkins
mailing list