示例#1
0
        private void WriteEllipseAttributes(SvgEllipse svg, EllipseVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var rect = vObject.Rectangle;

            svg.Cx = rect.CenterX;
            svg.Cy = rect.CenterY;
            svg.Rx = rect.Width / 2;
            svg.Ry = rect.Height / 2;
            var m = new Matrix();

            m.RotateAt(rect.Angle, new System.Drawing.PointF(rect.CenterX, rect.CenterY));
            svg.Transform = m;

            svg.StrokeWidth = vObject.BorderWidth;

            var cm = vObject.GetColorManagement(true);

            svg.Stroke = ColorManagement.GetPreviewColor(cm, vObject.BorderColor);
            svg.CustomAttributes.Add(new SvgVoAttribute("border-color", _serializer.Serialize(vObject.BorderColor)));
            svg.Fill = ColorManagement.GetPreviewColor(cm, vObject.FillColor);
            svg.CustomAttributes.Add(new SvgVoAttribute("fill-color", _serializer.Serialize(vObject.FillColor)));

            if (vObject.FixedBorderWidth)
            {
                svg.CustomAttributes.Add(new SvgVoAttribute("fixed-border-width", vObject.FixedBorderWidth));
            }
        }
示例#2
0
        void HandleIconButtonClicked(object sender, EventArgs args)
        {
            var dialog = new EditTagIconDialog(db, tag, this);

            var response = (ResponseType)dialog.Run();

            if (response == ResponseType.Ok)
            {
                if (dialog.ThemeIconName != null)
                {
                    tag.ThemeIconName = dialog.ThemeIconName;
                }
                else
                {
                    tag.ThemeIconName = null;
                    tag.Icon          = dialog.PreviewPixbuf;
                }
            }
            else if (response == (ResponseType)1)
            {
                tag.Icon = null;
            }

            if (tag.Icon != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                icon_image.Pixbuf = tag.Icon.Copy();
                ColorManagement.ApplyProfile(icon_image.Pixbuf, screen_profile);
            }
            else
            {
                icon_image.Pixbuf = tag.Icon;
            }

            dialog.Destroy();
        }
示例#3
0
 protected override void ApplyColorTransform(Pixbuf pixbuf)
 {
     if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
     {
         ColorManagement.ApplyProfile(pixbuf, screen_profile);
     }
 }
示例#4
0
        public void DrawTags()
        {
            if (tags == null)
            {
                return;
            }

            SetSizeRequest((thumbnail_size + TAG_ICON_VSPACING) * tags.Length,
                           thumbnail_size);

            int tag_x = Allocation.X;
            int tag_y = Allocation.Y + (Allocation.Height - thumbnail_size) / 2;

            string[] names = new string[tags.Length];
            int      i     = 0;

            foreach (var t in tags)
            {
                names[i++] = t.Name;

                Pixbuf icon = t.Icon;

                var category = t.Category;
                while (icon == null && category != null)
                {
                    icon     = category.Icon;
                    category = category.Category;
                }

                if (icon == null)
                {
                    continue;
                }

                Pixbuf scaled_icon;
                if (icon.Width == thumbnail_size)
                {
                    scaled_icon = icon;
                }
                else
                {
                    scaled_icon = icon.ScaleSimple(thumbnail_size, thumbnail_size, InterpType.Bilinear);
                }
                if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                {
                    ColorManagement.ApplyProfile(scaled_icon, screen_profile);
                }

                scaled_icon.RenderToDrawable(GdkWindow, Style.WhiteGC,
                                             0, 0, tag_x, tag_y, thumbnail_size, thumbnail_size,
                                             RgbDither.None, tag_x, tag_y);
                tag_x += thumbnail_size + TAG_ICON_VSPACING;
            }

            TooltipText = string.Join(", ", names);
        }
