📄 ctk-vncserver.c
字号:
posy = win->y + 2; if(w == win->focused) { focus |= CTK_FOCUS_WIDGET; } draw_widget(w, posx, posy, posx + win->w, posy + win->h, clipy1, clipy2, focus); if(w->type != CTK_WIDGET_ICON) { update_area(posx + w->x, posy + w->y, w->w + 2, w->h); } else { icon = (struct ctk_icon *)w; len = strlen(icon->title); x = posx + w->x; if(x + len >= sizex) { x = sizex - len; } update_area(x, posy + w->y, len > 4? len: 4, w->h); } #ifdef CTK_CONIO_CONF_UPDATE CTK_CONIO_CONF_UPDATE();#endif /* CTK_CONIO_CONF_UPDATE */}/*-----------------------------------------------------------------------------------*//** * Clear a window on the VNC screen. Called by the CTK module. * * \param window The window to be cleared. * \param focus The focus of the window. * \param clipy1 The lower y coordinate bound. * \param clipy2 The upper y coordinate bound. *//*-----------------------------------------------------------------------------------*/voidctk_draw_clear_window(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2){ unsigned char i; unsigned char h; /* if(focus & CTK_FOCUS_WINDOW){ textcolor(WINDOWCOLOR_FOCUS); } else { textcolor(WINDOWCOLOR); }*/ textcolor(VNC_OUT_WINDOWCOLOR + focus); h = window->y + 2 + window->h; /* Clear window contents. */ for(i = window->y + 2; i < h; ++i) { if(i >= clipy1 && i < clipy2) { cclearxy(window->x + 1, i, window->w); } } update_area(window->x + 1, window->y + 2, window->w, window->h);}/*-----------------------------------------------------------------------------------*/static voiddraw_window_contents(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2, unsigned char x1, unsigned char x2, unsigned char y1, unsigned char y2){ struct ctk_widget *w; unsigned char wfocus; /* Draw inactive widgets. */ for(w = window->inactive; w != NULL; w = w->next) { draw_widget(w, x1, y1, x2, y2, 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, x2, y2, clipy1, clipy2, wfocus); }#ifdef CTK_CONIO_CONF_UPDATE CTK_CONIO_CONF_UPDATE();#endif /* CTK_CONIO_CONF_UPDATE */}/*-----------------------------------------------------------------------------------*//** * Draw a window on the VNC screen. Called by the CTK module. * * \param window The window to be drawn. * \param focus The focus of the window. * \param clipy1 The lower y coordinate bound. * \param clipy2 The upper y coordinate bound. *//*-----------------------------------------------------------------------------------*/voidctk_draw_window(struct ctk_window *window, unsigned char focus, unsigned char clipy1, unsigned char clipy2){ unsigned char x, y; unsigned char h; unsigned char x1, y1, x2, y2; unsigned char i; if(window->y + 1 >= clipy2) { return; } x = window->x; y = window->y + 1; textcolor(VNC_OUT_WINDOWCOLOR + focus); /* if(focus & CTK_FOCUS_WINDOW) { textcolor(WINDOWCOLOR_FOCUS); } else { textcolor(WINDOWCOLOR); }*/ x1 = x + 1; y1 = y + 1; x2 = x1 + window->w; y2 = y1 + window->h; /* Draw window frame. */ if(y >= clipy1) { cputcxy(x, y, CH_ULCORNER); for(i = wherex() + window->titlelen + 2; i < x2; ++i) { cputcxy(i, y, CH_TITLEBAR); } cputcxy(x2, y, CH_URCORNER); } h = window->h; if(clipy1 > y1) { if(clipy1 - y1 < h) { h = clipy1 - y1; y1 = clipy1; } else { h = 0; } } if(clipy2 < y1 + h) { if(y1 >= clipy2) { h = 0; } else { h = clipy2 - y1; } } for(i = y1; i < y1 + h; ++i) { cputcxy(x, i, CH_WINDOWLBORDER); cputcxy(x2, i, CH_WINDOWRBORDER); } /* cvlinexy(x, y1, h); cvlinexy(x2, y1, h); */ if(y + window->h >= clipy1 && y + window->h < clipy2) { cputcxy(x, y2, CH_LLCORNER); for(i = x1; i < x2; ++i) { cputcxy(i, y2, CH_WINDOWLOWERBORDER); } /* chlinexy(x1, y2, window->w);*/ cputcxy(x2, y2, CH_LRCORNER); } draw_window_contents(window, focus & CTK_FOCUS_WINDOW, clipy1, clipy2, x1, x2, y + 1, y2); update_area(window->x, window->y, window->w + 2, window->h + 2);}/*-----------------------------------------------------------------------------------*//** * Draw a dialog on the VNC screen. Called by the CTK module. * * \param dialog The dialog to be drawn. *//*-----------------------------------------------------------------------------------*/voidctk_draw_dialog(struct ctk_window *dialog){ unsigned char x, y; unsigned char i; unsigned char x1, y1, x2, y2; /* textcolor(DIALOGCOLOR);*/ textcolor(VNC_OUT_WINDOWCOLOR + CTK_FOCUS_DIALOG); x = dialog->x; y = dialog->y + 1; x1 = x + 1; y1 = y + 1; x2 = x1 + dialog->w; y2 = y1 + dialog->h; /* Draw dialog frame. */ for(i = y1; i < y1 + dialog->h; ++i) { cputcxy(x, i, CH_DIALOGLBORDER); cputcxy(x2, i, CH_DIALOGRBORDER); } /* cvlinexy(x, y1, dialog->h); cvlinexy(x2, y1, dialog->h);*/ for(i = x1; i < x2; ++i) { cputcxy(i, y, CH_DIALOGUPPERBORDER); cputcxy(i, y2, CH_DIALOGLOWERBORDER); } /* chlinexy(x1, y, dialog->w); chlinexy(x1, y2, dialog->w);*/ cputcxy(x, y, CH_DIALOG_ULCORNER); cputcxy(x, y2, CH_DIALOG_LLCORNER); cputcxy(x2, y, CH_DIALOG_URCORNER); cputcxy(x2, y2, CH_DIALOG_LRCORNER); /* Clear dialog contents. */ for(i = y1; i < y2; ++i) { cclearxy(x1, i, dialog->w); } draw_window_contents(dialog, CTK_FOCUS_DIALOG, 0, sizey, x1, x2, y1, y2); update_area(dialog->x, dialog->y, dialog->w + 4, dialog->h + 4);}/*-----------------------------------------------------------------------------------*//** * Clear parts of the VNC desktop. Called by the CTK module. * * \param y1 The lower y coordinate bound. * \param y2 The upped y coordinate bound. *//*-----------------------------------------------------------------------------------*/voidctk_draw_clear(unsigned char y1, unsigned char y2){ unsigned char i; textcolor(VNC_OUT_BACKGROUNDCOLOR); for(i = y1; i < y2; ++i) { cclearxy(0, i, sizex); } update_area(0, y1, sizex, y2 - y1);}/*-----------------------------------------------------------------------------------*//** \internal * Draw one menu on the VNC desktop. * * \param m The CTK menu to be drawn. *//*-----------------------------------------------------------------------------------*/static voiddraw_menu(struct ctk_menu *m){ unsigned char x, x2, y; textcolor(VNC_OUT_MENUCOLOR); x = wherex(); cputs(m->title); cputc(' '); x2 = wherex(); if(x + CTK_CONF_MENUWIDTH > sizex) { x = sizex - CTK_CONF_MENUWIDTH; } for(y = 0; y < m->nitems; ++y) { if(y == m->active) { textcolor(VNC_OUT_ACTIVEMENUCOLOR); revers(0); } else { textcolor(VNC_OUT_MENUCOLOR); } gotoxy(x, y + 1); if(m->items[y].title[0] == '-') { chline(CTK_CONF_MENUWIDTH); } else { cputs(m->items[y].title); } if(x + CTK_CONF_MENUWIDTH > wherex()) { cclear(x + CTK_CONF_MENUWIDTH - wherex()); } revers(1); } gotoxy(x2, 0); textcolor(VNC_OUT_MENUCOLOR); update_area(x, 0, CTK_CONF_MENUWIDTH, m->nitems + 1);}/*-----------------------------------------------------------------------------------*//** * Draw the menus on the virtual VNC desktop. Called by the CTK module. * * \param menus The CTK menubar. *//*-----------------------------------------------------------------------------------*/voidctk_draw_menus(struct ctk_menus *menus){ struct ctk_menu *m; /* Draw menus */ textcolor(VNC_OUT_MENUCOLOR); gotoxy(0, 0); revers(1); cputc(' '); for(m = menus->menus->next; m != NULL; m = m->next) { if(m != menus->open) { update_area(wherex(), 0, strlen(m->title) + 1, 1); cputs(m->title); cputc(' '); } else { draw_menu(m); } } if(wherex() + strlen(menus->desktopmenu->title) + 1>= sizex) { gotoxy(sizex - strlen(menus->desktopmenu->title) - 1, 0); } else { cclear(sizex - wherex() - strlen(menus->desktopmenu->title) - 1); update_area(wherex(), 0, sizex - wherex() - strlen(menus->desktopmenu->title) - 1, 1); } /* Draw desktopmenu */ if(menus->desktopmenu != menus->open) { update_area(wherex(), 0, strlen(menus->desktopmenu->title) + 1, 1); cputs(menus->desktopmenu->title); cputc(' '); } else { draw_menu(menus->desktopmenu); } revers(0);}/*-----------------------------------------------------------------------------------*//** * Obtain the height of the VNC desktop. Called by the CTK module. * * \return The height of the VNC desktop, in characters. *//*-----------------------------------------------------------------------------------*/unsigned charctk_draw_height(void){ return sizey;}/*-----------------------------------------------------------------------------------*//** * Obtain the height of the VNC desktop. Called by the CTK module. * * \return The height of the VNC desktop, in characters. *//*-----------------------------------------------------------------------------------*/unsigned charctk_draw_width(void){ return sizex;}/*-----------------------------------------------------------------------------------*//** \internal * Converts between ASCII and the VNC screen character encoding. *//*-----------------------------------------------------------------------------------*/static unsigned charascii2screen(unsigned char c){ if(c == '|') { return 0x68; } if(c < 0x20) { return c + 0x60; } if(c > 0x20 && c < 0x40) { return c; } if(c >= 0x40 && c < 0x60) { return c; } if(c >= 0x60 && c < 0x80) { return c - 0x60; } if(c >= 0x80) { return c; } return 32;}/*-----------------------------------------------------------------------------------*//** * Draws a character on the virtual VNC screen. Called by the libconio module. * * \param c The character to be drawn. * \param xpos The x position of the character. * \param ypos The y position of the character. * \param reversedflag Determines if the character should be reversed or not. * \param color The color of the character. *//*-----------------------------------------------------------------------------------*/voidctk_arch_draw_char(char c, unsigned char xpos, unsigned char ypos, unsigned char reversedflag, unsigned char color){ vnc_out_update_screen(xpos, ypos, ascii2screen(c), color); /* vnc_out_update_screen(xpos, ypos, c | (reversedflag? 0x80: 0));*/}/*-----------------------------------------------------------------------------------*//** * Checks the key press input queue to see if there are pending * keys. Called by the CTK module. * * \return Zero if no key presses are in buffer, non-zero if there are * key presses in input buffer. *//*-----------------------------------------------------------------------------------*/unsigned charctk_arch_keyavail(void){ return vnc_out_keyavail();}/*-----------------------------------------------------------------------------------*//** * Retrieves key presses from the VNC client. Called by the CTK * module. * * \return The next key in the input queue. *//*-----------------------------------------------------------------------------------*/ctk_arch_key_tctk_arch_getkey(void){ return vnc_out_getkey() & 0x7f;}/*-----------------------------------------------------------------------------------*//** \internal * The uIP event handler. *//*-----------------------------------------------------------------------------------*/staticDISPATCHER_UIPCALL(ctk_vncserver_appcall, state){ static struct vnc_server_state *vs; DISPATCHER_UIPCALL_ARG(state); vs = (struct vnc_server_state *)(state); if(uip_connected()) { /* Since we've just been connected, the state pointer should be NULL and we need to allocate a new state object. If we have run out of memory for state objects, we'll have to abort the connection and return. */ if(vs == NULL) { vs = alloc_state(); if(vs == NULL) { uip_close(); return; } dispatcher_markconn(uip_conn, (void *)vs); } } else if(uip_closed() || uip_aborted()) { if(vs != NULL) { dealloc_state(vs); } return; } vnc_server_appcall(vs);}/*-----------------------------------------------------------------------------------*/LOADER_INIT_FUNC(ctk_vncserver_init, arg){ u8_t i; arg_free(arg); if(id == EK_ID_NONE) { id = dispatcher_start(&p); dispatcher_uiplisten(HTONS(5900)); for(i = 0; i < CTK_VNCSERVER_CONF_NUMCONNS; ++i) { conns[i].state = VNC_DEALLOCATED; } }}/*-----------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -