PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/cui/dialog.d

http://github.com/wilkie/djehuty
D | 92 lines | 65 code | 21 blank | 6 comment | 6 complexity | 378ea9c90681a010a40382732a432375 MD5 | raw file
 1/*
 2 * dialog.d
 3 *
 4 * This module implements a subwindow for Cui applications.
 5 *
 6 */
 7
 8module cui.dialog;
 9
10import cui.widget;
11import cui.container;
12
13private import io.console;
14
15import djehuty;
16
17class CuiDialog : CuiContainer {
18	this(string title, uint x, uint y, uint width, uint height) {
19		_title = Unicode.toUtf32(title);
20		super(x,y,width,height);
21	}
22
23	override void onAdd() {
24		_old_base_y = _base_y;
25		_base_y++;
26	}
27
28	override void onDraw() {
29		io.console.Console.position(_base_x + this.left, _base_y + this.top - 1);
30
31		io.console.Console.forecolor = _forecolor;
32		io.console.Console.backcolor = _backcolor;
33
34		uint x;
35		if (_title.length + 2 > this.width) {
36			x = 1;
37		}
38		else {
39			x = (this.width - _title.length) / 2;
40		}
41
42		io.console.Console.put(" ");
43		for (uint i = 1; i < x-1; i++) {
44			io.console.Console.put("-");
45		}
46		if (x > 1) {
47			io.console.Console.put(" ");
48		}
49
50		io.console.Console.put(_title);
51
52		if (x > 1) {
53			io.console.Console.put(" ");
54		}
55		for (uint i = x + _title.length + 2; i < this.width; i++) {
56			io.console.Console.put("-");
57		}
58		io.console.Console.put(" ");
59
60		super.onDraw();
61	}
62
63protected:
64
65	override void _reportMove(uint x, uint y) {
66		_base_y++;
67		super._reportMove(x,y);
68	}
69
70	dstring _title;
71
72	Color _forecolor = Color.Black;
73	Color _backcolor = Color.White;
74
75	uint _old_base_y;
76}
77
78import cui.filebox;
79import cui.listbox;
80
81class CuiOpenDialog : CuiDialog {
82	this(uint x, uint y) {
83		super("Open", x, y, 60, 20);
84	}
85
86	override void onAdd() {
87		super.onAdd();
88		push(files = new CuiFileBox(0,0,60,19));
89	}
90protected:
91	CuiFileBox files;
92}