]> Shamusworld >> Repos - wozmaker/blob - src/tmpwindow.cpp
Flesh out the disk settings dialog.
[wozmaker] / src / tmpwindow.cpp
1 //
2 // tmpwindow.cpp: Disk structure window
3 //
4 // Part of the WOZ Maker project
5 // by James Hammons
6 // (C) 2018 Underground Software
7 //
8
9 #include "tmpwindow.h"
10 #include "fileio.h"
11 #include "global.h"
12
13
14 TmpWindow::TmpWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window)
15 {
16         setGeometry(QRect(0, 0, 1024, 1024));
17         setMinimumWidth(1024);
18         setMinimumHeight(1024);
19         setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
20 }
21
22
23 TmpWindow::~TmpWindow(void)
24 {
25 }
26
27
28 void TmpWindow::paintEvent(QPaintEvent * /*event*/)
29 {
30         QPainter painter(this);
31         painter.setRenderHint(QPainter::Antialiasing);
32
33         QPen dkGreyPen(QColor(0x3A, 0x3B, 0x3A, 0xFF), 1.0, Qt::SolidLine);
34         QBrush dkGreyBrush(QColor(0x3A, 0x3B, 0x3A, 0xFF));
35
36         // Draw empty disk
37         painter.setPen(dkGreyPen);
38         painter.setBrush(dkGreyBrush);
39         painter.drawEllipse(0, 0, 1024, 1024);
40         painter.setPen(Qt::white);
41         painter.setBrush(Qt::white);
42         painter.drawEllipse(388, 388, 248, 248);
43
44         // Draw disk track data
45         uint8_t lastLocation = 0xFF;
46         uint32_t x = 4, y = 4, w = 1024 - (2 * 4);
47
48         for(uint32_t str=0; str<Global::numStreams; str++)
49         {
50                 if (Global::stream[str]->location != lastLocation)
51                 {
52                         uint32_t splicePoint = Uint32LE(Global::stream[str]->estLoopPoint);
53                         float angleTime = (float)splicePoint / (5760.0f / 2.0f);
54                         uint32_t pos = 0;
55                         float strTime = 0;
56                         float curTime = angleTime;
57
58                         for(uint32_t i=0; i<5760; i+=2)
59                         {
60                                 float ones = 0;
61
62                                 while (strTime < curTime)
63                                 {
64                                         while (Global::stream[str]->data[pos] == 0xFF)
65                                                 strTime += Global::stream[str]->data[pos++];
66
67                                         strTime += Global::stream[str]->data[pos++];
68                                         ones += 1.0f;
69                                 }
70
71                                 uint32_t color = ((ones * 32.0f) / angleTime) * 255.0f;
72
73                                 if (color > 255)
74                                         color = 255;
75
76                                 painter.setPen(QPen(QColor(color, color, color, 0xFF), 1.0, Qt::SolidLine));
77                                 painter.drawArc(x, y, w, w, -i, 2);
78                                 painter.drawArc(x+1, y+1, w-2, w-2, -i, 2);
79
80                                 curTime += angleTime;
81                         }
82
83                         x += 2;
84                         y += 2;
85                         w -= 4;
86                         lastLocation = Global::stream[str]->location;
87                 }
88         }
89 }
90