| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- /*
- ** 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/tooltip.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 1/24/02 4:05p $*
- * *
- * $Revision:: 5 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "tooltip.h"
- #include "assetmgr.h"
- #include "refcount.h"
- #include "font3d.h"
- #include "stylemgr.h"
- ////////////////////////////////////////////////////////////////
- //
- // ToolTipClass
- //
- ////////////////////////////////////////////////////////////////
- ToolTipClass::ToolTipClass (void) :
- Rect (0, 0, 0, 0),
- TextColor (0, 0, 0),
- BkColor (1.0F, 0.956F, 0.733F)
- {
- //
- // Set the font for the text renderers
- //
- StyleMgrClass::Assign_Font (&TextRenderer, StyleMgrClass::FONT_TOOLTIPS);
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // ~ToolTipClass
- //
- ////////////////////////////////////////////////////////////////
- ToolTipClass::~ToolTipClass (void)
- {
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create_Text_Renderer
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Create_Text_Renderer (void)
- {
- Render2DSentenceClass &renderer = TextRenderer;
- //
- // Setup the coordinate system of the renderer
- //
- renderer.Reset ();
- //
- // Calculate where to draw the text
- //
- Vector2 text_extent = renderer.Get_Text_Extents (Text);
- int x_pos = int(Rect.Left + ((Rect.Width() - text_extent.X) / 2));
- int y_pos = int(Rect.Top + ((Rect.Height() - text_extent.Y) / 2));
- //
- // Draw the text
- //
- renderer.Set_Location(Vector2 (x_pos, y_pos));
- renderer.Set_Clipping_Rect (Rect);
- renderer.Build_Sentence(Text);
- renderer.Draw_Sentence(VRGB_TO_INT32(TextColor));
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Create_Background_Renderer
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Create_Background_Renderer (void)
- {
- Render2DClass &renderer = BackgroundRenderer;
- //
- // Configure this renderer
- //
- renderer.Reset ();
- renderer.Enable_Texturing (false);
- renderer.Set_Coordinate_Range (Render2DClass::Get_Screen_Resolution());
- //
- // Make a hilight color by brightening the background color
- //
- Vector3 temp = BkColor * 2;
- temp.X = min (255.0F, temp.X);
- temp.Y = min (255.0F, temp.Y);
- temp.Z = min (255.0F, temp.Z);
- //
- // Make two int's representing the hilight and shadow colors
- //
- int hilight_color = VRGB_TO_INT32 (temp);
- int shadow_color = VRGB_TO_INT32 (Vector3 (0, 0, 0));
- //
- // Draw the box outline
- //
- RectClass rect = Rect;
- renderer.Add_Line (Vector2 (rect.Left, rect.Bottom), Vector2 (rect.Left, rect.Top-1), 1, hilight_color);
- renderer.Add_Line (Vector2 (rect.Left, rect.Top), Vector2 (rect.Right, rect.Top), 1, hilight_color);
- renderer.Add_Line (Vector2 (rect.Right, rect.Top), Vector2 (rect.Right, rect.Bottom), 1, shadow_color);
- renderer.Add_Line (Vector2 (rect.Right, rect.Bottom), Vector2 (rect.Left, rect.Bottom), 1, shadow_color);
- //
- // Now draw the background
- //
- rect.Right -= 1;
- rect.Bottom -= 1;
- renderer.Add_Quad (rect, VRGB_TO_INT32 (BkColor));
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Render
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Render (void)
- {
- //
- // Render the background and text
- //
- BackgroundRenderer.Render ();
- TextRenderer.Render ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Position
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Set_Position (const Vector2 &pos)
- {
- Rect.Left = pos.X;
- Rect.Top = pos.Y;
- Update_Rect ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Text
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Set_Text (const WCHAR *text)
- {
- Text = text;
-
- //
- // Force the renderer's to be repositioned and resized
- //
- Update_Rect ();
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Update_Rect
- //
- ////////////////////////////////////////////////////////////////
- void
- ToolTipClass::Update_Rect (void)
- {
- //
- // Get the dimensions of the string
- //
- const RectClass &screen_rect = Render2DClass::Get_Screen_Resolution ();
- Vector2 text_extent = TextRenderer.Get_Text_Extents (Text);
- if (text_extent.X <= 0.0f) {
- BackgroundRenderer.Reset();
- TextRenderer.Reset();
- return;
- }
- //
- // Update the rectangle's width and height
- //
- Rect.Right = Rect.Left + (text_extent.X + 5); //10);
- Rect.Bottom = Rect.Top + (text_extent.Y + 4); //* 2);
- //
- // Clip the rectangle to the right side of the screen
- //
- if (Rect.Right > screen_rect.Right) {
- float delta = Rect.Right - screen_rect.Right;
- Rect.Left -= delta;
- Rect.Right -= delta;
- }
- //
- // Clip the rectangle to the bottom of the screen
- //
- if (Rect.Bottom > screen_rect.Bottom) {
- float delta = Rect.Bottom - screen_rect.Bottom;
- Rect.Top -= delta;
- Rect.Bottom -= delta;
- }
- //
- // Update the renderer's
- //
- Create_Text_Renderer ();
- Create_Background_Renderer ();
- return ;
- }
|