00001
00002
00003
00004
00005
00006
00007 #ifndef OglGui_MenuOnButton_h
00008 #define OglGui_MenuOnButton_h
00009
00010 #ifndef OglGui_Button_h
00011 #include "OglGui/Button.h"
00012 #endif
00013
00014 #ifndef OglGui_Menu_h
00015 #include "OglGui/Menu.h"
00016 #endif
00017
00018 namespace OglGui {
00019
00020 class MenuOnButton : public Button,
00021 public ButtonListener
00022 {
00023 public:
00024 MenuOnButton(Window* parent, int x, int y, int w, int h, strconst label,
00025 Menu* menu=0) :
00026 Button(parent,x,y,w,h,label,BEV_ETCHED,true)
00027 {
00028 Init(menu,w,h);
00029 }
00030
00031 MenuOnButton(Window* parent, int w, int h, strconst label, Menu* menu=0) :
00032 Button(parent,w,h,label,BEV_ETCHED,true)
00033 {
00034 Init(menu,w,h);
00035 }
00036
00037 virtual void ButtonSelectionEvent(Button *src, void* userData)
00038 {
00039 if (!mMenu)
00040 return;
00041 int x = 0, y = 2;
00042 ToTopWindow(src,x,y);
00043 mMenu->Open(x,y);
00044 mActive = true;
00045 }
00046
00047 void SetMenu(Menu* menu) { mMenu = menu; }
00048 void ShowTriangle(bool mode=true) { mShowTriangle = mode; }
00049
00050 void ActiveBorderType(int type)
00051 {
00052 mNonActiveBorderType = GetBorderType();
00053 mActiveBorderType = type;
00054 }
00055
00056 void ShowMenuTriangle()
00057 {
00058 OGC myOGC;
00059 OGCSave(&myOGC);
00060
00061 float w = W(), hH = H()/2, coords[6];
00062 coords[0] = w - (mActive ? 9 : 7);
00063 coords[1] = hH + (mActive ? 2 : 3);
00064 coords[2] = w - 3;
00065 coords[3] = hH + (mActive ? 2 : 0);
00066 coords[4] = w - (mActive ? 6 : 7);
00067 coords[5] = hH - (mActive ? 2 : 3);
00068
00069 ULONG col = GetState() ? 0xff505050 : oglLIGHTGREY;
00070 col = (GetState()==2 || mActive) ? oglBLACK : col;
00071 OGCSetPolyFillMode(theOGC,3);
00072 SetSolidFillColor(col);
00073 FillTriangles(coords,3);
00074 OGCRestore(&myOGC);
00075 }
00076
00077 virtual void DisplayFunc()
00078 {
00079 mActive = (mActive && mMenu) ? mMenu->GetVisible() : false;
00080 if (mActiveBorderType != -2)
00081 SetBorderType(mActive ? mActiveBorderType : mNonActiveBorderType);
00082 Button::DisplayFunc();
00083 if (mShowTriangle)
00084 ShowMenuTriangle();
00085 }
00086
00087 virtual void
00088 MouseFunc(int msg, int but, int state, int x, int y)
00089 {
00090 if (!GetState()) return;
00091
00092 Button::MouseFunc( msg, but, state, x, y );
00093
00094 if (msg == oglMouseEnter)
00095 {
00096 mNonActiveBg = GetBorderBackground();
00097 SetBorderBackground(mStateFeedbackColor);
00098 }
00099 if (msg == oglMouseLeave)
00100 SetBorderBackground(mNonActiveBg);
00101 }
00102
00103 private:
00104 Menu* mMenu;
00105 ULONG mNonActiveBg;
00106 int mNonActiveBorderType;
00107 int mActiveBorderType;
00108 bool mActive;
00109 bool mShowTriangle;
00110
00111 void Init(Menu* menu, int w, int h)
00112 {
00113 mMenu = menu;
00114 mActive = false;
00115 mShowTriangle = true;
00116 mNonActiveBorderType = GetBorderType();
00117 mActiveBorderType = -2;
00118 mDoStateFeedback = false;
00119 SetButtonListener(this);
00120 }
00121 };
00122
00123 }
00124 #endif
00125