1 #ifndef SCREENSHOTLIST_H
2 #define SCREENSHOTLIST_H
4 CLASS(XonoticScreenshotList, XonoticListBox)
5 METHOD(XonoticScreenshotList, configureXonoticScreenshotList, void(entity))
6 ATTRIB(XonoticScreenshotList, rowsPerItem, float, 1)
7 METHOD(XonoticScreenshotList, resizeNotify, void(entity, vector, vector, vector, vector))
8 METHOD(XonoticScreenshotList, setSelected, void(entity, float))
9 METHOD(XonoticScreenshotList, draw, void(entity))
10 METHOD(XonoticScreenshotList, drawListBoxItem, void(entity, int, vector, bool, bool))
11 METHOD(XonoticScreenshotList, getScreenshots, void(entity))
12 METHOD(XonoticScreenshotList, previewScreenshot, void(entity))
13 METHOD(XonoticScreenshotList, startScreenshot, void(entity))
14 METHOD(XonoticScreenshotList, screenshotName, string(entity, float))
15 METHOD(XonoticScreenshotList, doubleClickListBoxItem, void(entity, float, vector))
16 METHOD(XonoticScreenshotList, keyDown, float(entity, float, float, float))
17 METHOD(XonoticScreenshotList, destroy, void(entity))
18 METHOD(XonoticScreenshotList, showNotify, void(entity))
19 ATTRIB(XonoticScreenshotList, listScreenshot, float, -1)
20 ATTRIB(XonoticScreenshotList, realFontSize, vector, '0 0 0')
21 ATTRIB(XonoticScreenshotList, columnNameOrigin, float, 0)
22 ATTRIB(XonoticScreenshotList, columnNameSize, float, 0)
23 ATTRIB(XonoticScreenshotList, realUpperMargin, float, 0)
24 ATTRIB(XonoticScreenshotList, origin, vector, '0 0 0')
25 ATTRIB(XonoticScreenshotList, itemAbsSize, vector, '0 0 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 = NEW(XonoticScreenshotList);
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);
70 if(substring(s, 0, 1) == "/")
71 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
76 // if subdir is true look in subdirectories too (1 level)
77 void getScreenshots_for_ext(entity me, string ext, float subdir)
85 s=strcat(s, me.filterString, ext);
87 s=strcat(s, "*", ext);
90 list = search_begin(s, false, true);
93 n = search_getsize(list);
94 for(i = 0; i < n; ++i)
96 s = search_getfilename(list, i); // get initial full file name
97 s = substring(s, 12, (strlen(s) - 12 - 4)); // remove "screenshots/" prefix and ".<ext>" suffix
98 s = strdecolorize(s); // remove any pre-existing colors
101 s = strreplace("/", "^7/", s); // clear colors at the forward slash
102 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_SCREENSHOTLIST_SUBDIR), s); // add a forward slash for sorting, then color
103 bufstr_add(me.listScreenshot, s, true);
105 else { bufstr_add(me.listScreenshot, s, true); }
111 getScreenshots_for_ext(me, ext, false);
114 void XonoticScreenshotList_getScreenshots(entity me)
116 if (me.listScreenshot >= 0)
117 buf_del(me.listScreenshot);
118 me.listScreenshot = buf_create();
119 if (me.listScreenshot < 0)
124 getScreenshots_for_ext(me, ".jpg", true);
125 getScreenshots_for_ext(me, ".tga", true);
126 getScreenshots_for_ext(me, ".png", true);
127 me.nItems = buf_getsize(me.listScreenshot);
129 buf_sort(me.listScreenshot, 128, false);
132 void XonoticScreenshotList_destroy(entity me)
135 buf_del(me.listScreenshot);
138 void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
140 me.itemAbsSize = '0 0 0';
141 SUPER(XonoticScreenshotList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
143 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
144 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
145 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
147 me.columnNameOrigin = me.realFontSize.x;
148 me.columnNameSize = 1 - 2 * me.realFontSize.x;
151 void XonoticScreenshotList_setSelected(entity me, float i)
153 if (me.newSlideShowScreenshotTime)
154 me.startSlideShow(me);
155 me.prevSelectedItem = me.selectedItem;
156 SUPER(XonoticScreenshotList).setSelected(me, i);
157 if (me.pressed && me.selectedItem != me.prevSelectedItem)
159 // while dragging the scrollbar (or an item)
160 // for a smooth mouse movement do not load immediately the new selected images
161 me.newScreenshotTime = time + 0.22; // dragging an item we need a delay > 0.2 (from listbox: me.dragScrollTimer = time + 0.2;)
163 else if (time > me.newScreenshotTime)
165 me.newScreenshotTime = 0;
166 me.previewScreenshot(me); // load the preview on selection change
170 void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
174 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
177 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
178 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
181 s = me.screenshotName(me,i);
182 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
183 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);
186 void XonoticScreenshotList_showNotify(entity me)
188 me.getScreenshots(me);
189 me.previewScreenshot(me);
192 void ScreenshotList_Refresh_Click(entity btn, entity me)
194 me.getScreenshots(me);
195 me.setSelected(me, 0); //always select the first element after a list update
198 void ScreenshotList_Filter_Change(entity box, entity me)
201 strunzone(me.filterString);
205 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
206 me.filterString = strzone(box.text);
208 me.filterString = strzone(strcat("*", box.text, "*"));
211 me.filterString = string_null;
213 ScreenshotList_Refresh_Click(world, me);
216 void ScreenshotList_Filter_Would_Change(entity box, entity me)
219 me.filterTime = time + 0.5;
222 void XonoticScreenshotList_draw(entity me)
224 if (me.filterTime && time > me.filterTime)
226 ScreenshotList_Filter_Change(me.filterBox, me);
229 if (me.newScreenshotTime && time > me.newScreenshotTime)
231 me.previewScreenshot(me);
232 me.newScreenshotTime = 0;
234 else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime)
236 if (me.selectedItem == me.nItems - 1) //last screenshot?
238 // restart from the first screenshot
239 me.setSelected(me, 0);
240 me.goScreenshot(me, +0);
243 me.goScreenshot(me, +1);
245 SUPER(XonoticScreenshotList).draw(me);
248 void XonoticScreenshotList_startSlideShow(entity me)
250 me.newSlideShowScreenshotTime = time + 3;
253 void XonoticScreenshotList_stopSlideShow(entity me)
255 me.newSlideShowScreenshotTime = 0;
258 void XonoticScreenshotList_goScreenshot(entity me, float d)
260 if(!me.screenshotViewerDialog)
262 me.setSelected(me, me.selectedItem + d);
263 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
266 void XonoticScreenshotList_startScreenshot(entity me)
268 me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
270 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));
273 void XonoticScreenshotList_previewScreenshot(entity me)
275 if(!me.screenshotBrowserDialog)
278 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, "");
280 me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
283 void StartScreenshot_Click(entity btn, entity me)
285 me.startScreenshot(me);
288 void XonoticScreenshotList_doubleClickListBoxItem(entity me, float i, vector where)
290 me.startScreenshot(me);
293 float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
295 if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_MOUSE2 || scan == K_SPACE) {
296 me.startScreenshot(me);
299 if(scan == K_MWHEELUP || scan == K_MWHEELDOWN)
300 me.newScreenshotTime = time + 0.2;
301 return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);