Exemplo n.º 1
0
 public override sd.Size GetPreferredSize(sd.Size proposedSize)
 {
     if (cachedSize == null)
     {
         var size = new sd.Size(16, 20);
         var font = Font;
         using (var g = CreateGraphics())
         {
             foreach (object item in Items)
             {
                 var text     = GetItemText(item);
                 var itemSize = swf.TextRenderer.MeasureText(g, text, font);
                 size.Width  = Math.Max(size.Width, (int)itemSize.Width);
                 size.Height = Math.Max(size.Height, (int)itemSize.Height);
             }
         }
         // for drop down glyph and border
         if (DrawMode == swf.DrawMode.OwnerDrawFixed)
         {
             size.Width += 4;
         }
         size.Width  += 18;
         size.Height += 4;
         size.Width   = Math.Max(size.Width, MinSize.Width);
         size.Height  = Math.Max(size.Height, MinSize.Height);
         cachedSize   = size;
     }
     return(cachedSize.Value);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an image.
        /// </summary>
        /// <param name="model">The upload to create.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Image populated with newly allocated upload identifier.</returns>
        private Image CreateImage(CreateUploadModel model, IUnitOfWork unitOfWork)
        {
            // Validate create upload model
            Drawing.Size?size = _uploadValidator.ValidateCreateImage(model);

            // Construct image object
            DateTime now   = DateTime.UtcNow;
            Image    image = new Image
            {
                TenantId    = model.TenantId,
                Created     = now,
                Updated     = now,
                Name        = model.Name.Trim(),
                Content     = model.Content,
                ContentType = model.ContentType.Trim().ToLower(),
                Size        = model.Content.Length,
                UploadType  = UploadType.Image,
                Committed   = false,
                Width       = size.Value.Width,
                Height      = size.Value.Height
            };

            // Create image and record newly allocated upload identifier
            image.UploadId = _uploadRepository.CreateImage(image, unitOfWork);

            // Return image object
            return(image);
        }
Exemplo n.º 3
0
        /*
         * protected override void OnMeasureItem(swf.MeasureItemEventArgs e)
         * {
         *      base.OnMeasureItem(e);
         *      using (var g = CreateGraphics())
         *      {
         *              //foreach (object item in Items)
         *              {
         *                      var font = Font;
         *                      var text = GetItemText(e.Index);
         *                      var itemSize = swf.TextRenderer.MeasureText(g, text, font);
         *                      e.ItemWidth = (int)itemSize.Width;
         *                      e.ItemHeight = (int)itemSize.Height;
         *              }
         *      }
         * }*/

        public override sd.Size GetPreferredSize(sd.Size proposedSize)
        {
            if (cachedSize == null)
            {
                var size = new sd.Size(16, 20);
                var font = Font;
                foreach (object item in Items)
                {
                    var text     = GetItemText(item);
                    var itemSize = swf.TextRenderer.MeasureText(text, font);
                    var image    = (item as EtoComboBoxItem)?.Image;
                    if (image != null)
                    {
                        itemSize.Width += 18;
                    }
                    size.Width  = Math.Max(size.Width, (int)itemSize.Width);
                    size.Height = Math.Max(size.Height, (int)itemSize.Height);
                }
                // for drop down glyph and border
                if (DrawMode == swf.DrawMode.OwnerDrawFixed)
                {
                    size.Width += 4;
                }
                size.Width  += 18;
                size.Height += 4;
                size.Width   = Math.Max(size.Width, MinSize.Width);
                size.Height  = Math.Max(size.Height, MinSize.Height);
                cachedSize   = size;
            }
            return(cachedSize.Value);
        }
Exemplo n.º 4
0
        public void ChangeDesktopSize(System.Drawing.Size?size = null, DesktopSize?desktopSize = null)
        {
            if (this.Favorite == null && !desktopSize.HasValue)
            {
                return;
            }

            if (!(size.HasValue && desktopSize.HasValue))
            {
                if (desktopSize.HasValue)
                {
                    if (size.HasValue)
                    {
                        size = GetSize(this, desktopSize.Value, size.Value.Width, size.Value.Height);
                    }
                    else
                    {
                        size = GetSize(this, desktopSize.Value, this.Favorite.DesktopSizeWidth, this.Favorite.DesktopSizeHeight);
                    }
                }
                else
                if (size == null)
                {
                    size = GetSize();
                }

                if (size == null)
                {
                    return;
                }
            }

            this.ChangeDesktopSize(desktopSize.HasValue ? desktopSize.Value : this.Favorite.DesktopSize, size.Value);
        }
Exemplo n.º 5
0
            sd.SizeF CalculatePositions(sd.Size proposedSize, bool force)
            {
                if (!force && (positions != null && positionSize == proposedSize))
                {
                    return(sd.SizeF.Empty);
                }

                positionSize = proposedSize;
                var size = sd.SizeF.Empty;

                sd.Size lineSize = sd.Size.Empty;
                var     text     = Text;

                positions = new List <Position>();
                while (text.Length > 0)
                {
                    var lineText = string.Empty;
                    for (int len = 0; len <= text.Length; len++)
                    {
                        var t  = text.Substring(0, len);
                        var ls = swf.TextRenderer.MeasureText(t, Font, proposedSize, textFormat);
                        if (ls.Width < proposedSize.Width)
                        {
                            lineText = t;
                            lineSize = ls;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (lineText.Length == 0)
                    {
                        break;
                    }
                    positions.Add(new Position {
                        Size = lineSize, Text = lineText
                    });
                    size.Height += lineSize.Height;
                    size.Width   = Math.Max(lineSize.Width, size.Width);
                    text         = text.Substring(lineText.Length);
                }
                return(size);
            }
Exemplo n.º 6
0
        public DisplayObject LoadClass(System.Type type)
        {
            // get desired size of object from [SWF] attributes
            System.Drawing.Size?desiredSize = GetSWFDesiredSize(type);

            // construct instance of type
            // we set the global stage so that it will be set during this display object's constructor
            DisplayObjectContainer.globalStage = mStage;
            DisplayObject displayObject = System.Activator.CreateInstance(type) as DisplayObject;

            DisplayObjectContainer.globalStage = null;

            if (displayObject != null)
            {
                // TODO: this size may need to be set before the display object constructor executes
                if (desiredSize.HasValue)
                {
                    // resize object to desired size
                    displayObject.width  = desiredSize.Value.Width;
                    displayObject.height = desiredSize.Value.Height;
                }
                else
                {
                    // resize object to size of stage
                    displayObject.width  = mStage.stageWidth;
                    displayObject.height = mStage.stageHeight;
                }

                // add display object to stage
                mStage.addChild(displayObject);

                // set title
                Title = displayObject.GetType().ToString();
            }

            return(displayObject);
        }
Exemplo n.º 7
0
 public void ResetSize()
 {
     cachedSize = null;
 }
Exemplo n.º 8
0
        /// <summary>上传图片到指定目录</summary>
        /// <param name="fileUpload">文件上传控件</param>
        /// <param name="folderName">上传目录名,如Users</param>
        /// <returns>图片的虚拟路径</returns>
        public static string UploadFile(FineUI.FileUpload fileUpload, string folderName, System.Drawing.Size?size = null)
        {
            if (!fileUpload.HasFile)
            {
                return("");
            }

            // 图片文件检测
            string fileName = fileUpload.ShortFileName;

            if (!Common.IsImageFile(fileName))
            {
                Alert.Show("无效的图片类型!");
                return("");
            }

            // 保存文件, 调整尺寸
            string virtualPath  = Common.GetUploadFilePath(folderName, fileName);
            string physicalPath = SaveUploadFile(fileUpload, virtualPath);

            if (size != null)
            {
                DrawHelper.CreateThumbnail(physicalPath, physicalPath, size.Value.Width);
            }
            return(virtualPath);
        }