1 #include "dialog_multiplayer_media_screenshot_viewer.qh"
2 #ifndef DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
3 #define DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
5 CLASS(XonoticScreenshotViewerDialog, XonoticDialog)
6 METHOD(XonoticScreenshotViewerDialog, fill, void(entity));
7 METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float));
8 METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string));
9 METHOD(XonoticScreenshotViewerDialog, close, void(entity));
10 ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
11 ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer")
12 ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
13 ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
14 ATTRIB(XonoticScreenshotViewerDialog, columns, float, 4)
15 ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
16 ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
17 ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
18 ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
19 ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
20 ENDCLASS(XonoticScreenshotViewerDialog)
24 float music_playlist_index_backup;
25 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
27 // disable music as it can lag depending on image loading time
28 if(!cvar("menu_screenshotviewer_enablemusic"))
29 if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
32 if(cvar("music_playlist_index") != -1)
34 music_playlist_index_backup = cvar("music_playlist_index");
35 cvar_set("music_playlist_sampleposition0", "0");
36 cvar_set("music_playlist_index", "999");
39 localcmd("\ncd pause\n");
42 if (me.currentScrPath == scrImage)
44 if (me.currentScrPath)
45 strunzone(me.currentScrPath);
46 me.currentScrPath = strzone(scrImage);
47 me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
48 me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
50 void prevScreenshot_Click(entity btn, entity me)
52 me.scrList.goScreenshot(me.scrList, -1);
54 void nextScreenshot_Click(entity btn, entity me)
56 me.scrList.goScreenshot(me.scrList, +1);
58 void increaseZoom_Click(entity btn, entity me)
60 me.screenshotImage.setZoom(me.screenshotImage, -2, false);
62 void decreaseZoom_Click(entity btn, entity me)
64 me.screenshotImage.setZoom(me.screenshotImage, -1/2, false);
66 void resetZoom_Click(entity btn, entity me)
68 me.screenshotImage.setZoom(me.screenshotImage, 0, false);
70 void toggleSlideShow_Click(entity btn, entity me)
72 if (me.slideShowButton.forcePressed)
74 me.scrList.stopSlideShow(me.scrList);
75 me.slideShowButton.forcePressed = 0;
79 me.scrList.startSlideShow(me.scrList);
80 me.slideShowButton.forcePressed = 1;
83 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
89 me.scrList.goScreenshot(me.scrList, -1);
93 me.scrList.goScreenshot(me.scrList, +1);
98 // we cannot use SPACE/ENTER directly, as in a dialog they are needed
99 // to press buttons while browsing with only the keyboard
102 toggleSlideShow_Click(NULL, me);
105 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
107 if (key == K_MWHEELUP || ascii == '+')
109 me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
112 else if (key == K_MWHEELDOWN || ascii == '-')
114 me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
117 if (me.scrList.keyDown(me.scrList, key, ascii, shift))
119 // keyDown has already changed the selected item
120 me.scrList.goScreenshot(me.scrList, 0);
123 return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
126 void XonoticScreenshotViewerDialog_close(entity me)
129 if(!cvar("menu_screenshotviewer_enablemusic"))
130 if(cvar("music_playlist_index") == 999)
132 cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
135 localcmd("\ncd resume\n");
137 me.scrList.stopSlideShow(me.scrList);
138 me.slideShowButton.forcePressed = 0;
139 SUPER(XonoticScreenshotViewerDialog).close(me);
141 void XonoticScreenshotViewerDialog_fill(entity me)
145 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
146 e.showTitle = 0; // dialog title is enough
147 me.screenshotImage = e;
148 me.gotoRC(me, me.rows - 1, 0);
149 me.TDempty(me, 1/20 * me.columns);
150 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
151 e.onClick = decreaseZoom_Click;
152 e.onClickEntity = me;
153 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
154 e.onClick = increaseZoom_Click;
155 e.onClickEntity = me;
156 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
157 e.onClick = resetZoom_Click;
158 e.onClickEntity = me;
160 me.TDempty(me, 2/20 * me.columns);
161 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
162 e.onClick = prevScreenshot_Click;
163 e.onClickEntity = me;
164 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
165 e.onClick = nextScreenshot_Click;
166 e.onClickEntity = me;
168 me.TDempty(me, 2/20 * me.columns);
169 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
170 e.onClick = toggleSlideShow_Click;
171 e.onClickEntity = me;
172 me.slideShowButton = e;