Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 244 | chris | 1 | #ifndef __WIDGET_H__ |
| 2 | #define __WIDGET_H__ |
||
| 3 | |||
| 4 | #include "Common.h" |
||
| 5 | #include "Color.h" |
||
| 6 | #include "Insets.h" |
||
| 7 | #include "Graphics.h" |
||
| 8 | #include "KeyCodes.h" |
||
| 9 | #include "WidgetContainer.h" |
||
| 10 | |||
| 11 | namespace Sexy |
||
| 12 | { |
||
| 13 | |||
| 14 | class WidgetManager; |
||
| 15 | |||
| 16 | typedef std::vector<Color> ColorVector; |
||
| 17 | |||
| 18 | class Widget : public WidgetContainer |
||
| 19 | { |
||
| 20 | public: |
||
| 21 | bool mVisible; |
||
| 22 | bool mMouseVisible; |
||
| 23 | bool mDisabled; |
||
| 24 | bool mHasFocus; |
||
| 25 | bool mIsDown; |
||
| 26 | bool mIsOver; |
||
| 27 | bool mHasTransparencies; |
||
| 28 | ColorVector mColors; |
||
| 29 | Insets mMouseInsets; |
||
| 30 | bool mDoFinger; |
||
| 31 | bool mWantsFocus; |
||
| 32 | |||
| 33 | Widget* mTabPrev; |
||
| 34 | Widget* mTabNext; |
||
| 35 | |||
| 36 | static bool mWriteColoredString; // controls whether ^color^ works in calls to WriteString |
||
| 37 | |||
| 38 | void WidgetRemovedHelper(); |
||
| 39 | |||
| 40 | public: |
||
| 41 | Widget(); |
||
| 42 | virtual ~Widget(); |
||
| 43 | |||
| 44 | virtual void OrderInManagerChanged(); |
||
| 45 | virtual void SetVisible(bool isVisible); |
||
| 46 | |||
| 47 | virtual void SetColors(int theColors[][3], int theNumColors); |
||
| 48 | virtual void SetColors(int theColors[][4], int theNumColors); |
||
| 49 | virtual void SetColor(int theIdx, const Color& theColor); |
||
| 50 | virtual const Color& GetColor(int theIdx); |
||
| 51 | virtual Color GetColor(int theIdx, const Color& theDefaultColor); |
||
| 52 | |||
| 53 | virtual void SetDisabled(bool isDisabled); |
||
| 54 | virtual void ShowFinger(bool on); |
||
| 55 | |||
| 56 | virtual void Resize(int theX, int theY, int theWidth, int theHeight); |
||
| 57 | virtual void Resize(const Rect& theRect); |
||
| 58 | virtual void Move(int theNewX, int theNewY); |
||
| 59 | virtual bool WantsFocus(); |
||
| 60 | virtual void Draw(Graphics* g); // Already translated |
||
| 61 | virtual void DrawOverlay(Graphics* g); |
||
| 62 | virtual void DrawOverlay(Graphics* g, int thePriority); |
||
| 63 | virtual void Update(); |
||
| 64 | virtual void UpdateF(float theFrac); |
||
| 65 | virtual void GotFocus(); |
||
| 66 | virtual void LostFocus(); |
||
| 67 | virtual void KeyChar(SexyChar theChar); |
||
| 68 | virtual void KeyDown(KeyCode theKey); |
||
| 69 | virtual void KeyUp(KeyCode theKey); |
||
| 70 | virtual void MouseEnter(); |
||
| 71 | virtual void MouseLeave(); |
||
| 72 | virtual void MouseMove(int x, int y); |
||
| 73 | virtual void MouseDown(int x, int y, int theClickCount); |
||
| 74 | virtual void MouseDown(int x, int y, int theBtnNum, int theClickCount); |
||
| 75 | virtual void MouseUp(int x, int y); |
||
| 76 | virtual void MouseUp(int x, int y, int theClickCount); |
||
| 77 | virtual void MouseUp(int x, int y, int theBtnNum, int theClickCount); |
||
| 78 | virtual void MouseDrag(int x, int y); |
||
| 79 | virtual void MouseWheel(int theDelta); |
||
| 80 | virtual bool IsPointVisible(int x, int y); |
||
| 81 | |||
| 82 | //////// Helper functions |
||
| 83 | |||
| 84 | virtual Rect WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine); |
||
| 85 | virtual Rect WriteCenteredLine(Graphics* g, int anOffset, const SexyString& theLine, Color theColor1, Color theColor2, const Point& theShadowOffset = Point(1,2)); |
||
| 86 | |||
| 87 | virtual int WriteString(Graphics* g, const SexyString& theString, int theX, int theY, int theWidth = -1, int theJustification = -1, bool drawString = true, int theOffset = 0, int theLength = -1); |
||
| 88 | virtual int WriteWordWrapped(Graphics* g, const Rect& theRect, const SexyString& theLine, int theLineSpacing, int theJustification); |
||
| 89 | virtual int GetWordWrappedHeight(Graphics* g, int theWidth, const SexyString& theLine, int aLineSpacing); |
||
| 90 | virtual int GetNumDigits(int theNumber); |
||
| 91 | virtual void WriteNumberFromStrip(Graphics* g, int theNumber, int theX, int theY, Image* theNumberStrip, int aSpacing); |
||
| 92 | virtual bool Contains(int theX, int theY); |
||
| 93 | virtual Rect GetInsetRect(); |
||
| 94 | void DeferOverlay(int thePriority = 0); |
||
| 95 | |||
| 96 | //////// Layout functions |
||
| 97 | int Left() { return mX; } |
||
| 98 | int Top() { return mY; } |
||
| 99 | int Right() { return mX + mWidth; } |
||
| 100 | int Bottom() { return mY + mHeight; } |
||
| 101 | int Width() { return mWidth; } |
||
| 102 | int Height() { return mHeight; } |
||
| 103 | |||
| 104 | void Layout(int theLayoutFlags, Widget *theRelativeWidget, int theLeftPad = 0, int theTopPad = 0, int theWidthPad = 0, int theHeightPad = 0); |
||
| 105 | }; |
||
| 106 | |||
| 107 | /////// Layout flags used in Widget::Layout method |
||
| 108 | enum LayoutFlags |
||
| 109 | { |
||
| 110 | LAY_SameWidth = 0x0001, |
||
| 111 | LAY_SameHeight = 0x0002, |
||
| 112 | |||
| 113 | LAY_SetLeft = 0x0010, |
||
| 114 | LAY_SetTop = 0x0020, |
||
| 115 | LAY_SetWidth = 0x0040, |
||
| 116 | LAY_SetHeight = 0x0080, |
||
| 117 | |||
| 118 | LAY_Above = 0x0100, |
||
| 119 | LAY_Below = 0x0200, |
||
| 120 | LAY_Right = 0x0400, |
||
| 121 | LAY_Left = 0x0800, |
||
| 122 | |||
| 123 | LAY_SameLeft = 0x1000, |
||
| 124 | LAY_SameRight = 0x2000, |
||
| 125 | LAY_SameTop = 0x4000, |
||
| 126 | LAY_SameBottom = 0x8000, |
||
| 127 | |||
| 128 | LAY_GrowToRight = 0x10000, |
||
| 129 | LAY_GrowToLeft = 0x20000, |
||
| 130 | LAY_GrowToTop = 0x40000, |
||
| 131 | LAY_GrowToBottom = 0x80000, |
||
| 132 | |||
| 133 | LAY_HCenter = 0x100000, |
||
| 134 | LAY_VCenter = 0x200000, |
||
| 135 | LAY_Max = 0x400000, |
||
| 136 | |||
| 137 | LAY_SameSize = LAY_SameWidth | LAY_SameHeight, |
||
| 138 | LAY_SameCorner = LAY_SameLeft | LAY_SameTop, |
||
| 139 | LAY_SetPos = LAY_SetLeft | LAY_SetTop, |
||
| 140 | LAY_SetSize = LAY_SetWidth | LAY_SetHeight |
||
| 141 | }; |
||
| 142 | |||
| 143 | |||
| 144 | } |
||
| 145 | |||
| 146 | #endif //__WIDGET_H__ |