Mercurial > hg > svgui
comparison layer/LogNumericalScale.cpp @ 1277:82258db96244 horizontal-scale
Draw some ticks
author | Chris Cannam |
---|---|
date | Tue, 01 May 2018 16:32:35 +0100 |
parents | b4cb11ca8233 |
children | b6fc0970cd66 |
comparison
equal
deleted
inserted
replaced
1276:b4cb11ca8233 | 1277:82258db96244 |
---|---|
93 { | 93 { |
94 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | 94 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); |
95 | 95 |
96 paint.drawLine(x0, y0, x1, y0); | 96 paint.drawLine(x0, y0, x1, y0); |
97 | 97 |
98 double f0 = p->getFrequencyForX(v, x0); | 98 double f0 = p->getFrequencyForX(v, x0 ? x0 : 1); |
99 double f1 = p->getFrequencyForX(v, x1); | 99 double f1 = p->getFrequencyForX(v, x1); |
100 | 100 |
101 cerr << "f0 = " << f0 << " at x " << (x0 ? x0 : 1) << endl; | |
102 cerr << "f1 = " << f1 << " at x " << x1 << endl; | |
103 | |
101 int n = 10; | 104 int n = 10; |
102 auto ticks = ScaleTickIntervals::logarithmic({ f0, f1, n }); | 105 auto ticks = ScaleTickIntervals::logarithmic({ f0, f1, n }); |
103 n = int(ticks.size()); | 106 n = int(ticks.size()); |
104 | 107 |
105 // int prevx = -1; | 108 int marginx = -1; |
106 (void)y1; | |
107 | 109 |
108 for (int i = 0; i < n; ++i) { | 110 for (int i = 0; i < n; ++i) { |
109 | 111 |
110 double val = ticks[i].value; | 112 double val = ticks[i].value; |
111 QString label = QString::fromStdString(ticks[i].label); | 113 QString label = QString::fromStdString(ticks[i].label); |
112 int tw = paint.fontMetrics().width(label); | 114 int tw = paint.fontMetrics().width(label); |
113 | 115 |
114 cerr << "i = " << i << ", value = " << val << ", tw = " << tw << endl; | 116 cerr << "i = " << i << ", value = " << val << ", tw = " << tw << endl; |
115 | 117 |
116 double x = p->getXForFrequency(v, val); | 118 int x = int(round(p->getXForFrequency(v, val))); |
117 | 119 |
118 cerr << "x = " << x << endl; | 120 cerr << "x = " << x << endl; |
121 | |
122 if (x < marginx) continue; | |
119 | 123 |
124 //!!! todo: pixel scaling (here & elsewhere in these classes) | |
125 | |
126 paint.drawLine(x, y0, x, y1); | |
127 | |
128 paint.drawText(x + 5, y0 + paint.fontMetrics().ascent() + 5, label); | |
129 | |
130 marginx = x + tw + 10; | |
120 } | 131 } |
121 } | 132 } |
122 | 133 |