- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

uxglxdriver.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/ux/uxglxdriver.hpp 00008 begin : Fri Aug 13 2004 00009 $Id: uxglxdriver.hpp,v 1.6 2005/10/17 16:22:50 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UXGLXDRIVER_HPP 00029 #define UXGLXDRIVER_HPP 00030 00031 #include "../uvideodriver.hpp" 00032 #include "../uvideodevice.hpp" 00033 00034 #include "../events/ukeysym.hpp" 00035 #include "GL/glx.h" 00036 #include <X11/Xlib.h> 00037 00038 namespace ufo { 00039 00040 class UXContext; 00041 class UXDisplay; 00042 class UXGLXDevice; 00043 class UVideoPlugin; 00044 class UPluginBase; 00045 class USharedLib; 00046 00053 class UFO_EXPORT UXGLXDriver : public UVideoDriver { 00054 UFO_DECLARE_DYNAMIC_CLASS(UXGLXDriver) 00055 public: 00056 UXGLXDriver(); 00057 virtual ~UXGLXDriver(); 00058 00059 public: // Implements UVideoDriver 00060 virtual bool init(); 00061 virtual bool isInitialized(); 00062 virtual void quit(); 00063 virtual std::string getName(); 00064 00065 virtual void pumpEvents(); 00066 00067 virtual UVideoDevice * createVideoDevice(); 00068 00069 bool isValid() const; 00070 00071 #define UFO_GLX_PROC(ret,func,params) ret (*func) params; 00072 UFO_GLX_PROC(Bool,glXMakeCurrent,(Display *dpy, GLXDrawable drawable, GLXContext ctx)) 00073 UFO_GLX_PROC(Bool,glXQueryExtension,(Display *dpy, int *errorBase, int *eventBase)) 00074 UFO_GLX_PROC(void,glXSwapBuffers,(Display *dpy, GLXDrawable drawable)) 00075 UFO_GLX_PROC(XVisualInfo*,glXChooseVisual,(Display *dpy, int screen, int *attribList)) 00076 UFO_GLX_PROC(void,glXDestroyContext,(Display *dpy, GLXContext ctx)) 00077 UFO_GLX_PROC(GLXContext,glXCreateContext,(Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct)) 00078 #undef UFO_GLX_PROC 00079 00080 public: // Public methods 00081 Display * getX11Display() const; 00082 Window getRootWindow() const; 00083 Atom * getDeleteWindowAtom(); 00084 UXContext * getContextFromWindow(int window) const; 00085 00086 public: // Public methods 00087 void initKeymap(); 00088 void pushXEvent(UXContext * context, const XEvent & event); 00089 UKeyCode_t mapX11Keycode(const XKeyEvent & xkey); 00090 wchar_t mapX11Unicode(const XKeyEvent & xkey); 00091 UMod::Modifier mapX11Modifiers(int modifiers); 00092 00093 protected: 00094 friend class UXGLXDevice; 00096 void destroyed(UXGLXDevice * device); 00097 00098 public: // plugin methods 00099 static UPluginBase * createPlugin(); 00100 static void destroyPlugin(UPluginBase * plugin); 00101 00102 private: // Private attributes 00103 bool m_isValid; 00104 bool m_isInit; 00105 bool m_createdGLDriver; 00106 Display * m_x11Display; 00107 Window m_rootWindow; 00108 Atom m_deleteWindowAtom; 00109 UXDisplay * m_display; 00110 std::vector<UXGLXDevice*> m_windowMap; 00111 00112 UKeyCode_t m_MISC_keymap[256]; 00113 UKeyCode_t m_ODD_keymap[255]; 00114 }; 00115 00121 class UFO_EXPORT UXGLXDevice : public UVideoDevice { 00122 UFO_DECLARE_DYNAMIC_CLASS(UXGLXDevice) 00123 public: 00124 UXGLXDevice(UXGLXDriver * driver); 00125 virtual ~UXGLXDevice(); 00126 public: // Implements UVideoDevice 00127 virtual void setSize(int w, int h); 00128 virtual UDimension getSize() const; 00129 00130 virtual void setLocation(int x, int y); 00131 virtual UPoint getLocation() const; 00132 00133 virtual void setTitle(const std::string & title); 00134 virtual std::string getTitle() const; 00135 00136 virtual void setDepth(int depth); 00137 virtual int getDepth() const; 00138 00139 virtual void swapBuffers(); 00140 virtual void makeContextCurrent(); 00141 00142 virtual bool show(); 00143 virtual void hide(); 00144 00145 virtual void setFrameStyle(uint32_t frameStyle); 00146 virtual uint32_t getFrameStyle() const; 00147 00148 virtual void setInitialFrameState(uint32_t frameState); 00149 virtual uint32_t getFrameState() const; 00150 00151 virtual void setFrame(UXFrame * frame); 00152 virtual void notify(uint32_t type, int arg1, int arg2, int arg3, int arg4); 00153 public: 00154 virtual UXFrame * getFrame(); 00155 Window getWindow() { return m_window; } 00156 GLXContext getGLContext() { return m_glContext; } 00157 00158 void setDecorations(); 00159 void setSizeHints(); 00160 void setWMHints(); 00161 protected: 00162 virtual XVisualInfo * chooseVisual(); 00163 int getAttribute(int key); 00164 void setAttribute(int key, int value); 00165 00166 private: // Private attributes 00167 UXGLXDriver * m_glxDriver; 00168 Window m_window; 00169 GLXContext m_glContext; 00170 UXFrame * m_frame; 00171 mutable UDimension m_size; 00172 mutable UPoint m_pos; 00173 bool m_isVisible; 00174 uint32_t m_frameStyle; 00175 uint32_t m_frameState; 00176 int m_depth; 00177 std::string m_title; 00178 std::map<int, int> m_attributes; 00179 }; 00180 00181 } // namespace ufo 00182 00183 #endif // UXGLXDRIVER_HPP

The libUFO Project - written by Johannes Schmidt