ctk-hires-service.c
来自「伟大的Contiki工程, 短小精悍 的操作系统, 学习编程不可不看」· C语言 代码 · 共 926 行 · 第 1/2 页
C
926 行
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; }}/*-----------------------------------------------------------------------------------*/static voids_ctk_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);}/*-----------------------------------------------------------------------------------*/static voids_ctk_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); } }}/*-----------------------------------------------------------------------------------*/static voids_ctk_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); }}/*-----------------------------------------------------------------------------------*/static voids_ctk_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); }}/*-----------------------------------------------------------------------------------*/static voids_ctk_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); }/*-----------------------------------------------------------------------------------*/static voids_ctk_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); }}/*-----------------------------------------------------------------------------------*/static unsigned chars_ctk_draw_height(void){ return SCREEN_HEIGHT;}/*-----------------------------------------------------------------------------------*/static unsigned chars_ctk_draw_width(void){ return SCREEN_WIDTH;}/*-----------------------------------------------------------------------------------*/static unsigned shorts_ctk_mouse_xtoc(unsigned short x){ return x / 8;}/*-----------------------------------------------------------------------------------*/static unsigned shorts_ctk_mouse_ytoc(unsigned short y){ return y / 8;}/*-----------------------------------------------------------------------------------*/SERVICE(ctk_hires_service, ctk_draw_service, { 1, 1, 1, s_ctk_draw_init, s_ctk_draw_clear, s_ctk_draw_clear_window, s_ctk_draw_window, s_ctk_draw_dialog, s_ctk_draw_widget, s_ctk_draw_menus, s_ctk_draw_width, s_ctk_draw_height, s_ctk_mouse_xtoc, s_ctk_mouse_ytoc });/*--------------------------------------------------------------------------*/PROCESS(ctk_hires_service_process, "CTK hires service");PROCESS_THREAD(ctk_hires_service_process, ev, data) { PROCESS_BEGIN(); s_ctk_draw_init(); ctk_restore(); SERVICE_REGISTER(ctk_hires_service); while(ev != PROCESS_EVENT_SERVICE_REMOVED && ev != PROCESS_EVENT_EXIT) { PROCESS_WAIT_EVENT(); } SERVICE_REMOVE(ctk_hires_service); VIC.ctrl1 = 0x1b; /* $D011 */ VIC.addr = 0x17; /* $D018 */ VIC.ctrl2 = 0xc8; /* $D016 */ CIA2.pra = 0x03; /* $DD00 */ PROCESS_END();}/*--------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?