public void GetCurrentRgba(Gdk.RGBA rgba)
        {
            IntPtr native_rgba = GLib.Marshaller.StructureToPtrAlloc(rgba);

            gtk_color_selection_get_current_rgba(Handle, native_rgba);
            Marshal.FreeHGlobal(native_rgba);
        }
        public void SetPreviousRgba(Gdk.RGBA rgba)
        {
            IntPtr native_rgba = GLib.Marshaller.StructureToPtrAlloc(rgba);

            gtk_color_selection_set_previous_rgba(Handle, native_rgba);
            Marshal.FreeHGlobal(native_rgba);
        }
Esempio n. 3
0
        public SymbolicColor(Gdk.RGBA color)
        {
            IntPtr native_color = GLib.Marshaller.StructureToPtrAlloc(color);

            Raw = gtk_symbolic_color_new_literal(native_color);
            Marshal.FreeHGlobal(native_color);
        }
Esempio n. 4
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!pulsator.IsPulsing)
            {
                return(base.OnDrawn(cr));
            }

            double x     = Allocation.Width / 2;
            double y     = Allocation.Height / 2;
            double r     = Math.Min(Allocation.Width, Allocation.Height) / 2;
            double alpha = Choreographer.Compose(pulsator.Percent, Easing.Sine);

            Gdk.RGBA             rgba  = StyleContext.GetBackgroundColor(StateFlags.Selected);
            Cairo.Color          color = CairoExtensions.GdkRGBAToCairoColor(rgba);
            Cairo.RadialGradient fill  = new Cairo.RadialGradient(x, y, 0, x, y, r);
            color.A = alpha;
            fill.AddColorStop(0, color);
            fill.AddColorStop(0.5, color);
            color.A = 0;
            fill.AddColorStop(1, color);

            cr.Arc(x, y, r, 0, 2 * Math.PI);
            cr.Pattern = fill;
            cr.Fill();
            fill.Destroy();

            return(base.OnDrawn(cr));
        }
Esempio n. 5
0
        public static Gdk.RGBA ColorBlend(Gdk.RGBA a, Gdk.RGBA b)
        {
            // at some point, might be nice to allow any blend?
            double blend = 0.5;

            if (blend < 0.0 || blend > 1.0)
            {
                throw new ApplicationException("blend < 0.0 || blend > 1.0");
            }

            double blendRatio = 1.0 - blend;

            double mR = a.Red + b.Red;
            double mG = a.Green + b.Green;
            double mB = a.Blue + b.Blue;

            double blR = mR * blendRatio;
            double blG = mG * blendRatio;
            double blB = mB * blendRatio;

            Gdk.RGBA color = new Gdk.RGBA();
            color.Red   = blR;
            color.Green = blG;
            color.Blue  = blB;
            return(color);
        }
Esempio n. 6
0
        public static void SetSourceRgba(Cairo.Context cr, Gdk.RGBA rgba)
        {
            IntPtr native_rgba = GLib.Marshaller.StructureToPtrAlloc(rgba);

            gdk_cairo_set_source_rgba(cr == null ? IntPtr.Zero : cr.Handle, native_rgba);
            Marshal.FreeHGlobal(native_rgba);
        }
Esempio n. 7
0
		public static Gdk.RGBA ToGtkRgbaValue (this Xwt.Drawing.Color color)
		{
			var rgba = new Gdk.RGBA ();
			rgba.Red = color.Red;
			rgba.Green = color.Green;
			rgba.Blue = color.Blue;
			rgba.Alpha = color.Alpha;
			return rgba;
		}
Esempio n. 8
0
 public static Gdk.Color RGBAToColor(Gdk.RGBA rgba)
 {
     return(new Gdk.Color()
     {
         Red = (ushort)(rgba.Red * 65535),
         Green = (ushort)(rgba.Green * 65535),
         Blue = (ushort)(rgba.Blue * 65535)
     });
 }
Esempio n. 9
0
        public bool GetBackground(Gdk.RGBA background)
        {
            IntPtr native_background = GLib.Marshaller.StructureToPtrAlloc(background);
            bool   raw_ret           = gtk_source_mark_attributes_get_background(Handle, native_background);
            bool   ret = raw_ret;

            Marshal.FreeHGlobal(native_background);
            return(ret);
        }
