]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c
Fix minor issues with mouse wheel up/down keys
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_screenshot_screenshotviewer.c
1 #ifdef INTERFACE
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, currentScrPath, string, string_null)
16 ENDCLASS(XonoticScreenshotViewerDialog)
17 #endif
18
19 #ifdef IMPLEMENTATION
20 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
21 {
22         if (me.currentScrPath == scrImage)
23                 return;
24         if (me.currentScrPath)
25                 strunzone(me.currentScrPath);
26         me.currentScrPath = strzone(scrImage);
27         me.screenshotImage.configureXonoticScreenshotImage(me.screenshotImage, me.currentScrPath);
28 }
29 void prevScreenshot_Click(entity btn, entity me)
30 {
31         me.scrList.goScreenshot(me.scrList, -1);
32 }
33 void nextScreenshot_Click(entity btn, entity me)
34 {
35         me.scrList.goScreenshot(me.scrList, +1);
36 }
37 void startSlideShow_Click(entity btn, entity me)
38 {
39         me.scrList.startSlideShow(me.scrList);
40 }
41 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
42 {
43         switch(key)
44         {
45                 case K_LEFTARROW:
46                         me.scrList.goScreenshot(me.scrList, -1);
47                         return 1;
48                 case K_KP_RIGHTARROW:
49                 case K_RIGHTARROW:
50                         me.scrList.goScreenshot(me.scrList, +1);
51                         return 1;
52                 case K_KP_ENTER:
53                 case K_ENTER:
54                 case K_SPACE:
55                         // we cannot use SPACE/ENTER directly, as in a dialog they are needed
56                         // to press buttons while browsing with only the keyboard
57                         if (shift & S_CTRL)
58                         {
59                                 me.scrList.startSlideShow(me.scrList);
60                                 return 1;
61                         }
62                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
63                 default:
64                         // mousewheel doesn't always reach the first/last screenshot
65                         if (key == K_MWHEELUP)
66                                 key = K_PGUP;
67                         else if (key == K_MWHEELDOWN)
68                                 key = K_PGDN;
69                         if (me.scrList.keyDown(me.scrList, key, ascii, shift))
70                         {
71                                 // keyDown has already changed the selected item
72                                 me.scrList.goScreenshot(me.scrList, 0);
73                                 return 1;
74                         }
75                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
76         }
77 }
78 void XonoticScreenshotViewerDialog_close(entity me)
79 {
80         me.scrList.stopSlideShow(me.scrList);
81         SUPER(XonoticScreenshotViewerDialog).close(me);
82 }
83 void XonoticScreenshotViewerDialog_fill(entity me)
84 {
85         entity e;
86         me.TR(me);
87                 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
88                         me.screenshotImage = e;
89         me.gotoRC(me, me.rows - 1, 0);
90                 me.TDempty(me, 1/4);
91                 me.TD(me, 1, 1, e = makeXonoticButton("Previous", '0 0 0'));
92                         e.onClick = prevScreenshot_Click;
93                         e.onClickEntity = me;
94                 me.TDempty(me, 1/4);
95                 me.TD(me, 1, 1, e = makeXonoticButton("Start slide show", '0 0 0'));
96                         e.onClick = startSlideShow_Click;
97                         e.onClickEntity = me;
98                 me.TDempty(me, 1/4);
99                 me.TD(me, 1, 1, e = makeXonoticButton("Next", '0 0 0'));
100                         e.onClick = nextScreenshot_Click;
101                         e.onClickEntity = me;
102 }
103 #endif