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