Esempio n. 10
0
 private void SetColors()
 {
     marginTextColor        = Base.Ui.Window.StyleContext.GetColor(StateFlags.Active);
     marginBGColor          = Base.Ui.Window.StyleContext.GetBackgroundColor(StateFlags.Active);
     marginLineColor        = marginBGColor;
     marginLineColor.Red   -= (marginLineColor.Red <= 0.1 ? 0 : 0.1);
     marginLineColor.Green -= (marginLineColor.Green <= 0.1 ? 0 : 0.1);
     marginLineColor.Blue  -= (marginLineColor.Blue <= 0.1 ? 0 : 0.1);
 }
Esempio n. 11
0
 /// <summary>
 /// Convert a System.Drawing.Color to a Gdk.RGBA.
 /// </summary>
 /// <param name="colour">The colour to be converted.</param>
 /// <returns></returns>
 internal static Color ToColour(this Gdk.RGBA colour)
 {
     return(Color.FromArgb
            (
                Convert.ToInt32(MathUtilities.Bound(colour.Alpha, 0, 1) * 0xff),
                Convert.ToInt32(MathUtilities.Bound(colour.Red, 0, 1) * 0xff),
                Convert.ToInt32(MathUtilities.Bound(colour.Green, 0, 1) * 0xff),
                Convert.ToInt32(MathUtilities.Bound(colour.Blue, 0, 1) * 0xff)
            ));
 }
Esempio n. 12
0
        public static Gdk.RGBA ToGtkRgbaValue(this Xwt.Drawing.Color color)
        {
            var rgba = new Gdk.RGBA();

            rgba.Red   = color.Red;
            rgba.Green = color.Green;
            rgba.Blue  = color.Blue;
            rgba.Alpha = color.Alpha;
            return(rgba);
        }
Esempio n. 13
0
 protected override bool OnDrawn(Cairo.Context cr)
 {
     cr.Save();
     Gdk.RGBA color = Hyena.Gui.GtkUtilities.ColorBlend(
         StyleContext.GetBackgroundColor(StateFlags.Normal),
         StyleContext.GetColor(StateFlags.Normal));
     cr.SetSourceRGBA(color.Red, color.Green, color.Blue, color.Alpha);
     DrawCairo(cr);
     cr.Restore();
     return(false);
 }
Esempio n. 14
0
        public bool LookupColor(string color_name, out Gdk.RGBA color)
        {
            IntPtr native_color_name = GLib.Marshaller.StringToPtrGStrdup(color_name);
            IntPtr native_color      = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Gdk.RGBA)));
            bool   raw_ret           = gtk_style_context_lookup_color(Handle, native_color_name, native_color);
            bool   ret = raw_ret;

            GLib.Marshaller.Free(native_color_name);
            color = Gdk.RGBA.New(native_color);
            Marshal.FreeHGlobal(native_color);
            return(ret);
        }
Esempio n. 15
0
        public Gdk.RGBA Copy()
        {
            IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(this));

            System.Runtime.InteropServices.Marshal.StructureToPtr(this, this_as_native, false);
            IntPtr raw_ret = gdk_rgba_copy(this_as_native);

            Gdk.RGBA ret = Gdk.RGBA.New(raw_ret);
            ReadNative(this_as_native, ref this);
            System.Runtime.InteropServices.Marshal.FreeHGlobal(this_as_native);
            return(ret);
        }
