floathelp.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. //--------------------------
  10. // Include Files
  11. #ifndef FLOATHELP_H
  12. #include "floathelp.h"
  13. #endif
  14. #ifndef HEAP_H
  15. #include "heap.h"
  16. #endif
  17. //-----------------------------------------------------------------------------------------
  18. DWORD FloatHelp::currentFloatHelp = 0; //How many of them are we using at present
  19. FloatHelp* FloatHelp::floatHelps = NULL; //POinters to all of them.
  20. //-----------------------------------------------------------------------------------------
  21. // class FloatHelp
  22. void FloatHelp::init (long maxHelps)
  23. {
  24. floatHelps = (FloatHelp *)systemHeap->Malloc(sizeof(FloatHelp) * MAX_FLOAT_HELPS);
  25. gosASSERT(floatHelps != NULL);
  26. FloatHelp *tmp = floatHelps;
  27. for (long i=0;i<MAX_FLOAT_HELPS;i++,tmp++)
  28. {
  29. tmp->text[0] = 0;
  30. tmp->screenPos.x = tmp->screenPos.y = tmp->screenPos.z = tmp->screenPos.w = 0.0f;
  31. tmp->foregroundColor = SD_WHITE;
  32. tmp->backgroundColor = SD_BLACK;
  33. tmp->scale = 1.0f;
  34. tmp->proportional = true;
  35. tmp->bold = tmp->italic = tmp->wordWrap = false;
  36. }
  37. currentFloatHelp = 0;
  38. }
  39. //-----------------------------------------------------------------------------------------
  40. void FloatHelp::destroy (void)
  41. {
  42. systemHeap->Free(floatHelps);
  43. floatHelps = NULL;
  44. currentFloatHelp = 0;
  45. }
  46. //-----------------------------------------------------------------------------------------
  47. void FloatHelp::resetAll (void)
  48. {
  49. currentFloatHelp = 0;
  50. for (long i=0;i<MAX_FLOAT_HELPS;i++)
  51. floatHelps[i].reset();
  52. }
  53. //-----------------------------------------------------------------------------------------
  54. void FloatHelp::renderAll (void)
  55. {
  56. for (long i=0;i<MAX_FLOAT_HELPS;i++)
  57. floatHelps[i].render();
  58. }
  59. //-----------------------------------------------------------------------------------------
  60. void FloatHelp::setFloatHelp(char * txt,
  61. Stuff::Vector4D screenPos,
  62. DWORD fClr,
  63. DWORD bClr,
  64. float scl,
  65. bool proportional,
  66. bool bold,
  67. bool italic,
  68. bool wordWrap)
  69. {
  70. if (currentFloatHelp < MAX_FLOAT_HELPS)
  71. {
  72. floatHelps[currentFloatHelp].setHelpText(txt);
  73. floatHelps[currentFloatHelp].setScreenPos(screenPos);
  74. floatHelps[currentFloatHelp].setForegroundColor(fClr);
  75. floatHelps[currentFloatHelp].setBackgroundColor(bClr);
  76. floatHelps[currentFloatHelp].setScale(scl);
  77. floatHelps[currentFloatHelp].setProportional(proportional);
  78. floatHelps[currentFloatHelp].setBold(bold);
  79. floatHelps[currentFloatHelp].setItalic(italic);
  80. floatHelps[currentFloatHelp].setWordWrap(wordWrap);
  81. currentFloatHelp++;
  82. }
  83. }
  84. //-----------------------------------------------------------------------------------------
  85. void FloatHelp::getTextStringLength (char * txt,
  86. DWORD fColor,
  87. float scl,
  88. bool proportional,
  89. bool bold,
  90. bool italic,
  91. bool wordWrap,
  92. DWORD &width, DWORD &height)
  93. {
  94. // must use globalFloat Scale because of true type fonts
  95. gos_TextSetAttributes (gosFontHandle, fColor, gosFontScale, wordWrap, proportional, bold, italic);
  96. unsigned long gHeight = 0, gWidth = 0;
  97. if (txt[0])
  98. {
  99. gos_TextStringLength(&gWidth,&gHeight,txt);
  100. }
  101. width = gWidth;
  102. height = gHeight;
  103. }
  104. //-----------------------------------------------------------------------------------------