/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. module cui.dialog;
  8. import cui.widget;
  9. import cui.container;
  10. private import io.console;
  11. import djehuty;
  12. class CuiDialog : CuiContainer {
  13. this(string title, uint x, uint y, uint width, uint height) {
  14. _title = Unicode.toUtf32(title);
  15. super(x,y,width,height);
  16. }
  17. override void onAdd() {
  18. _old_base_y = _base_y;
  19. _base_y++;
  20. }
  21. override void onDraw() {
  22. io.console.Console.position(_base_x + this.left, _base_y + this.top - 1);
  23. io.console.Console.forecolor = _forecolor;
  24. io.console.Console.backcolor = _backcolor;
  25. uint x;
  26. if (_title.length + 2 > this.width) {
  27. x = 1;
  28. }
  29. else {
  30. x = (this.width - _title.length) / 2;
  31. }
  32. io.console.Console.put(" ");
  33. for (uint i = 1; i < x-1; i++) {
  34. io.console.Console.put("-");
  35. }
  36. if (x > 1) {
  37. io.console.Console.put(" ");
  38. }
  39. io.console.Console.put(_title);
  40. if (x > 1) {
  41. io.console.Console.put(" ");
  42. }
  43. for (uint i = x + _title.length + 2; i < this.width; i++) {
  44. io.console.Console.put("-");
  45. }
  46. io.console.Console.put(" ");
  47. super.onDraw();
  48. }
  49. protected:
  50. override void _reportMove(uint x, uint y) {
  51. _base_y++;
  52. super._reportMove(x,y);
  53. }
  54. dstring _title;
  55. Color _forecolor = Color.Black;
  56. Color _backcolor = Color.White;
  57. uint _old_base_y;
  58. }
  59. import cui.filebox;
  60. import cui.listbox;
  61. class CuiOpenDialog : CuiDialog {
  62. this(uint x, uint y) {
  63. super("Open", x, y, 60, 20);
  64. }
  65. override void onAdd() {
  66. super.onAdd();
  67. push(files = new CuiFileBox(0,0,60,19));
  68. }
  69. protected:
  70. CuiFileBox files;
  71. }