No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

71 líneas
1.8KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * GUI text boxes.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_player.h"
  15. #include "w_world.h"
  16. #include "m_cps.h"
  17. #include "m_char.h"
  18. struct gui_txt *G_TxtBox_Imp(struct gui_state *g, u32 id, struct gui_arg_txt const *a) {
  19. struct gui_txt *st = a->st;
  20. G_Auto(g, id, a->x, a->y, 260, 10);
  21. bool hot = g->hot == id;
  22. if(hot) a->p->grabInput = true;
  23. if(*a->p->txtbuf) ACS_LocalAmbientSound(ss_player_cbi_keypress, 30);
  24. for(char *c = a->p->txtbuf; *c; c++)
  25. {
  26. switch(*c)
  27. {
  28. case '\b':
  29. if(st->tbptr - 1 >= 0)
  30. st->tbptr--;
  31. break;
  32. case '\r':
  33. *c = '\n';
  34. default:
  35. if(st->tbptr + 1 < Cps_CountOf(st->txtbuf) && (IsPrint(*c) || IsSpace(*c)))
  36. {
  37. Cps_SetC(st->txtbuf, st->tbptr, *c);
  38. st->tbptr++;
  39. }
  40. break;
  41. }
  42. }
  43. Cps_SetC(st->txtbuf, st->tbptr, '\0');
  44. PrintSprite(sp_UI_TextBoxBack, a->x-3 + g->ox,1, a->y-3 + g->oy,1);
  45. SetClipW(a->x + g->ox, a->y + g->oy, 260, 200, 260);
  46. if(st->tbptr)
  47. PrintTextFmt("%s%s", Cps_Expand(st->txtbuf, 0, st->tbptr),
  48. hot ? Ticker("|", "") : "");
  49. else
  50. PrintTextFmt("\C%c%s", hot ? 'c' : 'm', LC(LANG "GUI_TEXTBOX"));
  51. PrintText(s_smallfnt, g->defcr, a->x + g->ox,1, a->y + g->oy,1);
  52. ClearClip();
  53. fastmemset(a->p->txtbuf, 0, sizeof a->p->txtbuf);
  54. a->p->tbptr = 0;
  55. return st;
  56. }
  57. /* EOF */