Blender V2.61 - r43446

GPC_Canvas.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef _GPC_CANVAS_H_
00033 #define _GPC_CANVAS_H_
00034 
00035 #include "RAS_ICanvas.h"
00036 #include "RAS_Rect.h"
00037 
00038 #ifdef WIN32
00039     #pragma warning (disable:4786) // suppress stl-MSVC debug info warning
00040     #include <windows.h>
00041 #endif // WIN32
00042 
00043 #include "GL/glew.h"
00044 
00045 #include <map>
00046 
00047 
00048 class GPC_Canvas : public RAS_ICanvas
00049 {
00050 public:
00054     typedef enum {
00055         alignTopLeft,
00056         alignBottomRight
00057     } TBannerAlignment;
00058 
00059     typedef int TBannerId;
00060 
00061 protected:
00065     typedef struct {
00067         TBannerAlignment alignment;
00069         bool enabled;
00071         unsigned int displayWidth;
00073         unsigned int displayHeight;
00075         unsigned int imageWidth;
00077         unsigned int imageHeight;
00079         unsigned char* imageData;
00081         unsigned int textureName;
00082     } TBannerData;
00083     typedef std::map<TBannerId, TBannerData> TBannerMap;
00084 
00086     int m_width;
00088     int m_height;
00091     RAS_Rect m_displayarea;
00092 
00094     TBannerMap m_banners;
00096     bool m_bannersEnabled;
00097 
00098 public:
00099 
00100     GPC_Canvas(int width, int height);
00101 
00102     virtual ~GPC_Canvas();
00103 
00104     void Resize(int width, int height);
00105 
00106 
00111         int 
00112     GetWidth(
00113     ) const {
00114         return m_width;
00115     }
00116     
00117         int 
00118     GetHeight(
00119     ) const {
00120         return m_height;
00121     }
00122 
00123     const 
00124         RAS_Rect &
00125     GetDisplayArea(
00126     ) const {
00127         return m_displayarea;
00128     };
00129 
00130         void
00131     SetDisplayArea(
00132         RAS_Rect *rect
00133     ) {
00134         m_displayarea= *rect;
00135     };
00136     
00137         RAS_Rect &
00138     GetWindowArea(
00139     ) {
00140         return m_displayarea;
00141     }
00142 
00143         void 
00144     BeginFrame(
00145     ) {};
00146 
00150         void 
00151     EndFrame(
00152     );
00153     
00154     void SetViewPort(int x1, int y1, int x2, int y2);
00155 
00156     void ClearColor(float r, float g, float b, float a);
00157 
00163     void SetMouseState(RAS_MouseState mousestate)
00164     {
00165         // not yet      
00166     }
00167 
00168     void SetMousePosition(int x, int y)
00169     {
00170         // not yet
00171     }
00172 
00173     virtual void MakeScreenShot(const char* filename);
00174 
00175     void ClearBuffer(int type);
00176 
00193     TBannerId AddBanner(
00194         unsigned int bannerWidth, unsigned int bannerHeight,
00195         unsigned int imageWidth, unsigned int imageHeight,
00196         unsigned char* imageData, TBannerAlignment alignment = alignTopLeft, 
00197         bool enabled = true);
00198 
00203     void DisposeBanner(TBannerId id);
00204 
00208     void DisposeAllBanners();
00209 
00215     void SetBannerEnabled(TBannerId id, bool enabled = true);
00216 
00221     void SetBannerDisplayEnabled(bool enabled = true);
00222 
00223 protected:
00228     void DisposeBanner(TBannerData& banner);
00229 
00233     void DrawAllBanners(void);
00234 
00238     void DrawBanner(TBannerData& banner);
00239 
00240     struct CanvasRenderState {
00241         int oldLighting;
00242         int oldDepthTest;
00243         int oldFog;
00244         int oldTexture2D;
00245         int oldBlend;
00246         int oldBlendSrc;
00247         int oldBlendDst;
00248         float oldColor[4];
00249         int oldWriteMask;
00250     };
00251 
00252         void            
00253     PushRenderState(
00254         CanvasRenderState & render_state
00255     );
00256         void
00257     PopRenderState(
00258         const CanvasRenderState & render_state
00259     );
00260 
00265         void
00266     SetOrthoProjection(
00267     );
00268     
00269     static TBannerId s_bannerId;
00270 };
00271 
00272 #endif // _GPC_CANVAS_H_
00273