Utilities.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // stuff I need all over the place
  5. #ifndef UTILITIES_H
  6. #define UTILITIES_H
  7. #include <gameos.hpp>
  8. #include <string.h>
  9. class FitIniFile;
  10. class StaticInfo
  11. {
  12. public:
  13. void init( FitIniFile& file, char* blockName, long hiResOffsetX = 0, long hiResOffsetY = 0, DWORD neverFlush = 0 );
  14. void render();
  15. bool isInside( int mouseX, int mouseY );
  16. void setLocation( float newX, float newY );
  17. void move( float deltaX, float deltaY );
  18. void setNewUVs( float uLeft, float vTop, float uRight, float vBottom );
  19. float width(){ return location[2].x - location[0].x; }
  20. float height(){ return location[2].y - location[0].y; }
  21. void getData(unsigned char * buffer);
  22. void showGUIWindow( bool bShow );
  23. void setColor( long newColor );
  24. StaticInfo(){}
  25. ~StaticInfo();
  26. unsigned long textureHandle;
  27. gos_VERTEX location[4];
  28. long u, v, uWidth, vHeight;
  29. unsigned long textureWidth; // textures are square
  30. };
  31. typedef struct _GUI_RECTd
  32. {
  33. long left;
  34. long top;
  35. long right;
  36. long bottom;
  37. } GUI_RECT;
  38. void drawEmptyRect( const GUI_RECT& rect, unsigned long leftBorderColor = 0xffffffff,
  39. unsigned long rightBorderColor = 0xff000000 );
  40. void drawRect( const GUI_RECT& rect, unsigned long color );
  41. void drawShadowText( long colorTop, long colorShadow, HGOSFONT3D font,
  42. long left, long top, bool proportional, const char* text, bool bBold, float scale );
  43. void drawShadowText( long colorTop, long colorShadow, HGOSFONT3D font,
  44. long left, long top, bool proportional, const char* text, bool bold, float scale,
  45. long xOffset, long yOffset);
  46. void drawShadowText( long colorTop, long colorShadow, HGOSFONT3D font,
  47. long left, long top, long right, long bottom, bool proportional, const char* text, bool bold, float scale,
  48. long xOffset, long yOffset);
  49. long interpolateColor( long color1, long color2, float percent );
  50. inline long reverseRGB( long oldVal )
  51. {
  52. return ( (oldVal & 0xff000000) | ((oldVal & 0xff0000) >> 16) | (oldVal & 0xff00) | ((oldVal & 0xff) << 16) );
  53. }
  54. //-------------------------------------------------------
  55. // Replaces the WINDOWS version because it is a lie!
  56. // There are cases where windows does NOT append a null.
  57. // THANKS!
  58. //
  59. // Replace with GOS String Resource get when available
  60. // Replaced. Andy wants us to call everytime. Will try and see if practical.
  61. extern DWORD gosResourceHandle;
  62. #if 1
  63. inline int cLoadString(
  64. unsigned int uID, // resource identifier
  65. char* lpBuffer, // pointer to buffer for resource
  66. int nBufferMax, // size of buffer
  67. unsigned long handle = gosResourceHandle
  68. )
  69. {
  70. memset(lpBuffer,0,nBufferMax);
  71. char * tmpBuffer = gos_GetResourceString(handle, uID);
  72. long stringLength = strlen(tmpBuffer);
  73. if (stringLength >= nBufferMax)
  74. STOP(("String too long for buffer. String Id %d, bufferLen %d, StringLen %d",uID,nBufferMax,stringLength));
  75. memcpy(lpBuffer,tmpBuffer,stringLength);
  76. return stringLength;
  77. }
  78. #else
  79. inline char * cLoadString (unsigned int uID)
  80. {
  81. return gos_GetResourceString(gosResourceHandle, uID);
  82. }
  83. #endif
  84. #endif