Esempio n. 16
0
        private void RenderLabels(Context cr)
        {
            if (segments.Count == 0)
            {
                return;
            }

            Pango.Layout layout           = null;
            Gdk.RGBA     rgba             = StyleContext.GetColor(StateFlags);
            Color        text_color       = CairoExtensions.GdkRGBAToCairoColor(rgba);
            Color        box_stroke_color = new Color(0, 0, 0, 0.6);

            int x = 0;

            foreach (Segment segment in segments)
            {
                cr.LineWidth = 1;
                cr.Rectangle(x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
                using (var grad = MakeSegmentGradient(segment_box_size, segment.Color, true)) {
                    cr.SetSource(grad);
                    cr.FillPreserve();
                    cr.SetSourceColor(box_stroke_color);
                    cr.Stroke();
                }

                x += segment_box_size + segment_box_spacing;

                int lw, lh;
                layout = CreateAdaptLayout(layout, false, true);
                layout.SetText(FormatSegmentText(segment));
                layout.GetPixelSize(out lw, out lh);

                cr.MoveTo(x, 0);
                text_color.A = 0.9;
                cr.SetSourceColor(text_color);
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                layout = CreateAdaptLayout(layout, true, false);
                layout.SetText(FormatSegmentValue(segment));

                cr.MoveTo(x, lh);
                text_color.A = 0.75;
                cr.SetSourceColor(text_color);
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                x += segment.LayoutWidth + segment_label_spacing;
            }

            layout.Dispose();
        }
Esempio n. 17
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!composited)
            {
                return(base.OnDrawn(cr));
            }

            Gdk.RGBA color = StyleContext.GetBackgroundColor(StateFlags);

            ShapeSurface(cr, new Cairo.Color(color.Red, color.Blue, color.Green, 0.85));

            return(base.OnDrawn(cr));
        }
Esempio n. 18
0
 protected override void OnStyleUpdated()
 {
     Gdk.RGBA rgba = StyleContext.GetBackgroundColor(StateFlags.Selected);
     fill_color_a       = new Color(rgba.Red, rgba.Green, rgba.Blue, rgba.Alpha);
     rgba               = StyleContext.GetColor(StateFlags.Selected);
     fill_color_b       = new Color(rgba.Red, rgba.Green, rgba.Blue, rgba.Alpha);
     rgba               = StyleContext.GetColor(StateFlags.Normal);
     stroke_color       = new Color(rgba.Red, rgba.Green, rgba.Blue, 0.6);
     inner_stroke_color = new Color(rgba.Red, rgba.Green, rgba.Blue, 0.4);
     text_color         = new Color(rgba.Red, rgba.Green, rgba.Blue, 0.8);
     rgba               = StyleContext.GetBackgroundColor(StateFlags.Normal);
     text_bg_color      = new Color(rgba.Red, rgba.Green, rgba.Blue, 0.6);
     fill_color_c       = new Color(rgba.Red, rgba.Green, rgba.Blue, rgba.Alpha);
 }
