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

📄 framewin.c

📁 一个用于单片机上的的gui...,里面有实例和pc模拟器
💻 C
📖 第 1 页 / 共 2 页
字号:
  switch (pMsg->MsgId) {
    case WM_PAINT:
      GUI_SetBkColor(pObj->ClientColor);
      GUI_Clear();
      if (pObj->cb) {
	      WM_MESSAGE msg;
        msg.hWin   = hWin;
		    msg.MsgId  = WM_PAINT;
        (*pObj->cb)(&msg);
      }
      return;
    case WM_GET_FOCUSSED_CHILD:
      pMsg->Data.v = pObj->hFocussedChild;
      return;
    case WM_SET_FOCUS:
      if (pMsg->Data.v) {      /* Focus received */
        if (pObj->hFocussedChild) {
          WM_SendMessage(pObj->hFocussedChild, pMsg);
        } else {
          pObj->hFocussedChild = WM_SetFocusOnNextChild(hWin);
        }
      }
      return;
    case WM_KEY:
      if ( ((WM_KEY_INFO*)(pMsg->Data.p))->PressedCnt >0) {
        int Key = ((WM_KEY_INFO*)(pMsg->Data.p))->Key;
        switch (Key) {
          case GUI_KEY_TAB:
            pObj->hFocussedChild = WM_SetFocusOnNextChild(hWin);
            break;                    /* Send to parent by not doing anything */
        }
      }
      break;
    case WM_NOTIFY_CHILD_HAS_FOCUS:
      pObj->hFocussedChild = pMsg->hWinSrc;
      if (pMsg->Data.v) {
        pObj->Widget.State |= WIDGET_STATE_CHILD_HAS_FOCUS;
      } else {
        pObj->Widget.State &= ~WIDGET_STATE_CHILD_HAS_FOCUS;
      }
      WM_InvalidateWindow(hParent);
      break;
    case WM_GET_BKCOLOR:
      pMsg->Data.Color = pObj->ClientColor;
      return;                       /* Message handled */
    case WM_GETCLIENTRECT_ABS:      /* return client window in absolute (screen) coordinates */
    case WM_GET_CLIENT_WINDOW:      /* return handle to client window. For most windows, there is no seperate client window, so it is the same handle */
      WM_DefaultProc(pMsg);
      return;                       /* We are done ! */
  }
  if (cb) {
    pMsg->hWin = hParent;
    (*cb)(pMsg);
  }
}

/*********************************************************************
*
*        Exported routines:  Create
*
**********************************************************************
*/

FRAMEWIN_Handle FRAMEWIN_CreateAsChild( 
                                    int x0, int y0, int xsize, int ysize, WM_HWIN hParent,
                                    const char* pText, WM_CALLBACK* cb, int Flags)
{
  FRAMEWIN_Handle hObj;
  /* Create the window */
  GUI_LOCK();
  hObj = WM_CreateWindowAsChild(x0, y0, xsize/*+2*HBorder*/, ysize/*+TBorder+BBorder*/, hParent,
                        Flags, _FRAMEWIN_Callback, sizeof(FRAMEWIN_Obj) - sizeof(WM_Obj));
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED);
    /* init member variables */
    pObj->pFont = _pDefaultFont;
    memcpy(pObj->BarColor, _aBarColor, sizeof(pObj->BarColor));
    pObj->TextColor    = 0xffffff;
    pObj->TextAlign    = GUI_TA_LEFT;
    pObj->ClientColor  = _DefaultClientColor;
    pObj->pText        = pText;
    pObj->XOff = 1;
    pObj->YOff = 1;
    pObj->cb = cb;
    CalcPositions(hObj);
    pObj->hClient = WM_CreateWindowAsChild(0, 0, 0, 0, hObj, WM_CF_SHOW, FRAMEWIN__cbClient, 0);
  }
  GUI_UNLOCK();
  return hObj;
}

FRAMEWIN_Handle FRAMEWIN_Create( const char* pText,
                                    WM_CALLBACK* cb,
                                    int Flags,
                                    int x0, int y0, int xsize, int ysize) {

  return FRAMEWIN_CreateAsChild(x0, y0, xsize, ysize, WM_HWIN_NULL, pText, cb, Flags);
}


