Xonotic
button.qc
Go to the documentation of this file.
1 #include "button.qh"
2 
3  void Button_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
4  {
5  if (me.srcMulti) me.keepspaceLeft = 0;
6  else me.keepspaceLeft = min(0.8, absSize.x == 0 ? 0 : (absSize.y / absSize.x));
7  SUPER(Button).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
8 
9  if(me.disableOnClick)
10  me.disabled = true; // initially disabled
11  }
12  void Button_configureButton(entity me, string txt, float sz, string gfx)
13  {
14  SUPER(Button).configureLabel(me, txt, sz, me.srcMulti ? 0.5 : 0);
15  me.src = gfx;
16  }
17  float Button_keyDown(entity me, float key, float ascii, float shift)
18  {
19  if (key == K_ENTER || key == K_SPACE || key == K_KP_ENTER)
20  {
21  if(!me.disabled)
22  {
23  me.playClickSound(me);
24  me.clickTime = 0.1; // delayed for effect
25  }
26  return 1;
27  }
28  return 0;
29  }
31  {
32  me.pressed = 1;
33  if (pos.x < 0) me.pressed = 0;
34  if (pos.y < 0) me.pressed = 0;
35  if (pos.x >= 1) me.pressed = 0;
36  if (pos.y >= 1) me.pressed = 0;
37  return 1;
38  }
39  METHOD(Button, mousePress, bool(Button this, vector pos))
40  {
41  this.mouseDrag(this, pos); // verify coordinates
42  return true;
43  }
45  {
46  me.mouseDrag(me, pos); // verify coordinates
47  if (me.pressed)
48  {
49  if (!me.disabled)
50  {
51  me.playClickSound(me);
52  if (me.onClick)
53  {
54  if(me.applyButton)
55  me.applyButton.disabled = false;
56  me.onClick(me, me.onClickEntity);
57  if(me.disableOnClick)
58  me.disabled = true;
59  }
60  }
61  me.pressed = 0;
62  }
63  return 1;
64  }
66  {
67  me.focusable = !me.disabled;
68  }
70  {
71  vector bOrigin, bSize;
72  float save;
73 
74  me.focusable = !me.disabled;
75 
76  save = draw_alpha;
77  if (me.disabled) draw_alpha *= me.disabledAlpha;
78 
79  if (me.src)
80  {
81  if (me.srcMulti)
82  {
83  bOrigin = '0 0 0';
84  bSize = '1 1 0';
85  if (me.disabled) draw_ButtonPicture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
86  else if (me.forcePressed || me.pressed || me.clickTime > 0) draw_ButtonPicture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
87  else if (me.focused) draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
88  else draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
89  }
90  else
91  {
92  if (me.realFontSize_y == 0)
93  {
94  bOrigin = '0 0 0';
95  bSize = '1 1 0';
96  }
97  else
98  {
99  bOrigin = eY * (0.5 * (1 - me.realFontSize.y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize.x));
100  bSize = me.realFontSize;
101  }
102  if (me.disabled) draw_Picture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
103  else if (me.forcePressed || me.pressed || me.clickTime > 0) draw_Picture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
104  else if (me.focused) draw_Picture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
105  else draw_Picture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
106  }
107  }
108  if (me.src2)
109  {
110  bOrigin = me.keepspaceLeft * eX;
111  bSize = eY + eX * (1 - me.keepspaceLeft);
112 
113  bOrigin += bSize * (0.5 - 0.5 * me.src2scale);
114  bSize = bSize * me.src2scale;
115 
116  draw_Picture(bOrigin, me.src2, bSize, me.color2, me.alpha2);
117  }
118 
119  draw_alpha = save;
120 
121  if (me.clickTime > 0 && me.clickTime <= frametime)
122  {
123  // keyboard click timer expired? Fire the event then.
124  if (!me.disabled && me.onClick)
125  {
126  if(me.applyButton)
127  me.applyButton.disabled = false;
128  me.onClick(me, me.onClickEntity);
129  if(me.disableOnClick)
130  me.disabled = true;
131  }
132  }
133  me.clickTime -= frametime;
134 
135  SUPER(Button).draw(me);
136  }
137  void Dialog_Close(entity button, entity me);
139  {
141  else if (me.onClick == Dialog_Close) m_play_click_sound(MENU_SOUND_CLOSE);
143  }
const vector eY
Definition: vector.qh:45
entity() spawn
Definition: button.qh:6
void DialogOpenButton_Click(entity button, entity tab)
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
float K_SPACE
Definition: keycodes.qc:10
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float frametime
Definition: csprogsdefs.qc:17
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector eX
Definition: vector.qh:44
float K_ENTER
Definition: keycodes.qc:8