static public Dot9BitmapD2D CreateDot9BoxShadowBitmap(D2DGraphics g, float cornersRadius, float shadowRadius, System.Drawing.Color shadowColor) { int width = (int)(cornersRadius * 2 + shadowRadius * 4 + 2); int height = (int)(cornersRadius * 2 + shadowRadius * 4 + 2); SharpDX.Direct2D1.PixelFormat format = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied); BitmapProperties prop = new BitmapProperties(format); SharpDX.Direct2D1.Bitmap bitmap = new SharpDX.Direct2D1.Bitmap(g.RenderTarget, new Size2(width, height), prop); unsafe { System.Drawing.Bitmap gdibmp = new System.Drawing.Bitmap(width, height); System.Drawing.RectangleF rect = new System.Drawing.RectangleF(shadowRadius, shadowRadius, width - shadowRadius * 2, height - shadowRadius * 2); Graphics gdiGraph = Graphics.FromImage(gdibmp); GraphicsPath myPath = DrawUtils.CreateRoundedRectanglePath(rect, cornersRadius); System.Drawing.Brush brush = new SolidBrush(shadowColor); gdiGraph.FillPath(brush, myPath); brush.Dispose(); GaussianBlur gs = new GaussianBlur((int)shadowRadius); gdibmp = gs.ProcessImage(gdibmp); System.Drawing.Rectangle bitmapRect = new System.Drawing.Rectangle(0, 0, gdibmp.Width, gdibmp.Height); BitmapData srcBmData = gdibmp.LockBits(bitmapRect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); byte * ptr = (byte *)srcBmData.Scan0; bitmap.CopyFromMemory((IntPtr)ptr, srcBmData.Stride); gdibmp.UnlockBits(srcBmData); // gdibmp.Save("f:\\shadow.png"); gdibmp.Dispose(); } int[] widthPts = new int[] { (int)(cornersRadius + shadowRadius * 2 + 1), (int)(width - cornersRadius - shadowRadius * 2 - 1) }; int[] heightPts = new int[] { (int)(cornersRadius + shadowRadius * 2 + 1), (int)(width - cornersRadius - shadowRadius * 2 - 1) }; Dot9BitmapD2D dot9Bitmap = new Dot9BitmapD2D(bitmap, widthPts, heightPts); return(dot9Bitmap); }
/// <summary> /// Draws info box of the provided scene /// </summary> private void DrawSceneInfoGUI(Rect position, BuildUtils.BuildScene buildScene, int sceneControlID) { bool readOnly = BuildUtils.IsReadOnly(); string readOnlyWarning = readOnly ? "\n\nWARNING: Build Settings is not checked out and so cannot be modified." : ""; // Label Prefix GUIContent iconContent = new GUIContent(); GUIContent labelContent = new GUIContent(); // Missing from build scenes if (buildScene.buildIndex == -1) { iconContent = EditorGUIUtility.IconContent("d_winbtn_mac_close"); labelContent.text = "NOT In Build"; labelContent.tooltip = "This scene is NOT in build settings.\nIt will be NOT included in builds."; } // In build scenes and enabled else if (buildScene.scene.enabled) { iconContent = EditorGUIUtility.IconContent("d_winbtn_mac_max"); labelContent.text = "BuildIndex: " + buildScene.buildIndex; labelContent.tooltip = "This scene is in build settings and ENABLED.\nIt will be included in builds." + readOnlyWarning; } // In build scenes and disabled else { iconContent = EditorGUIUtility.IconContent("d_winbtn_mac_min"); labelContent.text = "BuildIndex: " + buildScene.buildIndex; labelContent.tooltip = "This scene is in build settings and DISABLED.\nIt will be NOT included in builds."; } // Left status label using (new EditorGUI.DisabledScope(readOnly)) { Rect labelRect = DrawUtils.GetLabelRect(position); Rect iconRect = labelRect; iconRect.width = iconContent.image.width + padSize; labelRect.width -= iconRect.width; labelRect.x += iconRect.width; EditorGUI.PrefixLabel(iconRect, sceneControlID, iconContent); EditorGUI.PrefixLabel(labelRect, sceneControlID, labelContent); } // Right context buttons Rect buttonRect = DrawUtils.GetFieldRect(position); buttonRect.width = (buttonRect.width) / 3; string tooltipMsg = ""; using (new EditorGUI.DisabledScope(readOnly)) { // NOT in build settings if (buildScene.buildIndex == -1) { buttonRect.width *= 2; int addIndex = EditorBuildSettings.scenes.Length; tooltipMsg = "Add this scene to build settings. It will be appended to the end of the build scenes as buildIndex: " + addIndex + "." + readOnlyWarning; if (DrawUtils.ButtonHelper(buttonRect, "Add...", "Add (buildIndex " + addIndex + ")", EditorStyles.miniButtonLeft, tooltipMsg)) { BuildUtils.AddBuildScene(buildScene); } buttonRect.width /= 2; buttonRect.x += buttonRect.width; } // In build settings else { bool isEnabled = buildScene.scene.enabled; string stateString = isEnabled ? "Disable" : "Enable"; tooltipMsg = stateString + " this scene in build settings.\n" + (isEnabled ? "It will no longer be included in builds" : "It will be included in builds") + "." + readOnlyWarning; if (DrawUtils.ButtonHelper(buttonRect, stateString, stateString + " In Build", EditorStyles.miniButtonLeft, tooltipMsg)) { BuildUtils.SetBuildSceneState(buildScene, !isEnabled); } buttonRect.x += buttonRect.width; tooltipMsg = "Completely remove this scene from build settings.\nYou will need to add it again for it to be included in builds!" + readOnlyWarning; if (DrawUtils.ButtonHelper(buttonRect, "Remove...", "Remove from Build", EditorStyles.miniButtonMid, tooltipMsg)) { BuildUtils.RemoveBuildScene(buildScene); } } } buttonRect.x += buttonRect.width; tooltipMsg = "Open the 'Build Settings' Window for managing scenes." + readOnlyWarning; if (DrawUtils.ButtonHelper(buttonRect, "Settings", "Build Settings", EditorStyles.miniButtonRight, tooltipMsg)) { BuildUtils.OpenBuildSettings(); } }
static public void BoxShadow(Bitmap processBitmap, int shadowRadius, int[] cornersType, int[] cornersRadius) { int r = shadowRadius; int sideWidth = shadowRadius; int offset = 2; Graphics g; Bitmap bitmap; Rectangle rc; Rectangle rc1; Bitmap effectBitmap; GraphicsPath path; GaussianBlur gs = new GaussianBlur(r); int width = processBitmap.Width; int height = processBitmap.Height; Graphics baseg = Graphics.FromImage(processBitmap); // int leftTopWidth = sideWidth + r; int leftTopHeight = sideWidth + r; bitmap = new Bitmap(leftTopWidth, leftTopHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(sideWidth, sideWidth, r, r); if (cornersType[0] == 0) { g.FillRectangle(Brushes.Black, rc); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, 0, 0, new Rectangle(0, 0, sideWidth, sideWidth), GraphicsUnit.Pixel); } else { g.SmoothingMode = SmoothingMode.HighQuality; path = DrawUtils.CreateRoundedRectanglePath(rc, cornersRadius[0]); g.FillPath(Brushes.Black, path); path.Dispose(); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, 0, 0, new Rectangle(0, 0, sideWidth, sideWidth), GraphicsUnit.Pixel); baseg.DrawImage(effectBitmap, sideWidth, sideWidth, new Rectangle(sideWidth, sideWidth, r, r), GraphicsUnit.Pixel); } g.Dispose(); bitmap.Dispose(); //// int rightTopWidth = sideWidth + r; int rightTopHeight = sideWidth + r; bitmap = new Bitmap(rightTopWidth, rightTopHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(0, sideWidth, r, r); if (cornersType[0] == 0) { g.FillRectangle(Brushes.Black, rc); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, width - sideWidth, 0, new Rectangle(rightTopWidth - sideWidth, 0, sideWidth, sideWidth), GraphicsUnit.Pixel); } else { g.SmoothingMode = SmoothingMode.HighQuality; path = DrawUtils.CreateRoundedRectanglePath(rc, cornersRadius[0]); g.FillPath(Brushes.Black, path); path.Dispose(); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, width - sideWidth, 0, new Rectangle(rightTopWidth - sideWidth, 0, sideWidth, sideWidth), GraphicsUnit.Pixel); baseg.DrawImage(effectBitmap, width - sideWidth - r, sideWidth, new Rectangle(0, sideWidth, r, r), GraphicsUnit.Pixel); } g.Dispose(); bitmap.Dispose(); //// int leftBottomWidth = sideWidth + r; int leftBottomHeight = sideWidth + r; bitmap = new Bitmap(leftBottomWidth, leftBottomHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(sideWidth, 0, r, r); if (cornersType[2] == 0) { g.FillRectangle(Brushes.Black, rc); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, 0, height - sideWidth, new Rectangle(0, leftBottomHeight - sideWidth, sideWidth, sideWidth), GraphicsUnit.Pixel); } else { g.SmoothingMode = SmoothingMode.HighQuality; path = DrawUtils.CreateRoundedRectanglePath(rc, cornersRadius[0]); g.FillPath(Brushes.Black, path); path.Dispose(); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, 0, height - sideWidth, new Rectangle(0, leftBottomHeight - sideWidth, sideWidth, sideWidth), GraphicsUnit.Pixel); baseg.DrawImage(effectBitmap, sideWidth, height - sideWidth - r, new Rectangle(sideWidth, 0, r, r), GraphicsUnit.Pixel); } g.Dispose(); bitmap.Dispose(); //// int rightBottomWidth = sideWidth + r; int rightBottomHeight = sideWidth + r; bitmap = new Bitmap(rightBottomWidth, rightBottomHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(0, 0, r, r); if (cornersType[3] == 0) { g.FillRectangle(Brushes.Black, rc); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, width - sideWidth, height - sideWidth, new Rectangle(rightBottomHeight - sideWidth, rightBottomHeight - sideWidth, sideWidth, sideWidth), GraphicsUnit.Pixel); } else { g.SmoothingMode = SmoothingMode.HighQuality; path = DrawUtils.CreateRoundedRectanglePath(rc, cornersRadius[0]); g.FillPath(Brushes.Black, path); path.Dispose(); effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, width - sideWidth, height - sideWidth, new Rectangle(rightBottomHeight - sideWidth, rightBottomHeight - sideWidth, sideWidth, sideWidth), GraphicsUnit.Pixel); baseg.DrawImage(effectBitmap, width - sideWidth - r, height - sideWidth - r, new Rectangle(0, 0, r, r), GraphicsUnit.Pixel); } g.Dispose(); bitmap.Dispose(); //// int topWidth = width; int topHeight = r + sideWidth; bitmap = new Bitmap(topWidth, topHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(sideWidth, sideWidth, width - sideWidth * 2, r); if (cornersType[0] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Y, rc.Width / 2 + offset, rc.Height); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[0]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Y, rc.Width / 2 + offset, rc.Height); g.FillRectangle(Brushes.Black, rc1); } if (cornersType[1] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.Right - rc.Width / 2 - offset, rc.Y, rc.Width / 2 + offset, rc.Height); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[1]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.Right - rc.Width / 2 - offset, rc.Y, rc.Width / 2 + offset, rc.Height); g.FillRectangle(Brushes.Black, rc1); } effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, sideWidth, 0, new Rectangle(sideWidth, 0, topWidth - sideWidth * 2, sideWidth), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); //// int bottomWidth = width; int bottomHeight = r + sideWidth; bitmap = new Bitmap(bottomWidth, bottomHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(sideWidth, 0, bottomWidth - 2 * sideWidth, r); if (cornersType[2] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Y, rc.Width / 2 + offset, rc.Height); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[0]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Y, rc.Width / 2 + offset, rc.Height); g.FillRectangle(Brushes.Black, rc1); } if (cornersType[3] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.Right - rc.Width / 2 - offset, rc.Y, rc.Width / 2 + offset, rc.Height); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[1]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.Right - rc.Width / 2 - offset, rc.Y, rc.Width / 2 + offset, rc.Height); g.FillRectangle(Brushes.Black, rc1); } effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, sideWidth, height - sideWidth, new Rectangle(sideWidth, bottomHeight - sideWidth, bottomWidth - sideWidth * 2, sideWidth), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); //// int leftWidth = sideWidth + r; int leftHeight = height; bitmap = new Bitmap(leftWidth, leftHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(sideWidth, sideWidth, r, leftHeight - sideWidth * 2); if (cornersType[0] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Y, rc.Width, rc.Height / 2 + offset); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[0]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Y, rc.Width, rc.Height / 2 + offset); g.FillRectangle(Brushes.Black, rc1); } if (cornersType[2] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Bottom - rc.Height / 2 - offset, rc.Width, rc.Height / 2 + offset); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[2]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Bottom - rc.Height / 2 - offset, rc.Width, rc.Height / 2 + offset); g.FillRectangle(Brushes.Black, rc1); } effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, 0, sideWidth, new Rectangle(0, sideWidth, sideWidth, leftHeight - sideWidth * 2), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); //// int rightWidth = sideWidth + r; int rightHeight = height; bitmap = new Bitmap(leftWidth, leftHeight); g = Graphics.FromImage(bitmap); rc = new Rectangle(0, sideWidth, r, rightHeight - sideWidth * 2); if (cornersType[1] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Y, rc.Width, rc.Height / 2 + offset); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[1]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Y, rc.Width, rc.Height / 2 + offset); g.FillRectangle(Brushes.Black, rc1); } if (cornersType[3] == 1) { g.SmoothingMode = SmoothingMode.HighQuality; rc1 = new Rectangle(rc.X, rc.Bottom - rc.Height / 2 - offset, rc.Width, rc.Height / 2 + offset); path = DrawUtils.CreateRoundedRectanglePath(rc1, cornersRadius[3]); g.FillPath(Brushes.Black, path); } else { rc1 = new Rectangle(rc.X, rc.Bottom - rc.Height / 2 - offset, rc.Width, rc.Height / 2 + offset); g.FillRectangle(Brushes.Black, rc1); } effectBitmap = gs.ProcessImage(bitmap); baseg.DrawImage(effectBitmap, width - sideWidth, sideWidth, new Rectangle(leftWidth - sideWidth, sideWidth, sideWidth, leftHeight - sideWidth * 2), GraphicsUnit.Pixel); g.Dispose(); bitmap.Dispose(); baseg.Dispose(); }