00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef GLCANVAS_H
00026 #define GLCANVAS_H
00027
00028 #include "global.h"
00029 #include <wx/timer.h>
00030
00031
00032
00033 namespace WDS
00034 {
00035
00036 class CTexture;
00037
00038
00039
00040 typedef map< string, CTexture* > TexMap;
00041
00048 class CGLCanvas: public wxGLCanvas
00049 {
00050 public:
00051 CGLCanvas ( wxWindow *parent );
00052 ~CGLCanvas( );
00053
00054
00055 CTexture* LoadTexture( string strTexture, bool bMipMap );
00056 void DeleteTexture( CTexture *pTexture );
00057
00058
00059 void ZoomIn ( );
00060 void ZoomOut( );
00061 void SetZoom( float fZoom );
00062 float GetZoom( ) { return m_fZoom; }
00063
00064
00065 void ScrollTo ( int x, int y );
00066 void ScrollREL( int dx, int dy );
00067
00068 void ClientToOpenGL( wxPoint &pt ) { ClientToOpenGL( pt.x, pt.y ); }
00069 void ClientToOpenGL( int &x, int &y );
00070 void OpenGLToClient( wxPoint &pt ) { OpenGLToClient( pt.x, pt.y ); }
00071 void OpenGLToClient( int &x, int &y );
00072
00073
00074 void BeginDraw( float r, float g, float b, float a );
00075 void EndDraw( );
00076 void FillRect ( const Rect &rcRect, float r, float g, float b, float a = 1.0f );
00077 void DrawRect ( const Rect &rcRect, float r, float g, float b, float a = 1.0f );
00078 void DrawCircle( const wxPoint &ptCenter, int n, float radius, float r, float g, float b, float a = 1.0f );
00079 void DrawLine ( const wxPoint &pt1, const wxPoint &pt2, float width, float r, float g, float b, float a = 1.0f );
00080
00081
00082 void DrawTextBox( int x, int y, float r, float g, float b, float a, const char *szText );
00083 void DrawText( int x, int y, float r, float g, float b, float a, const char *fmt, ... );
00084 void DrawChar( int x, int y, unsigned char c );
00085 wxPoint GetTextExtent( const char *szText );
00086
00087
00088 void OnPaint(wxPaintEvent &event);
00089 void OnSize(wxSizeEvent &event);
00090 void OnEraseBackground(wxEraseEvent &event);
00091 void OnKeyDown(wxKeyEvent &event);
00092 void OnMouseMove( wxMouseEvent &event);
00093 void OnLButtonDown( wxMouseEvent &event);
00094 void OnLButtonUp( wxMouseEvent &event);
00095 void OnScrollBar( wxScrollWinEvent &event);
00096
00097 void Init( );
00098 void UpdateView( );
00099
00100
00101 int GetWidth() { return m_Width; }
00102 int GetHeigth() { return m_Height; }
00103 int GetXPos() { return m_XPos; }
00104 int GetYPos() { return m_YPos; }
00105 Rect GetVisibleRect();
00106 void SetXYPos(int x, int y) { m_XPos = x; m_YPos = y; }
00107
00108 protected:
00109 CTexture* CreateTexture( wxImage *pImage, string strTexture, bool bMipMap );
00110
00111 void BuildMipmaps(int nWidth, int nHeigth, GLenum nFormat, int nBpp, BYTE *pData);
00112 void ScaleForWDS( int inw, int inh, BYTE *in, int outw, int outh, BYTE *out );
00113 int power_of_two(int input);
00114
00115 void ClampView();
00116
00117 protected:
00118 int m_XPos;
00119 int m_YPos;
00120 float m_fZoom;
00121
00122 int m_Width;
00123 int m_Height;
00124
00125 wxPoint m_ptMouseOld;
00126
00127
00128 void OnTimer( wxTimerEvent &event);
00129 wxTimer m_timer;
00130
00131
00132 TexMap m_aTextures;
00133
00134 CTexture *m_pFont;
00135
00136 DECLARE_EVENT_TABLE()
00137 };
00138
00139 }
00140
00141 #endif // GLCANVAS_H
00142
00143