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)
77 e.Nexposee_smallOrigin_x = 1 - e.Nexposee_align.x * scale;
78 if(e.Nexposee_align.x < 0)
79 e.Nexposee_smallOrigin_x = -e.Nexposee_smallSize.x + e.Nexposee_align.x * scale;
80 if(e.Nexposee_align.y > 0)
81 e.Nexposee_smallOrigin_y = 1 - e.Nexposee_align.y * scale;
82 if(e.Nexposee_align.y < 0)
83 e.Nexposee_smallOrigin_y = -e.Nexposee_smallSize.y + e.Nexposee_align.y * scale;
87 void Nexposee_calc(entity me)
91 * can't put that here ;)
95 vector emins, emaxs, e2mins, e2maxs;
97 for(scale = 0.7;; scale *= 0.99)
99 Nexposee_Calc_Scale(me, scale);
101 for(e = me.firstChild; e; e = e.nextSibling)
103 emins = e.Nexposee_smallOrigin;
104 emaxs = emins + e.Nexposee_smallSize;
105 for(e2 = e.nextSibling; e2; e2 = e2.nextSibling)
107 e2mins = e2.Nexposee_smallOrigin;
108 e2maxs = e2mins + e2.Nexposee_smallSize;
110 // two intervals [amins, amaxs] and [bmins, bmaxs] overlap if:
111 // amins < bmins < amaxs < bmaxs
112 // for which suffices
115 if((e2mins.x - emaxs.x) * (emins.x - e2maxs.x) > 0) // x overlap
116 if((e2mins.y - emaxs.y) * (emins.y - e2maxs.y) > 0) // y overlap
129 Nexposee_Calc_Scale(me, scale);
132 void Nexposee_setNexposee(entity me, entity other, vector scalecenter, float a0, float a1)
134 other.Nexposee_scaleCenter = scalecenter;
135 other.Nexposee_smallAlpha = a0;
136 me.setAlphaOf(me, other, a0);
137 other.Nexposee_mediumAlpha = a1;
140 void Nexposee_draw(entity me)
148 if(me.animationState == -1)
150 me.animationState = 0;
153 f = min(1, frametime * 5);
154 switch(me.animationState)
157 me.animationFactor = 0;
160 me.animationFactor += f;
161 if(me.animationFactor >= 1)
163 me.animationFactor = 1;
164 me.animationState = 2;
165 SUPER(Nexposee).setFocus(me, me.selectedChild);
169 me.animationFactor = 1;
172 me.animationFactor -= f;
173 me.mouseFocusedChild = me.itemFromPoint(me, me.mousePosition);
174 if(me.animationFactor <= 0)
176 me.animationFactor = 0;
177 me.animationState = 0;
178 me.selectedChild = me.mouseFocusedChild;
183 f = min(1, frametime * 10);
184 for(e = me.firstChild; e; e = e.nextSibling)
186 if(e == me.selectedChild)
188 e.Container_origin = e.Nexposee_smallOrigin * (1 - me.animationFactor) + e.Nexposee_initialOrigin * me.animationFactor;
189 e.Container_size = e.Nexposee_smallSize * (1 - me.animationFactor) + e.Nexposee_initialSize * me.animationFactor;
190 e.Nexposee_animationFactor = me.animationFactor;
191 a0 = e.Nexposee_mediumAlpha;
192 if(me.animationState == 3)
193 if(e != me.mouseFocusedChild)
194 a0 = e.Nexposee_smallAlpha;
195 a = a0 * (1 - me.animationFactor) + me.animationFactor;
199 // minimum theSize counts
200 e.Container_origin = e.Nexposee_smallOrigin;
201 e.Container_size = e.Nexposee_smallSize;
202 e.Nexposee_animationFactor = 0;
203 a = e.Nexposee_smallAlpha * (1 - me.animationFactor);
205 me.setAlphaOf(me, e, e.Container_alpha * (1 - f) + a * f);
207 fs = globalToBoxSize(e.Container_size, e.Nexposee_initialSize);
208 e.Container_fontscale_x = fs.x * e.Nexposee_initialFontScale.x;
209 e.Container_fontscale_y = fs.y * e.Nexposee_initialFontScale.y;
212 SUPER(Nexposee).draw(me);
215 float Nexposee_mousePress(entity me, vector pos)
217 if(me.animationState == 0)
219 me.mouseFocusedChild = NULL;
220 Nexposee_mouseMove(me, pos);
221 if(me.mouseFocusedChild)
223 m_play_click_sound(MENU_SOUND_OPEN);
224 me.animationState = 1;
225 SUPER(Nexposee).setFocus(me, NULL);
231 else if(me.animationState == 2)
233 if (!(SUPER(Nexposee).mousePress(me, pos)))
235 m_play_click_sound(MENU_SOUND_CLOSE);
236 me.animationState = 3;
237 SUPER(Nexposee).setFocus(me, NULL);
244 float Nexposee_mouseRelease(entity me, vector pos)
246 if(me.animationState == 2)
247 return SUPER(Nexposee).mouseRelease(me, pos);
251 float Nexposee_mouseDrag(entity me, vector pos)
253 if(me.animationState == 2)
254 return SUPER(Nexposee).mouseDrag(me, pos);
258 float Nexposee_mouseMove(entity me, vector pos)
261 me.mousePosition = pos;
262 e = me.mouseFocusedChild;
263 me.mouseFocusedChild = me.itemFromPoint(me, pos);
264 if(me.animationState == 2)
265 return SUPER(Nexposee).mouseMove(me, pos);
266 if(me.animationState == 0)
268 if(me.mouseFocusedChild)
269 if(me.mouseFocusedChild != e || me.mouseFocusedChild != me.selectedChild)
270 me.selectedChild = me.mouseFocusedChild;
276 float Nexposee_keyUp(entity me, float scan, float ascii, float shift)
278 if(me.animationState == 2)
279 return SUPER(Nexposee).keyUp(me, scan, ascii, shift);
283 float Nexposee_keyDown(entity me, float scan, float ascii, float shift)
285 float nexposeeKey = 0;
286 if(me.animationState == 2)
287 if(SUPER(Nexposee).keyDown(me, scan, ascii, shift))
291 if(me.animationState == 0)
296 me.selectedChild = me.selectedChild.prevSibling;
297 if (!me.selectedChild)
298 me.selectedChild = me.lastChild;
303 me.selectedChild = me.selectedChild.nextSibling;
304 if (!me.selectedChild)
305 me.selectedChild = me.firstChild;
309 switch(me.animationState)
314 nexposeeKey = ((scan == K_SPACE) || (scan == K_ENTER) || (scan == K_KP_ENTER));
318 nexposeeKey = (scan == K_ESCAPE);
323 switch(me.animationState)
328 m_play_click_sound(MENU_SOUND_OPEN);
329 me.animationState = 1;
333 m_play_click_sound(MENU_SOUND_CLOSE);
334 me.animationState = 3;
338 me.selectedChild = me.focusedChild;
339 if (!me.selectedChild)
340 me.animationState = 0;
341 SUPER(Nexposee).setFocus(me, NULL);
347 void Nexposee_addItem(entity me, entity other, vector theOrigin, vector theSize, float theAlpha)
349 SUPER(Nexposee).addItem(me, other, theOrigin, theSize, theAlpha);
350 other.Nexposee_initialFontScale = other.Container_fontscale;
351 other.Nexposee_initialSize = other.Container_size;
352 other.Nexposee_initialOrigin = other.Container_origin;
353 other.Nexposee_initialAlpha = other.Container_alpha;
354 if(other.Nexposee_initialFontScale == '0 0 0')
355 other.Nexposee_initialFontScale = '1 1 0';
358 void Nexposee_focusEnter(entity me)
360 if(me.animationState == 2)
361 SUPER(Nexposee).setFocus(me, me.selectedChild);
364 void Nexposee_pullNexposee(entity me, entity other, vector theAlign)
366 other.Nexposee_align = theAlign;