FRAMEWIN_Handle FRAMEWIN_CreateIndirect(const GUI_WIDGET_CREATE_INFO* pCreateInfo, WM_HWIN hWinParent, int x0, int y0, WM_CALLBACK* pCallback) {
  FRAMEWIN_Handle hObj;
  hObj = FRAMEWIN_CreateAsChild(
    pCreateInfo->x0 + x0, pCreateInfo->y0 + y0, pCreateInfo->xSize, pCreateInfo->ySize, hWinParent,
    pCreateInfo->pName, pCallback, 0);
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->Flags = pCreateInfo->Flags;
  }
  return hObj;
}

/*********************************************************************
*
*        Exported routines:  Various methods
*
**********************************************************************
*/
void FRAMEWIN_SetFont(FRAMEWIN_Handle hObj, const GUI_FONT* pFont) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->pFont = pFont;
    CalcPositions(hObj);
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetBarColor(FRAMEWIN_Handle hObj, int index, GUI_COLOR color) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->BarColor[index] = color;
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetTextColor(FRAMEWIN_Handle hObj, GUI_COLOR color) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->TextColor = color;
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetText(FRAMEWIN_Handle hObj, const char* s) {
  char NeedsInvalidate;
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    NeedsInvalidate = 1;
    if (s && pObj->pText) {
      if (strcmp(s, pObj->pText) == 0) {
        NeedsInvalidate = 0;
      }
    }
    pObj->pText = s;
    if (NeedsInvalidate) {
      FRAMEWIN_Invalidate(hObj);
    }
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetTextAlign(FRAMEWIN_Handle hObj, int Align) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->TextAlign = Align;
    switch (Align) {
    case GUI_TA_HCENTER:
      pObj->XOff = (pObj->rClient.x1 - pObj->rClient.x0) / 2;
      break;
    case GUI_TA_LEFT:
      pObj->XOff = pObj->FrameSize;
      break;
    case GUI_TA_RIGHT:
      pObj->XOff = pObj->rClient.x1 - pObj->FrameSize;
      break;
    }
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetTextPos(FRAMEWIN_Handle hObj, int XOff, int YOff) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->XOff = XOff;
    pObj->YOff = YOff;
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetActive(FRAMEWIN_Handle hObj, int State) {
  GUI_LOCK();
  if (hObj) {
    if (State) {
      FRAMEWIN_SetBarColor(hObj, 0, FRAMEWIN_BARCOLOR_ACTIVE_DEFAULT);
    } else {
      FRAMEWIN_SetBarColor(hObj, 0, FRAMEWIN_BARCOLOR_INACTIVE_DEFAULT);
    }
  }
  GUI_UNLOCK();
}

void FRAMEWIN_SetClientColor(FRAMEWIN_Handle hObj, GUI_COLOR Color) {
  GUI_LOCK();
  if (hObj) {
    FRAMEWIN_Obj* pObj = FRAMEWIN_H2P(hObj);
    pObj->ClientColor = Color;
    FRAMEWIN_Invalidate(hObj);
  }
  GUI_UNLOCK();
}

  /***************************************************************
  *
  *                Set/Get defaults
  *
  ***************************************************************/

void FRAMEWIN_SetDefaultFont(const GUI_FONT* pFont) {
  _pDefaultFont = pFont;
}

const GUI_FONT* FRAMEWIN_GetDefaultFont(void) {
  return _pDefaultFont;
}

void FRAMEWIN_SetDefaultBarColor(int Index, GUI_COLOR Color) {
  if ((Index >= 0) && (Index <= 1)) {
    _aBarColor[Index] = Color;
  }
}

GUI_COLOR FRAMEWIN_GetDefaultBarColor(int Index) {
  GUI_COLOR r = 0;
  if ((Index >= 0) && (Index <= 1)) {
    r = _aBarColor[Index];
  }
  return r;
}

void FRAMEWIN_SetDefaultClientColor(GUI_COLOR Color) {
  _DefaultClientColor = Color;
}

GUI_COLOR FRAMEWIN_GetDefaultClientColor(void) {
  return _DefaultClientColor;
}

int FRAMEWIN_GetDefaultCaptionSize(void) {
  return _DefaultCaptionSize;
}

void FRAMEWIN_SetDefaultCaptionSize(int DefaultCaptionSize) {
  _DefaultCaptionSize = DefaultCaptionSize;
}

int FRAMEWIN_GetDefaultBorderSize(void) {
  return _DefaultBorderSize;
}

void FRAMEWIN_SetDefaultBorderSize(int DefaultBorderSize) {
  _DefaultBorderSize = DefaultBorderSize;
}

#else
  void WIDGET_FrameWin(void) {} /* avoid empty object files */
#endif /* GUI_WINSUPPORT */

⌨️ 快捷键说明

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