]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/screenshotimage.qc
82ff4ba7b2b8dad148e2b4f20cf854271ce95838
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / screenshotimage.qc
1 #include "screenshotimage.qh"
2
3 entity makeXonoticScreenshotImage()
4 {
5         entity me;
6         me = NEW(XonoticScreenshotImage);
7         me.configureXonoticScreenshotImage(me);
8         return me;
9 }
10
11 void XonoticScreenshotImage_configureXonoticScreenshotImage(entity me)
12 {
13         me.configureXonoticImage(me, string_null, -2);
14         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)
15         me.zoomSnapToTheBox = false; // disabled: it's cooler
16 }
17
18 void XonoticScreenshotImage_load(entity me, string theImage)
19 {
20         me.screenshotTime = time;
21         me.src = theImage;
22         if (me.screenshotTitle)
23                 strunzone(me.screenshotTitle);
24         me.screenshotTitle = strzone(substring(me.src, 13, strlen(theImage) - 13)); //strip "/screenshots/"
25
26         me.initZoom(me); // this image may have a different size
27         me.setZoom(me, 0, 0);
28 }
29
30 float XonoticScreenshotImage_mousePress(entity me, vector coords)
31 {
32         return me.drag_setStartPos(me, coords);
33 }
34
35 float XonoticScreenshotImage_mouseDrag(entity me, vector coords)
36 {
37         return me.drag(me, coords);
38 }
39
40 float XonoticScreenshotImage_mouseMove(entity me, vector coords)
41 {
42         return me.drag_setStartPos(me, coords);
43 }
44
45 void XonoticScreenshotImage_draw(entity me)
46 {
47         if (me.src != "")
48         {
49                 float theAlpha;
50                 SUPER(XonoticScreenshotImage).draw(me);
51                 if (me.showTitle && time < me.screenshotTime + 4) // 3 seconds at full alpha, 1 second fading out
52                 {
53                         theAlpha = (4 - (time - me.screenshotTime));
54                         draw_CenterText('0.5 0 0', me.screenshotTitle, me.realFontSize, '1 1 1', theAlpha, false);
55                 }
56                 if (time < me.zoomTime + 2) // 1 seconds at full alpha, 1 second fading out
57                 {
58                         string zoomString;
59                         float z;
60                         z = me.zoomFactor * 100;
61                         if (z - floor(z) == 0)
62                                 zoomString = sprintf("%d%%", z);
63                         else
64                                 zoomString = sprintf("%.2f%%", z);
65                         theAlpha = (2 - (time - me.zoomTime));
66                         draw_Text('0.05 0.95 0', zoomString, me.realFontSize, '1 1 1', theAlpha, false);
67                 }
68         }
69 }
70
71 void XonoticScreenshotImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
72 {
73         SUPER(XonoticScreenshotImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
74         me.realFontSize_y = me.fontSize / absSize.y;
75         me.realFontSize_x = me.fontSize / absSize.x;
76 }