diff options
-rw-r--r-- | plugins/gtkui/ddbequalizer.c | 64 | ||||
-rw-r--r-- | plugins/gtkui/ddbequalizer.vala | 61 |
2 files changed, 99 insertions, 26 deletions
diff --git a/plugins/gtkui/ddbequalizer.c b/plugins/gtkui/ddbequalizer.c index db97cd45..2d8bc577 100644 --- a/plugins/gtkui/ddbequalizer.c +++ b/plugins/gtkui/ddbequalizer.c @@ -1,6 +1,24 @@ /* ddbequalizer.c generated by valac, the Vala compiler * generated from ddbequalizer.vala, do not modify */ +/* + SuperEQ GTK Widget for for DeaDBeeF + Copyright (C) 2010 Viktor Semykin <thesame.ml@gmail.com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +/* sripped down and polished by Alexey Yakovenko <waker@users.sourceforge.net>*/ #include <glib.h> #include <glib-object.h> @@ -96,17 +114,14 @@ static gpointer _g_object_ref0 (gpointer self) { } -static gpointer _pango_font_description_copy0 (gpointer self) { - return self ? pango_font_description_copy (self) : NULL; -} - - static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose* event) { DdbEqualizer * self; gboolean result = FALSE; GdkColor _tmp0_ = {0}; GdkColor fore_bright_color; + GdkColor c1; GdkColor _tmp1_ = {0}; + GdkColor c2; GdkColor fore_dark_color; gint width; gint height; @@ -120,6 +135,7 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose PangoLayout* l; PangoContext* ctx; PangoFontDescription* fd; + gint fontsize; gboolean _tmp7_ = FALSE; char* tmp; double val; @@ -137,7 +153,12 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose GdkRectangle _tmp22_ = {0}; self = (DdbEqualizer*) base; fore_bright_color = (gtkui_get_bar_foreground_color (&_tmp0_), _tmp0_); - fore_dark_color = (gtkui_get_bar_foreground_color (&_tmp1_), _tmp1_); + c1 = fore_bright_color; + c2 = (gtkui_get_bar_background_color (&_tmp1_), _tmp1_); + fore_dark_color = c2; + fore_dark_color.red = fore_dark_color.red + ((guint16) ((gint16) ((c1.red - c2.red) * 0.5))); + fore_dark_color.green = fore_dark_color.green + ((guint16) ((gint16) ((c1.green - c2.green) * 0.5))); + fore_dark_color.blue = fore_dark_color.blue + ((guint16) ((gint16) ((c1.blue - c2.blue) * 0.5))); width = ((GtkWidget*) self)->allocation.width; height = ((GtkWidget*) self)->allocation.height; d = _g_object_ref0 ((GdkDrawable*) gtk_widget_get_window ((GtkWidget*) self)); @@ -181,13 +202,17 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); l = gtk_widget_create_pango_layout ((GtkWidget*) self, NULL); ctx = _g_object_ref0 (pango_layout_get_context (l)); - fd = _pango_font_description_copy0 (pango_context_get_font_description (ctx)); + fd = pango_font_description_copy (gtk_widget_get_style ((GtkWidget*) self)->font_desc); + pango_font_description_set_size (fd, (gint) (pango_font_description_get_size (gtk_widget_get_style ((GtkWidget*) self)->font_desc) * 0.7)); pango_context_set_font_description (ctx, fd); { gboolean _tmp6_; i = 0; _tmp6_ = TRUE; while (TRUE) { + PangoRectangle ink = {0}; + PangoRectangle log = {0}; + gint offs; if (!_tmp6_) { i++; } @@ -196,11 +221,19 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose break; } pango_layout_set_text (l, freqs[i], (gint) g_utf8_strlen (freqs[i], -1)); - gdk_draw_layout (d, gc, ((gint) (((i + 1) * step) - 5)) + self->priv->margin_left, (height - self->priv->margin_bottom) + 2, l); + pango_layout_get_pixel_extents (l, &ink, &log); + offs = 2; + if ((i % 2) != 0) { + offs = offs + 2; + } + gdk_draw_layout (d, gc, (((gint) ((i + 1) * step)) + self->priv->margin_left) - (ink.width / 2), (height - self->priv->margin_bottom) + offs, l); } } + pango_font_description_set_size (fd, (gint) pango_font_description_get_size (gtk_widget_get_style ((GtkWidget*) self)->font_desc)); + pango_context_set_font_description (ctx, fd); pango_layout_set_width (l, self->priv->margin_left - 1); pango_layout_set_alignment (l, PANGO_ALIGN_RIGHT); + fontsize = (gint) ((pango_units_to_double (pango_font_description_get_size (fd)) * gdk_screen_get_resolution (gdk_screen_get_default ())) / 72); if (self->priv->mouse_y != (-1)) { _tmp7_ = self->priv->mouse_y < (height - self->priv->margin_bottom); } else { @@ -232,7 +265,7 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose } tmp = (_tmp10_ = g_strdup_printf ("%s%.1fdB", _tmp9_, val), _g_free0 (tmp), _tmp10_); pango_layout_set_text (l, tmp, (gint) g_utf8_strlen (tmp, -1)); - gdk_draw_layout (d, gc, self->priv->margin_left - 1, (height - self->priv->margin_bottom) - 6, l); + gdk_draw_layout (d, gc, self->priv->margin_left - 1, (height - self->priv->margin_bottom) - fontsize, l); val = ddb_equalizer_scale (self, (double) 0); _tmp11_ = NULL; if (val > 0) { @@ -243,15 +276,15 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose tmp = (_tmp12_ = g_strdup_printf ("%s%.1fdB", _tmp11_, val), _g_free0 (tmp), _tmp12_); pango_layout_set_text (l, tmp, (gint) g_utf8_strlen (tmp, -1)); gdk_draw_layout (d, gc, self->priv->margin_left - 1, 1, l); - pango_layout_set_text (l, "0dB", 4); - gdk_draw_layout (d, gc, self->priv->margin_left - 1, ((gint) ((1 - self->priv->preamp) * (height - self->priv->margin_bottom))) - 3, l); + pango_layout_set_text (l, "+0dB", 4); + gdk_draw_layout (d, gc, self->priv->margin_left - 1, ((gint) ((1 - self->priv->preamp) * (height - self->priv->margin_bottom))) - (fontsize / 2), l); pango_layout_set_text (l, "preamp", 6); pango_layout_set_alignment (l, PANGO_ALIGN_LEFT); gdk_draw_layout (d, gc, 1, (height - self->priv->margin_bottom) + 2, l); gdk_draw_rectangle (d, gc, FALSE, self->priv->margin_left, 0, (width - self->priv->margin_left) - 1, (height - self->priv->margin_bottom) - 1); gdk_gc_set_line_attributes (gc, 2, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); gdk_gc_set_clip_rectangle (gc, (_tmp14_ = (_tmp13_.x = 0, _tmp13_.y = (gint) (self->priv->preamp * (height - self->priv->margin_bottom)), _tmp13_.width = 11, _tmp13_.height = height, _tmp13_), &_tmp14_)); - gdk_gc_set_rgb_fg_color (gc, &fore_dark_color); + gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); count = ((gint) ((height - self->priv->margin_bottom) / 6)) + 1; { gint j; @@ -272,7 +305,7 @@ static gboolean ddb_equalizer_real_expose_event (GtkWidget* base, GdkEventExpose } } gdk_gc_set_clip_rectangle (gc, (_tmp17_ = (_tmp16_.x = self->priv->margin_left + 1, _tmp16_.y = 1, _tmp16_.width = (width - self->priv->margin_left) - 2, _tmp16_.height = (height - self->priv->margin_bottom) - 2, _tmp16_), &_tmp17_)); - gdk_gc_set_rgb_fg_color (gc, &fore_dark_color); + gdk_gc_set_rgb_fg_color (gc, &fore_bright_color); bar_w = 11; if (step < bar_w) { bar_w = ((gint) step) - 1; @@ -544,11 +577,12 @@ static GObject * ddb_equalizer_constructor (GType type, guint n_construct_proper obj = parent_class->constructor (type, n_construct_properties, construct_properties); self = DDB_EQUALIZER (obj); { - GdkColor _tmp0_; + GdkColor _tmp1_; + GdkColor _tmp0_ = {0}; gtk_widget_add_events ((GtkWidget*) self, (gint) (((GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK) | GDK_LEAVE_NOTIFY_MASK) | GDK_POINTER_MOTION_MASK)); - gtk_widget_modify_bg ((GtkWidget*) self, GTK_STATE_NORMAL, (_tmp0_ = gtk_widget_get_style ((GtkWidget*) self)->fg[GTK_STATE_NORMAL], &_tmp0_)); self->priv->margin_bottom = (gint) (((pango_units_to_double (pango_font_description_get_size (gtk_widget_get_style ((GtkWidget*) self)->font_desc)) * gdk_screen_get_resolution (gdk_screen_get_default ())) / 72) + 4); self->priv->margin_left = self->priv->margin_bottom * 4; + gtk_widget_modify_bg ((GtkWidget*) self, GTK_STATE_NORMAL, (_tmp1_ = (gtkui_get_bar_background_color (&_tmp0_), _tmp0_), &_tmp1_)); } return obj; } diff --git a/plugins/gtkui/ddbequalizer.vala b/plugins/gtkui/ddbequalizer.vala index f7912cfc..9f18279a 100644 --- a/plugins/gtkui/ddbequalizer.vala +++ b/plugins/gtkui/ddbequalizer.vala @@ -1,3 +1,23 @@ +/* + SuperEQ GTK Widget for for DeaDBeeF + Copyright (C) 2010 Viktor Semykin <thesame.ml@gmail.com> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +// sripped down and polished by Alexey Yakovenko <waker@users.sourceforge.net> + 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" @@ -34,11 +54,10 @@ namespace Ddb { | Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.POINTER_MOTION_MASK); - modify_bg (Gtk.StateType.NORMAL, get_style ().fg[Gtk.StateType.NORMAL]); - - margin_bottom = (int)(Pango.units_to_double (get_style ().font_desc.get_size ())* Gdk.Screen.get_default ().get_resolution () / 72 + 4); + 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; + modify_bg (Gtk.StateType.NORMAL, Gtkui.get_bar_background_color ()); } public void @@ -52,7 +71,13 @@ namespace Ddb { expose_event (Gdk.EventExpose event) { Gdk.Color fore_bright_color = Gtkui.get_bar_foreground_color (); - Gdk.Color fore_dark_color = Gtkui.get_bar_foreground_color (); + + Gdk.Color c1 = fore_bright_color; + Gdk.Color c2 = Gtkui.get_bar_background_color (); + Gdk.Color fore_dark_color = c2; + fore_dark_color.red += (int16)((c1.red - c2.red) * 0.5); + 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; @@ -89,18 +114,32 @@ namespace Ddb { //drawing freqs: Pango.Layout l = create_pango_layout (null); var ctx = l.get_context (); - var fd = ctx.get_font_description (); + + 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); for (i = 0; i < bands; i++) { l.set_text (freqs[i], (int)freqs[i].len()); - Gdk.draw_layout (d, gc, (int)((i+1)*step-5)+margin_left, height-margin_bottom+2, l); + 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); } + fd.set_size ((int)(get_style ().font_desc.get_size ())); + ctx.set_font_description (fd); //drawing db's: l.set_width (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 != -1) && (mouse_y < height - margin_bottom)) { double db = scale((double)(mouse_y-1) / (double)(height - margin_bottom - 2)); @@ -113,15 +152,15 @@ namespace Ddb { 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-6, l); + Gdk.draw_layout (d, gc, margin_left-1, height-margin_bottom-fontsize, l); 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 ("0dB", 4); - Gdk.draw_layout (d, gc, margin_left-1, (int)((1-preamp)*(height-margin_bottom))-3, l); + l.set_text ("+0dB", 4); + Gdk.draw_layout (d, gc, margin_left-1, (int)((1-preamp)*(height-margin_bottom))-fontsize/2, l); l.set_text ("preamp", 6); l.set_alignment (Pango.Alignment.LEFT); @@ -133,7 +172,7 @@ namespace Ddb { //draw preamp gc.set_clip_rectangle ({0, (int)(preamp * (height-margin_bottom)), 11, height}); - gc.set_rgb_fg_color (fore_dark_color); + 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 ( @@ -147,7 +186,7 @@ namespace Ddb { gc.set_clip_rectangle ({margin_left+1, 1, width-margin_left-2, height-margin_bottom-2}); //drawing bars: - gc.set_rgb_fg_color (fore_dark_color); + gc.set_rgb_fg_color (fore_bright_color); int bar_w = 11; if (step < bar_w) |