ctk-hires.c

来自「伟大的Contiki工程, 短小精悍 的操作系统, 学习编程不可不看」· C语言 代码 · 共 872 行 · 第 1/2 页

C
872
字号
  asm("lda %v+%w", ctk_hires_theme,      offsetof(struct ctk_hires_theme, pointercolor));  asm("sta $d028");  ptr1 = ctk_hires_theme.pointer;  ptr2 = (unsigned char *)0xff40;    for(i = 0; i < 0x80; ++i) {    *ptr2++ = *ptr1++;  }  return;}#pragma optimize(pop)/*-----------------------------------------------------------------------------------*/static void __fastcall__draw_widget(register struct ctk_widget *w,	    unsigned char x, unsigned char y,	    unsigned char clipy1, unsigned char clipy2,	    unsigned char afocus){  static unsigned char xpos, ypos, xscroll;  static unsigned char i;  static char c;  static unsigned char len;  static unsigned char tmp;  static unsigned char yclipped;  static unsigned char focus;  char *text;    xpos = x + w->x;  ypos = y + w->y;    yclipped = 0;    if(ypos >= clipy1 && ypos < clipy2) {    yclipped = 1;  }  focus = afocus;      switch(w->type) {  case CTK_WIDGET_SEPARATOR:    hires_color(ctk_hires_theme.separatorcolors[focus]);    if(yclipped) {      hires_chlinexy(xpos, ypos, w->w);    }    break;  case CTK_WIDGET_LABEL:    hires_color(ctk_hires_theme.labelcolors[focus]);    text = w->widget.label.text;    for(i = 0; i < w->h; ++i) {      if(ypos >= clipy1 && ypos < clipy2) {	hires_gotoxy(xpos, ypos);	ctk_hires_cputsn(text, w->w);	tmp = w->w - (hires_wherex() - xpos);	if(tmp > 0) {	  ctk_hires_cclear(tmp);	}      }      ++ypos;      text += w->w;    }    break;  case CTK_WIDGET_BUTTON:    if(yclipped) {      hires_color(ctk_hires_theme.buttonleftcolors[focus]);      hires_gotoxy(xpos, ypos);      ctk_hires_draw_buttonleft();      hires_color(ctk_hires_theme.buttoncolors[focus]);      hires_gotoxy(xpos + 1, ypos);      ctk_hires_cputsn(w->widget.button.text, w->w);      hires_color(ctk_hires_theme.buttonrightcolors[focus]);      ctk_hires_draw_buttonright();    }    break;  case CTK_WIDGET_HYPERLINK:    if(yclipped) {      hires_color(ctk_hires_theme.hyperlinkcolors[focus]);      hires_underline(1);      hires_gotoxy(xpos, ypos);      ctk_hires_cputsn(w->widget.button.text, w->w);      hires_underline(0);    }    break;  case CTK_WIDGET_TEXTENTRY:    if(yclipped) {      hires_color(ctk_hires_theme.textentrycolors[focus]);            if((focus & CTK_FOCUS_WIDGET) &&	 w->widget.textentry.state != CTK_TEXTENTRY_EDIT) {	hires_revers(1);      } else {	hires_revers(0);      }      xscroll = 0;      tmp = w->w - 1;      if(w->widget.textentry.xpos >= tmp) {	xscroll = w->widget.textentry.xpos - tmp;      }      text = w->widget.textentry.text;      if(w->widget.textentry.state == CTK_TEXTENTRY_EDIT) {	hires_revers(0);	hires_cputcxy(xpos, ypos, '>');	text += xscroll;	for(i = 0; i < w->w; ++i) {	  c = *text;	  if(i == w->widget.textentry.xpos - xscroll) {	    hires_revers(1);	  } else {	    hires_revers(0);	  }	  if(c == 0) {	    ctk_hires_cputc(' ');	  } else {	    ctk_hires_cputc(c);	  }	  hires_revers(0);	  ++text;	}	ctk_hires_cputc('<');      } else {	hires_cputcxy(xpos, ypos, '|');	/*	  hires_gotoxy(xpos + 1, ypos);          */	ctk_hires_cputsn(text, w->w);	i = hires_wherex();	tmp = i - xpos - 1;	if(tmp < w->w) {	  ctk_hires_cclear(w->w - tmp);	}	ctk_hires_cputc('|');      }    }    hires_revers(0);    break;  case CTK_WIDGET_ICON:    if(yclipped) {      hires_color(ctk_hires_theme.iconcolors[focus]);      x = xpos;      len = strlen(w->widget.icon.title);      if(x + len >= SCREEN_WIDTH) {	x = SCREEN_WIDTH - len;      }      tmp = ypos + 3;	      if(tmp < clipy2) {	hires_gotoxy(x, tmp);	ctk_hires_cputsn(w->widget.icon.title, len);      }      hires_gotoxy(xpos, ypos);      if(w->widget.icon.bitmap != NULL) {	ctk_hires_bitmapptr = w->widget.icon.bitmap;	for(i = 0; i < 3; ++i) {	  if(ypos >= clipy1 && ypos < clipy2) {	    hires_gotoxy(xpos, ypos);	    ctk_hires_draw_bitmapline(3);	  }	  ctk_hires_bitmapptr += 3 * 8;	  ++ypos;	}		/*	draw_bitmap_icon(w->widget.icon.bitmap);*/      }    }    break;  case CTK_WIDGET_BITMAP:    hires_color(ctk_hires_theme.bitmapcolors[focus]);    ctk_hires_bitmapptr = w->widget.bitmap.bitmap;    for(i = 0; i < w->h; ++i) {      if(ypos >= clipy1 && ypos < clipy2) {	hires_gotoxy(xpos, ypos);	ctk_hires_draw_bitmapline(w->w);      }      ctk_hires_bitmapptr += w->w * 8;      ++ypos;    }    break;  default:    break;  }}/*-----------------------------------------------------------------------------------*/voidctk_draw_widget(struct ctk_widget *w,		unsigned char focus,		unsigned char clipy1,		unsigned char clipy2){  struct ctk_window *win = w->window;  unsigned char posx, posy;  posx = win->x + 1;  posy = win->y + 2;  if(w == win->focused) {    focus |= CTK_FOCUS_WIDGET;  }    draw_widget(w, posx, posy,	      clipy1, clipy2,	      focus);}/*-----------------------------------------------------------------------------------*/voidctk_draw_clear_window(register struct ctk_window *window,		      unsigned char focus,		      unsigned char clipy1,		      unsigned char clipy2){  static unsigned char h;  hires_color(ctk_hires_theme.windowcolors[focus]);    h = window->y + 2 + window->h;  /* Clear window contents. */  for(i = window->y + 2; i < h; ++i) {    if(i >= clipy1 && i <= clipy2) {      hires_cclearxy(window->x + 1, i, window->w);    }  }}/*-----------------------------------------------------------------------------------*/voidctk_draw_window(register struct ctk_window *window,		unsigned char focus,		unsigned char clipy1, unsigned char clipy2,		unsigned char draw_borders){  register struct ctk_widget *w;  x = window->x;  y = window->y + 1;    ++clipy2;    if(clipy2 <= y) {    return;  }    /*  hires_color(ctk_hires_theme.windowcolors[focus+1]);*/    x1 = x + 1;  y1 = y + 1;  /*  x2 = x1 + window->w;      y2 = y1 + window->h;*/      hires_gotoxy(x, y);  ctk_hires_windowparams.w = window->w;  ctk_hires_windowparams.h = window->h;  if(clipy1 < y) {    ctk_hires_windowparams.clipy1 = 0;  } else {    ctk_hires_windowparams.clipy1 = clipy1 - y;  }  ctk_hires_windowparams.clipy2 = clipy2 - y;  ctk_hires_windowparams.color1 = ctk_hires_theme.windowcolors[focus+1];  ctk_hires_windowparams.color2 = ctk_hires_theme.windowcolors[focus];  ctk_hires_windowparams.title = window->title;  ctk_hires_windowparams.titlelen = window->titlelen;  if(ctk_hires_windowparams.clipy1 < ctk_hires_windowparams.clipy2 &&     ctk_hires_windowparams.clipy2 > 0) {    ctk_hires_draw_windowborders();  }    /* Draw inactive widgets. */  for(w = window->inactive; w != NULL; w = w->next) {    draw_widget(w, x1, y1,		clipy1, clipy2,		focus);  }    /* Draw active widgets. */  for(w = window->active; w != NULL; w = w->next) {      wfocus = focus;    if(w == window->focused) {      wfocus |= CTK_FOCUS_WIDGET;    }    draw_widget(w, x1, y1,		clipy1, clipy2,		wfocus);  }}/*-----------------------------------------------------------------------------------*/voidctk_draw_dialog(register struct ctk_window *dialog){  register struct ctk_widget *w;  hires_color(ctk_hires_theme.windowcolors[CTK_FOCUS_DIALOG]);  /*  x = (SCREEN_WIDTH - dialog->w) / 2;      y = (SCREEN_HEIGHT - 1 - dialog->h) / 2; */  x = dialog->x;  y = dialog->y + 1;  x1 = x + 1;  y1 = y + 1;  x2 = x1 + dialog->w;  y2 = y1 + dialog->h;  /* Draw dialog frame. */    hires_cvlinexy(x, y1, dialog->h);  hires_cvlinexy(x2, y1, dialog->h);  hires_chlinexy(x1, y, dialog->w);  hires_chlinexy(x1, y2, dialog->w);  hires_cputcxy(x, y, CH_ULCORNER);  hires_cputcxy(x, y2, CH_LLCORNER);  hires_cputcxy(x2, y, CH_URCORNER);  hires_cputcxy(x2, y2, CH_LRCORNER);      /* Clear window contents. */  for(i = y1; i < y2; ++i) {    hires_cclearxy(x1, i, dialog->w);  }    /* Draw inactive widgets. */  for(w = dialog->inactive; w != NULL; w = w->next) {    draw_widget(w, x1, y1,		0, SCREEN_HEIGHT, CTK_FOCUS_DIALOG);  }  /* Draw active widgets. */  for(w = dialog->active; w != NULL; w = w->next) {    wfocus = CTK_FOCUS_DIALOG;    if(w == dialog->focused) {      wfocus |= CTK_FOCUS_WIDGET;    }    draw_widget(w, x1, y1, 		0, SCREEN_HEIGHT, wfocus);  }}/*-----------------------------------------------------------------------------------*/voidctk_draw_clear(unsigned char y1, unsigned char y2){  for(i = y1; i < y2; ++i) {    clear_line(i);  }}/*-----------------------------------------------------------------------------------*/static voiddraw_menu(register struct ctk_menu *m){  static unsigned char x, x2, y;    hires_color(ctk_hires_theme.openmenucolor);  x = hires_wherex();  ctk_hires_cputsn(m->title, m->titlelen);  ctk_hires_cputc(' ');  x2 = hires_wherex();  if(x + CTK_CONF_MENUWIDTH > SCREEN_WIDTH) {    x = SCREEN_WIDTH - CTK_CONF_MENUWIDTH;  }        for(y = 0; y < m->nitems; ++y) {    if(y == m->active) {      hires_color(ctk_hires_theme.activemenucolor);    } else {      hires_color(ctk_hires_theme.menucolor);    }    hires_gotoxy(x, y + 1);    if(m->items[y].title[0] == '-') {      ctk_hires_chline(CTK_CONF_MENUWIDTH);    } else {      ctk_hires_cputsn(m->items[y].title,			  strlen(m->items[y].title));    }    ctk_hires_cclear(x + CTK_CONF_MENUWIDTH - hires_wherex());    hires_revers(0);  }  hires_gotoxy(x2, 0);  hires_color(ctk_hires_theme.menucolor);  }/*-----------------------------------------------------------------------------------*/voidctk_draw_menus(struct ctk_menus *menus){  struct ctk_menu *m;    /* Draw menus */  hires_color(ctk_hires_theme.menucolor);   hires_gotoxy(0, 0);  hires_revers(0);  ctk_hires_cputc(' ');  for(m = menus->menus->next; m != NULL; m = m->next) {    if(m != menus->open) {      ctk_hires_cputsn(m->title, m->titlelen);      ctk_hires_cputc(' ');    } else {           draw_menu(m);    }  }  ctk_hires_cclear(SCREEN_WIDTH - hires_wherex() -		      strlen(menus->desktopmenu->title) - 1);    /* Draw desktopmenu */    if(menus->desktopmenu != menus->open) {    ctk_hires_cputsn(menus->desktopmenu->title,			menus->desktopmenu->titlelen);    ctk_hires_cputc(' ');  } else {    draw_menu(menus->desktopmenu);  }}/*-----------------------------------------------------------------------------------*/unsigned charctk_draw_height(void){  return SCREEN_HEIGHT;}/*-----------------------------------------------------------------------------------*/unsigned charctk_draw_width(void){  return SCREEN_WIDTH;}/*-----------------------------------------------------------------------------------*//*unsigned charctk_arch_isprint(char c){  return isprint(c);}*/

⌨️ 快捷键说明

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