示例#5
0
        private void WriteSvgAttributes(SvgVoSvg svg, SvgVObject vObject)
        {
            WriteRectangleAttributes(svg, vObject);

            svg.Svg = vObject.Svg;

            var cm = vObject.GetColorManagement(true);

            svg.SetStrokeColor(vObject.StrokeColor, ColorManagement.GetPreviewColor(cm, vObject.StrokeColor), _serializer);
        }
        public static string AddFile(this IFileStorage storage, string extension, Stream fileData, bool fixColorProfile)
        {
            if (!fixColorProfile || fileData == null)
            {
                return(storage.AddFile(extension, fileData));
            }

            var fixedFilePath = ColorManagement.FixColorProfile(fileData);

            return(fixedFilePath == null?storage.AddFile(extension, fileData) : AddFixedFile(storage, fixedFilePath));
        }
        public static string AddFile(this IFileStorage storage, string filePath, bool fixColorProfile)
        {
            if (!fixColorProfile || filePath == null)
            {
                return(storage.AddFile(filePath));
            }

            var fixedFilePath = ColorManagement.FixColorProfile(filePath);

            return(fixedFilePath == null?storage.AddFile(filePath) : AddFixedFile(storage, fixedFilePath));
        }
示例#8
0
        private void WriteDashLineAttributes(SvgVoDashLine svg, DashedLineVObject vObject)
        {
            WriteLineAttributes(svg, vObject);

            var cm = vObject.GetColorManagement(true);

            svg.SetAltColor(vObject.AltColor, ColorManagement.GetPreviewColor(cm, vObject.AltColor), _serializer);

            svg.AltDashWidth = vObject.AltDashWidth;
            svg.DashWidth    = vObject.DashWidth;
        }
示例#9
0
        public Task ColorAsync(string color)
        {
            var color_response = ColorManagement.GetColor(color);

            var p = PartnerService.GetPartnerInfo(Context.Guild.Id, true);

            p.Message.Color = new PartnerService.PartnerInfo.PartnerMessage.RGB {
                R = color_response.R, G = color_response.G, B = color_response.B
            };
            p.Save();
            return(ReplyAsync(PartnerHelp.GenerateMessage(p, Context.Guild)));
        }
示例#10
0
        /// <summary>
        /// Gets a specific color related to the current workspace.
        /// </summary>
        /// <param name="what">Type of the color to be returned.</param>
        /// <returns>The desired color.</returns>
        public Color GetWorkspaceColor(Colors what)
        {
            EnsureWorkspaceHasColor( );             // Assing the color, if needeed

            // Read the base color (or take the default for Default workspace)
            Color colorBase = _workspace != null?Color.FromArgb(_workspace.GetIntProp(((WorkspaceManager)Core.WorkspaceManager).Props.WorkspaceColor)) : SystemColors.Control;

            if (what == Colors.Base)
            {
                return(colorBase);                // The base workspace color, as is
            }
            // Get the HLS components
            byte bH, bL, bS;

            ColorManagement.RGBtoHLS(ColorManagement.RGB(colorBase), out bH, out bL, out bS);
            double H = bH;
            double L = bL;
            double S = bS;

            // Produce the color appropriate
            switch (what)
            {
            case Colors.Light:
                L += 27.0 * 1.5;
                S -= 43.0 * 1.5;
                break;

            case Colors.Dark:
                L -= 16.0 * 2.0;
                S -= 8.0 * 2.0;
                break;

            case Colors.Shadow:
                L -= 8.0 * 2.0;
                S -= 75.0 * 2.0;
                break;

            default:
                throw new InvalidOperationException("Unsupported workspace color type.");
            }

            // Constraint
            bH = (byte)(H >= 0 ? (H <= ColorManagement.MaxHLS - 1 ? H : ColorManagement.MaxHLS - 1) : 0);
            bL = (byte)(L >= 0 ? (L <= ColorManagement.MaxHLS - 1 ? L : ColorManagement.MaxHLS - 1) : 0);
            bS = (byte)(S >= 0 ? (S <= ColorManagement.MaxHLS - 1 ? S : ColorManagement.MaxHLS - 1) : 0);

            // Produce the color
            return(ColorManagement.HLStoRGB(bH, bL, bS));
        }
