public static void DrawImage(this SKCanvas canvas, SKImage image, SKRect dest,
                                     ImageStretch stretch,
                                     ImageAlignment horizontal = ImageAlignment.Center,
                                     ImageAlignment vertical   = ImageAlignment.Center,
                                     SKPaint paint             = null)
        {
            if (stretch == ImageStretch.Fill)
            {
                canvas.DrawImage(image, dest, paint);
            }
            else
            {
                float scale = 1;
                switch (stretch)
                {
                case ImageStretch.None:
                    break;

                case ImageStretch.Uniform:
                    scale = Math.Min(dest.Width / image.Width, dest.Height / image.Height);
                    break;

                case ImageStretch.UniformToFill:
                    scale = Math.Max(dest.Width / image.Width, dest.Height / image.Height);
                    break;
                }

                SKRect display = CalculateDisplayRect(dest, scale * image.Width, scale * image.Height, horizontal, vertical);
                canvas.DrawImage(image, display, paint);
            }
        }
Example #2
0
        public PlottableImage PlotBitmap(
            Bitmap bitmap,
            double x,
            double y,
            string label             = null,
            ImageAlignment alignment = ImageAlignment.middleLeft,
            double rotation          = 0,
            Color?frameColor         = null,
            int frameSize            = 0
            )
        {
            PlottableImage plottableImage = new PlottableImage()
            {
                image      = bitmap,
                x          = x,
                y          = y,
                label      = label,
                alignment  = alignment,
                rotation   = rotation,
                frameColor = frameColor ?? Color.White,
                frameSize  = frameSize
            };

            settings.plottables.Add(plottableImage);
            return(plottableImage);
        }
Example #3
0
        /// <summary>
        /// Draw related icon if any.
        /// </summary>
        public void DrawIcon()
        {
            ImageAlignment alignment = Item.ImageAlignment == ItemImageAlignment.Inherit
                                           ? Bar.ImageAlignment
                                           : ((ImageAlignment)((int)Item.ImageAlignment));
            var b        = new Rectangle(Bounds.Location, Bounds.Size);
            var iconSize = Size.Empty;

            if (Bar.ImageList != null && Item.ImageIndex >= 0 && Item.ImageIndex < Bar.ImageList.Images.Count)
            {
                iconSize = Bar.ImageList.ImageSize;
            }
            b.Inflate(-2, -2);
            var iconRect = new Rectangle(0, 0,
                                         iconSize.Width, iconSize.Height);

            if (alignment == ImageAlignment.Top || alignment == ImageAlignment.Bottom)
            {
                iconRect.X = b.X + (b.Width - iconSize.Width) / 2;
            }
            else if (alignment == ImageAlignment.Left)
            {
                iconRect.X = b.X;
            }
            else
            {
                iconRect.X = b.X + b.Width - iconSize.Width;
            }

            if (alignment == ImageAlignment.Top)
            {
                iconRect.Y = b.Y;
            }
            else if (alignment == ImageAlignment.Bottom)
            {
                iconRect.Y = b.Y + b.Height - iconSize.Height;
            }
            else if (alignment == ImageAlignment.Right || alignment == ImageAlignment.Left)
            {
                iconRect.Y = b.Y + (b.Height - iconSize.Height) / 2;
            }

            if (State == State.Pressed)
            {
                iconRect.Offset(1, 1);
            }
            if (Bar.ImageList != null && Item.ImageIndex >= 0 && Item.ImageIndex < Bar.ImageList.Images.Count)
            {
                if (Item.Enabled)
                {
                    Graphics.DrawImage(Bar.ImageList.Images[Item.ImageIndex], iconRect.X, iconRect.Y);
                }
                else
                {
                    ControlPaint.DrawImageDisabled(Graphics, Bar.ImageList.Images[Item.ImageIndex], iconRect.X,
                                                   iconRect.Y, Bar.BackColor);
                }
            }
        }
        public void AddVariant(DeviceRequirement requirement, string path, ImageAlignment alignment, ImageResizing resizing)
        {
            var imageset = new ImageSetVariant(requirement, path);

            imageset.alignment = alignment;
            imageset.resizing  = resizing;
            AddVariant(imageset);
        }
