| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Combat *
- * *
- * $Archive:: /Commando/Code/wwui/popupdialog.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/02/02 11:25a $*
- * *
- * $Revision:: 14 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- // Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
- #pragma warning(disable : 4530)
- #include "popupdialog.h"
- #include "assetmgr.h"
- #include "texture.h"
- #include "stylemgr.h"
- ////////////////////////////////////////////////////////////////
- // Local constants
- ////////////////////////////////////////////////////////////////
- const int TITLE_BORDER_WIDTH = 10;
- const int TITLE_BORDER_HEIGHT = 8;
- ////////////////////////////////////////////////////////////////
- //
- // PopupDialogClass
- //
- ////////////////////////////////////////////////////////////////
- PopupDialogClass::PopupDialogClass (int res_id) :
- DialogBaseClass (res_id)
- {
- //
- // Configure the renderers
- //
- StyleMgrClass::Configure_Renderer (&BackgroundRenderer);
- StyleMgrClass::Configure_Renderer (&BlackoutRenderer);
- StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_HEADER);
- //
- // Force this renderer to always render
- //
- BlackoutRenderer.Get_Shader ()->Set_Depth_Compare (ShaderClass::PASS_ALWAYS);
- //
- // By default, popup backgrounds are dark
- //
- IsBackgroundDarkened = true;
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~PopupDialogClass
- //
- ////////////////////////////////////////////////////////////////
- PopupDialogClass::~PopupDialogClass (void)
- {
- return ;
- }
- void PopupDialogClass::Set_Title(const WCHAR* title)
- {
- DialogBaseClass::Set_Title(title);
- Build_Background_Renderers();
- }
- ////////////////////////////////////////////////////////////////
- //
- // On_Init_Dialog
- //
- ////////////////////////////////////////////////////////////////
- void
- PopupDialogClass::On_Init_Dialog (void)
- {
- //
- // Generate the backdrop
- //
- Build_Background_Renderers ();
- DialogBaseClass::On_Init_Dialog ();
- //
- // Play the sound effect
- //
- StyleMgrClass::Play_Sound (StyleMgrClass::EVENT_POPUP);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Build_Background_Renderers
- //
- ////////////////////////////////////////////////////////////////
- void
- PopupDialogClass::Build_Background_Renderers (void)
- {
- //
- // Configure this renderer
- //
- TextRenderer.Reset();
- BackgroundRenderer.Reset ();
- BlackoutRenderer.Reset ();
- BackgroundRenderer.Enable_Texturing (false);
- BlackoutRenderer.Enable_Texturing (false);
- //
- // Darken the background if IsBackgroundDarkened is set
- //
- if (IsBackgroundDarkened) {
- BlackoutRenderer.Add_Quad (Render2DClass::Get_Screen_Resolution(), RGBA_TO_INT32 (0, 0, 0, 236));
- }
- //
- // Determine which color to draw the outline in
- //
- int color = StyleMgrClass::Get_Line_Color ();
- int bkcolor = StyleMgrClass::Get_Bk_Color ();
- //
- // Draw the control outline
- //
- RectClass rect = Rect;
- BackgroundRenderer.Add_Rect (rect, 1.0F, color, bkcolor);
- if (Title.Get_Length () > 0) {
- //
- // Determine what scale to use
- //
- float scale_x = Render2DClass::Get_Screen_Resolution().Width () / 800;
- float scale_y = Render2DClass::Get_Screen_Resolution().Height () / 600;
- //
- // Calculate the title bar rectangle
- //
- Vector2 text_extent = TextRenderer.Get_Text_Extents (Title);
- if (text_extent != Vector2(0,0)) {
- RectClass text_rect;
- text_rect.Left = Rect.Left;
- text_rect.Right = Rect.Left + int(text_extent.X + (TITLE_BORDER_WIDTH * 2 * scale_x));
- text_rect.Top = Rect.Top - int(text_extent.Y + (TITLE_BORDER_HEIGHT * 2 * scale_y));
- text_rect.Bottom = Rect.Top;
- //
- // Draw the title bar
- //
- BackgroundRenderer.Add_Rect (text_rect, 1.0F, color, bkcolor);
- //
- // Draw the title text
- //
- StyleMgrClass::Render_Text (Title, &TextRenderer, text_rect, true, true, StyleMgrClass::CENTER_JUSTIFY);
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Render
- //
- ////////////////////////////////////////////////////////////////
- void
- PopupDialogClass::Render (void)
- {
- //
- // Render the backdrop
- //
- BlackoutRenderer.Render ();
- BackgroundRenderer.Render ();
- TextRenderer.Render ();
- //
- // Render the controls
- //
- DialogBaseClass::Render ();
- return ;
- }
|