//----------------------------------------------------------------------------- // main application //----------------------------------------------------------------------------- void CVsVGuiWindow::PaintWindow() { if ( m_nCurrentTick == m_nLastRenderedTick || !g_pVGui->IsRunning() ) { ValidateRect( m_hWnd, NULL ); return; } m_nCurrentTick = m_nLastRenderedTick; vgui::VPANEL root = g_pVGuiSurface->GetEmbeddedPanel(); g_pVGuiSurface->Invalidate( root ); RECT windowRect; CMatRenderContextPtr pRenderContext( g_pMaterialSystem ); ::GetClientRect( m_hWnd, &windowRect ); g_pMaterialSystem->SetView( m_hWnd ); pRenderContext->Viewport( 0, 0, windowRect.right, windowRect.bottom ); float flStartTime = Plat_FloatTime(); pRenderContext->ClearColor4ub( 76, 88, 68, 255 ); pRenderContext->ClearBuffers( true, true ); g_pMaterialSystem->BeginFrame( 0 ); // draw from the main panel down if ( m_hMainPanel.Get() ) { int w, h; m_hMainPanel->GetSize( w, h ); if ( w != windowRect.right || h != windowRect.bottom ) { m_hMainPanel->SetBounds( 0, 0, windowRect.right, windowRect.bottom ); m_hMainPanel->Repaint(); } g_pVGuiSurface->RestrictPaintToSinglePanel( m_hMainPanel->GetVPanel() ); g_pVGuiSurface->PaintTraverseEx( root, true ); g_pVGuiSurface->RestrictPaintToSinglePanel( 0 ); } g_pMaterialSystem->EndFrame(); g_pMaterialSystem->SwapBuffers(); g_pMaterialSystem->SetView( NULL ); ValidateRect( m_hWnd, NULL ); m_flRenderDelayTime = Plat_FloatTime() - flStartTime; m_flRenderDelayTime = max( m_flRenderDelayTime, 0.015f ); }
//----------------------------------------------------------------------------- // Sets a panel to be the main panel //----------------------------------------------------------------------------- void CVsVGuiWindow::SetMainPanel( vgui::EditablePanel * pPanel ) { Assert( m_hMainPanel.Get() == NULL ); Assert( m_hVGuiContext == vgui::DEFAULT_VGUI_CONTEXT ); m_hMainPanel = pPanel; m_hMainPanel->SetParent( vgui::surface()->GetEmbeddedPanel() ); m_hMainPanel->SetVisible( true ); m_hMainPanel->SetCursor( vgui::dc_arrow ); m_hVGuiContext = vgui::ivgui()->CreateContext(); vgui::ivgui()->AssociatePanelWithContext( m_hVGuiContext, m_hMainPanel->GetVPanel() ); pPanel->InvalidateLayout(); EnableWindow( m_hWnd, true ); SetFocus( m_hWnd ); }