tooltipmgr.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/wwui/tooltipmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 9/07/01 5:26p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "tooltipmgr.h"
  36. #include "tooltip.h"
  37. #include "dialogcontrol.h"
  38. #include "dialogmgr.h"
  39. #include "ww3d.h"
  40. ////////////////////////////////////////////////////////////////
  41. // Static member initialization
  42. ////////////////////////////////////////////////////////////////
  43. ToolTipClass * ToolTipMgrClass::ToolTip = NULL;
  44. int ToolTipMgrClass::ToolTipDelay = 1000;
  45. int ToolTipMgrClass::DefaultToolTipDelay = 1000;
  46. bool ToolTipMgrClass::ToolTipDisplayed = false;
  47. DialogControlClass * ToolTipMgrClass::CurrentControl = NULL;
  48. Vector2 ToolTipMgrClass::LastMousePos (0, 0);
  49. int ToolTipMgrClass::PauseTime = -1;
  50. ////////////////////////////////////////////////////////////////
  51. //
  52. // Initialize
  53. //
  54. ////////////////////////////////////////////////////////////////
  55. void
  56. ToolTipMgrClass::Initialize (void)
  57. {
  58. ToolTipDisplayed = false;
  59. //
  60. // Allocate the tooltip object
  61. //
  62. ToolTip = new ToolTipClass;
  63. return ;
  64. }
  65. ////////////////////////////////////////////////////////////////
  66. //
  67. // Shutdown
  68. //
  69. ////////////////////////////////////////////////////////////////
  70. void
  71. ToolTipMgrClass::Shutdown (void)
  72. {
  73. ToolTipDisplayed = false;
  74. //
  75. // Free the tooltip object
  76. //
  77. delete ToolTip;
  78. ToolTip = NULL;
  79. return ;
  80. }
  81. ////////////////////////////////////////////////////////////////
  82. //
  83. // Render
  84. //
  85. ////////////////////////////////////////////////////////////////
  86. void
  87. ToolTipMgrClass::Render (void)
  88. {
  89. //
  90. // Simply render the tooltip (if necessary)
  91. //
  92. if (ToolTipDisplayed && ToolTip != NULL) {
  93. ToolTip->Render ();
  94. }
  95. return ;
  96. }
  97. ////////////////////////////////////////////////////////////////
  98. //
  99. // Reset
  100. //
  101. ////////////////////////////////////////////////////////////////
  102. void
  103. ToolTipMgrClass::Reset (void)
  104. {
  105. ToolTipDisplayed = false;
  106. return ;
  107. }
  108. ////////////////////////////////////////////////////////////////
  109. //
  110. // Update
  111. //
  112. ////////////////////////////////////////////////////////////////
  113. void
  114. ToolTipMgrClass::Update (const Vector2 &mouse_pos)
  115. {
  116. if (ToolTip == NULL) {
  117. return ;
  118. }
  119. if (ToolTipDisplayed == false && mouse_pos == LastMousePos) {
  120. //
  121. // Begin waiting for the mouse to move
  122. //
  123. if (PauseTime == -1) {
  124. PauseTime = (int)DialogMgrClass::Get_Time ();
  125. } else if (((int)DialogMgrClass::Get_Time () - PauseTime) > ToolTipDelay) {
  126. //
  127. // What control are we over?
  128. //
  129. DialogControlClass *control = DialogMgrClass::Find_Control (mouse_pos);
  130. if (control != NULL && control->Wants_Tooltip ()) {
  131. CurrentControl = control;
  132. //
  133. // Update the text of the tooltip
  134. //
  135. WideStringClass text;
  136. control->Get_Tooltip_Text (text);
  137. ToolTip->Set_Text (text);
  138. //
  139. // Reposition the tooltip
  140. //
  141. Vector2 tip_pos (mouse_pos.X + 16, mouse_pos.Y + 32);
  142. ToolTip->Set_Position (tip_pos);
  143. //
  144. // Display the tooltip
  145. //
  146. ToolTipDisplayed = true;
  147. PauseTime = -1;
  148. }
  149. }
  150. } else if (mouse_pos != LastMousePos) {
  151. PauseTime = -1;
  152. if (ToolTipDisplayed) {
  153. //
  154. // Did we move onto a different control?
  155. //
  156. DialogControlClass *control = DialogMgrClass::Find_Control (mouse_pos);
  157. if (control != CurrentControl) {
  158. //
  159. // Force the tooltip to be hidden
  160. //
  161. ToolTipDisplayed = false;
  162. CurrentControl = NULL;
  163. }
  164. }
  165. }
  166. LastMousePos = mouse_pos;
  167. return ;
  168. }