ABUTTON.H 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #ifndef ABUTTON_H
  5. #define ABUTTON_H
  6. #include "aSystem.h"
  7. #include "aFont.h"
  8. #include "aAnim.h"
  9. class FitIniFile;
  10. class aButton : public aObject
  11. {
  12. public:
  13. aButton();
  14. long init(long xPos, long yPos, long w, long h);
  15. void destroy();
  16. virtual void update();
  17. virtual void render();
  18. void init( FitIniFile& file, const char* headerName, HGOSFONT3D font = 0 );
  19. aButton& operator=( const aButton& src);
  20. aButton( const aButton& src);
  21. virtual void move( float offsetX, float offsetY );
  22. void setHoldTime( float newTime ) { holdTime = newTime; }
  23. virtual bool pointInside(long xPos, long yPos) const;
  24. void press( bool );
  25. void toggle();
  26. void disable( bool );
  27. bool isEnabled();
  28. bool isPressed() { return state == PRESSED; }
  29. void makeAmbiguous( bool bAmbiguous );
  30. void setSinglePress(){ singlePress = true; }
  31. void setMessageOnRelease() { messageOnRelease = true; }
  32. void hide( bool );
  33. int getID();
  34. void setID( int ID );
  35. void setText( int newID ) { data.textID = newID; }
  36. void setPressFX( int newFX ){ clickSFX = newFX; }
  37. void setHighlightFX( int newFX ){ highlightSFX = newFX; }
  38. void setDisabledFX( int newFX ){ disabledSFX = newFX; }
  39. enum States
  40. {
  41. ENABLED = 0,
  42. PRESSED,
  43. DISABLED,
  44. AMBIGUOUS,
  45. HIGHLIGHT,
  46. HIDDEN
  47. };
  48. protected:
  49. struct aButtonData
  50. {
  51. long ID;
  52. long textID;
  53. long textColors[5];
  54. HGOSFONT3D textFont;
  55. long textSize; // for ttf
  56. char fileName[32];
  57. long stateCoords[5][2];
  58. long textureWidth;
  59. long textureHeight;
  60. int fileWidth;
  61. int fileHeight;
  62. bool textureRotated;
  63. GUI_RECT textRect; // center text in here
  64. bool outlineText; // draw empty square around text rect
  65. bool outline; // draw empty square around button
  66. long textAlign;
  67. };
  68. aButtonData data;
  69. int state;
  70. bool toggleButton;
  71. bool singlePress;
  72. bool messageOnRelease;
  73. float holdTime;
  74. long clickSFX;
  75. long highlightSFX;
  76. long disabledSFX;
  77. static void makeUVs( gos_VERTEX* vertices, int State, aButtonData& data );
  78. private:
  79. void copyData( const aButton& src );
  80. };
  81. class aAnimButton : public aButton
  82. {
  83. public:
  84. aAnimButton();
  85. void init( FitIniFile& file, const char* headerName, HGOSFONT3D font = 0 );
  86. virtual void update();
  87. virtual void render();
  88. void destroy();
  89. aAnimButton& operator=( const aAnimButton& src);
  90. aAnimButton( const aAnimButton& src );
  91. void setAnimationInfo( aAnimation* normal, aAnimation* highlight,
  92. aAnimation* pressed, aAnimation* disabled );
  93. void animateChildren( bool bAnimate ){ bAnimateChildren = bAnimate; }
  94. private:
  95. aAnimation normalData;
  96. aAnimation highlightData;
  97. aAnimation pressedData;
  98. aAnimation disabledData;
  99. void update( const aAnimation& data );
  100. bool animateText;
  101. bool animateBmp;
  102. bool bAnimateChildren;
  103. void copyData( const aAnimButton& src );
  104. };
  105. #endif