NS_IMETHODIMP nsSimplePageSequenceFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(), "A Page Sequence is only for real pages"); DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow"); aStatus = NS_FRAME_COMPLETE; // we're always complete // Don't do incremental reflow until we've taught tables how to do // it right in paginated mode. if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) { // Return our desired size aDesiredSize.height = mSize.height * PresContext()->GetPrintPreviewScale(); aDesiredSize.width = mSize.width * PresContext()->GetPrintPreviewScale(); aDesiredSize.SetOverflowAreasToDesiredBounds(); FinishAndStoreOverflow(&aDesiredSize); return NS_OK; } PRBool isPrintPreview = aPresContext->Type() == nsPresContext::eContext_PrintPreview; // See if we can get a Print Settings from the Context if (!mPageData->mPrintSettings && aPresContext->Medium() == nsGkAtoms::print) { mPageData->mPrintSettings = aPresContext->GetPrintSettings(); } // now get out margins & edges if (mPageData->mPrintSettings) { nsIntMargin unwriteableTwips; mPageData->mPrintSettings->GetUnwriteableMarginInTwips(unwriteableTwips); NS_ASSERTION(unwriteableTwips.left >= 0 && unwriteableTwips.top >= 0 && unwriteableTwips.right >= 0 && unwriteableTwips.bottom >= 0, "Unwriteable twips should be non-negative"); nsIntMargin marginTwips; mPageData->mPrintSettings->GetMarginInTwips(marginTwips); mMargin = aPresContext->CSSTwipsToAppUnits(marginTwips + unwriteableTwips); PRInt16 printType; mPageData->mPrintSettings->GetPrintRange(&printType); mPrintRangeType = printType; nsIntMargin edgeTwips; mPageData->mPrintSettings->GetEdgeInTwips(edgeTwips); // sanity check the values. three inches are sometimes needed PRInt32 inchInTwips = NS_INCHES_TO_INT_TWIPS(3.0); edgeTwips.top = NS_MIN(NS_MAX(edgeTwips.top, 0), inchInTwips); edgeTwips.bottom = NS_MIN(NS_MAX(edgeTwips.bottom, 0), inchInTwips); edgeTwips.left = NS_MIN(NS_MAX(edgeTwips.left, 0), inchInTwips); edgeTwips.right = NS_MIN(NS_MAX(edgeTwips.right, 0), inchInTwips); mPageData->mEdgePaperMargin = aPresContext->CSSTwipsToAppUnits(edgeTwips + unwriteableTwips); } // *** Special Override *** // If this is a sub-sdoc (meaning it doesn't take the whole page) // and if this Document is in the upper left hand corner // we need to suppress the top margin or it will reflow too small nsSize pageSize = aPresContext->GetPageSize(); mPageData->mReflowSize = pageSize; // If we're printing a selection, we need to reflow with // unconstrained height, to make sure we'll get to the selection // even if it's beyond the first page of content. if (nsIPrintSettings::kRangeSelection == mPrintRangeType) { mPageData->mReflowSize.height = NS_UNCONSTRAINEDSIZE; } mPageData->mReflowMargin = mMargin; // Compute the size of each page and the x coordinate that each page will // be placed at nscoord extraThreshold = NS_MAX(pageSize.width, pageSize.height)/10; PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin"); gapInTwips = NS_MAX(0, gapInTwips); nscoord extraGap = aPresContext->CSSTwipsToAppUnits(gapInTwips); extraGap = NS_MIN(extraGap, extraThreshold); // clamp to 1/10 of the largest dim of the page nscoord deadSpaceGap = 0; if (isPrintPreview) { GetDeadSpaceValue(&gapInTwips); deadSpaceGap = aPresContext->CSSTwipsToAppUnits(gapInTwips); } nsMargin extraMargin(0,0,0,0); nsSize shadowSize(0,0); if (aPresContext->IsScreen()) { extraMargin.SizeTo(extraGap, extraGap, extraGap, extraGap); nscoord fourPixels = nsPresContext::CSSPixelsToAppUnits(4); shadowSize.SizeTo(fourPixels, fourPixels); } mPageData->mShadowSize = shadowSize; mPageData->mExtraMargin = extraMargin; const nscoord x = deadSpaceGap; nscoord y = deadSpaceGap;// Running y-offset for each page nsSize availSize(pageSize.width + shadowSize.width + extraMargin.LeftRight(), pageSize.height + shadowSize.height + extraMargin.TopBottom()); // Tile the pages vertically nsHTMLReflowMetrics kidSize; for (nsIFrame* kidFrame = mFrames.FirstChild(); nsnull != kidFrame; ) { // Set the shared data into the page frame before reflow nsPageFrame * pf = static_cast<nsPageFrame*>(kidFrame); pf->SetSharedPageData(mPageData); // Reflow the page nsHTMLReflowState kidReflowState(aPresContext, aReflowState, kidFrame, availSize); nsReflowStatus status; kidReflowState.SetComputedWidth(kidReflowState.availableWidth); //kidReflowState.SetComputedHeight(kidReflowState.availableHeight); PR_PL(("AV W: %d H: %d\n", kidReflowState.availableWidth, kidReflowState.availableHeight)); // Place and size the page. If the page is narrower than our // max width then center it horizontally ReflowChild(kidFrame, aPresContext, kidSize, kidReflowState, x, y, 0, status); FinishReflowChild(kidFrame, aPresContext, nsnull, kidSize, x, y, 0); y += kidSize.height; // Leave a slight gap between the pages y += deadSpaceGap; // Is the page complete? nsIFrame* kidNextInFlow = kidFrame->GetNextInFlow(); if (NS_FRAME_IS_FULLY_COMPLETE(status)) { NS_ASSERTION(!kidNextInFlow, "bad child flow list"); } else if (!kidNextInFlow) { // The page isn't complete and it doesn't have a next-in-flow, so // create a continuing page. nsIFrame* continuingPage; nsresult rv = aPresContext->PresShell()->FrameConstructor()-> CreateContinuingFrame(aPresContext, kidFrame, this, &continuingPage); if (NS_FAILED(rv)) { break; } // Add it to our child list mFrames.InsertFrame(nsnull, kidFrame, continuingPage); } // Get the next page kidFrame = kidFrame->GetNextSibling(); } // Get Total Page Count nsIFrame* page; PRInt32 pageTot = 0; for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) { pageTot++; } // Set Page Number Info PRInt32 pageNum = 1; for (page = mFrames.FirstChild(); page; page = page->GetNextSibling()) { nsPageFrame * pf = static_cast<nsPageFrame*>(page); if (pf != nsnull) { pf->SetPageNumInfo(pageNum, pageTot); } pageNum++; } // Create current Date/Time String if (!mDateFormatter) mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID); NS_ENSURE_TRUE(mDateFormatter, NS_ERROR_FAILURE); nsAutoString formattedDateString; time_t ltime; time( <ime ); if (NS_SUCCEEDED(mDateFormatter->FormatTime(nsnull /* nsILocale* locale */, kDateFormatShort, kTimeFormatNoSeconds, ltime, formattedDateString))) { PRUnichar * uStr = ToNewUnicode(formattedDateString); SetDateTimeStr(uStr); // memory will be freed } // Return our desired size // Adjustr the reflow size by PrintPreviewScale so the scrollbars end up the // correct size nscoord w = (x + availSize.width + deadSpaceGap); aDesiredSize.height = y * PresContext()->GetPrintPreviewScale(); // includes page heights and dead space aDesiredSize.width = w * PresContext()->GetPrintPreviewScale(); aDesiredSize.SetOverflowAreasToDesiredBounds(); FinishAndStoreOverflow(&aDesiredSize); // cache the size so we can set the desired size // for the other reflows that happen mSize.width = w; mSize.height = y; NS_FRAME_TRACE_REFLOW_OUT("nsSimplePageSequeceFrame::Reflow", aStatus); NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); return NS_OK; }
void LOPuzzle::render() { if (!puzzleTextureID<0 || puzzleObject==0) return; glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); SHTextureBase::bindTexture(puzzleTextureID); SunnyMatrix m1 = getScaleMatrix(puzzlePartsScale) * getRotationXMatrix(M_PI_2); SunnyMatrix m; puzzleObject->prepareForRender(isVAOSupported); sunnyUseShader(globalShaders[LOS_Textured3D]); glUniform4fv(uniform3D_C, 1, SunnyVector4D(1,1,1,1)); float depth = 0; float shadowD = 0; for (short i = puzzleHorizontalSize*puzzleVerticalSize-1;i>=0;i--) if (puzzleParts[renderOrder[i]].active) { if (rotatingParts[renderOrder[i]].isRotating) { float angle = (- 1 + rotatingParts[renderOrder[i]].time/ppRotationTime)*M_PI_2; SunnyVector2D distance = puzzleParts[renderOrder[i]].position - rotatingParts[renderOrder[i]].origin; SunnyVector2D pos; pos.x = distance.x*cosf(angle) + distance.y*sinf(angle); pos.y =-distance.x*sinf(angle) + distance.y*cosf(angle); pos += rotatingParts[renderOrder[i]].origin; angle = (puzzleParts[renderOrder[i]].rotation - 1 + rotatingParts[renderOrder[i]].time/ppRotationTime)*M_PI_2; m = getRotationZMatrix(-angle) * getTranslateMatrix(SunnyVector3D(pos.x,pos.y,-5)); } else { m = getRotationZMatrix(-puzzleParts[renderOrder[i]].rotation*M_PI_2) * getTranslateMatrix(SunnyVector3D(puzzleParts[renderOrder[i]].position.x,puzzleParts[renderOrder[i]].position.y,-200+depth)); } if (puzzleHeight[renderOrder[i]]>1) { m = getScaleMatrix(puzzleHeight[renderOrder[i]]) * getRotationXMatrix(-M_PI*4*(puzzleHeight[renderOrder[i]]-1))* m; puzzleHeight[renderOrder[i]] -= deltaTime; if (puzzleHeight[renderOrder[i]]<1) puzzleHeight[renderOrder[i]] = 1; } m = getTranslateMatrix(partsTranslations[renderOrder[i]]) * m1*m; glUniformMatrix4fv(globalModelview[LOS_Textured3D], 1, GL_FALSE, &(m.front.x)); puzzleObject->renderObject(objectsNumbers[renderOrder[i]]); if (i+1 == selectedPartsCount) shadowD = depth; depth += 5; } if (selectedParts) { glEnable(GL_BLEND); SunnyVector3D shadowSize(-0.15,-0.15,-1); sunnyUseShader(globalShaders[LOS_Textured3DA]); glUniform4fv(uniform3D_A, 1, SunnyVector4D(0,0,0,0.3)); for (short i = 0;i<selectedPartsCount;i++) { if (rotatingParts[selectedParts[i]].isRotating) { float angle = (- 1 + rotatingParts[selectedParts[i]].time/ppRotationTime)*M_PI_2; SunnyVector2D distance = puzzleParts[selectedParts[i]].position - rotatingParts[selectedParts[i]].origin; SunnyVector2D pos; pos.x = distance.x*cosf(angle) + distance.y*sinf(angle); pos.y =-distance.x*sinf(angle) + distance.y*cosf(angle); pos += rotatingParts[selectedParts[i]].origin; angle = (puzzleParts[selectedParts[i]].rotation - 1 + rotatingParts[selectedParts[i]].time/ppRotationTime)*M_PI_2; m = getRotationZMatrix(-angle) * getTranslateMatrix(SunnyVector3D(pos.x,pos.y,-5)); } else m = getRotationZMatrix(-puzzleParts[selectedParts[i]].rotation*M_PI_2) * getTranslateMatrix(SunnyVector3D(puzzleParts[selectedParts[i]].position.x+shadowSize.x,puzzleParts[selectedParts[i]].position.y+shadowSize.y,-200+shadowSize.z+shadowD)); m = getTranslateMatrix(partsTranslations[renderOrder[i]]) * m1*m; glUniformMatrix4fv(globalModelview[LOS_Textured3DA], 1, GL_FALSE, &(m.front.x)); puzzleObject->renderObject(objectsNumbers[selectedParts[i]]); } } glDisable(GL_CULL_FACE); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); bindGameGlobal(); SHTextureBase::bindTexture(menuTexture); const float mapKoef = mapSize.x/1920; const float farDist = -20; //fade sunnyUseShader(globalShaders[LOS_TexturedTSA]); m = sunnyIdentityMatrix; glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(m.front.x)); glUniform1f(uniformTSA_A, 1); //Buttons { m = getTranslateMatrix(SunnyVector3D(0,0,farDist)); glUniform1f(uniformTSA_A, 1); float btnScale; SunnyMatrix rot; rot = m; //Back rot.pos = puzzleButtons[PuzzleButton_Back]->matrix.pos; puzzleButtons[PuzzleButton_Back]->active?btnScale = defaultButtonScale:btnScale = 1; glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(rot.front.x)); btnScale *= 0.82; glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(0, 0, btnScale, btnScale)); SunnyDrawArrays(LOLCButtonsVAO); glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(-4*mapKoef, 6*mapKoef, btnScale, btnScale)); SunnyDrawArrays(LOLCButtonsVAO+6); // //Store // rot.pos = puzzleButtons[PuzzleButton_Store]->matrix.pos; // puzzleButtons[PuzzleButton_Store]->active?btnScale = defaultButtonScale:btnScale = 1; // glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(rot.front.x)); // glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(0, 0, btnScale, btnScale)); // SunnyDrawArrays(LOLCButtonsVAO); // glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(-4*mapKoef, -2*mapKoef, btnScale, btnScale)); // SunnyDrawArrays(LOLCButtonsVAO+2); //break if (!puzzleButtons[PuzzleButton_Break]->hidden) { rot.pos = puzzleButtons[PuzzleButton_Break]->matrix.pos; puzzleButtons[PuzzleButton_Break]->active?btnScale = defaultButtonScale:btnScale = 1; glUniformMatrix4fv(globalModelview[LOS_TexturedTSA], 1, GL_FALSE, &(rot.front.x)); btnScale *= 0.82; glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(0, 0, btnScale, btnScale)); SunnyDrawArrays(LOLCButtonsVAO); glUniform4fv(uniformTSA_TR, 1, SunnyVector4D(-2*mapKoef, 4*mapKoef, btnScale, btnScale)); SunnyDrawArrays(LOLCButtonsVAO+3); } } }