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