SpeedButton.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef SPEEDBUTTON_H
  2. #define SPEEDBUTTON_H
  3. //-------------------------------------------------------------------------------
  4. //
  5. // SpeedButton
  6. //
  7. // Deco SpeedButton class, a nifty X-style button with a graphic and a label.
  8. // It tries to be as lightweight as possible (but is failing miserably ;).
  9. //
  10. // Author: Alan Ellis
  11. // Copyright 1999 - 2001, the Deco team. CGSoftware International
  12. //
  13. // Used with permission for the Vision project. (http://vision.sourceforge.net/)
  14. //-------------------------------------------------------------------------------
  15. class BLooper;
  16. class BBitmap;
  17. #include <interface/Control.h>
  18. #include <interface/Rect.h>
  19. // How many pixels around the edge we need for comfort.
  20. #define EDGE_SPACE 0
  21. enum TSBStyle
  22. {
  23. sbFlat,
  24. sbUp
  25. };
  26. /**
  27. * @short A nifty X-style button with a graphic..
  28. * This class is a BButton derivative with some cool features.
  29. * @author Alan Ellis
  30. */
  31. class TSpeedButton : public BControl
  32. {
  33. public:
  34. /**
  35. * Standard stuff for BButtons with some additions.
  36. * @param Label Set this to NULL if you do not wish to have a label drawn on your button.
  37. * @param EnabledBitmap The bitmap which shows the button in an enabled state.
  38. * Copies are made of the bitmaps that you pass in. You still own them.
  39. * @param Style Optional style. Avaliable styles are sbFlat (pops up as the mouse goes over it)
  40. * and sbUp, normal looking button.
  41. * @param DisabledBitmap Optional look for a disabled bitmap.
  42. * If this is not supplied, a disabled button will be created from the
  43. * Enabled bitmap
  44. */
  45. TSpeedButton(BRect Frame, const char *Name, const char* Label,
  46. BMessage *Message, BBitmap *EnabledBitmap,
  47. TSBStyle Style = sbFlat,
  48. BBitmap *DisabledBitmap = NULL,
  49. uint32 ResizingMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
  50. uint32 Flags = B_WILL_DRAW);
  51. /**
  52. * Standard unarchiving constructor.
  53. */
  54. TSpeedButton(BMessage *Archive);
  55. /**
  56. * Goes with above constructor.
  57. */
  58. static TSpeedButton *Instantiate(BMessage *Archive);
  59. /**
  60. * Standard destructor.
  61. */
  62. virtual ~TSpeedButton();
  63. /**
  64. * More archiving stuff.
  65. */
  66. virtual status_t Archive(BMessage *Archive, bool Deep = true) const;
  67. virtual void AttachedToWindow();
  68. virtual void DetachedFromWindow();
  69. virtual void Draw(BRect Frame);
  70. virtual void MouseDown(BPoint where);
  71. virtual void MouseUp(BPoint where);
  72. virtual void MouseMoved(BPoint where,
  73. uint32 code,
  74. const BMessage *a_message);
  75. virtual void FrameResized(float Width, float Height);
  76. /**
  77. * What style is the button? You need but ask.
  78. */
  79. virtual TSBStyle Style();
  80. /**
  81. * Set the style.
  82. * @param Style Set to one of 'sbFlat' or 'sbUp'. See the constructor for explanation of the vaules.
  83. */
  84. virtual void Style(TSBStyle Style);
  85. /**
  86. * Used to 'group' buttons owned by the same view for 'radio' functionality.
  87. * @param Index All buttons belonging to the same index will be in the same group. A group index of
  88. * -1 indicates a button is not part of any group.
  89. */
  90. virtual void GroupIndex(int32 Index);
  91. /**
  92. * Oh great oracle, to which group does my button belong?
  93. */
  94. virtual int32 GroupIndex();
  95. /**
  96. * Primarily useful to buttons in Groups or latching, a button is seleced when it is in the 'down' state.
  97. */
  98. virtual void Selected(bool Selected);
  99. virtual bool Selected();
  100. /**
  101. * A button that 'latches' will stick down when pressed. If the button is part of a group the other buttons in the
  102. * group will become un-latched.
  103. */
  104. virtual void Latching(bool Latching);
  105. virtual bool Latching();
  106. /**
  107. * You may want to show that a button is in a special state, Highlighting can do this for you by drawing an outline
  108. * inside the edge of the button.
  109. */
  110. virtual void Highlighted(bool Highlighted);
  111. virtual bool Highlighted();
  112. virtual void HighlightColor(rgb_color HighlightColor);
  113. virtual rgb_color HighlightColor();
  114. protected:
  115. private:
  116. void SetupBitmaps(BBitmap* Source);
  117. void SetupLabel();
  118. private:
  119. enum TSBDrawState { sbSDown, sbSFlat, sbSUp };
  120. BBitmap* fDisabledBitmap;
  121. BBitmap* fEnabledBitmap;
  122. BRect fBitmapSourceRect;
  123. BRect fBitmapDestinationRect;
  124. BRect fBorder;
  125. TSBStyle fStyle;
  126. int32 fGroupIndex;
  127. rgb_color fHighlightColor;
  128. rgb_color fEnabledViewColor;
  129. BPoint fLabelPos;
  130. bool fActive;
  131. bool fMouseDown;
  132. bool fOutside;
  133. bool fAttachedToWindow;
  134. bool fSelected;
  135. bool fLatching;
  136. bool fHighlighted;
  137. };
  138. #endif