]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/item/dialog.c
Tweak the system sound to use 0.5 as the default volume, instead of 1.0. This allows...
[voretournament/voretournament.git] / data / qcsrc / menu / item / dialog.c
1 // Note: this class is called Dialog, but it can also handle a tab under the following conditions:\r
2 // - isTabRoot is 0\r
3 // - backgroundImage is the tab's background\r
4 // - closable is 0\r
5 // - rootDialog is 0\r
6 // - title is ""\r
7 // - marginTop is \r
8 // - intendedHeight ends up to be the tab's actual height, or at least close\r
9 // - titleFontSize is 0\r
10 // - marginTop cancels out as much of titleHeight as needed (that is, it should be actualMarginTop - titleHeight)\r
11 // To ensure the latter, you best create all tabs FIRST and insert the tabbed\r
12 // control to your dialog THEN - with the right height\r
13 //\r
14 // a subclass may help with using this as a tab\r
15 \r
16 #ifdef INTERFACE\r
17 CLASS(Dialog) EXTENDS(InputContainer)\r
18         METHOD(Dialog, configureDialog, void(entity)) // no runtime configuration, all parameters are given in the code!\r
19         METHOD(Dialog, fill, void(entity)) // to be overridden by user to fill the dialog with controls\r
20         METHOD(Dialog, keyDown, float(entity, float, float, float))\r
21         METHOD(Dialog, close, void(entity))\r
22         METHOD(Dialog, addItemSimple, void(entity, float, float, float, float, entity, vector))\r
23 \r
24         METHOD(Dialog, TD, void(entity, float, float, entity))\r
25         METHOD(Dialog, TDNoMargin, void(entity, float, float, entity, vector))\r
26         METHOD(Dialog, TDempty, void(entity, float))\r
27         METHOD(Dialog, setFirstColumn, void(entity, float))\r
28         METHOD(Dialog, TR, void(entity))\r
29         METHOD(Dialog, gotoRC, void(entity, float, float))\r
30 \r
31         ATTRIB(Dialog, isTabRoot, float, 1)\r
32         ATTRIB(Dialog, closeButton, entity, NULL)\r
33         ATTRIB(Dialog, intendedHeight, float, 0)\r
34         ATTRIB(Dialog, itemOrigin, vector, '0 0 0')\r
35         ATTRIB(Dialog, itemSize, vector, '0 0 0')\r
36         ATTRIB(Dialog, itemSpacing, vector, '0 0 0')\r
37         ATTRIB(Dialog, currentRow, float, 0)\r
38         ATTRIB(Dialog, currentColumn, float, 0)\r
39         ATTRIB(Dialog, firstColumn, float, 0)\r
40 \r
41         // to be customized\r
42         ATTRIB(Dialog, closable, float, 1)\r
43         ATTRIB(Dialog, title, string, "Form1") // ;)\r
44         ATTRIB(Dialog, color, vector, '1 0.5 1')\r
45         ATTRIB(Dialog, intendedWidth, float, 0)\r
46         ATTRIB(Dialog, rows, float, 3)\r
47         ATTRIB(Dialog, columns, float, 2)\r
48 \r
49         ATTRIB(Dialog, marginTop, float, 0) // pixels\r
50         ATTRIB(Dialog, marginBottom, float, 0) // pixels\r
51         ATTRIB(Dialog, marginLeft, float, 0) // pixels\r
52         ATTRIB(Dialog, marginRight, float, 0) // pixels\r
53         ATTRIB(Dialog, columnSpacing, float, 0) // pixels\r
54         ATTRIB(Dialog, rowSpacing, float, 0) // pixels\r
55         ATTRIB(Dialog, rowHeight, float, 0) // pixels\r
56         ATTRIB(Dialog, titleHeight, float, 0) // pixels\r
57         ATTRIB(Dialog, titleFontSize, float, 0) // pixels; if 0, title causes no margin\r
58         ATTRIB(Dialog, zoomedOutTitleBarPosition, float, 0)\r
59         ATTRIB(Dialog, zoomedOutTitleBar, float, 0)\r
60 \r
61         ATTRIB(Dialog, backgroundImage, string, string_null)\r
62         ATTRIB(Dialog, closeButtonImage, string, string_null)\r
63 \r
64         ATTRIB(Dialog, frame, entity, NULL)\r
65 ENDCLASS(Dialog)\r
66 #endif\r
67 \r
68 #ifdef IMPLEMENTATION\r
69 void Dialog_Close(entity button, entity me)\r
70 {\r
71         me.close(me);\r
72 }\r
73 \r
74 void fillDialog(entity me)\r
75 {\r
76 }\r
77 \r
78 void addItemSimpleDialog(entity me, float row, float col, float rowspan, float colspan, entity e, vector v)\r
79 {\r
80         //print(vtos(me.itemSpacing), " ", vtos(me.itemSize), "\n");\r
81         vector o, s;\r
82         o = me.itemOrigin + eX * ( col          * me.itemSpacing_x) + eY * ( row          * me.itemSpacing_y);\r
83         s = me.itemSize   + eX * ((colspan - 1) * me.itemSpacing_x) + eY * ((rowspan - 1) * me.itemSpacing_y);\r
84         o_x -= 0.5 * (me.itemSpacing_x - me.itemSize_x) * v_x;\r
85         s_x +=       (me.itemSpacing_x - me.itemSize_x) * v_x;\r
86         o_y -= 0.5 * (me.itemSpacing_y - me.itemSize_y) * v_y;\r
87         s_y +=       (me.itemSpacing_y - me.itemSize_y) * v_y;\r
88         me.addItem(me, e, o, s, 1);\r
89 }\r
90 \r
91 void gotoRCDialog(entity me, float row, float col)\r
92 {\r
93         me.currentRow = row;\r
94         me.currentColumn = col;\r
95 }\r
96 \r
97 void TRDialog(entity me)\r
98 {\r
99         me.currentRow += 1;\r
100         me.currentColumn = me.firstColumn;\r
101 }\r
102 \r
103 void TDDialog(entity me, float rowspan, float colspan, entity e)\r
104 {\r
105         me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, '0 0 0');\r
106         me.currentColumn += colspan;\r
107 }\r
108 \r
109 void TDNoMarginDialog(entity me, float rowspan, float colspan, entity e, vector v)\r
110 {\r
111         me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, v);\r
112         me.currentColumn += colspan;\r
113 }\r
114 \r
115 void setFirstColumnDialog(entity me, float col)\r
116 {\r
117         me.firstColumn = col;\r
118 }\r
119 \r
120 void TDemptyDialog(entity me, float colspan)\r
121 {\r
122         me.currentColumn += colspan;\r
123 }\r
124 \r
125 void configureDialogDialog(entity me)\r
126 {\r
127         entity closebutton;\r
128         float absWidth, absHeight;\r
129 \r
130         me.frame = spawnBorderImage();\r
131         me.frame.configureBorderImage(me.frame, me.title, me.titleFontSize, me.color, me.backgroundImage, me.titleHeight);\r
132         me.frame.zoomedOutTitleBarPosition = me.zoomedOutTitleBarPosition;\r
133         me.frame.zoomedOutTitleBar = me.zoomedOutTitleBar;\r
134         me.frame.alpha = me.alpha;\r
135         me.addItem(me, me.frame, '0 0 0', '1 1 0', 1);\r
136 \r
137         if not(me.titleFontSize)\r
138                 me.titleHeight = 0; // no title bar\r
139 \r
140         absWidth = me.intendedWidth * conwidth;\r
141         absHeight = me.titleHeight + me.marginTop + me.rows * me.rowHeight + (me.rows - 1) * me.rowSpacing + me.marginBottom;\r
142         me.itemOrigin  = eX * (me.marginLeft / absWidth)\r
143                        + eY * ((me.titleHeight + me.marginTop) / absHeight);\r
144         me.itemSize    = eX * ((1 - (me.marginLeft + me.marginRight + me.columnSpacing * (me.columns - 1)) / absWidth) / me.columns)\r
145                        + eY * (me.rowHeight / absHeight);\r
146         me.itemSpacing = me.itemSize\r
147                        + eX * (me.columnSpacing / absWidth)\r
148                        + eY * (me.rowSpacing / absHeight);\r
149         me.intendedHeight = absHeight / conheight;\r
150         me.currentRow = -1;\r
151         me.currentColumn = -1;\r
152 \r
153         me.fill(me);\r
154 \r
155         if(me.closable)\r
156         {\r
157                 closebutton = me.closeButton = spawnButton();\r
158                 closebutton.configureButton(closebutton, "Close", 0, me.closeButtonImage);\r
159                 closebutton.onClick = Dialog_Close; closebutton.onClickEntity = me;\r
160                 closebutton.srcMulti = 0;\r
161                 me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST\r
162         }\r
163 \r
164         me.frame.closeButton = closebutton;\r
165 }\r
166 \r
167 void closeDialog(entity me)\r
168 {\r
169         if(me.parent.instanceOfNexposee)\r
170         {\r
171                 ExposeeCloseButton_Click(me, me.parent);\r
172         }\r
173         else if(me.parent.instanceOfModalController)\r
174         {\r
175                 DialogCloseButton_Click(me, me);\r
176         }\r
177 }\r
178 \r
179 float keyDownDialog(entity me, float key, float ascii, float shift)\r
180 {\r
181         if(me.closable)\r
182         {\r
183                 if(key == K_ESCAPE)\r
184                 {\r
185                         me.close(me);\r
186                         return 1;\r
187                 }\r
188         }\r
189         return keyDownInputContainer(me, key, ascii, shift);\r
190 }\r
191 #endif\r