示例#11
0
        void LoadNext()
        {
            if (next != null)
            {
                next = null;
            }

            if (item == null || item.Current == null)
            {
                return;
            }

            using (var img = App.Instance.Container.Resolve <IImageFileFactory>().Create(item.Current.DefaultVersion.Uri))
            {
                try
                {
                    using (var pb = img.Load())
                    {
                        double scale = Math.Min((double)Allocation.Width / (double)pb.Width, (double)Allocation.Height / (double)pb.Height);
                        int    w     = (int)(pb.Width * scale);
                        int    h     = (int)(pb.Height * scale);

                        //if (w > 0 && h > 0)
                        //	next = pb.ScaleSimple ((int)(pb.Width * scale), (int)(pb.Height * scale), InterpType.Bilinear);
                    }
                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string>(Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                    {
                        ColorManagement.ApplyProfile(next, screen_profile);
                    }
                    loadRetries = 0;
                }
                catch (Exception)
                {
                    next = PixbufUtils.ErrorPixbuf;
                    if (++loadRetries < 10)
                    {
                        item.MoveNext(true);
                    }
                    else
                    {
                        loadRetries = 0;
                    }
                }
            }
        }
示例#12
0
        private void WritePolylineAttributes(SvgPolyline svg, PolylineVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var points = svg.Points;

            foreach (var p in vObject.GetPoints())
            {
                points.Add(p.ToPoint());
            }

            var cm = vObject.GetColorManagement(true);

            svg.Stroke = ColorManagement.GetPreviewColor(cm, vObject.Color);
            svg.CustomAttributes.Add(new SvgVoAttribute("color", _serializer.Serialize(vObject.Color)));

            svg.StrokeWidth = vObject.Width;
            svg.Fill        = RgbColor.Transparent;
        }
示例#13
0
        private void WriteTextAttributes(SvgVoText svg, BaseTextVObject vObject)
        {
            WriteContentAttributes(svg, vObject);

            var cm = vObject.GetColorManagement(true);

            svg.SetTextColor(vObject.TextColor, ColorManagement.GetPreviewColor(cm, vObject.TextColor), _serializer);

            svg.Text = vObject.Text;

            svg.Font = new FontSettings(vObject.Font);

            svg.Underline       = vObject.Underline;
            svg.Alignment       = vObject.Alignment;
            svg.Tracking        = vObject.Tracking;
            svg.Leading         = vObject.Leading;
            svg.IsRichText      = vObject.IsRichText;
            svg.VerticalScale   = vObject.VerticalScale;
            svg.HorizontalScale = vObject.HorizontalScale;
        }
示例#14
0
        private void WriteLineAttributes(SvgLine svg, LineVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var cm = vObject.GetColorManagement(true);

            svg.Stroke = ColorManagement.GetPreviewColor(cm, vObject.Color);
            svg.CustomAttributes.Add(new SvgVoAttribute("color", _serializer.Serialize(vObject.Color)));

            svg.StrokeWidth = vObject.Width;
            svg.X1          = vObject.Point0.X;
            svg.Y1          = vObject.Point0.Y;
            svg.X2          = vObject.Point1.X;
            svg.Y2          = vObject.Point1.Y;

            if (vObject.FixedWidth)
            {
                svg.CustomAttributes.Add(new SvgVoAttribute("fixed-width", vObject.FixedWidth));
            }
        }
示例#15
0
        /// <summary>
        /// Checks whether the given workspace has a color assigned to it, and, if no, generates a random one.
        /// For the <c>Null</c> Default workspace, does nothing.
        /// </summary>
        public void EnsureWorkspaceHasColor( )
        {
            if (_workspace == null)
            {
                return;                                                    // No checks for the default workspace
            }
            WorkspaceManager wm = (WorkspaceManager)Core.WorkspaceManager; // Provides IDs of workspace resource properties

            if (_workspace.HasProp(wm.Props.WorkspaceColor))
            {
                return;                 // Assigned already, do nothing
            }
            // No, the workspace does not have a color yet
            // Choose one based on its title
            byte  hue   = (byte)new Random(_workspace.DisplayName.GetHashCode()).Next(ColorManagement.MaxHLS);
            Color color = ColorManagement.HLStoRGB(hue, DefaultWorkspaceLuminocity, DefaultWorkspaceSaturation);

            // Apply the property synchronously so that it would be valid as we exit the method
            new ResourceProxy(_workspace).SetProp(wm.Props.WorkspaceColor, color.ToArgb());
        }
示例#16
0
#pragma warning restore 649

        public EditTagDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagDialog.ui", "edit_tag_dialog")
        {
            this.db      = db;
            tag          = t;
            TransientFor = parent_window;

            orig_name           = TagName = t.Name;
            tag_name_entry.Text = t.Name;

            icon_image.Pixbuf = t.Icon;
            if (icon_image.Pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                icon_image.Pixbuf = icon_image.Pixbuf.Copy();
                ColorManagement.ApplyProfile(icon_image.Pixbuf, screen_profile);
            }
            PopulateCategoryOptionMenu(t);

            tag_name_entry.GrabFocus();

            category_option_menu.Changed += HandleTagNameEntryChanged;
        }
示例#17
0
        private void WriteShapeAttributes(SvgVoShape svg, ShapeVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var rect = vObject.Rectangle;

            vObject.Angle = 0;
            svg.Path      = vObject.GetTransformedPath().ToPathCommands();
            vObject.Angle = rect.Angle;

            var m = new Matrix();

            m.RotateAt(rect.Angle, new System.Drawing.PointF(rect.CenterX, rect.CenterY));
            svg.Transform = m;

            var cm = vObject.GetColorManagement(true);

            svg.SetFillColor(vObject.FillColor, ColorManagement.GetPreviewColor(cm, vObject.FillColor), _serializer);
            svg.SetBorderColor(vObject.BorderColor, ColorManagement.GetPreviewColor(cm, vObject.BorderColor), _serializer);
            svg.StrokeWidth      = vObject.BorderWidth;
            svg.FixedBorderWidth = vObject.FixedBorderWidth;
        }
示例#18
0
        private void WriteGridAttributes(SvgVoGrid svg, GridVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var cm = vObject.GetColorManagement(true);

            svg.SetVerticalLineColor(vObject.VerticalLineColor, ColorManagement.GetPreviewColor(cm, vObject.VerticalLineColor), _serializer);
            svg.SetHorizontalLineColor(vObject.HorizontalLineColor, ColorManagement.GetPreviewColor(cm, vObject.HorizontalLineColor), _serializer);

            svg.StrokeWidth = vObject.LineWidth;

            svg.Cols  = vObject.Cols;
            svg.Rows  = vObject.Rows;
            svg.StepX = vObject.StepX;
            svg.StepY = vObject.StepY;

            var rect = vObject.Rectangle.ToRectangleF();

            svg.X = rect.X;
            svg.Y = rect.Y;
            svg.FixedStrokeWidth = vObject.FixedLineWidth;
        }
示例#19
0
        private void WriteRectangleAttributes(SvgVoRectangle svg, RectangleVObject vObject)
        {
            WriteBaseRectangleVObjectAttributes(svg, vObject);

            var rect = vObject.Rectangle;

            svg.X      = rect.CenterX - rect.Width / 2;
            svg.Y      = rect.CenterY - rect.Height / 2;
            svg.Width  = rect.Width;
            svg.Height = rect.Height;
            var m = new Matrix();

            m.RotateAt(rect.Angle, new System.Drawing.PointF(rect.CenterX, rect.CenterY));
            svg.Transform = m;

            var cm = vObject.GetColorManagement(true);

            svg.SetFillColor(vObject.FillColor, ColorManagement.GetPreviewColor(cm, vObject.FillColor), _serializer);
            svg.SetBorderColor(vObject.BorderColor, ColorManagement.GetPreviewColor(cm, vObject.BorderColor), _serializer);
            svg.StrokeWidth      = vObject.BorderWidth;
            svg.FixedBorderWidth = vObject.FixedBorderWidth;
        }
示例#20
0
        // FIXME Cache the GCs?
        protected virtual void DrawPhoto(int cell_num, Rectangle cell_area, Rectangle expose_area, bool selected, bool focussed)
        {
            if (!cell_area.Intersect(expose_area, out expose_area))
            {
                return;
            }

            IPhoto photo = Collection [cell_num];

            PixbufCache.CacheEntry entry = Cache.Lookup(photo.DefaultVersion.Uri);
            if (entry == null)
            {
                Cache.Request(photo.DefaultVersion.Uri, cell_num, ThumbnailWidth, ThumbnailHeight);
            }
            else
            {
                entry.Data = cell_num;
            }

            StateType cell_state = selected ? (HasFocus ? StateType.Selected : StateType.Active) : State;

            if (cell_state != State)
            {
                Style.PaintBox(Style, BinWindow, cell_state,
                               ShadowType.Out, expose_area, this, "IconView",
                               cell_area.X, cell_area.Y,
                               cell_area.Width - 1, cell_area.Height - 1);
            }

            var focus = Rectangle.Inflate(cell_area, -3, -3);

            if (HasFocus && focussed)
            {
                Style.PaintFocus(Style, BinWindow,
                                 cell_state, expose_area,
                                 this, null,
                                 focus.X, focus.Y,
                                 focus.Width, focus.Height);
            }

            var region       = Rectangle.Zero;
            var image_bounds = Rectangle.Inflate(cell_area, -CELL_BORDER_WIDTH, -CELL_BORDER_WIDTH);
            int expansion    = ThrobExpansion(cell_num, selected);

            Pixbuf thumbnail = null;

            if (entry != null)
            {
                thumbnail = entry.ShallowCopyPixbuf();
            }

            var draw = Rectangle.Zero;

            if (Rectangle.Inflate(image_bounds, expansion + 1, expansion + 1).Intersect(expose_area, out image_bounds) && thumbnail != null)
            {
                PixbufUtils.Fit(thumbnail, ThumbnailWidth, ThumbnailHeight,
                                true, out region.Width, out region.Height);

                region.X = (int)(cell_area.X + (cell_area.Width - region.Width) / 2);
                region.Y = (int)cell_area.Y + ThumbnailHeight - region.Height + CELL_BORDER_WIDTH;

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    Cache.Reload(entry, cell_num, thumbnail.Width, thumbnail.Height);
                }

                region = Rectangle.Inflate(region, expansion, expansion);
                Pixbuf temp_thumbnail;
                region.Width  = Math.Max(1, region.Width);
                region.Height = Math.Max(1, region.Height);

                if (Math.Abs(region.Width - thumbnail.Width) > 1 &&
                    Math.Abs(region.Height - thumbnail.Height) > 1)
                {
                    if (region.Width < thumbnail.Width && region.Height < thumbnail.Height)
                    {
                        /*
                         * temp_thumbnail = PixbufUtils.ScaleDown (thumbnail,
                         *      region.Width, region.Height);
                         */
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);


                        lock (entry) {
                            if (entry.Reload && expansion == 0 && !entry.IsDisposed)
                            {
                                entry.SetPixbufExtended(temp_thumbnail.ShallowCopy(), false);
                                entry.Reload = true;
                            }
                        }
                    }
                    else
                    {
                        temp_thumbnail = thumbnail.ScaleSimple(region.Width, region.Height,
                                                               InterpType.Bilinear);
                    }
                }
                else
                {
                    temp_thumbnail = thumbnail;
                }

                // FIXME There seems to be a rounding issue between the
                // scaled thumbnail sizes, we avoid this for now by using
                // the actual thumnail sizes here.
                region.Width  = temp_thumbnail.Width;
                region.Height = temp_thumbnail.Height;

                draw = Rectangle.Inflate(region, 1, 1);

                if (!temp_thumbnail.HasAlpha)
                {
                    Style.PaintShadow(Style, BinWindow, cell_state,
                                      ShadowType.Out, expose_area, this,
                                      "IconView",
                                      draw.X, draw.Y,
                                      draw.Width, draw.Height);
                }

                if (region.Intersect(expose_area, out draw))
                {
                    Cms.Profile screen_profile;
                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
                    {
                        Pixbuf t = temp_thumbnail.Copy();
                        temp_thumbnail.Dispose();
                        temp_thumbnail = t;
                        ColorManagement.ApplyProfile(temp_thumbnail, screen_profile);
                    }
                    temp_thumbnail.RenderToDrawable(BinWindow, Style.WhiteGC,
                                                    draw.X - region.X,
                                                    draw.Y - region.Y,
                                                    draw.X, draw.Y,
                                                    draw.Width, draw.Height,
                                                    RgbDither.None,
                                                    draw.X, draw.Y);
                }

                if (temp_thumbnail != thumbnail)
                {
                    temp_thumbnail.Dispose();
                }
            }

            if (thumbnail != null)
            {
                thumbnail.Dispose();
            }

            // Render Decorations
            if (DisplayRatings && region.X == draw.X && region.X != 0)
            {
                rating_renderer.Render(BinWindow, this, region, expose_area, cell_state, photo);
            }

            // Render Captions
            Rectangle caption_area = Rectangle.Zero;

            caption_area.Y     = cell_area.Y + CELL_BORDER_WIDTH + ThumbnailHeight + CAPTION_PADDING;
            caption_area.X     = cell_area.X + CELL_BORDER_WIDTH;
            caption_area.Width = cell_area.Width - 2 * CELL_BORDER_WIDTH;

            if (DisplayDates)
            {
                caption_area.Height = date_renderer.GetHeight(this, ThumbnailWidth);
                date_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayFilenames)
            {
                caption_area.Height = filename_renderer.GetHeight(this, ThumbnailWidth);
                filename_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }

            if (DisplayTags)
            {
                caption_area.Height = tag_renderer.GetHeight(this, ThumbnailWidth);
                tag_renderer.Render(BinWindow, this, caption_area, expose_area, cell_state, photo);

                caption_area.Y += caption_area.Height;
            }
        }
