Dialog.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "Dialog.h"
  2. #include "AsynchronCall.h"
  3. #include "SelectionBox.h"
  4. #include "Screen.h"
  5. #include "Window.h"
  6. #include "Button.h"
  7. #include "RenderThread.h"
  8. #include "Font.h"
  9. #include "Text.h"
  10. using namespace Framework;
  11. // Contents of the MultiplChoiceDialog class from Dialog.h
  12. MultiplChoiceDialog::MultiplChoiceDialog()
  13. : ReferenceCounter()
  14. {
  15. entrys = new RCArray<Text>();
  16. ids = new Array<void*>();
  17. }
  18. MultiplChoiceDialog::~MultiplChoiceDialog()
  19. {
  20. entrys->release();
  21. ids->release();
  22. }
  23. // Adds a selection option
  24. void MultiplChoiceDialog::addChoice(const char* text, void* id)
  25. {
  26. entrys->add(new Text(text));
  27. ids->add(id);
  28. }
  29. // shows the dialog and waits for user input
  30. void* MultiplChoiceDialog::anzeigen(Font* zFont)
  31. {
  32. void* result = 0;
  33. bool ex = 0;
  34. WNDCLASS wc = F_Normal(0);
  35. wc.lpszClassName = "Dialog";
  36. NativeWindow* f = new NativeWindow();
  37. f->setVSchliessAktion([&ex](void* p, void* o) { ex = true; });
  38. f->setMausAktion(_ret1ME);
  39. f->setTastaturAktion(_ret1TE);
  40. f->erstellen(WS_OVERLAPPEDWINDOW, wc);
  41. f->setSize(200, 200);
  42. f->setPosition(ScreenCenter(dynamic_cast<NativeWindow*>(f->getThis())));
  43. f->setVerschiebbar(1);
  44. f->setAnzeigeModus(1);
  45. Screen* b = new Screen2D(dynamic_cast<NativeWindow*>(f->getThis()));
  46. f->setScreen(dynamic_cast<Screen*>(b->getThis()));
  47. b->update();
  48. RenderTh* r = new RenderTh();
  49. r->setScreen(dynamic_cast<Screen*>(b->getThis()));
  50. r->beginn();
  51. SelectionBox* ab = new SelectionBox();
  52. ab->setPosition(10, 10);
  53. ab->setSize(180, 20);
  54. ab->setHintergrundFarbe(0xFF000000);
  55. ab->setBorderWidth(1);
  56. ab->setBorderColor(0xFFFFFFFF);
  57. ab->setMaxAuskappHeight(120);
  58. ab->setMausRahmenBreite(1);
  59. ab->setMausRahmenFarbe(0xFF005500);
  60. ab->setMouseAlphaFieldColor(0x00008700);
  61. ab->setMausAlphaFeldStrength(-8);
  62. ab->setAuswRahmenBreite(1);
  63. ab->setAuswRahmenFarbe(0xFF00FF00);
  64. ab->setSelAlphaFieldColor(0x0000FF00);
  65. ab->setAuswAlphaFeldStrength(-8);
  66. ab->setStyle(SelectionBox::Style::Normal);
  67. ab->setFontZ(dynamic_cast<Font*>(zFont->getThis()));
  68. for (Text* i : *entrys)
  69. ab->addEintrag(i->getText());
  70. ab->setMouseEvent(_ret1ME);
  71. b->addMember(ab);
  72. Button* ok = new Button();
  73. ok->setStyle(Button::Style::Normal);
  74. ok->setPosition(50, 150);
  75. ok->setSize(100, 20);
  76. ok->setFontZ(dynamic_cast<Font*>(zFont->getThis()));
  77. ok->setText("Ok");
  78. ok->setMouseEvent(
  79. [this, &ex, &result, ab](void* p, void* o, MouseEvent me) {
  80. if (me.id == ME_RLinks)
  81. {
  82. result = ids->get(ab->getAuswahl());
  83. ex = true;
  84. }
  85. return 1;
  86. });
  87. b->addMember(ok);
  88. MSG msg;
  89. while (GetMessage(&msg, NULL, 0, 0) > 0 && !ex)
  90. {
  91. if (!ex)
  92. {
  93. TranslateMessage(&msg);
  94. DispatchMessage(&msg);
  95. }
  96. }
  97. r->beenden();
  98. r->release();
  99. b->release();
  100. f->setScreen(0);
  101. f->setAnzeigeModus(0);
  102. f->zerstoeren();
  103. f->release();
  104. ok->release();
  105. ab->release();
  106. return result;
  107. }