📄 fg__x11adaptor_8cpp-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>FishGUI: FG_X11Adaptor.cpp Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- 制作者 Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="main.html">首页</a> | <a class="qindex" href="modules.html">模块</a> | <a class="qindex" href="hierarchy.html">类继承关系</a> | <a class="qindex" href="classes.html">按字典顺序排序的列表</a> | <a class="qindex" href="annotated.html">组合类型列表</a> | <a class="qindex" href="files.html">文件列表</a> | <a class="qindex" href="functions.html">组合类型成员</a> | <a class="qindex" href="globals.html">文件成员</a></div><h1>FG_X11Adaptor.cpp</h1><a href="FG__X11Adaptor_8cpp.html">浏览该文件的文档。</a><div class="fragment"><pre>00001 <span class="comment">/*--------------------------------------------------------------------------</span>00002 <span class="comment"></span>00003 <span class="comment"> FG_X11Adaptor.cpp - X11的适配器类的实现文件</span>00004 <span class="comment"></span>00005 <span class="comment"> 本程序是FishGUI软件的一部分</span>00006 <span class="comment"></span>00007 <span class="comment"> 版权所有 (C) 2003,2004 王咏武</span>00008 <span class="comment"> http://www.contextfree.net/wangyw/</span>00009 <span class="comment"></span>00010 <span class="comment">----------------------------------------------------------------------------</span>00011 <span class="comment"></span>00012 <span class="comment"> 作者对 FishGUI 软件及其所有源代码授权如下:</span>00013 <span class="comment"></span>00014 <span class="comment"> 允许任何个人、组织、机构、企业无偿获得、修改、使用、重新发布 FishGUI 软</span>00015 <span class="comment"> 件及其源代码,或按照有偿或者无偿的方式发行基于 FishGUI 源代码的全部或部</span>00016 <span class="comment"> 分内容开发的软件产品,——但行使以上权利时,须遵守以下约定:</span>00017 <span class="comment"></span>00018 <span class="comment"> 1、重新发布 FishGUI 软件及其源代码时,不得隐去软件及其源代码中原有的版</span>00019 <span class="comment"> 权信息和开发者标识。</span>00020 <span class="comment"></span>00021 <span class="comment"> 2、发行基于 FishGUI 源代码的全部或部分内容开发的软件产品时,必须在产品</span>00022 <span class="comment"> 的显著位置标明以下字样:</span>00023 <span class="comment"></span>00024 <span class="comment"> 【本产品的一部分功能是基于王咏武在 FishGUI 软件中的工作完成的】</span>00025 <span class="comment"></span>00026 <span class="comment"> 3、在正式出版物中引用 FishGUI 的文档、源代码或注释内容的,应注明软件的</span>00027 <span class="comment"> 原作者为王咏武。</span>00028 <span class="comment"></span>00029 <span class="comment">--------------------------------------------------------------------------*/</span>00040 <span class="preprocessor">#include <stdio.h></span>00041 <span class="preprocessor">#include <stdlib.h></span>00042 <span class="preprocessor">#include <string.h></span>00043 <span class="preprocessor">#include <unistd.h></span>00044 <span class="preprocessor">#include <sys/time.h></span>00045 <span class="preprocessor">#include <X11/keysym.h></span>00046 <span class="preprocessor">#include <X11/Xlib.h></span>00047 <span class="preprocessor">#include <X11/Xutil.h></span>00048 <span class="preprocessor">#include "<a class="code" href="FG__X11DrawInterface_8h.html">FG_X11DrawInterface.h</a>"</span>00049 <span class="preprocessor">#include "<a class="code" href="FG__X11Adaptor_8h.html">FG_X11Adaptor.h</a>"</span>00050 00051 <span class="preprocessor">#if defined(WIN32) && defined(_DEBUG)</span>00052 <span class="preprocessor"></span> <span class="comment">/* Trace memory allocation in windows debug version */</span>00053 <span class="preprocessor"> #include <crtdbg.h></span>00054 <span class="keyword">static</span> <span class="keywordtype">char</span> THIS_FILE[] = __FILE__;00055 <span class="preprocessor"> #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)</span>00056 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* _DEBUG */</span>00057 <a name="l00058"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a0">00058</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a0">COLOR_BLACK</a>;<a name="l00059"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a1">00059</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a1">COLOR_GRAY</a>;<a name="l00060"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a2">00060</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a2">COLOR_WHITE</a>;<a name="l00061"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a3">00061</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a3">COLOR_DARKGRAY</a>;<a name="l00062"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a4">00062</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a4">COLOR_BLUE</a>;<a name="l00063"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a5">00063</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a5">COLOR_BLUE1</a>;<a name="l00064"></a><a class="code" href="FG__X11Adaptor_8cpp.html#a6">00064</a> <a class="code" href="group__Color.html#ga0">COLORVAL</a> <a class="code" href="FG__X11Adaptor_8cpp.html#a6">COLOR_RED</a>;00065 00066 <span class="comment">//##ModelId=3F6EB00003E2</span><a name="l00067"></a><a class="code" href="classFG__X11Adaptor.html#a0">00067</a> <span class="keywordtype">bool</span> <a class="code" href="classFG__X11Adaptor.html#a0">FG_X11Adaptor::InitInstance</a>()00068 {00069 <a class="code" href="classFG__X11Adaptor.html#r0">display</a> = XOpenDisplay(<a class="code" href="group__Utility.html#ga11">NULL</a>);00070 <span class="keywordflow">if</span> (<a class="code" href="classFG__X11Adaptor.html#r0">display</a> == <a class="code" href="group__Utility.html#ga11">NULL</a>)00071 {00072 printf(<span class="stringliteral">"Failed to open display\n"</span>);00073 <span class="keywordflow">return</span> 0;00074 }00075 00076 <a class="code" href="classFG__X11Adaptor.html#r1">screen</a> = DefaultScreen(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>);00077 Window rootwin = RootWindow(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r1">screen</a>);00078 <a class="code" href="classFG__X11Adaptor.html#r2">win</a> = XCreateSimpleWindow(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, rootwin, 10, 10, <a class="code" href="group__Utility.html#ga3">SCREEN_WIDTH</a>, <a class="code" href="group__Utility.html#ga4">SCREEN_HEIGHT</a>, 5,00079 BlackPixel(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r1">screen</a>), BlackPixel(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r1">screen</a>));00080 00081 <span class="keyword">static</span> XSizeHints size_hints;00082 size_hints.flags = PSize | PMinSize | PMaxSize;00083 size_hints.min_width = <a class="code" href="group__Utility.html#ga3">SCREEN_WIDTH</a>;00084 size_hints.max_width = <a class="code" href="group__Utility.html#ga3">SCREEN_WIDTH</a>;00085 size_hints.min_height = <a class="code" href="group__Utility.html#ga4">SCREEN_HEIGHT</a>;00086 size_hints.max_height = <a class="code" href="group__Utility.html#ga4">SCREEN_HEIGHT</a>;00087 00088 <span class="keywordtype">char</span> szAppName[] = <span class="stringliteral">"FishGUI Win32 Simulator"</span>;00089 <span class="keywordtype">char</span> * icon_name = <span class="stringliteral">"window"</span>;00090 XSetStandardProperties(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r2">win</a>, szAppName, icon_name, None, 0, 0, & size_hints); 00091 00092 XSelectInput(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r2">win</a>, ExposureMask | ButtonPressMask | KeyPressMask | ButtonReleaseMask | KeyReleaseMask);00093 XMapWindow(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r2">win</a>);00094 00095 m_pDraw = <span class="keyword">new</span> <a class="code" href="classFG__X11DrawInterface.html">FG_X11DrawInterface</a>(<a class="code" href="classFG__X11Adaptor.html#r2">win</a>, <a class="code" href="classFG__X11Adaptor.html#r0">display</a>, <a class="code" href="classFG__X11Adaptor.html#r1">screen</a>);00096 00097 <a class="code" href="structFG__Message.html">FG_Message</a> Msg(<a class="code" href="group__Utility.html#gga12a17">FG_MSG_STARTUP</a>);00098 <a class="code" href="classFG__OSAdaptor.html#a2">SendMsg</a>(& Msg);00099 00100 <span class="keywordflow">return</span> <span class="keyword">true</span>;00101 }00102 00103 <span class="comment">//##ModelId=3F6EB00003E3</span><a name="l00104"></a><a class="code" href="classFG__X11Adaptor.html#a1">00104</a> <span class="keywordtype">bool</span> <a class="code" href="classFG__X11Adaptor.html#a1">FG_X11Adaptor::ExitInstance</a>()00105 {00106 <span class="keyword">delete</span> m_pDraw;00107 XCloseDisplay(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>);00108 <span class="keywordflow">return</span> <span class="keyword">true</span>;00109 }00110 00111 <span class="comment">//##ModelId=3F6EB00003E4</span><a name="l00112"></a><a class="code" href="classFG__X11Adaptor.html#a2">00112</a> <span class="keywordtype">bool</span> <a class="code" href="classFG__X11Adaptor.html#a2">FG_X11Adaptor::Execute</a>()00113 {00114 XEvent xev;00115 <span class="keywordtype">int</span> i, num_events;00116 timeval last_tv = {0, 0};00117 timeval tv;00118 00119 <span class="keywordflow">while</span> (1)00120 {00121 gettimeofday(& tv, <a class="code" href="group__Utility.html#ga11">NULL</a>);00122 <span class="keywordflow">if</span> (tv.tv_sec > last_tv.tv_sec || tv.tv_usec - last_tv.tv_usec > 50000)00123 {00124 <a class="code" href="structFG__Message.html">FG_Message</a> Msg(<a class="code" href="group__Utility.html#gga12a22">FG_MSG_TIMER</a>);00125 <a class="code" href="group__OSAdaptor.html#ga1">FG_GetAdaptor</a>()-><a class="code" href="classFG__OSAdaptor.html#a2">SendMsg</a>(& Msg);00126 last_tv = tv;00127 }00128 XFlush(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>);00129 num_events = XPending(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>);00130 <span class="keywordflow">while</span>((num_events != 0))00131 {00132 num_events--;00133 XNextEvent(<a class="code" href="classFG__X11Adaptor.html#r0">display</a>, &xev);00134 <a class="code" href="classFG__X11Adaptor.html#d0">process_event</a>(xev);00135 }00136 }00137 <span class="keywordflow">return</span> <span class="keyword">true</span>;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -