2 CLASS(XonoticScreenshotViewerDialog) EXTENDS(XonoticDialog)
3 METHOD(XonoticScreenshotViewerDialog, fill, void(entity))
4 METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float))
5 METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string))
6 METHOD(XonoticScreenshotViewerDialog, close, void(entity))
7 ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
8 ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer")
9 ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
10 ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
11 ATTRIB(XonoticScreenshotViewerDialog, columns, float, 4)
12 ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
13 ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
14 ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
15 ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
16 ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
17 ENDCLASS(XonoticScreenshotViewerDialog)
21 float music_playlist_index_backup;
22 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
24 // disable music as it can lag depending on image loading time
25 if(!cvar("menu_screenshotviewer_enablemusic"))
26 if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
29 if(cvar("music_playlist_index") != -1)
31 music_playlist_index_backup = cvar("music_playlist_index");
32 cvar_set("music_playlist_sampleposition0", "0");
33 cvar_set("music_playlist_index", "999");
36 localcmd("\ncd pause\n");
39 if (me.currentScrPath == scrImage)
41 if (me.currentScrPath)
42 strunzone(me.currentScrPath);
43 me.currentScrPath = strzone(scrImage);
44 me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
45 me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
47 void prevScreenshot_Click(entity btn, entity me)
49 me.scrList.goScreenshot(me.scrList, -1);
51 void nextScreenshot_Click(entity btn, entity me)
53 me.scrList.goScreenshot(me.scrList, +1);
55 void increaseZoom_Click(entity btn, entity me)
57 me.screenshotImage.setZoom(me.screenshotImage, -2, FALSE);
59 void decreaseZoom_Click(entity btn, entity me)
61 me.screenshotImage.setZoom(me.screenshotImage, -1/2, FALSE);
63 void resetZoom_Click(entity btn, entity me)
65 me.screenshotImage.setZoom(me.screenshotImage, 0, FALSE);
67 void toggleSlideShow_Click(entity btn, entity me)
69 if (me.slideShowButton.forcePressed)
71 me.scrList.stopSlideShow(me.scrList);
72 me.slideShowButton.forcePressed = 0;
76 me.scrList.startSlideShow(me.scrList);
77 me.slideShowButton.forcePressed = 1;
80 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
86 me.scrList.goScreenshot(me.scrList, -1);
90 me.scrList.goScreenshot(me.scrList, +1);
95 // we cannot use SPACE/ENTER directly, as in a dialog they are needed
96 // to press buttons while browsing with only the keyboard
99 toggleSlideShow_Click(world, me);
102 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
104 if (key == K_MWHEELUP || ascii == '+')
106 me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
109 else if (key == K_MWHEELDOWN || ascii == '-')
111 me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
114 if (me.scrList.keyDown(me.scrList, key, ascii, shift))
116 // keyDown has already changed the selected item
117 me.scrList.goScreenshot(me.scrList, 0);
120 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
123 void XonoticScreenshotViewerDialog_close(entity me)
126 if(!cvar("menu_screenshotviewer_enablemusic"))
127 if(cvar("music_playlist_index") == 999)
129 cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
132 localcmd("\ncd resume\n");
134 me.scrList.stopSlideShow(me.scrList);
135 me.slideShowButton.forcePressed = 0;
136 SUPER(XonoticScreenshotViewerDialog).close(me);
138 void XonoticScreenshotViewerDialog_fill(entity me)
142 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
143 e.showTitle = 0; // dialog title is enough
144 me.screenshotImage = e;
145 me.gotoRC(me, me.rows - 1, 0);
146 me.TDempty(me, 1/20 * me.columns);
147 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
148 e.onClick = decreaseZoom_Click;
149 e.onClickEntity = me;
150 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
151 e.onClick = increaseZoom_Click;
152 e.onClickEntity = me;
153 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
154 e.onClick = resetZoom_Click;
155 e.onClickEntity = me;
157 me.TDempty(me, 2/20 * me.columns);
158 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
159 e.onClick = prevScreenshot_Click;
160 e.onClickEntity = me;
161 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
162 e.onClick = nextScreenshot_Click;
163 e.onClickEntity = me;
165 me.TDempty(me, 2/20 * me.columns);
166 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
167 e.onClick = toggleSlideShow_Click;
168 e.onClickEntity = me;
169 me.slideShowButton = e;