mirror of
https://github.com/alexkay/spek.git
synced 2025-06-07 10:53:00 +03:00
Add the frequency ruler
This commit is contained in:
parent
c7e088496f
commit
c04c76a0b6
@ -40,16 +40,16 @@ namespace Spek {
|
|||||||
this.format_tick = format_tick;
|
this.format_tick = format_tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw (Context cr) {
|
public void draw (Context cr, bool horizontal) {
|
||||||
// Mesure the sample label.
|
// Mesure the sample label.
|
||||||
TextExtents ext;
|
TextExtents ext;
|
||||||
cr.text_extents (sample_label, out ext);
|
cr.text_extents (sample_label, out ext);
|
||||||
var label_width = ext.width;
|
var size = horizontal ? ext.width : ext.height;
|
||||||
|
|
||||||
// Select the factor to use, we want some space between the labels.
|
// Select the factor to use, we want some space between the labels.
|
||||||
int factor = 0;
|
int factor = 0;
|
||||||
foreach (var f in factors) {
|
foreach (var f in factors) {
|
||||||
if (unit_to_pixel (f) >= 1.5 * label_width) {
|
if (unit_to_pixel (f) >= 1.5 * size) {
|
||||||
factor = f;
|
factor = f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ namespace Spek {
|
|||||||
int[] ticks = { 0, units };
|
int[] ticks = { 0, units };
|
||||||
if (factor > 0) {
|
if (factor > 0) {
|
||||||
for (var tick = factor; tick < units; tick += factor) {
|
for (var tick = factor; tick < units; tick += factor) {
|
||||||
if (unit_to_pixel (units - tick) < label_width) {
|
if (unit_to_pixel (units - tick) < size) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ticks += tick;
|
ticks += tick;
|
||||||
@ -72,13 +72,22 @@ namespace Spek {
|
|||||||
double TICK_LEN = 4;
|
double TICK_LEN = 4;
|
||||||
foreach (var tick in ticks) {
|
foreach (var tick in ticks) {
|
||||||
var label = format_tick (tick);
|
var label = format_tick (tick);
|
||||||
var pos = unit_to_pixel (tick);
|
var pos = unit_to_pixel (horizontal ? tick : units - tick);
|
||||||
cr.text_extents (label, out ext);
|
cr.text_extents (label, out ext);
|
||||||
// TODO: use font measurements instead ext.height
|
// TODO: use font measurements instead ext.height
|
||||||
cr.move_to (pos - ext.width / 2, GAP + ext.height);
|
if (horizontal) {
|
||||||
|
cr.move_to (pos - ext.width / 2, GAP + ext.height);
|
||||||
|
} else {
|
||||||
|
cr.move_to (-ext.width - GAP, pos + ext.height / 2);
|
||||||
|
}
|
||||||
cr.show_text (label);
|
cr.show_text (label);
|
||||||
cr.move_to (pos, 0);
|
if (horizontal) {
|
||||||
cr.rel_line_to (0, TICK_LEN);
|
cr.move_to (pos, 0);
|
||||||
|
cr.rel_line_to (0, TICK_LEN);
|
||||||
|
} else {
|
||||||
|
cr.move_to (0, pos);
|
||||||
|
cr.rel_line_to (-TICK_LEN, 0);
|
||||||
|
}
|
||||||
cr.stroke ();
|
cr.stroke ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace Spek {
|
|||||||
|
|
||||||
private ImageSurface image;
|
private ImageSurface image;
|
||||||
private ImageSurface palette;
|
private ImageSurface palette;
|
||||||
private const int PADDING = 40;
|
private const int PADDING = 60;
|
||||||
private const int GAP = 10;
|
private const int GAP = 10;
|
||||||
private const int RULER = 10;
|
private const int RULER = 10;
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ namespace Spek {
|
|||||||
cr.paint ();
|
cr.paint ();
|
||||||
cr.identity_matrix ();
|
cr.identity_matrix ();
|
||||||
|
|
||||||
// Prepare to draw the time ruler.
|
// Prepare to draw the rulers.
|
||||||
cr.set_source_rgb (1, 1, 1);
|
cr.set_source_rgb (1, 1, 1);
|
||||||
cr.set_line_width (1);
|
cr.set_line_width (1);
|
||||||
cr.set_antialias (Antialias.NONE);
|
cr.set_antialias (Antialias.NONE);
|
||||||
@ -136,7 +136,19 @@ namespace Spek {
|
|||||||
unit => (w - 2 * PADDING) * unit / duration_seconds,
|
unit => (w - 2 * PADDING) * unit / duration_seconds,
|
||||||
unit => "%d:%02d".printf (unit / 60, unit % 60));
|
unit => "%d:%02d".printf (unit / 60, unit % 60));
|
||||||
cr.translate (PADDING, h - PADDING);
|
cr.translate (PADDING, h - PADDING);
|
||||||
time_ruler.draw (cr);
|
time_ruler.draw (cr, true);
|
||||||
|
cr.identity_matrix ();
|
||||||
|
|
||||||
|
// Frequency ruler.
|
||||||
|
var freq = source.rate / 2;
|
||||||
|
var rate_ruler = new Ruler (
|
||||||
|
"00.0 kHz",
|
||||||
|
{1000, 2000, 5000, 10000, 20000},
|
||||||
|
freq,
|
||||||
|
unit => (h - 2 * PADDING) * unit / freq,
|
||||||
|
unit => "%d.%01d kHz".printf (unit / 1000, (unit % 1000) / 100));
|
||||||
|
cr.translate (PADDING, PADDING);
|
||||||
|
rate_ruler.draw (cr, false);
|
||||||
cr.identity_matrix ();
|
cr.identity_matrix ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user