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

display_xwindow.h

Go to the documentation of this file.
00001 /*
00002         $Id: display_xwindow.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_display_xwindow
00016 #define header_display_xwindow
00017 
00018 #ifdef USE_X11
00019 
00020 #include "Display/Display/Generic/displaycard_generic.h"
00021 #include "API/Core/System/keep_alive.h"
00022 
00023 #include <X11/Xlib.h>
00024 #include <X11/Xutil.h>
00025 #include <X11/cursorfont.h>
00026 
00027 #include "target_ximage_std.h"
00028 #include "target_ximage_shm.h"
00029 #include "target_ximage_dga.h"
00030 
00031 #include "Core/System/Unix/init_linux.h"
00032 #include "x11_resolution.h"
00033 
00034 class CL_XWindow_CompatibleCard : public CL_DisplayCard_Generic
00035 // used by PTC and GLX implementation.
00036 {
00037 public:
00038         CL_XWindow_CompatibleCard(int card_no)
00039         : CL_DisplayCard_Generic(card_no)
00040         {
00041                 fullscreen = false;
00042                 cursor = None;
00043         }
00044         
00045         static CL_Signal_v1<XEvent&> sig_xevent;
00046         
00047         virtual Window get_window()=0;
00048         virtual Display *get_display()=0;
00049         virtual Window get_root()=0;
00050 
00051         virtual int get_total_memory() { return -1; }
00052         virtual const std::list<CL_VidMode*> &get_videomodes() 
00053         {
00054                 if (modelist.empty())
00055                         fill_modelist();
00056                 return modelist; 
00057         }
00058         virtual bool is_fullscreen() { return fullscreen; }
00059 
00060         // used by mouse code
00061         int get_win_width() { return win_width; }
00062         int get_win_height() { return win_height; }
00063 
00064         virtual void show_system_cursor()
00065         {
00066                 if (cursor != None)
00067                 {
00068                         XFreeCursor(get_display(), cursor);
00069                 }
00070 
00071                 XUndefineCursor(get_display(), get_window());
00072         }
00073         
00074         virtual void hide_system_cursor()
00075         {
00076                 if (cursor == None)
00077                 {
00078                         char bm_no_data[] = { 0,0,0,0, 0,0,0,0 };
00079                         Pixmap pixmap_no_data = XCreateBitmapFromData(
00080                                 get_display(),
00081                                 get_window(),
00082                                 bm_no_data,
00083                                 8, 8);
00084                 
00085                         XColor black;
00086                         memset(&black, 0, sizeof(XColor));
00087                         black.flags = DoRed | DoGreen | DoBlue;
00088 
00089                         cursor = XCreatePixmapCursor(
00090                                 get_display(),
00091                                 pixmap_no_data,
00092                                 pixmap_no_data,
00093                                 &black,
00094                                 &black,
00095                                 0, 0);
00096 
00097                         XFreePixmap(get_display(), pixmap_no_data);
00098 
00099 //                      cursor = XCreateFontCursor(get_display(), XC_tcross);
00100                 }
00101         
00102                 XDefineCursor(get_display(), get_window(), cursor);
00103         }
00104         
00105 protected:
00106         virtual void get_real_resolution(int* width, int* height);
00107         void fill_modelist();
00108 
00109         bool fullscreen;
00110         int win_width, win_height;
00111 
00112 private:
00113         std::list<CL_VidMode*> modelist;
00114         Cursor cursor;
00115 };
00116 
00117 class CL_XWindow_DisplayCard
00118 : public CL_XWindow_CompatibleCard, public CL_KeepAlive
00119 {
00120 public:
00121         CL_XWindow_DisplayCard(Display *dpy, Window root, int card_no);
00122         virtual ~CL_XWindow_DisplayCard();
00123         
00124         // CL_XWindow_CompatibleCard:
00125         // --------------------------
00126 
00127         virtual Window get_window() { return m_win; }
00128         virtual Display *get_display() { return m_dpy; }
00129         virtual Window get_root() { return m_root; }
00130 
00131         // CL_DisplayCard functions:
00132         // -------------------------
00133 
00134         virtual void flip_display(bool sync=false);
00135         virtual void put_display(const class CL_Rect &rect);
00136         virtual void set_palette(CL_Palette *palette);
00137         virtual CL_Palette *get_palette();
00138         virtual void set_videomode(int width, int height, int bpp, bool fullscreen, bool allow_resize, bool video_memory);
00139         virtual bool is_initialized();
00140 
00141         virtual std::string get_name() { return "X11 Display"; }
00142 
00143         // CL_DisplayCard_Generic functions:
00144         // ---------------------------------
00145 
00146         virtual CL_Target *get_target() { return m_target; }
00147         virtual CL_Target *get_frontbuffer() { return m_target_front; }
00148         
00149         // CL_System_KeepAlive functions:
00150         // ------------------------------
00151 
00152         virtual void keep_alive();
00153         
00154 protected: // inherited by mesa impl.
00155         virtual CL_Target_XImage *create_target();
00156         virtual XVisualInfo *get_visual_info() { return &m_visual_info; }
00157 
00158 private:
00159         void on_resize(int width, int height);
00160 
00161         bool m_initialized;
00162         CL_Palette *m_palette;
00163         CL_Target_XImage *m_target;
00164         CL_Target_XImage *m_target_front;
00165 
00166         XVisualInfo m_visual_info;
00167         Display *m_dpy;
00168         Window m_win;
00169         Window m_root;
00170         GC m_gc;
00171         int m_scr;
00172         Colormap m_color_map;
00173         
00174         CL_X11Resolution resolution;
00175         CL_Slot slot_resize;
00176 };
00177 
00178 #endif /* USE_X11 */
00179 
00180 #endif

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