uCGUI3.98 触摸消息响应过程分析

3530阅读 0评论2013-04-17 qiushui_007
分类:C/C++

一. 循环调用 GUI_TOUCH_Exec --> GUI_TOUCH_StoreUnstable(x, y)
--> 注意此定义了静态变量GUI_PID_STATE _State
void GUI_TOUCH_StoreState(int x, int y) {
  static GUI_PID_STATE _State;  /* static so we retain coordinates when touch is released */
  if ((x >= 0) && (y >= 0)) {
    _State.Pressed = 1;
    _State.x = x;
    _State.y = y;
  } else {
    _State.Pressed = 0;
  }
  GUI_TOUCH_StoreStateEx(&_State);
}

-->
void GUI_TOUCH_StoreStateEx(const GUI_PID_STATE *pState) {
  if (memcmp(pState, &_State, sizeof(_State))) {
    _State = *pState;
    GUI_PID_StoreState(pState);
  }
}

-->首先定义了函数指针所指向的函数
void GUI_PID_StoreState(const GUI_PID_STATE *pState) {
  _PID_Load();
  if (memcmp(&_State, pState, sizeof(_State))) {
    _State = *pState;
    GUI_X_SIGNAL_EVENT(); //由以下定义,一般为空
  }
}
#ifndef GUI_X_SIGNAL_EVENT
  #define GUI_X_SIGNAL_EVENT()
#endif

-->此定义了函数指针所指向的函数
typedef int  WM_tfHandlePID(void);
WM_tfHandlePID*    WM_pfHandlePID;

static void _PID_Load(void) {
  #if (GUI_WINSUPPORT)
  WM_pfHandlePID = WM_HandlePID;
  #endif
}
--- 总结: GUI_TOUCH_Exec的作用是获取Touch的相关的位置和状态并利用函数指针定义了要执行的函数.
那么函数运行在那里调用呢?

循环调用GUI_Exec()以运行回调函数(所有的工作),
该函数会自动地重复地调用 GUI_Exec1()直到它完成全部工作——本质上是直到返回一个 0值。
通常该函数不需要被用户应用程序所调用, 它自动地被 GUI_Delay() 所调用
-->
void GUI_Delay(int Period) {
  int EndTime = GUI_GetTime()+Period;
  int tRem; /* remaining Time */
  GUI_ASSERT_NO_LOCK();
  while (tRem = EndTime- GUI_GetTime(), tRem>0) {
    GUI_Exec();
    GUI_X_Delay((tRem >5) ? 5 : tRem);
  }
}

--> 调用顺序: GUI_Exec --> GUI_Exec1 --> WM_Exec --> WM_Exec1

//--- gui_exec.c
int GUI_Exec(void) {
  int r = 0;
  while (GUI_Exec1()) {
    r = 1;                  /* We have done something */
  }
  return r;
}

int GUI_Exec1(void) {
  int r = 0;
  /* Execute background jobs */
  if (GUI_pfTimerExec) {
    if ((*GUI_pfTimerExec)()) {
      r = 1;                  /* We have done something */
    }
  }
  #if GUI_WINSUPPORT    /* If 0, WM will not generate any code */
  if (WM_Exec())
    r = 1;
  #endif
  return r;
}

//--- WM.c
int WM_Exec(void) {
  int r = 0;
  while (WM_Exec1()) {
    r = 1;                  /* We have done something */
  }
  return r;
}

int WM_Exec1(void) {
  /* Poll PID if necessary */
  if (WM_pfPollPID) {
    WM_pfPollPID();
  }
  //若指针有效则运行函数WM_pfHandlePID(), 由上面定义可知执行的是 WM_HandlePID 函数. !!!!
  if (WM_pfHandlePID) {
    //if (WM_pfHandlePID()) //原代码
    if ((*WM_pfHandlePID)()) //个人习惯, 测试OK
      return 1;               /* We have done something ... */
  }
  if (WM_IsActive) {
    if (GUI_PollKeyMsg()) {
      return 1;               /* We have done something ... */
    }
  }
  if (WM_IsActive && WM__NumInvalidWindows) {
    WM_LOCK();
    _DrawNext();
    WM_UNLOCK();
    return 1;               /* We have done something ... */
  }
  return 0;                  /* There was nothing to do ... */
}
剩下的就是核心函数 WM_HandlePID, 这个你们都懂得......




上一篇:FreeRTOS 应用集锦
下一篇:LM3S系列集锦