Main Page | Class List | File List | Class Members | Related Pages

glcanvas.h

00001 /***************************************************************************
00002                            glcanvas.h
00003                            -------------------
00004     begin                : 2004-05-24 22:17
00005     copyright            : (C) 2004-2005 by Michael Menne
00006     email                : menne@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 #ifndef GLCANVAS_H
00026 #define GLCANVAS_H
00027 
00028 #include "global.h"
00029 #include <wx/timer.h>
00030 
00031 //#include "wxscrollglcanvas.h"
00032 
00033 namespace WDS
00034 {
00035 
00036 class CTexture;
00037 
00038 // Typen
00039 //typedef hash_map< string, CTexture* > TexMap;
00040 typedef map< string, CTexture* > TexMap;
00041 
00048 class CGLCanvas: public wxGLCanvas //, public wxScrollHelper
00049 {
00050 public:
00051     CGLCanvas ( wxWindow *parent );
00052     ~CGLCanvas( );
00053 
00054     // Textur Funktionen
00055     CTexture* LoadTexture( string strTexture, bool bMipMap );
00056     void DeleteTexture( CTexture *pTexture );
00057 
00058     // Zoom Funktionen
00059     void  ZoomIn ( );
00060     void  ZoomOut( );
00061     void  SetZoom( float fZoom );
00062     float GetZoom( ) { return m_fZoom; }
00063 
00064     // Scrolling functions
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     // Drawing functions
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     // Text functions
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      // Event Funktionen
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( ); // Sollte aufgerufen werden, nachdem eine neue Karte geladen wurde
00099 
00100     // Get / Set Funktionen
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     // HACK: make resizing work for wxGTK.
00128     void OnTimer( wxTimerEvent &event);
00129     wxTimer m_timer;
00130 
00131     // Map mit allen gelandenen Texturen
00132     TexMap m_aTextures;
00133 
00134     CTexture *m_pFont;  // Font Textur
00135 
00136 DECLARE_EVENT_TABLE()
00137 };
00138 
00139 }
00140 
00141 #endif // GLCANVAS_H
00142 
00143 // kate: space-indent off; tab-width 4; replace-tabs off;

Generated on Sun Jan 16 18:20:26 2005 for WDSMap by  doxygen 1.3.9.1