Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BounceWindow.h"
- #include "Box.h"
- #include "Circle.h"
- #include <wx/arrimpl.cpp>
- #define TIMER_ID 2000
- BEGIN_EVENT_TABLE(BounceWindow, wxWindow)
- EVT_PAINT(BounceWindow::OnPaint)
- EVT_TIMER(TIMER_ID, BounceWindow::OnTimer)
- EVT_LEFT_DOWN(BounceWindow::OnMouseLeftDown)
- EVT_RIGHT_DOWN(BounceWindow::OnMouseRightDown)
- END_EVENT_TABLE()
- WX_DECLARE_OBJARRAY(Circle, CircleArray);
- WX_DECLARE_OBJARRAY(Box, BoxArray);
- WX_DEFINE_OBJARRAY(CircleArray);
- WX_DEFINE_OBJARRAY(BoxArray);
- BoxArray boxes;
- CircleArray circ;
- BounceWindow::BounceWindow(wxFrame *frame)
- : wxWindow(frame, wxID_ANY)
- {
- SetBackgroundColour(wxColour(*wxWHITE));
- timer = new wxTimer(this, TIMER_ID);
- //memulai timer dengan interval 50ms.
- timer->Start(60);
- //box = new Box(10, 40, 110, 50);
- //circle = new Circle(10, 40, 50);
- }
- BounceWindow::~BounceWindow()
- {
- timer->Stop();
- delete timer;
- delete box;
- delete circle;
- boxes.Clear();
- circ.Clear();
- }
- void BounceWindow::OnPaint(wxPaintEvent &event)
- {
- if (circle != nullptr) {
- wxPaintDC pdc(this);
- this->circle->Draw(pdc);
- }
- if (box != nullptr) {
- wxPaintDC pdc(this);
- this->box->Draw(pdc);
- }
- for (unsigned int i = 0; i < boxes.GetCount(); i++) {
- wxPaintDC pdc(this);
- boxes[i].Draw(pdc);
- }
- for (unsigned int j = 0; j < circ.GetCount(); j++) {
- wxPaintDC pdc(this);
- circ[j].Draw(pdc);
- }
- }
- void BounceWindow::OnTimer(wxTimerEvent &event)
- {
- for (unsigned int i = 0; i < boxes.GetCount(); i++) {
- boxes[i].Move(5, 2, GetClientSize().GetWidth(),
- GetClientSize().GetHeight());
- Refresh();
- }
- for (unsigned int j = 0; j < circ.GetCount(); j++) {
- circ[j].Move(3, 3, GetClientSize().GetWidth(),
- GetClientSize().GetHeight());
- Refresh();
- }
- }
- void BounceWindow::OnMouseRightDown(wxMouseEvent &event)
- {
- bool crcsts = 1;
- for (unsigned int i = 0; i < circ.GetCount(); i++)
- {
- if (circ[i].GetX() == event.GetX() && circ[i].GetY() == event.GetY())
- crcsts = 0;
- }
- if (crcsts) {
- wxMessageOutputDebug().Printf("CIRCLE\n");
- circle = new Circle(event.GetX(), event.GetY(), 40);
- circ.Add(circle);
- }
- }
- void BounceWindow::OnMouseLeftDown(wxMouseEvent & event)
- {
- bool boxsts = 1;
- for (unsigned int i = 0; i < boxes.GetCount(); i++)
- {
- if (boxes[i].GetX() == event.GetX() && boxes[i].GetY() == event.GetY())
- boxsts = 0;
- }
- if (boxsts) {
- wxMessageOutputDebug().Printf("KOTAK\n");
- box = new Box(event.GetX(), event.GetY(), 50, 50);
- boxes.Add(box);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement