]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/screenshotimage.qc
Merge branch 'TimePath/qc_updates' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / screenshotimage.qc
1 #ifndef SCREENSHOTIMAGE_H
2 #define SCREENSHOTIMAGE_H
3 #include "image.qc"
4 CLASS(XonoticScreenshotImage, XonoticImage)
5         METHOD(XonoticScreenshotImage, configureXonoticScreenshotImage, void(entity))
6         METHOD(XonoticScreenshotImage, load, void(entity, string))
7         METHOD(XonoticScreenshotImage, draw, void(entity))
8         ATTRIB(XonoticScreenshotImage, focusable, float, 1) // mousePress and mouseDrag work only if focusable is set
9         METHOD(XonoticScreenshotImage, mousePress, float(entity, vector))
10         METHOD(XonoticScreenshotImage, mouseDrag, float(entity, vector))
11         METHOD(XonoticScreenshotImage, mouseMove, float(entity, vector))
12         METHOD(XonoticScreenshotImage, resizeNotify, void(entity, vector, vector, vector, vector))
13         ATTRIB(XonoticScreenshotImage, realFontSize, vector, '0 0 0')
14         ATTRIB(XonoticScreenshotImage, fontSize, float, SKINFONTSIZE_NORMAL)
15         ATTRIB(XonoticScreenshotImage, showTitle, float, 1)
16         ATTRIB(XonoticScreenshotImage, screenshotTime, float, 0)
17         ATTRIB(XonoticScreenshotImage, screenshotTitle, string, string_null)
18 ENDCLASS(XonoticScreenshotImage)
19 entity makeXonoticScreenshotImage();
20 #endif
21
22 #ifdef IMPLEMENTATION
23 entity makeXonoticScreenshotImage()
24 {
25         entity me;
26         me = NEW(XonoticScreenshotImage);
27         me.configureXonoticScreenshotImage(me);
28         return me;
29 }
30
31 void XonoticScreenshotImage_configureXonoticScreenshotImage(entity me)
32 {
33         me.configureXonoticImage(me, string_null, -2);
34         me.zoomLimitedByTheBox = false; // enable this to forbid enlarging the image more than the containing box (if making use of draw_SetClip is a too bad thing)
35         me.zoomSnapToTheBox = false; // disabled: it's cooler
36 }
37
38 void XonoticScreenshotImage_load(entity me, string theImage)
39 {
40         me.screenshotTime = time;
41         me.src = theImage;
42         if (me.screenshotTitle)
43                 strunzone(me.screenshotTitle);
44         me.screenshotTitle = strzone(substring(me.src, 13, strlen(theImage) - 13)); //strip "/screenshots/"
45
46         me.initZoom(me); // this image may have a different size
47         me.setZoom(me, 0, 0);
48 }
49
50 float XonoticScreenshotImage_mousePress(entity me, vector coords)
51 {
52         return me.drag_setStartPos(me, coords);
53 }
54
55 float XonoticScreenshotImage_mouseDrag(entity me, vector coords)
56 {
57         return me.drag(me, coords);
58 }
59
60 float XonoticScreenshotImage_mouseMove(entity me, vector coords)
61 {
62         return me.drag_setStartPos(me, coords);
63 }
64
65 void XonoticScreenshotImage_draw(entity me)
66 {
67         if (me.src != "")
68         {
69                 float theAlpha;
70                 SUPER(XonoticScreenshotImage).draw(me);
71                 if (me.showTitle && time < me.screenshotTime + 4) // 3 seconds at full alpha, 1 second fading out
72                 {
73                         theAlpha = (4 - (time - me.screenshotTime));
74                         draw_CenterText('0.5 0 0', me.screenshotTitle, me.realFontSize, '1 1 1', theAlpha, false);
75                 }
76                 if (time < me.zoomTime + 2) // 1 seconds at full alpha, 1 second fading out
77                 {
78                         string zoomString;
79                         float z;
80                         z = me.zoomFactor * 100;
81                         if (z - floor(z) == 0)
82                                 zoomString = sprintf("%d%%", z);
83                         else
84                                 zoomString = sprintf("%.2f%%", z);
85                         theAlpha = (2 - (time - me.zoomTime));
86                         draw_Text('0.05 0.95 0', zoomString, me.realFontSize, '1 1 1', theAlpha, false);
87                 }
88         }
89 }
90
91 void XonoticScreenshotImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
92 {
93         SUPER(XonoticScreenshotImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
94         me.realFontSize_y = me.fontSize / absSize.y;
95         me.realFontSize_x = me.fontSize / absSize.x;
96 }
97 #endif