Example #5
0
        public ArtImageControl()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);

            hueIndex = 24;
            imageAlignment = ImageAlignment.Center;
        }
Example #6
0
        public ArtImageControlExt()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);

            hueIndex       = 24;
            imageAlignment = ImageAlignment.Center;
        }
        void WriteAlignmentToJson(JsonElementDict item, ImageAlignment alignment)
        {
            var docAlignment = item.CreateDict("alignment-insets");

            docAlignment.SetInteger("top", alignment.top);
            docAlignment.SetInteger("bottom", alignment.bottom);
            docAlignment.SetInteger("left", alignment.left);
            docAlignment.SetInteger("right", alignment.right);
        }
Example #8
0
        public override int Run(Terminal.Terminal config)
        {
            var defaultProfile = config.Settings["profiles"]["defaults"] as JObject;

            if (!string.IsNullOrEmpty(Image))
            {
                if (!CheckURLValid(Image))
                {
                    defaultProfile["backgroundImage"] = Image;
                }
                else
                {
                    Console.WriteLine($"Downloading Image: {Image}");
                    using var wc = new WebClient();
                    var fileName = System.IO.Path.GetFileName(Image);
                    wc.DownloadFile(Image, System.IO.Path.Combine(wt_tool.Program.ApplicationCache, fileName));

                    defaultProfile["backgroundImage"] = System.IO.Path.Combine(wt_tool.Program.ApplicationCache, fileName);
                }
            }

            if (ImageAlignment != null)
            {
                defaultProfile["backgroundImageAlignment"] = ImageAlignment.ToString();
            }

            if (ImageStrechMode != null)
            {
                defaultProfile["backgroundImageStretchMode"] = ImageStrechMode.ToString();
            }

            if (ImageOpacity != null)
            {
                var op = ImageOpacity;

                if (op > 1.0)
                {
                    op = 1.0f;
                }
                if (op < 0.0)
                {
                    op = 0.0f;
                }

                defaultProfile["backgroundImageOpacity"] = op;
            }

            if (BackgroundColor != null && CheckValidFormatHtmlColor(BackgroundColor))
            {
                defaultProfile["background"] = BackgroundColor;
            }

            config.Save();

            return(1);
        }
Example #9
0
        public void ImageSetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                testFiles.CreateFile("data1.png", "img1"));

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                testFiles.CreateFile("data2.png", "img2"));

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X1),
                                testFiles.CreateFile("data3.png", "img3"));

            var alignment = new ImageAlignment();

            alignment.top    = 1;
            alignment.bottom = 2;
            alignment.left   = 3;
            alignment.right  = 4;

            var resizing = new ImageResizing();

            resizing.type             = ImageResizing.SlicingType.HorizontalAndVertical;
            resizing.top              = 1;
            resizing.bottom           = 2;
            resizing.left             = 3;
            resizing.right            = 4;
            resizing.centerResizeMode = ImageResizing.ResizeMode.Stretch;
            resizing.centerWidth      = 2;
            resizing.centerHeight     = 4;

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X3),
                                testFiles.CreateFile("data4.png", "img4"), alignment, resizing);
            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data2.png"), "img2");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data3.png"), "img3");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data4.png"), "img4");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Example #10
0
 protected ShowImageAction(LoadInfo info)
     : base(info)
 {
     imageFile       = info.GetString(IMAGE_FILE, imageFile);
     position        = info.GetValue <Vector2>(POSITION);
     size            = info.GetValue <Size2>(SIZE);
     keepAspectRatio = info.GetValue(KEEP_ASPECT_RATIO, keepAspectRatio);
     CameraName      = info.GetValue(CAMERA_NAME, CameraName);
     alignment       = info.GetValue <ImageAlignment>(IMAGE_ALIGNMENT, ImageAlignment.Specify);
 }
