private void btnSelectGradient_Click(object sender, EventArgs e)
 {
     using (var gradient = new GradientMaker(Config.GradientMakerOptions))
     {
         gradient.Icon = Icon;
         if (gradient.ShowDialog() == DialogResult.OK)
         {
             Config.GradientMakerOptions = gradient.Options;
             TestWatermark();
         }
     }
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        GradientMaker g = (GradientMaker)target;
        if (GUILayout.Button("Generate"))
        {
            Texture2D newTex;
            float imgW = g.imgReference.gameObject.GetComponent<RectTransform>().rect.width;
            float imgH = g.imgReference.gameObject.GetComponent<RectTransform>().rect.height;
            int iImgW = Mathf.RoundToInt(imgW);
            int iImgH = Mathf.RoundToInt(imgH);
            newTex = new Texture2D(Mathf.RoundToInt(imgW), Mathf.RoundToInt(imgH));

            Color[] evalColors;
            if (g.gradDirection == GradientMaker.Direction.LeftToRight)
            {
                for (int i = 0; i < iImgW; i++)
                {
                    evalColors = new Color[iImgH];
                    for (int j = 0; j < iImgH; j++)
                    {
                        evalColors[j] = g.grad.Evaluate((i * 1.0f) / imgW);
                        //newTex.SetPixel(i, j, g.grad.Evaluate(i / iImgW));
                    }
                    newTex.SetPixels(i, 0, 1, iImgH, evalColors);
                }

            }
            else if (g.gradDirection == GradientMaker.Direction.DownToUp)

                for (int i = 0; i < iImgH; i++)
                {
                    evalColors = new Color[iImgW];
                    for (int j = 0; j < iImgW; j++)
                    {
                        evalColors[j] = g.grad.Evaluate((i * 1.0f) / imgH);
                        //newTex.SetPixel(i, j, g.grad.Evaluate(i / iImgW));
                    }
                    newTex.SetPixels(0, i, iImgW, 1, evalColors);
                }



            newTex.Apply();

            g.imgReference.sprite = Sprite.Create(newTex, new Rect(0f, 0f, imgW, imgH), new Vector2(0, 0));

        }
    }
Exemplo n.º 3
0
                public LoadingAnimation(int width, int height, UIColor baseColor = null)
                {
                    StartingRect = new CGRect(0 - width, 0, width, height);

                    if (baseColor == null)
                    {
                        baseColor = UIColor.Blue;
                    }

                    var gradientLayer = GradientMaker.Make(baseColor, StartingRect);

                    Layer.AddSublayer(gradientLayer);
                    Layer.MasksToBounds = true;
                    Layer.Bounds        = StartingRect;
                    ResetFrame();
                }
