Advertisement
hannamori

Berarray

Nov 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include "BounceWindow.h"
  2. #include "Box.h"
  3. #include "Circle.h"
  4. #include <wx/arrimpl.cpp>
  5. #define TIMER_ID 2000
  6. BEGIN_EVENT_TABLE(BounceWindow, wxWindow)
  7. EVT_PAINT(BounceWindow::OnPaint)
  8. EVT_TIMER(TIMER_ID, BounceWindow::OnTimer)
  9. EVT_LEFT_DOWN(BounceWindow::OnMouseLeftDown)
  10. EVT_RIGHT_DOWN(BounceWindow::OnMouseRightDown)
  11. END_EVENT_TABLE()
  12.  
  13. WX_DECLARE_OBJARRAY(Circle, CircleArray);
  14. WX_DECLARE_OBJARRAY(Box, BoxArray);
  15. WX_DEFINE_OBJARRAY(CircleArray);
  16. WX_DEFINE_OBJARRAY(BoxArray);
  17.  
  18.  
  19. BoxArray boxes;
  20. CircleArray circ;
  21.  
  22.  
  23. BounceWindow::BounceWindow(wxFrame *frame)
  24. : wxWindow(frame, wxID_ANY)
  25. {
  26. SetBackgroundColour(wxColour(*wxWHITE));
  27. timer = new wxTimer(this, TIMER_ID);
  28. //memulai timer dengan interval 50ms.
  29. timer->Start(60);
  30. //box = new Box(10, 40, 110, 50);
  31. //circle = new Circle(10, 40, 50);
  32. }
  33.  
  34. BounceWindow::~BounceWindow()
  35. {
  36. timer->Stop();
  37. delete timer;
  38. delete box;
  39. delete circle;
  40. boxes.Clear();
  41. circ.Clear();
  42. }
  43. void BounceWindow::OnPaint(wxPaintEvent &event)
  44. {
  45. if (circle != nullptr) {
  46. wxPaintDC pdc(this);
  47. this->circle->Draw(pdc);
  48. }
  49. if (box != nullptr) {
  50. wxPaintDC pdc(this);
  51. this->box->Draw(pdc);
  52. }
  53. for (unsigned int i = 0; i < boxes.GetCount(); i++) {
  54. wxPaintDC pdc(this);
  55. boxes[i].Draw(pdc);
  56. }
  57.  
  58. for (unsigned int j = 0; j < circ.GetCount(); j++) {
  59. wxPaintDC pdc(this);
  60. circ[j].Draw(pdc);
  61. }
  62. }
  63. void BounceWindow::OnTimer(wxTimerEvent &event)
  64. {
  65. for (unsigned int i = 0; i < boxes.GetCount(); i++) {
  66. boxes[i].Move(5, 2, GetClientSize().GetWidth(),
  67. GetClientSize().GetHeight());
  68. Refresh();
  69. }
  70.  
  71. for (unsigned int j = 0; j < circ.GetCount(); j++) {
  72. circ[j].Move(3, 3, GetClientSize().GetWidth(),
  73. GetClientSize().GetHeight());
  74. Refresh();
  75. }
  76. }
  77.  
  78. void BounceWindow::OnMouseRightDown(wxMouseEvent &event)
  79. {
  80. bool crcsts = 1;
  81. for (unsigned int i = 0; i < circ.GetCount(); i++)
  82. {
  83. if (circ[i].GetX() == event.GetX() && circ[i].GetY() == event.GetY())
  84. crcsts = 0;
  85. }
  86.  
  87. if (crcsts) {
  88. wxMessageOutputDebug().Printf("CIRCLE\n");
  89. circle = new Circle(event.GetX(), event.GetY(), 40);
  90. circ.Add(circle);
  91. }
  92.  
  93. }
  94. void BounceWindow::OnMouseLeftDown(wxMouseEvent & event)
  95. {
  96. bool boxsts = 1;
  97. for (unsigned int i = 0; i < boxes.GetCount(); i++)
  98. {
  99. if (boxes[i].GetX() == event.GetX() && boxes[i].GetY() == event.GetY())
  100. boxsts = 0;
  101. }
  102.  
  103. if (boxsts) {
  104. wxMessageOutputDebug().Printf("KOTAK\n");
  105. box = new Box(event.GetX(), event.GetY(), 50, 50);
  106. boxes.Add(box);
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement