From 96bc549ed8f1d11397a31e73b85f1c8598213c52 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 11 Feb 2015 16:15:11 -0800 Subject: [PATCH] Legacy sync --- legacy/project/include/Font.h | 2 +- legacy/project/include/TextField.h | 2 +- legacy/project/src/common/Hardware.cpp | 418 ++++++++++++++++++------- legacy/project/src/common/Utils.cpp | 61 ++-- legacy/project/src/sdl2/SDL2Stage.cpp | 12 +- 5 files changed, 342 insertions(+), 153 deletions(-) diff --git a/legacy/project/include/Font.h b/legacy/project/include/Font.h index a5cbb3874..8c6d12656 100644 --- a/legacy/project/include/Font.h +++ b/legacy/project/include/Font.h @@ -217,4 +217,4 @@ class FontCache } // end namespace nme -#endif \ No newline at end of file +#endif diff --git a/legacy/project/include/TextField.h b/legacy/project/include/TextField.h index 7834eadc3..bce22ab93 100644 --- a/legacy/project/include/TextField.h +++ b/legacy/project/include/TextField.h @@ -226,4 +226,4 @@ private: } // end namespace nme -#endif \ No newline at end of file +#endif diff --git a/legacy/project/src/common/Hardware.cpp b/legacy/project/src/common/Hardware.cpp index 524682d7a..85d01f74f 100644 --- a/legacy/project/src/common/Hardware.cpp +++ b/legacy/project/src/common/Hardware.cpp @@ -6,7 +6,6 @@ #define M_PI 3.14159265358979323846 #endif - namespace nme { @@ -103,8 +102,8 @@ public: mPerpLen = stroke->thickness * 0.5; if (mPerpLen<=0.0) { - mPerpLen = 0.5; - mElement.mWidth = 1.0; + mPerpLen = 0.5/mScale; + mElement.mWidth = 1.0/mScale; } mCaps = stroke->caps; @@ -119,7 +118,7 @@ public: mElement.mWidth = 1.0/mScale; } - if (alphaAA && !DEBUG_FAT_LINES) + if (alphaAA) { mPerpLen += 0.5/mScale; mElement.mWidth += 1.0/mScale; @@ -865,7 +864,7 @@ public: void AddArc(Curves &outCurve, UserPoint inP, double angle, UserPoint inVx, UserPoint inVy, float t) { - int steps = 1 + mPerpLen*angle*3; + int steps = 1 + mPerpLen*mScale*angle*3; if (steps>60) steps = 60; double d_theta = angle / (steps+1); @@ -900,23 +899,39 @@ public: - void cleanCurve(Curves &curve,bool inLoop) + void cleanCurve(Curves &curve,bool inLoop,double inSide) { + bool debug = false; + double oT = curve[ curve.size()-1 ].t + 1; + + if (DEBUG_KEEP_LOOPS) + { + if (inLoop) + curve.push_back( CurveEdge( curve[0].p, oT) ); + return; + } + double perp2 = mPerpLen*mPerpLen*4.0; - for(int startPoint=0; startPoint perp2 && l0.Dist2(p1) > perp2 ) + // Distance from testPoint to line-segment l1-l0 + // testPoint = l0 + alpha * dp + UserPoint dTest = l0-p0; + double perp = dTest.x*dpY - dTest.y*dpX; + //if (perp<0 || perp > mPerpLen*2) + if (perp*perp > perp2) break; - const UserPoint &l1 = curve[testPoint+1].p; + const UserPoint &l1 = curve[testNext].p; if ( (l0.xmaxX && l1.x>maxX) || (l0.y=0 && a<=1) equals case? { - if (a>0 && a<1 && b>0 && b<1) + if (a>=0 && a<=1) { UserPoint p = p0 + dp*a; - // Remove the loop - // c[startPoint] - // p <- new point between c[startPoint] and c[startPoint+1] - // c[startPoint+1] - // c[startPoint+2] - // ... - // c[testPoint] - // p <- new point between c[testPoint] and c[testPoint+1] - // c[testPoint+1] + // Calculate loop-sense ... + double sense = 0.0; + int end = testPoint; + if (end0) // figure-8 intersection Ok.... + { + continue; + } + else + if (testNext>1].t; + curve.EraseAt(0, testPoint); + // Done + } + else if (testPoint>1].t; + //curve.EraseAt(startNext,curve.size()); + oT = curve[startNext].t; + curve.resize(startNext); + curve.EraseAt(0,testPoint); + startPoint-= testPoint; + startPoint--; + } + else + { + // Remove the loop + // c[testNext] <- p + // ... + // c[startPoint] + // c[startNext] + // ... + // c[testPoint] + curve[testNext].p = p; + oT = curve[startNext].t; + curve.EraseAt(startNext,curve.size()); + startPoint--; + } + } + else + { + // Remove the loop + // c[startPoint] + // c[startNext] + // ... + // c[testPoint] <- p + // c[testNext] + // ... + curve[testPoint].p = p; + curve[testPoint].t = curve[ (startNext+testPoint) >> 1].t; + curve.EraseAt(startNext,testPoint); + startPoint -=1; + if (startPoint<-1) startPoint = -1; + } + // Try again... + break; } } } } } } + + + /* + double sense = 0; + if (inLoop) + { + int n = inPath.size(); + for(int i=0;i1 && curve[ curve.size()-1].p != curve[0].p) + curve.push_back( CurveEdge( curve[0].p, oT) ); } @@ -1177,29 +1297,39 @@ public: } } - UserPoint CalcNormalInfo(const UserPoint &base, UserPoint prev, UserPoint p, float inSign, bool inAllowSmaller) + bool ComputeDistInfo(const UserPoint &otherSide, const UserPoint &prev, const UserPoint &p, + UserPoint &outSideInfo, UserPoint &outInfo, double inSign) { /* prev p - +------------------+ - | / - | _/ - | / - | / - | / - | / - base + ^ +------------------+ + | +-----------------/+ +Feather zone + | | / + | | _/ + h |- - - - - / Zero line + | | / + | | / + | |-- + v |. -Feather Zone + otherSide - Thickness at p = perp distance from base to prev->p + h = perpendicular height */ - float dist = fabs( (p-base).Dot( (p-prev).Perp(1.0) ) ); - if (!inAllowSmaller && dist 1.0; } void AddStrip(const QuickVec &inPath, bool inLoop) @@ -1207,12 +1337,22 @@ public: if (inPath.size()<2) return; + + // Allow shrinking to half the size + float s = mScale * 0.5; + if (data.mMinScale==0 || s>data.mMinScale) + data.mMinScale = s; + + // And growing to 1.41 the size ... + s = mScale * 1.41; + if (data.mMaxScale==0 || s 1.0 && (mJoints==sjRound || mJoints==sjMiter); + for(int i=1;i1 && (mJoints==sjRound || mJoints==sjMiter) && (reversed || fabs(next_dir.Cross(dir1))>0.25 ) ) + else if ( fancyJoints && angle<0.9 ) { /* @@ -1372,14 +1509,6 @@ public: } } t+=1.0; - - float turnLeft = seg.isCurve() ? segJoinLeft - 0.66 : 0; - float turnRight = seg.isCurve() ? segJoinRight - 0.66 : 0; - removeLoops(leftCurve,prevSegLeft,turnLeft,&segStartLeft); - removeLoops(rightCurve,prevSegRight,turnRight,&segStartRight); - - prevSegLeft = segStartLeft; - prevSegRight = segStartRight; } // Endcap end ... @@ -1388,25 +1517,43 @@ public: EndCap(leftCurve, rightCurve, p, dir1.Perp(mPerpLen),t); } - removeLoops(leftCurve,prevSegLeft,0); - removeLoops(rightCurve,prevSegRight,0); + cleanCurve(leftCurve,inLoop,-1); + cleanCurve(rightCurve,inLoop,1); - if (DEBUG_KEEP_LOOPS==2) - { - cleanCurve(leftCurve,inLoop); - cleanCurve(rightCurve,inLoop); - } - - - if (leftCurve.size()<2 || rightCurve.size()<2) + if (leftCurve.size()<1 || rightCurve.size()<1) + return; + if (leftCurve.size()<3 && rightCurve.size()<3) return; bool useTriStrip = true; bool keepTriSense = true; - if (DEBUG_FAT_LINES) + bool debug = false; + /* + if (debug) { + printf("Left %d\n", leftCurve.size()); + for(int i=0;i=leftCurve.size() || (right=0) - { + bool forceTri = ComputeDistInfo(pLeft, pRight, test, leftNormal, rightNormal, 1); + + if (!useTriStrip) { *v = pRight; Next(v); if (normal) - { *normal = rightNormal; Next(normal); } + { + *normal = rightNormal; + Next(normal); + } *v = pLeft; Next(v); if (normal) - { *normal = leftNormal; Next(normal); } + { + *normal = leftNormal; + Next(normal); + } added+=2; } - else if (keepTriSense && prevEdge!=PREV_LEFT) + else { - *v = pLeft; Next(v); - if (normal) - { *normal = leftNormal; Next(normal); } - added++; + if (added==0) + { + *v = pLeft; Next(v); + if (normal) + { *normal = leftNormal; Next(normal); } + + *v = pRight; Next(v); + if (normal) + { *normal = rightNormal; Next(normal); } + added += 2; + } + else if (forceTri || (keepTriSense && prevEdge!=PREV_LEFT)) + { + if (prevEdge==PREV_LEFT) + { + *v = pRight; Next(v); + if (normal) + { *normal = rightNormal; Next(normal); } + added++; + } + + *v = pLeft; Next(v); + if (normal) + { *normal = leftNormal; Next(normal); } + added++; + } } + added++; if (normal) { - *normal = rightNormal = CalcNormalInfo(pLeft, pRight, test, 1.0, testT<1 ||testT>=t); + *normal = rightNormal; Next(normal); } *v = pRight = test; Next(v); prevEdge = PREV_RIGHT; - } } else { float testT = rightCurve[left].t; UserPoint test = leftCurve[left++].p; - if ( mPerpLen=0) - { + bool forceTri = ComputeDistInfo(pRight, pLeft, test, rightNormal, leftNormal, -1); + if (!useTriStrip) { *v = pRight; Next(v); @@ -1527,24 +1695,46 @@ public: { *normal = leftNormal; Next(normal); } added+=2; } - else if (keepTriSense && prevEdge!=PREV_RIGHT) + else { - *v = pRight; Next(v); - if (normal) - { *normal = rightNormal; Next(normal); } - added++; + if (added==0) + { + *v = pLeft; Next(v); + if (normal) + { *normal = leftNormal; Next(normal); } + + *v = pRight; Next(v); + if (normal) + { *normal = rightNormal; Next(normal); } + + added+=2; + } + else if (forceTri || (keepTriSense && prevEdge!=PREV_RIGHT)) + { + if (prevEdge==PREV_RIGHT) + { + *v = pLeft; Next(v); + if (normal) + { *normal = leftNormal; Next(normal); } + added++; + } + + *v = pRight; Next(v); + if (normal) + { *normal = rightNormal; Next(normal); } + added++; + } } - + added++; if (normal) { - *normal = leftNormal = CalcNormalInfo(pRight, pLeft, test, -1.0, testT<1 || testT>=t); + *normal = leftNormal; Next(normal); } *v = pLeft = test; Next(v); prevEdge = PREV_LEFT; - } } } @@ -1661,14 +1851,6 @@ public: if (strip.size()>1) { - float s = mScale * 0.707; - if (data.mMinScale==0 || s>data.mMinScale) - data.mMinScale = s; - - s = mScale * 1.41; - if (data.mMaxScale==0 || s -#include #endif #ifdef TIZEN @@ -198,39 +197,47 @@ std::string WideToUTF8(const WString &inWideString) #endif +void NumberToWide(WString &outResult, bool inNegative, unsigned int value, int inBase) +{ + const char *chars = "0123456789ABCDEF"; + wchar_t buffer[16]; + int pos = 0; + + if (value==0) + { + buffer[pos++]=chars[0]; + } + else + { + if (inNegative) + buffer[pos++] = '-'; + + char reverseDigits[16]; + int rpos = 0; + while(value>0) + { + reverseDigits[rpos++] = chars[value%inBase]; + value /= inBase; + } + while(rpos>0) + buffer[pos++] = reverseDigits[--rpos]; + } + + outResult = WString( buffer, pos ); +} WString IntToWide(int value) { - #ifdef ANDROID - std::wstringstream wss; - wss << value; - return WString(wss.str().c_str()); - #else - wchar_t buffer[16]; - #ifdef __MINGW32__ - swprintf(buffer, L"%i", value); - #else - swprintf(buffer, 16, L"%i", value); - #endif - return WString(buffer); - #endif + WString result; + NumberToWide(result, value<0, abs(value), 10); + return result; } WString ColorToWide(int value) { - #ifdef ANDROID - std::wstringstream wss; - wss << value; - return WString(wss.str().c_str()); - #else - wchar_t buffer[40]; - #ifdef __MINGW32__ - swprintf(buffer, L"%X", value); - #else - swprintf(buffer, 40, L"%X", value); - #endif - return WString(buffer); - #endif + WString result; + NumberToWide(result, false, (unsigned int)value, 16); + return result; } diff --git a/legacy/project/src/sdl2/SDL2Stage.cpp b/legacy/project/src/sdl2/SDL2Stage.cpp index cccc9b013..361450884 100644 --- a/legacy/project/src/sdl2/SDL2Stage.cpp +++ b/legacy/project/src/sdl2/SDL2Stage.cpp @@ -1503,21 +1503,21 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, window = NULL; } - window = SDL_CreateWindow (inTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, setWidth, setHeight, requestWindowFlags); + window = SDL_CreateWindow(inTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, setWidth, setHeight, requestWindowFlags); #ifdef HX_WINDOWS - HINSTANCE handle = ::GetModuleHandle (nullptr); - HICON icon = ::LoadIcon (handle, MAKEINTRESOURCE (1)); + HINSTANCE handle = ::GetModuleHandle(0); + HICON icon = ::LoadIcon(handle, MAKEINTRESOURCE (1)); - if (icon != nullptr) + if (icon) { SDL_SysWMinfo wminfo; SDL_VERSION (&wminfo.version); - if (SDL_GetWindowWMInfo (window, &wminfo) == 1) + if (SDL_GetWindowWMInfo(window, &wminfo) == 1) { HWND hwnd = wminfo.info.win.window; - ::SetClassLong (hwnd, GCL_HICON, reinterpret_cast(icon)); + ::SetClassLong(hwnd, GCL_HICON, reinterpret_cast(icon)); } } #endif