RecipieGroup.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "RecipieGroup.h"
  2. #include <Bild.h>
  3. #include <Schrift.h>
  4. #include "Globals.h"
  5. RecipieGroup::RecipieGroup()
  6. : Framework::ZeichnungHintergrund()
  7. {
  8. setStyle(Framework::Zeichnung::Style::Erlaubt
  9. | Framework::Zeichnung::Style::Sichtbar);
  10. icon = 0;
  11. previousPage = uiFactory.createKnopf(uiFactory.initParam);
  12. previousPage->setText("<");
  13. previousPage->setToolTipText("Previous Page",
  14. uiFactory.initParam.bildschirm,
  15. uiFactory.initParam.schrift);
  16. previousPage->setSize(20, 20);
  17. previousPage->setPosition(0, 0);
  18. previousPage->setStyle(
  19. Framework::Knopf::Style::Normal & ~Framework::Knopf::Style::Sichtbar);
  20. previousPage->setMausEreignis([this](void* p, void* z, MausEreignis me) {
  21. if (me.id == ME_RLinks)
  22. {
  23. currentPage--;
  24. }
  25. return 1;
  26. });
  27. nextPage = uiFactory.createKnopf(uiFactory.initParam);
  28. nextPage->setText(">");
  29. nextPage->setToolTipText("Next Page",
  30. uiFactory.initParam.bildschirm,
  31. uiFactory.initParam.schrift);
  32. nextPage->setSize(20, 20);
  33. nextPage->setPosition(0, 0);
  34. nextPage->setStyle(
  35. Framework::Knopf::Style::Normal & ~Framework::Knopf::Style::Sichtbar);
  36. nextPage->setMausEreignis([this](void* p, void* z, MausEreignis me) {
  37. if (me.id == ME_RLinks)
  38. {
  39. currentPage++;
  40. }
  41. return 1;
  42. });
  43. }
  44. RecipieGroup::~RecipieGroup()
  45. {
  46. if (icon) icon->release();
  47. previousPage->release();
  48. nextPage->release();
  49. }
  50. void RecipieGroup::addRecipie(Framework::Zeichnung* recipie)
  51. {
  52. recipies.add(recipie);
  53. }
  54. void RecipieGroup::setIcon(Framework::Bild* icon)
  55. {
  56. if (this->icon) this->icon->release();
  57. this->icon = icon;
  58. }
  59. void RecipieGroup::setToolTip(Framework::Text toolTip)
  60. {
  61. this->toolTip = toolTip;
  62. }
  63. bool RecipieGroup::tick(double tickVal)
  64. {
  65. int pi = 1;
  66. int y = 20;
  67. bool first = 1;
  68. for (Zeichnung* recipie : recipies)
  69. {
  70. if (recipie->getHeight() + y > getHeight() && !first)
  71. {
  72. pi++;
  73. y = 20;
  74. }
  75. recipie->setStyle(Zeichnung::Style::Sichtbar, pi == currentPage);
  76. recipie->setX(getBreite() / 2 - recipie->getBreite() / 2);
  77. recipie->setY(y);
  78. y += recipie->getHeight() + 50;
  79. first = 0;
  80. rend |= recipie->tick(tickVal);
  81. }
  82. nextPage->setX(getBreite() - 20);
  83. maxPage = pi;
  84. currentPage = MAX(1, MIN(pi, currentPage));
  85. previousPage->setStyle(Knopf::Style::Sichtbar, currentPage > 1);
  86. nextPage->setStyle(Knopf::Style::Sichtbar, currentPage < maxPage);
  87. rend |= previousPage->tick(tickVal);
  88. rend |= nextPage->tick(tickVal);
  89. return ZeichnungHintergrund::tick(tickVal);
  90. }
  91. void RecipieGroup::render(Framework::Bild& rObj)
  92. {
  93. if (!hatStyle(Zeichnung::Style::Sichtbar)) return;
  94. ZeichnungHintergrund::render(rObj);
  95. if (!rObj.setDrawOptions(pos.x, pos.y, gr.x, gr.y)) return;
  96. Framework::TextRenderer tr(dynamic_cast<Framework::Schrift*>(uiFactory.initParam.schrift->getThis()));
  97. tr.setSchriftSize(12);
  98. Text t = Text("Recipie page ") + Text(currentPage) + Text(" of ") + Text(maxPage);
  99. int tbr = tr.getTextBreite(t);
  100. tr.renderText(getBreite() / 2 - tbr / 2, 4, t, rObj, 0xFFFFFFFF);
  101. for (Framework::Zeichnung* recipie : recipies)
  102. {
  103. recipie->render(rObj);
  104. }
  105. previousPage->render(rObj);
  106. nextPage->render(rObj);
  107. rObj.releaseDrawOptions();
  108. }
  109. void RecipieGroup::doMausEreignis(Framework::MausEreignis& me, bool userRet)
  110. {
  111. previousPage->doPublicMausEreignis(me);
  112. nextPage->doPublicMausEreignis(me);
  113. for (Zeichnung* recipie : recipies)
  114. {
  115. recipie->doPublicMausEreignis(me);
  116. }
  117. }
  118. Framework::Bild* RecipieGroup::zIcon() const
  119. {
  120. return icon;
  121. }
  122. Framework::Text RecipieGroup::getToolTip() const
  123. {
  124. return toolTip;
  125. }