]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/dialog.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / dialog.qc
1 #include "dialog.qh"
2
3 #include "borderimage.qh"
4 #include "button.qh"
5 #include "nexposee.qh"
6
7 void Dialog_Close(entity button, entity me)
8 {
9         me.close(me);
10 }
11
12 void Dialog_fill(entity me)
13 {}
14
15 void Dialog_addItemSimple(entity me, float row, float col, float rowspan, float colspan, entity e, vector v)
16 {
17         vector o, s;
18         o = me.itemOrigin + eX * (col          * me.itemSpacing.x) + eY * (row          * me.itemSpacing.y);
19         s = me.itemSize   + eX * ((colspan - 1) * me.itemSpacing.x) + eY * ((rowspan - 1) * me.itemSpacing.y);
20         o.x -= 0.5 * (me.itemSpacing.x - me.itemSize.x) * v.x;
21         s.x +=       (me.itemSpacing.x - me.itemSize.x) * v.x;
22         o.y -= 0.5 * (me.itemSpacing.y - me.itemSize.y) * v.y;
23         s.y +=       (me.itemSpacing.y - me.itemSize.y) * v.y;
24         me.addItem(me, e, o, s, 1);
25 }
26
27 void Dialog_gotoRC(entity me, float row, float col)
28 {
29         me.currentRow = row;
30         me.currentColumn = col;
31 }
32
33 void Dialog_TR(entity me)
34 {
35         me.currentRow += 1;
36         me.currentColumn = me.firstColumn;
37 }
38
39 void Dialog_TD(entity me, float rowspan, float colspan, entity e)
40 {
41         me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, '0 0 0');
42         me.currentColumn += colspan;
43 }
44
45 void Dialog_TDNoMargin(entity me, float rowspan, float colspan, entity e, vector v)
46 {
47         me.addItemSimple(me, me.currentRow, me.currentColumn, rowspan, colspan, e, v);
48         me.currentColumn += colspan;
49 }
50
51 void Dialog_setFirstColumn(entity me, float col)
52 {
53         me.firstColumn = col;
54 }
55
56 void Dialog_TDempty(entity me, float colspan)
57 {
58         me.currentColumn += colspan;
59 }
60
61 void Dialog_configureDialog(entity me)
62 {
63         float absWidth, absHeight;
64
65         if (me.isTabRoot) {
66                 me.frame = NEW(BorderImage);
67                 me.frame.configureBorderImage(me.frame, me.title, me.titleFontSize, me.color, me.backgroundImage, me.borderLines * me.titleHeight);
68                 me.frame.zoomedOutTitleBarPosition = me.zoomedOutTitleBarPosition;
69                 me.frame.zoomedOutTitleBar = me.zoomedOutTitleBar;
70                 me.frame.alpha = me.alpha;
71                 me.addItem(me, me.frame, '0 0 0', '1 1 0', 1);
72         }
73
74         if (!me.titleFontSize) {
75                 me.titleHeight = 0; // no title bar
76         }
77         absWidth = me.intendedWidth * conwidth;
78         absHeight = me.borderLines * me.titleHeight + me.marginTop + me.rows * me.rowHeight + (me.rows - 1) * me.rowSpacing + me.marginBottom;
79         me.itemOrigin  = eX * (me.marginLeft / absWidth)
80                 + eY * ((me.borderLines * me.titleHeight + me.marginTop) / absHeight);
81         me.itemSize    = eX * ((1 - (me.marginLeft + me.marginRight + me.columnSpacing * (me.columns - 1)) / absWidth) / me.columns)
82                 + eY * (me.rowHeight / absHeight);
83         me.itemSpacing = me.itemSize
84                 + eX * (me.columnSpacing / absWidth)
85                 + eY * (me.rowSpacing / absHeight);
86         me.intendedHeight = absHeight / conheight;
87         me.currentRow = -1;
88         me.currentColumn = -1;
89
90         me.fill(me);
91
92         if (me.isTabRoot && me.closable && me.borderLines > 0) {
93                 entity closebutton;
94                 closebutton = me.closeButton = me.frame.closeButton = NEW(Button);
95                 closebutton.configureButton(closebutton, "", 0, me.closeButtonImage);
96                 closebutton.onClick = Dialog_Close;
97                 closebutton.onClickEntity = me;
98                 closebutton.srcMulti = 0;
99                 me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST
100         }
101 }
102
103 void Dialog_close(entity me)
104 {
105         if (me.parent.instanceOfNexposee) {
106                 ExposeeCloseButton_Click(me, me.parent);
107                 if (me.hideMenuOnClose) {
108                         me.hideMenuOnClose = false;
109                         m_hide();
110                 }
111         } else if (me.parent.instanceOfModalController) {
112                 DialogCloseButton_Click(me, me);
113         }
114 }
115
116 float Dialog_keyDown(entity me, float key, float ascii, float shift)
117 {
118         if (me.closable) {
119                 if (key == K_ESCAPE) {
120                         m_play_click_sound(MENU_SOUND_CLOSE);
121                         me.close(me);
122                         return 1;
123                 }
124         }
125         float r = SUPER(Dialog).keyDown(me, key, ascii, shift);
126         if (!me.closable && key == K_ESCAPE) {
127                 return 1;
128         }
129         return r;
130 }