]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c
Add a refresh button
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_screenshot_screenshotviewer.c
1 #ifdef INTERFACE
2 CLASS(XonoticScreenshotViewerDialog) EXTENDS(XonoticRootDialog)
3         METHOD(XonoticScreenshotViewerDialog, fill, void(entity))
4         METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float))
5         METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string))
6         ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
7         ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
8         ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
9         ATTRIB(XonoticScreenshotViewerDialog, columns, float, 6.5)
10         ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
11         ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_MULTIPLAYER)
12         ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
13         ATTRIB(XonoticScreenshotViewerDialog, titleLabel, entity, NULL)
14         
15         ATTRIB(XonoticScreenshotViewerDialog, currentScrName, string, string_null)
16         ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
17 ENDCLASS(XonoticScreenshotViewerDialog)
18 #endif
19
20 #ifdef IMPLEMENTATION
21 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
22 {
23         if (me.currentScrPath)
24                 strunzone(me.currentScrPath);
25         me.currentScrPath = strzone(scrImage);
26         me.screenshotImage.configureImage(me.screenshotImage, me.currentScrPath);
27         me.screenshotImage.updateAspect(me.screenshotImage);
28
29         if (me.currentScrName)
30                 strunzone(me.currentScrName);
31         me.currentScrName = strzone(substring(scrImage, 13, strlen(scrImage) - 13));
32         me.titleLabel.setText(me.titleLabel, me.currentScrName);
33 }
34 void prevScreenshot_Click(entity btn, entity me)
35 {
36         me.scrList.goScreenshot(me.scrList, -1);
37 }
38 void nextScreenshot_Click(entity btn, entity me)
39 {
40         me.scrList.goScreenshot(me.scrList, +1);
41 }
42
43 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
44 {
45         switch(key)
46         {
47                 case K_KP_LEFTARROW:
48                 case K_LEFTARROW:
49                         me.scrList.goScreenshot(me.scrList, -1);
50                         return 1;
51                 case K_KP_RIGHTARROW:
52                 case K_RIGHTARROW:
53                         me.scrList.goScreenshot(me.scrList, +1);
54                         return 1;
55                 default:
56                         if (me.scrList.keyDown(me.scrList, key, ascii, shift))
57                         {
58                                 // keyDown has already changed the selected item
59                                 me.scrList.goScreenshot(me.scrList, 0);
60                                 return 1;
61                         }
62                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
63         }
64 }
65 void XonoticScreenshotViewerDialog_fill(entity me)
66 {
67         entity e;
68
69         me.TR(me);
70                 me.TD(me, me.rows - 1, me.columns, e = makeXonoticImage(string_null, -1));
71                         me.screenshotImage = e;
72                 me.TD(me, 1, me.columns, e = makeXonoticTextLabel(0.5, ""));
73                         me.titleLabel = e;
74         me.gotoRC(me, me.rows - 1, 0);
75                 me.TD(me, 1, me.columns/2, e = makeXonoticButton("Previous", '0 0 0'));
76                         e.onClick = prevScreenshot_Click;
77                         e.onClickEntity = me;
78                 me.TD(me, 1, me.columns/2, e = makeXonoticButton("Next", '0 0 0'));
79                         e.onClick = nextScreenshot_Click;
80                         e.onClickEntity = me;
81 }
82 #endif