示例#21
0
        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = String.Format(Catalog.GetString("Edit Icon for Tag {0}"), t.Name);

            preview_pixbuf = t.Icon;
            Cms.Profile screen_profile;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new [] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Catalog.GetString("Select Photo from file"),
                                                               Gtk.FileChooserAction.Open);

            external_photo_chooser.Filter = new FileFilter();
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = (double)query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup = String.Format(Catalog.GetString(
                                                            "\n<b>From Photo</b>\n" +
                                                            " You can use one of your library photos as an icon for this tag.\n" +
                                                            " However, first you must have at least one photo associated\n" +
                                                            " with this tag. Please tag a photo as '{0}' and return here\n" +
                                                            " to use it as an icon."), t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store);
            icon_view.PixbufColumn      = 1;
            icon_view.SelectionMode     = SelectionMode.Single;
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            DelayedOperation fill_delay = new DelayedOperation(FillIconView);

            fill_delay.Start();
        }
示例#22
0
#pragma warning restore 649

        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = Strings.EditIconForTagName(t.Name);

            // FIXME, Icon
            //preview_pixbuf = t.Icon;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new[] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Strings.SelectPhotoFromFile, Gtk.FileChooserAction.Open)
            {
                Filter = new FileFilter()
            };
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup       = string.Format($"\n<b>{Strings.FromPhoto}</b>\n{Strings.TagFromPhotoLabelMessage}", t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store)
            {
                PixbufColumn  = 1,
                SelectionMode = SelectionMode.Single
            };
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            //var fill_delay = new DelayedOperation (FillIconView);
            //fill_delay.Start ();
        }
        public override void Render(Drawable window, Widget widget, Rectangle cell_area, Rectangle expose_area, StateType cell_state, IPhoto photo)
        {
            Tag[]     tags = photo.Tags;
            Rectangle tag_bounds;

            tag_bounds.X      = cell_area.X + (cell_area.Width + tag_icon_hspacing - tags.Length * (tag_icon_size + tag_icon_hspacing)) / 2;
            tag_bounds.Y      = cell_area.Y;       // + cell_area.Height - cell_border_width - tag_icon_size + tag_icon_vspacing;
            tag_bounds.Width  = tag_icon_size;
            tag_bounds.Height = tag_icon_size;


            foreach (var t in tags)
            {
                if (t == null)
                {
                    continue;
                }

                Pixbuf icon = t.Icon;

                Tag tag_iter = t.Category;
                while (icon == null && tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null)
                {
                    icon     = tag_iter.Icon;
                    tag_iter = tag_iter.Category;
                }

                if (icon == null)
                {
                    continue;
                }

                if (tag_bounds.Intersect(expose_area, out var region))
                {
                    Pixbuf scaled_icon;
                    if (icon.Width == tag_bounds.Width)
                    {
                        scaled_icon = icon;
                    }
                    else
                    {
                        scaled_icon = icon.ScaleSimple(tag_bounds.Width,
                                                       tag_bounds.Height,
                                                       InterpType.Bilinear);
                    }

                    if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
                    {
                        ColorManagement.ApplyProfile(scaled_icon, screen_profile);
                    }

                    scaled_icon.RenderToDrawable(window, widget.Style.WhiteGC, region.X - tag_bounds.X, region.Y - tag_bounds.Y,
                                                 region.X, region.Y, region.Width, region.Height, RgbDither.None, region.X, region.Y);

                    if (scaled_icon != icon)
                    {
                        scaled_icon.Dispose();
                    }
                }

                tag_bounds.X += tag_bounds.Width + tag_icon_hspacing;
            }
        }
