Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
button.qc File Reference
#include "button.qh"
Include dependency graph for button.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Button_configureButton (entity me, string txt, float sz, string gfx)
void Button_draw (entity me)
float Button_keyDown (entity me, float key, float ascii, float shift)
float Button_mouseDrag (entity me, vector pos)
float Button_mouseRelease (entity me, vector pos)
void Button_playClickSound (entity me)
void Button_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void Button_showNotify (entity me)
void Dialog_Close (entity button, entity me)

Function Documentation

◆ Button_configureButton()

void Button_configureButton ( entity me,
string txt,
float sz,
string gfx )

Definition at line 14 of file button.qc.

15 {
16 SUPER(Button).configureLabel(me, txt, sz, me.srcMulti ? 0.5 : 0);
17 me.src = gfx;
18 }
#define SUPER(cname)
Definition oo.qh:236

References entity(), and SUPER.

◆ Button_draw()

void Button_draw ( entity me)

Definition at line 67 of file button.qc.

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 }
float alpha
Definition items.qc:13
float frametime
float time
#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 sin(float f)
float min(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
vector
Definition self.qh:96
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43

References alpha, draw_alpha, draw_ButtonPicture(), draw_Picture(), entity(), eX, eY, frametime, M_PI, min(), sin(), strcat(), SUPER, time, and vector.

◆ Button_keyDown()

float Button_keyDown ( entity me,
float key,
float ascii,
float shift )

Definition at line 19 of file button.qc.

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 }
float K_SPACE
Definition keycodes.qc:10
float K_ENTER
Definition keycodes.qc:8
float K_KP_ENTER
Definition keycodes.qc:74

References entity(), K_ENTER, K_KP_ENTER, and K_SPACE.

◆ Button_mouseDrag()

float Button_mouseDrag ( entity me,
vector pos )

Definition at line 32 of file button.qc.

33 {
34 me.pressed = (pos.x < 0 || pos.y < 0 || pos.x >= 1 || pos.y >= 1) ? 0 : 1;
35 return 1;
36 }

References entity(), and vector.

◆ Button_mouseRelease()

float Button_mouseRelease ( entity me,
vector pos )

Definition at line 42 of file button.qc.

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 }

References entity(), and vector.

◆ Button_playClickSound()

void Button_playClickSound ( entity me)

Definition at line 156 of file button.qc.

157 {
158 if (me.onClick == DialogOpenButton_Click)
160 else if (me.onClick == Dialog_Close)
162 else
164 }
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
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
void DialogOpenButton_Click(entity button, entity tab)

References Dialog_Close(), DialogOpenButton_Click(), entity(), m_play_click_sound(), MENU_SOUND_CLOSE, MENU_SOUND_EXECUTE, and MENU_SOUND_OPEN.

◆ Button_resizeNotify()

void Button_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 3 of file button.qc.

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 }

References entity(), min(), SUPER, and vector.

◆ Button_showNotify()

void Button_showNotify ( entity me)

Definition at line 63 of file button.qc.

64 {
65 me.focusable = !me.disabled;
66 }

References entity().

◆ Dialog_Close()