void nuiRect::RoundToSmallest() { mLeft = (nuiSize)ToAbove(mLeft ); mRight = (nuiSize)ToBelow(mRight ); mTop = (nuiSize)ToAbove(mTop ); mBottom = (nuiSize)ToBelow(mBottom); }
void nuiGLPainter::SetViewport() { //GetAngle(), GetCurrentWidth(), GetCurrentHeight(), mProjectionViewportStack.top(), mProjectionMatrixStack.top()); GLuint Angle = GetAngle(); GLuint Width = GetCurrentWidth(); GLuint Height = GetCurrentHeight(); const nuiRect& rViewport(mProjectionViewportStack.top()); const nuiMatrix& rMatrix = mProjectionMatrixStack.top(); uint32 x, y, w, h; nuiRect r(rViewport); if (Angle == 90 || Angle == 270) { uint32 tmp = Width; Width = Height; Height = tmp; r.Set(r.Top(), r.Left(), r.GetHeight(), r.GetWidth()); } x = ToBelow(r.Left()); w = ToBelow(r.GetWidth()); y = Height - ToBelow(r.Bottom()); h = ToBelow(r.GetHeight()); //printf("set projection matrix (%d %d - %d %d)\n", x, y, w, h); glViewport(x * NUI_SCALE_FACTOR, y * NUI_SCALE_FACTOR, w * NUI_SCALE_FACTOR, h * NUI_SCALE_FACTOR); nuiCheckForGLErrors(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glScalef(NUI_SCALE_FACTOR, NUI_SCALE_FACTOR, 1.0f); if (Angle != 0.0f) { glRotatef(Angle, 0.f,0.f,1.f); glMultMatrixf(rMatrix.Array); } else { glLoadMatrixf(rMatrix.Array); } nuiCheckForGLErrors(); glMatrixMode (GL_MODELVIEW); nuiCheckForGLErrors(); }
void nuiSprite::GetSpritesAtPoint(float x, float y, std::vector<nuiSprite*>& rSprites) { CheckValid(); nuiVector ov(x, y, 0); nuiMatrix m; GetMatrix(m); m.Invert(); nuiVector v = m * ov; x = v[0]; y = v[1]; const nuiSpriteAnimation* pAnim = mpSpriteDef->GetAnimation(mCurrentAnimation); const nuiSpriteFrame* pFrame = pAnim->GetFrame(ToBelow(mCurrentFrame)); nuiRect dst(pFrame->GetRect()); dst.Move(-pFrame->GetHandleX(), -pFrame->GetHandleY()); if (dst.IsInside(x, y)) rSprites.push_back(this); uint32 s = mpChildren.size(); for (size_t i = 0; i < s; i++) { mpChildren[i]->GetSpritesAtPoint(x, y, rSprites); } }
void nuiSprite::Draw(nuiDrawContext* pContext) { CheckValid(); nuiMatrix m; GetMatrix(m); pContext->PushMatrix(); pContext->MultMatrix(m); const nuiSpriteAnimation* pAnim = mpSpriteDef->GetAnimation(mCurrentAnimation); const nuiSpriteFrame* pFrame = pAnim->GetFrame(ToBelow(mCurrentFrame)); nuiRect src(pFrame->GetRect()); nuiRect dst(src); dst.Move(-pFrame->GetHandleX(), -pFrame->GetHandleY()); nuiTexture* pTex = pFrame->GetTexture(); pContext->EnableBlending(true); pContext->SetBlendFunc(mBlendFunc); nuiColor c = mColor; c.Multiply(mAlpha); pContext->SetFillColor(c); pContext->SetTexture(pFrame->GetTexture()); // #TEST Meeloo //dst.Grow(dst.GetWidth() * -.25, dst.GetHeight() * -.25); pContext->DrawImage(dst, src); pContext->PopMatrix(); for (size_t i = 0; i < mpChildren.size(); i++) mpChildren[i]->Draw(pContext); }
void nuiGLDrawContext::StartRendering(nuiSize ClipOffsetX, nuiSize ClipOffsetY) { mpContext->BeginSession(); mClipOffsetX = ClipOffsetX; mClipOffsetY = ClipOffsetY; glMatrixMode(GL_PROJECTION); glViewport(0,0, ToBelow(mWidth), ToBelow(mHeight)); glLoadIdentity(); // glScalef (1, -1, 1); glTranslatef(-1.0f, 1.0f, 0.0f ); glScalef (2.0f/mWidth, -2.0f/mHeight, 1.0f); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); }
bool nglTimer::SetPeriod(nglTime Period) { if (mRunning) return false; mPeriod = Period; mRoundsPerTick = ToBelow(mPeriod / GetMinPeriod()); if (!mRoundsPerTick) mRoundsPerTick = 1; return true; }
nglString TimeToString(double seconds) { uint32 s = ToBelow(seconds); uint32 m = s / 60; s -= m * 60; uint32 h = m / 60; m -= h * 60; nglString res; res.Format("%d:%02d:%02d", h, m, s); return res; }
bool nglTimer::SetPeriod(nglTime Period) { if (mRunning) { return false; } mPeriod = MAX(TIMER_MIN_PERIOD, Period.GetValue()); mRoundsPerTick = ToBelow(mPeriod.GetValue() / (DispatchPeriod / 1000.0)); if (!mRoundsPerTick) mRoundsPerTick = 1; return true; }
bool nuiSWF::MouseUnclicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { mButtons &= ~GetMouseButtons(Button); mpMovieInterface->notify_mouse_state(ToBelow(X), ToBelow(Y), mButtons); return mInterceptMouse; }
nuiTexture* nuiGradient::CreateTexture(int32 size, nglImagePixelFormat format) const { // int32 bpp = 32; // switch (format) // { // case eImagePixelRGB: // { // bpp = 24; // } // break; // case eImagePixelRGBA: // { // bpp = 32; // } // break; // case eImagePixelAlpha: // case eImagePixelLum: // { // bpp = 8; // } // break; // case eImagePixelLumA: // { // bpp = 16; // } // break; // } format = eImagePixelRGBA; nglImageInfo imageinfo(size, 1, 32); imageinfo.mPixelFormat = format; imageinfo.AllocateBuffer(); uint32* pBuffer = (uint32*)imageinfo.mpBuffer; nuiGradientStopList::const_iterator it = mStops.begin(); nuiGradientStopList::const_iterator end = mStops.end(); if (it == end) memset(pBuffer, 0, size * 4); float pos0 = 0; nuiColor col0 = it->second; while (it != end) { float pos1 = it->first; nuiColor col1 = it->second; int32 ipos0 = ToBelow(pos0 * size); int32 ipos1 = ToBelow(pos1 * size); float r = 0; const float incr = 1.0f / (ipos1 - ipos0); for (int32 i = ipos0; i < ipos1; i++) { nuiColor col(col1); col.Mix(col0, r); r += incr; *pBuffer = col.GetRGBA(); pBuffer++; } pos0 = pos1; col0 = col1; ++it; } if (pos0 < 1) { // fill to the end of the line: float pos1 = 1; int32 ipos0 = ToBelow(pos0 * size); int32 ipos1 = ToBelow(pos1 * size); float r = 0; const float incr = 1.0f / (ipos1 - ipos0); for (int32 i = ipos0; i < ipos1; i++) { *pBuffer = col0.GetRGBA(); pBuffer++; } } nglImage* pImage = new nglImage(imageinfo); nuiTexture* pTexture = nuiTexture::GetTexture(pImage, true); return pTexture; }
bool nuiCoverFlow::Draw(nuiDrawContext* pContext) { int32 image = ToBelow(mPos); float fractional = mPos - image; float fract = 1.0 - fractional; //NGL_OUT(_T("image: %d\npos: %f\nfractionnal: %f\nfract: %f\n\n"), image, mPos, fractional, fract); pContext->EnableBlending(true); pContext->SetBlendFunc(nuiBlendTransp); nuiRect rect(GetRect().Size()); if (mDrawBackground) { // Draw a rectangle with the background color: pContext->SetFillColor(mBackground); pContext->DrawRect(rect, eFillShape); } if (mImages.empty()) return true; float aspectratio = rect.GetWidth() / rect.GetHeight(); pContext->PushProjectionMatrix(); //LocalToGlobal(rect); pContext->SetPerspectiveProjectionMatrix(rect, 25, aspectratio, .2, 20); pContext->PushMatrix(); pContext->LoadIdentity(); pContext->Translate(0, -.5, -2); // pContext->ResetClipRect(); float height = mRect.GetHeight(); float width = mRect.GetWidth(); float top = height * .05; float bot = height - 100; float h = bot - top; float w = h; float left = (width - w) * .5; float right = width - left; float halfwidth = left * .8; float sidewidth = w * .1; float sidespace = sidewidth * .5; int32 maxcount = ToBelow(halfwidth / sidespace); int32 size = mImages.size(); int32 maxcountleft = MIN(maxcount, MAX(0, image)); int32 maxcountright = MIN(maxcount, size - 2 - image); nuiRect r(left, top, w, h); float start = mReflectionStart; float end = mReflectionEnd; pContext->Scale(1.0f, -1.0f, 1.0f); const float SIDE_SHIFT = mSideShift; const float SIDE_GAP = mSideGap; const float DEPTH_SHIFT = mSideDepth; const float ANGLE = mAngle; for (int32 i = 0; i < 2; i++) { { int32 s = image + 1; for (int32 l = s + maxcountright, c = maxcountright; c >= 0; l--, c--) { pContext->PushMatrix(); float shiftx = c * SIDE_GAP + SIDE_SHIFT - SIDE_GAP * fractional; float shifty = mYOffset; float shiftz = -DEPTH_SHIFT; float angle = -ANGLE; if (l == image + 1) { angle *= fract; shiftx *= fract; shifty = (mYOffset * fract + mSelectionYOffset * fractional); shiftz *= fract; } pContext->Translate(shiftx, shifty, shiftz); nuiMatrix m; m.SetRotation(angle, 0, 1, 0); pContext->MultMatrix(m); float shade = 1 - (shiftx / (maxcountright * SIDE_GAP + SIDE_SHIFT)); float sstart = start * shade; float send = end * shade; DrawCard(pContext, l, sstart, send); pContext->PopMatrix(); } } { int32 s = image - maxcountleft; for (int32 l = s, c = 0; l <= image; l++, c++) { pContext->PushMatrix(); float shiftx = (c - maxcountleft + 1) * SIDE_GAP - SIDE_SHIFT - SIDE_GAP * fractional; float shifty = mYOffset; float shiftz = -DEPTH_SHIFT; float angle = ANGLE; if (l == image) { angle *= fractional; shiftx *= fractional; shifty = (mYOffset * fractional + mSelectionYOffset * fract); shiftz *= fractional; } pContext->Translate(shiftx, shifty, shiftz); nuiMatrix m; m.SetRotation(angle, 0, 1, 0); pContext->MultMatrix(m); float shade = 1 + (shiftx / (maxcountleft * SIDE_GAP + SIDE_SHIFT)); float sstart = start * shade; float send = end * shade; DrawCard(pContext, l, sstart, send); pContext->PopMatrix(); } } // if (fractional == 0) // DrawCard(pContext, image, start, end); start = 1.0f; end = 1.0f; pContext->Scale(1.0f, -1.0f, 1.0f); } pContext->PopMatrix(); pContext->PopProjectionMatrix(); // pContext->EnableTexturing(false); // pContext->SetStrokeColor(nuiColor(_T("red"))); // pContext->DrawLine(mRect.GetWidth() / 2, 0, mRect.GetWidth() / 2, mRect.GetHeight()); // pContext->SetStrokeColor(nuiColor(_T("blue"))); // pContext->DrawLine(mRect.GetWidth() * .25, 0, mRect.GetWidth() * .25, mRect.GetHeight()); // pContext->DrawLine(mRect.GetWidth() * .75, 0, mRect.GetWidth() * .75, mRect.GetHeight()); return false; }
void nuiGLPainter::SetState(const nuiRenderState& rState, bool ForceApply) { //TEST_FBO_CREATION(); NUI_RETURN_IF_RENDERING_DISABLED; nuiCheckForGLErrors(); // blending if (ForceApply || mState.mBlending != rState.mBlending) { mState.mBlending = rState.mBlending; if (mState.mBlending) { glEnable(GL_BLEND); } else { glDisable(GL_BLEND); } } if (ForceApply || mState.mBlendFunc != rState.mBlendFunc) { mState.mBlendFunc = rState.mBlendFunc; GLenum src, dst; nuiGetBlendFuncFactors(rState.mBlendFunc, src, dst); BlendFuncSeparate(src, dst); nuiCheckForGLErrors(); } if (ForceApply || mState.mDepthTest != rState.mDepthTest) { mState.mDepthTest = rState.mDepthTest; if (mState.mDepthTest) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); } if (ForceApply || mState.mDepthWrite != rState.mDepthWrite) { mState.mDepthWrite = rState.mDepthWrite; glDepthMask(mState.mDepthWrite); } // We don't care about the font in the lower layer of rendering //nuiFont* mpFont; // ApplyTexture(rState, ForceApply); // Rendering buffers: if (ForceApply || mState.mColorBuffer != rState.mColorBuffer) { mState.mColorBuffer = rState.mColorBuffer; GLboolean m = mState.mColorBuffer ? GL_TRUE : GL_FALSE; glColorMask(m, m, m, m); nuiCheckForGLErrors(); } if (mClip.mEnabled || ForceApply) { uint32 width = mWidth; uint32 height = mHeight; if (mpSurface) { width = mpSurface->GetWidth(); height = mpSurface->GetHeight(); } nuiRect clip(mClip); int x,y,w,h; uint angle = (mpSurface && mpSurface->GetRenderToTexture()) ? 0 : mAngle; if (angle == 90) { x = ToBelow(clip.Top()); y = ToBelow(clip.Left()); w = ToBelow(clip.GetHeight()); h = ToBelow(clip.GetWidth()); } else if (angle == 180) { w = ToBelow(clip.GetWidth()); h = ToBelow(clip.GetHeight()); x = ToBelow(width - w - clip.Left()); y = ToBelow(clip.Top()); } else if (angle == 270) { w = ToBelow(clip.GetHeight()); h = ToBelow(clip.GetWidth()); x = ToBelow(height - clip.Top() - w); y = ToBelow(width - clip.Left() - h); } else { NGL_ASSERT(!angle); x = ToBelow(clip.Left()); y = ToBelow(height - clip.Bottom()); w = ToBelow(clip.GetWidth()); h = ToBelow(clip.GetHeight()); } //NGL_OUT(_T("To Screen Clip {%d, %d, %d, %d}\n"), x,y,w,h); if (!mScissorOn || ForceApply) { glEnable(GL_SCISSOR_TEST); mScissorOn = true; } if (mScissorX != x || mScissorY != y || mScissorW != w || mScissorH != h || ForceApply) { mScissorX = x; mScissorY = y; mScissorW = w; mScissorH = h; x *= NUI_SCALE_FACTOR; y *= NUI_SCALE_FACTOR; w *= NUI_SCALE_FACTOR; h *= NUI_SCALE_FACTOR; glScissor(x, y, w, h); } nuiCheckForGLErrors(); } else { if (mScissorOn || ForceApply) { glDisable(GL_SCISSOR_TEST); mScissorOn = false; } } mState.mClearColor = rState.mClearColor; mState.mStrokeColor = rState.mStrokeColor; mState.mFillColor = rState.mFillColor; nuiCheckForGLErrors(); }
void nuiDrawContext::DrawShade(const nuiRect& rSourceRect, const nuiRect& rShadeRect, const nuiColor& rTint) { bool texturing = mCurrentState.mTexturing; bool blending = mCurrentState.mBlending; nuiBlendFunc blendfunc; blendfunc = mCurrentState.mBlendFunc; if (!blending) EnableBlending(true); if (blendfunc != nuiBlendTransp) SetBlendFunc(nuiBlendTransp); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; nuiTexture* pShade = ::nuiTexture::GetTexture(nglString(_T("NUI_Shade_LUT"))); if (!pShade) { // Left shadow const uint32 size = 16; uint8 pLUT[size * 4]; uint i; for (i = 0; i<size; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; float p = (float)i * (255.0f / (float)size); pLUT[3+(i*4)] = ToBelow(p); } nglImageInfo info(false); info.mBitDepth = 32; info.mBufferFormat = eImageFormatRaw; info.mBytesPerLine = size * 4; info.mBytesPerPixel = 4; info.mHeight = 1; info.mWidth = size; info.mpBuffer = (char*)pLUT; info.mPixelFormat = eImagePixelRGBA; pShade = nuiTexture::GetTexture(info, true); pShade->SetSource(_T("NUI_Shade_LUT")); NGL_ASSERT(pShade); pShade->SetMinFilter(GL_LINEAR); pShade->SetMagFilter(GL_LINEAR); #ifndef _OPENGL_ES_ pShade->SetWrapS(GL_CLAMP); pShade->SetWrapT(GL_CLAMP); #else pShade->SetWrapS(GL_CLAMP_TO_EDGE); pShade->SetWrapT(GL_CLAMP_TO_EDGE); #endif pShade->SetEnvMode(GL_MODULATE); } nuiColor transp(rTint); nuiColor opaque(rTint); transp.Multiply(0.0f); opaque.Multiply(SHADE_ALPHA); if (!texturing) EnableTexturing(true); SetTexture(pShade); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); pArray->EnableArray(nuiRenderArray::eTexCoord); pArray->Reserve(42); // Top Left: pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetTexCoords(0, 0); pArray->SetColor(opaque); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); // Left pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); // Left Corner: pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // bottom shadow pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right Corner pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); // Top Right pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(false); if (!blending) EnableBlending(blending); if (blendfunc != nuiBlendTransp) SetBlendFunc(blendfunc); }
void nuiSoftwarePainter::Display(nglWindow* pWindow, const nuiRect& rRect) { if (!pWindow) return; const nglWindow::OSInfo* pInfo = pWindow->GetOSInfo(); NGL_ASSERT(pInfo); if (!pInfo) return; //TestAgg((char*)&mBuffer[0], mWidth, mHeight); int32 x, y, w, h; x = ToBelow(rRect.Left()); y = ToBelow(rRect.Top()); w = ToBelow(rRect.GetWidth()); h = ToBelow(rRect.GetHeight()); int32 offset = (x + mWidth * y); #ifdef _WIN32_ HDC hdc = GetDC(pInfo->GLWindowHandle); BITMAPV5HEADER bminfo; // BITMAPV5HEADER bminfo.bV5Size = sizeof(BITMAPV5HEADER); bminfo.bV5Width = (LONG)mWidth; bminfo.bV5Height = -(LONG)mHeight; bminfo.bV5Planes = 1; bminfo.bV5BitCount = 32; bminfo.bV5Compression = BI_RGB; bminfo.bV5SizeImage = 0; bminfo.bV5XPelsPerMeter = 0; bminfo.bV5YPelsPerMeter = 0; bminfo.bV5ClrUsed = 0; bminfo.bV5ClrImportant =0; bminfo.bV5RedMask = 0; bminfo.bV5GreenMask = 0; bminfo.bV5BlueMask = 0; bminfo.bV5AlphaMask = 0; bminfo.bV5CSType = LCS_WINDOWS_COLOR_SPACE; bminfo.bV5Endpoints.ciexyzRed.ciexyzX = 0; bminfo.bV5Endpoints.ciexyzRed.ciexyzY = 0; bminfo.bV5Endpoints.ciexyzRed.ciexyzZ = 0; bminfo.bV5Endpoints.ciexyzGreen.ciexyzX = 0; bminfo.bV5Endpoints.ciexyzGreen.ciexyzY = 0; bminfo.bV5Endpoints.ciexyzGreen.ciexyzZ = 0; bminfo.bV5Endpoints.ciexyzBlue.ciexyzX = 0; bminfo.bV5Endpoints.ciexyzBlue.ciexyzY = 0; bminfo.bV5Endpoints.ciexyzBlue.ciexyzZ = 0; bminfo.bV5GammaRed = 0; bminfo.bV5GammaGreen = 0; bminfo.bV5GammaBlue = 0; bminfo.bV5Intent = LCS_GM_IMAGES; bminfo.bV5ProfileData = 0; bminfo.bV5ProfileSize = 0; bminfo.bV5Reserved = 0; RECT r; GetClientRect(pInfo->GLWindowHandle, &r); r.right = (LONG)mWidth; r.bottom = (LONG)mHeight; uint32* pBuffer = mpRasterizer->GetBuffer(); /* for (uint32 i = 0; i < mWidth * mHeight; i++) pBuffer[i] = rand(); */ SetDIBitsToDevice( hdc, // handle to DC x, // x-coord of destination upper-left corner y, // y-coord of destination upper-left corner w, // width of destination rectangle h, // height of destination rectangle x, // x-coord of source upper-left corner mHeight - h - y, // y-coord of source upper-left corner 0, // first scan line (LONG)mHeight, // number of scan lines pBuffer, // bitmap bits (const BITMAPINFO*)&bminfo, // bitmap data DIB_RGB_COLORS // usage options ); ReleaseDC(pInfo->GLWindowHandle, hdc); #elif (defined _CARBON_) WindowRef win = pInfo->WindowHandle; if (!win) win = pInfo->Parent; //CGContextRef myMemoryContext; CGColorSpaceRef cspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, mpRasterizer->GetBuffer() + offset, mWidth * h * 4, NULL); CGImageRef img = CGImageCreate( w, h, 8, 32, mWidth * 4, cspace, kCGBitmapByteOrder32Host | kCGImageAlphaNoneSkipFirst, provider, NULL, 0, kCGRenderingIntentDefault ); CGContextRef myContext; SetPortWindowPort (win);// 1 QDBeginCGContext (GetWindowPort (win), &myContext); CGRect rect = CGRectMake(x, mHeight - h - y, w, h); CGContextDrawImage(myContext, rect, img); QDEndCGContext (GetWindowPort(win), &myContext); #endif }
bool nuiSWF::MouseMoved (nuiSize X, nuiSize Y) { mpMovieInterface->notify_mouse_state(ToBelow(X), ToBelow(Y), mButtons); return true; }
bool nuiSWF::Draw(nuiDrawContext* pContext) { gameswf::set_render_handler(mpRenderHandler); nglTime now; if (mLastTime <= 0) mLastTime = now; double lap = now - mLastTime; mLastTime = now; /* double advance = lap * mFPS; unused */ nuiRenderArray* pDummy = new nuiRenderArray(GL_POINTS); pContext->DrawArray(pDummy); glPushAttrib(GL_ALL_ATTRIB_BITS); float width, height; width = mpMovie->get_width_pixels(); height = mpMovie->get_height_pixels(); //glScalef(10/width, 10/height, 0); nuiSize x=0,y=0; LocalToGlobal(x,y); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_EDGE_FLAG_ARRAY); glDisableClientState(GL_INDEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); mpMovieInterface->set_display_viewport(ToBelow(x), ToBelow(y), ToBelow(mRect.GetWidth()), ToBelow(mRect.GetHeight())); //mpMovieInterface->set_display_viewport(50, 50, 1, 1); mpMovieInterface->set_background_alpha(GetAlpha()); if (IsPlaying()) mpMovieInterface->advance((float)lap); mpMovieInterface->display(); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_EDGE_FLAG_ARRAY); glDisableClientState(GL_INDEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // Restore state that gameswf kills glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); // See if we should exit. if (mLoop == false && (mpMovieInterface->get_current_frame() + 1 == mpMovie->get_frame_count() || mpMovieInterface->get_play_state() == gameswf::character::STOP) ) { // We're reached the end of the movie; exit. Stop(); } glPopAttrib(); pContext->SetTexture(NULL); return true; }
bool nuiArc::Tessellate(nuiPath& rVertices, float Quality) const { // I shamelessly stole this code from svgl double x1, y1, x2, y2; x1 = mStartVertex.Elt[0]; y1 = mStartVertex.Elt[1]; x2 = mStopVertex.Elt[0]; y2 = mStopVertex.Elt[1]; double angle = mAngle; double xr, yr; xr = mXRadius; yr = mYRadius; rVertices.AddVertexOptim(nuiPoint((float)x1, (float)y1)); if ((x1 == x2) && (y1 == y2) && !mLargeArc) { return true; } // be sure mXRadius or mYRadius are non-zero if( mXRadius == 0 || mYRadius == 0) { rVertices.AddVertexOptim(nuiPoint((float)x2, (float)y2)); return true; } // make sure mXRadius and mYRadius are positive if(xr < 0) xr = -xr; if(yr < 0) yr = -yr; const double cosa = cos(angle * M_PI / 180.0); const double sina = sin(angle * M_PI / 180.0); // compute the center (see svg.pdf) const double xp1 = cosa * (x1 - x2) / 2.0 + sina * (y1 - y2) / 2.f; const double yp1 = -sina * (x1 - x2) / 2.0 + cosa * (y1 - y2) / 2.f; double rx2 = xr * xr, ry2 = yr * yr, xp12 = xp1 * xp1, yp12 = yp1 * yp1; // make sure xr and yr are large enough { double tmp = xp12 / rx2 + yp12 / ry2; if (tmp > 1) { rx2 *= tmp; ry2 *= tmp; tmp = sqrt(tmp); xr *= tmp; yr *= tmp; } } double fact = ( rx2 * ry2 / (rx2 * yp12 + ry2 * xp12)) - 1; if (fact < 0) { fact = 0; } fact = sqrt(fact); if (mLargeArc == mSweep) fact = -fact; double xpc = xr * yp1 / yr; double ypc = - yr * xp1 / xr; xpc *= fact; ypc *= fact; double xc = xpc * cosa - ypc * sina + (x1 + x2) / 2.f; double yc = xpc * sina + ypc * cosa + (y1 + y2) / 2.f; // determine t1 and t2, limits given by (x1, y1) (x2, y2) double t1; double deltat; // double t2; { double xv1 = (xp1 - xpc) / xr; double yv1 = (yp1 - ypc) / yr; double norm1 = xv1 * xv1 + yv1 * yv1; double cosangle1 = xv1 / sqrt(norm1); if (cosangle1 < -1.0f) cosangle1 = -1.0f; if (cosangle1 > 1.0f) cosangle1 = 1.0f; t1 = acos(cosangle1); if (yv1 < 0) t1 = -t1; double xv2 = (-xp1 - xpc) / xr; double yv2 = (-yp1 - ypc) / yr; double norm2 = xv2 * xv2 + yv2 * yv2; deltat = xv1 * xv2 + yv1 * yv2; deltat = deltat / sqrt(norm1 * norm2); if (deltat < -1.0) deltat = -1.0; if (deltat > 1.0) deltat = 1.0; deltat = acos(deltat); if ( (xv1 * yv2 - yv1 * xv2) < 0) deltat = -deltat; if (!mSweep && (deltat > 0)) deltat -= 2.0 * M_PI; if (mSweep && (deltat < 0)) deltat += 2.0 * M_PI; } // compute vertices /* fast incremental cos and sin generation cos(a+dt) = cos(a) cos(dt) - sin(a) sin(dt); sin(a+dt) = cos(a) sin(dt) + cos(dt) sin(a); <=> cos(a+2*dt) = cos(a + dt) cos(dt) - sin(a + dt) sin(dt) sin(a+2*dt) = cos(a + dt) sin(dt) + cos(a + dt) sin(a) */ const int nb = ToBelow(M_PI * (xr + yr) * Quality); const double dt = deltat / nb; const double cosdt = cos(dt); const double sindt = sin(dt); double cost1_plus_ndt = cos(t1 + dt); double sint1_plus_ndt = sin(t1 + dt); for (int i = 0; i < nb; ++i) { /* ellipsoid: x(t) = xr.cos(t) y(t) = yr.cos(t) */ double x = xr * cost1_plus_ndt; double y = yr * sint1_plus_ndt; { // compute cos and sin double tmp = cost1_plus_ndt * cosdt - sint1_plus_ndt * sindt; sint1_plus_ndt = cost1_plus_ndt * sindt + sint1_plus_ndt * cosdt; cost1_plus_ndt = tmp; } // rotate // angle = -angle, I don't know why... { double tmp = x * cosa - y * sina; y = x * sina + y * cosa; x = tmp; } // translate x += xc; y += yc; rVertices.AddVertexOptim(nuiPoint((float)x, (float)y)); } return true; }