/// <summary> /// Changer la couleur /// </summary> /// <param name="color">Objet transformations de couleur</param> public void SetColor(VO_ColorTransformation color) { /*foreach (VO_Sprite sprite in _Sprites) * { * if (sprite != null) * SpriteManager.ChangeScreenSpriteColor(sprite.Id, color); * }*/ }
/// <summary> /// Renvoie une image colorée /// </summary> /// <param name="url">Url de l'image</param> /// <param name="color">Modifications de couleur</param> /// <param name="type">Type de ressource</param> /// <returns>Image</returns> public Texture2D GetColoredImage(string url, VO_ColorTransformation color, ViewerEnums.ImageResourceType type) { string serial = url + ";" + color.ToString(); if (_ColoredResources != null && _ColoredResources.ContainsKey(serial)) { return(_ColoredResources[serial]); } //Dictionnaire d'image if (_ColoredResources == null) { _ColoredResources = new Dictionary <string, Texture2D>(); } Texture2D originalImage = null; switch (type) { case ViewerEnums.ImageResourceType.Permanent: originalImage = GetPermanentImage(url); break; case ViewerEnums.ImageResourceType.Screen: originalImage = GetScreenImage(url); break; } try { //if (!color.IsUnmodifiedColor()) // ApplyColorFilters(serial, color, new Texture2D(url)); //else _ColoredResources.Add(serial, originalImage); return(_ColoredResources[serial]); } catch (InsufficientMemoryException ie) { LogTools.WriteInfo(Logs.MANAGER_MEMORY_ERROR); LogTools.WriteDebug(ie.Message); FreeScreenImages(); return(GetColoredImage(url, color, type)); } catch (Exception e) { LogTools.WriteInfo(string.Format(Logs.MANAGER_IMAGE_NOT_FOUND, url)); LogTools.WriteDebug(e.Message); _ColoredResources.Add(serial, null); } return(null); }
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) { IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; VO_ColorTransformation ct = value as VO_ColorTransformation; if (svc != null && ct != null) { using (ImageColorManager form = new ImageColorManager()) { form.OriginalColorTransformations = ct; if (svc.ShowDialog(form) == DialogResult.OK) { ct = form.OriginalColorTransformations; // update object } } } return(value); // can also replace the wrapper object here }
/// <summary> /// Applique différents paramètres de couleurs à une image en fonction de paramètres définis /// </summary> /// <param name="image">Instance de l'image</param> /// <param name="Red">Rouge</param> /// <param name="Green">Vert</param> /// <param name="Blue">Bleu</param> /// <param name="Grey">Gris</param> /// <param name="Alpha">Opacité</param> private void ApplyColorFilters(string serial, VO_ColorTransformation color, Texture2D image) { /*//Dictionnaire d'image * if (_ColoredResources == null) * _ColoredResources = new Dictionary<string, Texture2D>(); * * float alphaTouch = (float)color.Opacity / 255.0f; * if (color.Grey == 0) * { * for (uint i = 0; i < image.Width; i++) * { * for (uint j = 0; j < image.Height; j++) * { * Color pixel = image.GetPixel(i, j); * image.SetPixel(i, j, new Color(GetColorByte(pixel.R + color.Red), GetColorByte(pixel.G + color.Green), GetColorByte(pixel.B + color.Blue), GetColorByte((int)((float)pixel.A * alphaTouch)))); * } * } * } * else * { * int rat = color.Grey * 100 / 255; * //float ratGrey = rat / 100; * //float ratColor = (100 - rat) / 100; * for (uint i = 0; i < image.Width; i++) * { * for (uint j = 0; j < image.Height; j++) * { * Color pixel = image.GetPixel(i, j); * byte grayScale = GetColorByte((int)(((pixel.R + color.Red) * .33) + ((pixel.G + color.Green) * .34) + ((pixel.B + color.Blue) * .33))); * byte red = GetColorByte((int)((pixel.R + color.Red) * (100 - rat) / 100) + (int)(grayScale * rat / 100)); * byte green = GetColorByte((int)((pixel.G + color.Green) * (100 - rat) / 100) + (int)(grayScale * rat / 100)); * byte blue = GetColorByte((int)((pixel.B + color.Blue) * (100 - rat) / 100) + (int)(grayScale * rat / 100)); * image.SetPixel(i, j, new Color(red, green, GetColorByte(blue), GetColorByte((int)((float)pixel.A * alphaTouch)))); * } * } * } * LogTools.WriteDebug(string.Format(Logs.MANAGER_IMAGE_CREATED, serial, Logs.MANAGER_COLORED)); * _ColoredResources.Add(serial, image);*/ }
/// <summary> /// Charge le panneau avec les données du calque /// </summary> public void LoadPanel() { List <VO_Layer> layers = EditorHelper.Instance.GetCurrentStageInstance().ListLayers; foreach (VO_Layer layer in layers) { if (layer.Id == EditorHelper.Instance.CurrentLayer) { CurrentLayer = layer; OriginalColorTransformations = new VO_ColorTransformation(); OriginalColorTransformations.Red = layer.ColorTransformations.Red; OriginalColorTransformations.Blue = layer.ColorTransformations.Blue; OriginalColorTransformations.Green = layer.ColorTransformations.Green; OriginalColorTransformations.Grey = layer.ColorTransformations.Grey; OriginalColorTransformations.Opacity = layer.ColorTransformations.Opacity; tbRed.Value = Convert.ToInt32(layer.ColorTransformations.Red); tbGreen.Value = Convert.ToInt32(layer.ColorTransformations.Green); tbBlue.Value = Convert.ToInt32(layer.ColorTransformations.Blue); tbGrey.Value = Convert.ToInt32(layer.ColorTransformations.Grey); tbOpacity.Value = Convert.ToInt32(layer.ColorTransformations.Opacity); } } }
/// <summary> /// Changer la couleur /// </summary> /// <param name="color">Objet transformations de couleur</param> public void SetColor(VO_ColorTransformation color) { foreach (VO_AnimatedSprite[] animArray in _AnimationsStanding) { foreach (VO_AnimatedSprite anim in animArray) { anim.SetColor(color); } } foreach (VO_AnimatedSprite[] animArray in _AnimationsWalking) { foreach (VO_AnimatedSprite anim in animArray) { anim.SetColor(color); } } foreach (VO_AnimatedSprite[] animArray in _AnimationsTalking) { foreach (VO_AnimatedSprite anim in animArray) { anim.SetColor(color); } } }
/// <summary> /// Créer un sprite /// </summary> /// <param name="id">Id du sprite</param> /// <param name="url">Url de l'image</param> /// <param name="location">Location</param> /// <param name="color">Couleur</param> public static void CreateScreenSprite(Guid id, string url, Vector2 location, Rectangle source, VO_ColorTransformation color) { //Dictionnaire d'image if (_ScreenSprites == null) { _ScreenSprites = new Dictionary <Guid, VO_Sprite>(); } //Pas d'image envoyée if (id == new Guid()) { return; } //Ajout de l'image if (!_ScreenSprites.ContainsKey(id)) { try { VO_Sprite newSprite = new VO_Sprite(id); newSprite.ResourceUrl = url; newSprite.Scale = new Vector2(1.0f, 1.0f); newSprite.Image = ImageManager.CurrentStage.GetScreenImage(url); newSprite.Position = new Vector2(location.X, location.Y); newSprite.Source = source; _ScreenSprites.Add(id, newSprite); LogTools.WriteDebug(string.Format(Logs.MANAGER_SPRITE_CREATED, id, Logs.MANAGER_SCREEN)); } catch (Exception e) { LogTools.WriteInfo(string.Format(Logs.MANAGER_SPRITE_NOT_FOUND, url)); LogTools.WriteDebug(e.Message); _ScreenSprites.Add(id, null); } } }