Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

IPhoneApp.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 #ifndef OglGui_IPhoneApp_h
00004 #define OglGui_IPhoneApp_h
00005 
00006 #ifndef OglGui_IPhoneAppListener_h
00007 #include "OglGui/IPhoneAppListener.h"
00008 #endif
00009 
00010 #ifndef OglGui_Button_h
00011 #include "OglGui/Button.h"
00012 #endif
00013 
00014 #ifndef OglGui_OpenClose_
00015 #include "OglGui/OpenClose.h"
00016 #endif
00017 
00018 namespace OglGui {
00019 
00020 class IPhoneApp : public Window, public ButtonListener
00021 {
00022 public:
00023     IPhoneApp(int x, int y, int w, int h) :
00024         Window(x,y,w,h)
00025     {
00026         Init(w,h);
00027     }
00028 
00029     void SetIPhoneAppListener(IPhoneAppListener* l, void *userData)
00030     {
00031         mListener = l;
00032         mListenerData = userData;
00033     }
00034 
00035     Button* AddCommand(strconst cmd, Window* wnd)
00036     {
00037         Button* btn = new Button(mCmdBtnWnd, 116, 60, cmd, BEV_ETCHED, true);
00038         btn->SetButtonListener(this, (void*) wnd);
00039         return btn;
00040     }
00041 
00042     Window* CmdBtnWnd()
00043     {
00044         return mCmdBtnWnd;
00045     }
00046 
00047     OpenClose* AppOpenCloser()     { return mAppOpenCloser; }
00048     OpenClose* CmdOpenCloser()     { return mCmdOpenCloser; }
00049 
00050     void OpenApp(Window* wnd, int x, int y, int w, int h, int ms=500)
00051     {
00052         SetAlwaysDraw(true);
00053         mAppOpenCloser->Open(wnd, x, y, w, h, ms);
00054         mAppOpening   = true;
00055     }
00056     void CloseApp(Window* wnd, int ms=500)
00057     {
00058         SetAlwaysDraw(true);
00059         mAppOpenCloser->Target(wnd);
00060         mAppOpenCloser->Close(ms);
00061         mAppClosing = true;;
00062     }
00063 
00064     void OpenCmdPicker(Window* wnd, int x, int y, int w, int h)
00065     {
00066         SetAlwaysDraw(true);
00067         mCmdOpening = true;
00068         mCommandPickerWnd = wnd;
00069         mCmdOpenCloser->Open(wnd, x, y, w, h);
00070     }
00071     void CloseCmdPicker(Window* wnd)
00072     {
00073         SetAlwaysDraw(true);
00074         mCommandPickerWnd = wnd;
00075         mCmdClosing = true;
00076         mCmdOpenCloser->Close();
00077     }
00078 
00079     void StartCmd()
00080     {
00081         mStarting = true;
00082         mCmdBtnWnd->RepositionViewports();
00083         mCmdBtnWnd->ScaleChildren();
00084         OpenCmdPicker(mCmdBtnWnd, 0, 0, 10, 10);
00085     }
00086 
00087     virtual void ButtonSelectionEvent(Button *src, void *userData)
00088     {
00089         SetAlwaysDraw(true);
00090         // BACK BUTTON
00091         if (userData == (void*) BACK_BTN_ID)
00092         {
00093             if (mListener != 0)
00094                 mListener->OnIPhoneAppBackButton(this, mCommandPickerWnd, mListenerData);
00095             OpenCmdPicker(mCommandPickerWnd, 0, 0, 10, 10);
00096             mAppClosing = true;
00097             mAppOpenCloser->Close();
00098             return;
00099         }
00100 
00101         // COMMAND BUTTONS
00102         if (mListener != 0)
00103             mListener->OnIPhoneAppCmdButton(this, src, mListenerData);
00104 
00105         // Close the command button window
00106         //mCmdClosing = true;
00107         //mCmdOpenCloser->Close();
00108         CloseCmdPicker(mCommandPickerWnd);
00109 
00110         // Open the new target window
00111         int x,y,w,h;
00112         src->GetDimensions(x, y, w, h);
00113         OpenApp((Window*) userData, x, y, w, h);
00114     }
00115 
00116     void Stopping(bool& b)
00117     {
00118         b = false;
00119         SetAlwaysDraw(mStarting|mAppOpening|mAppClosing|mCmdOpening|mCmdClosing);
00120         UpdateScene();
00121     }
00122 
00123     virtual void DisplayFunc()
00124     {
00125         mCmdOpenCloser->DisplayFunc();
00126         mAppOpenCloser->DisplayFunc();
00127         if (mStarting && !mCmdOpenCloser->Opening())
00128             Stopping(mStarting);
00129         if (mAppOpening && !mAppOpenCloser->Opening())
00130             Stopping(mAppOpening);
00131         if (mAppClosing && !mAppOpenCloser->Closing())
00132             Stopping(mAppClosing);
00133         if (mCmdOpening && !mCmdOpenCloser->Opening())
00134             Stopping(mCmdOpening);
00135         if (mCmdClosing && !mCmdOpenCloser->Closing())
00136             Stopping(mCmdClosing);
00137         Window::DisplayFunc();
00138     }
00139 
00140 private:
00141 
00142     void Init(int w, int h)
00143     {
00144         mCmdBtnWnd = new Window(this, 0, 0, W(), H());
00145         //mCommandPickerWnd->ConnectTo(this);
00146         mAppOpenCloser = new OpenClose(this);
00147         mCmdOpenCloser = new OpenClose(this);
00148 
00149         mListener    = 0;
00150         mStarting    = false;
00151         mAppClosing  = false;
00152         mAppOpening  = false;
00153         mCmdClosing  = false;
00154         mCmdOpening  = false;
00155     }
00156 
00157     IPhoneAppListener*      mListener;
00158     void*                   mListenerData;
00159 
00160     Window*                 mCommandPickerWnd;
00161     Window*                 mCmdBtnWnd;
00162     //Window*                 mTargetWnd;
00163     OpenClose*              mCmdOpenCloser;
00164     OpenClose*              mAppOpenCloser;
00165     bool                    mStarting;
00166     bool                    mAppOpening;
00167     bool                    mAppClosing;
00168     bool                    mCmdOpening;
00169     bool                    mCmdClosing;
00170 
00171 public:
00172     static const int BACK_BTN_ID  = 4393;
00173 };
00174 
00175 } // namespace OglGui
00176 #endif

Generated on Fri Mar 19 09:31:36 2010 for ImpalaSrc by  doxygen 1.5.1