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

Go to the source code of this file.

Functions

void DialogCloseButton_Click (entity button, entity tab)
void DialogOpenButton_Click (entity button, entity tab)
void DialogOpenButton_Click_withCoords (entity button, entity tab, vector theOrigin, vector theSize)
void ModalController_addItem (entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
void ModalController_addTab (entity me, entity other, entity tabButton)
void ModalController_draw (entity me)
void ModalController_hideAll (entity me, float skipAnimation)
void ModalController_hideChild (entity me, entity other, float skipAnimation)
void ModalController_initializeDialog (entity me, entity root)
void ModalController_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void ModalController_showChild (entity me, entity other, vector theOrigin, vector theSize, float skipAnimation)
void ModalController_switchState (entity me, entity other, float state, float skipAnimation)
void TabButton_Click (entity button, entity tab)

Variables

vector ModalController_buttonOrigin
vector ModalController_buttonSize
entity ModalController_controllingButton
float ModalController_factor
float ModalController_initialAlpha
vector ModalController_initialFontScale
vector ModalController_initialOrigin
vector ModalController_initialSize
float ModalController_state

Function Documentation

◆ DialogCloseButton_Click()

void DialogCloseButton_Click ( entity button,
entity tab )

Definition at line 44 of file modalcontroller.qc.

45 {
46 tab.parent.hideChild(tab.parent, tab, 0);
47 }

References entity().

Referenced by Dialog_close().

◆ DialogOpenButton_Click()

void DialogOpenButton_Click ( entity button,
entity tab )

◆ DialogOpenButton_Click_withCoords()

void DialogOpenButton_Click_withCoords ( entity button,
entity tab,
vector theOrigin,
vector theSize )

Definition at line 35 of file modalcontroller.qc.

36 {
37 if (tab.ModalController_state) return;
38 if (button) button.forcePressed = true;
39 if (tab.parent.focusedChild) tab.parent.focusedChild.saveFocus(tab.parent.focusedChild);
40 tab.ModalController_controllingButton = button;
41 tab.parent.showChild(tab.parent, tab, theOrigin, theSize, 0);
42 }

References entity(), and vector.

Referenced by DemoConfirm_ListClick_Check_Gamestatus(), DialogOpenButton_Click(), MainWindow_draw(), preMenuDraw(), ServerList_Info_Click(), XonoticMapList_doubleClickListBoxItem(), XonoticMapList_keyDown(), XonoticScreenshotList_startScreenshot(), and XonoticServerList_keyDown().

◆ ModalController_addItem()

void ModalController_addItem ( entity me,
entity other,
vector theOrigin,
vector theSize,
float theAlpha )

Definition at line 194 of file modalcontroller.qc.

195 {
196 SUPER(ModalController).addItem(me, other, theOrigin, theSize, (other == me.firstChild) ? theAlpha : 0);
197 other.ModalController_initialFontScale = other.Container_fontscale;
198 other.ModalController_initialSize = other.Container_size;
199 other.ModalController_initialOrigin = other.Container_origin;
200 other.ModalController_initialAlpha = theAlpha; // hope Container never modifies this
201 if (other.ModalController_initialFontScale == '0 0 0') other.ModalController_initialFontScale = '1 1 0';
202 }
entity other
#define SUPER(cname)
Definition oo.qh:231

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

◆ ModalController_addTab()

void ModalController_addTab ( entity me,
entity other,
entity tabButton )

Definition at line 180 of file modalcontroller.qc.

181 {
182 me.addItem(me, other, '0 0 0', '1 1 1', 1);
183 tabButton.onClick = TabButton_Click;
184 tabButton.onClickEntity = other;
185 other.tabSelectingButton = tabButton;
186 if (other == me.firstChild)
187 {
188 tabButton.forcePressed = true;
189 other.ModalController_controllingButton = tabButton;
190 me.showChild(me, other, '0 0 0', '0 0 0', 1);
191 }
192 }
void TabButton_Click(entity button, entity tab)

References entity(), other, and TabButton_Click().

◆ ModalController_draw()

void ModalController_draw ( entity me)

Definition at line 82 of file modalcontroller.qc.

83 {
84 entity e;
85 entity front;
86 float animating;
87 float f; // animation factor
88 float df; // animation step size
89 float prevFactor, targetFactor;
90 vector targetOrigin, targetSize;
91 float targetAlpha;
92 vector fs;
93 animating = 0;
94
95 front = NULL;
96 for (e = me.firstChild; e; e = e.nextSibling)
97 if (e.ModalController_state)
98 {
99 if (front) me.switchState(me, front, 2, 0);
100 front = e;
101 }
102 if (front) me.switchState(me, front, 1, 0);
103
104 df = frametime * 3; // animation speed
105
106 for (e = me.firstChild; e; e = e.nextSibling)
107 {
108 if (e.ModalController_state == 2)
109 {
110 // fading out partially
111 targetOrigin = e.Container_origin; // stay as is
112 targetSize = e.Container_size; // stay as is
113 targetAlpha = me.fadedAlpha * e.ModalController_initialAlpha;
114 }
115 else if (e.ModalController_state == 1)
116 {
117 // zooming in
118 targetOrigin = e.ModalController_initialOrigin;
119 targetSize = e.ModalController_initialSize;
120 targetAlpha = e.ModalController_initialAlpha;
121 }
122 else
123 {
124 // fading out
125 targetOrigin = e.Container_origin; // stay as is
126 targetSize = e.Container_size; // stay as is
127 targetAlpha = 0;
128 }
129
130 f = (e.ModalController_factor = min(1, e.ModalController_factor + df));
131 if (f == 1)
132 {
133 prevFactor = 0;
134 targetFactor = 1;
135 e.Container_origin = targetOrigin;
136 e.Container_size = targetSize;
137 me.setAlphaOf(me, e, targetAlpha);
138 }
139 else
140 {
141 prevFactor = (1 - f) / (1 - f + df);
142 if (!e.ModalController_state) // optimize code and avoid precision errors
143 {
144 me.setAlphaOf(me, e, e.Container_alpha * prevFactor);
145 }
146 else
147 {
148 animating = 1;
149 targetFactor = df / (1 - f + df);
150
151 if (e.ModalController_state == 1)
152 {
153 e.Container_origin = e.Container_origin * prevFactor + targetOrigin * targetFactor;
154 e.Container_size = e.Container_size * prevFactor + targetSize * targetFactor;
155 }
156 me.setAlphaOf(me, e, e.Container_alpha * prevFactor + targetAlpha * targetFactor);
157 }
158 }
159 // assume: o == to * f_prev + X * (1 - f_prev)
160 // make: o' = to * f + X * (1 - f)
161 // -->
162 // X == (o - to * f_prev) / (1 - f_prev)
163 // o' = to * f + (o - to * f_prev) / (1 - f_prev) * (1 - f)
164 // --> (maxima)
165 // o' = (to * (f - f_prev) + o * (1 - f)) / (1 - f_prev)
166
167 if (e.ModalController_state == 1)
168 {
169 fs = globalToBoxSize(e.Container_size, e.ModalController_initialSize);
170 e.Container_fontscale_x = fs.x * e.ModalController_initialFontScale.x;
171 e.Container_fontscale_y = fs.y * e.ModalController_initialFontScale.y;
172 }
173 }
174
175 if (animating || !me.focused) me.setFocus(me, NULL);
176 else me.setFocus(me, front);
177 SUPER(ModalController).draw(me);
178 }
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float frametime
vector globalToBoxSize(vector v, vector theScale)
Definition draw.qc:38
float min(float f,...)
#define NULL
Definition post.qh:14
vector
Definition self.qh:92

References entity(), frametime, globalToBoxSize(), min(), NULL, SUPER, and vector.

◆ ModalController_hideAll()

void ModalController_hideAll ( entity me,
float skipAnimation )

Definition at line 218 of file modalcontroller.qc.

219 {
220 entity e;
221 for (e = me.firstChild; e; e = e.nextSibling)
222 me.hideChild(me, e, skipAnimation);
223 }

References entity().

◆ ModalController_hideChild()

void ModalController_hideChild ( entity me,
entity other,
float skipAnimation )

Definition at line 225 of file modalcontroller.qc.

226 {
227 if (other.ModalController_state || skipAnimation)
228 {
229 me.setFocus(me, NULL);
230 me.switchState(me, other, 0, skipAnimation);
231 if (other.ModalController_controllingButton)
232 {
233 other.ModalController_controllingButton.forcePressed = false;
234 other.ModalController_controllingButton = NULL;
235 }
236 } // just alpha fade out (factor increases and decreases alpha)
237 }

References entity(), NULL, and other.

◆ ModalController_initializeDialog()

void ModalController_initializeDialog ( entity me,
entity root )

Definition at line 15 of file modalcontroller.qc.

16 {
17 me.hideAll(me, 1);
18 me.showChild(me, root, '0 0 0', '0 0 0', 1); // someone else animates for us
19 }

References entity().

◆ ModalController_resizeNotify()

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

Definition at line 49 of file modalcontroller.qc.

50 {
51 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, ModalController_initialOrigin, ModalController_initialSize, ModalController_initialFontScale);
52 }
vector ModalController_initialFontScale
vector ModalController_initialOrigin
vector ModalController_initialSize

