mirror of
https://github.com/alexkay/spek.git
synced 2025-06-06 02:13:31 +03:00
Right and top rulers
This commit is contained in:
parent
bf139c96a9
commit
a741fb0d22
@ -21,7 +21,14 @@ using Pango;
|
|||||||
|
|
||||||
namespace Spek {
|
namespace Spek {
|
||||||
class Ruler : GLib.Object {
|
class Ruler : GLib.Object {
|
||||||
|
public enum Position {
|
||||||
|
TOP,
|
||||||
|
RIGHT,
|
||||||
|
BOTTOM,
|
||||||
|
LEFT
|
||||||
|
}
|
||||||
|
|
||||||
|
private Position pos;
|
||||||
private string sample_label;
|
private string sample_label;
|
||||||
private int[] factors;
|
private int[] factors;
|
||||||
private int units;
|
private int units;
|
||||||
@ -33,8 +40,10 @@ namespace Spek {
|
|||||||
public delegate string FormatTick (int unit);
|
public delegate string FormatTick (int unit);
|
||||||
|
|
||||||
public Ruler (
|
public Ruler (
|
||||||
string sample_label, int[] factors, int units, double spacing,
|
Position pos, string sample_label,
|
||||||
|
int[] factors, int units, double spacing,
|
||||||
UnitToPixel unit_to_pixel, FormatTick format_tick) {
|
UnitToPixel unit_to_pixel, FormatTick format_tick) {
|
||||||
|
this.pos = pos;
|
||||||
this.sample_label = sample_label;
|
this.sample_label = sample_label;
|
||||||
this.factors = factors;
|
this.factors = factors;
|
||||||
this.units = units;
|
this.units = units;
|
||||||
@ -43,12 +52,12 @@ namespace Spek {
|
|||||||
this.format_tick = format_tick;
|
this.format_tick = format_tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw (Cairo.Context cr, Pango.Layout layout, bool horizontal) {
|
public void draw (Cairo.Context cr, Pango.Layout layout) {
|
||||||
// Mesure the sample label.
|
// Mesure the sample label.
|
||||||
int w, h;
|
int w, h;
|
||||||
layout.set_text (sample_label, -1);
|
layout.set_text (sample_label, -1);
|
||||||
layout.get_pixel_size (out w, out h);
|
layout.get_pixel_size (out w, out h);
|
||||||
var size = horizontal ? w : h;
|
var size = pos == Position.TOP || pos == Position.BOTTOM ? w : h;
|
||||||
|
|
||||||
// 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;
|
||||||
@ -76,20 +85,32 @@ 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 (horizontal ? tick : units - tick);
|
var p = unit_to_pixel (
|
||||||
|
pos == Position.TOP || pos == Position.BOTTOM
|
||||||
|
? tick : units - tick);
|
||||||
layout.set_text (label, -1);
|
layout.set_text (label, -1);
|
||||||
layout.get_pixel_size (out w, out h);
|
layout.get_pixel_size (out w, out h);
|
||||||
if (horizontal) {
|
if (pos == Position.TOP) {
|
||||||
cr.move_to (pos - w / 2, GAP + h);
|
cr.move_to (p - w / 2, -GAP - h);
|
||||||
} else {
|
} else if (pos == Position.RIGHT){
|
||||||
cr.move_to (-w - GAP, pos + h / 2);
|
cr.move_to (w + GAP, p + h / 2);
|
||||||
|
} else if (pos == Position.BOTTOM) {
|
||||||
|
cr.move_to (p - w / 2, GAP + h);
|
||||||
|
} else if (pos == Position.LEFT){
|
||||||
|
cr.move_to (-w - GAP, p + h / 2);
|
||||||
}
|
}
|
||||||
cairo_show_layout_line (cr, layout.get_line (0));
|
cairo_show_layout_line (cr, layout.get_line (0));
|
||||||
if (horizontal) {
|
if (pos == Position.TOP) {
|
||||||
cr.move_to (pos, 0);
|
cr.move_to (p, 0);
|
||||||
|
cr.rel_line_to (0, -TICK_LEN);
|
||||||
|
} else if (pos == Position.RIGHT) {
|
||||||
|
cr.move_to (0, p);
|
||||||
|
cr.rel_line_to (TICK_LEN, 0);
|
||||||
|
} else if (pos == Position.BOTTOM) {
|
||||||
|
cr.move_to (p, 0);
|
||||||
cr.rel_line_to (0, TICK_LEN);
|
cr.rel_line_to (0, TICK_LEN);
|
||||||
} else {
|
} else if (pos == Position.LEFT) {
|
||||||
cr.move_to (0, pos);
|
cr.move_to (0, p);
|
||||||
cr.rel_line_to (-TICK_LEN, 0);
|
cr.rel_line_to (-TICK_LEN, 0);
|
||||||
}
|
}
|
||||||
cr.stroke ();
|
cr.stroke ();
|
||||||
|
@ -180,6 +180,7 @@ namespace Spek {
|
|||||||
// Time ruler.
|
// Time ruler.
|
||||||
var duration_seconds = (int) pipeline.duration;
|
var duration_seconds = (int) pipeline.duration;
|
||||||
var time_ruler = new Ruler (
|
var time_ruler = new Ruler (
|
||||||
|
Ruler.Position.BOTTOM,
|
||||||
"00:00",
|
"00:00",
|
||||||
{1, 2, 5, 10, 20, 30, 1*60, 2*60, 5*60, 10*60, 20*60, 30*60},
|
{1, 2, 5, 10, 20, 30, 1*60, 2*60, 5*60, 10*60, 20*60, 30*60},
|
||||||
duration_seconds,
|
duration_seconds,
|
||||||
@ -187,12 +188,13 @@ namespace Spek {
|
|||||||
unit => (w - LPAD - RPAD) * unit / duration_seconds,
|
unit => (w - LPAD - RPAD) * unit / duration_seconds,
|
||||||
unit => "%d:%02d".printf (unit / 60, unit % 60));
|
unit => "%d:%02d".printf (unit / 60, unit % 60));
|
||||||
cr.translate (LPAD, h - BPAD);
|
cr.translate (LPAD, h - BPAD);
|
||||||
time_ruler.draw (cr, layout, true);
|
time_ruler.draw (cr, layout);
|
||||||
cr.identity_matrix ();
|
cr.identity_matrix ();
|
||||||
|
|
||||||
// Frequency ruler.
|
// Frequency ruler.
|
||||||
var freq = pipeline.sample_rate / 2;
|
var freq = pipeline.sample_rate / 2;
|
||||||
var rate_ruler = new Ruler (
|
var rate_ruler = new Ruler (
|
||||||
|
Ruler.Position.LEFT,
|
||||||
"00 kHz",
|
"00 kHz",
|
||||||
{1000, 2000, 5000, 10000, 20000},
|
{1000, 2000, 5000, 10000, 20000},
|
||||||
freq,
|
freq,
|
||||||
@ -200,7 +202,7 @@ namespace Spek {
|
|||||||
unit => (h - TPAD - BPAD) * unit / freq,
|
unit => (h - TPAD - BPAD) * unit / freq,
|
||||||
unit => _("%d kHz").printf (unit / 1000));
|
unit => _("%d kHz").printf (unit / 1000));
|
||||||
cr.translate (LPAD, TPAD);
|
cr.translate (LPAD, TPAD);
|
||||||
rate_ruler.draw (cr, layout, false);
|
rate_ruler.draw (cr, layout);
|
||||||
cr.identity_matrix ();
|
cr.identity_matrix ();
|
||||||
|
|
||||||
// File properties.
|
// File properties.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user