void TranslationView::Resize() { Size parentSize = ParentView->GetSize(); Layout.SetSize(parentSize); State.EnsureSize(parentSize); Size bufferingDeviceContextSize = DeviceContextBuffer->GetSize(); bufferingDeviceContextSize = Size( max(parentSize.GetWidth(), bufferingDeviceContextSize.GetWidth()), max(parentSize.GetHeight(), bufferingDeviceContextSize.GetHeight())); DeviceContextBuffer->Resize(bufferingDeviceContextSize); ApplyViewState(true); Renderer* renderer = RenderingContext->GetRenderer(); if(GetModel()->GetTranslateResult().IsEmptyResult()) { renderer->DrawRect(Rect(0, headerHeight, State.GetSize().GetWidth(), State.GetSize().GetHeight() - headerHeight), LightGrayBrush); } RenderSeparator(renderer, max(State.GetContentSize().GetWidth(), State.GetSize().GetWidth())); renderer->Render(DeviceContextBuffer); RenderingContext->ReleaseRenderer(renderer); Draw(); }
void Game::DrawPlaying( Renderer& renderer ) { static unsigned int blockSizePixels = 32; // Draw field unsigned int fieldWidthPixels = m_field.width * blockSizePixels; unsigned int fieldHeightPixels = m_field.height * blockSizePixels; unsigned int fieldOffsetPixelsX = 0; if( renderer.GetLogicalWidth() > fieldWidthPixels ) { fieldOffsetPixelsX = ( renderer.GetLogicalWidth() - fieldWidthPixels ) / 2; } unsigned int fieldOffsetPixelsY = 0; if( renderer.GetLogicalHeight() > fieldHeightPixels ) { fieldOffsetPixelsY = ( renderer.GetLogicalHeight() - fieldHeightPixels ) / 2; } for( unsigned int iy = 0; iy < m_field.height; ++iy ) { const unsigned int y = fieldOffsetPixelsY + iy * blockSizePixels; for( unsigned int ix = 0; ix < m_field.width; ++ix ) { const unsigned int x = fieldOffsetPixelsX + ix * blockSizePixels; const int blockState = m_field.staticBlocks[iy * m_field.width + ix]; unsigned int blockRgba = 0x202020ff; if( blockState != -1 ) { HP_ASSERT( blockState < kNumTetrominoTypes ); blockRgba = s_tetrominos[blockState].rgba; } renderer.DrawSolidRect( x, y, blockSizePixels, blockSizePixels, blockRgba ); renderer.DrawRect( x, y, blockSizePixels, blockSizePixels, 0x404040ff ); } } // draw active tetromino for( unsigned int i = 0; i < 4; ++i ) { const Tetromino& tetromino = s_tetrominos[m_activeTetromino.m_tetrominoType]; const Tetromino::BlockCoords& blockCoords = tetromino.blockCoord[m_activeTetromino.m_rotation]; unsigned int tetrominoRgba = tetromino.rgba; const unsigned int x = fieldOffsetPixelsX + ( m_activeTetromino.m_pos.x + blockCoords[i].x ) * blockSizePixels; const unsigned int y = fieldOffsetPixelsY + ( m_activeTetromino.m_pos.y + blockCoords[i].y ) * blockSizePixels; renderer.DrawSolidRect( x, y, blockSizePixels, blockSizePixels, tetrominoRgba ); } char text[128]; snprintf( text, sizeof(text), "Lines: %u", m_numLinesCleared ); renderer.DrawText( text, 0, 100, 0xffffffff ); snprintf( text, sizeof(text), "Level: %u", m_level ); renderer.DrawText( text, 0, 140, 0xffffffff ); snprintf( text, sizeof(text), "Score: %u", m_score ); renderer.DrawText( text, 0, 180, 0xffffffff ); snprintf( text, sizeof(text), "High score: %u", m_hiScore ); renderer.DrawText( text, 0, 220, 0xffffffff ); #ifdef _DEBUG snprintf( text, sizeof(text), "Frames per fall: %u", m_framesPerFallStep ); renderer.DrawText( text, 0, 400, 0x404040ff ); #endif }