Example #11
0
 public GeneralShadingDesc(GeneralShadingDesc toClone)
 {
     this.antiAliasing          = toClone.antiAliasing;
     this.wireframe             = toClone.wireframe;
     this.bgColor               = toClone.bgColor;
     this.bgImg                 = toClone.bgImg;
     this.bgImgSize             = toClone.bgImgSize;
     this.shadingMode           = toClone.shadingMode;
     this.backgroundImgFilename = toClone.backgroundImgFilename;
     this.backgroundImgAlign    = toClone.backgroundImgAlign;
 }
 public GeneralShadingDesc(GeneralShadingDesc toClone)
 {
     this.antiAliasing = toClone.antiAliasing;
     this.wireframe = toClone.wireframe;
     this.bgColor = toClone.bgColor;
     this.bgImg = toClone.bgImg;
     this.bgImgSize = toClone.bgImgSize;
     this.shadingMode = toClone.shadingMode;
     this.backgroundImgFilename = toClone.backgroundImgFilename;
     this.backgroundImgAlign = toClone.backgroundImgAlign;
 }
Example #13
0
        private void UpdateStretchCenter()
        {
            ImageAlignment align = this.ImageAlignment;

            switch (align)
            {
            case ImageAlignment.Center:
                display.HorizontalAlignment = HorizontalAlignment.Center;
                display.VerticalAlignment   = VerticalAlignment.Center;
                break;

            case ImageAlignment.Stretch:
                display.HorizontalAlignment = HorizontalAlignment.Stretch;
                display.VerticalAlignment   = VerticalAlignment.Stretch;
                break;

            case ImageAlignment.TopRight:
                display.HorizontalAlignment = HorizontalAlignment.Right;
                display.VerticalAlignment   = VerticalAlignment.Top;
                break;

            case ImageAlignment.BottomRight:
                display.HorizontalAlignment = HorizontalAlignment.Right;
                display.VerticalAlignment   = VerticalAlignment.Bottom;
                break;

            case ImageAlignment.BottomLeft:
                display.HorizontalAlignment = HorizontalAlignment.Left;
                display.VerticalAlignment   = VerticalAlignment.Bottom;
                break;

            case ImageAlignment.TopLeft:
            case ImageAlignment.Default:
            default:
                display.HorizontalAlignment = HorizontalAlignment.Left;
                display.VerticalAlignment   = VerticalAlignment.Top;
                break;
            }

            UpdateFlip();

            bool stretch = this.ImageAlignment == ImageAlignment.Stretch;

            scrollView.HorizontalScrollBarVisibility = stretch ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Auto;
            scrollView.VerticalScrollBarVisibility   = stretch ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Auto;
        }
Example #14
0
 public GeniusTreeViewColonne(GeniusHeader aOwner) : base()
 {
     //Valeur par défaut
     FWidth           = 75;
     FAlignment       = StringAlignment.Center;
     FVAlignment      = StringAlignment.Center;
     FTextAlignment   = StringAlignment.Near;
     FVisible         = true;
     FSizable         = true;
     FDraggable       = true;
     FAllowClick      = true;
     FAllowEdit       = true;
     FOwner           = aOwner;
     FFont            = null;
     FFontColonne     = null;
     FImageIndex      = -1;
     FTextOrientation = 0.0f;
     FImageAlignment  = ImageAlignment.Left;
 }
Example #15
0
        static SKRect CalculateDisplayRect(SKRect dest, float imageWidth, float imageHeight,
                                           ImageAlignment horizontal, ImageAlignment vertical)
        {
            float x = 0;
            float y = 0;

            switch (horizontal)
            {
            case ImageAlignment.Center:
                x = (dest.Width - imageWidth) / 2;
                break;

            case ImageAlignment.Start:
                break;

            case ImageAlignment.End:
                x = dest.Width - imageWidth;
                break;
            }

            switch (vertical)
            {
            case ImageAlignment.Center:
                y = (dest.Height - imageHeight) / 2;
                break;

            case ImageAlignment.Start:
                break;

            case ImageAlignment.End:
                x = dest.Height - imageHeight;
                break;
            }

            x += dest.Left;
            y += dest.Top;
            return(new SKRect(x, y, x + imageWidth, y + imageHeight));
        }
