예제 #1
0
파일: Frame.cs 프로젝트: parhelia512/ZHSan
        /// <summary>
        /// 添加控件后计算新的画布大小
        /// </summary>
        /// <param name="contentContorl">添加的控件</param>
        private void CalculateCanvasSize(IFrameContent contentContorl)
        {
            contentContorl.CalculateControlSize();//计算添加控件的大小

            //如果新添加的控件大于现在画布的范围则生成适合新控件大小的画布
            if (contentContorl.OffsetPos.X + contentContorl.Width > CanvasWidth - CanvasRightPadding || contentContorl.OffsetPos.Y + contentContorl.Height > CanvasHeight - CanvasBottomPadding)
            {
                if (contentContorl.OffsetPos.X + contentContorl.Width > CanvasWidth - CanvasRightPadding)
                {
                    CanvasWidth = contentContorl.OffsetPos.X + contentContorl.Width + CanvasRightPadding;//添加画布边界填充距离
                }
                if (contentContorl.OffsetPos.Y + contentContorl.Height > CanvasHeight - CanvasBottomPadding)
                {
                    CanvasHeight = contentContorl.OffsetPos.Y + contentContorl.Height + CanvasBottomPadding;//添加画布边界填充距离
                }
                if (renderTarget2D != null)
                {
                    renderTarget2D.Dispose();
                }
                renderTarget2D = new RenderTarget2D(Platform.GraphicsDevice, CanvasWidth.ConvertToIntPlus(), CanvasHeight.ConvertToIntPlus());
            }
        }
예제 #2
0
파일: Frame.cs 프로젝트: parhelia512/ZHSan
        /// <summary>
        /// 用于删减控件后重新计算并生成新画布
        /// </summary>
        public void ReCalcuateCanvasSize()
        {
            CanvasWidth = CanvasHeight = 0;
            ContentContorls.ForEach(cc =>
            {
                cc.CalculateControlSize();
                CanvasWidth  = cc.OffsetPos.X + cc.Width > CanvasWidth ? cc.OffsetPos.X + cc.Width : CanvasWidth;
                CanvasHeight = cc.OffsetPos.Y + cc.Height > CanvasHeight ? cc.OffsetPos.Y + cc.Height : CanvasHeight;
            });

            //添加画布边界填充
            CanvasWidth  += CanvasRightPadding;
            CanvasHeight += CanvasBottomPadding;

            if (renderTarget2D != null)
            {
                renderTarget2D.Dispose();
            }
            renderTarget2D = new RenderTarget2D(Platform.GraphicsDevice, CanvasWidth.ConvertToIntPlus(), CanvasHeight.ConvertToIntPlus());
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        protected override void CreateChildControls()
        {
            //Add the jquery/jcrop includes
            AddFileReferences();

            System.Web.UI.WebControls.Image image =
                Parent.FindControl(this.Image) as System.Web.UI.WebControls.Image;


            string url         = image.ImageUrl;
            string resolvedUrl = url.StartsWith("~") ? ResolveUrl(url) : url;

            ViewState["ImageUrl"] = resolvedUrl;


            //image - '<img />' tag ID, DOM, or jquery reference
            //settings - object

            /*
             * settings = {keepAspectRatio:false,
             *          keepAspectRatioCheckbox: '#id' or reference,
             *          aspectRatio: null or value,
             *          minSize: [w,h],
             *          maxSize: [w,h],
             *          previewDiv: '#id' or reference or null,
             *          previewWidth: (previewDiv original width, or 100),
             *          previewHeight: (previewDiv original height, or 100),
             *          boxWidth: null or value,
             *          boxHeight: null or value,
             *          setSelect: [x1,y1,x2,y2],
             *          updateLinks: "#id1, #id2" or null,
             *          updateFields: "#id1, #id2" or null,
             *          updateImages: "#id1, #id2" or null
             */

            NameValueCollection s = new NameValueCollection();

            if (!string.IsNullOrEmpty(this.FixedAspectRatioCheckboxID))
            {
                Control c = Parent.FindControl(FixedAspectRatioCheckboxID);
                if (c != null)
                {
                    s["keepAspectRatioCheckbox"] = "'#" + c.ClientID + "'";
                }
            }
            s["keepAspectRatio"] = FixedAspectRatio.ToString().ToLower();

            if (!string.IsNullOrEmpty(this.Ratio))
            {
                s["aspectRatio"] = Ratio;
            }

            //If the image URL is a virtual path within the application, and ServerSideResize=true, then use URL resizing; otherwise, use boxWidth/boxHeight
            if (CanvasHeight > 0 | CanvasWidth > 0)
            {
                if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase) && this.ServerSizeResize)
                {
                    NameValueCollection max = new NameValueCollection();
                    if (CanvasHeight > 0)
                    {
                        max["maxheight"] = CanvasHeight.ToString();
                    }
                    if (CanvasWidth > 0)
                    {
                        max["maxwidth"] = CanvasWidth.ToString();
                    }
                    url            = ImageResizer.Util.PathUtils.MergeOverwriteQueryString(url, max);
                    image.ImageUrl = url;
                }
                else
                {
                    if (CanvasHeight > 0)
                    {
                        s["boxHeight"] = CanvasHeight.ToString();
                    }
                    if (CanvasWidth > 0)
                    {
                        s["boxWidth"] = CanvasWidth.ToString();
                    }
                }
            }


            //If there has been a crop rectangle specified, use it
            if (W > 0 || H > 0)
            {
                s["setSelect"] =
                    "[" + X.ToString() + "," +
                    Y.ToString() + "," +
                    X2.ToString() + ", " +
                    Y2.ToString() + "]";
            }



            if (!string.IsNullOrEmpty(this.MaxSize))
            {
                s["maxSize"] = "[" + this.MaxSize + "]";
            }

            if (!string.IsNullOrEmpty(this.MinSize))
            {
                s["minSize"] = "[" + this.MinSize + "]";
            }

            if (this.PreviewWidth > 0)
            {
                s["previewWidth"] = this.PreviewWidth.ToString();
            }

            if (this.PreviewHeight > 0)
            {
                s["previewHeight"] = this.PreviewHeight.ToString();
            }

            if (!string.IsNullOrEmpty(this.PreviewImageID))
            {
                Control c = Parent.FindControl(PreviewImageID);
                if (c != null)
                {
                    s["previewDiv"] = "'#" + c.ClientID + "'";
                }
            }

            s["updateFields"] = "'#" + HiddenFieldClientId + "'";



            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<script>$(function(){ ");
            sb.AppendLine("webcropimage('#" + image.ClientID + "', {");
            foreach (string key in s)
            {
                sb.AppendLine(key + ": " + s[key] + ",");
            }
            sb.Append("});});");
            sb.Append(@"</script>");


            if (isInUpdatePanel)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType()
                                                        , "cropInit" + this.ClientID
                                                        , sb.ToString(), false);
                ScriptManager.RegisterHiddenField(this, HiddenFieldClientId, resolvedUrl);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType()
                                                            , "cropInit" + this.ClientID
                                                            , sb.ToString(), false);
                Page.ClientScript.RegisterHiddenField(HiddenFieldClientId, resolvedUrl);
            }

            base.CreateChildControls();
        }