Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <nana/gui.hpp>
- #include <nana/gui/widgets/menubar.hpp>
- #include <nana/gui/widgets/textbox.hpp>
- #include <nana/gui/place.hpp>
- #include <nana/gui/msgbox.hpp>
- #include <nana/gui/filebox.hpp>
- #include <nana/gui/widgets/button.hpp>
- #include <nana/gui/widgets/progress.hpp>
- #include <nana/threads/pool.hpp>
- #include <thread>
- #include <iostream>
- #include <atomic>
- using namespace nana;
- class MainWindow : public form
- {
- public:
- MainWindow();
- ~MainWindow();
- void wait(unsigned int wait = 0);
- private:
- void mainLoop();
- place place{ *this };
- textbox textBox{ *this };
- button startBtn{ *this };
- progress progressBar{ *this };
- threads::pool pool_;
- std::atomic_bool flag = true;
- std::atomic_bool started = false;
- };
- #include "MainWindow.h"
- MainWindow::MainWindow()
- {
- caption("Simple Game");
- textBox.borderless(true);
- textBox.editable(false);
- API::effects_edge_nimbus(textBox, effects::edge_nimbus::none);
- API::window_size(*this, nana::size(400, 450));
- place.div("vert<textbox height=400><btn height=20><progress height=20>");
- place["textbox"] << textBox;
- place["btn"] << startBtn;
- place["progress"] << progressBar;
- place.collocate();
- startBtn.caption("Start");
- startBtn.events().click(nana::threads::pool_push(pool_, *this, &MainWindow::mainLoop));
- auto window_handle = this->handle();
- textBox.events().key_press([&](const nana::arg_keyboard&arg)
- {
- textBox.reset("");
- textBox.append(std::wstring(L"Key pressed: ") + std::wstring(&arg.key) + L"\n", true);
- });
- }
- MainWindow::~MainWindow()
- {
- flag = false;
- pool_.wait_for_finished();
- }
- void MainWindow::mainLoop()
- {
- if (!started)
- {
- started = true;
- startBtn.caption("Stop");
- while (flag)
- {
- progressBar.inc();
- if (progressBar.value() >= 100)
- progressBar.value(0);
- wait(100);
- }
- startBtn.caption("Start");
- flag = true;
- }
- else
- {
- started = false;
- flag = false;
- }
- }
- void MainWindow::wait(unsigned int wait)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds{ wait });
- }
- #include "MainWindow.h"
- int main()
- {
- MainWindow window;
- window.show();
- exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement