1 #ifndef ITEM_NEXPOSEE_H
2 #define ITEM_NEXPOSEE_H
3 #include "container.qc"
4 CLASS(Nexposee, Container)
5 METHOD(Nexposee, draw, void(entity));
6 METHOD(Nexposee, keyDown, float(entity, float, float, float));
7 METHOD(Nexposee, keyUp, float(entity, float, float, float));
8 METHOD(Nexposee, mousePress, float(entity, vector));
9 METHOD(Nexposee, mouseMove, float(entity, vector));
10 METHOD(Nexposee, mouseRelease, float(entity, vector));
11 METHOD(Nexposee, mouseDrag, float(entity, vector));
12 METHOD(Nexposee, resizeNotify, void(entity, vector, vector, vector, vector));
13 METHOD(Nexposee, focusEnter, void(entity));
14 METHOD(Nexposee, close, void(entity));
16 ATTRIB(Nexposee, animationState, float, -1)
17 ATTRIB(Nexposee, animationFactor, float, 0)
18 ATTRIB(Nexposee, selectedChild, entity, NULL)
19 ATTRIB(Nexposee, mouseFocusedChild, entity, NULL)
20 METHOD(Nexposee, addItem, void(entity, entity, vector, vector, float));
21 METHOD(Nexposee, calc, void(entity));
22 METHOD(Nexposee, setNexposee, void(entity, entity, vector, float, float));
23 ATTRIB(Nexposee, mousePosition, vector, '0 0 0')
24 METHOD(Nexposee, pullNexposee, void(entity, entity, vector));
27 void ExposeeCloseButton_Click(entity button, entity other); // un-exposees the current state
30 // 0 = thumbnails seen
34 // animation factor: 0 = minimum theSize, 1 = maximum theSize
35 .vector Nexposee_initialSize;
36 .vector Nexposee_initialFontScale;
37 .vector Nexposee_initialOrigin;
38 .float Nexposee_initialAlpha;
40 .vector Nexposee_smallSize;
41 .vector Nexposee_smallOrigin;
42 .float Nexposee_smallAlpha;
43 .float Nexposee_mediumAlpha;
44 .vector Nexposee_scaleCenter;
45 .vector Nexposee_align;
46 .float Nexposee_animationFactor;
51 void Nexposee_close(entity me)
53 // user must override this
56 void ExposeeCloseButton_Click(entity button, entity other)
58 other.selectedChild = other.focusedChild;
59 other.setFocus(other, NULL);
60 other.animationState = 3;
63 void Nexposee_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
66 me.resizeNotifyLie(me, relOrigin, relSize, absOrigin, absSize, Nexposee_initialOrigin, Nexposee_initialSize, Nexposee_initialFontScale);
69 void Nexposee_Calc_Scale(entity me, float scale)
72 for (e = me.firstChild; e; e = e.nextSibling)
74 e.Nexposee_smallOrigin = (e.Nexposee_initialOrigin - e.Nexposee_scaleCenter) * scale + e.Nexposee_scaleCenter;
75 e.Nexposee_smallSize = e.Nexposee_initialSize * scale;
76 if (e.Nexposee_align.x > 0) e.Nexposee_smallOrigin_x = 1 - e.Nexposee_align.x * scale;
77 if (e.Nexposee_align.x < 0) e.Nexposee_smallOrigin_x = -e.Nexposee_smallSize.x + e.Nexposee_align.x * scale;
78 if (e.Nexposee_align.y > 0) e.Nexposee_smallOrigin_y = 1 - e.Nexposee_align.y * scale;
79 if (e.Nexposee_align.y < 0) e.Nexposee_smallOrigin_y = -e.Nexposee_smallSize.y + e.Nexposee_align.y * scale;
83 void Nexposee_calc(entity me)
87 * can't put that here ;)
91 vector emins, emaxs, e2mins, e2maxs;
93 for (scale = 0.7; ; scale *= 0.99)
95 Nexposee_Calc_Scale(me, scale);
97 for (e = me.firstChild; e; e = e.nextSibling)
99 emins = e.Nexposee_smallOrigin;
100 emaxs = emins + e.Nexposee_smallSize;
101 for (e2 = e.nextSibling; e2; e2 = e2.nextSibling)
103 e2mins = e2.Nexposee_smallOrigin;
104 e2maxs = e2mins + e2.Nexposee_smallSize;
106 // two intervals [amins, amaxs] and [bmins, bmaxs] overlap if:
107 // amins < bmins < amaxs < bmaxs
108 // for which suffices
111 if ((e2mins.x - emaxs.x) * (emins.x - e2maxs.x) > 0) // x overlap
112 if ((e2mins.y - emaxs.y) * (emins.y - e2maxs.y) > 0) // y overlap
123 Nexposee_Calc_Scale(me, scale);
126 void Nexposee_setNexposee(entity me, entity other, vector scalecenter, float a0, float a1)
128 other.Nexposee_scaleCenter = scalecenter;
129 other.Nexposee_smallAlpha = a0;
130 me.setAlphaOf(me, other, a0);
131 other.Nexposee_mediumAlpha = a1;
134 void Nexposee_draw(entity me)
142 if (me.animationState == -1) me.animationState = 0;
144 f = min(1, frametime * 5);
145 switch (me.animationState)
148 me.animationFactor = 0;
151 me.animationFactor += f;
152 if (me.animationFactor >= 1)
154 me.animationFactor = 1;
155 me.animationState = 2;
156 SUPER(Nexposee).setFocus(me, me.selectedChild);
160 me.animationFactor = 1;
163 me.animationFactor -= f;
164 me.mouseFocusedChild = me.itemFromPoint(me, me.mousePosition);
165 if (me.animationFactor <= 0)
167 me.animationFactor = 0;
168 me.animationState = 0;
169 me.selectedChild = me.mouseFocusedChild;
174 f = min(1, frametime * 10);
175 for (e = me.firstChild; e; e = e.nextSibling)
177 if (e == me.selectedChild)
179 e.Container_origin = e.Nexposee_smallOrigin * (1 - me.animationFactor) + e.Nexposee_initialOrigin * me.animationFactor;
180 e.Container_size = e.Nexposee_smallSize * (1 - me.animationFactor) + e.Nexposee_initialSize * me.animationFactor;
181 e.Nexposee_animationFactor = me.animationFactor;
182 a0 = e.Nexposee_mediumAlpha;
183 if (me.animationState == 3)
184 if (e != me.mouseFocusedChild) a0 = e.Nexposee_smallAlpha;
185 a = a0 * (1 - me.animationFactor) + me.animationFactor;
189 // minimum theSize counts
190 e.Container_origin = e.Nexposee_smallOrigin;
191 e.Container_size = e.Nexposee_smallSize;
192 e.Nexposee_animationFactor = 0;
193 a = e.Nexposee_smallAlpha * (1 - me.animationFactor);
195 me.setAlphaOf(me, e, e.Container_alpha * (1 - f) + a * f);
197 fs = globalToBoxSize(e.Container_size, e.Nexposee_initialSize);
198 e.Container_fontscale_x = fs.x * e.Nexposee_initialFontScale.x;
199 e.Container_fontscale_y = fs.y * e.Nexposee_initialFontScale.y;
202 SUPER(Nexposee).draw(me);
205 float Nexposee_mousePress(entity me, vector pos)
207 if (me.animationState == 0)
209 me.mouseFocusedChild = NULL;
210 Nexposee_mouseMove(me, pos);
211 if (me.mouseFocusedChild)
213 m_play_click_sound(MENU_SOUND_OPEN);
214 me.animationState = 1;
215 SUPER(Nexposee).setFocus(me, NULL);
223 else if (me.animationState == 2)
225 if (!(SUPER(Nexposee).mousePress(me, pos)))
227 m_play_click_sound(MENU_SOUND_CLOSE);
228 me.animationState = 3;
229 SUPER(Nexposee).setFocus(me, NULL);
236 float Nexposee_mouseRelease(entity me, vector pos)
238 if (me.animationState == 2) return SUPER(Nexposee).mouseRelease(me, pos);
242 float Nexposee_mouseDrag(entity me, vector pos)
244 if (me.animationState == 2) return SUPER(Nexposee).mouseDrag(me, pos);
248 float Nexposee_mouseMove(entity me, vector pos)
251 me.mousePosition = pos;
252 e = me.mouseFocusedChild;
253 me.mouseFocusedChild = me.itemFromPoint(me, pos);
254 if (me.animationState == 2) return SUPER(Nexposee).mouseMove(me, pos);
255 if (me.animationState == 0)
257 if (me.mouseFocusedChild)
258 if (me.mouseFocusedChild != e || me.mouseFocusedChild != me.selectedChild) me.selectedChild = me.mouseFocusedChild;
264 float Nexposee_keyUp(entity me, float scan, float ascii, float shift)
266 if (me.animationState == 2) return SUPER(Nexposee).keyUp(me, scan, ascii, shift);
270 float Nexposee_keyDown(entity me, float scan, float ascii, float shift)
272 float nexposeeKey = 0;
273 if (me.animationState == 2)
274 if (SUPER(Nexposee).keyDown(me, scan, ascii, shift)) return 1;
277 if (me.animationState == 0)
281 if (me.selectedChild) me.selectedChild = me.selectedChild.prevSibling;
282 if (!me.selectedChild) me.selectedChild = me.lastChild;
286 if (me.selectedChild) me.selectedChild = me.selectedChild.nextSibling;
287 if (!me.selectedChild) me.selectedChild = me.firstChild;
291 switch (me.animationState)
296 nexposeeKey = ((scan == K_SPACE) || (scan == K_ENTER) || (scan == K_KP_ENTER));
300 nexposeeKey = (scan == K_ESCAPE);
305 switch (me.animationState)
310 m_play_click_sound(MENU_SOUND_OPEN);
311 me.animationState = 1;
315 m_play_click_sound(MENU_SOUND_CLOSE);
316 me.animationState = 3;
319 if (me.focusedChild) me.selectedChild = me.focusedChild;
320 if (!me.selectedChild) me.animationState = 0;
321 SUPER(Nexposee).setFocus(me, NULL);
327 void Nexposee_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
329 SUPER(Nexposee).addItem(me, other, theOrigin, theSize, theAlpha);
330 other.Nexposee_initialFontScale = other.Container_fontscale;
331 other.Nexposee_initialSize = other.Container_size;
332 other.Nexposee_initialOrigin = other.Container_origin;
333 other.Nexposee_initialAlpha = other.Container_alpha;
334 if (other.Nexposee_initialFontScale == '0 0 0') other.Nexposee_initialFontScale = '1 1 0';
337 void Nexposee_focusEnter(entity me)
339 if (me.animationState == 2) SUPER(Nexposee).setFocus(me, me.selectedChild);
342 void Nexposee_pullNexposee(entity me, entity other, vector theAlign)
344 other.Nexposee_align = theAlign;