public ComplexImageComponent(Texture tex, int x1, int y1, int x2, int y2, int u, int v, int texWidth, int texHeight, ComplexImageFlags flags) { ComplexImageFlags f; f = flags & (ComplexImageFlags.UsingLeft | ComplexImageFlags.UsingRight | ComplexImageFlags.UsingWidth); if (f == (ComplexImageFlags.UsingLeft | ComplexImageFlags.UsingRight | ComplexImageFlags.UsingWidth)) { throw new UserFriendlyException("ComplexImageComponent may not have 'left', 'right' and 'width' attributes at the same time"); } if (f == ComplexImageFlags.None) { throw new UserFriendlyException("ComplexImageComponent must have a combination of 'left'-'right', 'left'-'width' or 'right'-'width' attributes to define it's positioning"); } if (f == ComplexImageFlags.UsingLeft) { throw new UserFriendlyException("ComplexImageComponent 'right' or 'width' attribute is missing"); } if (f == ComplexImageFlags.UsingRight) { throw new UserFriendlyException("ComplexImageComponent 'left' or 'width' attribute is missing"); } if (f == ComplexImageFlags.UsingWidth) { throw new UserFriendlyException("ComplexImageComponent 'left' or 'right' attribute is missing"); } f = flags & (ComplexImageFlags.UsingBottom | ComplexImageFlags.UsingTop | ComplexImageFlags.UsingHeight); if (f == (ComplexImageFlags.UsingBottom | ComplexImageFlags.UsingTop | ComplexImageFlags.UsingHeight)) { throw new UserFriendlyException("ComplexImageComponent may not have 'bottom', 'top' and 'height' attributes at the same time"); } if (f == ComplexImageFlags.None) { throw new UserFriendlyException("ComplexImageComponent must have a combination of 'bottom'-'top', 'bottom'-'height' or 'top'-'height' attributes to define it's positioning"); } if (f == ComplexImageFlags.UsingBottom) { throw new UserFriendlyException("ComplexImageComponent 'top' or 'height' attribute is missing"); } if (f == ComplexImageFlags.UsingTop) { throw new UserFriendlyException("ComplexImageComponent 'bottom' or 'height' attribute is missing"); } if (f == ComplexImageFlags.UsingHeight) { throw new UserFriendlyException("ComplexImageComponent 'top' or 'bottom' attribute is missing"); } if (tex == null) { throw new UserFriendlyException("ComplexImageComponent is useless without a texture"); } m_X1 = x1; m_Y1 = y1; m_X2 = x2; m_Y2 = y2; m_Flags = flags; m_U1 = u; m_V1 = v; m_U2 = texWidth; m_V2 = texHeight; m_Texture = tex; // GameDebugger.Log("{0},{1}-{2},{3} [{4}]", m_X1, m_Y1, m_X2, m_Y2, m_Flags); }
public static ComplexImageComponent Load(string fileName, DomNode node, string defaultTex) { Texture tex = null; int x1 = 0, y1 = 0, x2 = 0, y2 = 0, u, v, texWidth, texHeight; ComplexImageFlags flags = ComplexImageFlags.None; if (!node["relTex"].Equals("")) { tex = Texture.Cache(node["relTex"].RelativeTo(fileName)); if (tex == null) { throw new UserFriendlyException(String.Format("Could not load the texture '{0}' for ComplexImageComponent", node["relTex"].RelativeTo(fileName))); } } else if (!node["tex"].Equals("")) { tex = Texture.Cache(node["tex"].ToPath()); if (tex == null) { throw new UserFriendlyException(String.Format("Could not load the texture '{0}' for ComplexImageComponent", node["tex"].ToPath())); } } else { tex = Texture.Cache(defaultTex); if (tex == null) { throw new UserFriendlyException(String.Format("Could not load the texture '{0}' for ComplexImageComponent", defaultTex)); } } tex.Bind(); tex.SetFilter(TextureMinFilter.Nearest, TextureMagFilter.Nearest); if (!node["width"].Equals("")) { flags |= ComplexImageFlags.UsingWidth; x2 = node["width"].ToInt32(0); } if (!node["left"].Equals("")) { flags |= ComplexImageFlags.UsingLeft; x1 = node["left"].ToInt32(0); } if (!node["right"].Equals("")) { flags |= ComplexImageFlags.UsingRight; if ((flags & ComplexImageFlags.UsingWidth) == ComplexImageFlags.UsingWidth) { x1 = node["right"].ToInt32(0); } else { x2 = node["right"].ToInt32(0); } } if (node["tilex"].Equals("true") || node["tilex"].Equals("yes") || node["tilex"].Equals("on") || node["tilex"].Equals("1")) { flags |= ComplexImageFlags.TileHorizontal; } if (!node["height"].Equals("")) { flags |= ComplexImageFlags.UsingHeight; y2 = node["height"].ToInt32(0); } if (!node["bottom"].Equals("")) { flags |= ComplexImageFlags.UsingBottom; y1 = node["bottom"].ToInt32(0); } if (!node["top"].Equals("")) { flags |= ComplexImageFlags.UsingTop; if ((flags & ComplexImageFlags.UsingHeight) == ComplexImageFlags.UsingHeight) { y1 = node["top"].ToInt32(0); } else { y2 = node["top"].ToInt32(0); } } if (node["tiley"].Equals("true") || node["tiley"].Equals("yes") || node["tiley"].Equals("on") || node["tiley"].Equals("1")) { flags |= ComplexImageFlags.TileVertical; } u = node["u"].ToInt32(0); v = node["v"].ToInt32(0); texWidth = node["texwidth"].ToInt32(tex.Width); texHeight = node["texheight"].ToInt32(tex.Height); return(new ComplexImageComponent(tex, x1, y1, x2, y2, u, v, texWidth, texHeight, flags)); }