//******************************************************************************** bool CExplosionEffect::Draw(SDL_Surface* pDestSurface) //Draw the effect. // //Returns: //True if effect should continue, or false if effect is done. { const UINT dwTimeElapsed = TimeElapsed(); if (dwTimeElapsed >= this->dwDuration) return false; //Effect is done. if (!pDestSurface) pDestSurface = GetDestSurface(); //Draw shrinking explosion. const float fPercent = (this->dwDuration - dwTimeElapsed) / (float)this->dwDuration; ASSERT(fPercent >= 0.0); ASSERT(fPercent <= 1.0); UINT wTile = TI_EXPLOSION_1; if (fPercent < 0.30) wTile = TI_EXPLOSION_4; else if (fPercent < 0.55) wTile = TI_EXPLOSION_3; else if (fPercent < 0.80) wTile = TI_EXPLOSION_2; DrawTile(wTile, pDestSurface); //Continue effect. return true; }
//********************************************************************************************************* void CProgressBarWidget::DrawBar() { SDL_Rect rectInset; GetRect(rectInset); static const UINT CX_BAR_SPACE = 1; static const UINT CY_BAR_SPACE = 1; static const UINT CX_MIN_INSET = (CX_BAR_SPACE + CX_INSET_BORDER) * 2 + 3; //3 = left/right bar border + red center. static const UINT CY_MIN_INSET = (CY_BAR_SPACE + CY_INSET_BORDER) * 2 + 3; //3 = top/bottom bar border + red center. SDL_Surface *pDestSurface = GetDestSurface(); if (rectInset.w >= CX_MIN_INSET && rectInset.h >= CY_MIN_INSET) //Inset must be big enough to display bar. { SURFACECOLOR Black; SURFACECOLOR Red; GetDestSurfaceColor(0, 0, 0, Black); ASSERT(this->fValue >= 0.0 && this->fValue <= 1.0); GetDestSurfaceColor(128 + (Uint8)(this->fValue*127), (Uint8)(this->fValue*255), 0, Red); //get brighter //Calc bar's rect. SDL_Rect rectBar; rectBar.x = rectInset.x + CX_INSET_BORDER + CX_BAR_SPACE; rectBar.y = rectInset.y + CY_INSET_BORDER + CY_BAR_SPACE; rectBar.h = rectInset.h - (CY_INSET_BORDER + CY_BAR_SPACE) * 2; const UINT wAvailableWidth = rectInset.w - (CX_INSET_BORDER + CX_BAR_SPACE) * 2; rectBar.w = static_cast<Uint16>(wAvailableWidth * this->fValue); if (rectBar.w < 3) rectBar.w = 3; //Draw the bar. DrawFilledRect(rectBar, Red, pDestSurface); DrawRect(rectBar, Black, pDestSurface); } }
//***************************************************************************** void CHTMLWidget::HandleAnimate() //Draw as much of page surface as can be done this frame without slowing animation. { ASSERT(IsVisible()); if (!this->pHTMLSurface) return; if (this->wHeightDrawn >= (UINT)this->pHTMLSurface->h) return; //all done SDL_Surface *pDestSurface = GetDestSurface(); //Blit horizontal strips of HTML surface to screen until animation duration is up. static const UINT dwMaxTime = 30; //30ms const UINT dwStopTime = SDL_GetTicks() + dwMaxTime; ASSERT(this->pParent); SDL_Rect clipRect; this->pParent->GetChildClippingRect(clipRect); SDL_SetClipRect(pDestSurface, &clipRect); do { static const UINT wStripHeight = 64; SDL_Rect src = {-this->nOffsetX, -this->nOffsetY + this->wHeightDrawn, this->pHTMLSurface->w, wStripHeight}; SDL_Rect dest = {this->x, this->y + this->wHeightDrawn, this->pHTMLSurface->w, wStripHeight}; //Bounds check on last row. if (this->wHeightDrawn + wStripHeight > (UINT)this->pHTMLSurface->h) src.h = dest.h = this->pHTMLSurface->h - this->wHeightDrawn; if (dest.y + dest.h >= clipRect.y + clipRect.h) { //Now rendering past the visible rect -- stop drawing the page after this, //or repaint if dirty flag is set. src.h = dest.h = (clipRect.y + clipRect.h) - dest.y; if (bNeedRepaint) { bNeedRepaint = false; this->wHeightDrawn = -dest.h; GetScrollOffset(this->nOffsetX, this->nOffsetY); } else this->wHeightDrawn = this->pHTMLSurface->h; } SDL_BlitSurface(this->pHTMLSurface, &src, pDestSurface, &dest); UpdateRect(dest); this->wHeightDrawn += dest.h; if (this->wHeightDrawn >= (UINT)this->pHTMLSurface->h) break; //all done if (this->wHeightDrawn >= this->h) break; //drawn entire visible area } while (SDL_GetTicks() < dwStopTime); SDL_SetClipRect(pDestSurface, NULL); }
//***************************************************************************** void CCreditsScreen::Paint( //Overridable method to paint the screen. // //Params: bool bUpdateRect) //(in) If true (default) and destination // surface is the screen, the screen // will be immediately updated in // the widget's rect. { //Blit the background graphic. SDL_BlitSurface(this->images[0], NULL, GetDestSurface(), NULL); PaintChildren(); if (bUpdateRect) UpdateRect(); }
//********************************************************************************************************* void CProgressBarWidget::Paint( //Paint widget area. // //Params: bool bUpdateRect) //(in) If true (default) and destination // surface is the screen, the screen // will be immediately updated in // the widget's rect. { //Draw inset covering entire widget area. SDL_Rect rectInset; GetRect(rectInset); DrawInset(rectInset.x, rectInset.y, rectInset.w, rectInset.h, this->images[0], GetDestSurface()); DrawBar(); this->fLastDrawnValue = this->fValue; if (bUpdateRect) UpdateRect(); }
/** * @fn RaiseBottomOnMask(float RaiseValue) * * @brief This function raises the bottom level according to a mask * indicating the dry or wet state * * @note This function is used for generating the channel bottom profile * * @param RaiseValue - The raise value */ void CFlux2DGrid::RaiseBottomOnMask(float RaiseValue) { // Declare and initialize working variables int x,y; const int width = m_bottom.m_heightMap.Width(); const int height = m_bottom.m_heightMap.Height(); // For every line in the height map for (y = 0; y < height; y++) { // Get past, present and future surfaces float* pH0 = &(GetPastSurface().m_heightMap.At(0,y)); float* pH1 = &(GetDestSurface().m_heightMap.At(0,y)); float* pH2 = &(GetCurrentSurface().m_heightMap.At(0,y)); // Get pointers into the maps and data float* pB = &(m_bottom.m_heightMap.At(0,y)); float* pD = &(m_bottom.m_precompDataMap.At(0,y)); char* pM = m_InnerMaskData.GetLinePtr(y); // For every pixel in the line for (x = 0; x < width; x++) { // If the mask for the previous pixel has a value if(pM[x-1]) { // Raise the level for past, present and future surfaces pH0[x] -= RaiseValue; pH1[x] -= RaiseValue; pH2[x] -= RaiseValue; // Raise the bottom height pB[x] -= RaiseValue; // Ensure the modifier from the pre-computed data is greater than or equal to zero float hMod = __max(0.0f, pD[x]); // Adjust the pre-computed value pD[x] = hMod * sqrt(m_Globals.gravity * hMod); } } } }
//***************************************************************************** void CHTMLWidget::GetChildClippingRect( //Children draw themselves to a surface sized to hold the whole page. // //Params: SDL_Rect &ChildClipRect) //(out) the area this widget wants its children clipped to const { //When drawing to the browser's internal surface, children are clipped //directly to it. When the children's coordinates are being considered //externally, however, they must be relative to this widget itself. if (GetDestSurface() == this->pHTMLSurface) { //Clip to pHTMLSurface ChildClipRect.x = 0; ChildClipRect.y = 0; ChildClipRect.w = this->pHTMLSurface->w; ChildClipRect.h = this->pHTMLSurface->h; } else pParent->GetChildClippingRect(ChildClipRect); }
//***************************************************************************** void CHTMLWidget::UpdateHTMLSurface() //Updates the HTML surface. { if (this->pHTMLSurface) SDL_FreeSurface(this->pHTMLSurface); //Create surface to fit the parsed HTML page. this->pHTMLSurface = CBitmapManager::ConvertSurface(SDL_CreateRGBSurface( SDL_SWSURFACE, this->w, this->wY, g_pTheBM->BITS_PER_PIXEL, 0, 0, 0, 0)); if (this->pHTMLSurface) { //Set surface BG color to designated page color. const Uint32 wBGColor = TranslateColor(this->pHTMLSurface, this->wstrBGColor); SDL_FillRect(this->pHTMLSurface, NULL, wBGColor); //Draw children on the correct spot on the HTML surface. SDL_Surface *pDestSurface = GetDestSurface(); SetDestSurface(this->pHTMLSurface); Scroll(-this->x, -this->y); PaintChildren(); Scroll(this->x, this->y); SetDestSurface(pDestSurface); //Prepare for paint this->wHeightDrawn = (UINT)this->pHTMLSurface->h; this->bNeedRepaint = false; } else { //Couldn't create surface; report error and use slow rendering mode char errorStr[256]; _snprintf(errorStr, 256, "Error creating HTML surface: %s", SDL_GetError()); CFiles Files; Files.AppendErrorLog((char *)errorStr); } }
//******************************************************************************** bool CDebrisEffect::Draw(SDL_Surface* pDestSurface) //Draw the effect. // //Returns: //True if effect should continue, or false if effect is done. { if (!MoveParticles()) return false; if (!pDestSurface) pDestSurface = GetDestSurface(); for (int nIndex=wParticleCount; nIndex--; ) //If particle is still active, plot to display. if (parrParticles[nIndex].bActive) if (parrParticles[nIndex].type) g_pTheBM->BlitTileImagePart(TI_DEBRIS_2, ROUND(parrParticles[nIndex].x), ROUND(parrParticles[nIndex].y), 4, 5, pDestSurface); else g_pTheBM->BlitTileImagePart(TI_DEBRIS_1, ROUND(parrParticles[nIndex].x), ROUND(parrParticles[nIndex].y), 7, 8, pDestSurface); return true; }