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