예제 #1
0
 public override SizeF Measure(SizeF availableSize)
 {
     if (this.Owner.Image != null)
     {
         lock (this.Owner.Image)
         {
             if (this.Owner.ImageLayout == ImageLayout.Zoom)
             {
                 float f    = Math.Min(availableSize.Width / (float)this.Owner.Image.Width, availableSize.Height / (float)this.Owner.Image.Height);
                 int   num1 = (int)Math.Round((double)this.Owner.Image.Width * (double)f);
                 int   num2 = (int)Math.Round((double)this.Owner.Image.Height * (double)f);
                 if (float.IsInfinity(f))
                 {
                     num1 = num2 = 0;
                 }
                 this.DesiredSize = new SizeF((float)num1, (float)num2);
             }
             else
             {
                 this.DesiredSize = TelerikDpiHelper.ScaleSizeF((SizeF)this.Owner.Image.Size, this.Owner.DpiScaleFactor);
             }
         }
     }
     else
     {
         this.DesiredSize = SizeF.Empty;
     }
     this.DesiredSize = new SizeF(Math.Min(availableSize.Width, this.DesiredSize.Width), Math.Min(availableSize.Height, this.DesiredSize.Height));
     return(this.DesiredSize);
 }
예제 #2
0
 protected override void HandleDpiChanged()
 {
     if (TelerikHelper.IsWindows8OrLower || TelerikHelper.IsWindows10CreatorsUpdateOrHigher)
     {
         this.Scale(TelerikDpiHelper.ScaleSizeF(Telerik.WinControls.NativeMethods.GetMonitorDpi(Screen.FromControl((Control)this), Telerik.WinControls.NativeMethods.DpiType.Effective), new SizeF(1f / this.RootElement.DpiScaleFactor.Width, 1f / this.RootElement.DpiScaleFactor.Height)));
     }
     else
     {
         base.HandleDpiChanged();
     }
 }
