示例#1
0
        public StyleWindow()
            : base(Gtk.WindowType.Toplevel)
        {
            SetSizeRequest(800, 800);

            var box = new VBox();
            Add(box);

            var tab = new TextTagTable();
            buf = new TextBuffer(tab);
            buf.Text = System.IO.File.ReadAllText("res/theme/gtk.css");
            var en = new TextView(buf);
            sv = new ScrolledWindow();
            sv.Add(en);
            box.PackStart(sv, true, true, 0);

            var cssProvider = new CssProvider();
            StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, uint.MaxValue - 10);

            var isDefault = true;

            var but = new Button();
            but.Label = "Save";
            but.HeightRequest = 30;
            box.PackEnd(but, false, false, 0);
            but.Clicked += (s, e) => {
                System.IO.File.WriteAllText("res/theme/gtk.css", buf.Text);
            };

            buf.Changed += (s, e) => {
                bool error = false;
                try {
                    //StyleContext.RemoveProviderForScreen(Gdk.Screen.Default, cssProvider);
                    cssProvider.LoadFromData(buf.Text);
                    //StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, uint.MaxValue - 10);
                } catch (Exception ex) {
                    error = true;
                }
                if (error) {
                    if (!isDefault) {
                        StyleContext.RemoveProviderForScreen(Gdk.Screen.Default, cssProvider);
                        StyleContext.AddProviderForScreen(Gdk.Screen.Default, AppLib.GlobalCssProvider, uint.MaxValue);
                        isDefault = true;
                    }

                } else {
                    if (isDefault) {
                        StyleContext.RemoveProviderForScreen(Gdk.Screen.Default, AppLib.GlobalCssProvider);
                        StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, uint.MaxValue);
                        isDefault = false;
                    }
                }

            };

            ShowAll();
        }
示例#2
0
 static void ParsingError_cb(IntPtr inst, IntPtr section, IntPtr error)
 {
     try {
         CssProvider __obj = GLib.Object.GetObject(inst, false) as CssProvider;
         __obj.OnParsingError(section == IntPtr.Zero ? null : (Gtk.CssSection)GLib.Opaque.GetOpaque(section, typeof(Gtk.CssSection), false), error);
     } catch (Exception e) {
         GLib.ExceptionManager.RaiseUnhandledException(e, false);
     }
 }
示例#3
0
		private void ApplyCss (Widget widget, CssProvider provider, uint priority)
		{
			widget.StyleContext.AddProvider (provider, priority);
			var container = widget as Container;
			if (container != null) {
				foreach (var child in container.Children) {
					ApplyCss (child, provider, priority);
				}
			}
		}
示例#4
0
		public DemoCssBasics () : base ("CSS Basics")
		{
			SetDefaultSize (600, 500);

			buffer = new TextBuffer (null);

			var warning = new TextTag ("warning");
			warning.Underline = Pango.Underline.Single;
			buffer.TagTable.Add (warning);

			var error = new TextTag ("error");
			error.Underline = Pango.Underline.Error;
			buffer.TagTable.Add (error);

			provider = new CssProvider ();
			provider_reset = new CssProvider ();

			var container = new ScrolledWindow ();
			Add (container);
			var view = new TextView (buffer);
			container.Add (view);
			buffer.Changed += OnCssTextChanged;

			using (Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("reset.css"))
			using (StreamReader reader = new StreamReader(stream))
			{
				provider_reset.LoadFromData (reader.ReadToEnd());
			}

			using (Stream stream = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("css_basics.css"))
			using (StreamReader reader = new StreamReader(stream))
			{
				buffer.Text = reader.ReadToEnd();
			}

			// TODO: Connect to "parsing-error" signal in CssProvider, added in GTK+ 3.2

			ApplyCss (this, provider_reset, 800);
			ApplyCss (this, provider, UInt32.MaxValue);

			ShowAll ();
		}
示例#5
0
        public static void ApplyTheme() {
            // Based on this Link http://awesome.naquadah.org/wiki/Better_Font_Rendering

            // Get the Global Settings
            var setts = Gtk.Settings.Default;
            // This enables clear text on Win32, makes the text look a lot less crappy
            setts.XftRgba = "rgb";
            // This enlarges the size of the controls based on the dpi
            setts.XftDpi = 96;
            // By Default Anti-aliasing is enabled, if you want to disable it for any reason set this value to 0
            //setts.XftAntialias = 0
            // Enable text hinting
            setts.XftHinting = 1;
            //setts.XftHintstyle = "hintslight"
            setts.XftHintstyle = "hintfull";

            // Load the Theme
            Gtk.CssProvider css_provider = new Gtk.CssProvider();
            //css_provider.LoadFromPath("themes/DeLorean-3.14/gtk-3.0/gtk.css")
            css_provider.LoadFromPath("themes/DeLorean-Dark-3.14/gtk-3.0/gtk.css");
            Gtk.StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800);
        }
示例#6
0
        void CreateAbout()
        {
            CssProvider window_css_provider = new CssProvider ();
            Image image = UserInterfaceHelpers.GetImage ("about.png");

            window_css_provider.LoadFromData ("GtkWindow {" +
                "background-image: url('" + image.File + "');" +
                "background-repeat: no-repeat;" +
                "background-position: left bottom;" +
                "}");

            StyleContext.AddProvider (window_css_provider, 800);

            var layout_vertical = new VBox (false, 0);
            var links_layout = new HBox (false, 16);

            CssProvider label_css_provider = new CssProvider ();
            label_css_provider.LoadFromData ("GtkLabel { color: #fff; font-size: 10px; background-color: rgba(0, 0, 0, 0); }");

            CssProvider label_highlight_css_provider = new CssProvider ();
            label_highlight_css_provider.LoadFromData ("GtkLabel { color: #a8bbcf; font-size: 10px; }");

            var version = new Label {
                Text = "version " + Controller.RunningVersion,
                Xalign = 0, Xpad = 0
            };

            if (InstallationInfo.Directory.StartsWith ("/app", StringComparison.InvariantCulture))
                version.Text += " (Flatpak)";

            version.StyleContext.AddProvider (label_css_provider, 800);

            updates = new Label ("Checking for updates…") {
                Xalign = 0, Xpad = 0
            };

            updates.StyleContext.AddProvider (label_highlight_css_provider, 800);

            var copyright = new Label {
                Markup = string.Format ("Copyright © 2010–{0} Hylke Bons and others", DateTime.Now.Year),
                Xalign = 0, Xpad = 0
            };

            copyright.StyleContext.AddProvider (label_css_provider, 800);

            var license = new TextView {
                Sensitive = false,
                WrapMode = WrapMode.Word
            };

            var text_view_css_provider = new CssProvider ();
            text_view_css_provider.LoadFromData ("GtkTextView { color: #fff; font-size: 10px; background-color: rgba(0, 0, 0, 0); }");

            license.StyleContext.AddProvider (text_view_css_provider, 800);

            TextBuffer license_buffer = license.Buffer;

            license_buffer.Text = "SparkleShare is Open Source and you’re free to use, change, " +
                "and share it under the GNU GPLv3";

            version.StyleContext.AddProvider (label_css_provider, 800);

            var website_link        = new Link ("Website", Controller.WebsiteLinkAddress);
            var credits_link        = new Link ("Credits", Controller.CreditsLinkAddress);
            var report_problem_link = new Link ("Report a problem", Controller.ReportProblemLinkAddress);
            var debug_log_link      = new Link ("Debug log", Controller.DebugLogLinkAddress);

            layout_vertical.PackStart (new Label (""), true, true, 0);
            layout_vertical.PackStart (version, false, false, 0);
            layout_vertical.PackStart (updates, false, false, 0);
            layout_vertical.PackStart (copyright, false, false, 6);
            layout_vertical.PackStart (license, false, false, 6);
            layout_vertical.PackStart (links_layout, false, false, 16);

            links_layout.PackStart (website_link, false, false, 0);
            links_layout.PackStart (credits_link, false, false, 0);
            links_layout.PackStart (report_problem_link, false, false, 0);
            links_layout.PackStart (debug_log_link, false, false, 0);

            var layout_horizontal = new HBox (false, 0);
            layout_horizontal.PackStart (new Label (""), false, false, 149);
            layout_horizontal.PackStart (layout_vertical, false, false, 0);

            Add (layout_horizontal);
        }
示例#7
0
        public Link(string label, string url)
        {
            Markup   = string.Format ("<a href=\"{0}\">{1}</a>", url, label);
            CanFocus = false;

            CssProvider css_provider = new CssProvider ();
            css_provider.LoadFromData ("GtkLabel { color: #729fcf; font-size: 10px; }");
            StyleContext.AddProvider (css_provider, 800);
        }
