diff options
Diffstat (limited to 'plugins/gtkui/ddbequalizer.vala')
-rw-r--r-- | plugins/gtkui/ddbequalizer.vala | 183 |
1 files changed, 96 insertions, 87 deletions
diff --git a/plugins/gtkui/ddbequalizer.vala b/plugins/gtkui/ddbequalizer.vala index 4b82671c..82a1f060 100644 --- a/plugins/gtkui/ddbequalizer.vala +++ b/plugins/gtkui/ddbequalizer.vala @@ -18,6 +18,9 @@ // sripped down and polished by Alexey Yakovenko <waker@users.sourceforge.net> +using Gtk; +using Gdk; + const string[] freqs = { "55 Hz","77 Hz","110 Hz","156 Hz","220 Hz","311 Hz","440 Hz","622 Hz","880 Hz", "1.2 kHz","1.8 kHz","2.5 kHz","3.5 kHz","5 kHz","7 kHz","10 kHz","14 kHz","20 kHz" @@ -36,8 +39,8 @@ namespace Ddb { private bool curve_hook = false; private bool preamp_hook = false; - private int margin_bottom = -1; - private int margin_left = -1; + private int eq_margin_bottom = -1; + private int eq_margin_left = -1; static const int spot_size = 3; static const int bands = 18; @@ -47,8 +50,8 @@ namespace Ddb { construct { - margin_bottom = (int)(Pango.units_to_double (get_style ().font_desc.get_size ()) * Gdk.Screen.get_default ().get_resolution () / 72 + 4); - margin_left = margin_bottom * 4; + eq_margin_bottom = (int)(Pango.units_to_double (get_style ().font_desc.get_size ()) * Gdk.Screen.get_default ().get_resolution () / 72 + 4); + eq_margin_left = eq_margin_bottom * 4; //color_changed (); } @@ -75,121 +78,131 @@ namespace Ddb { fore_dark_color.green += (int16)((c1.green - c2.green) * 0.5); fore_dark_color.blue += (int16)((c1.blue - c2.blue) * 0.5); - int width = allocation.width; - int height = allocation.height; + Allocation alloc; + get_allocation (out alloc); - Gdk.Drawable d = get_window(); - var gc = d.create_gc (Gdk.GCValues(), 0); - //Gdk.Rectangle rc = {0, 0, allocation.width, allocation.height}; - //gc.set_clip_rectangle (rc); + int width = alloc.width; + int height = alloc.height; - gc.set_rgb_fg_color (c2); + var ctx = Gdk.cairo_create (get_window ()); + ctx.set_antialias (Cairo.Antialias.NONE); + ctx.set_line_width (1.0); + ctx.set_source_rgba (c2.red/65535.0, c2.green/65535.0, c2.blue/65535.0, 1); + ctx.rectangle (0, 0, width, height); + ctx.fill (); - d.draw_rectangle (gc, true, 0, 0, width, height); + ctx.set_source_rgba (fore_dark_color.red/65535.0, fore_dark_color.green/65535.0, fore_dark_color.blue/65535.0, 1); - gc.set_rgb_fg_color (fore_dark_color); //drawing grid: - double step = (double)(width - margin_left) / (double)(bands+1); + double step = (double)(width - eq_margin_left) / (double)(bands+1); int i; for (i = 0; i < bands; i++) { //does anyone know why this method is static? - Gdk.draw_line (d, gc, - (int)((i+1)*step)+margin_left, - 0, - (int)((i+1)*step)+margin_left, - height - margin_bottom); + ctx.move_to ((int)((i+1)*step)+eq_margin_left, 0); + ctx.line_to ((int)((i+1)*step)+eq_margin_left, height - eq_margin_bottom); } - double vstep = (double)(height-margin_bottom); + double vstep = (double)(height-eq_margin_bottom); for (double di=0; di < 2; di += 0.25) { - Gdk.draw_line (d, gc, - margin_left, - (int)((di-preamp)*vstep), - width, - (int)((di-preamp)*vstep)); + ctx.move_to (eq_margin_left, (int)((di-preamp)*vstep)); + ctx.line_to (width, (int)((di-preamp)*vstep)); } + ctx.stroke (); - gc.set_rgb_fg_color (fore_bright_color); + ctx.set_source_rgba (fore_bright_color.red/65535.0, fore_bright_color.green/65535.0, fore_bright_color.blue/65535.0, 1); //drawing freqs: - Pango.Layout l = create_pango_layout (null); - var ctx = l.get_context (); + + Pango.Layout l = Pango.cairo_create_layout (ctx); + var pctx = l.get_context (); var fd = get_style ().font_desc.copy (); -// var fd = ctx.get_font_description (); fd.set_size ((int)(get_style ().font_desc.get_size () * 0.7)); - ctx.set_font_description (fd); + pctx.set_font_description (fd); for (i = 0; i < bands; i++) { - l.set_text (freqs[i], (int)freqs[i].len()); + ctx.save (); + l.set_text (freqs[i], (int)freqs[i].length); Pango.Rectangle ink, log; l.get_pixel_extents (out ink, out log); int offs = 2; if ((i % 2) != 0) { offs += 2; } - Gdk.draw_layout (d, gc, (int)((i+1)*step)+margin_left - ink.width/2, height-margin_bottom + offs, l); + ctx.move_to ( (int)((i+1)*step)+eq_margin_left - ink.width/2, height-eq_margin_bottom + offs); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); } fd.set_size ((int)(get_style ().font_desc.get_size ())); - ctx.set_font_description (fd); + pctx.set_font_description (fd); //drawing db's: - l.set_width (margin_left-1); + l.set_width (eq_margin_left-1); l.set_alignment (Pango.Alignment.RIGHT); int fontsize = (int)(Pango.units_to_double (fd.get_size ()) * Gdk.Screen.get_default ().get_resolution () / 72); - if ((mouse_y >= 0) && (mouse_y < height - margin_bottom)) + if ((mouse_y >= 0) && (mouse_y < height - eq_margin_bottom)) { - double db = scale((double)(mouse_y-1) / (double)(height - margin_bottom - 2)); + ctx.save (); + double db = scale((double)(mouse_y-1) / (double)(height - eq_margin_bottom - 2)); string tmp = "%s%.1fdB".printf (db > 0 ? "+" : "", db); - l.set_text (tmp, (int)tmp.len()); - Gdk.draw_layout (d, gc, margin_left-1, mouse_y-3, l); + l.set_text (tmp, (int)tmp.length); + ctx.move_to (eq_margin_left-1, mouse_y-3); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); } + ctx.save (); string tmp; double val = scale(1); tmp = "%s%.1fdB".printf (val > 0 ? "+" : "", val); - l.set_text (tmp, (int)tmp.len()); - Gdk.draw_layout (d, gc, margin_left-1, height-margin_bottom-fontsize, l); + l.set_text (tmp, (int)tmp.length); + ctx.move_to (eq_margin_left-1, height-eq_margin_bottom-fontsize); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); + ctx.save (); val = scale(0); tmp = "%s%.1fdB".printf (val > 0 ? "+" : "", val); - l.set_text (tmp, (int)tmp.len()); - Gdk.draw_layout (d, gc, margin_left-1, 1, l); + l.set_text (tmp, (int)tmp.length); + ctx.move_to (eq_margin_left-1, 1); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); + ctx.save (); l.set_text ("+0dB", 4); - Gdk.draw_layout (d, gc, margin_left-1, (int)((1-preamp)*(height-margin_bottom))-fontsize/2, l); + ctx.move_to (eq_margin_left-1, (int)((1-preamp)*(height-eq_margin_bottom))-fontsize/2); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); + ctx.save (); l.set_text ("preamp", 6); l.set_alignment (Pango.Alignment.LEFT); - Gdk.draw_layout (d, gc, 1, height-margin_bottom+2, l); + ctx.move_to (1, height-eq_margin_bottom+2); + Pango.cairo_show_layout (ctx, l); + ctx.restore (); - d.draw_rectangle (gc, false, margin_left, 0, width-margin_left-1, height-margin_bottom-1); - gc.set_line_attributes (2, Gdk.LineStyle.SOLID, Gdk.CapStyle.NOT_LAST, Gdk.JoinStyle.MITER); - - //draw preamp - gc.set_clip_rectangle ({0, (int)(preamp * (height-margin_bottom)), 11, height}); + // frame + ctx.rectangle (eq_margin_left, 0, width-eq_margin_left-1, height-eq_margin_bottom-1); + ctx.stroke (); - gc.set_rgb_fg_color (fore_bright_color); - int count = (int)((height-margin_bottom) / 6)+1; - for (int j = 0; j < count; j++) - d.draw_rectangle ( - gc, - true, - 1, - height-margin_bottom-j*6 - 6, - 11, - 4); + //draw preamp + ctx.rectangle (0, (int)(preamp * (height-eq_margin_bottom)), 11, height); + ctx.clip (); - gc.set_clip_rectangle ({margin_left+1, 1, width-margin_left-2, height-margin_bottom-2}); + ctx.set_source_rgba (fore_bright_color.red/65535.0, fore_bright_color.green/65535.0, fore_bright_color.blue/65535.0, 1.0); + int count = (int)((height-eq_margin_bottom) / 6)+1; + for (int j = 0; j < count; j++) { + ctx.rectangle (1, height-eq_margin_bottom-j*6 - 6, 11, 4); + } + ctx.fill (); + ctx.reset_clip (); //drawing bars: - gc.set_rgb_fg_color (fore_bright_color); - int bar_w = 11; if (step < bar_w) bar_w = (int)step-1; @@ -197,26 +210,22 @@ namespace Ddb { for (i = 0; i < bands; i++) { - gc.set_clip_rectangle ({ - (int)((i+1)*step)+margin_left - bar_w/2, - (int)(values[i] * (height-margin_bottom)), - 11, - height}); - count = (int)((height-margin_bottom) * (1-values[i]) / 6)+1; - for (int j = 0; j < count; j++) - d.draw_rectangle ( - gc, - true, - (int)((i+1)*step)+margin_left - bar_w/2, - height-margin_bottom-j*6 - 6, - bar_w, - 4); + ctx.reset_clip (); + ctx.rectangle ((int)((i+1)*step)+eq_margin_left - bar_w/2, (int)(values[i] * (height-eq_margin_bottom)), 11, height); + ctx.clip (); + count = (int)((height-eq_margin_bottom) * (1-values[i]) / 6)+1; + for (int j = 0; j < count; j++) { + ctx.rectangle ( (int)((i+1)*step)+eq_margin_left - bar_w/2, height-eq_margin_bottom-j*6 - 6, bar_w, 4); + } + ctx.fill (); } - gc.set_clip_rectangle ({0, 0, width, height}); //drawing mouse coordinates: - gc.set_line_attributes (1, Gdk.LineStyle.ON_OFF_DASH, Gdk.CapStyle.NOT_LAST, Gdk.JoinStyle.MITER); - Gdk.draw_line (d, gc, margin_left+1, mouse_y, width, mouse_y); + ctx.reset_clip (); + ctx.set_dash (new double[] {4, 4}, 0); + ctx.move_to (eq_margin_left+1, mouse_y); + ctx.line_to (width, mouse_y); + ctx.stroke (); return false; } @@ -233,16 +242,16 @@ namespace Ddb { in_curve_area (double x, double y) { return - x > margin_left && + x > eq_margin_left && x < allocation.width-1 && y > 1 && - y < allocation.height-margin_bottom; + y < allocation.height-eq_margin_bottom; } private void update_eq_drag (double x, double y) { - double band_width = (double)(allocation.width - margin_left) / (double)(bands+1); - int band = (int)GLib.Math.floor ((x - margin_left) / band_width - 0.5); + double band_width = (double)(allocation.width - eq_margin_left) / (double)(bands+1); + int band = (int)GLib.Math.floor ((x - eq_margin_left) / band_width - 0.5); if (band < 0) { band = 0; } @@ -250,7 +259,7 @@ namespace Ddb { band = band-1; } if (band >= 0 && band < bands) { - values[band] = y / (double)(allocation.height - margin_bottom); + values[band] = y / (double)(allocation.height - eq_margin_bottom); if (values[band] > 1) { values[band] = 1; } @@ -276,11 +285,11 @@ namespace Ddb { if (event.x <= 11 && event.y > 1 && - event.y <= allocation.height-margin_bottom && + event.y <= allocation.height-eq_margin_bottom && event.button == 1 ) { - preamp = event.y / (double)(allocation.height - margin_bottom); + preamp = event.y / (double)(allocation.height - eq_margin_bottom); on_changed (); preamp_hook = true; mouse_y = (int)event.y; @@ -311,7 +320,7 @@ namespace Ddb { /* Mouse pointer moved over widget */ public override bool motion_notify_event (Gdk.EventMotion event) { - double y = event.y / (double)(allocation.height - margin_bottom); + double y = event.y / (double)(allocation.height - eq_margin_bottom); if (y < 0) y = 0; if (y > 1) y = 1; |