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