[chronojump] labels on top (contacts/encoder) contrast with background



commit af9580c127c7b6d2f50055a810992145dbf0a432
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Mar 27 13:48:42 2020 +0100

    labels on top (contacts/encoder) contrast with background

 glade/app1.glade                  | 35 ++++++++++++++++++++---------------
 src/gui/app1/chronojump.cs        | 10 ++++++++++
 src/gui/app1/chronojumpPersons.cs |  8 ++++++++
 src/gui/app1/menu.cs              |  1 +
 src/utilGtk.cs                    | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index cda83610..23295d0d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -6721,7 +6721,7 @@ EncoderInertialCapture</property>
                                                       </packing>
                                                     </child>
                                                     <child>
-                                                      <widget class="GtkTable" id="table13">
+                                                      <widget class="GtkTable" id="table_rest_times">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
                                                         <property name="n_rows">2</property>
@@ -6864,7 +6864,6 @@ EncoderInertialCapture</property>
                                                   <packing>
                                                     <property name="expand">True</property>
                                                     <property name="fill">False</property>
-                                                    <property name="padding">30</property>
                                                     <property name="position">2</property>
                                                   </packing>
                                                 </child>
@@ -24879,6 +24878,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -25685,7 +25687,7 @@ Concentric</property>
                                                       </packing>
                                                     </child>
                                                     <child>
-                                                      <widget class="GtkTable" id="table14">
+                                                      <widget class="GtkTable" id="table_rest_times_encoder">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
                                                         <property name="n_rows">2</property>
@@ -27200,18 +27202,6 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -27248,6 +27238,18 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -34759,6 +34761,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index e296cfc0..340c72e1 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -723,6 +723,10 @@ public partial class ChronoJumpWindow
                //ensure chronopicRegisterWindow is shown after (on top of) app1
                app1Shown = true;
 
+               //done after app1.Show in order to be able to gather the colors
+               if(configChronojump.PersonWinHide)
+                       doPersonLabelsContrast();
+
                if(splashWin != null) {
                        LogB.Information("Destroying splashWin");
                        splashWin.Destroy();
@@ -3111,8 +3115,14 @@ public partial class ChronoJumpWindow
                if(pen_black_force_ai != null)
                        pen_black_force_ai.SetLineAttributes (preferences.forceSensorGraphsLineWidth, 
Gdk.LineStyle.Solid, Gdk.CapStyle.Round, Gdk.JoinStyle.Round);
 
+               //TODO: only if personWinHide changed
                initialize_menu_or_menu_tiny();
 
+               //repaint labels that are on the background
+               //TODO: only if color changed or personWinHide
+               if(configChronojump.PersonWinHide)
+                       doPersonLabelsContrast();
+
                // update force_capture_drawingarea
                if(current_menuitem_mode == Constants.Menuitem_modes.FORCESENSOR && 
radiobutton_force_sensor_analyze_manual.Active)
                        forceSensorDoGraphAI();
diff --git a/src/gui/app1/chronojumpPersons.cs b/src/gui/app1/chronojumpPersons.cs
index 7d226edf..b133b68a 100644
--- a/src/gui/app1/chronojumpPersons.cs
+++ b/src/gui/app1/chronojumpPersons.cs
@@ -24,6 +24,7 @@ using System;
 using Gtk;
 using Gdk;
 using Glade;
+using System.Collections.Generic; //List
 
 public partial class ChronoJumpWindow
 {
@@ -72,4 +73,11 @@ public partial class ChronoJumpWindow
                }
        }
 
+       //used on this free labels that have zto contrast with background
+       private void doPersonLabelsContrast()
+       {
+               UtilGtk.HboxDoContrastLabels (viewport_hpaned_contacts_main, hbox_top_person);
+               UtilGtk.HboxDoContrastLabels (viewport_hpaned_contacts_main, hbox_top_person_encoder);
+       }
+
 }
diff --git a/src/gui/app1/menu.cs b/src/gui/app1/menu.cs
index 8995159a..7dea8c8c 100644
--- a/src/gui/app1/menu.cs
+++ b/src/gui/app1/menu.cs
@@ -182,6 +182,7 @@ public partial class ChronoJumpWindow
        {
                //Gdk.Color color = UtilGtk.YELLOW;
                //Gdk.Color color = UtilGtk.BLUE_CHRONOJUMP;
+               //Gdk.Color color = //#FFE891 //this is nice
 
                Gdk.Color color = UtilGtk.ColorParse(preferences.colorBackgroundString);
 
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 8fd4a0e9..f8c00bbe 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -494,6 +494,12 @@ public class UtilGtk
        
        public static Gdk.Color SELECTED = GetBackgroundColorSelected();
 
+       public static bool ColorIsDark(Gdk.Color color)
+       {
+               //LogB.Information(string.Format("color red: {0}, green: {1}, blue: {2}", color.Red, 
color.Green, color.Blue));
+               //3 components come in ushort (0-65535)
+               return (color.Red + color.Green + color.Blue < 3 * 65535 / 2.0);
+       }
 
        public static Gdk.Color GetBackgroundColorSelected() {
                Gtk.Style regularLabel = Gtk.Rc.GetStyle (new Gtk.Label());
@@ -595,7 +601,36 @@ public class UtilGtk
                e.ModifyBg(StateType.Active, color);
                e.ModifyBg(StateType.Prelight, color);
        }
+
+
+       //TODO: instead of checking for hbox or table, check if it is a container
+       public static void HboxDoContrastLabels (Gtk.Viewport v, Gtk.Box box)
+       {
+               foreach(Gtk.Widget w in box.Children)
+               {
+                       if(w.GetType() == typeof(Gtk.Label))
+                               LabelDoContrastColor (v, (Gtk.Label) w);
+                       else if(w.GetType() == typeof(Gtk.Table))
+                               TableDoContrastLabels (v, (Gtk.Table) w);
+               }
+       }
+
+       public static void TableDoContrastLabels (Gtk.Viewport v, Gtk.Table table)
+       {
+               foreach(Gtk.Widget w in table.Children)
+                       if(w.GetType() == typeof(Gtk.Label))
+                               LabelDoContrastColor (v, (Gtk.Label) w);
+       }
+
+       public static void LabelDoContrastColor (Gtk.Viewport v, Gtk.Label l)
+       {
+               if(ColorIsDark(v.Style.Background(StateType.Normal)))
+                       l.ModifyFg(StateType.Normal, YELLOW_LIGHT);
+               else
+                       l.ModifyFg(StateType.Normal, BLACK);
+       }
        
+
        /*
         *
         * PRETTY THINGS


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