Permalink
Browse files

Better adjust to varying DPI settings (GTK interfaces).

  • Loading branch information...
1 parent 29dc88e commit 6caded2b3ff8842e548693ffde1e7b75782739d6 @jlindgren90 jlindgren90 committed May 30, 2015
@@ -70,7 +70,6 @@ void * AlbumArtPlugin::get_gtk_widget ()
audgui_init ();
GtkWidget * widget = audgui_scaled_image_new (nullptr);
- gtk_widget_set_size_request (widget, 96, 96);
g_signal_connect (widget, "destroy", (GCallback) album_cleanup, nullptr);
@@ -33,9 +33,6 @@
#include <libaudcore/plugin.h>
#include <libaudcore/preferences.h>
-#define D_WIDTH 64
-#define D_HEIGHT 32
-
static void /* GtkWidget */ * bscope_get_color_chooser (void);
static const PreferencesWidget bscope_widgets[] = {
@@ -144,8 +141,6 @@ gboolean BlurScope::expose_event (GtkWidget * widget, GdkEventExpose * event, vo
void * BlurScope::get_gtk_widget ()
{
area = gtk_drawing_area_new ();
- gtk_widget_set_size_request (area, D_WIDTH, D_HEIGHT);
- resize (D_WIDTH, D_HEIGHT);
g_signal_connect (area, "expose-event", (GCallback) expose_event, this);
g_signal_connect (area, "configure-event", (GCallback) configure_event, this);
@@ -112,8 +112,13 @@ void pw_col_init ()
}
String widths = aud_get_str ("gtkui", "column_widths");
+
if (! str_to_int_array (widths, pw_col_widths, PW_COLS))
- memcpy (pw_col_widths, pw_default_widths, sizeof pw_col_widths);
+ {
+ int dpi = audgui_get_dpi ();
+ for (int i = 0; i < PW_COLS; i ++)
+ pw_col_widths[i] = pw_default_widths[i] * dpi / 96;
+ }
}
struct Column {
@@ -295,7 +300,7 @@ void * pw_col_create_chooser ()
}
GtkWidget * hbox = gtk_hbox_new (false, 6);
- gtk_widget_set_size_request (hbox, -1, 160);
+ gtk_widget_set_size_request (hbox, -1, audgui_get_dpi () * 5 / 4);
GtkWidget * scroll = gtk_scrolled_window_new (nullptr, nullptr);
gtk_scrolled_window_set_policy ((GtkScrolledWindow *) scroll,
View
@@ -25,12 +25,10 @@
#include <libaudcore/i18n.h>
#include <libaudcore/runtime.h>
#include <libaudcore/plugins.h>
+#include <libaudgui/libaudgui-gtk.h>
#include "layout.h"
-#define DEFAULT_WIDTH 300
-#define DEFAULT_HEIGHT 200
-
enum {
DOCK_LEFT,
DOCK_RIGHT,
@@ -61,18 +59,20 @@ static GtkWidget * menu = nullptr;
static Item * item_new (const char * name)
{
+ int dpi = audgui_get_dpi ();
+
Item * item = new Item ();
item->name = String (name);
item->plugin = nullptr;
item->widget = item->vbox = item->paned = item->window = nullptr;
item->dock = item->x = item->y = -1;
- item->w = DEFAULT_WIDTH;
- item->h = DEFAULT_HEIGHT;
+ item->w = 3 * dpi;
+ item->h = 2 * dpi;
if (! strcmp (name, _("Search Tool")))
{
item->dock = DOCK_LEFT;
- item->w = 200;
+ item->w = 2 * dpi;
}
items = g_list_append (items, item);
View
@@ -32,6 +32,7 @@
#include <libaudcore/audstrings.h>
#include <libaudcore/hook.h>
#include <libaudgui/libaudgui.h>
+#include <libaudgui/libaudgui-gtk.h>
#include "gtkui.h"
#include "layout.h"
@@ -58,8 +59,6 @@ static const char * const gtkui_defaults[] = {
"player_x", "-1000",
"player_y", "-1000",
- "player_width", "760",
- "player_height", "460",
nullptr
};
@@ -144,11 +143,17 @@ static void save_window_size ()
static void restore_window_size ()
{
+ int dpi = audgui_get_dpi ();
int x = aud_get_int ("gtkui", "player_x");
int y = aud_get_int ("gtkui", "player_y");
int w = aud_get_int ("gtkui", "player_width");
int h = aud_get_int ("gtkui", "player_height");
+ if (w < 1)
+ w = 8 * dpi;
+ if (h < 1)
+ h = 5 * dpi;
+
gtk_window_set_default_size ((GtkWindow *) window, w, h);
if (x > -1000 && y > -1000)
@@ -802,6 +807,7 @@ bool GtkUI::init ()
toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style ((GtkToolbar *) toolbar, GTK_TOOLBAR_ICONS);
+ gtk_toolbar_set_show_arrow ((GtkToolbar *) toolbar, false);
gtk_box_pack_start ((GtkBox *) vbox_outer, toolbar, false, false, 0);
/* search button */
@@ -832,7 +838,7 @@ bool GtkUI::init ()
slider = gtk_hscale_new (nullptr);
gtk_scale_set_draw_value ((GtkScale *) slider, false);
- gtk_widget_set_size_request (slider, 120, -1);
+ gtk_widget_set_size_request (slider, audgui_get_dpi () * 5 / 4, -1);
gtk_widget_set_can_focus (slider, false);
gtk_box_pack_start ((GtkBox *) box1, slider, true, true, 6);
@@ -29,15 +29,25 @@
#include "ui_infoarea.h"
-#define SPACING 8
-#define ICON_SIZE 64
-#define HEIGHT (ICON_SIZE + 2 * SPACING)
-
#define VIS_BANDS 12
-#define VIS_WIDTH (8 * VIS_BANDS - 2)
-#define VIS_CENTER (ICON_SIZE * 5 / 8 + SPACING)
#define VIS_DELAY 2 /* delay before falloff in frames */
-#define VIS_FALLOFF 2 /* falloff in pixels per frame */
+#define VIS_FALLOFF 2 /* falloff in decibels per frame */
+
+int SPACING, ICON_SIZE, HEIGHT, BAND_WIDTH, BAND_SPACING, VIS_WIDTH, VIS_SCALE, VIS_CENTER;
+
+static void compute_sizes ()
+{
+ int dpi = audgui_get_dpi ();
+
+ SPACING = aud::rescale (dpi, 12, 1);
+ ICON_SIZE = aud::rescale (dpi, 3, 2);
+ HEIGHT = ICON_SIZE + 2 * SPACING;
+ BAND_WIDTH = aud::rescale (dpi, 16, 1);
+ BAND_SPACING = aud::rescale (dpi, 48, 1);
+ VIS_WIDTH = VIS_BANDS * (BAND_WIDTH + BAND_SPACING) - BAND_SPACING;
+ VIS_SCALE = aud::rescale (ICON_SIZE, 8, 5);
+ VIS_CENTER = VIS_SCALE + SPACING;
+}
typedef struct {
GtkWidget * box, * main;
@@ -59,7 +69,7 @@ class InfoAreaVis : public Visualizer
Visualizer (Freq) {}
GtkWidget * widget = nullptr;
- char bars[VIS_BANDS] {};
+ float bars[VIS_BANDS] {};
char delay[VIS_BANDS] {};
void clear ();
@@ -97,8 +107,7 @@ void InfoAreaVis::render_freq (const float * freq)
}
/* 40 dB range */
- int x = 40 + 20 * log10f (n);
- x = aud::clamp (x, 0, 40);
+ float x = 40 + 20 * log10f (n);
bars[i] -= aud::max (0, VIS_FALLOFF - delay[i]);
@@ -259,19 +268,19 @@ static int expose_vis_cb (GtkWidget * widget, GdkEventExpose * event)
for (int i = 0; i < VIS_BANDS; i++)
{
- int x = SPACING + 8 * i;
- int t = VIS_CENTER - vis.bars[i];
- int m = aud::min (VIS_CENTER + vis.bars[i], HEIGHT);
+ int x = SPACING + i * (BAND_WIDTH + BAND_SPACING);
+ int v = aud::clamp ((int) (vis.bars[i] * VIS_SCALE / 40), 0, VIS_SCALE);
+ int m = aud::min (VIS_CENTER + v, HEIGHT);
float r, g, b;
get_color (widget, i, & r, & g, & b);
cairo_set_source_rgb (cr, r, g, b);
- cairo_rectangle (cr, x, t, 6, VIS_CENTER - t);
+ cairo_rectangle (cr, x, VIS_CENTER - v, BAND_WIDTH, v);
cairo_fill (cr);
cairo_set_source_rgb (cr, r * 0.3, g * 0.3, b * 0.3);
- cairo_rectangle (cr, x, VIS_CENTER, 6, m - VIS_CENTER);
+ cairo_rectangle (cr, x, VIS_CENTER, BAND_WIDTH, m - VIS_CENTER);
cairo_fill (cr);
}
@@ -285,13 +294,17 @@ static void draw_album_art (cairo_t * cr)
if (area->pb)
{
- gdk_cairo_set_source_pixbuf (cr, area->pb, SPACING, SPACING);
+ int left = SPACING + (ICON_SIZE - gdk_pixbuf_get_width (area->pb)) / 2;
+ int top = SPACING + (ICON_SIZE - gdk_pixbuf_get_height (area->pb)) / 2;
+ gdk_cairo_set_source_pixbuf (cr, area->pb, left, top);
cairo_paint_with_alpha (cr, area->alpha);
}
if (area->last_pb)
{
- gdk_cairo_set_source_pixbuf (cr, area->last_pb, SPACING, SPACING);
+ int left = SPACING + (ICON_SIZE - gdk_pixbuf_get_width (area->last_pb)) / 2;
+ int top = SPACING + (ICON_SIZE - gdk_pixbuf_get_height (area->last_pb)) / 2;
+ gdk_cairo_set_source_pixbuf (cr, area->last_pb, left, top);
cairo_paint_with_alpha (cr, area->last_alpha);
}
}
@@ -303,7 +316,7 @@ static void draw_title (cairo_t * cr)
GtkAllocation alloc;
gtk_widget_get_allocation (area->main, & alloc);
- int x = ICON_SIZE + SPACING * 2;
+ int x = HEIGHT;
int width = alloc.width - x;
if (area->title)
@@ -516,12 +529,14 @@ static void destroy_cb (GtkWidget * widget)
GtkWidget * ui_infoarea_new ()
{
g_return_val_if_fail (! area, nullptr);
- area = new UIInfoArea ();
+ compute_sizes ();
+
+ area = new UIInfoArea ();
area->box = gtk_hbox_new (false, 0);
area->main = gtk_drawing_area_new ();
- gtk_widget_set_size_request (area->main, ICON_SIZE + 2 * SPACING, HEIGHT);
+ gtk_widget_set_size_request (area->main, HEIGHT, HEIGHT);
gtk_box_pack_start ((GtkBox *) area->box, area->main, true, true, 0);
g_signal_connect (area->main, "expose-event", (GCallback) expose_cb, nullptr);
@@ -30,6 +30,7 @@
#include <libaudcore/audstrings.h>
#include <libaudcore/preferences.h>
#include <libaudcore/runtime.h>
+#include <libaudgui/libaudgui-gtk.h>
#include "plugin.h"
@@ -469,8 +470,10 @@ static void configure_selected ()
static void * make_config_widget ()
{
+ int dpi = audgui_get_dpi ();
+
GtkWidget * vbox = gtk_vbox_new (FALSE, 6);
- gtk_widget_set_size_request (vbox, 480, 360);
+ gtk_widget_set_size_request (vbox, 5 * dpi, 4 * dpi);
GtkWidget * hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start ((GtkBox *) vbox, hbox, 0, 0, 0);
View
@@ -55,7 +55,7 @@ static gboolean get_album_art (void)
if (! last_pixbuf)
return FALSE;
- audgui_pixbuf_scale_within (& last_pixbuf, 96);
+ audgui_pixbuf_scale_within (& last_pixbuf, audgui_get_dpi ());
return TRUE;
}
@@ -27,6 +27,7 @@
#include <libaudcore/plugin.h>
#include <libaudcore/multihash.h>
#include <libaudcore/runtime.h>
+#include <libaudgui/libaudgui-gtk.h>
#include <libaudgui/list.h>
#include <libaudgui/menu.h>
@@ -687,7 +688,8 @@ void * SearchTool::get_gtk_widget ()
help_label = gtk_label_new (_("To import your music library into "
"Audacious, choose a folder and then click the \"refresh\" icon."));
- gtk_widget_set_size_request (help_label, 194, -1);
+ int label_width = aud::rescale (audgui_get_dpi (), 4, 7);
+ gtk_widget_set_size_request (help_label, label_width, -1);
gtk_label_set_line_wrap ((GtkLabel *) help_label, TRUE);
g_signal_connect (help_label, "destroy", (GCallback) gtk_widget_destroyed, & help_label);
gtk_widget_set_no_show_all (help_label, TRUE);
@@ -32,6 +32,7 @@
#include <libaudcore/plugins.h>
#include <libaudcore/hook.h>
#include <libaudcore/runtime.h>
+#include <libaudgui/libaudgui-gtk.h>
static GList * windows;
@@ -76,7 +77,10 @@ static void add_dock_plugin (PluginHandle * plugin, void * unused)
gtk_window_move ((GtkWindow *) window, pos[0], pos[1]);
}
else
- gtk_window_set_default_size ((GtkWindow *) window, 300, 200);
+ {
+ int dpi = audgui_get_dpi ();
+ gtk_window_set_default_size ((GtkWindow *) window, 3 * dpi, 2 * dpi);
+ }
if (aud_ui_is_shown ())
gtk_widget_show_all (window);
View
@@ -28,6 +28,7 @@
#include <libaudcore/plugin.h>
#include <libaudcore/hook.h>
#include <libaudgui/libaudgui.h>
+#include <libaudgui/libaudgui-gtk.h>
#include "menus.h"
#include "plugin.h"
@@ -115,6 +116,11 @@ static gboolean update_cb (void *)
static void skins_init_main (void)
{
+ if (aud_get_bool ("skins", "double_size"))
+ config.scale = aud::rescale (audgui_get_dpi (), 48, 1);
+ else
+ config.scale = aud::rescale (audgui_get_dpi (), 96, 1);
+
init_skins (aud_get_str ("skins", "skin"));
view_apply_on_top ();
@@ -26,6 +26,7 @@
#include <libaudcore/runtime.h>
#include <libaudcore/preferences.h>
#include <libaudcore/audstrings.h>
+#include <libaudgui/libaudgui-gtk.h>
#include "dnd.h"
#include "skins_cfg.h"
@@ -131,8 +132,6 @@ void skins_cfg_load (void)
for (auto & nument : skins_numents)
* nument.ptr = aud_get_int ("skins", nument.name);
-
- config.scale = aud_get_bool ("skins", "double_size") ? 2 : 1;
}
void skins_cfg_save (void)
@@ -324,7 +323,7 @@ static void * create_skin_view (void)
gtk_scrolled_window_set_policy ((GtkScrolledWindow *) scrolled,
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type ((GtkScrolledWindow *) scrolled, GTK_SHADOW_IN);
- gtk_widget_set_size_request (scrolled, -1, 160);
+ gtk_widget_set_size_request (scrolled, -1, audgui_get_dpi () * 3 / 2);
skin_view = gtk_tree_view_new ();
skin_view_realize ((GtkTreeView *) skin_view);
Oops, something went wrong.

0 comments on commit 6caded2

Please sign in to comment.