示例#24
0
        protected virtual Pixbuf GetPixbuf(int i, bool highlighted)
        {
            Pixbuf  current = null;
            SafeUri uri     = (selection.Collection [i]).DefaultVersion.Uri;

            try {
                var pixbuf = thumb_cache.Get(uri);
                if (pixbuf != null)
                {
                    current = pixbuf.ShallowCopy();
                }
            } catch (IndexOutOfRangeException) {
                current = null;
            }

            if (current == null)
            {
                var pixbuf = XdgThumbnailSpec.LoadThumbnail(uri, ThumbnailSize.Large, null);
                if (pixbuf == null)
                {
                    ThumbnailLoader.Default.Request(uri, ThumbnailSize.Large, 0);
                    current = FSpot.Core.Global.IconTheme.LoadIcon("gtk-missing-image", ThumbSize, (IconLookupFlags)0);
                }
                else
                {
                    if (SquaredThumbs)
                    {
                        current = PixbufUtils.IconFromPixbuf(pixbuf, ThumbSize);
                    }
                    else
                    {
                        current = pixbuf.ScaleSimple(ThumbSize, ThumbSize, InterpType.Nearest);
                    }
                    pixbuf.Dispose();
                    thumb_cache.Add(uri, current);
                }
            }

            //FIXME: we might end up leaking a pixbuf here
            Cms.Profile screen_profile;
            if (ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                Pixbuf t = current.Copy();
                current = t;
                ColorManagement.ApplyProfile(current, screen_profile);
            }

            // Add a four pixel white border around the thumbnail
            // for some reason we cannot use "using" here, it looks like the pixbuf copy is not done properly
            Pixbuf whiteBorder = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            whiteBorder.Fill(0);
            current.CopyArea(1, 1, current.Width - 8, current.Height - 8, whiteBorder, 4, 4);
            current = whiteBorder;

            if (!highlighted)
            {
                return(current);
            }

            Pixbuf highlight = new Pixbuf(Colorspace.Rgb, true, 8, current.Width, current.Height);

            highlight.Fill(ColorToInt(Style.Light(StateType.Selected)));

            // Add a two pixel highlight around the thumbnail
            current.CopyArea(2, 2, current.Width - 4, current.Height - 4, highlight, 2, 2);

            return(highlight);
        }