public void OnEnable() { var pattern = GridTexture.CreatePattern(1 << 7); var users = GetUsers(); foreach (var u in users) { u.Texture = pattern; } }
public override Size GetRealSize() { if (this.GetActualTexture() is GridTexture) { GridTexture tex = (GridTexture)this.GetActualTexture(); return(new Size( this.Size.Width * this.Scale.Width * tex.xCount, this.Size.Height * this.Scale.Height * tex.yCount)); } return(base.GetRealSize()); }
/// <summary> /// Gets start position of an object /// </summary> public Vector2D GetStartPosition() { float decreaseLeft = 0; float decreaseTop = 0; Texture actualTexture = this.GetActualTexture(); if (actualTexture is RegularTexture || actualTexture is ColorTexture) { decreaseLeft -= this.Scale.Width * this.Size.Width / 2; decreaseTop -= this.Scale.Height * this.Size.Height / 2; } else if (actualTexture is GridTexture) { GridTexture tex = (GridTexture)this.GetActualTexture(); decreaseLeft -= this.Scale.Width * this.Size.Width * tex.xCount / 2; decreaseTop -= this.Scale.Height * this.Size.Height * tex.yCount / 2; } Vector2D decrease = new Vector2D(decreaseLeft, decreaseTop); return(this.GetNonRotatedGlobalPosition() + decrease); }
public static void LoadConfig(string path) { dynamic val = ReadConfigFile(path); try { var a = val["Image"]["Regular"]; var b = val["Image"]["Grid"]; var c = val["Other"]["Color"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } foreach (Dictionary <string, object> dict in val["Image"]["Regular"]) { string name; string p; try { name = (string)dict["Name"]; p = (string)dict["ImagePath"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } RegularTexture t = new RegularTexture(name, p); if (dict.ContainsKey("InterpolationMode")) { t.InterpolationMode = (System.Drawing.Drawing2D.InterpolationMode) Enum.Parse(typeof(System.Drawing.Drawing2D.InterpolationMode), (string)dict["InterpolationMode"]); } All.Add(t); } foreach (Dictionary <string, object> dict in val["Image"]["Grid"]) { string name; string p; int xc; int yc; try { name = (string)dict["Name"]; p = (string)dict["ImagePath"]; xc = (int)dict["xCount"]; yc = (int)dict["yCount"]; } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } GridTexture t = new GridTexture(name, p, xc, yc); if (dict.ContainsKey("InterpolationMode")) { t.InterpolationMode = (System.Drawing.Drawing2D.InterpolationMode) Enum.Parse(typeof(System.Drawing.Drawing2D.InterpolationMode), (string)dict["InterpolationMode"]); } All.Add(t); } foreach (Dictionary <string, object> dict in val["Other"]["Color"]) { string name; string hex; ColorTextureShape shape; try { name = (string)dict["Name"]; hex = (string)dict["HexColor"]; Dictionary <string, object> sd = (Dictionary <string, object>)dict["Size"]; shape = (ColorTextureShape)Enum.Parse(typeof(ColorTextureShape), (string)dict["ShapeString"]); } catch (Exception e) { Exception ex = new ConfigException(path + " config file is incorrect", e); Log.Exception(ex); throw ex; } ColorConverter cc = new ColorConverter(); Color c = (Color)cc.ConvertFromString(hex); All.Add(new ColorTexture(name, c, shape)); } foreach (Texture t in All) { if (t is ImageTexture) { ((ImageTexture)t).InitializeImage(); } } }