1 #ifndef BASE_MANAGER_H_ 2 #define BASE_MANAGER_H_ 3 4 #include <MyGUI.h> 5 #include <MyGUI_OpenGL3Platform.h> 6 7 #include "InputManager.h" 8 #include "PointerManager.h" 9 10 #ifdef EMSCRIPTEN 11 #include <SDL2/SDL.h> 12 #else 13 #include <SDL.h> 14 #endif 15 16 namespace base 17 { 18 19 class BaseManager : 20 public input::InputManager, 21 public input::PointerManager, 22 public MyGUI::OpenGL3ImageLoader 23 { 24 public: 25 BaseManager(); 26 27 virtual void prepare(); 28 bool create(int _width = 1024, int _height = 768); 29 void destroy(); 30 void run(); 31 void quit(); 32 33 void setWindowCaption(const std::wstring& _text); makeScreenShot()34 void makeScreenShot() { } 35 36 const std::string& getRootMedia(); 37 void setResourceFilename(const std::string& _flename); 38 void addResourceLocation(const std::string& _name, bool _recursive = false); 39 40 MyGUI::MapString getStatistic(); 41 42 /*internal:*/ 43 void _windowResized(int w, int h); 44 virtual void* loadImage(int& _width, int& _height, MyGUI::PixelFormat& _format, const std::string& _filename); 45 virtual void saveImage(int _width, int _height, MyGUI::PixelFormat _format, void* _texture, const std::string& _filename); 46 47 protected: createScene()48 virtual void createScene() { } destroyScene()49 virtual void destroyScene() { } 50 51 virtual void setupResources(); 52 53 virtual void injectMouseMove(int _absx, int _absy, int _absz); 54 virtual void injectMousePress(int _absx, int _absy, MyGUI::MouseButton _id); 55 virtual void injectMouseRelease(int _absx, int _absy, MyGUI::MouseButton _id); 56 virtual void injectKeyPress(MyGUI::KeyCode _key, MyGUI::Char _text); 57 virtual void injectKeyRelease(MyGUI::KeyCode _key); 58 59 virtual void createGui(); 60 virtual void destroyGui(); 61 62 virtual void setWindowMaximized(bool _value); 63 virtual bool getWindowMaximized(); 64 65 virtual void setWindowCoord(const MyGUI::IntCoord& _value); 66 virtual MyGUI::IntCoord getWindowCoord(); 67 68 private: 69 //void resizeRender(int _width, int _height); 70 bool createRender(int _width, int _height, bool _windowed); 71 void drawOneFrame(); 72 void destroyRender(); 73 void* convertPixelData(SDL_Surface *_image, MyGUI::PixelFormat& _myGuiPixelFormat); 74 void updateSDL_Keycode(); 75 76 private: 77 MyGUI::Gui* mGUI; 78 MyGUI::OpenGL3Platform* mPlatform; 79 80 bool mExit; 81 SDL_Event mEvent; 82 SDL_Window* mWindow; 83 SDL_GLContext mContext; 84 std::string mRootMedia; 85 std::string mResourceFileName; 86 bool mWindowOn; 87 SDL_Keycode mKeyCode; 88 int mFpsCounter; 89 }; 90 91 } // namespace base 92 93 #endif // BASE_MANAGER_H_ 94