Example #16
0
 public ImageAlignmentChange(MapNode node, ImageAlignment oldValue)
 {
     this.node = node;
     this.oldValue = oldValue;
 }
Example #17
0
 public ImageAlignmentChange(MapNode node, ImageAlignment oldValue)
 {
     this.node     = node;
     this.oldValue = oldValue;
 }
Example #18
0
 public static string ToRQLString(this ImageAlignment align)
 {
     return(align == ImageAlignment.NotSet ? "" : align.ToString());
 }
Example #19
0
 public ShowImageAction()
 {
     size      = new Size2(0.2f, 0.2f);
     position  = new Vector2(0.0f, 0.0f);
     alignment = ImageAlignment.Specify;
 }
Example #20
0
        public static void DrawImage(object sender, PaintEventArgs e, Image image, ImageAlignment alignment, bool adaptImage)
        {
            UserControl control = (UserControl)sender;
            int
                x             = 0,
                y             = 0,
                controlHeight = control.Height,
                controlWidth  = control.Width,
                imageHeight   = image.Height,
                imageWidth    = image.Width;

            float aspectRatio = (float)image.Width / image.Height;

            Size adaptedSize = new Size(imageWidth, imageHeight);

            if (adaptImage)
            {
                adaptedSize = AdaptImage(image, new Size(controlWidth, controlHeight));
                imageWidth  = adaptedSize.Width;
                imageHeight = adaptedSize.Height;
            }

            switch (alignment)
            {
            case ImageAlignment.BottomLeft:
                x = 0;
                y = controlHeight - imageHeight;
                break;

            case ImageAlignment.BottomCenter:
                x = (controlWidth / 2) - (imageWidth / 2);
                y = controlHeight - imageHeight;
                break;

            case ImageAlignment.BottomRight:
                x = controlWidth - imageWidth;
                y = controlHeight - imageHeight;
                break;

            case ImageAlignment.MiddleLeft:
                x = 0;
                y = (controlHeight / 2) - (imageHeight / 2);
                break;

            case ImageAlignment.MiddleCenter:
                x = (controlWidth / 2) - (imageWidth / 2);
                y = (controlHeight / 2) - (imageHeight / 2);
                break;

            case ImageAlignment.MiddleRight:
                x = controlWidth - imageWidth;
                y = (controlHeight / 2) - (imageHeight / 2);
                break;

            case ImageAlignment.TopLeft:
                x = 0;
                y = 0;
                break;

            case ImageAlignment.TopCenter:
                x = (controlWidth / 2) - (imageWidth / 2);
                y = 0;
                break;

            case ImageAlignment.TopRight:
                x = controlWidth - imageWidth;
                y = 0;
                break;

            case ImageAlignment.Fill:
                x = 0;
                y = 0;

                if (!adaptImage)
                {
                    adaptedSize.Width  = controlWidth;
                    adaptedSize.Height = controlHeight;
                }
                break;
            }

            e.Graphics.DrawImage(image, new Rectangle(x, y, adaptedSize.Width, adaptedSize.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
        }
Example #21
0
 public Image()
 {
     Alignment = ImageAlignment.Left;
 }
Example #22
0
        /// <summary>
        /// Default constructor of the control
        /// </summary>
        public InfoBarLite()
        {
            m_Image = null;
              m_ImageAlignment = ImageAlignment.TopLeft;
              m_BackStyle = BackStyle.Solid;
              m_GradientMode = LinearGradientMode.Horizontal;
              m_GradientStartColor = Color.DeepSkyBlue;
              m_GradientEndColor = Color.White;
              m_BorderStyle = Border3DStyle.Etched;
              m_BorderSide = Border3DSide.Bottom;

              m_Text1 = "Peace at home, peace in the world!";
              m_Text1ForeColor = SystemColors.ControlText;

              m_Text2 = "The quick brown fox lazily jumped over the bridge.";
              m_Text2ForeColor = SystemColors.ControlText;

              try
              {
            m_Text1Font = new Font("Tahoma", 8, FontStyle.Bold, GraphicsUnit.Point);
            m_Text2Font = new Font("Tahoma", 8);
              }
              catch
              {
            m_Text1Font = Font;
            m_Text2Font = Font;
              }

              m_ImageOffsetX = 2;
              m_ImageOffsetY = 0;
              m_Text1OffsetX = 0;
              m_Text1OffsetY = 0;
              m_Text2OffsetX = 20;
              m_Text2OffsetY = 0;

              BackColor = SystemColors.Window;

              ResizeRedraw = true;
              SetStyle(ControlStyles.UserPaint, true);
              SetStyle(ControlStyles.AllPaintingInWmPaint, true);
              SetStyle(ControlStyles.DoubleBuffer, true);
        }
Example #23
0
        /// <summary>
        /// Draw Caption of <see cref="BarItem"/>
        /// </summary>
        public void DrawItemText()
        {
            ImageAlignment alignment = Item.ImageAlignment == ItemImageAlignment.Inherit
                                           ? Bar.ImageAlignment
                                           : ((ImageAlignment)((int)Item.ImageAlignment));
            var b        = new Rectangle(Bounds.Location, Bounds.Size);
            var iconSize = Size.Empty;

            if (Bar.ImageList != null && Item.ImageIndex >= 0 && Item.ImageIndex < Bar.ImageList.Images.Count)
            {
                iconSize = Bar.ImageList.ImageSize;
            }
            int iW = (!iconSize.IsEmpty && (alignment == ImageAlignment.Left || alignment == ImageAlignment.Right)
                          ? iconSize.Width + 6
                          : 0);
            int iH = (!iconSize.IsEmpty && (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Top)
                          ? iconSize.Height
                          : 0);

            var textRect = new Rectangle(0, 0,
                                         Bounds.Width - iW - 1, Bounds.Height - iH - 1);

            if (alignment == ImageAlignment.Top || alignment == ImageAlignment.Bottom)
            {
                textRect.X = b.X;
            }
            else if (alignment == ImageAlignment.Left)
            {
                textRect.X = b.X + iW;
            }
            else
            {
                textRect.X = Bounds.X;
            }

            if (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Right)
            {
                textRect.Y = b.Y;
            }
            else if (alignment == ImageAlignment.Top)
            {
                textRect.Y = b.Y + iH;
            }
            else if (alignment == ImageAlignment.Left)
            {
                textRect.Y = b.Y;
            }

            string itemText = Item.Caption;
            var    c        = Color.Empty;

            switch (State)
            {
            case State.Selected:
                c = Item.Appearance.SelectedForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.SelectedForeGround
                            : Item.Appearance.SelectedForeGround;
                break;

            case State.Disabled:
                c = Item.Appearance.DisabledForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.DisabledForeGround
                            : Item.Appearance.DisabledForeGround;
                break;

            case State.Hover:
                c = Item.Appearance.HoverForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.HoverForeGround
                            : Item.Appearance.HoverForeGround;
                break;

            case State.SelectedHover:
                c = Item.Appearance.HoverForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.HoverForeGround
                            : Item.Appearance.HoverForeGround;
                break;

            case State.Normal:
                c = Item.Appearance.NormalForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.NormalForeGround
                            : Item.Appearance.NormalForeGround;
                break;

            case State.Pressed:
                c = Item.Appearance.SelectedForeGround.IsEmpty
                            ? Bar.CurrentAppearance.Item.SelectedForeGround
                            : Item.Appearance.SelectedForeGround;
                break;
            }
            PaintUtility.DrawString(Graphics, textRect, itemText,
                                    Item.Appearance.AppearenceText.IsEmpty
                                        ? Bar.CurrentAppearance.Item.AppearenceText
                                        : Item.Appearance.AppearenceText, Bar.UseMnemonic, c);
        }