#pragma once

#define MXCAD_OPENGLFLAG_GLFW_DECORATED 1

#ifndef MXCADHANDLE
	#define MXCADHANDLE void*
#endif


class MxCADAppDefalut;
class MXCADDLL MxCADApp {
	friend class MxCADAppDefalut;
public:
	MxCADApp();
	~MxCADApp();
	bool Free();
	void Log(const char* pszString);

	void CallMain(const std::function<void()>& callbackp, bool isAsync = false);

	void InitWorkDir(const std::string& sWorkDir);

	void InitUserFileDir(const std::string& sUserFileDir);

	void InitAndroidPrivateDir(const std::string& sUserFileDir);
#ifdef MXANDROID
	std::string getAndroidPrivateDir();

#elif defined(MXHM)

	void InitHmSandboxDir(const std::string& sDir);

	std::string  GetHmSandboxDir();
	
#endif
	void SetExternalStorageDirectory(const std::string& sUserFileDir);

	void CallMainIdeaTimer();

	void SetUseUtf8(bool isUseUtf8);

	void SetDefaultTrueTypeFontFile(const char* pszPath);

	void SetOpenGlThread(bool isOpenGlThread = true);

	static MxCADApp& instance();

protected:
	MxCADApp(bool isDefaut);
	void Init();
	void UnInit();
private:
	static MxCADApp* s_pInstance;
	bool  m_isDefault;
};

#define MXAPP MxCADApp::instance()

class MxCADOpenGlView;
class MxCADObject;
class MXCADDLL MxCADView {
public:
	MxCADView();
	~MxCADView();
	bool Create(int width, int height, HWND hParentWnd, bool isVisible = true, int posx = 0, int posy = 0,int iOpenGlWindowFlag = 0, MxCADOpenGlView* pOpenGLView = 0);

	bool Free();

	MXCADHANDLE GetOcxHandle();

	bool   ReadFile(const char* pszFileName);


    void   UpdateDisplay(bool isClearOpenGL = true);

	bool   SetMxDrawPosition(int posx, int posy, int width, int height);

	bool   OpenGLWindowShouldClose();
	void   OpenGLPollEvents();
	void   OpenGLWaitEvents();
	void   OpenGLSetCallOnPaint(bool isCall);

	void    InvalidVboVaoEbo();
	void    RendererRecreated();

	inline MxCADObject* GetMxCADObject() const {
		return m_pMxCAD;
	}

private:
	MxCADObject* m_pMxCAD;
};