Esempio n. 19
0
        public void LoadSymbolicAsync(Gdk.RGBA fg, Gdk.RGBA success_color, Gdk.RGBA warning_color, Gdk.RGBA error_color, GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb)
        {
            IntPtr native_fg            = GLib.Marshaller.StructureToPtrAlloc(fg);
            IntPtr native_success_color = GLib.Marshaller.StructureToPtrAlloc(success_color);
            IntPtr native_warning_color = GLib.Marshaller.StructureToPtrAlloc(warning_color);
            IntPtr native_error_color   = GLib.Marshaller.StructureToPtrAlloc(error_color);

            GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper(cb);
            gtk_icon_info_load_symbolic_async(Handle, native_fg, native_success_color, native_warning_color, native_error_color, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
            Marshal.FreeHGlobal(native_fg);
            Marshal.FreeHGlobal(native_success_color);
            Marshal.FreeHGlobal(native_warning_color);
            Marshal.FreeHGlobal(native_error_color);
        }
Esempio n. 20
0
        public LinkLabel(string text, Uri uri)
        {
            CanFocus     = true;
            AppPaintable = true;

            this.uri = uri;

            label = new Label(text);
            label.Show();

            link_color = label.StyleContext.GetBackgroundColor(StateFlags.Selected);
            ActAsLink  = true;

            Add(label);
        }
Esempio n. 21
0
 private void InternalColorActivated(Gdk.RGBA color)
 {
     GLib.Value      ret             = GLib.Value.Empty;
     GLib.ValueArray inst_and_params = new GLib.ValueArray(2);
     GLib.Value[]    vals            = new GLib.Value [2];
     vals [0] = new GLib.Value(this);
     inst_and_params.Append(vals [0]);
     vals [1] = new GLib.Value(color);
     inst_and_params.Append(vals [1]);
     g_signal_chain_from_overridden(inst_and_params.ArrayPtr, ref ret);
     foreach (GLib.Value v in vals)
     {
         v.Dispose();
     }
 }
Esempio n. 22
0
        public ColorButton(Gdk.RGBA rgba) : base(IntPtr.Zero)
        {
            if (GetType() != typeof(ColorButton))
            {
                var vals  = new List <GLib.Value> ();
                var names = new List <string> ();
                names.Add("rgba");
                vals.Add(new GLib.Value(rgba));
                CreateNativeObject(names.ToArray(), vals.ToArray());
                return;
            }
            IntPtr native_rgba = GLib.Marshaller.StructureToPtrAlloc(rgba);

            Raw = gtk_color_button_new_with_rgba(native_rgba);
            Marshal.FreeHGlobal(native_rgba);
        }
Esempio n. 23
0
        static public Gdk.RGBA RGBToGDKRGB(double red, double green,
                                           double blue)
        {
            var r = red / 255d;
            var g = green / 255d;
            var b = blue / 255d;

            var rgba = new Gdk.RGBA();

            rgba.Red   = r;
            rgba.Green = g;
            rgba.Blue  = b;
            rgba.Alpha = 1;

            return(rgba);
        }
Esempio n. 24
0
        public ChatMessageUserWidget(Gdk.RGBA color, string username) : base($"<b>{username}</b>")
        {
            Color    = color;
            Username = username;

            this.UseMarkup = true;

            //this.Expand = false;
            //this.Ellipsize = EllipsizeMode.Middle;

            this.SetPadding(10, 2);


            this.OverrideFont(FontDescription.FromString("'Raleway' Normal Normal Small-Caps Normal 11"));

            this.OverrideColor(StateFlags.Normal, Color);
            this.OverrideBackgroundColor(StateFlags.Normal, ColorHelper.Color8888(100, 0, 0, 0));
        }
        static string HexFormat(Gdk.RGBA color)
        {
            StringBuilder s = new StringBuilder();

            double[] vals     = { color.Red, color.Green, color.Blue };
            char[]   hexchars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                                  'A',   'B', 'C', 'D', 'E', 'F' };

            s.Append('#');
            foreach (double val in vals)
            {
                /* Convert to a range of 0-255, then lookup the
                 * digit for each half-byte */
                byte rounded = (byte)(val * 255);
                s.Append(hexchars[(rounded & 0xf0) >> 4]);
                s.Append(hexchars[rounded & 0x0f]);
            }

            return(s.ToString());
        }
Esempio n. 26
0
        public unsafe Gdk.Pixbuf LoadSymbolic(Gdk.RGBA fg, Gdk.RGBA success_color, Gdk.RGBA warning_color, Gdk.RGBA error_color, out bool was_symbolic)
        {
            IntPtr native_fg            = GLib.Marshaller.StructureToPtrAlloc(fg);
            IntPtr native_success_color = GLib.Marshaller.StructureToPtrAlloc(success_color);
            IntPtr native_warning_color = GLib.Marshaller.StructureToPtrAlloc(warning_color);
            IntPtr native_error_color   = GLib.Marshaller.StructureToPtrAlloc(error_color);
            IntPtr error   = IntPtr.Zero;
            IntPtr raw_ret = gtk_icon_info_load_symbolic(Handle, native_fg, native_success_color, native_warning_color, native_error_color, out was_symbolic, out error);

            Gdk.Pixbuf ret = GLib.Object.GetObject(raw_ret) as Gdk.Pixbuf;
            Marshal.FreeHGlobal(native_fg);
            Marshal.FreeHGlobal(native_success_color);
            Marshal.FreeHGlobal(native_warning_color);
            Marshal.FreeHGlobal(native_error_color);
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(ret);
        }
        static void Display_Result(Gdk.RGBA color)
        {
            dialog       = new Dialog();
            dialog.Title = "Selected Color: " + HexFormat(color);

            DrawingArea da = new DrawingArea();

            da.OverrideBackgroundColor(StateFlags.Normal, color);

            dialog.ContentArea.BorderWidth = 10;
            dialog.ContentArea.PackStart(da, true, true, 10);
            dialog.SetDefaultSize(200, 200);

            Button button = new Button(Stock.Ok);

            button.Clicked   += new EventHandler(Dialog_Ok);
            button.CanDefault = true;
            dialog.ActionArea.PackStart(button, true, true, 0);
            button.GrabDefault();

            dialog.ShowAll();
        }
