diff --git a/examples/pxScene2d/src/browser.js b/examples/pxScene2d/src/browser.js index d38964b247..57f907d861 100644 --- a/examples/pxScene2d/src/browser.js +++ b/examples/pxScene2d/src/browser.js @@ -118,7 +118,7 @@ px.import({ scene: 'px:scene.1.js', } - // JRJR BUG BUG + // JRJR BUGBUG // Promise doesn't seem to fire if url is empty if (u == '') spinner.a = 0 @@ -159,7 +159,6 @@ px.import({ scene: 'px:scene.1.js', } } - backButton.a = backUrls.length?0.65:0.2 foreButton.a = foreUrls.length?0.65:0.2 } @@ -208,6 +207,7 @@ px.import({ scene: 'px:scene.1.js', content.focus=true; }); + // layout function updateSize(w,h) { // console.log("\n\n BROWSER: Resizing... WxH: " + w + " x " + h + " \n\n"); @@ -215,6 +215,9 @@ px.import({ scene: 'px:scene.1.js', bg.w = w; bg.h = h; + // show/hide browser chrome + browser.a = showFullscreen ? 0 : 1; + // Anchor content.x = showFullscreen ? 0 : 10; content.y = showFullscreen ? 0 : 60; @@ -324,27 +327,6 @@ px.import({ scene: 'px:scene.1.js', else if (code == keys.F) // CTRL-ALT-F { showFullscreen = !showFullscreen; - - /* - if(showFullscreen) - { - content.moveToFront(); - } - else - { - browser.moveToFront(); - } - */ - - browser.draw = showFullscreen ? false : true; - browser.a = showFullscreen ? 0 : 1; - - content.x = showFullscreen ? 0 : contentBG.x; - content.y = showFullscreen ? 0 : contentBG.y; - - content.w = showFullscreen ? bg.w : contentBG.w; - content.h = showFullscreen ? bg.h : contentBG.h; - updateSize(scene.w, scene.h) e.stopPropagation() } diff --git a/examples/pxScene2d/src/init.js b/examples/pxScene2d/src/init.js index 442ccfbf05..2a3d4f803f 100644 --- a/examples/pxScene2d/src/init.js +++ b/examples/pxScene2d/src/init.js @@ -76,7 +76,20 @@ else { function loadUrl(url) { var Url = require('url') var Path = require('path') - var ext = Path.extname(Url.parse(url).pathname) + + var ext + + if (false) { + var urlParts = Url.parse(url,true) + ext = urlParts.query['_ext'] + } + else { + var urlParts = Url.parse(url) + } + + if (!ext) { + ext = Path.extname(urlParts.pathname) + } //console.log('Original Url: ', url) if (ext=='.md' || ext=='.sd') { @@ -85,11 +98,24 @@ else { else if (ext=='.png' || ext == '.jpg' || ext=='.svg') { url = baseViewerUrl+'/mime/viewImage.js?url='+encodeURIComponent(url) } - else if (ext=='.txt') { + else if (ext=='.txt' || ext=='.text') { url = baseViewerUrl+'/mime/viewText.js?url='+encodeURIComponent(url) } + /* + else if (ext=='.htm' || ext=='.html'){ + url = baseViewerUrl+'/mime/viewHTML.js?url='+encodeURIComponent(url) + } + */ + else if (ext=='.js' || ext=='.jar') { + // Do nothing and let the url fall through + } + else { + // TODO Do a HTTP head check to see if we can get a mimetype/contenttype for routing + } + //console.log('Rewritten Url: ', url) + var ctx = new AppSceneContext({ scene: getScene("scene.1"), makeReady: this.makeReady, getContextID: this.getContextID, diff --git a/examples/pxScene2d/src/pxScene2d.cpp b/examples/pxScene2d/src/pxScene2d.cpp index 9eb046013c..d808369313 100644 --- a/examples/pxScene2d/src/pxScene2d.cpp +++ b/examples/pxScene2d/src/pxScene2d.cpp @@ -1940,9 +1940,10 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView) } mPointerHidden= false; - #ifdef USE_SCENE_POINTER mPointerX= 0; mPointerY= 0; + mPointerLastUpdated= 0; + #ifdef USE_SCENE_POINTER mPointerW= 0; mPointerH= 0; mPointerHotSpotX= 40; @@ -2663,12 +2664,22 @@ void pxScene2d::onUpdate(double t) mEmit.send("onFPS", e); } - start = end2; // start of frame + start = end2; // start of frame frameCount = 0; } frameCount++; } + + // Periodically let's poke the onMouseMove handler with the current pointer position + // to better handle objects that animate in or out from under the mouse cursor + // eg. scrolling + if (t-mPointerLastUpdated > 1) // Once a second + { + updateMouseEntered(); + mPointerLastUpdated = t; + } + #ifdef ENABLE_RT_NODE if (mTop) { @@ -3131,9 +3142,10 @@ bool pxScene2d::bubbleEventOnBlur(rtObjectRef e, rtRef t, rtRef(mPointerX),static_cast(mPointerY)), hitPt; + rtRef hit; + if (mRoot->hitTestInternal(m, pt, hit, hitPt)) + { + setMouseEntered(hit); + } + else + setMouseEntered(NULL); + #endif +} bool pxScene2d::onScrollWheel(float dx, float dy) { - if (mFocusObj) + if (mMouseEntered) { rtObjectRef e = new rtMapObject; e.set("name", "onScrollWheel"); + e.set("target", mMouseEntered.getPtr()); e.set("dx", dx); e.set("dy", dy); - rtRef t = (pxObject*)mFocusObj.get("_pxObject"); - return bubbleEvent(e, t, "onPreScrollWheel", "onScrollWheel"); + + return bubbleEvent(e, mMouseEntered, "onPreScrollWheel", "onScrollWheel"); } return false; } diff --git a/examples/pxScene2d/src/pxScene2d.h b/examples/pxScene2d/src/pxScene2d.h index 1278de4589..9f58512f04 100644 --- a/examples/pxScene2d/src/pxScene2d.h +++ b/examples/pxScene2d/src/pxScene2d.h @@ -916,7 +916,15 @@ class pxViewContainer: public pxObject, public pxIViewContainer { float dx = o.get("dx"); float dy = o.get("dy"); - mView->onScrollWheel( dx, dy ); + bool consumed = mView->onScrollWheel( dx, dy ); + if (consumed) + { + rtFunctionRef stopPropagation = o.get("stopPropagation"); + if (stopPropagation) + { + stopPropagation.send(); + } + } } return RT_OK; } @@ -1576,6 +1584,8 @@ class pxScene2d: public rtObject, public pxIView, public rtIServiceProvider virtual bool onMouseMove(int32_t x, int32_t y); virtual bool onScrollWheel(float dx, float dy); + void updateMouseEntered(); + virtual bool onFocus(); virtual bool onBlur(); @@ -1727,12 +1737,14 @@ class pxScene2d: public rtObject, public pxIView, public rtIServiceProvider pxScriptView *mScriptView; bool mShowDirtyRectangle; bool mEnableDirtyRectangles; + int32_t mPointerX; + int32_t mPointerY; + double mPointerLastUpdated; + #ifdef USE_SCENE_POINTER pxTextureRef mNullTexture; rtObjectRef mPointerResource; pxTextureRef mPointerTexture; - int32_t mPointerX; - int32_t mPointerY; int32_t mPointerW; int32_t mPointerH; int32_t mPointerHotSpotX;