예제 #3
0
        protected override void PaintElement(IGraphics graphics, float angle, SizeF scale)
        {
            if (this.IsCropping)
            {
                Rectangle cropRectangle = this.GetCropRectangle();
                SizeF     scaleFactor   = new SizeF(1f / this.DpiScaleFactor.Width, 1f / this.DpiScaleFactor.Height);
                this.AcceptButton.PositionOffset = TelerikDpiHelper.ScaleSizeF(new SizeF((float)cropRectangle.X + (float)cropRectangle.Width / 2f - (float)this.AcceptButton.Location.X - this.AcceptButton.DesiredSize.Width, (float)(cropRectangle.Y + cropRectangle.Height) + (float)this.CropHandlesSize.Height / 2f - (float)this.AcceptButton.Location.Y), scaleFactor);
                this.CancelButton.PositionOffset = TelerikDpiHelper.ScaleSizeF(new SizeF((float)cropRectangle.X + (float)cropRectangle.Width / 2f - (float)this.CancelButton.Location.X - this.CancelButton.DesiredSize.Width, (float)(cropRectangle.Y + cropRectangle.Height) + (float)this.CropHandlesSize.Height / 2f - (float)this.CancelButton.Location.Y), scaleFactor);
            }
            base.PaintElement(graphics, angle, scale);
            if (this.imageEditorElement.CurrentBitmap == null)
            {
                return;
            }
            Graphics  underlayGraphics   = (Graphics)graphics.UnderlayGraphics;
            Rectangle imageDrawRectangle = this.GetImageDrawRectangle();

            underlayGraphics.DrawImage((Image)this.imageEditorElement.CurrentBitmap, imageDrawRectangle);
            if (!this.IsCropping)
            {
                return;
            }
            RectangleF srcRect        = new RectangleF((float)this.imageEditorElement.CurrentBitmap.Width * this.RelativeCropRect.X, (float)this.imageEditorElement.CurrentBitmap.Height * this.RelativeCropRect.Y, (float)this.imageEditorElement.CurrentBitmap.Width * this.RelativeCropRect.Width, (float)this.imageEditorElement.CurrentBitmap.Height * this.RelativeCropRect.Height);
            Rectangle  cropRectangle1 = this.GetCropRectangle();
            SizeF      sizeF1         = new SizeF((float)this.CropHandlesSize.Width / 2f, (float)this.CropHandlesSize.Height / 2f);

            graphics.FillRectangle(imageDrawRectangle, Color.FromArgb(100, Color.White));
            underlayGraphics.DrawImage((Image)this.imageEditorElement.CurrentBitmap, (RectangleF)cropRectangle1, srcRect, GraphicsUnit.Pixel);
            underlayGraphics.DrawRectangle(Pens.OrangeRed, cropRectangle1);
            underlayGraphics.FillRectangle(Brushes.OrangeRed, new RectangleF((float)cropRectangle1.X - sizeF1.Width, (float)cropRectangle1.Y - sizeF1.Height, (float)this.CropHandlesSize.Width, (float)this.CropHandlesSize.Height));
            underlayGraphics.FillRectangle(Brushes.OrangeRed, new RectangleF((float)cropRectangle1.Right - sizeF1.Width, (float)cropRectangle1.Y - sizeF1.Height, (float)this.CropHandlesSize.Width, (float)this.CropHandlesSize.Height));
            underlayGraphics.FillRectangle(Brushes.OrangeRed, new RectangleF((float)cropRectangle1.X - sizeF1.Width, (float)cropRectangle1.Bottom - sizeF1.Height, (float)this.CropHandlesSize.Width, (float)this.CropHandlesSize.Height));
            underlayGraphics.FillRectangle(Brushes.OrangeRed, new RectangleF((float)cropRectangle1.Right - sizeF1.Width, (float)cropRectangle1.Bottom - sizeF1.Height, (float)this.CropHandlesSize.Width, (float)this.CropHandlesSize.Height));
            string str1   = string.Format("X={0}, Y={1}", (object)(cropRectangle1.X - imageDrawRectangle.X), (object)(cropRectangle1.Y - imageDrawRectangle.Y));
            SizeF  sizeF2 = underlayGraphics.MeasureString(str1, this.GetScaledFont(this.DpiScaleFactor.Height));

            underlayGraphics.DrawString(str1, this.GetScaledFont(this.DpiScaleFactor.Height), Brushes.OrangeRed, (float)cropRectangle1.X - sizeF1.Width, (float)cropRectangle1.Y - sizeF1.Height - sizeF2.Height);
            string str2   = string.Format("{0} x {1} px", (object)cropRectangle1.Width, (object)cropRectangle1.Height);
            SizeF  sizeF3 = underlayGraphics.MeasureString(str2, this.GetScaledFont(this.DpiScaleFactor.Height));

            underlayGraphics.DrawString(str2, this.GetScaledFont(this.DpiScaleFactor.Height), Brushes.OrangeRed, (float)cropRectangle1.Right + sizeF1.Width - sizeF3.Width, (float)cropRectangle1.Bottom + sizeF1.Height);
        }
예제 #4
0
        protected virtual Size GetPopupSize()
        {
            Size  defaultSize = RadDesktopAlert.DefaultSize;
            SizeF scaleFactor = RadControl.EnableDpiScaling ? Telerik.WinControls.NativeMethods.GetMonitorDpi(Screen.FromPoint(this.Popup.Location), Telerik.WinControls.NativeMethods.DpiType.Effective) : new SizeF(1f, 1f);

            if (this.fixedSize != Size.Empty)
            {
                if (this.FixedSize.Width == 0 || (this.FixedSize.Height != 0 || !this.AutoSize))
                {
                    return(TelerikDpiHelper.ScaleSize(this.fixedSize, scaleFactor));
                }
                defaultSize.Width = this.FixedSize.Width;
            }
            Size desiredSize = new Size(defaultSize.Width, defaultSize.Height);

            this.popup.Size = desiredSize;
            this.popup.LoadElementTree(desiredSize);
            SizeF sizeF = new SizeF((float)defaultSize.Width, this.popup.AlertElement.DesiredSize.Height);

            sizeF = TelerikDpiHelper.ScaleSizeF(sizeF, scaleFactor);
            return(sizeF.ToSize());
        }