This repository has been archived by the owner on Apr 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImpressionist.cpp
79 lines (64 loc) · 1.81 KB
/
Impressionist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// impressionist.cpp
//
// The main driver program for the other parts. We have two major components,
// UI and Doc.
// They do have a link to each other as their member such that they can
// communicate.
//
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
#include "impressionistDoc.h"
#include "impressionistUI.h"
#include "Image.hpp"
#include "VideoUtils.hpp"
#include <chrono>
#include <thread>
#include <functional>
ImpressionistUI* impUI;
ImpressionistDoc* impDoc;
void timer_start(std::function<void(void)> func, unsigned int interval)
{
std::thread([func, interval]()
{
while (true)
{
auto x = std::chrono::steady_clock::now() + std::chrono::milliseconds(interval);
func();
std::this_thread::sleep_until(x);
}
}).detach();
}
void task() {
if (impDoc->app_mode == VIDEO && impUI->m_paintView->finish_painting_flag) {
Image frame = VideoUtils::next_frame();
if (frame.contain_content()) {
impUI->m_origView->set_current_img(frame);
impUI->m_paintView->cur = frame;
impUI->m_paintView->auto_paint_flag = true;
printf("request draw\n");
fflush(stdout);
impUI->m_paintView->refresh();
}
} else if (!impUI->m_paintView->finish_painting_flag) {
//printf("skip this loop\n");
fflush(stdout);
}
}
int main(int argc, char **argv) {
impDoc = new ImpressionistDoc();
// Create the UI
impUI = new ImpressionistUI();
// Set the impDoc which is used as the bridge between UI and brushes
impUI->setDocument(impDoc);
impDoc->setUI(impUI);
Fl::visual(FL_DOUBLE | FL_INDEX);
timer_start(task, 50);
impUI->show();
return Fl::run();
}
// global functions
float frand() { return (float)rand() / RAND_MAX; }
int irand(int max) { return rand() % max; }