]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/nexuiz/dialog.c
first attempt at teamselect dialog... not good yet (need a better way to implement...
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / nexuiz / dialog.c
1 #ifdef INTERFACE
2 CLASS(Dialog) EXTENDS(InputContainer)
3         METHOD(Dialog, configureDialog, void(entity)) // no runtime configuration, all parameters are given in the code!
4         METHOD(Dialog, fill, void(entity)) // to be overridden by user to fill the dialog with controls
5         METHOD(Dialog, keyDown, float(entity, float, float, float))
6         METHOD(Dialog, close, void(entity))
7         METHOD(Dialog, addItemSimple, void(entity, float, float, float, entity))
8         ATTRIB(Dialog, isTabRoot, float, 1)
9         ATTRIB(Dialog, closeButton, entity, NULL)
10         ATTRIB(Dialog, firstLine, float, 0)
11         ATTRIB(Dialog, lineSpacing, float, 0)
12         ATTRIB(Dialog, firstColumn, float, 0)
13         ATTRIB(Dialog, columnWidth, float, 0)
14         ATTRIB(Dialog, lineHeight, float, 0)
15
16         // to be customized
17         ATTRIB(Dialog, closable, float, 1)
18         ATTRIB(Dialog, rootDialog, float, 1)
19         ATTRIB(Dialog, title, string, "Form1") // ;)
20         ATTRIB(Dialog, color, vector, '1 0.5 1')
21         ATTRIB(Dialog, intendedWidth, float, 0.96)
22         ATTRIB(Dialog, intendedHeight, float, 0.96)
23         ATTRIB(Dialog, lines, float, 5)
24 ENDCLASS(Dialog)
25 #endif
26
27 #ifdef IMPLEMENTATION
28 void Dialog_Close(entity button, entity me)
29 {
30         me.close(me);
31 }
32
33 void fillDialog(entity me)
34 {
35 }
36
37 void addItemSimpleDialog(entity me, float line, float col, float cols, entity e)
38 {
39         me.addItem(me, e, (me.firstLine + (line - 1) * me.lineSpacing) * eY + (me.firstColumn + (col - 1) / cols * me.columnWidth) * eX, me.lineHeight * eY + me.columnWidth / cols * eX, 1);
40 }
41
42 void configureDialogDialog(entity me)
43 {
44         entity frame, closebutton;
45         float ch, cw;
46
47         frame = spawnBorderImage();
48         frame.configureBorderImage(frame, me.title, SKINFONTSIZE_TITLE, me.color, SKINGFX_DIALOGBORDER, SKINHEIGHT_TITLE);
49         me.addItem(me, frame, '0 0 0', '1 1 0', 1);
50
51         ch = me.intendedHeight * cvar("vid_conheight");
52         cw = me.intendedWidth * cvar("vid_conwidth");
53
54         me.firstLine = (SKINFONTSIZE_TITLE * SKINHEIGHT_TITLE + SKINMARGIN_TOP) / ch;
55         me.lineSpacing = SKINFONTSIZE_NORMAL * SKINHEIGHT_NORMAL_WITHSPACING / ch;
56         me.lineHeight = SKINFONTSIZE_NORMAL * SKINHEIGHT_NORMAL/ ch;
57         me.firstColumn = SKINMARGIN_LEFT / cw;
58         me.columnWidth = 1 - 2 * SKINMARGIN_LEFT / cw;
59
60         me.lines = (1 - SKINMARGIN_TOP / ch - me.firstLine + me.lineSpacing - me.lineHeight) / me.lineSpacing;
61
62         me.fill(me);
63
64         if(me.closable)
65         {
66                 closebutton = me.closeButton = spawnButton();
67                 closebutton.configureButton(closebutton, "", 12, SKINGFX_CLOSEBUTTON);
68                 closebutton.onClick = Dialog_Close; closebutton.onClickEntity = me;
69                 closebutton.srcMulti = 0;
70                 me.addItem(me, closebutton, '0 0 0', '1 1 0', 1); // put it as LAST
71         }
72
73         frame.closeButton = closebutton;
74 }
75
76 void closeDialog(entity me)
77 {
78         if(me.parent.instanceOfNexposee)
79         {
80                 ExposeeCloseButton_Click(me, me.parent);
81         }
82         else if(me.parent.instanceOfModalController)
83         {
84                 DialogCloseButton_Click(me, me);
85         }
86         if(me.rootDialog)
87         {
88                 m_goto("");
89         }
90 }
91
92 float keyDownDialog(entity me, float key, float ascii, float shift)
93 {
94         if(me.closable)
95         {
96                 if(key == K_ESCAPE)
97                 {
98                         me.close(me);
99                         return 1;
100                 }
101         }
102         return keyDownInputContainer(me, key, ascii, shift);
103 }
104 #endif