References entity(), ModalController_initialFontScale, ModalController_initialOrigin, ModalController_initialSize, and vector.

◆ ModalController_showChild()

void ModalController_showChild ( entity me,
entity other,
vector theOrigin,
vector theSize,
float skipAnimation )

Definition at line 204 of file modalcontroller.qc.

205 {
206 if (other.ModalController_state == 0 || skipAnimation)
207 {
208 me.setFocus(me, NULL);
209 if (!skipAnimation)
210 {
211 other.ModalController_buttonOrigin = globalToBox(theOrigin, me.origin, me.size);
212 other.ModalController_buttonSize = globalToBoxSize(theSize, me.size);
213 }
214 me.switchState(me, other, 1, skipAnimation);
215 } // zoom in from button (factor increases)
216 }
vector globalToBox(vector v, vector theOrigin, vector theScale)
Definition draw.qc:30

References entity(), globalToBox(), globalToBoxSize(), NULL, other, and vector.

◆ ModalController_switchState()

void ModalController_switchState ( entity me,
entity other,
float state,
float skipAnimation )

Definition at line 54 of file modalcontroller.qc.

55 {
56 float previousState = other.ModalController_state;
57 if (state == previousState && !skipAnimation) return;
58 other.ModalController_state = state;
59 switch (state)
60 {
61 case 0:
62 other.ModalController_factor = 1 - other.Container_alpha / other.ModalController_initialAlpha;
63 // fading out
64 break;
65 case 1:
66 other.ModalController_factor = other.Container_alpha / other.ModalController_initialAlpha;
67 if (previousState == 0 && !skipAnimation)
68 {
69 other.Container_origin = other.ModalController_buttonOrigin;
70 other.Container_size = other.ModalController_buttonSize;
71 }
72 // zooming in
73 break;
74 case 2:
75 other.ModalController_factor = bound(0, (1 - other.Container_alpha / other.ModalController_initialAlpha) / me.fadedAlpha, 1);
76 // fading out halfway
77 break;
78 }
79 if (skipAnimation) other.ModalController_factor = 1;
80 }
int state
float bound(float min, float value, float max)

