Skip to content

Commit

Permalink
linux ui: Move text colors to more accessible SparkleUI class
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Jun 25, 2015
1 parent 07c821e commit e85ac9b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
14 changes: 7 additions & 7 deletions SparkleShare/Linux/SparkleSetup.cs
Expand Up @@ -160,7 +160,7 @@ public void ShowPage (PageType type, string [] warnings)
foreach (SparklePlugin plugin in Controller.Plugins) {
store.AppendValues ("", new Gdk.Pixbuf (plugin.ImagePath),
"<span size=\"small\"><b>" + plugin.Name + "</b>\n" +
"<span fgcolor=\"" + SecondaryTextColor + "\">" + plugin.Description + "</span>" +
"<span fgcolor=\"" + Program.UI.SecondaryTextColor + "\">" + plugin.Description + "</span>" +
"</span>", plugin);
}

Expand All @@ -183,14 +183,14 @@ public void ShowPage (PageType type, string [] warnings)
Xalign = 0,
UseMarkup = true,
Markup = "<span size=\"small\" fgcolor=\"" +
SecondaryTextColor + "\">" + Controller.SelectedPlugin.AddressExample + "</span>"
Program.UI.SecondaryTextColor + "\">" + Controller.SelectedPlugin.AddressExample + "</span>"
};

Label path_example = new Label () {
Xalign = 0,
UseMarkup = true,
Markup = "<span size=\"small\" fgcolor=\"" +
SecondaryTextColor + "\">" + Controller.SelectedPlugin.PathExample + "</span>"
Program.UI.SecondaryTextColor + "\">" + Controller.SelectedPlugin.PathExample + "</span>"
};


Expand Down Expand Up @@ -280,7 +280,7 @@ public void ShowPage (PageType type, string [] warnings)
address_entry.Text = text;
address_entry.Sensitive = (state == FieldState.Enabled);
address_example.Markup = "<span size=\"small\" fgcolor=\"" +
SecondaryTextColor + "\">" + example_text + "</span>";
Program.UI.SecondaryTextColor + "\">" + example_text + "</span>";
});
};

Expand All @@ -291,7 +291,7 @@ public void ShowPage (PageType type, string [] warnings)
path_entry.Text = text;
path_entry.Sensitive = (state == FieldState.Enabled);
path_example.Markup = "<span size=\"small\" fgcolor=\""
+ SecondaryTextColor + "\">" + example_text + "</span>";
+ Program.UI.SecondaryTextColor + "\">" + example_text + "</span>";
});
};

Expand Down Expand Up @@ -704,9 +704,9 @@ public void ShowPage (PageType type, string [] warnings)
TreeSelection selection = (column.TreeView as TreeView).Selection;

if (selection.IterIsSelected (iter))
markup = markup.Replace (SecondaryTextColor, SecondaryTextColorSelected);
markup = markup.Replace (Program.UI.SecondaryTextColor, Program.UI.SecondaryTextColorSelected);
else
markup = markup.Replace (SecondaryTextColorSelected, SecondaryTextColor);
markup = markup.Replace (Program.UI.SecondaryTextColorSelected, Program.UI.SecondaryTextColor);

(cell as CellRendererText).Markup = markup;
}
Expand Down
26 changes: 0 additions & 26 deletions SparkleShare/Linux/SparkleSetupWindow.cs
Expand Up @@ -29,9 +29,6 @@ public class SparkleSetupWindow : Window {
public string Header;
public string Description;

public readonly string SecondaryTextColor;
public readonly string SecondaryTextColorSelected;


public SparkleSetupWindow () : base ("SparkleShare Setup")
{
Expand All @@ -48,16 +45,6 @@ public SparkleSetupWindow () : base ("SparkleShare Setup")

DeleteEvent += delegate (object sender, DeleteEventArgs args) { args.RetVal = true; };

Gdk.Color color = SparkleUIHelpers.RGBAToColor (StyleContext.GetColor (StateFlags.Insensitive));
SecondaryTextColor = SparkleUIHelpers.ColorToHex (color);

color = MixColors (
SparkleUIHelpers.RGBAToColor (new TreeView ().StyleContext.GetColor (StateFlags.Selected)),
SparkleUIHelpers.RGBAToColor (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected)),
0.39);

SecondaryTextColorSelected = SparkleUIHelpers.ColorToHex (color);

HBox layout_horizontal = new HBox (false, 0);

VBox layout_vertical = new VBox (false, 0);
Expand Down Expand Up @@ -164,18 +151,5 @@ public void Reset ()
Present ();
base.ShowAll ();
}


private Gdk.Color MixColors (Gdk.Color first_color, Gdk.Color second_color, double ratio)
{
return new Gdk.Color (
Convert.ToByte ((255 * (Math.Min (65535, first_color.Red * (1.0 - ratio) +
second_color.Red * ratio))) / 65535),
Convert.ToByte ((255 * (Math.Min (65535, first_color.Green * (1.0 - ratio) +
second_color.Green * ratio))) / 65535),
Convert.ToByte ((255 * (Math.Min (65535, first_color.Blue * (1.0 - ratio) +
second_color.Blue * ratio))) / 65535)
);
}
}
}
15 changes: 15 additions & 0 deletions SparkleShare/Linux/SparkleUI.cs
Expand Up @@ -32,6 +32,10 @@ public class SparkleUI {
public SparkleBubbles Bubbles;
public SparkleSetup Setup;
public SparkleAbout About;
public SparkleNote Note;

public readonly string SecondaryTextColor;
public readonly string SecondaryTextColorSelected;

private Gtk.Application application;

Expand All @@ -42,6 +46,16 @@ public SparkleUI ()

this.application.Register (null);
this.application.Activated += ApplicationActivatedDelegate;

Gdk.Color color = SparkleUIHelpers.RGBAToColor (new Label().StyleContext.GetColor (StateFlags.Insensitive));
SecondaryTextColor = SparkleUIHelpers.ColorToHex (color);

color = SparkleUIHelpers.MixColors (
SparkleUIHelpers.RGBAToColor (new TreeView ().StyleContext.GetColor (StateFlags.Selected)),
SparkleUIHelpers.RGBAToColor (new TreeView ().StyleContext.GetBackgroundColor (StateFlags.Selected)),
0.39);

SecondaryTextColorSelected = SparkleUIHelpers.ColorToHex (color);
}


Expand Down Expand Up @@ -72,6 +86,7 @@ private void ApplicationActivatedDelegate (object sender, EventArgs args)
About = new SparkleAbout ();
Bubbles = new SparkleBubbles ();
StatusIcon = new SparkleStatusIcon ();
Note = new SparkleNote ();

Setup.Application = this.application;
EventLog.Application = this.application;
Expand Down
14 changes: 14 additions & 0 deletions SparkleShare/Linux/SparkleUIHelpers.cs
Expand Up @@ -75,5 +75,19 @@ public static string RGBAToHex (Gdk.RGBA rgba)
{
return ColorToHex (RGBAToColor (rgba));
}


public static Gdk.Color MixColors (Gdk.Color first_color, Gdk.Color second_color, double ratio)
{
return new Gdk.Color (
Convert.ToByte ((255 * (Math.Min (65535, first_color.Red * (1.0 - ratio) +
second_color.Red * ratio))) / 65535),
Convert.ToByte ((255 * (Math.Min (65535, first_color.Green * (1.0 - ratio) +
second_color.Green * ratio))) / 65535),
Convert.ToByte ((255 * (Math.Min (65535, first_color.Blue * (1.0 - ratio) +
second_color.Blue * ratio))) / 65535)
);
}
}
}

0 comments on commit e85ac9b

Please sign in to comment.