示例#8
0
        public EventLog () : base ("Recent Changes")
        {
            SetWmclass ("SparkleShare", "SparkleShare");

            TypeHint = Gdk.WindowTypeHint.Dialog;
            IconName = "org.sparkleshare.SparkleShare";

            SetSizeRequest (480, 640);

            Gdk.Rectangle monitor_0_rect = Gdk.Screen.Default.GetMonitorGeometry (0);
            pos_x = (int) (monitor_0_rect.Width * 0.61);
            pos_y = (int) (monitor_0_rect.Height * 0.5 - (HeightRequest * 0.5));

            Resize (480, (int) (monitor_0_rect.Height * 0.8));

            this.size_label    = new Label () { Xalign = 0, Markup = "<b>Size:</b> …" };
            this.history_label = new Label () { Xalign = 0, Markup = "<b>History:</b> …" };

            this.size_label.SetSizeRequest (100, 24);

            HBox layout_sizes = new HBox (false, 0);
            layout_sizes.PackStart (this.size_label, false, false, 12);
            layout_sizes.PackStart (this.history_label, false, false, 0);

            VBox layout_vertical = new VBox (false, 0);
            this.spinner         = new Spinner ();
            this.spinner_wrapper = new VBox ();
            this.content_wrapper = new EventBox ();
            this.scrolled_window = new ScrolledWindow ();

            CssProvider css_provider = new CssProvider ();
            css_provider.LoadFromData ("GtkEventBox { background-color: #ffffff; }");
            this.content_wrapper.StyleContext.AddProvider (css_provider, 800);

            this.web_view = CreateWebView ();
            this.scrolled_window.Add (this.web_view);
            
            this.spinner_wrapper = new VBox (false, 0);
            this.spinner_wrapper.PackStart (new Label(""), true, true, 0);
            this.spinner_wrapper.PackStart (this.spinner, false, false, 0);
            this.spinner_wrapper.PackStart (new Label(""), true, true, 0);            
            this.spinner.SetSizeRequest (24, 24);
            this.spinner.Start ();

            this.content_wrapper.Add (this.spinner_wrapper);

            layout_vertical.PackStart (this.content_wrapper, true, true, 0);

            Add (layout_vertical);


            Controller.HideWindowEvent += delegate {
                Application.Invoke (delegate {
                    Hide ();
                    
                    if (this.content_wrapper.Child != null)
                        this.content_wrapper.Remove (this.content_wrapper.Child);
                });
            };

            Controller.ShowWindowEvent += delegate {
                Application.Invoke (delegate {
                    Move (pos_x, pos_y);
                    ShowAll ();
                    Present ();
                });
            };
			
            Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) {
                Application.Invoke (delegate {
                    FileChooserDialog dialog = new FileChooserDialog ("Restore from History", this,
                        FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Ok);
					
                    dialog.CurrentName = file_name;
                    dialog.DoOverwriteConfirmation = true;
                    dialog.SetCurrentFolder (target_folder_path);

                    if (dialog.Run () == (int) ResponseType.Ok)
                        Controller.SaveDialogCompleted (dialog.Filename);
                    else
                        Controller.SaveDialogCancelled ();

                    dialog.Destroy ();
                });
            };

            Controller.UpdateContentEvent += delegate (string html) {
                 Application.Invoke (delegate { UpdateContent (html); });
            };

            Controller.ContentLoadingEvent += delegate {
                Application.Invoke (delegate {
                    if (this.content_wrapper.Child != null)
                        this.content_wrapper.Remove (this.content_wrapper.Child);

                    this.content_wrapper.Add (this.spinner_wrapper);
                    this.spinner.Start ();
                });
            };

            Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
                Application.Invoke (delegate {
                    this.size_label.Markup    = "<b>Size</b>  " + size;
                    this.history_label.Markup = "<b>History</b>  " + history_size;
                });
            };

            DeleteEvent += delegate (object o, DeleteEventArgs args) {
                Controller.WindowClosed ();
                args.RetVal = true;
            };
            
            KeyPressEvent += delegate (object o, KeyPressEventArgs args) {
                if (args.Event.Key == Gdk.Key.Escape ||
                    (args.Event.State == Gdk.ModifierType.ControlMask && args.Event.Key == Gdk.Key.w)) {
                    
                    Controller.WindowClosed ();
                }
            };
        }