Esempio n. 28
0
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is TrackInfo))
            {
                throw new InvalidCastException("ColumnCellAlbum can only bind to AlbumInfo objects");
            }

            TrackInfo track = (TrackInfo)BoundObject;

            context.Layout.Width     = (int)((cellWidth - 8) * Pango.Scale.PangoScale);
            context.Layout.Ellipsize = Pango.EllipsizeMode.End;
            context.Layout.FontDescription.Weight = font_weight;
            context.Layout.SetMarkup(String.Format("<b>{0}</b>\n<small><i>{1}</i></small>",
                                                   GLib.Markup.EscapeText(track.DisplayTrackTitle),
                                                   GLib.Markup.EscapeText(track.DisplayArtistName)));

            int text_width;
            int text_height;

            context.Layout.GetPixelSize(out text_width, out text_height);

            context.Context.MoveTo(4, ((int)cellHeight - text_height) / 2);
            context.Widget.StyleContext.Save();
            context.Widget.StyleContext.AddClass("entry");
            Gdk.RGBA    rgba  = context.Widget.StyleContext.GetColor(context.Selected ? StateFlags.Selected : StateFlags.Normal);
            Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor(rgba);
            context.Widget.StyleContext.Restore();
            color.A = (!context.Opaque) ? 0.3 : 1.0;
            context.Context.SetSourceColor(color);

            Pango.CairoHelper.ShowLayout(context.Context, context.Layout);
        }
