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, int, vector, bool, 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, doubleClickListBoxItem, 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, filterString, string, string_null)
25 ATTRIB(XonoticScreenshotList, filterBox, entity, NULL)
26 ATTRIB(XonoticScreenshotList, filterTime, float, 0)
28 ATTRIB(XonoticScreenshotList, newScreenshotTime, float, 0)
29 ATTRIB(XonoticScreenshotList, newSlideShowScreenshotTime, float, 0)
30 ATTRIB(XonoticScreenshotList, prevSelectedItem, float, 0)
32 ATTRIB(XonoticScreenshotList, screenshotBrowserDialog, entity, NULL)
33 ATTRIB(XonoticScreenshotList, screenshotPreview, entity, NULL)
34 ATTRIB(XonoticScreenshotList, screenshotViewerDialog, entity, NULL)
35 METHOD(XonoticScreenshotList, goScreenshot, void(entity, float))
36 METHOD(XonoticScreenshotList, startSlideShow, void(entity))
37 METHOD(XonoticScreenshotList, stopSlideShow, void(entity))
38 ENDCLASS(XonoticScreenshotList)
40 entity makeXonoticScreenshotList();
41 void StartScreenshot_Click(entity btn, entity me);
42 void ScreenshotList_Refresh_Click(entity btn, entity me);
43 void ScreenshotList_Filter_Would_Change(entity box, entity me);
44 void ScreenshotList_Filter_Change(entity box, entity me);
49 entity makeXonoticScreenshotList()
52 me = spawnXonoticScreenshotList();
53 me.configureXonoticScreenshotList(me);
57 void XonoticScreenshotList_configureXonoticScreenshotList(entity me)
59 me.configureXonoticListBox(me);
60 me.getScreenshots(me);
63 string XonoticScreenshotList_screenshotName(entity me, float i)
66 s = bufstr_get(me.listScreenshot, i);
68 if(substring(s, 0, 1) == "/")
69 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
74 // if subdir is true look in subdirectories too (1 level)
75 void getScreenshots_for_ext(entity me, string ext, float subdir)
83 s=strcat(s, me.filterString, ext);
85 s=strcat(s, "*", ext);
88 list = search_begin(s, false, true);
91 n = search_getsize(list);
92 for(i = 0; i < n; ++i)
94 s = search_getfilename(list, i); // get initial full file name
95 s = substring(s, 12, (strlen(s) - 12 - 4)); // remove "screenshots/" prefix and ".<ext>" suffix
96 s = strdecolorize(s); // remove any pre-existing colors
99 s = strreplace("/", "^7/", s); // clear colors at the forward slash
100 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_SCREENSHOTLIST_SUBDIR), s); // add a forward slash for sorting, then color
101 bufstr_add(me.listScreenshot, s, true);
103 else { bufstr_add(me.listScreenshot, s, true); }
109 getScreenshots_for_ext(me, ext, false);
112 void XonoticScreenshotList_getScreenshots(entity me)
114 if (me.listScreenshot >= 0)
115 buf_del(me.listScreenshot);
116 me.listScreenshot = buf_create();
117 if (me.listScreenshot < 0)
122 getScreenshots_for_ext(me, ".jpg", true);
123 getScreenshots_for_ext(me, ".tga", true);
124 getScreenshots_for_ext(me, ".png", true);
125 me.nItems = buf_getsize(me.listScreenshot);
127 buf_sort(me.listScreenshot, 128, false);
130 void XonoticScreenshotList_destroy(entity me)
133 buf_del(me.listScreenshot);
136 void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
138 me.itemAbsSize = '0 0 0';
139 SUPER(XonoticScreenshotList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
141 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
142 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
143 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
145 me.columnNameOrigin = me.realFontSize.x;
146 me.columnNameSize = 1 - 2 * me.realFontSize.x;
149 void XonoticScreenshotList_setSelected(entity me, float i)
151 if (me.newSlideShowScreenshotTime)
152 me.startSlideShow(me);
153 me.prevSelectedItem = me.selectedItem;
154 SUPER(XonoticScreenshotList).setSelected(me, i);
155 if (me.pressed && me.selectedItem != me.prevSelectedItem)
157 // while dragging the scrollbar (or an item)
158 // for a smooth mouse movement do not load immediately the new selected images
159 me.newScreenshotTime = time + 0.22; // dragging an item we need a delay > 0.2 (from listbox: me.dragScrollTimer = time + 0.2;)
161 else if (time > me.newScreenshotTime)
163 me.newScreenshotTime = 0;
164 me.previewScreenshot(me); // load the preview on selection change
168 void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, float highlightedTime)
172 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
173 else if(highlightedTime)
174 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, getHighlightAlpha(SKINALPHA_LISTBOX_SELECTED * 0.1, highlightedTime));
176 s = me.screenshotName(me,i);
177 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
178 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, 1);
181 void XonoticScreenshotList_showNotify(entity me)
183 me.getScreenshots(me);
184 me.previewScreenshot(me);
187 void ScreenshotList_Refresh_Click(entity btn, entity me)
189 me.getScreenshots(me);
190 me.setSelected(me, 0); //always select the first element after a list update
193 void ScreenshotList_Filter_Change(entity box, entity me)
196 strunzone(me.filterString);
200 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
201 me.filterString = strzone(box.text);
203 me.filterString = strzone(strcat("*", box.text, "*"));
206 me.filterString = string_null;
208 ScreenshotList_Refresh_Click(world, me);
211 void ScreenshotList_Filter_Would_Change(entity box, entity me)
214 me.filterTime = time + 0.5;
217 void XonoticScreenshotList_draw(entity me)
219 if (me.filterTime && time > me.filterTime)
221 ScreenshotList_Filter_Change(me.filterBox, me);
224 if (me.newScreenshotTime && time > me.newScreenshotTime)
226 me.previewScreenshot(me);
227 me.newScreenshotTime = 0;
229 else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime)
231 if (me.selectedItem == me.nItems - 1) //last screenshot?
233 // restart from the first screenshot
234 me.setSelected(me, 0);
235 me.goScreenshot(me, +0);
238 me.goScreenshot(me, +1);
240 SUPER(XonoticScreenshotList).draw(me);
243 void XonoticScreenshotList_startSlideShow(entity me)
245 me.newSlideShowScreenshotTime = time + 3;
248 void XonoticScreenshotList_stopSlideShow(entity me)
250 me.newSlideShowScreenshotTime = 0;
253 void XonoticScreenshotList_goScreenshot(entity me, float d)
255 if(!me.screenshotViewerDialog)
257 me.setSelected(me, me.selectedItem + d);
258 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
261 void XonoticScreenshotList_startScreenshot(entity me)
263 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
265 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));
268 void XonoticScreenshotList_previewScreenshot(entity me)
270 if(!me.screenshotBrowserDialog)
273 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, "");
275 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
278 void StartScreenshot_Click(entity btn, entity me)
280 me.startScreenshot(me);
283 void XonoticScreenshotList_doubleClickListBoxItem(entity me, float i, vector where)
285 me.startScreenshot(me);
288 float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
290 if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_MOUSE2 || scan == K_SPACE) {
291 me.startScreenshot(me);
294 if(scan == K_MWHEELUP || scan == K_MWHEELDOWN)
295 me.newScreenshotTime = time + 0.2;
296 return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);