Exemplo n.º 4
0
	public override void OnInspectorGUI(){
		DrawDefaultInspector();
		gradEdit = (GradientMaker)target;
		
		EditorGUIUtility.LookLikeControls();
		//// Gradient GUI element is being provided by GradientEditor class as it's an internal UI element
		
		// Gradient Options
		gradEdit._invertGradient = EditorGUILayout.Toggle("Invert Gradient", gradEdit._invertGradient);
		gradEdit.gradType = (GradType)EditorGUILayout.EnumPopup ("Gradient Type", gradEdit.gradType);
		
		// Gradient Falloff
		if(gradEdit.gradType == GradType.Radial){
			GUILayout.BeginHorizontal();
				string falloff = EditorGUILayout.TextField("Radial Gradient Falloff", gradEdit._radialGradientFalloff.ToString());
				float.TryParse(falloff, out gradEdit._radialGradientFalloff);
				gradEdit._radialGradientFalloff = GUILayout.HorizontalSlider(gradEdit._radialGradientFalloff, 0f, 100f);
			GUILayout.EndHorizontal();
		}
		
		// Output filename
		gradEdit._fileName = EditorGUILayout.TextField("Output Filename",gradEdit._fileName);
		gradEdit._overWriteExisting = EditorGUILayout.Toggle("Overwrite existing", gradEdit._overWriteExisting);

		// Gradient output size/aspect
		EditorGUILayout.BeginHorizontal();
			if(gradEdit._fixedAspect){
				EditorGUILayout.PrefixLabel("Gradient Size");
			} else {
				EditorGUILayout.PrefixLabel("Gradient Width");
			}
			string gradSizeX = EditorGUILayout.TextField(gradEdit._gradientSizeX.ToString());
			int.TryParse(gradSizeX, out gradEdit._gradientSizeX);
			EditorGUILayout.PrefixLabel("px");
		EditorGUILayout.EndHorizontal();

		if(gradEdit._fixedAspect){
			gradEdit._gradientSizeY = gradEdit._gradientSizeX;
		} else {
			string gradSizeY = EditorGUILayout.TextField("Gradient Height",gradEdit._gradientSizeY.ToString());
			int.TryParse(gradSizeY, out gradEdit._gradientSizeY);
		}

		// Set parammeters of gradient preview area
		GUILayoutOption[] guioptions = new GUILayoutOption[2];
		guioptions[0] = GUILayout.Height(Mathf.Clamp(gradEdit._gradientSizeX,gradEdit._gradientSizeX, 256));
        guioptions[1] = GUILayout.Width(Mathf.Clamp(gradEdit._gradientSizeX,gradEdit._gradientSizeX, 256));
		
		GUIStyle previewStyle = new GUIStyle();
		
		previewStyle.alignment = TextAnchor.MiddleCenter;
		
		// Load checker pattern for preview area
	
		string path = null;
		
		if(Application.platform == RuntimePlatform.OSXEditor){
			path = Application.dataPath + "/GradientMaker/";
		} else if (Application.platform == RuntimePlatform.WindowsEditor){
			path = Application.dataPath + "\\GradientMaker\\";		
		} 
		
		byte[] rawChecker = File.ReadAllBytes(path + "Checker.png");
		Texture2D checker = new Texture2D(gradEdit._gradientSizeX, gradEdit._gradientSizeY);
		checker.LoadImage(rawChecker);
		
		// Draw prewiew area
		GUILayout.BeginHorizontal(checker, previewStyle, guioptions);
            GUILayout.Label(gradEdit.outTexture, guioptions);
		GUILayout.EndHorizontal();
		
		GUILayout.BeginHorizontal();
			if(GUILayout.Button("Save Gradient")){
				gradEdit.InitProcessGradient(false);
			}
		GUILayout.EndHorizontal();
		
		// Update preview if nessisary
		if(GUI.changed || gradEdit.GradientChanged()){
			Undo.RecordObject(this, "Gradient Changed");
			gradEdit.InitProcessGradient(true);
			EditorUtility.SetDirty (target);
		}
	}
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        gradEdit = (GradientMaker)target;

        EditorGUIUtility.LookLikeControls();
        //// Gradient GUI element is being provided by GradientEditor class as it's an internal UI element

        // Gradient Options
        gradEdit._invertGradient = EditorGUILayout.Toggle("Invert Gradient", gradEdit._invertGradient);
        gradEdit.gradType        = (GradType)EditorGUILayout.EnumPopup("Gradient Type", gradEdit.gradType);

        // Gradient Falloff
        if (gradEdit.gradType == GradType.Radial)
        {
            GUILayout.BeginHorizontal();
            string falloff = EditorGUILayout.TextField("Radial Gradient Falloff", gradEdit._radialGradientFalloff.ToString());
            float.TryParse(falloff, out gradEdit._radialGradientFalloff);
            gradEdit._radialGradientFalloff = GUILayout.HorizontalSlider(gradEdit._radialGradientFalloff, 0f, 100f);
            GUILayout.EndHorizontal();
        }

        // Output filename
        gradEdit._fileName          = EditorGUILayout.TextField("Output Filename", gradEdit._fileName);
        gradEdit._overWriteExisting = EditorGUILayout.Toggle("Overwrite existing", gradEdit._overWriteExisting);

        // Gradient output size/aspect
        EditorGUILayout.BeginHorizontal();
        if (gradEdit._fixedAspect)
        {
            EditorGUILayout.PrefixLabel("Gradient Size");
        }
        else
        {
            EditorGUILayout.PrefixLabel("Gradient Width");
        }
        string gradSizeX = EditorGUILayout.TextField(gradEdit._gradientSizeX.ToString());

        int.TryParse(gradSizeX, out gradEdit._gradientSizeX);
        EditorGUILayout.PrefixLabel("px");
        EditorGUILayout.EndHorizontal();

        if (gradEdit._fixedAspect)
        {
            gradEdit._gradientSizeY = gradEdit._gradientSizeX;
        }
        else
        {
            string gradSizeY = EditorGUILayout.TextField("Gradient Height", gradEdit._gradientSizeY.ToString());
            int.TryParse(gradSizeY, out gradEdit._gradientSizeY);
        }

        // Set parammeters of gradient preview area
        GUILayoutOption[] guioptions = new GUILayoutOption[2];
        guioptions[0] = GUILayout.Height(Mathf.Clamp(gradEdit._gradientSizeX, gradEdit._gradientSizeX, 256));
        guioptions[1] = GUILayout.Width(Mathf.Clamp(gradEdit._gradientSizeX, gradEdit._gradientSizeX, 256));

        GUIStyle previewStyle = new GUIStyle();

        previewStyle.alignment = TextAnchor.MiddleCenter;

        // Load checker pattern for preview area

        string path = null;

        if (Application.platform == RuntimePlatform.OSXEditor)
        {
            path = Application.dataPath + "/GradientMaker/";
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = Application.dataPath + "\\GradientMaker\\";
        }

        byte[]    rawChecker = File.ReadAllBytes(path + "Checker.png");
        Texture2D checker    = new Texture2D(gradEdit._gradientSizeX, gradEdit._gradientSizeY);

        checker.LoadImage(rawChecker);

        // Draw prewiew area
        GUILayout.BeginHorizontal(checker, previewStyle, guioptions);
        GUILayout.Label(gradEdit.outTexture, guioptions);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Save Gradient"))
        {
            gradEdit.InitProcessGradient(false);
        }
        GUILayout.EndHorizontal();

        // Update preview if nessisary
        if (GUI.changed || gradEdit.GradientChanged())
        {
            Undo.RecordObject(this, "Gradient Changed");
            gradEdit.InitProcessGradient(true);
            EditorUtility.SetDirty(target);
        }
    }
        private static Image DrawWatermark(Image img, string drawText)
        {
            if (!string.IsNullOrEmpty(drawText))
            {
                if (0 == Engine.conf.WatermarkFont.Size)
                {
                    Adapter.ShowFontDialog();
                }
                try
                {
                    int   offset        = (int)Engine.conf.WatermarkOffset;
                    Font  font          = XMLSettings.DeserializeFont(Engine.conf.WatermarkFont);
                    Size  textSize      = TextRenderer.MeasureText(drawText, font);
                    Size  labelSize     = new Size(textSize.Width + 10, textSize.Height + 10);
                    Point labelPosition = FindPosition(Engine.conf.WatermarkPositionMode, offset, img.Size,
                                                       new Size(textSize.Width + 10, textSize.Height + 10), 1);
                    if (Engine.conf.WatermarkAutoHide && ((img.Width < labelSize.Width + offset) ||
                                                          (img.Height < labelSize.Height + offset)))
                    {
                        return(img);
                        //throw new Exception("Image size smaller than watermark size.");
                    }
                    Rectangle    labelRectangle = new Rectangle(Point.Empty, labelSize);
                    GraphicsPath gPath          = RoundedRectangle.Create(labelRectangle, (int)Engine.conf.WatermarkCornerRadius);

                    int      backTrans = (int)Engine.conf.WatermarkBackTrans;
                    int      fontTrans = (int)Engine.conf.WatermarkFontTrans;
                    Color    fontColor = XMLSettings.DeserializeColor(Engine.conf.WatermarkFontColor);
                    Bitmap   bmp       = new Bitmap(labelRectangle.Width + 1, labelRectangle.Height + 1);
                    Graphics g         = Graphics.FromImage(bmp);
                    g.SmoothingMode     = SmoothingMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
                    LinearGradientBrush brush;
                    if (Engine.conf.WatermarkUseCustomGradient)
                    {
                        brush = GradientMaker.CreateGradientBrush(labelRectangle.Size, Engine.conf.GradientMakerOptions.GetBrushDataActive());
                    }
                    else
                    {
                        brush = new LinearGradientBrush(labelRectangle, Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkGradient1)),
                                                        Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkGradient2)), Engine.conf.WatermarkGradientType);
                    }
                    g.FillPath(brush, gPath);
                    g.DrawPath(new Pen(Color.FromArgb(backTrans, XMLSettings.DeserializeColor(Engine.conf.WatermarkBorderColor))), gPath);
                    StringFormat sf = new StringFormat {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    };
                    g.DrawString(drawText, font, new SolidBrush(Color.FromArgb(fontTrans, fontColor)), bmp.Width / 2, bmp.Height / 2, sf);
                    Graphics gImg = Graphics.FromImage(img);
                    gImg.SmoothingMode = SmoothingMode.HighQuality;
                    gImg.DrawImage(bmp, labelPosition);
                    if (Engine.conf.WatermarkAddReflection)
                    {
                        Bitmap bmp2 = AddReflection(bmp, 50, 200);
                        gImg.DrawImage(bmp2, new Rectangle(labelPosition.X, labelPosition.Y + bmp.Height - 1, bmp2.Width, bmp2.Height));
                    }
                }
                catch (Exception ex)
                {
                    FileSystem.AppendDebug("Errow while drawing watermark", ex);
                }
            }

            return(img);
        }