Skip to content

Commit

Permalink
Merge pull request pxscene#1589 from johnrobinsn/master
Browse files Browse the repository at this point in the history
More browser.js patches
  • Loading branch information
johnrobinsn authored Nov 30, 2018
2 parents 94c37cd + 287416c commit b3c1913
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 35 deletions.
28 changes: 5 additions & 23 deletions examples/pxScene2d/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -208,13 +207,17 @@ 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");

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;
Expand Down Expand Up @@ -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()
}
Expand Down
30 changes: 28 additions & 2 deletions examples/pxScene2d/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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,
Expand Down
41 changes: 34 additions & 7 deletions examples/pxScene2d/src/pxScene2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -3131,9 +3142,10 @@ bool pxScene2d::bubbleEventOnBlur(rtObjectRef e, rtRef<pxObject> t, rtRef<pxObje

bool pxScene2d::onMouseMove(int32_t x, int32_t y)
{
#ifdef USE_SCENE_POINTER
mPointerX= x;
mPointerY= y;
mPointerY= y;
#ifdef USE_SCENE_POINTER
// JRJR this should be passing mouse cursor bounds in rather than dirty entire scene
invalidateRect(NULL);
mDirty= true;
#endif
Expand Down Expand Up @@ -3256,17 +3268,32 @@ bool pxScene2d::onMouseMove(int32_t x, int32_t y)
return false;
}

void pxScene2d::updateMouseEntered()
{
#if 1
pxMatrix4f m;
pxPoint2f pt(static_cast<float>(mPointerX),static_cast<float>(mPointerY)), hitPt;
rtRef<pxObject> 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<pxObject> t = (pxObject*)mFocusObj.get<voidPtr>("_pxObject");
return bubbleEvent(e, t, "onPreScrollWheel", "onScrollWheel");

return bubbleEvent(e, mMouseEntered, "onPreScrollWheel", "onScrollWheel");
}
return false;
}
Expand Down
18 changes: 15 additions & 3 deletions examples/pxScene2d/src/pxScene2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,15 @@ class pxViewContainer: public pxObject, public pxIViewContainer
{
float dx = o.get<float>("dx");
float dy = o.get<float>("dy");
mView->onScrollWheel( dx, dy );
bool consumed = mView->onScrollWheel( dx, dy );
if (consumed)
{
rtFunctionRef stopPropagation = o.get<rtFunctionRef>("stopPropagation");
if (stopPropagation)
{
stopPropagation.send();
}
}
}
return RT_OK;
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b3c1913

Please sign in to comment.