-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
109 lines (99 loc) · 2.33 KB
/
Copy pathmainwindow.cpp
File metadata and controls
109 lines (99 loc) · 2.33 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <QThreadPool>
#include <QDateTime>
#include <QImage>
#include <iostream>
#include <QMessageBox>
#include <sys/time.h>
#include <QTimer>
#include "mainwindow.h"
#include "ui_mainwindow.h"
extern const char *_kernelSrc;
double left = -2.5;
double top = -1.5;
double fwidth = 3.5;
double fheight = 3.0;
unsigned int iterations = 1024;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->cpuPB,SIGNAL(clicked(bool)),this,SLOT(cpuCompute()));
connect(ui->stPB,SIGNAL(clicked(bool)),this,SLOT(stCompute()));
pushButtons.append(ui->cpuPB);
pushButtons.append(ui->stPB);
QTimer::singleShot(0,this,&MainWindow::gpuDetect);
currentButton = nullptr;
}
MainWindow::~MainWindow()
{
delete ui;
}
gpuDef::gpuDef()
{
id = nullptr;
kernel = nullptr;
cmdQueue = nullptr;
context = nullptr;
}
gpuDef::~gpuDef()
{
if (cmdQueue)
{
clFlush(cmdQueue);
clFinish(cmdQueue);
clReleaseCommandQueue(cmdQueue);
}
if (kernel)
clReleaseKernel(kernel);
if (context)
clReleaseContext(context);
if (id)
clReleaseDevice(id);
}
void MainWindow::wheelEvent(QWheelEvent *ev)
{
iterations += ev->angleDelta().y();
if (currentButton)
currentButton->click();
}
void MainWindow::mousePressEvent(QMouseEvent *ev)
{
if (ev->button() == Qt::LeftButton)
{
QPoint p = ui->fracImg->mapFromParent(ev->pos());
double clx = left + (p.x() * fwidth / double(ui->fracImg->width()));
double cly = top + (p.y() * fheight / double(ui->fracImg->height()));
fwidth *= 0.75;
fheight *= 0.75;
top = cly - (fheight / 2);
left = clx - (fwidth / 2);
} else {
QPoint p = ui->fracImg->mapFromParent(ev->pos());
double clx = left + (p.x() * fwidth / double(ui->fracImg->width()));
double cly = top + (p.y() * fheight / double(ui->fracImg->height()));
fwidth *= 1.5;
fheight *= 1.5;
top = cly - (fheight / 2);
left = clx - (fwidth / 2);
}
if (currentButton)
currentButton->click();
}
double MainWindow::currentTime()
{
struct timeval t;
gettimeofday(&t,NULL);
double rv = t.tv_sec;
rv += (t.tv_usec / 1000000.0);
return rv;
}
void MainWindow::setButtonChecked(QPushButton *pb)
{
if (!pb)
return;
foreach (QPushButton *b,pushButtons)
b->setChecked(false);
pb->setChecked(true);
currentButton = pb;
}