1 #ifndef DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
2 #define DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
4 CLASS(XonoticScreenshotViewerDialog, XonoticDialog)
5 METHOD(XonoticScreenshotViewerDialog, fill, void(entity));
6 METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float));
7 METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string));
8 METHOD(XonoticScreenshotViewerDialog, close, void(entity));
9 ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
10 ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer")
11 ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
12 ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
13 ATTRIB(XonoticScreenshotViewerDialog, columns, float, 4)
14 ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
15 ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
16 ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
17 ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
18 ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
19 ENDCLASS(XonoticScreenshotViewerDialog)
23 float music_playlist_index_backup;
24 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
26 // disable music as it can lag depending on image loading time
27 if(!cvar("menu_screenshotviewer_enablemusic"))
28 if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
31 if(cvar("music_playlist_index") != -1)
33 music_playlist_index_backup = cvar("music_playlist_index");
34 cvar_set("music_playlist_sampleposition0", "0");
35 cvar_set("music_playlist_index", "999");
38 localcmd("\ncd pause\n");
41 if (me.currentScrPath == scrImage)
43 if (me.currentScrPath)
44 strunzone(me.currentScrPath);
45 me.currentScrPath = strzone(scrImage);
46 me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
47 me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
49 void prevScreenshot_Click(entity btn, entity me)
51 me.scrList.goScreenshot(me.scrList, -1);
53 void nextScreenshot_Click(entity btn, entity me)
55 me.scrList.goScreenshot(me.scrList, +1);
57 void increaseZoom_Click(entity btn, entity me)
59 me.screenshotImage.setZoom(me.screenshotImage, -2, false);
61 void decreaseZoom_Click(entity btn, entity me)
63 me.screenshotImage.setZoom(me.screenshotImage, -1/2, false);
65 void resetZoom_Click(entity btn, entity me)
67 me.screenshotImage.setZoom(me.screenshotImage, 0, false);
69 void toggleSlideShow_Click(entity btn, entity me)
71 if (me.slideShowButton.forcePressed)
73 me.scrList.stopSlideShow(me.scrList);
74 me.slideShowButton.forcePressed = 0;
78 me.scrList.startSlideShow(me.scrList);
79 me.slideShowButton.forcePressed = 1;
82 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
88 me.scrList.goScreenshot(me.scrList, -1);
92 me.scrList.goScreenshot(me.scrList, +1);
97 // we cannot use SPACE/ENTER directly, as in a dialog they are needed
98 // to press buttons while browsing with only the keyboard
101 toggleSlideShow_Click(world, me);
104 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
106 if (key == K_MWHEELUP || ascii == '+')
108 me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
111 else if (key == K_MWHEELDOWN || ascii == '-')
113 me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
116 if (me.scrList.keyDown(me.scrList, key, ascii, shift))
118 // keyDown has already changed the selected item
119 me.scrList.goScreenshot(me.scrList, 0);
122 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
125 void XonoticScreenshotViewerDialog_close(entity me)
128 if(!cvar("menu_screenshotviewer_enablemusic"))
129 if(cvar("music_playlist_index") == 999)
131 cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
134 localcmd("\ncd resume\n");
136 me.scrList.stopSlideShow(me.scrList);
137 me.slideShowButton.forcePressed = 0;
138 SUPER(XonoticScreenshotViewerDialog).close(me);
140 void XonoticScreenshotViewerDialog_fill(entity me)
144 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
145 e.showTitle = 0; // dialog title is enough
146 me.screenshotImage = e;
147 me.gotoRC(me, me.rows - 1, 0);
148 me.TDempty(me, 1/20 * me.columns);
149 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
150 e.onClick = decreaseZoom_Click;
151 e.onClickEntity = me;
152 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
153 e.onClick = increaseZoom_Click;
154 e.onClickEntity = me;
155 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
156 e.onClick = resetZoom_Click;
157 e.onClickEntity = me;
159 me.TDempty(me, 2/20 * me.columns);
160 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
161 e.onClick = prevScreenshot_Click;
162 e.onClickEntity = me;
163 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
164 e.onClick = nextScreenshot_Click;
165 e.onClickEntity = me;
167 me.TDempty(me, 2/20 * me.columns);
168 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
169 e.onClick = toggleSlideShow_Click;
170 e.onClickEntity = me;
171 me.slideShowButton = e;