Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////// MainWindow.h
- #pragma once
- #include <nana/gui.hpp>
- #include <nana/threads/pool.hpp>
- #include <thread>
- #include <iostream>
- #include <atomic>
- using namespace nana;
- class MainWindow : public form
- {
- public:
- MainWindow();
- ~MainWindow();
- static void draw(paint::graphics& graph);
- private:
- void mainLoop();
- void wait(unsigned int wait = 0);
- threads::pool pool_;
- std::atomic_bool flag = true;
- static int x;
- static int y;
- };
- /////////// MainWindow.cpp
- #include "MainWindow.h"
- int MainWindow::x = 5;
- int MainWindow::y = 5;
- MainWindow::MainWindow()
- {
- caption("Tetris");
- this->events().key_press([&](const nana::arg_keyboard&arg)
- {
- });
- this->events().expose(nana::threads::pool_push(pool_, *this, &MainWindow::mainLoop));
- }
- MainWindow::~MainWindow()
- {
- flag = false;
- pool_.wait_for_finished();
- }
- void MainWindow::mainLoop()
- {
- while (flag)
- {
- x++;
- y++;
- nana::API::refresh_window(*this);
- wait(1000);
- }
- }
- void MainWindow::wait(unsigned int wait)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds{ wait });
- }
- void MainWindow::draw(paint::graphics& graph)
- {
- graph.rectangle(rectangle{ x, y, 50, 50 }, true, colors::red);
- graph.line(point(x, y), point(55, 55), colors::blue);
- }
- /////////// main.cpp
- #include "MainWindow.h"
- int main()
- {
- MainWindow window;
- drawing dw(window);
- dw.draw(&window.draw);
- dw.update();
- window.show();
- ::nana::exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement