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 12 of file button.qc.

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

References entity(), and SUPER.

◆ Button_draw()

void Button_draw ( entity me)

Definition at line 69 of file button.qc.

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)
86 draw_ButtonPicture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
87 else if (me.forcePressed || me.pressed || me.clickTime > 0)
88 draw_ButtonPicture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
89 else if (me.focused)
90 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
91 else if (me.pulse)
92 {
93 float alpha = min(1, 1 + sin(1.2*M_PI * time));
94 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1 - alpha);
95 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, alpha);
96 }
97 else
98 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
99 }
100 else
101 {
102 if (me.realFontSize_y == 0)
103 {
104 bOrigin = '0 0 0';
105 bSize = '1 1 0';
106 }
107 else
108 {
109 bOrigin = eY * (0.5 * (1 - me.realFontSize.y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize.x));
110 bSize = me.realFontSize;
111 }
112 if (me.disabled)
113 draw_Picture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
114 else if (me.forcePressed || me.pressed || me.clickTime > 0)
115 draw_Picture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
116 else if (me.focused)
117 draw_Picture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
118 else if (me.pulse)
119 {
120 float alpha = min(1, 1 + sin(1.2*M_PI * time));
121 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1 - alpha);
122 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, alpha);
123 }
124 else
125 draw_Picture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
126 }
127 }
128 if (me.src2)
129 {
130 bOrigin = me.keepspaceLeft * eX;
131 bSize = eY + eX * (1 - me.keepspaceLeft);
132
133 bOrigin += bSize * (0.5 - 0.5 * me.src2scale);
134 bSize = bSize * me.src2scale;
135
136 draw_Picture(bOrigin, me.src2, bSize, me.color2, me.alpha2);
137 }
138
139 draw_alpha = save;
140
141 if (me.clickTime > 0 && me.clickTime <= frametime)
142 {
143 // keyboard click timer expired? Fire the event then.
144 if (!me.disabled && me.onClick)
145 {
146 if(me.applyButton)
147 me.applyButton.disabled = false;
148 me.onClick(me, me.onClickEntity);
149 if(me.disableOnClick)
150 me.disabled = true;
151 }
152 }
153 me.clickTime -= frametime;
154
155 SUPER(Button).draw(me);
156 }
float alpha
Definition items.qc:13
float frametime
float time
#define M_PI
Definition mathlib.qh:108
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:92
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

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 17 of file button.qc.

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 }
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 30 of file button.qc.

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 }

References entity(), and vector.

◆ Button_mouseRelease()

float Button_mouseRelease ( entity me,
vector pos )

Definition at line 44 of file button.qc.

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 }

References entity(), and vector.

◆ Button_playClickSound()

void Button_playClickSound ( entity me)

Definition at line 158 of file button.qc.

159 {
161 else if (me.onClick == Dialog_Close) m_play_click_sound(MENU_SOUND_CLOSE);
163 }
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
void m_play_click_sound(string soundfile)
Definition menu.qc:1106
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) 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 }

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

◆ Button_showNotify()

void Button_showNotify ( entity me)

Definition at line 65 of file button.qc.

66 {
67 me.focusable = !me.disabled;
68 }

References entity().

◆ Dialog_Close()