Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

displaycard_generic.h

Go to the documentation of this file.
00001 /*
00002         $Id: displaycard_generic.h,v 1.2 2001/03/15 12:14:46 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #ifndef header_displaycard_generic
00016 #define header_displaycard_generic
00017 
00018 #include "API/Display/Display/target.h"
00019 #include "API/Display/Display/displaycard.h"
00020 #include "API/Core/System/cl_assert.h"
00021 
00022 class CL_SurfaceProvider;
00023 class CL_CardSurface;
00024 class CL_Target;
00025 class CL_CardSurface_Blitter;
00026 class CL_Blitters;
00027 
00028 #include <stack>
00029 
00030 class CL_DisplayCard_Generic : public CL_DisplayCard
00031 {
00032 public:
00033         CL_DisplayCard_Generic(int card_no)
00034         {
00035                 m_card_no = card_no;
00036                 m_width = 0;
00037                 m_height = 0;
00038                 m_bpp = 0;
00039                 m_cur_clip = CL_ClipRect(0,0,0,0);
00040         }
00041 
00042         virtual ~CL_DisplayCard_Generic() {;}
00043         
00044         virtual CL_CardSurface *create_cardsurface_video(
00045                 CL_SurfaceProvider *provider);
00046 
00047         virtual CL_CardSurface *create_cardsurface_system(
00048                 CL_SurfaceProvider *provider);
00049 
00050         virtual int get_card_no() { return m_card_no; }
00051 
00052         virtual int get_width() { return m_width; }
00053         virtual int get_height() { return m_height; }
00054         virtual int get_bpp() { return m_bpp; }
00055         virtual bool is_fullscreen() { return m_fullscreen; }
00056         virtual bool allow_resize() { return m_allow_resize; }
00057         
00058         virtual void push_clip_rect()
00059         {
00060                 m_clip_stack.push_front(m_cur_clip);
00061         }
00062 
00063         virtual void push_clip_rect(const CL_ClipRect &clip)
00064         {
00065                 push_clip_rect();
00066                 m_cur_clip = m_cur_clip.clip(clip);
00067                 if (get_target() != NULL) get_target()->set_clip_rect(m_cur_clip);
00068         }
00069         virtual CL_ClipRect get_clip_rect()
00070         {
00071                 return m_cur_clip;
00072         }
00073 
00074         virtual void set_clip_rect(const CL_ClipRect &clip)
00075         {
00076                 m_cur_clip = clip;
00077                 if (get_target() != NULL) get_target()->set_clip_rect(m_cur_clip);
00078         }
00079 
00080         virtual void pop_clip_rect()
00081         {
00082                 m_cur_clip = m_clip_stack.front();
00083                 m_clip_stack.pop_front();
00084                 if (get_target() != NULL) get_target()->set_clip_rect(m_cur_clip);
00085         }
00086 
00087         virtual void clear_display(float red=0, float green=0, float blue=0, float alpha=1);
00088         virtual void fill_rect(int x1, int y1, int x2, int y2, float r, float g, float b, float a);
00089         virtual void draw_rect(int x1, int y1, int x2, int y2, float r, float g, float b, float a);
00090         virtual void draw_line(int x1, int y1, int x2, int y2, float r, float g, float b, float a);
00091         
00092         virtual void sync_buffers();
00093 
00094         virtual CL_Target *get_frontbuffer()=0;
00095         void frontbuffer_lock();
00096         void frontbuffer_unlock();
00097 
00098         class CL_FlipDisplayCallback_Generic
00099         {
00100         public:
00101                 virtual void pre_flip()=0;
00102                 virtual void post_flip()=0;
00103         };
00104 
00105         void add_callback(CL_FlipDisplayCallback_Generic *callback)
00106         {
00107                 callbacks.push_back(callback);
00108         }
00109         
00110         virtual void show_system_cursor()
00111         {
00112                 static bool warning = true;
00113                 if (warning)
00114                 {
00115                         cl_info(1, "System cursor show() not implemented for this display target.");
00116                         warning = false;
00117                 }
00118         }
00119 
00120         virtual void hide_system_cursor()
00121         {
00122                 static bool warning = true;
00123                 if (warning)
00124                 {
00125                         cl_info(1, "System cursor hide() not implemented for this display target.");
00126                         warning = false;
00127                 }
00128         }
00129 
00130 protected:
00131         std::list<CL_FlipDisplayCallback_Generic*> callbacks;
00132 
00133         void signal_preflip()
00134         {
00135                 for (std::list<CL_FlipDisplayCallback_Generic*>::iterator it = callbacks.begin();
00136                         it!=callbacks.end(); 
00137                         it++)
00138                 {
00139                         (*it)->pre_flip(); 
00140                 }
00141         }
00142 
00143         void signal_postflip()
00144         {
00145                 for (std::list<CL_FlipDisplayCallback_Generic*>::iterator it = callbacks.begin();
00146                         it!=callbacks.end(); 
00147                         it++)
00148                 {
00149                         (*it)->post_flip(); 
00150                 }
00151         }
00152 
00153         friend CL_CardSurface_Blitter;
00154 
00155         void set_gfxmode(int width, int height, int bpp, bool fullscreen, bool allow_resize)
00156         {
00157                 m_width = width;
00158                 m_height = height;
00159                 m_bpp = bpp;
00160                 m_fullscreen = fullscreen;
00161                 m_allow_resize = allow_resize;
00162                 
00163                 m_cur_clip = CL_ClipRect(0, 0, width, height);
00164                 while (m_clip_stack.empty() == false) m_clip_stack.pop_front();
00165         }
00166 
00167         void set_resize(int width, int height)
00168         {
00169                 m_width = width;
00170                 m_height = height;
00171 
00172                 if (m_clip_stack.empty())
00173                 {
00174                         set_clip_rect(CL_ClipRect(0, 0, width, height));
00175                 }
00176                 else
00177                 {
00178                         m_clip_stack.back() = CL_ClipRect(0, 0, width, height);
00179                 }
00180 
00181                 m_sig_resize(width, height);
00182         }
00183 
00184         // Implement those to get hardware support:
00185         virtual CL_Blitters create_hw_blitters(CL_SurfaceProvider *provider);
00186         virtual CL_Blitters create_hw_dynamic_blitters(CL_SurfaceProvider *provider);
00187 
00188         CL_ClipRect m_cur_clip;
00189         std::deque<CL_ClipRect> m_clip_stack;
00190 
00191 public:
00192         virtual void push_translate_offset() 
00193         {
00194                 if (get_target() == get_frontbuffer())
00195                 {
00196                         get_target()->push_translate_offset();
00197                 }
00198                 else
00199                 {
00200                         get_target()->push_translate_offset();
00201                         get_frontbuffer()->push_translate_offset();
00202                 }
00203         }
00204         virtual void push_translate_offset(int x, int y) 
00205         { 
00206                 if (get_target() == get_frontbuffer())
00207                 {
00208                         get_target()->push_translate_offset(x, y);
00209                 }
00210                 else
00211                 {
00212                         get_target()->push_translate_offset(x, y);
00213                         get_frontbuffer()->push_translate_offset(x, y);
00214                 }
00215         }
00216         virtual int  get_translate_offset_x() { return get_target()->get_translate_offset_x(); }
00217         virtual int  get_translate_offset_y() { return get_target()->get_translate_offset_y(); }
00218         virtual void set_translate_offset(int x, int y) 
00219         { 
00220                 if (get_target() == get_frontbuffer())
00221                 {
00222                         get_target()->set_translate_offset(x, y);
00223                 }
00224                 else
00225                 {
00226                         get_target()->set_translate_offset(x, y);
00227                         get_frontbuffer()->set_translate_offset(x, y);
00228                 }
00229         }
00230         virtual void pop_translate_offset() 
00231         { 
00232                 if (get_target() == get_frontbuffer())
00233                 {
00234                         get_target()->pop_translate_offset();
00235                 }
00236                 else
00237                 {
00238                         get_target()->pop_translate_offset();
00239                         get_frontbuffer()->pop_translate_offset();
00240                 }
00241         }
00242 
00243         virtual CL_Signal_v2<int, int> &get_sig_resize() { return m_sig_resize; }
00244         virtual CL_Signal_v1<const CL_Rect &> &get_sig_paint() { return m_sig_paint; }
00245 
00246 private:
00247         int m_card_no;
00248 
00249         int m_width;
00250         int m_height;
00251         int m_bpp;
00252 
00253         bool m_allow_resize;
00254         bool m_fullscreen;
00255 
00256         CL_Signal_v2<int, int> m_sig_resize;
00257         CL_Signal_v1<const CL_Rect &> m_sig_paint;
00258 
00259         void fill_rect_opaque(int x1, int y1, int x2, int y2, float r, float g, float b, float a);
00260 };
00261 
00262 #endif

Generated at Wed Apr 4 19:54:00 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001