Skip to content

Commit 992130f

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 74b25bd + d9ffbae commit 992130f

File tree

9 files changed

+109
-108
lines changed

9 files changed

+109
-108
lines changed

examples/pxScene2d/src/browser.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ px.import({ scene: 'px:scene.1.js',
118118
}
119119

120120

121-
// JRJR BUG BUG
121+
// JRJR BUGBUG
122122
// Promise doesn't seem to fire if url is empty
123123
if (u == '')
124124
spinner.a = 0
@@ -159,7 +159,6 @@ px.import({ scene: 'px:scene.1.js',
159159
}
160160
}
161161

162-
163162
backButton.a = backUrls.length?0.65:0.2
164163
foreButton.a = foreUrls.length?0.65:0.2
165164
}
@@ -208,13 +207,17 @@ px.import({ scene: 'px:scene.1.js',
208207
content.focus=true;
209208
});
210209

210+
// layout
211211
function updateSize(w,h)
212212
{
213213
// console.log("\n\n BROWSER: Resizing... WxH: " + w + " x " + h + " \n\n");
214214

215215
bg.w = w;
216216
bg.h = h;
217217

218+
// show/hide browser chrome
219+
browser.a = showFullscreen ? 0 : 1;
220+
218221
// Anchor
219222
content.x = showFullscreen ? 0 : 10;
220223
content.y = showFullscreen ? 0 : 60;
@@ -324,27 +327,6 @@ px.import({ scene: 'px:scene.1.js',
324327
else if (code == keys.F) // CTRL-ALT-F
325328
{
326329
showFullscreen = !showFullscreen;
327-
328-
/*
329-
if(showFullscreen)
330-
{
331-
content.moveToFront();
332-
}
333-
else
334-
{
335-
browser.moveToFront();
336-
}
337-
*/
338-
339-
browser.draw = showFullscreen ? false : true;
340-
browser.a = showFullscreen ? 0 : 1;
341-
342-
content.x = showFullscreen ? 0 : contentBG.x;
343-
content.y = showFullscreen ? 0 : contentBG.y;
344-
345-
content.w = showFullscreen ? bg.w : contentBG.w;
346-
content.h = showFullscreen ? bg.h : contentBG.h;
347-
348330
updateSize(scene.w, scene.h)
349331
e.stopPropagation()
350332
}

examples/pxScene2d/src/init.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,20 @@ else {
7676
function loadUrl(url) {
7777
var Url = require('url')
7878
var Path = require('path')
79-
var ext = Path.extname(Url.parse(url).pathname)
79+
80+
var ext
81+
82+
if (true) {
83+
var urlParts = Url.parse(url,true)
84+
ext = urlParts.query['_ext']
85+
}
86+
else {
87+
var urlParts = Url.parse(url)
88+
}
89+
90+
if (!ext) {
91+
ext = Path.extname(urlParts.pathname)
92+
}
8093

8194
//console.log('Original Url: ', url)
8295
if (ext=='.md' || ext=='.sd') {
@@ -85,11 +98,24 @@ else {
8598
else if (ext=='.png' || ext == '.jpg' || ext=='.svg') {
8699
url = baseViewerUrl+'/mime/viewImage.js?url='+encodeURIComponent(url)
87100
}
88-
else if (ext=='.txt') {
101+
else if (ext=='.txt' || ext=='.text') {
89102
url = baseViewerUrl+'/mime/viewText.js?url='+encodeURIComponent(url)
90103
}
104+
/*
105+
else if (ext=='.htm' || ext=='.html'){
106+
url = baseViewerUrl+'/mime/viewHTML.js?url='+encodeURIComponent(url)
107+
}
108+
*/
109+
else if (ext=='.js' || ext=='.jar') {
110+
// Do nothing and let the url fall through
111+
}
112+
else {
113+
// TODO Do a HTTP head check to see if we can get a mimetype/contenttype for routing
114+
}
115+
91116
//console.log('Rewritten Url: ', url)
92117

118+
93119
var ctx = new AppSceneContext({ scene: getScene("scene.1"),
94120
makeReady: this.makeReady,
95121
getContextID: this.getContextID,

examples/pxScene2d/src/macstuff/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundlePackageType</key>
2020
<string>APPL</string>
2121
<key>CFBundleShortVersionString</key>
22-
<string>1.3.0.0</string>
22+
<string>1.3.0.2</string>
2323
<key>CFBundleSignature</key>
2424
<string>????</string>
2525
<key>CFBundleVersion</key>

examples/pxScene2d/src/pxScene2d.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,9 +1940,10 @@ pxScene2d::pxScene2d(bool top, pxScriptView* scriptView)
19401940
}
19411941

19421942
mPointerHidden= false;
1943-
#ifdef USE_SCENE_POINTER
19441943
mPointerX= 0;
19451944
mPointerY= 0;
1945+
mPointerLastUpdated= 0;
1946+
#ifdef USE_SCENE_POINTER
19461947
mPointerW= 0;
19471948
mPointerH= 0;
19481949
mPointerHotSpotX= 40;
@@ -2663,12 +2664,22 @@ void pxScene2d::onUpdate(double t)
26632664
mEmit.send("onFPS", e);
26642665
}
26652666

2666-
start = end2; // start of frame
2667+
start = end2; // start of frame
26672668
frameCount = 0;
26682669
}
26692670

26702671
frameCount++;
26712672
}
2673+
2674+
// Periodically let's poke the onMouseMove handler with the current pointer position
2675+
// to better handle objects that animate in or out from under the mouse cursor
2676+
// eg. scrolling
2677+
if (t-mPointerLastUpdated > 1) // Once a second
2678+
{
2679+
updateMouseEntered();
2680+
mPointerLastUpdated = t;
2681+
}
2682+
26722683
#ifdef ENABLE_RT_NODE
26732684
if (mTop)
26742685
{
@@ -3131,9 +3142,10 @@ bool pxScene2d::bubbleEventOnBlur(rtObjectRef e, rtRef<pxObject> t, rtRef<pxObje
31313142

31323143
bool pxScene2d::onMouseMove(int32_t x, int32_t y)
31333144
{
3134-
#ifdef USE_SCENE_POINTER
31353145
mPointerX= x;
3136-
mPointerY= y;
3146+
mPointerY= y;
3147+
#ifdef USE_SCENE_POINTER
3148+
// JRJR this should be passing mouse cursor bounds in rather than dirty entire scene
31373149
invalidateRect(NULL);
31383150
mDirty= true;
31393151
#endif
@@ -3256,17 +3268,32 @@ bool pxScene2d::onMouseMove(int32_t x, int32_t y)
32563268
return false;
32573269
}
32583270

3271+
void pxScene2d::updateMouseEntered()
3272+
{
3273+
#if 1
3274+
pxMatrix4f m;
3275+
pxPoint2f pt(static_cast<float>(mPointerX),static_cast<float>(mPointerY)), hitPt;
3276+
rtRef<pxObject> hit;
3277+
if (mRoot->hitTestInternal(m, pt, hit, hitPt))
3278+
{
3279+
setMouseEntered(hit);
3280+
}
3281+
else
3282+
setMouseEntered(NULL);
3283+
#endif
3284+
}
32593285

32603286
bool pxScene2d::onScrollWheel(float dx, float dy)
32613287
{
3262-
if (mFocusObj)
3288+
if (mMouseEntered)
32633289
{
32643290
rtObjectRef e = new rtMapObject;
32653291
e.set("name", "onScrollWheel");
3292+
e.set("target", mMouseEntered.getPtr());
32663293
e.set("dx", dx);
32673294
e.set("dy", dy);
3268-
rtRef<pxObject> t = (pxObject*)mFocusObj.get<voidPtr>("_pxObject");
3269-
return bubbleEvent(e, t, "onPreScrollWheel", "onScrollWheel");
3295+
3296+
return bubbleEvent(e, mMouseEntered, "onPreScrollWheel", "onScrollWheel");
32703297
}
32713298
return false;
32723299
}

examples/pxScene2d/src/pxScene2d.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,15 @@ class pxViewContainer: public pxObject, public pxIViewContainer
916916
{
917917
float dx = o.get<float>("dx");
918918
float dy = o.get<float>("dy");
919-
mView->onScrollWheel( dx, dy );
919+
bool consumed = mView->onScrollWheel( dx, dy );
920+
if (consumed)
921+
{
922+
rtFunctionRef stopPropagation = o.get<rtFunctionRef>("stopPropagation");
923+
if (stopPropagation)
924+
{
925+
stopPropagation.send();
926+
}
927+
}
920928
}
921929
return RT_OK;
922930
}
@@ -1576,6 +1584,8 @@ class pxScene2d: public rtObject, public pxIView, public rtIServiceProvider
15761584
virtual bool onMouseMove(int32_t x, int32_t y);
15771585
virtual bool onScrollWheel(float dx, float dy);
15781586

1587+
void updateMouseEntered();
1588+
15791589
virtual bool onFocus();
15801590
virtual bool onBlur();
15811591

@@ -1727,12 +1737,14 @@ class pxScene2d: public rtObject, public pxIView, public rtIServiceProvider
17271737
pxScriptView *mScriptView;
17281738
bool mShowDirtyRectangle;
17291739
bool mEnableDirtyRectangles;
1740+
int32_t mPointerX;
1741+
int32_t mPointerY;
1742+
double mPointerLastUpdated;
1743+
17301744
#ifdef USE_SCENE_POINTER
17311745
pxTextureRef mNullTexture;
17321746
rtObjectRef mPointerResource;
17331747
pxTextureRef mPointerTexture;
1734-
int32_t mPointerX;
1735-
int32_t mPointerY;
17361748
int32_t mPointerW;
17371749
int32_t mPointerH;
17381750
int32_t mPointerHotSpotX;

examples/pxScene2d/src/pxTextBox.cpp

Lines changed: 13 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern pxContext context;
3333
static const char isNewline_chars[] = "\n\v\f\r";
3434
static const char isWordBoundary_chars[] = " \t/:&,;.";
3535
static const char isSpaceChar_chars[] = " \t";
36-
static const char isDelimeter_chars[] = "\n\v\f\r \t/:&,;.";
36+
3737
#define ELLIPSIS_STR u8"\u2026"
3838

3939
#if 1
@@ -384,18 +384,6 @@ void pxTextBox::measureTextWithWrapOrNewLine(const char *text, float sx, float s
384384
}
385385
}
386386

387-
std::string str(text);
388-
bool isDelimeter_charsPresent = false;
389-
for (size_t i = 0; i < sizeof(isDelimeter_chars); ++i)
390-
{
391-
std::size_t pos = str.find(isDelimeter_chars[i]);
392-
if (pos != std::string::npos)
393-
{
394-
isDelimeter_charsPresent = true;
395-
break;
396-
}
397-
}
398-
399387
// Read char by char to determine full line of text before rendering
400388
int i = 0;
401389
int lasti = 0;
@@ -413,25 +401,22 @@ void pxTextBox::measureTextWithWrapOrNewLine(const char *text, float sx, float s
413401
{
414402
getFontResource()->measureTextChar(charToMeasure, size, sx, sy, charW, charH);
415403
}
416-
417-
bool isContinuousLine = mWordWrap && !isDelimeter_charsPresent && tempX + charW > mw;
418-
if( isNewline(charToMeasure) || isContinuousLine)
404+
if( isNewline(charToMeasure))
419405
{
420406
//rtLogDebug("Found NEWLINE; calling renderOneLine\n");
421407
// Render what we had so far in accString; since we are here, it will fit.
422-
423408
renderOneLine(accString.cString(), 0, tempY, sx, sy, size, lineWidth, render);
424409

425-
accString = isContinuousLine ? tempChar.c_str() : "";
410+
accString = "";
426411
tempY += (mLeading*sy) + charH;
427412

428413
lineNumber++;
429-
tempX = isContinuousLine ? charW : 0;
430-
continue;
414+
tempX = 0;
415+
continue;
431416
}
432417

433418
// Check if text still fits on this line, or if wrap needs to occur
434-
if( (tempX + charW) <= lineWidth || (!mWordWrap && lineNumber == 0) || (mWordWrap && !isDelimeter_charsPresent))
419+
if( (tempX + charW) <= lineWidth || (!mWordWrap && lineNumber == 0))
435420
{
436421
accString.append(tempChar.c_str());
437422
tempX += charW;
@@ -602,8 +587,7 @@ void pxTextBox::measureTextWithWrapOrNewLine(const char *text, float sx, float s
602587
startY = my + (mh - textHeight); // could be negative
603588
if(!clip() && mTruncation == pxConstantsTruncation::NONE)
604589
{
605-
noClipY = my + (mh - textHeight);
606-
startY = my;
590+
noClipY = my;
607591
noClipH = textHeight;//mh;
608592
}
609593
}
@@ -627,8 +611,7 @@ void pxTextBox::measureTextWithWrapOrNewLine(const char *text, float sx, float s
627611
startY = my + (mh - textHeight)/2;
628612
if(!clip() && mTruncation == pxConstantsTruncation::NONE)
629613
{
630-
noClipY = my + (mh - textHeight)/2;
631-
startY = my;
614+
noClipY = my;
632615
noClipH = textHeight;
633616
}
634617
}
@@ -834,13 +817,8 @@ void pxTextBox::renderOneLine(const char * tempStr, float tempX, float tempY, fl
834817
if( lineNumber == lastLineNumber || mTruncation == pxConstantsTruncation::NONE)
835818
{
836819
//rtLogDebug("!CLF: calculating lineMeasurement! charH=%f pixelSize=%d noClipH=%f noClipY=%f lineNumber=%d\n",charH,mPixelSize,noClipH, noClipY, lineNumber);
837-
838-
//setLineMeasurements(false, xPos+charW, noClipY+noClipH-(noClipH/(lineNumber+1)));
839-
840-
setLineMeasurements(true, xPos, noClipY);
841-
setLineMeasurements(false, xPos+charW, noClipY + (noClipH - charH));
842-
843-
setMeasurementBoundsX(false, charW );
820+
setLineMeasurements(false, xPos+charW, noClipY+noClipH-(noClipH/(lineNumber+1)));
821+
setMeasurementBoundsX(false, charW );
844822
}
845823
}
846824
else
@@ -1094,39 +1072,12 @@ void pxTextBox::renderTextNoWordWrap(float sx, float sy, float tempX, bool rende
10941072
getFontResource()->getHeight(mPixelSize, metricHeight);
10951073
}
10961074
//rtLogDebug(">>>>>>>>>>>>>> metric height is %f and charH is %f\n", metricHeight, charH);
1097-
std::string str(mText);
1075+
10981076
if( charH > metricHeight) // There's a newline in the text somewhere
1099-
{
1100-
if (!mWordWrap && mTruncation != pxConstantsTruncation::NONE)
1101-
{
1102-
for (size_t i = 0; i < sizeof(isNewline_chars); ++i)
1103-
{
1104-
std::size_t pos = str.find(isNewline_chars[i]);
1105-
if (pos != std::string::npos)
1106-
{
1107-
str = str.substr (0, pos);
1108-
if (getFontResource() != NULL)
1109-
{
1110-
getFontResource()->measureTextInternal(str.c_str(), mPixelSize, sx, sy, charW, charH);
1111-
}
1112-
//rtLogDebug(">>>>>>>>>>>> pxTextBox::renderTextNoWordWrap charH=%f charW=%f\n", charH, charW);
1113-
1114-
metricHeight = 0;
1115-
if (getFontResource() != NULL)
1116-
{
1117-
getFontResource()->getHeight(mPixelSize, metricHeight);
1118-
}
1119-
}
1120-
}
1121-
}
1122-
}
1123-
1124-
/*rtString text*/ mText = str.c_str();
1125-
if( charH > metricHeight)
11261077
{
11271078
lineNumber = 0;
1128-
//noClipH = charH;
1129-
// noClipW = charW;
1079+
noClipH = charH;
1080+
// noClipW = charW;
11301081
float tempY = 0;
11311082
measureTextWithWrapOrNewLine(mText, sx, sy, tempX, tempY, mPixelSize, render);
11321083
}

0 commit comments

Comments
 (0)