Esempio n. 29
0
        public Tile()
        {
            Table table = new Table(2, 2, false);

            table.ColumnSpacing = 6;
            table.RowSpacing    = 2;
            table.BorderWidth   = 2;

            PrimaryLabel   = new Label();
            SecondaryLabel = new Label();

            table.Attach(image, 0, 1, 0, 2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
            table.Attach(PrimaryLabel, 1, 2, 0, 1,
                         AttachOptions.Fill | AttachOptions.Expand,
                         AttachOptions.Shrink, 0, 0);
            table.Attach(SecondaryLabel, 1, 2, 1, 2,
                         AttachOptions.Fill | AttachOptions.Expand,
                         AttachOptions.Fill | AttachOptions.Expand, 0, 0);

            table.ShowAll();
            Add(table);

            PrimaryLabel.Xalign = 0.0f;
            PrimaryLabel.Yalign = 0.0f;

            SecondaryLabel.Xalign = 0.0f;
            SecondaryLabel.Yalign = 0.0f;

            StyleUpdated += delegate {
                PrimaryLabel.OverrideColor(StateFlags.Normal, StyleContext.GetColor(StateFlags.Normal));
                Gdk.RGBA rgba = StyleContext.GetColor(StateFlags.Normal);
                SecondaryLabel.OverrideColor(StateFlags.Normal, Hyena.Gui.GtkUtilities.ColorBlend(
                                                 rgba, StyleContext.GetBackgroundColor(StateFlags.Normal)));
            };

            Relief = ReliefStyle.None;
        }
Esempio n. 30
0
        private void CreateTags(TextBuffer buffer)
        {
            Gdk.RGBA black = new Gdk.RGBA();
            black.Parse("#000000");
            Gdk.RGBA white = new Gdk.RGBA();
            white.Parse("#ffffff");

            TextTag tag = new TextTag("off")
            {
                Weight         = Pango.Weight.Normal,
                BackgroundRgba = black,
                ForegroundRgba = white
            };

            buffer.TagTable.Add(tag);

            tag = new TextTag("on")
            {
                Weight         = Pango.Weight.Normal,
                BackgroundRgba = white,
                ForegroundRgba = black
            };
            buffer.TagTable.Add(tag);
        }
Esempio n. 31
0
        public PropertyGridTable ()
        {
            Build();

            items = new List<TreeItem> ();
            pitems = new List<TreeItem> ();
            eitems = new List<EventItem> ();
            nulliter = new TreeIter ();
            sortgroup = true;

            var column1 = new TreeViewColumn ();
            column1.Sizing = TreeViewColumnSizing.Fixed;
            column1.FixedWidth = 100;
            column1.Resizable = true;
            column1.Title = "Name";

            var textCell1 = new CellRendererText ();
            textCell1.Underline = Pango.Underline.Single;
            column1.PackStart (textCell1, false);

            var textCell2 = new CellRendererText ();
            column1.PackStart (textCell2, false);

            var idCell = new CellRendererText ();
            idCell.Visible = false;
            column1.PackStart (idCell, false);

            treeview1.AppendColumn (column1);

            var column2 = new TreeViewColumn ();
            column2.Sizing = TreeViewColumnSizing.Fixed;
            column2.Resizable = true;
            column2.Title = "Value";

            var editTextCell = new CellRendererText ();

            editTextCell.Edited += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id == id)
                        {
                            if(eitems[i].eventHandler != null)
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 4, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart (editTextCell, false);

            var editTextCell2 = new CellRendererText ();
            editTextCell2.Editable = true;
            editTextCell2.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    var dialog = new CollectionEditorDialog(window, model.GetValue(iter, 14).ToString());
                    if(dialog.Run() == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for(int i = 0;i < eitems.Count;i++)
                        {
                            if(eitems[i].id == id)
                            {
                                if(eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(dialog.text);
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 14, dialog.text);
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart (editTextCell2, false);

            var editTextCell4 = new CellRendererText ();
            editTextCell4.Editable = true;
            editTextCell4.EditingStarted += delegate {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {
                    
                    var col = new Microsoft.Xna.Framework.Color ();
                    int response = (int)ResponseType.Reject;

                    if(Global.GtkMajorVersion < 3 || (Global.GtkMajorVersion == 3 && Global.GtkMinorVersion < 3))
                    {
                        var dialog = new ColorSelectionDialog("Color Chooser");
                        dialog.TransientFor = window;
                        dialog.ColorSelection.HasPalette = true;
                        dialog.ColorSelection.HasOpacityControl = true;

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace (":", " ").Replace("}", " ").Split (' ');

                            byte red = (byte)Convert.ToInt16 (cvalues [1]);
                            byte green = (byte)Convert.ToInt16 (cvalues [3]);
                            byte blue = (byte)Convert.ToInt16 (cvalues [5]);
                            int alpha = Convert.ToInt32(cvalues [7]);

                            dialog.ColorSelection.CurrentColor = new Gdk.Color (red, green, blue);
                            dialog.ColorSelection.CurrentAlpha = (ushort)(alpha * 257);
                        }
                        catch { }

                        response = dialog.Run();

                        col.R = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Red);
                        col.G = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Green);
                        col.B = (byte)Convert.ToInt32(dialog.ColorSelection.CurrentColor.Blue);
                        col.A = (byte)(dialog.ColorSelection.CurrentAlpha / 257);

                        dialog.Destroy();
                    }
                    else
                    {
                        #if LINUX
                        Gdk.RGBA rgba = new Gdk.RGBA();

                        try
                        {
                            string[] cvalues = model.GetValue(iter, 15).ToString().Replace (":", " ").Replace("}", " ").Split (' ');
                            rgba.Parse("rgba(" + cvalues [1] + "," + cvalues [3] + "," + cvalues [5] + "," + cvalues [7] + ")");
                        }
                        catch { }

                        var dialog = new ColorChooserDialog(window, "Color Chooser");
                        dialog.ColorChooser.CurrentRgba = rgba;
                        response = (int)dialog.Run();

                        rgba = dialog.ColorChooser.CurrentRgba;
                        dialog.Destroy();

                        string[] split = rgba.ToString().Split('(', ')')[1].Split(',');

                        col.R = (byte)Convert.ToInt32(split[0]);
                        col.G = (byte)Convert.ToInt32(split[1]);
                        col.B = (byte)Convert.ToInt32(split[2]);

                        if(split.Length == 4)
                            col.A = (byte)Convert.ToInt32(double.Parse(split[3]) * 255);
                        else
                            col.A = 255;
                        #endif
                    }

                    if(response == (int)ResponseType.Ok)
                    {
                        int id = Convert.ToInt32(model.GetValue(iter, 11));

                        for(int i = 0;i < eitems.Count;i++)
                        {
                            if(eitems[i].id == id)
                            {
                                if(eitems[i].eventHandler != null)
                                {
                                    var fwidget = new FalseWidget(col.ToString ());
                                    eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                    model.SetValue(iter, 15, col.ToString ());
                                    break;
                                }
                            }
                        }
                    }
                }
            };
            column2.PackStart (editTextCell4, false);

            var editTextCell3 = new CellRendererText ();
            editTextCell3.Visible = false;
            column2.PackStart (editTextCell3, false);

            var comboCell = new CellRendererCombo ();
            comboCell.TextColumn = 0;
            comboCell.IsExpanded = true;
            comboCell.Editable = true;
            comboCell.HasEntry = false;
            comboCell.Edited += delegate(object o, EditedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id == id)
                        {
                            if(eitems[i].eventHandler != null && args.NewText != null && args.NewText != "")
                            {
                                var fwidget = new FalseWidget(args.NewText);
                                eitems[i].eventHandler(fwidget, EventArgs.Empty);
                                model.SetValue(iter, 8, args.NewText);
                                break;
                            }
                        }
                    }
                }
            };

            column2.PackStart (comboCell , false);

            var editFilePathCell = new CellRendererText();
            editFilePathCell.Editable = true;
            editFilePathCell.EditingStarted += delegate(object o, EditingStartedArgs args) {
                #if GTK2
                TreeModel model;
                #elif GTK3
                ITreeModel model;
                #endif
                TreeIter iter;

                if (treeview1.Selection.GetSelected (out model, out iter)) {

                    var dialog = new CustomFolderDialog(window, model.GetValue(iter, 17).ToString());
                    var responseid = dialog.Run();
                    var fileName = dialog.FileName;
                    dialog.Destroy();

                    if(responseid != (int)ResponseType.Ok)
                        return;

                    int id = Convert.ToInt32(model.GetValue(iter, 11));

                    for(int i = 0;i < eitems.Count;i++)
                    {
                        if(eitems[i].id != id || eitems[i].eventHandler == null)
                            continue;

                        var fwidget = new FalseWidget(fileName);
                        eitems[i].eventHandler(fwidget, EventArgs.Empty);
                        model.SetValue(iter, 17, fileName);

                        break;
                    }
                }
            };
            column2.PackStart (editFilePathCell, false);

            treeview1.AppendColumn (column2);

            column1.AddAttribute (textCell1, "text", 0);
            column1.AddAttribute (textCell1, "visible", 1);
            column1.AddAttribute (textCell2, "text", 2);
            column1.AddAttribute (textCell2, "visible", 3);
            column2.AddAttribute (editTextCell, "text", 4);
            column2.AddAttribute (editTextCell, "visible", 5);
            column2.AddAttribute (editTextCell, "editable", 6);
            column2.AddAttribute (comboCell, "model", 7);
            column2.AddAttribute (comboCell, "text", 8);
            column2.AddAttribute (comboCell, "editable", 9);
            column2.AddAttribute (comboCell, "visible", 10);
            column1.AddAttribute (idCell, "text", 11);
            column2.AddAttribute (editTextCell2, "text", 12);
            column2.AddAttribute (editTextCell2, "visible", 13);
            column2.AddAttribute (editTextCell3, "text", 14);
            column2.AddAttribute (editTextCell4, "text", 15);
            column2.AddAttribute (editTextCell4, "visible", 16);
            column2.AddAttribute (editFilePathCell, "text", 17);
            column2.AddAttribute (editFilePathCell, "visible", 18);

            listStore = new TreeStore (typeof (string), typeof(bool), typeof (string), typeof(bool), typeof (string), typeof(bool), typeof(bool), typeof(TreeStore), typeof(string), typeof(bool), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(bool));
            treeview1.Model = listStore;
        }
Esempio n. 32
0
 static void ReadNative(IntPtr native, ref Gdk.RGBA target)
 {
     target = New(native);
 }
Esempio n. 33
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);
        }