]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/borderimage.qc
6b6f4693dc4a48d83823a7144c29f033daacc632
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / borderimage.qc
1 #ifndef ITEM_BORDERIMAGE_H
2 #define ITEM_BORDERIMAGE_H
3 #include "label.qc"
4 CLASS(BorderImage, Label)
5         METHOD(BorderImage, configureBorderImage, void(entity, string, float, vector, string, float))
6         METHOD(BorderImage, resizeNotify, void(entity, vector, vector, vector, vector))
7         METHOD(BorderImage, recalcPositionWithText, void(entity, string))
8         ATTRIB(BorderImage, isBold, float, 1)
9         METHOD(BorderImage, draw, void(entity))
10         ATTRIB(BorderImage, src, string, string_null)
11         ATTRIB(BorderImage, borderHeight, float, 0)
12         ATTRIB(BorderImage, borderVec, vector, '0 0 0')
13         ATTRIB(BorderImage, color, vector, '1 1 1')
14         ATTRIB(BorderImage, closeButton, entity, NULL)
15         ATTRIB(BorderImage, realFontSize_Nexposeed, vector, '0 0 0')
16         ATTRIB(BorderImage, realOrigin_Nexposeed, vector, '0 0 0')
17         ATTRIB(BorderImage, isNexposeeTitleBar, float, 0)
18         ATTRIB(BorderImage, zoomedOutTitleBarPosition, float, 0)
19         ATTRIB(BorderImage, zoomedOutTitleBar, float, 0)
20         ATTRIB(BorderImage, overrideRealOrigin, vector, '0 1 0')
21         ATTRIB(BorderImage, saveRelOrigin, vector, '0 0 0')
22         ATTRIB(BorderImage, saveRelSize, vector, '0 0 0')
23 ENDCLASS(BorderImage)
24 #endif
25
26 #ifdef IMPLEMENTATION
27 void BorderImage_recalcPositionWithText(entity me, string t)
28 {
29         if(me.isNexposeeTitleBar)
30         {
31                 vector scrs;
32                 scrs = eX * conwidth + eY * conheight;
33                 me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_smallOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_smallSize, scrs));
34                 SUPER(BorderImage).recalcPositionWithText(me, t);
35                 me.realOrigin_y = me.realFontSize.y * me.zoomedOutTitleBarPosition;
36                 me.realOrigin_Nexposeed = me.realOrigin;
37                 me.realFontSize_Nexposeed = me.realFontSize;
38                 me.resizeNotify(me, me.saveRelOrigin, me.saveRelSize, boxToGlobal(me.parent.Nexposee_initialOrigin, '0 0 0', scrs), boxToGlobalSize(me.parent.Nexposee_initialSize, scrs));
39         }
40         SUPER(BorderImage).recalcPositionWithText(me, t);
41 }
42 void BorderImage_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
43 {
44         me.isNexposeeTitleBar = 0;
45         if(me.zoomedOutTitleBar)
46                 if(me.parent.parent.instanceOfNexposee)
47                         if(me.parent.instanceOfDialog)
48                                 if(me == me.parent.frame)
49                                         me.isNexposeeTitleBar = 1;
50         me.saveRelOrigin = relOrigin;
51         me.saveRelSize = relSize;
52         SUPER(BorderImage).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
53         me.borderVec_x = me.borderHeight / absSize.x;
54         me.borderVec_y = me.borderHeight / absSize.y;
55         me.realOrigin_y = 0.5 * (me.borderVec.y - me.realFontSize.y);
56         if(me.closeButton)
57         {
58                 // move the close button to the right place
59                 me.closeButton.Container_origin = '1 0 0' * (1 - me.borderVec.x);
60                 me.closeButton.Container_size = me.borderVec;
61                 me.closeButton.color = me.color;
62                 me.closeButton.colorC = me.color;
63                 me.closeButton.colorF = me.color;
64         }
65 }
66 void BorderImage_configureBorderImage(entity me, string theTitle, float sz, vector theColor, string path, float theBorderHeight)
67 {
68         me.configureLabel(me, theTitle, sz, 0.5);
69         me.src = path;
70         me.color = theColor;
71         me.borderHeight = theBorderHeight;
72 }
73 void BorderImage_draw(entity me)
74 {
75         if(me.src)
76                 draw_BorderPicture('0 0 0', me.src, '1 1 0', me.color, 1, me.borderVec);
77
78         if(me.fontSize > 0)
79         {
80                 if(me.recalcPos)
81                         me.recalcPositionWithText(me, me.text);
82
83                 if(me.isNexposeeTitleBar)
84                 {
85                         vector ro, rf, df;
86
87                         // me.parent.Nexposee_animationFactor 0 (small) or 1 (full)
88                         // default values are for 1
89                         ro = me.realOrigin;
90                         rf = me.realFontSize;
91                         df = draw_fontscale;
92                         me.realOrigin = ro * me.parent.Nexposee_animationFactor + me.realOrigin_Nexposeed * (1 - me.parent.Nexposee_animationFactor);
93                         me.realFontSize = rf * me.parent.Nexposee_animationFactor + me.realFontSize_Nexposeed * (1 - me.parent.Nexposee_animationFactor);
94                         draw_fontscale = globalToBoxSize(boxToGlobalSize(df, me.realFontSize), rf);
95
96                         SUPER(BorderImage).draw(me);
97
98                         // me.Nexposee_animationState 0 (small) or 1 (full)
99                         // default values are for 1
100                         me.realOrigin = ro;
101                         me.realFontSize = rf;
102                         draw_fontscale = df;
103                 }
104                 else
105                         SUPER(BorderImage).draw(me);
106         }
107         else
108         {
109                 SUPER(BorderImage).draw(me);
110         }
111 }
112 #endif