⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wm.c

📁 uCGUI
💻 C
📖 第 1 页 / 共 4 页
字号:
      break;
    }
    hiWin = hNext;
  }
}


/*************************************************************************************************************
*
*/
void _AddToLinList(WM_HWIN hNew) {
  WM_Obj* pFirst;
  WM_Obj* pNew;
  if (WM__FirstWin) {
    pFirst = WM_H2P(WM__FirstWin);
    pNew   = WM_H2P(hNew);
    pNew->hNextLin = pFirst->hNextLin;
    pFirst->hNextLin = hNew;
  } else {
    WM__FirstWin = hNew;
  }
}


/*********************************************************************
   Check if the rectangle has some content (is non-zero)
   Returns 0 if the Rectangle has no content, else 1.
*/
int WM__RectIsNZ(const GUI_RECT* pr) {
  if (pr->x0 > pr->x1)
    return 0;
  if (pr->y0 > pr->y1)
    return 0;
  return 1;
}


/*
  ********************************************************************
  *                                                                  *
  *                    Sending messages                              *
  *                                                                  *
  ********************************************************************
*/


void WM_SendMessage(WM_HWIN hWin, WM_MESSAGE* pMsg) {
  WM_Obj* pWin;
  WM_LOCK();
  if (hWin) {
    pWin = WM_H2P(hWin);
  /* Do some checking to avoid program crashes due to user
     programming errors */
    #if GUI_DEBUG_LEVEL > 0
      if (!pWin->Status)
        goto Done;
    #endif
    if (pWin->cb != NULL) {
      pMsg->hWin = hWin;
      IsInCallback = 1;
      (*pWin->cb)(pMsg);
      IsInCallback = 0;
    }
  }
  #if GUI_DEBUG_LEVEL > 0
Done:
  #endif
  WM_UNLOCK();
}

/*************************************************************************************************************
*
*/
void WM__SendMsgNoData(WM_HWIN hWin, U8 MsgId) {
  WM_MESSAGE Msg;
  Msg.hWin  = hWin;
  Msg.MsgId = MsgId;
  WM_SendMessage(hWin, &Msg);
}



/* Get client rectangle in windows coordinates. This means that the
  upper left corner is always at (0,0). */
void WM__GetClientRectWin(WM_Obj* pWin, GUI_RECT* pRect) {
  pRect->x0 = pRect->y0 = 0;
  pRect->x1 = pWin->Rect.x1 - pWin->Rect.x0;
  pRect->y1 = pWin->Rect.y1 - pWin->Rect.y0;
}


static void WM__GetInvalidRectAbs(WM_Obj* pWin, GUI_RECT* pRect) {
  *pRect = pWin->InvalidRect;
  GUI_MoveRect (pRect, pWin->Rect.x0, pWin->Rect.y0);
}


/*
          *****************************************************************
          *                                                               *
          *              Invalidation functions                           *
          *                                                               *
          *****************************************************************
*/

/* Invalidate, using window coordinates */
static void WM_InvalidateBWin1(WM_HWIN hWin, const GUI_RECT*pRect) {
  GUI_RECT r;
  WM_Obj* pWin = WM_H2P(hWin);
  WM__GetClientRectWin(pWin, &r);
  if (pRect)
    GUI__IntersectRect(&r, pRect);
  if (WM__RectIsNZ(&r)) {
    if (pWin->Status & WM_SF_INVALID) {
      GUI_MergeRect(&pWin->InvalidRect, &pWin->InvalidRect, &r);
    } else {
      pWin->InvalidRect = r;
      pWin->Status |= WM_SF_INVALID;
      WM__NumInvalidWindows++;
      /* Debug code: shows invalid areas */
      #if (WM_SHOW_INVALID)
      {
        GUI_CONTEXT Context = GUI_Context;
        WM_SelectWindow(hWin);
        GUI_SetBkColor(GUI_GREEN);
        GUI_ClearRect(r.x0, r.y0, r.x1, r.y1);
        GUI_Context = Context;
      }
      #endif


    }
  }
}

/* Invalidate, using desktop coordinates (only this window,
   not the ones below !!!)
*/
static void WM_InvalidateBWin1Abs(WM_HWIN hWin, const GUI_RECT*pRect) {
  GUI_RECT r = *pRect;
  WM_LOCK();
  GUI_MoveRect(&r, -WM_H2P(hWin)->Rect.x0, -WM_H2P(hWin)->Rect.y0);
  WM_InvalidateBWin1(hWin, &r);
  WM_UNLOCK();
}



/*
  Invalidate a certain section of the display. One main reason for this is
  that a window has been moved or destroyed.
  The following windows are affected:
  * windows below the window creating the invalidation.
  * transparent windows located above
  The coordinates given are absolute coordinates (desktop coordinates)
*/
void WM__InvalidateAreaBelow(const GUI_RECT* pRect, WM_HWIN StopWin) {
  WM_HWIN   iWin, iNext;
  /* Iterate over windows below StopWin */
  for (iWin = WM__FirstWin; iWin!=StopWin; iWin = iNext) {
    GUI_RECT r = *pRect;
    WM_Obj* pWin = WM_H2P(iWin);
    iNext = pWin->hNextLin;
    if (GUI__IntersectRects(&r, &r, &pWin->Rect)) {
      WM_InvalidateBWin1Abs (iWin, &r);
    }
  };
}