References bound(), entity(), other, and state.

◆ TabButton_Click()

void TabButton_Click ( entity button,
entity tab )

Definition at line 21 of file modalcontroller.qc.

22 {
23 if (tab.ModalController_state == 1) return;
24 tab.parent.hideAll(tab.parent, 0);
25 button.forcePressed = true;
26 tab.ModalController_controllingButton = button;
27 tab.parent.showChild(tab.parent, tab, button.origin, button.size, 0);
28 }

References entity().

Referenced by m_activate_window(), and ModalController_addTab().

Variable Documentation

◆ ModalController_buttonOrigin

vector ModalController_buttonOrigin

Definition at line 10 of file modalcontroller.qc.

◆ ModalController_buttonSize

vector ModalController_buttonSize

Definition at line 9 of file modalcontroller.qc.

◆ ModalController_controllingButton

entity ModalController_controllingButton

Definition at line 13 of file modalcontroller.qc.

◆ ModalController_factor

float ModalController_factor

Definition at line 12 of file modalcontroller.qc.

◆ ModalController_initialAlpha

float ModalController_initialAlpha

Definition at line 8 of file modalcontroller.qc.

◆ ModalController_initialFontScale

vector ModalController_initialFontScale

Definition at line 7 of file modalcontroller.qc.

Referenced by ModalController_resizeNotify().

◆ ModalController_initialOrigin

vector ModalController_initialOrigin

Definition at line 6 of file modalcontroller.qc.

Referenced by ModalController_resizeNotify().

◆ ModalController_initialSize

vector ModalController_initialSize

Definition at line 5 of file modalcontroller.qc.

Referenced by ModalController_resizeNotify().

◆ ModalController_state

float ModalController_state

Definition at line 11 of file modalcontroller.qc.