?? rguiproc.c
字號:
}// d_raine_button_proc():// A button object (the dp field points to the text string). This object// can be selected by clicking on it with the mouse or by pressing its // keyboard shortcut. If the D_EXIT flag is set, selecting it will close // the dialog, otherwise it will toggle on and off.//// Only MSG_DRAW is changed, all others fall back on the original d_button_procint d_raine_button_proc(int msg, DIALOG *d, int c){ int state1, state2; int swap; int g; switch (msg) { case MSG_DRAW: if(d->flags & D_SELECTED){ solid_3d_box_invert(d->x, d->y, d->x + d->w, d->y + d->h); //line(screen, d->x+1, d->y+1, d->x+1, d->y+d->h-1, CGUI_BOX_COL_LOW_1); //line(screen, d->x+1, d->y+1, d->x+d->w-1, d->y+1, CGUI_BOX_COL_LOW_1); g = 1; state1 = (d->flags & D_DISABLED) ? gui_mg_color : translate_color(d->fg); state2 = translate_color(d->bg); } else{ solid_3d_box(d->x, d->y, d->x + d->w, d->y + d->h); //line(screen, d->x+1, d->y+d->h-1, d->x+d->w-1, d->y+d->h-1, CGUI_BOX_COL_LOW_1); //line(screen, d->x+d->w-1, d->y+1, d->x+d->w-1, d->y+d->h-1, CGUI_BOX_COL_LOW_1); g = 0; state1 = (d->flags & D_DISABLED) ? gui_mg_color : translate_color(d->fg); state2 = translate_color(d->bg); } text_mode(-1); gui_textout(screen, raine_translate_text(d->dp), d->x+d->w/2+g, d->y+d->h/2-text_height(font)/2+g, state1, TRUE); if((d->flags & D_GOTFOCUS) && (!(d->flags & D_SELECTED) || !(d->flags & D_EXIT))){ dotted_rect(d->x+1+g, d->y+1+g, d->x+d->w-2+g, d->y+d->h-2+g); } break; case MSG_WANTFOCUS: return D_WANTFOCUS; case MSG_KEY: /* close dialog? */ if (d->flags & D_EXIT) { return D_CLOSE; } /* or just toggle */ d->flags ^= D_SELECTED; scare_mouse(); SEND_MESSAGE(d, MSG_DRAW, 0); unscare_mouse(); break; case MSG_CLICK: /* what state was the button originally in? */ state1 = d->flags & D_SELECTED; if (d->flags & D_EXIT) swap = FALSE; else swap = state1; /* track the mouse until it is released */ while (gui_mouse_b()) { state2 = ((rgui_mouse_x() >= d->x) && (rgui_mouse_y() >= d->y) && (rgui_mouse_x() < d->x + d->w) && (rgui_mouse_y() < d->y + d->h)); if (swap) state2 = !state2; /* redraw? */ if (((state1) && (!state2)) || ((state2) && (!state1))) { d->flags ^= D_SELECTED; state1 = d->flags & D_SELECTED; scare_mouse(); SEND_MESSAGE(d, MSG_DRAW, 0); unscare_mouse(); } /* let other objects continue to animate */ broadcast_dialog_message(MSG_IDLE, 0); } /* should we close the dialog? */ if ((d->flags & D_SELECTED) && (d->flags & D_EXIT)) { d->flags ^= D_SELECTED; return D_CLOSE; } break; } return D_O_K;}int x_raine_button_proc(int msg, DIALOG *d, int c){ return d_raine_button_proc(msg,d,c);}/* x_edit_proc */int x_edit_proc(int msg, DIALOG *d, int c){ int f, l, p, w, x, fg, b, scroll; char buf[16]; char *s; int rtm; if (msg == MSG_DRAW) { s = d->dp; l = ustrlen(s); if (d->d2 > l) d->d2 = l; /* calculate maximal number of displayable characters */ if (d->d2 == l) { usetc(buf+usetc(buf, ' '), 0); x = text_length(font, buf); } else x = 0; b = 0; for (p=d->d2; p>=0; p--) { usetc(buf+usetc(buf, ugetat(s, p)), 0); x += text_length(font, buf); b++; if (x > d->w) break; } if (x <= d->w) { b = l; scroll = FALSE; } else { b--; scroll = TRUE; } // Real drawing fg = (d->flags & D_DISABLED) ? gui_mg_color : translate_color(d->fg); x = 0; if (scroll) { p = d->d2-b+1; b = d->d2; } else p = 0; for (; p<=b; p++) { f = ugetat(s, p); usetc(buf+usetc(buf, (f) ? f : ' '), 0); w = text_length(font, buf); if (x+w > d->w) break; f = ((p == d->d2) && (d->flags & D_GOTFOCUS)); rtm = text_mode((f) ? fg : translate_color(d->bg)); textout(screen, font, buf, d->x+x, d->y, (f) ? translate_color(d->bg) : fg); text_mode(rtm); x += w; } if (x < d->w) rectfill(screen, d->x+x, d->y, d->x+d->w-1, d->y+text_height(font)-1, translate_color(d->bg)); } else { // MSG_DRAW return d_edit_proc(msg,d,c); } return D_O_K;}// d_raine_radio_proc():// GUI procedure for radio buttons.// Parameters: d1-button group number; d2-button style (0=circle,1=square);// dp-text to appear as label to the right of the button.//// Only MSG_DRAW is changed, all others fall back on the original d_radio_procint d_raine_radio_proc(int msg, DIALOG *d, int c){ int x, center, r, fg; if(msg==MSG_DRAW){ fg = (d->flags & D_DISABLED) ? CGUI_BOX_COL_MIDDLE : translate_color(d->fg); text_mode(CGUI_BOX_COL_MIDDLE); gui_textout(screen, d->dp, d->x+d->h+text_height(font), d->y+(d->h-(text_height(font)-gui_font_baseline))/2, fg, FALSE); x = d->x; r = d->h/2; center = x+r; rectfill(screen, x+1, d->y+1, x+d->h-1, d->y+d->h-1, CGUI_BOX_COL_MIDDLE); switch (d->d2) { case 1: trans_3d_box(x, d->y, x+d->h, d->y+d->h); if (d->flags & D_SELECTED) rectfill(screen, x+r/2, d->y+r/2, x+d->h-r/2, d->y+d->h-r/2, CGUI_BOX_COL_HIGH_2); break; default: circle(screen, center, d->y+r, r, fg); if (d->flags & D_SELECTED) circlefill(screen, center, d->y+r, r/2, CGUI_BOX_COL_HIGH_2); break; } if(d->flags & D_GOTFOCUS){ dotted_rect(x+1, d->y+1, x+d->h-1, d->y+d->h-1); } return D_O_K; } else{ return d_radio_proc(msg,d,c); }}int x_raine_radio_proc(int msg, DIALOG *d, int c){ int x, center, r, fg; if(msg==MSG_DRAW){ fg = (d->flags & D_DISABLED) ? CGUI_BOX_COL_MIDDLE : translate_color(d->fg); text_mode(CGUI_BOX_COL_MIDDLE); gui_textout(screen, raine_translate_text(d->dp), d->x+d->h+text_height(font), d->y+(d->h-(text_height(font)-gui_font_baseline))/2, fg, FALSE); x = d->x; r = d->h/2; center = x+r; rectfill(screen, x+1, d->y+1, x+d->h-1, d->y+d->h-1, CGUI_BOX_COL_MIDDLE); switch (d->d2) { case 1: trans_3d_box(x, d->y, x+d->h, d->y+d->h); if (d->flags & D_SELECTED) rectfill(screen, x+r/2, d->y+r/2, x+d->h-r/2, d->y+d->h-r/2, CGUI_BOX_COL_HIGH_2); break; default: circle(screen, center, d->y+r, r, fg); if (d->flags & D_SELECTED) circlefill(screen, center, d->y+r, r/2, CGUI_BOX_COL_HIGH_2); break; } if(d->flags & D_GOTFOCUS){ dotted_rect(x+1, d->y+1, x+d->h-1, d->y+d->h-1); } return D_O_K; } else{ return d_radio_proc(msg,d,c); }}/* _draw_raine_scrollable_frame: * Helper function to draw a frame for all objects with vertical scrollbars. */void _draw_raine_scrollable_frame(DIALOG *d, int listsize, int offset, int height, int fg_color){ int i, len; int xx, yy; // possibly draw scrollbar if (listsize > height) { trans_3d_box(d->x, d->y, d->x+d->w-(8+5), d->y+d->h); trans_3d_box(d->x+d->w-(8+4), d->y, d->x+d->w, d->y+d->h); // scrollbar with focus if (d->flags & D_GOTFOCUS) { dotted_rect(d->x+1, d->y+1, d->x+d->w-(8+6), d->y+d->h-1); dotted_rect(d->x+d->w-(8+3), d->y+1, d->x+d->w-1, d->y+d->h-1); } else { rect(screen, d->x+1, d->y+1, d->x+d->w-(8+6), d->y+d->h-1, CGUI_BOX_COL_MIDDLE); rect(screen, d->x+d->w-(8+3), d->y+1, d->x+d->w-1, d->y+d->h-1, CGUI_BOX_COL_MIDDLE); } // create and draw the scrollbar i = ((d->h-4) * height + listsize/2) / listsize; xx = d->x+d->w-(8+2); yy = d->y+2; if (offset > 0) { len = (((d->h-4) * offset) + listsize/2) / listsize; rectfill(screen, xx, yy, xx+8, yy+len-1, CGUI_BOX_COL_MIDDLE); yy += len; } if (yy+i+1 < d->y+d->h-2) { solid_3d_box(xx, yy, xx+8+1, yy+i+1); yy += i+1; rectfill(screen, xx, yy, xx+8, d->y+d->h-2, CGUI_BOX_COL_MIDDLE); } else { solid_3d_box(xx, yy, xx+8+1, d->y+d->h-1); } } else { trans_3d_box(d->x, d->y, d->x+d->w, d->y+d->h); // no scrollbar necessary if (d->flags & D_GOTFOCUS) dotted_rect(d->x+1, d->y+1, d->x+d->w-1, d->y+d->h-1); else rect(screen, d->x+1, d->y+1, d->x+d->w-1, d->y+d->h-1, CGUI_BOX_COL_MIDDLE); }}/* _draw_raine_listbox: * Helper function to draw a listbox object. */void _draw_raine_listbox(DIALOG *d){ int height, listsize, i, len, bar, x, y, w; int fg_color, fg, bg; char *sel = d->dp2; char s[1024]; (*(getfuncptr)d->dp)(-1, &listsize); height = (d->h-3) / text_height(gui_fixed_font); bar = (listsize > height); w = (bar ? d->w-14 : d->w-2); fg_color = (d->flags & D_DISABLED) ? gui_mg_color : CGUI_BOX_COL_HIGH_2; /* draw box contents */ for (i=0; i<height; i++) { if (d->d2+i < listsize) { if (d->d2+i == d->d1) { fg = CGUI_COL_TEXT_1; bg = CGUI_BOX_COL_HIGH_2; } else if ((sel) && (sel[d->d2+i])) { fg = CGUI_COL_TEXT_1; bg = CGUI_BOX_COL_MIDDLE; } else { fg = CGUI_COL_TEXT_1; bg = CGUI_BOX_COL_MIDDLE; } usetc(s, 0); ustrncat(s, (*(getfuncptr)d->dp)(i+d->d2, NULL), sizeof(s)-ucwidth(0)); x = d->x + 2; y = d->y + 2 + i*text_height(gui_fixed_font); text_mode(bg); rectfill(screen, x, y, x+7, y+text_height(gui_fixed_font)-1, bg); x += 8; len = ustrlen(s); while (text_length(gui_fixed_font, s) >= MAX(d->w - (bar ? 22 : 10), 1)) { len--; usetat(s, len, 0); } textout(screen, gui_fixed_font, s, x, y, CGUI_COL_TEXT_1); x += text_length(gui_fixed_font, s); if (x <= d->x+w) rectfill(screen, x, y, d->x+w, y+text_height(gui_fixed_font)-1, bg); } else { rectfill(screen, d->x+2, d->y+2+i*text_height(gui_fixed_font), d->x+w, d->y+1+(i+1)*text_height(gui_fixed_font), CGUI_BOX_COL_MIDDLE); } } if (d->y+2+i*text_height(gui_fixed_font) <= d->y+d->h-2) rectfill(screen, d->x+2, d->y+2+i*text_height(gui_fixed_font), d->x+w, d->y+d->h-2, CGUI_BOX_COL_MIDDLE); /* draw frame, maybe with scrollbar */ _draw_raine_scrollable_frame(d, listsize, d->d2, height, fg_color);}// d_raine_list_proc():// A list box object. The dp field points to a function which it will call// to obtain information about the list. This should follow the form:// char *<list_func_name> (int index, int *list_size);// If index is zero or positive, the function should return a pointer to// the string which is to be displayed at position index in the list. If// index is negative, it should return null and list_size should be set// to the number of items in the list. The list box object will allow the
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -