Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1032206
  • 博文数量: 166
  • 博客积分: 10217
  • 博客等级: 上将
  • 技术积分: 2133
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 19:45
文章分类

全部博文(166)

文章存档

2012年(3)

2011年(7)

2010年(18)

2009年(59)

2008年(79)

我的朋友

分类: LINUX

2008-11-13 15:08:15

在看本文之前,最好先看一下xlib编程,因为fltk只不过是在xlib的基础上封了一层。下面的链接文一个简单介绍http://blog.chinaunix.net/u2/66024/showart.php?id=1333705

调xlib里的画图从window->show开始
在src/window.cxx里的
void Window::show()
        ---> open_display(); //此函数在src/x11/run.cxx里void fltk::open_display()
                 --->Display *d = XOpenDisplay(0);
                 --->open_display(d);
                         --->XCreateSimpleWindow(d, RootWindow(d, xscreen), 0,0,1,1,0, 0, 0);
        --->create();  //在src/x11/run.cxx里
               --->CreatedWindow::create(this, xvisual, xcolormap, -1);//在src/x11/run.cxx里
真正的图形实现在src/run.cxx,事件循环也在这里
int fltk::run() {
  while (Window::first()) wait(FOREVER);
  return(0);
}
而  
void Window::first(Window* window) {
  if (!window || !window->shown()) return;
  fltk::find(xid(window));
}
接下来主要是src/run.cxx里的
int fltk::wait(float time_to_wait)
      --->
      --->static inline int fl_wait(float time_to_wait)
                 --->do_queued_events(0,0);
                         --->XNextEvent(xdisplay, &xevent);
                 handle();//这里的handle()在 /src/x11/run.cxx里
                                 --->return handle(event, window);//这里的handle(event, window)在/src/run.cxx里,窗口的按键,鼠标事件就在这里处理了
                 ---> n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); //fd句柄的监听,用fltk::add_fd函数添加,类似的有fltk::add_check ,fltk::add_idle
                          if (fd[i].events & revents) fd[i].cb(f, fd[i].arg); //执行fd对应的回调函数


      --->while ((t = first_timeout)) { //以下为处理fltk里的定时器部分,用fltk::add_timeout添加定时器
          if (t->time > 0) break;
          // We must remove timeout from array before doing the callback
          void (*cb)(void*) = t->cb;
          void *arg = t->arg;
          first_timeout = t->next;
          t->next = free_timeout;
          free_timeout = t;
          // Now it is safe for the callback to do add_timeout:
          missed_timeout_by = t->time; // make repeat_timeout more accurate
          cb(arg);        //执行定时器的回调函数
          // return true because something was done:
          ret = 1;
          }
     --->flush(); //其定义在在src/x11/run.cxx
            --->XMapWindow(xdisplay, i->frontbuffer);//这里是真正的显示图形的地方




阅读(3816) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~