]> Shamusworld >> Repos - wozmaker/blob - src/diskdrawthread.cpp
Flesh out the disk settings dialog.
[wozmaker] / src / diskdrawthread.cpp
1 //
2 // diskdrawthread.cpp: Disk display thread
3 //
4 // Part of the WOZ Maker project
5 // by James Hammons
6 // (C) 2018 Underground Software
7 //
8 // Since this can take a bit of time, we shunt all the heavy lifting to a
9 // separate worker thread so that it doesn't block the GUI thread.
10 //
11
12 #include "diskdrawthread.h"
13
14 #include <QtWidgets>
15 #include <cmath>
16 #include "fileio.h"
17 #include "global.h"
18
19
20 DiskDrawThread::DiskDrawThread(QObject * parent): QThread(parent)
21 {
22 }
23
24
25 DiskDrawThread::~DiskDrawThread()
26 {
27 #if 0
28         mutex.lock();
29         abort = true;
30         condition.wakeOne();
31         mutex.unlock();
32
33         wait();
34 #endif
35 }
36
37
38 void DiskDrawThread::StartRender(QImage * i)
39 {
40         img = i;
41         start(LowPriority);
42 }
43
44
45 void DiskDrawThread::run()
46 {
47         DrawDisk(img);
48 }
49
50
51 void DiskDrawThread::DrawDisk(QImage * diskImg)
52 {
53         QPainter painter(diskImg);
54         painter.setRenderHint(QPainter::Antialiasing);
55
56         QPen dkGreyPen(QColor(0x3A, 0x3B, 0x3A, 0xFF));
57         QBrush dkGreyBrush(QColor(0x3A, 0x3B, 0x3A, 0xFF));
58
59         // Draw empty disk
60         painter.setPen(dkGreyPen);
61         painter.setBrush(dkGreyBrush);
62         painter.drawEllipse(0, 0, 1024, 1024);
63         painter.setPen(Qt::white);
64         painter.setBrush(Qt::white);
65         painter.drawEllipse(388, 388, 248, 248);
66
67 /*
68 945 - 1067
69 948-949 (brighter to the 949 side) 1063-1064 (brighter to the 1064 side)
70
71 116 px for 36 tracks (3.2857... px per track)
72
73 3px on each side of the tracks
74
75 388 / 122 = 3.1803278688525
76 qtr track width = 2.6836879432624
77 */
78         // Draw disk track data
79         uint8_t lastLocation = 0xFF;
80         float x = 9.6, y = 9.6, w = 1024.0 - (2.0 * 9.6);
81         float tw = 2.6156028368794;
82
83         for(uint32_t str=0; str<Global::numStreams; str++)
84         {
85 //N.B.: Should also make sure this isn't a BITS stream, or handle it properly (because right now, it doesn't)
86                 if (Global::stream[str]->location != lastLocation)
87                 {
88                         uint32_t splicePoint = Uint32LE(Global::stream[str]->estLoopPoint);
89                         float angleTime = (float)splicePoint / (5760.0f / 2.0f);
90                         uint32_t pos = 0;
91                         float strTime = 0;
92                         float curTime = angleTime;
93
94                         for(uint32_t i=0; i<5760; i+=2)
95                         {
96                                 float ones = 0;
97
98                                 while (strTime < curTime)
99                                 {
100                                         while (Global::stream[str]->data[pos] == 0xFF)
101                                                 strTime += Global::stream[str]->data[pos++];
102
103                                         strTime += Global::stream[str]->data[pos++];
104                                         ones += 1.0f;
105                                 }
106
107                                 uint32_t color = ((ones * 32.0f) / angleTime) * 255.0f;
108
109                                 if (color > 255)
110                                         color = 255;
111
112                                 painter.setPen(QPen(QColor(color, color, color, 0xFF), tw, Qt::SolidLine));
113                                 painter.drawArc(x, y, w, w, -i + 1440, 2);
114
115                                 curTime += angleTime;
116                         }
117
118                         x += tw;
119                         y += tw;
120                         w -= tw * 2.0;
121                         lastLocation = Global::stream[str]->location;
122                         emit(ShowDisk());
123                 }
124         }
125
126 //      emit(ShowDisk());
127 }
128