/*
  Invalidate any transparent window above the given area
*/
void WM__InvalidateTransAreaAbove(const GUI_RECT* pRect, WM_HWIN StopWin) {
  GUI_USE_PARA(pRect);
  GUI_USE_PARA(StopWin);
#if 0
  WM_HWIN   iWin;
  /* Iterate over windows below StopWin */
  for (iWin = StopWin; iWin!=WM_HWIN_NULL; iWin = WM_H2P(iWin)->Next) {
    WM_Obj *pWin = WM_H2P(iWin);
    if (pWin->Status & WM_SF_HASTRANS) {
      GUI_RECT r = *pRect;
      if (GUI__IntersectRects(&r, &r, &WM_H2P(iWin)->Rect)) {
        WM_InvalidateBWin1Abs (iWin, &r);
      }
    }
  }
#endif
}


/*
          *****************************************************************
          *                                                               *
          *              Invalidation functions                           *
          *                                                               *
          *****************************************************************
*/

/* Invalidate a section of the window. The optional rectangle
   contains client coordinates, which are independent of the
   position of the window on the logical desktop area.
*/


void WM_InvalidateRect(WM_HWIN hWin, const GUI_RECT*pRect) {
  GUI_RECT r;
  WM_Obj* pWin;
  WM_LOCK();
  pWin = WM_H2P(hWin);
  WM__GetClientRectWin(pWin, &r);
  if (pRect) {
    GUI__IntersectRect(&r, pRect);
  }
  WM_InvalidateBWin1(hWin, &r);
/* Convert into absolute coordinates ... */
  GUI_MoveRect (&r, pWin->Rect.x0, pWin->Rect.y0);
/* Make sure windows below are invalidated if this one is transparent */
  if (pWin->Status & WM_SF_HASTRANS) {
    ResetNextDrawWin();
    WM__InvalidateAreaBelow(&r, hWin);
  }
/* Invalidate the transparent ones above */
  WM__InvalidateTransAreaAbove(&r,hWin);
  WM_UNLOCK();
}

void WM_InvalidateWindow(WM_HWIN hWin) {
  WM_InvalidateRect(hWin, NULL);
}

/* Invalidate, using desktop coordinates */
void WM_InvalidateBWinAbs(WM_HWIN hWin, const GUI_RECT*pRect) {
  GUI_RECT r = *pRect;
  WM_LOCK();
  GUI_MoveRect(&r, -WM_H2P(hWin)->Rect.x0, -WM_H2P(hWin)->Rect.y0);
  WM_InvalidateRect(hWin, &r);
  WM_UNLOCK();
}


/*
  Invalidate a certain section of the display. One main reason for this is
  that the top window has been moved or destroyed.
  The coordinates given are absolute coordinates (desktop coordinates)
*/
void WM_InvalidateArea(GUI_RECT* pRect) {
  WM_HWIN   iWin;
  WM_LOCK();
  /* Iterate over all windows */
  for (iWin=WM__FirstWin; iWin !=0; ) {
    WM_Obj* pWin = WM_H2P(iWin);
    GUI_RECT r = *pRect;
    GUI__IntersectRect(&r, &pWin->Rect);
    /* Calculate which area is actually visible by subtracting the
       windows which are on top of this one */
    WM_InvalidateBWinAbs (iWin, &r);
    iWin = pWin->hNextLin;
  }
  WM_UNLOCK();
}


/*
  ********************************************************************
  *                                                                  *
  *              manage windows stack                                *
  *                                                                  *
  ********************************************************************
*/


/* Return index (handle) of the window which is bottom of stack.
   Note that in the current implementation, this is always
   window 0.
*/
WM_HWIN WM_GetDesktopWindow(void) {
  return WM__FirstWin;
}

/*
  ********************************************************************
  *
  *              Create window (as child)
  *
  ********************************************************************
*/

WM_HWIN WM_CreateWindowAsChild(
                    int x0, int y0, int width, int height
                   ,WM_HWIN hWinParent
                   ,U16 Style
                   ,WM_CALLBACK* cb
                   ,int NumExtraBytes)
{
  WM_Obj* pWin;
  WM_HWIN hWin;
  WM_LOCK();
  Style |= WM__CreateFlags;
  /* Get Parent info */
  if (!hWinParent) {
    if (WM__NumWindows) {
      hWinParent = WM_HBKWIN;
    }
  }
  if (hWinParent) {
    GUI_RECT Rect;
    WM_MESSAGE Msg;
    Msg.MsgId = WM_GETCLIENTRECT_ABS;
    Msg.Data.p = &Rect;
    WM_SendMessage(hWinParent, &Msg);
    x0 += Rect.x0;
    y0 += Rect.y0;
    if (width==0)
      width = Rect.x1-Rect.x0+1;
    if (height==0)
      height = Rect.y1-Rect.y0+1;
  }
  if ((hWin = (WM_HWIN) WM_ALLOC(NumExtraBytes+sizeof(WM_Obj))) == 0) {
    GUI_DEBUG_ERROROUT("WM_CreateWindow: No memory to create window");
  } else {
    WM__NumWindows++;
    pWin = WM_H2P(hWin);
    memset (pWin,   0, sizeof(WM_Obj));        /* erase this data structure
           The explicit zero-init is no longer needed since the entire data structure
           is already zeroed. The advantage is that it reduces program size.
           */
    pWin->Rect.x0 = x0;
    pWin->Rect.y0 = y0;
    pWin->Rect.x1 = x0+width-1;
    pWin->Rect.y1 = y0+height-1;
    pWin->Status = WM_SF_INUSE;     /* Mark window as in use */
    pWin->cb = cb;
    /* Add to linked lists */
    pWin->hParent = hWinParent;
    _AddChild(hWinParent, hWin, Style & WM_CF_STAYONTOP);
    _AddToLinList(hWin);
  /* Put Window on top (or bottom) of windows stack */
    if (Style & WM_CF_ACTIVATE /*| (cb==NULL)*/) {
      WM_SelectWindow(hWin);  /* This is not needed

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -