[goffice] GORotationSel: further css styling.



commit a7ed805154563d9704affa471ac296ad6d7793c2
Author: Morten Welinder <terra gnome org>
Date:   Mon Dec 18 12:29:24 2017 -0500

    GORotationSel: further css styling.

 goffice/gtk/go-rotation-sel.c |   84 +++++++++++++++++++++++++----------------
 goffice/gtk/goffice.css       |    8 ++++
 2 files changed, 59 insertions(+), 33 deletions(-)
---
diff --git a/goffice/gtk/go-rotation-sel.c b/goffice/gtk/go-rotation-sel.c
index d2286db..69c3f76 100644
--- a/goffice/gtk/go-rotation-sel.c
+++ b/goffice/gtk/go-rotation-sel.c
@@ -38,9 +38,10 @@ struct _GORotationSel {
        gboolean full;
 
        // Styling
-       GOColor          tick_color[2];         // [selected]
-       GOColor          tick_outline_color[2]; // [selected]
-       double           tick_outline_width[2]; // [selected]
+       GOColor          tick_color[2][2];         // [selected][major]
+       GOColor          tick_outline_color[2][2]; // [selected][major]
+       double           tick_outline_width[2][2]; // [selected][major]
+       double           tick_size[2][2];          // [selected][major]
        GOColor          line_color;
        double           line_width;
 };
@@ -61,34 +62,47 @@ static GObjectClass *grs_parent_class;
 static void
 grs_reload_style (GORotationSel *grs)
 {
+       int i;
 #if GTK_CHECK_VERSION(3,20,0)
-       int qSel;
        GtkStyleContext *ctxt_canvas =
                gtk_widget_get_style_context (GTK_WIDGET (grs->rotate_canvas));
-       static const char * const css_sniplet[2] = {
-               "ticks",
-               "ticks:selected"
-       };
+#endif
 
-       for (qSel = FALSE; qSel <= TRUE; qSel++) {
+       for (i = 0; i < 4; i++) {
+               gboolean qSelected = (i & 1);
+               gboolean qMajor = ((i >> 1) & 1);
+#if GTK_CHECK_VERSION(3,20,0)
                GtkStyleContext *ctxt = go_style_context_from_selector
-                       (ctxt_canvas, css_sniplet[qSel]);
+                       (ctxt_canvas, qSelected ? "ticks:selected" : "ticks");
                GdkRGBA *c, *oc;
-               int ow;
+               int ow, mw;
 
+               gtk_style_context_add_class (ctxt,
+                                            qMajor ? "major" : "minor");
                gtk_style_context_get (ctxt,
                                       gtk_style_context_get_state (ctxt),
                                       "color", &c,
                                       "outline-color", &oc,
                                       "outline-width", &ow,
+                                      "min-width", &mw,
                                       NULL);
-               grs->tick_color[qSel] = GO_COLOR_FROM_GDK_RGBA (*c);
-               grs->tick_outline_color[qSel] = GO_COLOR_FROM_GDK_RGBA (*oc);
-               grs->tick_outline_width[qSel] = ow;
+               grs->tick_color[qSelected][qMajor] = GO_COLOR_FROM_GDK_RGBA (*c);
+               grs->tick_outline_color[qSelected][qMajor] = GO_COLOR_FROM_GDK_RGBA (*oc);
+               grs->tick_outline_width[qSelected][qMajor] = ow;
+               // We highjack min-width to mean 2*radius
+               grs->tick_size[qSelected][qMajor] = mw / 2.0;
                gdk_rgba_free (c);
                gdk_rgba_free (oc);
                g_object_unref (ctxt);
+#else
+               grs->tick_color[qSelected][qMajor] = GO_COLOR_BLACK;
+               grs->tick_outline_color[qSelected][qMajor] = GO_COLOR_BLACK;
+               grs->tick_outline_width[qSelected][qMajor] = 1;
+               grs->tick_size[qSelected][qMajor] = (qMajor ? 4 : 3);
+#endif
        }
+
+#if GTK_CHECK_VERSION(3,20,0)
        {
                GtkStyleContext *ctxt = go_style_context_from_selector
                        (ctxt_canvas, "line");
@@ -105,12 +119,6 @@ grs_reload_style (GORotationSel *grs)
                g_object_unref (ctxt);
        }
 #else
-       grs->tick_color[FALSE] = GO_COLOR_BLACK;
-       grs->tick_color[TRUE] = GO_COLOR_GREEN;
-       grs->tick_outline_color[FALSE] = GO_COLOR_BLACK;
-       grs->tick_outline_color[TRUE] = GO_COLOR_BLACK;
-       grs->tick_outline_width[FALSE] = 1;
-       grs->tick_outline_width[TRUE] = 1;
        grs->line_color = GO_COLOR_BLACK;
        grs->line_width = 2;
 #endif
@@ -130,14 +138,17 @@ cb_rotate_changed (GORotationSel *grs)
 
        for (i = 0 ; i <= maxi ; i++) {
                int mark_angle = (i - 6) * 15;
+               gboolean qSelected = (angle == mark_angle);
+               gboolean qMajor = (i % 3 == 0);
+               GocItem *item = grs->rotate_marks[i];
 
-               if (grs->rotate_marks[i] != NULL) {
-                       GOStyledObject *so = GO_STYLED_OBJECT (grs->rotate_marks[i]);
+               if (item != NULL) {
+                       GOStyledObject *so = GO_STYLED_OBJECT (item);
                        GOStyle *style = go_styled_object_get_style (so);
-                       gboolean qSelected = (angle == mark_angle);
-                       GOColor color = grs->tick_color[qSelected];
-                       GOColor outline_color = grs->tick_outline_color[qSelected];
-                       int outline_width = grs->tick_outline_width[qSelected];
+                       GOColor color = grs->tick_color[qSelected][qMajor];
+                       GOColor outline_color = grs->tick_outline_color[qSelected][qMajor];
+                       int outline_width = grs->tick_outline_width[qSelected][qMajor];
+                       double radius = grs->tick_size[qSelected][qMajor];
                        if (style->fill.pattern.back != color ||
                            style->line.color != outline_color ||
                            style->line.width != outline_width) {
@@ -146,6 +157,10 @@ cb_rotate_changed (GORotationSel *grs)
                                style->fill.pattern.back = color;
                                go_styled_object_style_changed (so);
                        }
+                       if (GOC_CIRCLE (item)->radius != radius) {
+                               g_object_set (item, "radius", radius, NULL);
+                               goc_item_invalidate (item);
+                       }
                }
        }
 
@@ -176,22 +191,19 @@ cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
        int i, maxint = grs->full? 23: 12;
        GOStyle *go_style;
        double x0 = grs->full? 100.: 15.;
+       double mov = 0;
 
        for (i = 0 ; i <= maxint; i++) {
                int mark_angle = (i - 6) * 15;
                double x = x0 + go_cospi (mark_angle / 180.0) * 80.;
                double y = 100 - go_sinpi (mark_angle / 180.0) * 80.;
                gboolean qMajor = (i % 3 == 0);
-               double size = qMajor ? 4.0 : 3.0;
+               double size = grs->tick_size[FALSE][qMajor];
                GocItem *item = goc_item_new (group,
                        GOC_TYPE_CIRCLE,
                        "x", x, "y", y,
                        "radius", size,
                        NULL);
-               go_style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
-               go_style->line.width = grs->tick_outline_width[FALSE];
-               go_style->line.color = grs->tick_outline_color[FALSE];
-               go_style->fill.pattern.back = grs->tick_color[FALSE];
                grs->rotate_marks[i] = item;
        }
        grs->line = goc_item_new (group, GOC_TYPE_LINE, NULL);
@@ -223,8 +235,14 @@ cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
                grs->rot_width0  = w - x;
        }
 
-       grs->rot_width1 = 73 - MAX (grs->tick_outline_width[FALSE],
-                                   grs->tick_outline_width[TRUE]);
+       for (i = 0; i < 4; i++) {
+               gboolean qSelected = (i & 1);
+               gboolean qMajor = ((i >> 1) & 1);
+               double ov = grs->tick_outline_width[qSelected][qMajor];
+               if (ov > mov)
+                       mov = ov;
+       }
+       grs->rot_width1 = 73 - mov;
 
        cb_rotate_changed (grs);
 }
diff --git a/goffice/gtk/goffice.css b/goffice/gtk/goffice.css
index 022af45..d719ec5 100644
--- a/goffice/gtk/goffice.css
+++ b/goffice/gtk/goffice.css
@@ -11,6 +11,14 @@ rotationselector ticks {
   outline-color: black;
 }
 
+rotationselector ticks.minor {
+    min-width: 6px;
+}
+
+rotationselector ticks.major {
+    min-width: 8px;
+}
+
 rotationselector ticks:selected {
   color: #00ff00;
   outline-width: 1px;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]