misc_gui.c
branch0.4
changeset 9983 f04c5d60e63f
parent 9959 984493ab6fff
child 10009 5c196c78e0b9
equal deleted inserted replaced
9982:6f21b86be9af 9983:f04c5d60e63f
   806 	tb->length = tb->width = 0;
   806 	tb->length = tb->width = 0;
   807 	tb->caretpos = tb->caretxoffs = 0;
   807 	tb->caretpos = tb->caretxoffs = 0;
   808 }
   808 }
   809 
   809 
   810 /**
   810 /**
   811  * Insert a character to a textbuffer. If maxlength is zero, we don't care about
   811  * Insert a character to a textbuffer. If maxlength of the Textbuf is zero,
   812  * the screenlength but only about the physical length of the string
   812  * we don't care about the screenlength but only about the physical
       
   813  * length of the string
   813  * @param tb @Textbuf type to be changed
   814  * @param tb @Textbuf type to be changed
   814  * @param key Character to be inserted
   815  * @param key Character to be inserted
   815  * @return Return true on successfull change of Textbuf, or false otherwise
   816  * @return Return true on successfull change of Textbuf, or false otherwise
   816  */
   817  */
   817 bool InsertTextBufferChar(Textbuf *tb, byte key)
   818 bool InsertTextBufferChar(Textbuf *tb, byte key)
   818 {
   819 {
   819 	const byte charwidth = GetCharacterWidth(key);
   820 	const byte charwidth = GetCharacterWidth(key);
   820 	if (tb->length < tb->maxlength && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
   821 	if (tb->length < (tb->maxlength - 1) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) {
   821 		memmove(tb->buf + tb->caretpos + 1, tb->buf + tb->caretpos, (tb->length - tb->caretpos) + 1);
   822 		memmove(tb->buf + tb->caretpos + 1, tb->buf + tb->caretpos, (tb->length - tb->caretpos) + 1);
   822 		tb->buf[tb->caretpos] = key;
   823 		tb->buf[tb->caretpos] = key;
   823 		tb->length++;
   824 		tb->length++;
   824 		tb->width += charwidth;
   825 		tb->width += charwidth;
   825 
   826 
   873  * Useful when copying in a larger amount of text at once
   874  * Useful when copying in a larger amount of text at once
   874  * @param tb @Textbuf type which length is calculated
   875  * @param tb @Textbuf type which length is calculated
   875  */
   876  */
   876 void UpdateTextBufferSize(Textbuf *tb)
   877 void UpdateTextBufferSize(Textbuf *tb)
   877 {
   878 {
   878 	const char* buf;
   879 	const char *buf;
   879 
   880 
   880 	tb->length = 0;
   881 	tb->length = 0;
   881 	tb->width = 0;
   882 	tb->width = 0;
   882 
   883 
   883 	for (buf = tb->buf; *buf != '\0' && tb->length <= tb->maxlength; buf++) {
   884 	for (buf = tb->buf; *buf != '\0' && tb->length < (tb->maxlength - 1); buf++) {
   884 		tb->length++;
   885 		tb->length++;
   885 		tb->width += GetCharacterWidth((byte)*buf);
   886 		tb->width += GetCharacterWidth((byte)*buf);
   886 	}
   887 	}
   887 
   888 
   888 	tb->caretpos = tb->length;
   889 	tb->caretpos = tb->length;
  1076 	w->click_state = 1 << 5;
  1077 	w->click_state = 1 << 5;
  1077 	WP(w, querystr_d).caption = caption;
  1078 	WP(w, querystr_d).caption = caption;
  1078 	WP(w, querystr_d).wnd_class = window_class;
  1079 	WP(w, querystr_d).wnd_class = window_class;
  1079 	WP(w, querystr_d).wnd_num = window_number;
  1080 	WP(w, querystr_d).wnd_num = window_number;
  1080 	WP(w, querystr_d).text.caret = false;
  1081 	WP(w, querystr_d).text.caret = false;
  1081 	WP(w, querystr_d).text.maxlength = realmaxlen - 1;
  1082 	WP(w, querystr_d).text.maxlength = realmaxlen;
  1082 	WP(w, querystr_d).text.maxwidth = maxwidth;
  1083 	WP(w, querystr_d).text.maxwidth = maxwidth;
  1083 	WP(w, querystr_d).text.buf = _edit_str_buf;
  1084 	WP(w, querystr_d).text.buf = _edit_str_buf;
  1084 	UpdateTextBufferSize(&WP(w, querystr_d).text);
  1085 	UpdateTextBufferSize(&WP(w, querystr_d).text);
  1085 }
  1086 }
  1086 
  1087 
  1461 	w->resize.step_width = 2;
  1462 	w->resize.step_width = 2;
  1462 	w->resize.step_height = 10;
  1463 	w->resize.step_height = 10;
  1463 	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
  1464 	w->resize.height = w->height - 14 * 10; // Minimum of 10 items
  1464 	SETBIT(w->click_state, 7);
  1465 	SETBIT(w->click_state, 7);
  1465 	WP(w,querystr_d).text.caret = false;
  1466 	WP(w,querystr_d).text.caret = false;
  1466 	WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf) - 1;
  1467 	WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf);
  1467 	WP(w,querystr_d).text.maxwidth = 240;
  1468 	WP(w,querystr_d).text.maxwidth = 240;
  1468 	WP(w,querystr_d).text.buf = _edit_str_buf;
  1469 	WP(w,querystr_d).text.buf = _edit_str_buf;
  1469 	UpdateTextBufferSize(&WP(w, querystr_d).text);
  1470 	UpdateTextBufferSize(&WP(w, querystr_d).text);
  1470 
  1471 
  1471 	// pause is only used in single-player, non-editor mode, non-menu mode. It
  1472 	// pause is only used in single-player, non-editor mode, non-menu mode. It