You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.6KB

  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 buttons.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_player.h"
  15. bool G_Button_Imp(struct gui_state *g, u32 id, struct gui_arg_btn const *a) {
  16. struct gui_pre_btn const *pre = a->preset ? a->preset : &gui_p.btndef;
  17. if(!a->disabled)
  18. G_Auto(g, id, a->x, a->y, pre->w, pre->h, a->slide);
  19. __with(char graphic[30];) {
  20. if(g->hot == id && pre->hot) G_Prefix(g, graphic, pre, hot);
  21. else G_Prefix(g, graphic, pre, gfx);
  22. if(graphic[0]) PrintSprite(l_strdup(graphic), a->x + g->ox,1, a->y + g->oy,1);
  23. }
  24. if(a->label && pre->font) {
  25. i32 x, y;
  26. cstr color;
  27. if(pre->ax == 4 || !pre->ax) x = (pre->w / 2) + a->x + g->ox;
  28. else x = a->x + g->ox;
  29. if(pre->ay == 4 || !pre->ay) y = (pre->h / 2) + a->y + g->oy;
  30. else y = a->y + g->oy;
  31. if(a->disabled) color = pre->cdis;
  32. else if(g->active == id) color = pre->cact;
  33. else if(g->hot == id) color = pre->chot;
  34. else if(a->color) color = a->color;
  35. else color = pre->cdef;
  36. if(!color) color = "-";
  37. PrintTextFmt("\C%s%s", color, a->label);
  38. PrintText(pre->font, g->defcr, x,pre->ax, y,pre->ay);
  39. }
  40. if(!a->disabled) {
  41. bool click;
  42. if(a->fill.ptr && a->fill.tic) {
  43. if(g->hot == id && g->active == id) {
  44. click =
  45. G_Filler(g->cx + 8, g->cy, a->fill.ptr, a->fill.tic, click);
  46. } else {
  47. if(g->active != id) {
  48. *a->fill.ptr = 0;
  49. }
  50. click = false;
  51. }
  52. } else if(g->slide == id) {
  53. click = g->clicklft && !g->old.clicklft;
  54. if(g->slidecount < 2) click = click || g->slidetime % 20 == 0;
  55. else if(g->slidecount < 10) click = click || g->slidetime % 5 == 0;
  56. else click = true;
  57. } else {
  58. click = !g->clicklft;
  59. }
  60. click = g->hot == id && g->active == id && click;
  61. if(click) {
  62. if(g->slide == id) g->slidecount++;
  63. if(pre->snd) ACS_LocalAmbientSound(pre->snd, 127);
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. /* EOF */