diff --git a/NEWS b/NEWS index b8812f7da..5086bd4aa 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,9 @@ Development: 1/22/2013: - Breadcrumbs: Stylable by themes, see src/nemo-styles-fallback.css for default style information. - Border radius, color, background color, and text color can be customized through that. \ No newline at end of file + Border radius, color, background color, and text color can be customized through that. + +- Sidebar Disk Indicators: Stylable by themes, again, see src/nemo-styles-fallback.css for default + style information - you can customize the two colors (fore- and background), the + thickness of the bar, the corner radius, the maximum length of the bar, and an amount + of extra padding from the bottom of the cell. \ No newline at end of file diff --git a/libnemo-private/nemo-cell-renderer-disk.c b/libnemo-private/nemo-cell-renderer-disk.c index 7e09f6557..cd7f786f7 100644 --- a/libnemo-private/nemo-cell-renderer-disk.c +++ b/libnemo-private/nemo-cell-renderer-disk.c @@ -18,6 +18,7 @@ */ #include "nemo-cell-renderer-disk.h" +#include G_DEFINE_TYPE (NemoCellRendererDisk, nemo_cell_renderer_disk, GTK_TYPE_CELL_RENDERER_TEXT); @@ -95,7 +96,7 @@ nemo_cell_renderer_disk_class_init (NemoCellRendererDiskClass *klass) GtkCellRenderer * nemo_cell_renderer_disk_new (void) { - return g_object_new (NEMO_TYPE_CELL_RENDERER_DISK, NULL); + return g_object_new (NEMO_TYPE_CELL_RENDERER_DISK, NULL); } static void @@ -148,10 +149,38 @@ nemo_cell_renderer_disk_set_property (GObject *object, } } -#define BG_BAR_HEIGHT 2 -#define FG_BAR_HEIGHT 2 -#define EXTRA_BOTTOM_GAP 1 -#define MAX_WIDTH 70 +static void +convert_color (GdkColor *style_color, GdkRGBA *color) +{ + color->red = style_color->red / 65535.0; + color->green = style_color->green / 65535.0; + color->blue = style_color->blue / 65535.0; + color->alpha = 1; +} + +#define _270_DEG 270.0 * (M_PI/180.0) +#define _180_DEG 180.0 * (M_PI/180.0) +#define _90_DEG 90.0 * (M_PI/180.0) +#define _0_DEG 0.0 + +static void +cairo_rectangle_with_radius_corners (cairo_t *cr, + gint x, + gint y, + gint w, + gint h, + gint rad) +{ + cairo_move_to (cr, x+rad, y); + cairo_line_to (cr, x+w-rad, y); + cairo_arc (cr, x+w-rad, y+rad, rad, _270_DEG, _0_DEG); + cairo_line_to (cr, x+w, y+h-rad); + cairo_arc (cr, x+w-rad, y+h-rad, rad, _0_DEG, _90_DEG); + cairo_line_to (cr, x+rad, y+h); + cairo_arc (cr, x+rad, y+h-rad, rad, _90_DEG, _180_DEG); + cairo_line_to (cr, x, y-rad); + cairo_arc (cr, x+rad, y+rad, rad, _180_DEG, _270_DEG); +} static void nemo_cell_renderer_disk_render (GtkCellRenderer *cell, @@ -162,35 +191,69 @@ nemo_cell_renderer_disk_render (GtkCellRenderer *cell, GtkCellRendererState flags) { NemoCellRendererDisk *cellprogress = NEMO_CELL_RENDERER_DISK (cell); - GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell); - GtkCellRendererTextPrivate *priv = celltext->priv; - GtkStateType state; gint x, y, w; gint xpad, ypad; gint full; gboolean show = cellprogress->show_disk_full_percent; GtkStyleContext *context; - if (show) { - context = gtk_widget_get_style_context (widget); + GdkColor *gdk_bg_color, *gdk_fg_color; + GdkRGBA *bg_color, *fg_color; + gint bar_width, bar_radius, bottom_padding, max_length; + + gtk_style_context_get_style (context, + "disk-full-bg-color", &gdk_bg_color, + "disk-full-fg-color", &gdk_fg_color, + "disk-full-bar-width", &bar_width, + "disk-full-bar-radius", &bar_radius, + "disk-full-bottom-padding", &bottom_padding, + "disk-full-max-length", &max_length, + NULL); + + convert_color (gdk_bg_color, bg_color); + convert_color (gdk_fg_color, fg_color); + + gdk_color_free (gdk_bg_color); + gdk_color_free (gdk_fg_color); gtk_cell_renderer_get_padding (cell, &xpad, &ypad); x = cell_area->x + xpad; - y = cell_area->y + cell_area->height - BG_BAR_HEIGHT - EXTRA_BOTTOM_GAP; + y = cell_area->y + cell_area->height - bar_width - bottom_padding; w = cell_area->width - xpad * 2; - w = w < MAX_WIDTH ? w : MAX_WIDTH; + w = w < max_length ? w : max_length; full = (int) (((float) cellprogress->disk_full_percent / 100.0) * (float) w); gtk_style_context_save (context); - gtk_style_context_add_class (context, "nemo-disk-renderer-bg"); - gtk_render_frame (context, cr, x, y, w, BG_BAR_HEIGHT); - gtk_style_context_restore (context); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "nemo-disk-renderer-fg"); - gtk_render_frame (context, cr, x, y, full, FG_BAR_HEIGHT); + + cairo_save (cr); + + cairo_set_source_rgba (cr, + bg_color->red, + bg_color->green, + bg_color->blue, + bg_color->alpha); + + cairo_rectangle_with_radius_corners (cr, x, y, w, bar_width, bar_radius); + cairo_fill (cr); + + cairo_restore (cr); + cairo_save (cr); + + cairo_set_source_rgba (cr, + fg_color->red, + fg_color->green, + fg_color->blue, + fg_color->alpha); + + cairo_rectangle_with_radius_corners (cr, x, y, full, bar_width, bar_radius); + cairo_fill (cr); + + cairo_restore (cr); + + gdk_rgba_free (bg_color); + gdk_rgba_free (fg_color); gtk_style_context_restore (context); } diff --git a/src/nemo-places-sidebar.c b/src/nemo-places-sidebar.c index 51ffbbf30..1e861dfe3 100644 --- a/src/nemo-places-sidebar.c +++ b/src/nemo-places-sidebar.c @@ -58,15 +58,11 @@ #define DEBUG_FLAG NEMO_DEBUG_PLACES #include -#define ICON_CELL_XPAD 6 #define EXPANDER_COLUMN_WIDTH 14 #define EXPANDER_PAD_COLUMN_WIDTH 4 #define EJECT_COLUMN_WIDTH 22 #define DRAG_EXPAND_CATEGORY_DELAY 500 -#define GB 1048576.0 -#define MB 1024.0 - typedef struct { GtkScrolledWindow parent; GtkTreeView *tree_view; @@ -3567,6 +3563,54 @@ places_sidebar_sort_func (GtkTreeModel *model, return retval; } +static void +add_disk_indicator_style_props (GtkTreeView *tree_view) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (tree_view)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("disk-full-bg-color", + "Unselected disk indicator background color", + "Unselected disk indicator background color", + GDK_TYPE_COLOR, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("disk-full-fg-color", + "Unselected disk indicator foreground color", + "Unselected disk indicator foreground color", + GDK_TYPE_COLOR, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("disk-full-bar-width", + "Disk indicator bar width", + "Disk indicator bar width", + 0, G_MAXINT, 1, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("disk-full-bar-radius", + "Disk indicator bar radius (usually half the width)", + "Disk indicator bar radius (usually half the width)", + 0, G_MAXINT, 1, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("disk-full-bottom-padding", + "Extra padding under the disk indicator", + "Extra padding under the disk indicator", + 0, G_MAXINT, 1, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_int ("disk-full-max-length", + "Maximum length of the disk indicator", + "Maximum length of the disk indicator", + 0, G_MAXINT, 1, + G_PARAM_READABLE)); +} + static void nemo_places_sidebar_init (NemoPlacesSidebar *sidebar) { @@ -3596,6 +3640,9 @@ nemo_places_sidebar_init (NemoPlacesSidebar *sidebar) /* tree view */ tree_view = GTK_TREE_VIEW (gtk_tree_view_new ()); + + add_disk_indicator_style_props (tree_view); + gtk_tree_view_set_headers_visible (tree_view, FALSE); col = GTK_TREE_VIEW_COLUMN (gtk_tree_view_column_new ()); @@ -3860,10 +3907,13 @@ nemo_places_sidebar_dispose (GObject *object) static void nemo_places_sidebar_class_init (NemoPlacesSidebarClass *class) { + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); G_OBJECT_CLASS (class)->dispose = nemo_places_sidebar_dispose; - GTK_WIDGET_CLASS (class)->style_set = nemo_places_sidebar_style_set; - GTK_WIDGET_CLASS (class)->focus = nemo_places_sidebar_focus; + widget_class->style_set = nemo_places_sidebar_style_set; + widget_class->focus = nemo_places_sidebar_focus; + + } static void diff --git a/src/nemo-style-application.css b/src/nemo-style-application.css index 4e4439455..24071751e 100644 --- a/src/nemo-style-application.css +++ b/src/nemo-style-application.css @@ -6,33 +6,3 @@ .nemo-inactive-pane .view { background-color: shade(@theme_base_color, 0.9); } - -/* for nemo-cell-renderer-disk.c */ - -.nemo-disk-renderer-bg { - border-radius: 1px; - border-style: solid; - border-width: 1px; - border-color: shade(@theme_bg_color, .65); -} - -.nemo-disk-renderer-bg row:selected { - border-radius: 1px; - border-style: solid; - border-width: 1px; - border-color: shade(@theme_bg_color, 2.0); -} - -.nemo-disk-renderer-fg { - border-radius: 1px; - border-style: solid; - border-width: 1px; - border-color: shade(@theme_selected_bg_color, 1.0); -} - -.nemo-disk-renderer-fg row:selected { - border-radius: 1px; - border-style: solid; - border-width: 1px; - border-color: shade(@theme_fg_color, 2.0); -} diff --git a/src/nemo-style-fallback.css b/src/nemo-style-fallback.css index 446e6ec52..9dbe30b07 100644 --- a/src/nemo-style-fallback.css +++ b/src/nemo-style-fallback.css @@ -1,3 +1,4 @@ +/* for breadcrumbs path bar */ .nemo-pathbar-button, NemoPathbarButton { @@ -34,3 +35,26 @@ NemoPathbarButton:active:hover { color-stop (1, shade(alpha(@selected_bg_color, 0.8), 1.25))); border-color: #808080; } + + +/* For Places Sidebar diskfull indicators */ + +GtkTreeView { + -GtkTreeView-disk-full-bg-color: shade(@bg_color, .65); + -GtkTreeView-disk-full-fg-color: shade(@selected_bg_color, 1.0); + -GtkTreeView-disk-full-bar-width: 2px; + -GtkTreeView-disk-full-bar-radius: 1px; + -GtkTreeView-disk-full-bottom-padding: 1px; + -GtkTreeView-disk-full-max-length: 70px; +} + +GtkTreeView:selected { + -GtkTreeView-disk-full-bg-color: shade(@bg_color, 2.0); + -GtkTreeView-disk-full-fg-color: shade(@fg_color, 2.0); +} + +GtkTreeView:hover { +} + +GtkTreeView:selected:hover { +} \ No newline at end of file