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