]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_screenshot_screenshotviewer.c
99e8752b7a48536d688399c3321564305fbb9208
[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, slideShowButton, entity, 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 == scrImage)
24                 return;
25         if (me.currentScrPath)
26                 strunzone(me.currentScrPath);
27         me.currentScrPath = strzone(scrImage);
28         me.screenshotImage.configureXonoticScreenshotImage(me.screenshotImage, me.currentScrPath);
29 }
30 void prevScreenshot_Click(entity btn, entity me)
31 {
32         me.scrList.goScreenshot(me.scrList, -1);
33 }
34 void nextScreenshot_Click(entity btn, entity me)
35 {
36         me.scrList.goScreenshot(me.scrList, +1);
37 }
38 void increaseZoom_Click(entity btn, entity me)
39 {
40         me.screenshotImage.setZoom(me.screenshotImage, 2);
41 }
42 void decreaseZoom_Click(entity btn, entity me)
43 {
44         me.screenshotImage.setZoom(me.screenshotImage, 1/2);
45 }
46 void resetZoom_Click(entity btn, entity me)
47 {
48         me.screenshotImage.setZoom(me.screenshotImage, 0);
49 }
50 void toggleSlideShow_Click(entity btn, entity me)
51 {
52         if (me.slideShowButton.forcePressed)
53         {
54                 me.scrList.stopSlideShow(me.scrList);
55                 me.slideShowButton.forcePressed = 0;
56         }
57         else
58         {
59                 me.scrList.startSlideShow(me.scrList);
60                 me.slideShowButton.forcePressed = 1;
61         }
62 }
63 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
64 {
65         switch(key)
66         {
67                 case K_KP_LEFTARROW:
68                 case K_LEFTARROW:
69                         me.scrList.goScreenshot(me.scrList, -1);
70                         return 1;
71                 case K_KP_RIGHTARROW:
72                 case K_RIGHTARROW:
73                         me.scrList.goScreenshot(me.scrList, +1);
74                         return 1;
75                 case K_KP_ENTER:
76                 case K_ENTER:
77                 case K_SPACE:
78                         // we cannot use SPACE/ENTER directly, as in a dialog they are needed
79                         // to press buttons while browsing with only the keyboard
80                         if (shift & S_CTRL)
81                         {
82                                 toggleSlideShow_Click(world, me);
83                                 return 1;
84                         }
85                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
86                 default:
87                         // mousewheel doesn't always reach the first/last screenshot
88                         if (key == K_MWHEELUP)
89                                 key = K_PGUP;
90                         else if (key == K_MWHEELDOWN)
91                                 key = K_PGDN;
92                         if (me.scrList.keyDown(me.scrList, key, ascii, shift))
93                         {
94                                 // keyDown has already changed the selected item
95                                 me.scrList.goScreenshot(me.scrList, 0);
96                                 return 1;
97                         }
98                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
99         }
100 }
101 void XonoticScreenshotViewerDialog_close(entity me)
102 {
103         me.scrList.stopSlideShow(me.scrList);
104         me.slideShowButton.forcePressed = 0;
105         SUPER(XonoticScreenshotViewerDialog).close(me);
106 }
107 void XonoticScreenshotViewerDialog_fill(entity me)
108 {
109         entity e;
110         me.TR(me);
111                 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
112                         me.screenshotImage = e;
113         me.gotoRC(me, me.rows - 1, 0);
114                 me.TDempty(me, 1/20 * me.columns);
115                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
116                         e.onClick = decreaseZoom_Click;
117                         e.onClickEntity = me;
118                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
119                         e.onClick = increaseZoom_Click;
120                         e.onClickEntity = me;
121                 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton("reset", '0 0 0'));
122                         e.onClick = resetZoom_Click;
123                         e.onClickEntity = me;
124
125                 me.TDempty(me, 2/20 * me.columns);
126                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton("Previous", '0 0 0'));
127                         e.onClick = prevScreenshot_Click;
128                         e.onClickEntity = me;
129                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton("Next", '0 0 0'));
130                         e.onClick = nextScreenshot_Click;
131                         e.onClickEntity = me;
132
133                 me.TDempty(me, 2/20 * me.columns);
134                 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton("Slide show", '0 0 0'));
135                         e.onClick = toggleSlideShow_Click;
136                         e.onClickEntity = me;
137                         me.slideShowButton = e;
138 }
139 #endif