/// <param name="index">Index of the skin layer state to draw.</param> /// <param name="color">Color tint to apply to the skin layer.</param> /// <param name="rect">Destination region where the layer will be drawn.</param> /// <param name="layer">Skin layer to draw.</param> /// <summary> /// Draws a skin layer in the specified region. /// </summary> public virtual void DrawLayer(SkinLayer layer, Rectangle rect, Color color, int index) { // Get the size of the layer image asset and the size of the layer itself. var imageSize = new Size(layer.Image.Resource.Width, layer.Image.Resource.Height); var partSize = new Size(layer.Width, layer.Height); // Draw each section of the layer asset. Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.TopLeft), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.TopLeft, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.TopCenter), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.TopCenter, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.TopRight), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.TopRight, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.MiddleLeft), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.MiddleLeft, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.MiddleCenter), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.MiddleCenter, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.MiddleRight), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.MiddleRight, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.BottomLeft), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.BottomLeft, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.BottomCenter), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.BottomCenter, index), color); Draw(layer.Image.Resource, GetDestinationArea(rect, layer.SizingMargins, Alignment.BottomRight), GetSourceArea(imageSize, partSize, layer.SizingMargins, Alignment.BottomRight, index), color); }
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { //base.DrawControl(renderer, rect, gameTime); var s = new SkinLayer(Skin.Layers[0]); s.Text.Alignment = alignment; renderer.DrawString(this, s, Text, rect, true, 0, 0, ellipsis); }
protected override Rectangle DrawText(Renderer renderer, Rectangle rect, SkinLayer layer, int ox, int oy) { // Draw the button text. layer.Text.Font = Manager.Skin.Fonts["Default9"]; renderer.DrawString(this, layer, Title, rect, true, ox, 0, base.DrawFormattedText); layer.Text.Font = Manager.Skin.Fonts["Default8"]; renderer.DrawString(this, layer, Text, rect, true, ox, 14, base.DrawFormattedText); return(rect); }
/// <summary> /// Draws the list pane containing the collection items. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void DrawPane(object sender, DrawEventArgs e) { // Collection is non-empty? if (items != null && items.Count > 0) { SkinText font = Skin.Layers["Control"].Text; SkinLayer sel = Skin.Layers["ListBox.Selection"]; int h = (items[0] as T).Height; int v = (sbVert.Value / 10); int p = (sbVert.PageSize / 10); int d = (int)(((sbVert.Value % 10) / 10f) * h); int c = items.Count; int s = itemIndex; // Draw selection overlay? if (s >= 0 && s < c && (Focused || !hideSelection)) { int pos = -d + ((s - v) * h); // Selected index is visible? if (pos > -h && pos < (p + 1) * h) { e.Renderer.DrawLayer(this, sel, new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, h)); } } // Draw the visible collection items in the list pane. for (int i = v; i <= v + p + 1; i++) { if (i < c) { if (i < items.Count) { foreach (Control ctr in (items[i] as T).Controls) { ctr.DrawControl(e.Renderer, new Rectangle(e.Rectangle.Left + ctr.Left, (e.Rectangle.Top - d + ((i - v) * h)) + ctr.Top, e.Rectangle.Width, h), e.GameTime); } } } } // Draw selection overlay? if (s >= 0 && s < c && (Focused || !hideSelection)) { int pos = -d + ((s - v) * h); // Selected index is visible? if (pos > -h && pos < (p + 1) * h) { e.Renderer.DrawLayer(sel, new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, h), Color.White * .2f, 0); } } } }
public override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { //base.DrawControl(renderer, rect, gameTime); var s = new SkinLayer(Skin.Layers[0]); s.Text.Alignment = alignment; if (Shadow) { textColor = Color.Black; rect.X += 1; rect.Y += 1; renderer.DrawString(this, s, Renderer.StripFormattedText(Text), rect, true, 0, 0, ellipsis, false); rect.X -= 1; rect.Y -= 1; textColor = Color.White; } renderer.DrawString(this, s, Text, rect, true, 0, 0, ellipsis, DrawFormattedText); }
/// <summary> /// Updates the position of the slider button. /// </summary> private void RecalcParams() { // The slider button is created? if (btnSlider != null) { // Width of the slider is large enough to fit a glyph on? if (btnSlider.Width > 12) { // Reload the glyph and center it on the button. btnSlider.Glyph = new Glyph(Manager.Skin.Images["Shared.Glyph"].Resource); btnSlider.Glyph.SizeMode = SizeMode.Centered; } else { btnSlider.Glyph = null; } SkinLayer p = Skin.Layers["Control"]; btnSlider.Width = (int)(Height * 0.8); btnSlider.Height = Height; int size = btnSlider.Width; int w = Width - p.ContentMargins.Horizontal - size; // Determine the position of the slider button. float px = (float)range / (float)w; int pos = p.ContentMargins.Left + (int)(Math.Ceiling(Hue / (float)px)); // Clamp position within the bounds of the track bar control. if (pos < p.ContentMargins.Left) { pos = p.ContentMargins.Left; } if (pos > w + p.ContentMargins.Left) { pos = w + p.ContentMargins.Left; } btnSlider.SetPosition(pos, 0); } }
public SkinLayer(SkinLayer source) : base(source) { if (source != null) { Image = new SkinImage(source.Image); Width = source.Width; Height = source.Height; OffsetX = source.OffsetX; OffsetY = source.OffsetY; Alignment = source.Alignment; SizingMargins = source.SizingMargins; ContentMargins = source.ContentMargins; States = source.States; Overlays = source.Overlays; Text = new SkinText(source.Text); Attributes = new SkinList <SkinAttribute>(source.Attributes); } else { throw new Exception("Parameter for SkinLayer copy constructor cannot be null."); } }
/// <summary> /// Handles slider button move events. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void btnSlider_Move(object sender, MoveEventArgs e) { SkinLayer p = Skin.Layers["Control"]; int size = btnSlider.Width; int w = Width - p.ContentMargins.Horizontal - size; int pos = e.Left; // Keep button on track by clamping position values.. if (pos < p.ContentMargins.Left) { pos = p.ContentMargins.Left; } if (pos > w + p.ContentMargins.Left) { pos = w + p.ContentMargins.Left; } // Update button position and value. btnSlider.SetPosition(pos, 0); float px = (float)range / (float)w; Hue = (int)(Math.Ceiling((pos - p.ContentMargins.Left) * px)); }
/// <param name="l"></param> /// <param name="sl"></param> /// </summary> /// </summary> private void LoadLayerAttributes(SkinLayer sl, XmlNodeList l) { foreach (XmlElement e in l) { var name = ReadAttribute(e, "Name", null, true); var sa = sl.Attributes[name]; var inh = true; if (sa == null) { sa = new SkinAttribute(); inh = false; } sa.Name = name; ReadAttribute(ref sa.Value, inh, e, "Value", null, true); if (!inh) { sl.Attributes.Add(sa); } } }
/// <summary> /// Draws the track bar control. /// </summary> /// <param name="renderer">Render management object.</param> /// <param name="rect">Destination region where the control will be drawn.</param> /// <param name="gameTime">Snapshot of the application's timing values.</param> public override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { RecalcParams(); SkinLayer p = Skin.Layers["Control"]; SkinLayer l = Skin.Layers["Scale"]; // Scales down the height of the track bar to allow room for the scale to be drawn. float ratio = 0.66f; int h = (int)(ratio * rect.Height); int t = rect.Top + (Height - h) / 2; float px = ((float)range /*value*/ / (float)range); int w = (int)Math.Ceiling(px * (rect.Width - p.ContentMargins.Horizontal)) + 2; // NOTE: Should this be using horizontal sizing margins? if (w < l.SizingMargins.Vertical) { w = l.SizingMargins.Vertical; } if (w > rect.Width - p.ContentMargins.Horizontal) { w = rect.Width - p.ContentMargins.Horizontal; } // Create the region for the track bar scale. Rectangle r1 = new Rectangle(rect.Left + p.ContentMargins.Left, t + p.ContentMargins.Top, w, h - p.ContentMargins.Vertical); base.DrawControl(renderer, new Rectangle(rect.Left, t, rect.Width, h), gameTime); if (scale) { renderer.DrawLayer(this, l, r1); } }
// currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, bool margins) { DrawString(control, layer, text, rect, margins, 0, 0, true); }
/// <param name="l"></param> /// <param name="sc"></param> /// </summary> /// </summary> private void LoadLayers(SkinControl sc, XmlNodeList l) { foreach (XmlElement e in l) { var name = ReadAttribute(e, "Name", null, true); var over = ReadAttributeBool(e, "Override", false, false); var sl = sc.Layers[name]; var inh = true; if (sl == null) { sl = new SkinLayer(); inh = false; } if (inh && over) { sl = new SkinLayer(); sc.Layers[name] = sl; } ReadAttribute(ref sl.Name, inh, e, "Name", null, true); ReadAttribute(ref sl.Image.Name, inh, e, "Image", "Control", false); ReadAttributeInt(ref sl.Width, inh, e, "Width", 0, false); ReadAttributeInt(ref sl.Height, inh, e, "Height", 0, false); var tmp = sl.Alignment.ToString(); ReadAttribute(ref tmp, inh, e, "Alignment", "MiddleCenter", false); sl.Alignment = (Alignment)Enum.Parse(typeof(Alignment), tmp, true); ReadAttributeInt(ref sl.OffsetX, inh, e, "OffsetX", 0, false); ReadAttributeInt(ref sl.OffsetY, inh, e, "OffsetY", 0, false); ReadAttributeInt(ref sl.SizingMargins.Left, inh, e["SizingMargins"], "Left", 0, false); ReadAttributeInt(ref sl.SizingMargins.Top, inh, e["SizingMargins"], "Top", 0, false); ReadAttributeInt(ref sl.SizingMargins.Right, inh, e["SizingMargins"], "Right", 0, false); ReadAttributeInt(ref sl.SizingMargins.Bottom, inh, e["SizingMargins"], "Bottom", 0, false); ReadAttributeInt(ref sl.ContentMargins.Left, inh, e["ContentMargins"], "Left", 0, false); ReadAttributeInt(ref sl.ContentMargins.Top, inh, e["ContentMargins"], "Top", 0, false); ReadAttributeInt(ref sl.ContentMargins.Right, inh, e["ContentMargins"], "Right", 0, false); ReadAttributeInt(ref sl.ContentMargins.Bottom, inh, e["ContentMargins"], "Bottom", 0, false); if (e["States"] != null) { ReadAttributeInt(ref sl.States.Enabled.Index, inh, e["States"]["Enabled"], "Index", 0, false); var di = sl.States.Enabled.Index; ReadAttributeInt(ref sl.States.Hovered.Index, inh, e["States"]["Hovered"], "Index", di, false); ReadAttributeInt(ref sl.States.Pressed.Index, inh, e["States"]["Pressed"], "Index", di, false); ReadAttributeInt(ref sl.States.Focused.Index, inh, e["States"]["Focused"], "Index", di, false); ReadAttributeInt(ref sl.States.Disabled.Index, inh, e["States"]["Disabled"], "Index", di, false); ReadAttributeColor(ref sl.States.Enabled.Color, inh, e["States"]["Enabled"], "Color", Color.White, false); var dc = sl.States.Enabled.Color; ReadAttributeColor(ref sl.States.Hovered.Color, inh, e["States"]["Hovered"], "Color", dc, false); ReadAttributeColor(ref sl.States.Pressed.Color, inh, e["States"]["Pressed"], "Color", dc, false); ReadAttributeColor(ref sl.States.Focused.Color, inh, e["States"]["Focused"], "Color", dc, false); ReadAttributeColor(ref sl.States.Disabled.Color, inh, e["States"]["Disabled"], "Color", dc, false); ReadAttributeBool(ref sl.States.Enabled.Overlay, inh, e["States"]["Enabled"], "Overlay", false, false); var dv = sl.States.Enabled.Overlay; ReadAttributeBool(ref sl.States.Hovered.Overlay, inh, e["States"]["Hovered"], "Overlay", dv, false); ReadAttributeBool(ref sl.States.Pressed.Overlay, inh, e["States"]["Pressed"], "Overlay", dv, false); ReadAttributeBool(ref sl.States.Focused.Overlay, inh, e["States"]["Focused"], "Overlay", dv, false); ReadAttributeBool(ref sl.States.Disabled.Overlay, inh, e["States"]["Disabled"], "Overlay", dv, false); } if (e["Overlays"] != null) { ReadAttributeInt(ref sl.Overlays.Enabled.Index, inh, e["Overlays"]["Enabled"], "Index", 0, false); var di = sl.Overlays.Enabled.Index; ReadAttributeInt(ref sl.Overlays.Hovered.Index, inh, e["Overlays"]["Hovered"], "Index", di, false); ReadAttributeInt(ref sl.Overlays.Pressed.Index, inh, e["Overlays"]["Pressed"], "Index", di, false); ReadAttributeInt(ref sl.Overlays.Focused.Index, inh, e["Overlays"]["Focused"], "Index", di, false); ReadAttributeInt(ref sl.Overlays.Disabled.Index, inh, e["Overlays"]["Disabled"], "Index", di, false); ReadAttributeColor(ref sl.Overlays.Enabled.Color, inh, e["Overlays"]["Enabled"], "Color", Color.White, false); var dc = sl.Overlays.Enabled.Color; ReadAttributeColor(ref sl.Overlays.Hovered.Color, inh, e["Overlays"]["Hovered"], "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Pressed.Color, inh, e["Overlays"]["Pressed"], "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Focused.Color, inh, e["Overlays"]["Focused"], "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Disabled.Color, inh, e["Overlays"]["Disabled"], "Color", dc, false); } if (e["Text"] != null) { ReadAttribute(ref sl.Text.Name, inh, e["Text"], "Font", null, true); ReadAttributeInt(ref sl.Text.OffsetX, inh, e["Text"], "OffsetX", 0, false); ReadAttributeInt(ref sl.Text.OffsetY, inh, e["Text"], "OffsetY", 0, false); tmp = sl.Text.Alignment.ToString(); ReadAttribute(ref tmp, inh, e["Text"], "Alignment", "MiddleCenter", false); sl.Text.Alignment = (Alignment)Enum.Parse(typeof(Alignment), tmp, true); LoadColors(inh, e["Text"], ref sl.Text.Colors); } if (e["Attributes"] != null) { var l2 = e["Attributes"].GetElementsByTagName("Attribute"); if (l2 != null && l2.Count > 0) { LoadLayerAttributes(sl, l2); } } if (!inh) { sc.Layers.Add(sl); } } }
// currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, ControlState state, bool margins, int ox, int oy, bool ellipsis) { var col = Color.White; // currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: // Layer has text component defined? if (layer.Text != null) { // And it has margins? if (margins) { // Grab the layer's margins and update the destination region to account for them. var m = layer.ContentMargins; rect = new Rectangle(rect.Left + m.Left, rect.Top + m.Top, rect.Width - m.Horizontal, rect.Height - m.Vertical); } // currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: // Grab the text color of the Hovered state? if (state == ControlState.Hovered && (layer.States.Hovered.Index != -1)) { col = layer.Text.Colors.Hovered; } // Grab the text color of the Pressed state? else if (state == ControlState.Pressed) { col = layer.Text.Colors.Pressed; } // Grab the text color of the Focused state? else if (state == ControlState.Focused || (control.Focused && state == ControlState.Hovered && layer.States.Hovered.Index == -1)) { col = layer.Text.Colors.Focused; } // Grab the text color of the Disabled state? else if (state == ControlState.Disabled) { col = layer.Text.Colors.Disabled; } // Grab the text color of the Enabled state. else { col = layer.Text.Colors.Enabled; } // currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: // Valid text string supplied? if (text != null && text != "") { var font = layer.Text; if (control.TextColor != Control.UndefinedColor && control.ControlState != ControlState.Disabled) { col = control.TextColor; } DrawString(font.Font.Resource, text, rect, col, font.Alignment, font.OffsetX + ox, font.OffsetY + oy, ellipsis); } } }
// currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, bool margins, int ox, int oy, bool ellipsis) { DrawString(control, layer, text, rect, control.ControlState, margins, ox, oy, ellipsis); }
// currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, ControlState state) { DrawString(control, layer, text, rect, state, true, 0, 0, true); }
/// <param name="state">Control state to apply to the layer.</param> /// <param name="rect">Destination region where the control layer will be drawn.</param> /// <param name="layer">Skin layer of the control to draw.</param> /// <param name="control">Control to draw the layer of.</param> /// <summary> /// Draws the specified layer of the control in the defined region. /// </summary> public virtual void DrawLayer(Control control, SkinLayer layer, Rectangle rect, ControlState state) { // Get the layer color and overlay color. var c = Color.White; var oc = Color.White; // And the index to the layer and overlay image assets. var i = 0; var oi = -1; var l = layer; // Use the hovered state colors and assets? if (state == ControlState.Hovered && (layer.States.Hovered.Index != -1)) { c = l.States.Hovered.Color; i = l.States.Hovered.Index; if (l.States.Hovered.Overlay) { oc = l.Overlays.Hovered.Color; oi = l.Overlays.Hovered.Index; } } // Use the focused state colors and assets? else if (state == ControlState.Focused || (control.Focused && state == ControlState.Hovered && layer.States.Hovered.Index == -1)) { c = l.States.Focused.Color; i = l.States.Focused.Index; if (l.States.Focused.Overlay) { oc = l.Overlays.Focused.Color; oi = l.Overlays.Focused.Index; } } // Use the pressed state colors and assets? else if (state == ControlState.Pressed) { c = l.States.Pressed.Color; i = l.States.Pressed.Index; if (l.States.Pressed.Overlay) { oc = l.Overlays.Pressed.Color; oi = l.Overlays.Pressed.Index; } } // Use the disabled state colors and assets? else if (state == ControlState.Disabled) { c = l.States.Disabled.Color; i = l.States.Disabled.Index; if (l.States.Disabled.Overlay) { oc = l.Overlays.Disabled.Color; oi = l.Overlays.Disabled.Index; } } // Use the enabled state colors and assets? else { c = l.States.Enabled.Color; i = l.States.Enabled.Index; if (l.States.Enabled.Overlay) { oc = l.Overlays.Enabled.Color; oi = l.Overlays.Enabled.Index; } } if (control.Color != Control.UndefinedColor) { c = control.Color * (control.Color.A / 255f); } // Draw the control layer. DrawLayer(l, rect, c, i); // And draw the overlay if needed. if (oi != -1) { DrawLayer(l, rect, oc, oi); } }
/// <param name="rect">Destination region where the control layer will be drawn.</param> /// <param name="layer">Skin layer of the control to draw.</param> /// <param name="control">Control to draw the layer of.</param> /// <summary> /// Draws the specified layer of the control in the defined region. /// </summary> public virtual void DrawLayer(Control control, SkinLayer layer, Rectangle rect) { DrawLayer(control, layer, rect, control.ControlState); }
// currentMonster.Name, Color.Red.ToHex(true)); // string.Format("You attempt to hit the [color:#FFFF0000]{0}[/color] but [color:{1}]MISS[/color]!", // example: public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, ControlState state, bool margins, int ox, int oy) { DrawString(control, layer, text, rect, state, margins, ox, oy, true); }
protected virtual Rectangle DrawText(Renderer renderer, Rectangle rect, SkinLayer layer, int ox, int oy) { // Draw the button text. renderer.DrawString(this, layer, Text, rect, true, ox, oy, DrawFormattedText); return(rect); }