CalendarBlock.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #include "CalendarBlock.hpp"
  2. #include "Clock.hpp"
  3. #include "AssetManager.hpp"
  4. #include "Notification.hpp"
  5. #include "Util.hpp"
  6. #include <cpp3ds/System/I18n.hpp>
  7. #include <cpp3ds/System/FileSystem.hpp>
  8. #include <TweenEngine/Tween.h>
  9. #include <time.h>
  10. #include <stdlib.h>
  11. namespace Clock {
  12. CalendarBlock::CalendarBlock()
  13. : m_presetDay(None)
  14. , m_isInverted(false)
  15. , m_isSelected(false)
  16. {
  17. m_calendarBlockDial.setOutlineColor(cpp3ds::Color(117, 117, 117));
  18. m_calendarBlockDial.setOutlineThickness(1);
  19. m_calendarBlockDial.setSize(cpp3ds::Vector2f(22.f, 22.f));
  20. m_calendarBlockDial.setOrigin(m_calendarBlockDial.getLocalBounds().width / 2, m_calendarBlockDial.getLocalBounds().height / 2);
  21. m_textDate.setCharacterSize(12);
  22. m_textDate.setFillColor(cpp3ds::Color::Black);
  23. m_textDate.useSystemFont();
  24. m_selectedSquare = m_calendarBlockDial;
  25. m_selectedSquare.setSize(cpp3ds::Vector2f(17.f, 17.f));
  26. m_selectedSquare.setOrigin(m_selectedSquare.getLocalBounds().width / 2, m_selectedSquare.getLocalBounds().height / 2);
  27. setSelectedColor(g_themeColor);
  28. }
  29. CalendarBlock::~CalendarBlock()
  30. {
  31. }
  32. void CalendarBlock::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
  33. {
  34. states.transform *= getTransform();
  35. target.draw(m_calendarBlockDial);
  36. if (m_isSelected)
  37. target.draw(m_selectedSquare);
  38. target.draw(m_textDate);
  39. }
  40. void CalendarBlock::update(float delta)
  41. {
  42. m_tweenManager.update(delta);
  43. }
  44. void CalendarBlock::setBlockText(cpp3ds::String text)
  45. {
  46. m_textDate.setString(text);
  47. m_textDate.setOrigin(m_textDate.getLocalBounds().width / 2, m_textDate.getLocalBounds().height / 2);
  48. }
  49. cpp3ds::String CalendarBlock::getBlockText()
  50. {
  51. return m_textDate.getString();
  52. }
  53. void CalendarBlock::setPosition(float posX, float posY)
  54. {
  55. m_calendarBlockDial.setPosition(posX + (m_calendarBlockDial.getLocalBounds().width / 2), posY + (m_calendarBlockDial.getLocalBounds().height / 2));
  56. m_textDate.setPosition(m_calendarBlockDial.getPosition().x - 1, m_calendarBlockDial.getPosition().y);
  57. m_selectedSquare.setPosition(m_calendarBlockDial.getPosition().x - 1, m_calendarBlockDial.getPosition().y - 1);
  58. }
  59. cpp3ds::Vector2f CalendarBlock::getPosition()
  60. {
  61. return cpp3ds::Vector2f(m_calendarBlockDial.getPosition().x, m_calendarBlockDial.getPosition().y);
  62. }
  63. cpp3ds::Vector2f CalendarBlock::getSize()
  64. {
  65. return m_calendarBlockDial.getSize();
  66. }
  67. void CalendarBlock::toggleInverted()
  68. {
  69. m_isInverted = !m_isInverted;
  70. changePresets(m_presetDay, m_isInverted);
  71. }
  72. bool CalendarBlock::isInverted()
  73. {
  74. return m_isInverted;
  75. }
  76. void CalendarBlock::setPreset(PresetDay newPreset)
  77. {
  78. m_presetDay = newPreset;
  79. changePresets(m_presetDay, m_isInverted);
  80. }
  81. CalendarBlock::PresetDay CalendarBlock::getPreset()
  82. {
  83. return m_presetDay;
  84. }
  85. void CalendarBlock::changePresets(PresetDay newPreset, bool isInverted)
  86. {
  87. if (isInverted)
  88. m_textDate.setFillColor(cpp3ds::Color::White);
  89. else
  90. m_textDate.setFillColor(cpp3ds::Color::Black);
  91. if (newPreset == Saturday) {
  92. if (isInverted) {
  93. m_calendarBlockDial.setFillColor(cpp3ds::Color(63, 81, 181));
  94. } else {
  95. m_calendarBlockDial.setFillColor(cpp3ds::Color(63, 81, 181, 192));
  96. }
  97. } else if (newPreset == Sunday) {
  98. if (isInverted) {
  99. m_calendarBlockDial.setFillColor(cpp3ds::Color(244, 67, 54));
  100. } else {
  101. m_calendarBlockDial.setFillColor(cpp3ds::Color(244, 67, 54, 192));
  102. }
  103. } else {
  104. if (isInverted) {
  105. m_calendarBlockDial.setFillColor(cpp3ds::Color(158, 158, 158, 192));
  106. } else {
  107. m_calendarBlockDial.setFillColor(cpp3ds::Color::White);
  108. }
  109. }
  110. }
  111. void CalendarBlock::toggleSelected()
  112. {
  113. m_isSelected = !m_isSelected;
  114. }
  115. bool CalendarBlock::isSelected()
  116. {
  117. return m_isSelected;
  118. }
  119. void CalendarBlock::setSelectedColor(cpp3ds::Color newColor)
  120. {
  121. m_selectedSquare.setOutlineColor(newColor);
  122. m_selectedSquare.setFillColor(cpp3ds::Color(newColor.r, newColor.g, newColor.b, 128));
  123. }
  124. cpp3ds::Color CalendarBlock::getSelectedColor()
  125. {
  126. return m_selectedSquare.getOutlineColor();
  127. }
  128. } // namespace Clock