示例#9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            if (args.Length > 0)
            {
                Configure.Init(args[0]);
            }
            if (Configure.GetInstance().IsServer == 1)
            {
                Console.WriteLine("This is server!");
                TcpChatServer.Program.Start(new string[] { Configure.GetInstance().Port.ToString() });
            }
            else
            {
                Console.WriteLine("This is client!");
                TcpChatClient.Program.Start(new string[] { Configure.GetInstance().Host, Configure.GetInstance().Port.ToString() });
            }
            Gtk.Application.Init();//初始化

            // Load the Theme
            var css_provider = new Gtk.CssProvider();

            //css_provider.LoadFromPath("themes/DeLorean-3.14/gtk-3.0/gtk.css")
            //css_provider.LoadFromPath("themes/DeLorean-Dark-3.14/gtk-3.0/gtk.css");
            css_provider.LoadFromData("#myWindow,button,treeview {" +
                                      "background-image: url('bg.jpg');" +
                                      "background-repeat: no-repeat;" +
                                      "background-position: left bottom;" +
                                      "}" +
                                      "#myWindow,button,treeview {" +
                                      "background-image: radial-gradient(ellipse at center, yellow 0%, green 100%);" +
                                      "}" +
                                      "label0 {" +
                                      "background-image: radial-gradient(circle farthest-side at left bottom, red, yellow 50px, green);" +
                                      "}");
            Gtk.StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800);

            /*using (ImageSurface draw = new ImageSurface(Format.Argb32, 70, 150))
             * {
             *  using (Cairo.Context gr = new Cairo.Context(draw))
             *  {
             *      gr.Antialias = Antialias.Subpixel;    // sets the anti-aliasing method
             *      gr.LineWidth = 9;          // sets the line width
             *      gr.SetSourceColor(new Cairo.Color(0, 0, 0, 1));   // red, green, blue, alpha
             *      gr.MoveTo(10, 10);          // sets the Context's start point.
             *      gr.LineTo(40, 60);          // draws a "virtual" line from 5,5 to 20,30
             *      gr.Stroke();          //stroke the line to the image surface
             *
             *      gr.Antialias = Antialias.Gray;
             *      gr.LineWidth = 8;
             *      gr.SetSourceColor(new Cairo.Color(1, 0, 0, 1));
             *      gr.LineCap = LineCap.Round;
             *      gr.MoveTo(10, 50);
             *      gr.LineTo(40, 100);
             *      gr.Stroke();
             *
             *      gr.Antialias = Antialias.None;    //fastest method but low quality
             *      gr.LineWidth = 7;
             *      gr.MoveTo(10, 90);
             *      gr.LineTo(40, 140);
             *      gr.Stroke();
             *
             *      draw.WriteToPng("antialias.png");  //save the image as a png image.
             *  }
             * }
             * {
             *  var screen = Gdk.Screen.Default;
             *  var root_window = Gdk.Global.DefaultRootWindow;
             *  int w = screen.Width;
             *  int h = screen.Height;
             *
             *  var stopWatch = new Stopwatch();
             *  stopWatch.Start();
             *  Gdk.CairoHelper.Create(root_window).GetTarget().WriteToPng("test.png");
             *  stopWatch.Stop();
             *  Console.WriteLine("spend {0}ms", stopWatch.Elapsed.TotalMilliseconds);
             *
             *  var imageSurface = new Cairo.ImageSurface(Format.ARGB32, w, h);
             *  var context = new Cairo.Context(imageSurface);
             *  context.Antialias = Antialias.Default;
             *  context.SetSourceColor(new Cairo.Color(1, 0, 0, 1));
             *  // Select a color (blue)
             *  context.SetSourceRGB(0, 0, 1);
             *  // Select a font to draw with
             *  context.SelectFontFace("serif", FontSlant.Normal, FontWeight.Bold);
             *  context.SetFontSize(30.0);
             *  context.LineWidth = 10.0;
             *  context.MoveTo(0, 0);
             *  context.LineTo(600.0, 600.0);
             *  context.ShowText("Message");
             *  context.Stroke();
             *
             *  context.Rectangle(700, 700, 200, 200);
             *  context.Fill();
             *  context.Stroke();
             *
             *  double xc = 0.5;
             *  double yc = 0.5;
             *  double radius = 0.4;
             *  double angle1 = 45.0 * (Math.PI / 180.0);  // angles are specified
             *  double angle2 = 180.0 * (Math.PI / 180.0);  // in radians
             *  context.Scale(w, h);
             *  context.LineWidth = 0.04;
             *
             *  context.Arc(xc, yc, radius, angle1, angle2);
             *  context.Stroke();
             *
             *  // draw helping lines
             *  context.SetSourceColor(new Cairo.Color(1, 0.2, 0.2, 0.6));
             *  context.Arc(xc, yc, 0.05, 0, 2 * Math.PI);
             *  context.Fill();
             *  context.LineWidth = 0.03;
             *  context.Arc(xc, yc, radius, angle1, angle1);
             *  context.LineTo(new PointD(xc, yc));
             *  context.Arc(xc, yc, radius, angle2, angle2);
             *  context.LineTo(new PointD(xc, yc));
             *  context.Stroke();
             *
             *  context.SetSourceColor(new Cairo.Color(1, 0.2, 0.2, 0.6));
             *  context.Translate(100, 100);
             *  context.Scale(Math.Min(w / 640.0, h / 480.0), Math.Min(w / 640.0, h / 480.0));
             *  context.Arc(0, 0, 10.0, 0.0, 2 * Math.PI);
             *  context.Fill();
             *  context.Stroke();
             *
             *  context.Save();
             *  imageSurface.WriteToPng("aa.png");
             * }*/

            var win = init_window();

            win.Name = "myWindow";
            //将标签加入到窗体
            win.Add(MainForm.init_main_form());

            win.ShowAll();         //显示窗体

            Gtk.Application.Run(); //运行窗体

            if (Configure.GetInstance().IsServer == 0)
            {
                TcpChatClient.Program.Stop();
            }
            else
            {
                TcpChatServer.Program.Stop();
            }
        }
