Xonotic
screenshotlist.qc
Go to the documentation of this file.
1 #include "screenshotlist.qh"
2 
5 #include "inputbox.qh"
6 #include "../item/modalcontroller.qh"
7 
9 {
10  entity me;
12  me.configureXonoticScreenshotList(me);
13  return me;
14 }
15 
17 {
18  me.configureXonoticListBox(me);
19  me.nItems = 0;
20 }
21 
23 {
24  string s;
25  s = bufstr_get(me.listScreenshot, i);
26 
27  if(substring(s, 0, 1) == "/")
28  s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
29 
30  return s;
31 }
32 
33 // if subdir is true look in subdirectories too (1 level)
34 void getScreenshots_for_ext(entity me, string ext, float subdir)
35 {
36  string s;
37  if (subdir)
38  s="screenshots/*/";
39  else
40  s="screenshots/";
41  if(me.filterString)
42  s=strcat(s, me.filterString, ext);
43  else
44  s=strcat(s, "*", ext);
45 
46  float list, i, n;
47  list = search_begin(s, false, true);
48  if(list >= 0)
49  {
50  n = search_getsize(list);
51  for(i = 0; i < n; ++i)
52  {
53  s = search_getfilename(list, i); // get initial full file name
54  s = substring(s, 12, (strlen(s) - 12 - 4)); // remove "screenshots/" prefix and ".<ext>" suffix
55  s = strdecolorize(s); // remove any pre-existing colors
56  if(subdir)
57  {
58  s = strreplace("/", "^7/", s); // clear colors at the forward slash
59  s = strcat("/", rgb_to_hexcolor(SKINCOLOR_SCREENSHOTLIST_SUBDIR), s); // add a forward slash for sorting, then color
60  bufstr_add(me.listScreenshot, s, true);
61  }
62  else { bufstr_add(me.listScreenshot, s, true); }
63  }
64  search_end(list);
65  }
66 
67  if (subdir)
68  getScreenshots_for_ext(me, ext, false);
69 }
70 
72 {
73  if (me.listScreenshot >= 0)
74  buf_del(me.listScreenshot);
75  me.listScreenshot = buf_create();
76  if (me.listScreenshot < 0)
77  {
78  me.nItems = 0;
79  return;
80  }
81  getScreenshots_for_ext(me, ".jpg", true);
82  getScreenshots_for_ext(me, ".tga", true);
83  getScreenshots_for_ext(me, ".png", true);
84  me.nItems = buf_getsize(me.listScreenshot);
85  if(me.nItems > 0)
86  buf_sort(me.listScreenshot, 128, false);
87 }
88 
90 {
91  if(me.nItems > 0)
92  buf_del(me.listScreenshot);
93 }
94 
95 void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
96 {
97  me.itemAbsSize = '0 0 0';
98  SUPER(XonoticScreenshotList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
99 
100  me.itemAbsSize.y = absSize.y * me.itemHeight;
101  me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
102  me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
103  me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
104  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
105 
106  me.columnNameOrigin = me.realFontSize.x;
107  me.columnNameSize = 1 - 2 * me.realFontSize.x;
108 }
109 
111 {
112  if (me.newSlideShowScreenshotTime)
113  me.startSlideShow(me);
114  float selectedItem_save = me.selectedItem;
115  SUPER(XonoticScreenshotList).setSelected(me, i);
116  if (me.pressed && me.selectedItem != selectedItem_save)
117  {
118  // avoid immediate image loading on quick repeated selection changes
119  me.newScreenshotTime = time + 0.22;
120  }
121  else if (time > me.newScreenshotTime)
122  {
123  me.newScreenshotTime = 0;
124  me.previewScreenshot(me); // load the preview on selection change
125  }
126 }
127 
128 void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
129 {
130  string s;
131  if(isSelected)
132  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
133  else if(isFocused)
134  {
135  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
136  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
137  }
138 
139  s = me.screenshotName(me,i);
140  s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
141  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);
142 }
143 
145 {
146  me.getScreenshots(me);
147  me.previewScreenshot(me);
148 }
149 
151 {
152  me.getScreenshots(me);
153  me.setSelected(me, 0); //always select the first element after a list update
154 }
155 
157 {
158  strfree(me.filterString);
159 
160  if(box.text != "")
161  {
162  if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
163  me.filterString = strzone(box.text);
164  else
165  me.filterString = strzone(strcat("*", box.text, "*"));
166  }
167 
169 }
170 
172 {
173  me.filterBox = box;
174  me.filterTime = time + 0.5;
175 }
176 
178 {
179  if (me.filterTime && time > me.filterTime)
180  {
181  ScreenshotList_Filter_Change(me.filterBox, me);
182  me.filterTime = 0;
183  }
184  if (me.newScreenshotTime && time > me.newScreenshotTime)
185  {
186  me.previewScreenshot(me);
187  me.newScreenshotTime = 0;
188  }
189  else if (me.newSlideShowScreenshotTime && time > me.newSlideShowScreenshotTime)
190  {
191  if (me.selectedItem == me.nItems - 1) //last screenshot?
192  {
193  // restart from the first screenshot
194  me.setSelected(me, 0);
195  me.goScreenshot(me, +0);
196  }
197  else
198  me.goScreenshot(me, +1);
199  }
200  SUPER(XonoticScreenshotList).draw(me);
201 }
202 
204 {
205  me.newSlideShowScreenshotTime = time + 3;
206 }
207 
209 {
210  me.newSlideShowScreenshotTime = 0;
211 }
212 
214 {
215  if(!me.screenshotViewerDialog)
216  return;
217  me.setSelected(me, me.selectedItem + d);
218  me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
219 }
220 
222 {
223  me.screenshotViewerDialog.loadScreenshot(me.screenshotViewerDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
224  // pop up screenshot
225  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));
226 }
227 
229 {
230  if(!me.screenshotBrowserDialog)
231  return;
232  if (me.nItems <= 0)
233  me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, "");
234  else
235  me.screenshotBrowserDialog.loadPreviewScreenshot(me.screenshotBrowserDialog, strcat("/screenshots/", strdecolorize(me.screenshotName(me,me.selectedItem))));
236 }
237 
239 {
240  me.startScreenshot(me);
241 }
242 
244 {
245  me.startScreenshot(me);
246 }
247 
248 float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
249 {
250  if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_MOUSE2 || scan == K_SPACE) {
251  me.startScreenshot(me);
252  return 1;
253  }
254  return SUPER(XonoticScreenshotList).keyDown(me, scan, ascii, shift);
255 }
void XonoticScreenshotList_configureXonoticScreenshotList(entity me)
void StartScreenshot_Click(entity btn, entity me)
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
void XonoticScreenshotList_startSlideShow(entity me)
void XonoticScreenshotList_setSelected(entity me, float i)
void XonoticScreenshotList_draw(entity me)
entity() spawn
void DialogOpenButton_Click_withCoords(entity button, entity tab, vector theOrigin, vector theSize)
void ScreenshotList_Filter_Change(entity box, entity me)
void XonoticScreenshotList_destroy(entity me)
void XonoticScreenshotList_getScreenshots(entity me)
float XonoticScreenshotList_keyDown(entity me, float scan, float ascii, float shift)
float K_SPACE
Definition: keycodes.qc:10
float K_KP_ENTER
Definition: keycodes.qc:74
#define SUPER(cname)
Definition: oo.qh:219
#define buf_create
Definition: dpextensions.qh:63
void XonoticScreenshotList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float K_MOUSE2
Definition: keycodes.qc:130
#define NULL
Definition: post.qh:17
#define strstrofs
Definition: dpextensions.qh:42
void XonoticScreenshotList_showNotify(entity me)
void XonoticScreenshotList_doubleClickListBoxItem(entity me, float i, vector where)
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector eX
Definition: vector.qh:44
entity makeXonoticScreenshotList()
void XonoticScreenshotList_stopSlideShow(entity me)
void ScreenshotList_Refresh_Click(entity btn, entity me)
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition: color.qh:183
#define strfree(this)
Definition: string.qh:56
float K_ENTER
Definition: keycodes.qc:8
void ScreenshotList_Filter_Would_Change(entity box, entity me)
void XonoticScreenshotList_startScreenshot(entity me)
float time
Definition: csprogsdefs.qc:16
string XonoticScreenshotList_screenshotName(entity me, float i)
void XonoticScreenshotList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticScreenshotList_goScreenshot(entity me, float d)
void getScreenshots_for_ext(entity me, string ext, float subdir)
void XonoticScreenshotList_previewScreenshot(entity me)