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

📄 rguiproc.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 3 页
字号:
// user to scroll through the list and to select items list by clicking// on them, and if it has the input focus also by using the arrow keys. If // the D_EXIT flag is set, double clicking on a list item will cause it to // close the dialog. The index of the selected item is held in the d1 // field, and d2 is used to store how far it has scrolled through the list.//// + MSG_DRAW is changed// + MSG_KEY/MSG_DCLICK are changed, so the list function is able to act upon//   the selection// + MSG_CHAR is changed, so the list function can use key shortcuts for//   selecting positionint d_raine_list_proc(int msg, DIALOG *d, int c){  int last_d1,ret; //ta   last_d1 = d->d1;   ret = D_O_K;   switch(msg){      case MSG_DRAW:         _draw_raine_listbox(d);      break;      case MSG_DCLICK:      case MSG_KEY:         ret = d_list_proc(msg,d,c);	 (*(getfuncptr)d->dp)(-2, &ret);      break;      case MSG_XCHAR:      case MSG_CHAR:         ret = d_list_proc(msg,d,c);         if(ret != D_USED_CHAR){		// If base routine didn't use the key...         ret = c;	 (*(getfuncptr)d->dp)(-3, &ret);         if(ret == D_USED_CHAR){	    scare_mouse();	    SEND_MESSAGE(d, MSG_DRAW, 0);	    unscare_mouse();            ret = D_USED_CHAR;         }         else{            ret = D_O_K;         }         }      break;      default:         ret = d_list_proc(msg,d,c);      break;   }   // Act on change of d1   if(last_d1 != d->d1){      last_d1 = d->d1;      (*(getfuncptr)d->dp)(-4, &last_d1);   }   return ret;}/* _draw_textbox: *  Helper function to draw a textbox object. */void _draw_raine_textbox(char *thetext, int *listsize, int draw, int offset,		   int wword, int tabsize, int x, int y, int w, int h,		   int disabled, int fore, int deselect, int disable){   int fg = fore;   int y1 = y+4;   int x1;   int len;   int ww = w-4;   char s[16];   char text[16];   char space[16];   char *printed = text;   char *scanned = text;   char *oldscan = text;   char *ignore = NULL;   char *tmp, *ptmp;   int width;   int line = 0;   int i = 0;   usetc(s+usetc(s, '.'), 0);   usetc(text+usetc(text, ' '), 0);   usetc(space+usetc(space, ' '), 0);   /* find the correct text */   if (thetext != NULL) {      printed = thetext;      scanned = thetext;   }   /* do some drawing setup */   if (draw) {      /* initial start blanking at the top */      rectfill(screen, x+2, y+2, x+w-1, y1-1, deselect);   }   /* choose the text color */   if (disabled)       fg = disable;   text_mode(deselect);   /* loop over the entire string */   while (1) {      width = 0;      /* find the next break */      while (ugetc(scanned)) {	 /* check for a forced break */	 if (ugetc(scanned) == '\n') {	    scanned += uwidth(scanned);	    /* we are done parsing the line end */	    break;	 }	 /* the next character length */	 usetc(s+usetc(s, ugetc(scanned)), 0);	 len = text_length(gui_fixed_font, s);	 /* modify length if its a tab */	 if (ugetc(s) == '\t') 	    len = tabsize * text_length(gui_fixed_font, space);	 /* check for the end of a line by excess width of next char */	 if (width+len >= ww) {	    /* we have reached end of line do we go back to find start */	    if (wword) {	       /* remember where we were */	       oldscan = scanned;	       /* go backwards looking for start of word */	       while (!uisspace(ugetc(scanned))) {		  /* don't wrap too far */		  if (scanned == printed) {		     /* the whole line is filled, so stop here */		     scanned = oldscan;		     break;		  }		  /* look further backwards to wrap */		  tmp = ptmp = printed;		  while (tmp < scanned) {		     ptmp = tmp;		     tmp += uwidth(tmp);		  }		  scanned = ptmp;	       }	       /* put the space at the end of the line */	       ignore = scanned;	       scanned += uwidth(scanned);	       /* check for endline at the convenient place */	       if (ugetc(scanned) == '\n') 		  scanned += uwidth(scanned);	    }	    /* we are done parsing the line end */	    break;	 }	 /* the character can be added */	 scanned += uwidth(scanned);	 width += len;      }      /* check if we are to print it */      if ((draw) && (line >= offset) && (y1+text_height(gui_fixed_font) < (y+h-1))) {	 x1 = x+4;	 /* the initial blank bit */	 rectfill(screen, x+2, y1, x1-1, y1+text_height(gui_fixed_font), deselect);	 /* print up to the marked character */	 while (printed != scanned) {	    /* do special stuff for each charater */	    switch (ugetc(printed)) {	       case '\r':	       case '\n':		  /* don't print endlines in the text */		  break;	       /* possibly expand the tabs */	       case '\t':		  for (i=0; i<tabsize; i++) {		     usetc(s+usetc(s, ' '), 0);		     textout(screen, gui_fixed_font, s, x1, y1, fg);		     x1 += text_length(gui_fixed_font, s);		  }		  break;	       /* print a normal charater */	       default:		  if (printed != ignore) {		     usetc(s+usetc(s, ugetc(printed)), 0);		     textout(screen, gui_fixed_font, s, x1, y1, fg);		     x1 += text_length(gui_fixed_font, s);		  }	    }	    /* goto the next character */	    printed += uwidth(printed);	 }	 /* the last blank bit */	 if (x1 < x+w-1) 	    rectfill(screen, x1, y1, x+w-1, y1+text_height(gui_fixed_font)-1, deselect);	 /* print the line end */	 y1 += text_height(gui_fixed_font);      }      printed = scanned;      /* we have done a line */      line++;      /* check if we are at the end of the string */      if (!ugetc(printed)) {	 /* the under blank bit */	 if (draw) 	    rectfill(screen, x+1, y1, x+w-1, y+h-1, deselect);	 /* tell how many lines we found */	 *listsize = line;	 return;      }   }}int d_raine_textbox_proc(int msg, DIALOG *d, int c){   int height, bar, ret = D_O_K;   //int start, top, bottom,l;   //int used;   int fg_color = (d->flags & D_DISABLED) ? CGUI_BOX_COL_MIDDLE : translate_color(d->fg);   /* calculate the actual height */   height = (d->h-4) / text_height(gui_fixed_font);   switch (msg) {      case MSG_START:	 /* measure how many lines of text we contain */	 _draw_raine_textbox(d->dp, &d->d1, 		       0, /* DONT DRAW anything */		       d->d2, !(d->flags & D_SELECTED), 8,		       d->x, d->y, d->w, d->h,		       (d->flags & D_DISABLED),		       0, 0, 0);      break;      case MSG_DRAW:	 /* tell the object to sort of draw, but only calculate the listsize */	 _draw_raine_textbox(d->dp, &d->d1, 		       0, /* DONT DRAW anything */		       d->d2, !(d->flags & D_SELECTED), 8,		       d->x, d->y, d->w, d->h,		       (d->flags & D_DISABLED),		       0, 0, 0);	 if (d->d1 > height) {	    bar = 12;	 }	 else {	    bar = 0;	    d->d2 = 0;	 }	 /* now do the actual drawing */	 _draw_raine_textbox(d->dp, &d->d1, 1, d->d2,		       !(d->flags & D_SELECTED), 8,		       d->x, d->y, d->w-bar-1, d->h,		       (d->flags & D_DISABLED),		       fg_color, translate_color(d->bg), gui_mg_color);	 /* draw the frame around */	 _draw_raine_scrollable_frame(d, d->d1, d->d2, height, fg_color);      break;      default:         ret = d_textbox_proc(msg,d,c);      break;   }   return ret;}/* x_text_proc: *  Text proc, but with translation file support. */int x_text_proc(int msg, DIALOG *d, int c){   if (msg==MSG_DRAW) {      int fg = (d->flags & D_DISABLED) ? CGUI_BOX_COL_MIDDLE : translate_color(d->fg);      FONT *oldfont = font;      if (d->dp2)	 font = d->dp2;      text_mode(CGUI_BOX_COL_MIDDLE);      gui_textout(screen, raine_translate_text(d->dp), d->x, d->y, fg, FALSE);      font = oldfont;   }   return D_O_K;}/* x_ctext_proc: *  Simple dialog procedure: draws the text string which is pointed to by dp, *  centering it around the object's x coordinate. * Add translation of text and color for raine */int x_ctext_proc(int msg, DIALOG *d, int c){   if (msg==MSG_DRAW) {      int rtm;      int fg = (d->flags & D_DISABLED) ? gui_mg_color : translate_color(d->fg);      FONT *oldfont = font;      if (d->dp2)	 font = d->dp2;      rtm = text_mode(translate_color(d->bg));      gui_textout(screen, raine_translate_text(d->dp), d->x, d->y, fg, TRUE);      text_mode(rtm);      font = oldfont;   }   return D_O_K;}int d_progress_proc(int msg, DIALOG *d, int c){   if (msg==MSG_DRAW)   {      int i, bg, fg;      bg = CGUI_BOX_COL_LOW_2;      fg = CGUI_BOX_COL_HIGH_2;      if(!d->d2)         d->d2 = 100;      if(d->d1 > d->d2)         d->d1 = d->d2;      i = ((d->d1 * d->w) / d->d2);      if(i < d->w)         rectfill(screen, d->x + i, d->y, d->x + d->w - i, d->y + d->h, bg );      if(i > 0)         rectfill(screen, d->x, d->y, d->x + i, d->y + d->h, fg );   }   return D_O_K;}char *raine_translate_text(char *src){   char *result;   #if 0   char add_string[256];   for(ta=0;ta<=strlen(src);ta++){      if(src[ta]==' ')         add_string[ta]='_';      else         add_string[ta]=src[ta];   }   result = raine_get_config_text(src);   raine_set_config_string("incoming", add_string, result);   return result;   #else   result = raine_get_config_text(src);   return result;   #endif}

⌨️ 快捷键说明

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