示例#10
0
        private void CreateAbout ()
        {
            Gdk.RGBA white = new Gdk.RGBA ();
            white.Parse ("#ffffff");

            Gdk.RGBA highlight = new Gdk.RGBA ();
            highlight.Parse ("#a8bbcf");

            Pango.FontDescription font = StyleContext.GetFont (StateFlags.Normal);
            font.Size = 9 * 1024;

            CssProvider css_provider = new CssProvider ();
            string image_path        = new string [] { SparkleUI.AssetsPath, "pixmaps", "about.png" }.Combine ();

            css_provider.LoadFromData ("GtkWindow {" +
                "background-image: url('" + image_path + "');" +
                "background-repeat: no-repeat;" +
                "background-position: left bottom;" +
                "}");
            
            StyleContext.AddProvider (css_provider, 800);

            VBox layout_vertical = new VBox (false, 0);            
            HBox links_layout = new HBox (false, 16);


            Label version = new Label () {
                Text   = "version " + Controller.RunningVersion,
                Xalign = 0, Xpad   = 0
            };

            version.OverrideFont (font);
            version.OverrideColor (StateFlags.Normal, white);


            this.updates = new Label ("Checking for updates…") {
                Xalign = 0, Xpad = 0
            };

            this.updates.OverrideFont (font);
            this.updates.OverrideColor (StateFlags.Normal, highlight);


            Label copyright = new Label () {
                Markup = string.Format ("Copyright © 2010–{0} Hylke Bons and others.", DateTime.Now.Year),
                Xalign = 0, Xpad   = 0
            };

            copyright.OverrideFont (font);
            copyright.OverrideColor (StateFlags.Normal, white);


            TextView license          = new TextView ();
            TextBuffer license_buffer = license.Buffer;
            license.WrapMode          = WrapMode.Word;
            license.Sensitive         = false;

            license_buffer.Text = "SparkleShare is Open Source and you’re free to use, change, " +
                "and share it under the GNU GPLv3.";

            license.OverrideBackgroundColor (StateFlags.Normal, new Gdk.RGBA () { Alpha = 0 });
            license.OverrideFont (font);
            license.OverrideColor (StateFlags.Normal, white);

            
            SparkleLink website_link        = new SparkleLink ("Website", Controller.WebsiteLinkAddress);
            SparkleLink credits_link        = new SparkleLink ("Credits", Controller.CreditsLinkAddress);
            SparkleLink report_problem_link = new SparkleLink ("Report a problem", Controller.ReportProblemLinkAddress);
            SparkleLink debug_log_link      = new SparkleLink ("Debug log", Controller.DebugLogLinkAddress);


            layout_vertical.PackStart (new Label (""), true, true, 0);            
            layout_vertical.PackStart (version, false, false, 0);
            layout_vertical.PackStart (this.updates, false, false, 0);
            layout_vertical.PackStart (copyright, false, false, 6);
            layout_vertical.PackStart (license, false, false, 6);
            layout_vertical.PackStart (links_layout, false, false, 16);

            links_layout.PackStart (website_link, false, false, 0);
            links_layout.PackStart (credits_link, false, false, 0);
            links_layout.PackStart (report_problem_link, false, false, 0);
            links_layout.PackStart (debug_log_link, false, false, 0);
            
            HBox layout_horizontal = new HBox (false, 0);
            layout_horizontal.PackStart (new Label (""), false, false, 149);
            layout_horizontal.PackStart (layout_vertical, false, false, 0);

            Add (layout_horizontal);
        }