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

📄 widget_customeffect.c

📁 ucgu最新版本 4.14
💻 C
📖 第 1 页 / 共 4 页
字号:
*       _DrawDown
*
* Function description
*   Gets the rectangle of the current window and uses _DrawDownRect()
*   for drawing the effect.
*/
static void _DrawDown(void) {
  GUI_RECT r;
  WM_GetClientRect(&r);
  _DrawDownRect(&r);
}

/*********************************************************************
*
*       _DrawFlat
*
* Function description
*   Gets the rectangle of the current window and uses _DrawFlatRect()
*   for drawing the effect.
*/
static void _DrawFlat(void) {
  GUI_RECT r;
  WM_GetClientRect(&r);
  _DrawFlatRect(&r);
}
/*********************************************************************
*
*       _aEffects
*
* Purpose:
*   Array of structures of type WIDGET_EFFECT which contains the function pointers
*   used by emWin to draw the effect. It also contains the effect size
*   which specifies the number of pixels used by the effect frame.
*/
static WIDGET_EFFECT _Effect = {
  2,
  _DrawUp,
  _DrawUpRect,
  _DrawDown,
  _DrawDownRect,
  _DrawFlat,
  _DrawFlatRect
};

/*********************************************************************
*
*       _DrawGradientV
*
* Purpose:
*   Draws the vertical gradient ussed by the background
*/
static void _DrawGradientV(int x0, int y0, int x1, int y1, GUI_COLOR Color0, GUI_COLOR Color1) {
  int r0, g0, b0, r1, g1, b1;
  int y, ySize;
  ySize = y1 - y0 + 1;
  r0 = (Color0 >>  0) & 0x000000ff;
  g0 = (Color0 >>  8) & 0x000000ff;
  b0 = (Color0 >> 16) & 0x000000ff;
  r1 = (Color1 >>  0) & 0x000000ff;
  g1 = (Color1 >>  8) & 0x000000ff;
  b1 = (Color1 >> 16) & 0x000000ff;
  for (y = y0; y <= y1; y++) {
    GUI_COLOR Color;
    int r, g, b, yd;
    yd = (y - y0);
    r = r0 + ((r1 - r0) * yd) / ySize;
    g = g0 + ((g1 - g0) * yd) / ySize;
    b = b0 + ((b1 - b0) * yd) / ySize;
    Color = r | (g << 8) | (b << 16);
    GUI_SetColor(Color);
    GUI_DrawHLine(y, x0, x1);
  }
}

/*********************************************************************
*
*       _cbWin
*
* Purpose:
*   Callback function of desktop window
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
    _DrawGradientV(0, 0, 319, 239, 0xff0000, 0xffffff);
    GUI_SetFont(&GUI_Font16B_ASCII);
    GUI_SetTextMode(GUI_TM_TRANS);
    GUI_DispStringHCenterAt("Custom effect frames with standard widgets", 160, 20);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  WM_HWIN hButton, hEdit;
  GUI_Init();
  WM_SetCallback(WM_HBKWIN, _cbWin);
  _InitColors(0x002840, 0x00A5FF, _aColor, 3);
  /* 
   * Set custom effect as default effect
   */
  WIDGET_SetDefaultEffect(&_Effect);
  /* 
   * Create widgets
   */
  hButton = BUTTON_CreateEx  (105,  60, 110, 110, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, 0);
  hEdit   = EDIT_CreateEx    (105, 190, 110,  26, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, 0, 20);
  BUTTON_SetBitmapEx(hButton, 0, &_bmDolphin, 5, 22);
  BUTTON_SetBitmapEx(hButton, 1, &_bmDolphin, 6, 23);
  EDIT_SetText(hEdit, "Please edit me...");
  /* 
   * Loop
   */
  while (1) {
    GUI_Delay(100);
  }
}

⌨️ 快捷键说明

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