2 CLASS(XonoticScreenshotList) EXTENDS(XonoticListBox)
3 METHOD(XonoticScreenshotList, configureXonoticScreenshotList, void(entity))
4 ATTRIB(XonoticScreenshotList, rowsPerItem, float, 1)
5 METHOD(XonoticScreenshotList, resizeNotify, void(entity, vector, vector, vector, vector))
6 METHOD(XonoticScreenshotList, setSelected, void(entity, float))
7 METHOD(XonoticScreenshotList, draw, void(entity))
8 METHOD(XonoticScreenshotList, drawListBoxItem, void(entity, float, vector, float))
9 METHOD(XonoticScreenshotList, getScreenshots, void(entity))
10 METHOD(XonoticScreenshotList, previewScreenshot, void(entity))
11 METHOD(XonoticScreenshotList, startScreenshot, void(entity))
12 METHOD(XonoticScreenshotList, screenshotName, string(entity, float))
13 METHOD(XonoticScreenshotList, clickListBoxItem, void(entity, float, vector))
14 METHOD(XonoticScreenshotList, keyDown, float(entity, float, float, float))
15 METHOD(XonoticScreenshotList, destroy, void(entity))
16 METHOD(XonoticScreenshotList, showNotify, void(entity))
17 ATTRIB(XonoticScreenshotList, listScreenshot, float, -1)
18 ATTRIB(XonoticScreenshotList, realFontSize, vector, '0 0 0')
19 ATTRIB(XonoticScreenshotList, columnNameOrigin, float, 0)
20 ATTRIB(XonoticScreenshotList, columnNameSize, float, 0)
21 ATTRIB(XonoticScreenshotList, realUpperMargin, float, 0)
22 ATTRIB(XonoticScreenshotList, origin, vector, '0 0 0')
23 ATTRIB(XonoticScreenshotList, itemAbsSize, vector, '0 0 0')
24 ATTRIB(XonoticScreenshotList, lastClickedScreenshot, float, -1)
25 ATTRIB(XonoticScreenshotList, lastClickedTime, float, 0)
26 ATTRIB(XonoticScreenshotList, filterString, string, string_null)
27 ATTRIB(XonoticScreenshotList, filterBox, entity, NULL)
28 ATTRIB(XonoticScreenshotList, filterTime, float, 0)
30 ATTRIB(XonoticScreenshotList, newScreenshotTime, float, 0)
31 ATTRIB(XonoticScreenshotList, newSlideShowScreenshotTime, float, 0)
32 ATTRIB(XonoticScreenshotList, prevSelectedItem, float, 0)
34 ATTRIB(XonoticScreenshotList, screenshotBrowserDialog, entity, NULL)
35 ATTRIB(XonoticScreenshotList, screenshotPreview, entity, NULL)
36 ATTRIB(XonoticScreenshotList, screenshotViewerDialog, entity, NULL)
37 METHOD(XonoticScreenshotList, goScreenshot, void(entity, float))
38 METHOD(XonoticScreenshotList, startSlideShow, void(entity))
39 METHOD(XonoticScreenshotList, stopSlideShow, void(entity))
40 ENDCLASS(XonoticScreenshotList)
42 entity makeXonoticScreenshotList();
43 void StartScreenshot_Click(entity btn, entity me);
44 void ScreenshotList_Refresh_Click(entity btn, entity me);
45 void ScreenshotList_Filter_Would_Change(entity box, entity me);
46 void ScreenshotList_Filter_Change(entity box, entity me);
51 entity makeXonoticScreenshotList()
54 me = spawnXonoticScreenshotList();
55 me.configureXonoticScreenshotList(me);
59 void XonoticScreenshotList_configureXonoticScreenshotList(entity me)
61 me.configureXonoticListBox(me);
62 me.getScreenshots(me);
65 string XonoticScreenshotList_screenshotName(entity me, float i )
68 s = bufstr_get(me.listScreenshot, i);
69 s = substring(s, 12, strlen(s) - 12 - 4); // screenshots/, .<ext>
73 // if subdir is TRUE look in subdirectories too (1 level)
74 void getScreenshots_for_ext(entity me, string ext, float subdir)
82 s=strcat(s, me.filterString, ext);
84 s=strcat(s, "*", ext);
87 list = search_begin(s, FALSE, TRUE);
90 n = search_getsize(list);
91 for(i = 0; i < n; ++i)
92 bufstr_add(me.listScreenshot, search_getfilename(list, i), TRUE);
97 getScreenshots_for_ext(me, ext, FALSE);
100 void XonoticScreenshotList_getScreenshots(entity me)
102 if (me.listScreenshot >= 0)
103 buf_del(me.listScreenshot);
104 me.listScreenshot = buf_create();
105 if (me.listScreenshot < 0)
110 getScreenshots_for_ext(me, ".jpg", TRUE);
111 getScreenshots_for_ext(me, ".tga", TRUE);
112 getScreenshots_for_ext(me, ".png", TRUE);
113 me.nItems = buf_getsize(me.listScreenshot);
114 buf_sort(me.listScreenshot, 128, FALSE);
117 void XonoticScreenshotList_destroy(entity me)
119 buf_del(me.listScreenshot);
122 void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
124 me.itemAbsSize = '0 0 0';
125 SUPER(XonoticScreenshotList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
127 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize_y * me.itemHeight));
128 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
129 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
131 me.columnNameOrigin = me.realFontSize_x;
132 me.columnNameSize = 1 - 2 * me.realFontSize_x;
135 void XonoticScreenshotList_setSelected(entity me, float i)
137 if (me.newSlideShowScreenshotTime)
138 me.startSlideShow(me);
139 me.prevSelectedItem = me.selectedItem;
140 SUPER(XonoticScreenshotList).setSelected(me, i);
141 if (me.pressed && me.selectedItem != me.prevSelectedItem)
143 // while dragging the scrollbar (or an item)
144 // for a smooth mouse movement do not load immediately the new selected images
145 me.newScreenshotTime = time + 0.22; // dragging an item we need a delay > 0.2 (from listbox: me.dragScrollTimer = time + 0.2;)
147 else if (time > me.newScreenshotTime)
149 me.newScreenshotTime = 0;
150 me.previewScreenshot(me); // load the preview on selection change
154 void XonoticScreenshotList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
158 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
160 s = me.screenshotName(me,i);
161 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
162 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
165 void XonoticScreenshotList_showNotify(entity me)
167 me.getScreenshots(me);
168 me.previewScreenshot(me);
171 void ScreenshotList_Refresh_Click(entity btn, entity me)
173 me.getScreenshots(me);
174 me.setSelected(me, 0); //always select the first element after a list update
177 void ScreenshotList_Filter_Change(entity box, entity me)
180 strunzone(me.filterString);
184 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
185 me.filterString = strzone(box.text);
187 me.filterString = strzone(strcat("*", box.text, "*"));
190 me.filterString = string_null;
192 ScreenshotList_Refresh_Click(world, me);
195 void ScreenshotList_Filter_Would_Change(entity box, entity me)
198 me.filterTime = time + 0.5;
201 void XonoticScreenshotList_draw(entity me)
203 if (me.filterTime && time > me.filterTime)
205 ScreenshotList_Filter_Change(me.filterBox, me);
208 if (me.newScreenshotTime && time > me.newScreenshotTime)
210 me.previewScreenshot(me);
211 me.newScreenshotTime = 0;
213 else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime)
215 if (me.selectedItem == me.nItems - 1) //last screenshot?
217 // restart from the first screenshot
218 me.setSelected(me, 0);
219 me.goScreenshot(me, +0);
222 me.goScreenshot(me, +1);
224 SUPER(XonoticScreenshotList).draw(me);
227 void XonoticScreenshotList_startSlideShow(entity me)
229 me.newSlideShowScreenshotTime = time + 3;
232 void XonoticScreenshotList_stopSlideShow(entity me)
234 me.newSlideShowScreenshotTime = 0;
237 void XonoticScreenshotList_goScreenshot(entity me, float d)
239 if(!me.screenshotViewerDialog)
241 me.setSelected(me, me.selectedItem + d);
242 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
245 void XonoticScreenshotList_startScreenshot(entity me)
247 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
249 DialogOpenButton_Click_withCoords(NULL, me.screenshotViewerDialog, me.origin + eX * (me.columnNameOrigin * me.size_x) + eY * ((me.itemHeight * me.selectedItem - me.scrollPos) * me.size_y), eY * me.itemAbsSize_y + eX * (me.itemAbsSize_x * me.columnNameSize));
252 void XonoticScreenshotList_previewScreenshot(entity me)
254 if(!me.screenshotBrowserDialog)
257 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, "");
259 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", me.screenshotName(me,me.selectedItem)));
262 void StartScreenshot_Click(entity btn, entity me)
264 me.startScreenshot(me);
267 void XonoticScreenshotList_clickListBoxItem(entity me, float i, vector where)
269 if(i == me.lastClickedScreenshot)
270 if(time < me.lastClickedTime + 0.3)
274 me.setSelected(me, i);
275 me.startScreenshot(me);
277 me.lastClickedScreenshot = i;
278 me.lastClickedTime = time;
281 float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
283 if(scan == K_ENTER || scan == K_KP_ENTER) {
284 me.startScreenshot(me);
287 if(scan == K_MWHEELUP || scan == K_MWHEELDOWN)
288 me.newScreenshotTime = time + 0.2;
289 return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);