Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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)
6 me.keepspaceLeft = 0;
7 else
8 me.keepspaceLeft = min(0.8, absSize.x == 0 ? 0 : (absSize.y / absSize.x));
9 SUPER(Button).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
10
11 if(me.disableOnClick)
12 me.disabled = true; // initially disabled
13 }
14 void Button_configureButton(entity me, string txt, float sz, string gfx)
15 {
16 SUPER(Button).configureLabel(me, txt, sz, me.srcMulti ? 0.5 : 0);
17 me.src = gfx;
18 }
19 float Button_keyDown(entity me, float key, float ascii, float shift)
20 {
21 if (key == K_ENTER || key == K_SPACE || key == K_KP_ENTER)
22 {
23 if (!me.disabled)
24 {
25 me.playClickSound(me);
26 me.clickTime = 0.1; // delayed for effect
27 }
28 return 1;
29 }
30 return 0;
31 }
33 {
34 me.pressed = (pos.x < 0 || pos.y < 0 || pos.x >= 1 || pos.y >= 1) ? 0 : 1;
35 return 1;
36 }
38 {
39 this.mouseDrag(this, pos); // verify coordinates
40 return true;
41 }
43 {
44 me.mouseDrag(me, pos); // verify coordinates
45 if (me.pressed)
46 {
47 if (!me.disabled)
48 {
49 me.playClickSound(me);
50 if (me.onClick)
51 {
52 if (me.applyButton)
53 me.applyButton.disabled = false;
54 me.onClick(me, me.onClickEntity);
55 if (me.disableOnClick)
56 me.disabled = true;
57 }
58 }
59 me.pressed = 0;
60 }
61 return 1;
62 }
64 {
65 me.focusable = !me.disabled;
66 }
68 {
69 vector bOrigin, bSize;
70 float save;
71
72 me.focusable = !me.disabled;
73
74 save = draw_alpha;
75 if (me.disabled) draw_alpha *= me.disabledAlpha;
76
77 if (me.src)
78 {
79 if (me.srcMulti)
80 {
81 bOrigin = '0 0 0';
82 bSize = '1 1 0';
83 if (me.disabled)
84 draw_ButtonPicture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
85 else if (me.forcePressed || me.pressed || me.clickTime > 0)
86 draw_ButtonPicture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
87 else if (me.focused)
88 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
89 else if (me.pulse)
90 {
91 float alpha = min(1, 1 + sin(1.2*M_PI * time));
92 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1 - alpha);
93 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, alpha);
94 }
95 else
96 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
97 }
98 else
99 {
100 if (me.realFontSize.y == 0)
101 {
102 bOrigin = '0 0 0';
103 bSize = '1 1 0';
104 }
105 else
106 {
107 bOrigin = eY * (0.5 * (1 - me.realFontSize.y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize.x));
108 bSize = me.realFontSize;
109 }
110 if (me.disabled)
111 draw_Picture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
112 else if (me.forcePressed || me.pressed || me.clickTime > 0)
113 draw_Picture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
114 else if (me.focused)
115 draw_Picture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
116 else if (me.pulse)
117 {
118 float alpha = min(1, 1 + sin(1.2*M_PI * time));
119 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1 - alpha);
120 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, alpha);
121 }
122 else
123 draw_Picture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
124 }
125 }
126 if (me.src2)
127 {
128 bOrigin = me.keepspaceLeft * eX;
129 bSize = eY + eX * (1 - me.keepspaceLeft);
130
131 bOrigin += bSize * (0.5 - 0.5 * me.src2scale);
132 bSize *= me.src2scale;
133
134 draw_Picture(bOrigin, me.src2, bSize, me.color2, me.alpha2);
135 }
136
137 draw_alpha = save;
138
139 if (me.clickTime > 0 && me.clickTime <= frametime)
140 {
141 // keyboard click timer expired? Fire the event then.
142 if (!me.disabled && me.onClick)
143 {
144 if (me.applyButton)
145 me.applyButton.disabled = false;
146 me.onClick(me, me.onClickEntity);
147 if (me.disableOnClick)
148 me.disabled = true;
149 }
150 }
151 me.clickTime -= frametime;
152
153 SUPER(Button).draw(me);
154 }
155 void Dialog_Close(entity button, entity me);
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void mousePress()
Definition button.qc:37
virtual void mouseDrag()
float alpha
Definition items.qc:13
float frametime
float time
float K_SPACE
Definition keycodes.qc:10
float K_ENTER
Definition keycodes.qc:8
float K_KP_ENTER
Definition keycodes.qc:74
#define M_PI
pi
Definition mathlib.qh:114
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
void draw_ButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:108
float draw_alpha
Definition draw.qh:9
float Button_mouseRelease(entity me, vector pos)
Definition button.qc:42
float Button_mouseDrag(entity me, vector pos)
Definition button.qc:32
float Button_keyDown(entity me, float key, float ascii, float shift)
Definition button.qc:19
void Button_draw(entity me)
Definition button.qc:67
void Button_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition button.qc:3
void Button_configureButton(entity me, string txt, float sz, string gfx)
Definition button.qc:14
void Button_playClickSound(entity me)
Definition button.qc:156
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
void Button_showNotify(entity me)
Definition button.qc:63
void m_play_click_sound(string soundfile)
Definition menu.qc:1111
const string MENU_SOUND_CLOSE
Definition menu.qh:50
const string MENU_SOUND_OPEN
Definition menu.qh:53
const string MENU_SOUND_EXECUTE
Definition menu.qh:51
float sin(float f)
float min(float f,...)
void DialogOpenButton_Click(entity button, entity tab)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define SUPER(cname)
Definition oo.qh:236
#define METHOD(cname, name, prototype)
Definition oo.qh:274
vector
Definition self.qh:96
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43