您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

92 行
2.3KB

  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 sliders.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_player.h"
  15. k64 G_Slider_Imp(struct gui_state *g, u32 id, struct gui_arg_sld const *a) {
  16. struct gui_pre_sld const *pre = a->preset ? a->preset : &gui_p.slddef;
  17. k64 w = pre->w - (pre->pad * 2);
  18. i32 x = a->x + pre->pad;
  19. i32 y = a->y;
  20. G_Auto(g, id, x, y, w, pre->h);
  21. x += g->ox;
  22. y += g->oy;
  23. /* get a normalized value */
  24. k64 aval;
  25. aval = (a->val - a->minima) / (a->maxima - a->minima);
  26. aval = minmax(aval, 0, 1);
  27. k64 val;
  28. /* move scroll notch */
  29. if(g->active == id)
  30. {
  31. val = g->cx - x;
  32. val = minmax(val, 0, w);
  33. val /= w;
  34. /* play sound */
  35. if(pre->snd && g->cx != g->old.cx && g->cx >= x && g->cx < x + w)
  36. ACS_LocalAmbientSound(pre->snd, 60);
  37. }
  38. else
  39. val = aval;
  40. /* get result-normalized value */
  41. k64 norm = val * (a->maxima - a->minima) + a->minima;
  42. if(a->integ) norm = roundlk(norm, 10);
  43. /* draw graphic */
  44. __with(char gfx[64];)
  45. {
  46. G_Prefix(g, gfx, pre, gfx);
  47. if(gfx[0]) PrintSprite(l_strdup(gfx), x - pre->pad,1, y + pre->h / 2,0);
  48. }
  49. /* draw notch */
  50. __with(char gfx[64];)
  51. {
  52. if(g->hot == id || g->active == id) G_Prefix(g, gfx, pre, notchhot);
  53. else G_Prefix(g, gfx, pre, notch);
  54. if(gfx[0]) PrintSprite(l_strdup(gfx), x + val * w - 1,1, y,1);
  55. }
  56. /* draw value */
  57. if(pre->font)
  58. {
  59. cstr suf = a->suf ? a->suf : "";
  60. k64 amt = roundlk(norm * 100.0lk, 10) / 100.0lk;
  61. if(a->integ) PrintTextFmt("%i%s", (i32)amt, suf);
  62. else PrintTextFmt("%.1k%s", (k32)amt, suf);
  63. PrintText(pre->font, g->defcr, x + pre->w/2,4, y + pre->h/2,0);
  64. }
  65. /* if we've moved it, we return a difference */
  66. if(g->active == id && !g->clicklft && !CloseEnough(aval, val))
  67. return norm - a->val;
  68. else
  69. return 0;
  70. }
  71. /* EOF */