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

📄 ctrls.cpp

📁 一个嵌入式系统的C代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////// Same as above, but using a point as the event trigger..// RETURNS: ZERO if code unknown, or ID of radio button set.//UINT16 RbCtrl::Scan (point& Pt){  if (BtnHit(Pt)) {    btn *p = (btn*)DblGetHead();    while (p) {      if (p->status & 0x01) {	if (p != pb) {	  Toggle(p);	  break;	}      }      p = (btn*)DblGetNext();    }    if ((pb->status & 0x01) == 0)      Toggle(pb);    return pb->Id;  }  return 0;}///////////////// Repaint all defined radio buttons//void RbCtrl::Refresh (void){  btn *pb;  pb = (btn*)DblGetHead();  while (pb) {    Render(pb);    pb = (btn*)DblGetNext();  }}  //////////////////////////////////////////////////////////////////////////// Draw and optionally label a Check Box.//void CbCtrl::Render (btn *p){  INT16 x, y;  x = p->r.ul.x;  y = p->r.ul.y + ((p->r.lr.y - p->r.ul.y - CB_Height) >> 1);  GfxTextColor(_DarkGrey);  GfxMoveTo(x+CB_Width, y), GfxLineTo(x, y), GfxLineTo(x, y+CB_Height);  GfxTextColor(_BrightWhite);  GfxLineTo(x+CB_Width, y+CB_Height), GfxLineTo(x+CB_Width, y+1);  p->status ^= 0x01;  Toggle(p);  if (p->pst) {    rect rr = p->r;    rr.ul.x += CB_Width + GfxTextExtent(" ");    CtrlTxtLab(p->pst->StrGet(), rr, CTLS_LJustify);  }}/////////////// Toggle Check Box status and redraw its graphic state accordingly.//void CbCtrl::Toggle (btn *p){  INT16 x, y;  x = p->r.ul.x + 1;  y = p->r.ul.y + ((p->r.lr.y - p->r.ul.y - CB_Height) >> 1) + 1;  Mickey.AutoPointer(x, y, x+CB_Height, y+CB_Width);  GfxRect(x, y, x+CB_Width-2, y+CB_Height-2, GFX_Fill, _White);  p->status = (p->status & 0xfffe) | ((p->status & 0x01) ^ 0x01);  if (p->status & 0x01) {    GfxTextColor(_Black);    GfxMoveTo(x, y), GfxLineTo(x+CB_Width-2, y+CB_Height-2);    GfxMoveTo(x+CB_Width-2, y), GfxLineTo(x, y+CB_Height-2);  }  Mickey.ShowPointer();}/////////////// Create a new Check Box as defined by the passed params and draw it.// The coords define the centre of the actual Box.  A "Hot" area is// developed from this to include the control's label.// RETURNS: TRUE  .. button added to list//          FALSE .. unable to create button//BOOL CbCtrl::Create (UINT16 n, char *st, INT16 x, INT16 y, BOOL bSet){  btn *cb;  BOOL bOk;  rect r;  r.ul.x = MAX(0, x - (CB_Width >> 1));  r.ul.y = MAX(0, y - (MAX(CB_Height, GfxTextHeight()) >> 1));  r.lr.y = y + (MAX(CB_Height, GfxTextHeight()) >> 1);  r.lr.x = x + CB_Width + GfxTextExtent(" ") + GfxTextExtent(st);  if (strchr(st, '&'))    r.lr.x -= GfxTextExtent("&");  if (bOk = BtnNew(n, st, r)) {    cb = (btn*)DblGetTail();    if (bSet)      cb->status |= 0x01;    Render(cb);  }  return bOk;}///////////////// Remove button with passed ID from the list (if it exists)// RETURNS: TRUE  .. button destroyed//	    FALSE .. did not exist!//BOOL CbCtrl::Destroy (UINT16 n){  BOOL bRes = BtnFind(n);  if (bRes)    BtnKill(n);  return bRes;}//////////////////////// Wander through the list to see if any Box corresponds to the// passed ALT-key scan code.  If so, graphically toggle its state.// RETURNS: ZERO if code unknown, or ID of Check Box toggled.//UINT16 CbCtrl::Scan (char ch){  if (BtnHit(ch)) {    Toggle(pb);    return pb->Id;  }  return 0;}///////////////// Same as above, but using a point as the event trigger..// RETURNS: ZERO if code unknown, or ID of radio button set.//UINT16 CbCtrl::Scan (point& Pt){  if (BtnHit(Pt)) {    Toggle(pb);    return pb->Id;  }  return 0;}///////////////////// Routine to return the state (on/off) of check box with the passed ID// RETURNS: TRUE  .. state stored in passed reference var//	    FALSE .. unknown check box ID//BOOL CbCtrl::State (UINT16 id, BOOL &bState){  if (BtnFind(id)) {    bState = (BOOL)(pb->status & 0x01);    return TRUE;  }  return FALSE;}///////////////// Repaint all defined check boxes//void CbCtrl::Refresh (void){  btn *pb;  pb = (btn*)DblGetHead();  while (pb) {    Render(pb);    pb = (btn*)DblGetNext();  }}  //////////////////////////////////////////////////////////////////////////// Here is the system menu gadget.  For a change we need a constructor..// This will draw a DESK TOP Title area with optional close gadget and// title text.//SysMenu::SysMenu (char *st, BOOL bCloseGadget){  RenderTB();  if (bCloseGadget) {    rect rr(0, 0, SYS_Width-1, SYS_Height-1);    if (BtnNew(ID_CLOSE, "", rr)) {      btn *sb = (btn*)DblGetTail();      sb->HotKey = ALT_F4;      RenderCG(FALSE);    }    rr.lr.x = rr.lr.y = 0;    if (BtnNew(ID_HELP, "", rr)) {      btn *sb = (btn*)DblGetTail();      sb->HotKey = F1_KEY;    }    if (BtnNew(ID_REDRAW, "", rr)) {      btn *sb = (btn*)DblGetTail();      sb->HotKey = ALT_F5;    }  }  if (st) {    stTitle = st;    rect rt(SYS_Width, 0, GFX_Xmin-1, SYS_Height-1);    CtrlTxtLab(st, rt, CTLS_Centre, _BrightWhite);  }}///////////////////// Draw the Title bar//void SysMenu::RenderTB (void){  rect r(0, 0, GFX_Xmin-1, SYS_Height-1);  GfxTextColor(_Black);  GfxMoveTo(0, SYS_Height), GfxLineTo(GFX_Xmin-1, SYS_Height);  if (SYS_BarPatFgnd == SYS_BarPatBkgnd)    GfxRect(0, 0, GFX_Xmin-1, SYS_Height, GFX_Fill, SYS_BarPatBkgnd);  else {    GfxPattern(GFX_HalfTone);    GfxTextColorBg(SYS_BarPatFgnd);    GfxRect(0, 0, GFX_Xmin-1, SYS_Height, GFX_Fill, SYS_BarPatBkgnd);    GfxPattern(GFX_Solid);  }  if (stTitle.StrGetLen()) {    r.ul.x = SYS_Width;    char *psz = stTitle.StrGet();    CtrlTxtLab(psz, r, CTLS_Centre, _BrightWhite);  }}///////////////////// Draw the close gadget in one of its two states//void SysMenu::RenderCG (BOOL bSel){  UINT16 nBg = (bSel ? _DarkGrey : _White),         nBar = (bSel ? _BrightWhite : _Black),         nShad = (bSel ? _White : _DarkGrey);  Mickey.AutoPointer(0, 0, SYS_Width, SYS_Height);  GfxRect(0, 0, SYS_Width-1, SYS_Height-1, GFX_Fill, nBg);  GfxRect(4, 7, 13, 10, GFX_Fill, _BrightWhite);  GfxRect(3, 7, 14, 10, GFX_Frame, nBar);  GfxTextColor(nShad);  GfxMoveTo(5, 11), GfxLineTo(15, 11), GfxLineTo(15, 9);  GfxTextColor(_Black);  GfxMoveTo(SYS_Width, SYS_Height), GfxLineTo(SYS_Width, 0);  Mickey.ShowPointer();}//////////////////////// Walk through the system menu gadget list to see if anything corresponds// to the passed Hot Key code.  Possibilities are system gadgets (Iconize,// Maximise/Minimise and Close) or a user defined Pop-up Menu.  Some, you// may notice, are not yet implemented (NYI).// RETURNS: ZERO if code unknown, or ID of item selected.//UINT16 SysMenu::Scan (char ch){  if (BtnHit(ch)) {    if (pb->Id == ALT_F4) {      RenderCG(TRUE);      CtrlDelay();      RenderCG(FALSE);    }    return pb->Id;  }  return 0;}///////////////// This does the double click for the close gadget. On the click that "sets"// the graphic to clicked, ws store the time.  On the next click, we see if// the difference is within the double-click delay and respond accordingly.// RETURNS: ZERO if code unknown or clicks too far apart, ID otherwise..//UINT16 SysMenu::Scan (point& Pt){  static long lDblClk1, lDblClk2;  static BOOL bState = TRUE;  if (BtnHit(Pt)) {    Mickey.HidePointer();    RenderCG(bState);    Mickey.ShowPointer();    if (bState) {      lDblClk1 = Clock.GetTocks();            bState = FALSE;      return 0;    }    lDblClk2 = Clock.GetTocks();          bState = TRUE;    return (lDblClk2 - lDblClk1 <= SYS_DBLclick) ? pb->Id : 0;  }  return 0;}////////////////// Change the Application title.  Bit tricky.. we need to erase the area// occupied by the previous title (if any) having regard for whether the// title bar is a plain color or patterned.  Both this and the text// replacement (again, if any) need to adjust the location to account for// possible presence of the close gadget.//void SysMenu::SysTitle (char* st, rect &r){  INT16 nOffset = r.ul.x + (BtnHit(ALT_F4) ? SYS_Width : 0);  if (stTitle.StrGetLen()) {    INT16 y1 = r.ul.y + ((SYS_Height - GfxTextHeight()) >> 1);    INT16 y2 = y1 + GfxTextHeight();    INT16 x2 = GfxTextExtent(stTitle.StrGet());    INT16 x1 = nOffset + ((r.lr.x - nOffset - x2) >> 1);    x2 += x1;    Mickey.AutoPointer(x1, y1, x2, y2);    if (SYS_BarPatFgnd == SYS_BarPatBkgnd)      GfxRect(x1, y1, x2, y2, GFX_Fill, SYS_BarPatBkgnd);    else {      GfxSetClip(x1, y1, x2, y2);      GfxPattern(GFX_HalfTone);      GfxTextColorBg(SYS_BarPatFgnd);      GfxRect(x1, y1, x2, y2, GFX_Fill, SYS_BarPatBkgnd);      GfxPattern(GFX_Solid);      GfxClrClip();    }    Mickey.ShowPointer();  }  stTitle = st;  if (stTitle.StrGetLen()) {    rect r(nOffset, 0, GFX_Xmin-1, SYS_Height-1);    CtrlTxtLab(st, r, CTLS_Centre, _BrightWhite);  }}///////////////// Repaint all defined system gadgets, menus, etc..//void SysMenu::Refresh (void){  RenderTB();  if (BtnHit(ALT_F4))    RenderCG(FALSE);}  /********************************** eof **********************************/

⌨️ 快捷键说明

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