floathelp.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //-----------------------------------------------------------------------------------------
  2. //
  3. // Floating Help class. Used for tool tips, building/mech/vehicle IDs.
  4. // Basically draws itself AFTER everything else since gos_Font"3D" has no Z Depth!
  5. //
  6. //---------------------------------------------------------------------------//
  7. // Copyright (C) Microsoft Corporation. All rights reserved. //
  8. //===========================================================================//
  9. #ifndef FLOATHELP_H
  10. #define FLOATHELP_H
  11. //--------------------------
  12. // Include Files
  13. #ifndef DBASEGUI_H
  14. #include "dbasegui.h"
  15. #endif
  16. #include <gameos.hpp>
  17. #include <stuff/stuff.hpp>
  18. extern HGOSFONT3D gosFontHandle;
  19. extern float gosFontScale;
  20. #define MAX_FLOAT_HELPS 100 //Used for sensor information, too!
  21. //-----------------------------------------------------------------------------------------
  22. // Classes
  23. class FloatHelp
  24. {
  25. protected:
  26. char text[2048]; //Last person to set this displays the font.
  27. Stuff::Vector4D screenPos; //x,y are left and top. z,w are width and height.
  28. DWORD foregroundColor; //Color in aRGB Format.
  29. DWORD backgroundColor; //Color in aRGB Format.
  30. float scale; //Scale. 1.0f is normal.
  31. bool proportional; //if false, spacing is equal for each letter.
  32. bool bold; //if true, draws bold.
  33. bool italic; //if true, draws italic.
  34. bool wordWrap; //if true, wraps word.
  35. static DWORD currentFloatHelp; //How many of them are we using at present
  36. static FloatHelp* floatHelps; //POinters to all of them.
  37. public:
  38. FloatHelp (long maxHelps)
  39. {
  40. init(maxHelps);
  41. text[0] = 0;
  42. screenPos.x = screenPos.y = screenPos.z = screenPos.w = 0.0f;
  43. foregroundColor = SD_WHITE;
  44. backgroundColor = SD_BLACK;
  45. scale = 1.0f;
  46. proportional = true;
  47. bold = italic = wordWrap = false;
  48. }
  49. ~FloatHelp (void)
  50. {
  51. destroy();
  52. }
  53. void init (long maxHelps);
  54. void destroy (void);
  55. static void resetAll (void);
  56. static void renderAll (void);
  57. static void setFloatHelp(char * txt,
  58. Stuff::Vector4D screenPos,
  59. DWORD fClr,
  60. DWORD bClr,
  61. float scl,
  62. bool proportional,
  63. bool bold,
  64. bool italic,
  65. bool wordWrap);
  66. static void getTextStringLength (char *text,
  67. DWORD fColor,
  68. float scl,
  69. bool proportional,
  70. bool bold,
  71. bool italic,
  72. bool wordWrap,
  73. DWORD &width, DWORD &height);
  74. protected:
  75. void setHelpText (char *txt)
  76. {
  77. if (strlen(txt) < 2048)
  78. {
  79. strcpy(text,txt);
  80. }
  81. else
  82. {
  83. text[0] = 0;
  84. }
  85. }
  86. void setScreenPos (Stuff::Vector4D pos)
  87. {
  88. screenPos = pos;
  89. }
  90. void setForegroundColor (DWORD clr)
  91. {
  92. foregroundColor = clr;
  93. }
  94. void setBackgroundColor (DWORD clr)
  95. {
  96. backgroundColor = clr;
  97. }
  98. void setScale (float scl)
  99. {
  100. scale = scl;
  101. }
  102. void setProportional (bool flag)
  103. {
  104. proportional = flag;
  105. }
  106. void setBold (bool flag)
  107. {
  108. bold = flag;
  109. }
  110. void setItalic (bool flag)
  111. {
  112. italic = flag;
  113. }
  114. void setWordWrap (bool flag)
  115. {
  116. wordWrap = flag;
  117. }
  118. void reset (void)
  119. {
  120. //Call every frame. Otherwise floating help keeps floating!
  121. text[0] = 0;
  122. }
  123. void render (void)
  124. {
  125. if (text[0])
  126. {
  127. // must use global scale, incase of True Type fonts.
  128. gos_TextSetAttributes (gosFontHandle, foregroundColor, gosFontScale, wordWrap, proportional, bold, italic);
  129. //gos_TextDrawBackground ((int)screenPos.x, (int)screenPos.y, (int)(screenPos.x+screenPos.z), (int)(screenPos.y+screenPos.w), SD_BLACK);
  130. gos_TextSetPosition((int)screenPos.x,(int)screenPos.y);
  131. gos_TextDraw(text);
  132. }
  133. }
  134. };
  135. typedef FloatHelp* FloatHelpPtr;
  136. //-----------------------------------------------------------------------------------------
  137. #endif