//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void DrawPane(object sender, DrawEventArgs e) { if (items != null && items.Count > 0) { SkinText font = Skin.Layers["Control"].Text; SkinLayer sel = Skin.Layers["ListBox.Selection"]; int h = (int)font.Font.Resource.MeasureString(items[0].ToString()).Y; 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; for (int i = v; i <= v + p + 1; i++) { if (i < c) { e.Renderer.DrawString(this, Skin.Layers["Control"], items[i].ToString(), new Rectangle(e.Rectangle.Left, e.Rectangle.Top - d + ((i - v) * h), e.Rectangle.Width, h), false); } } if (s >= 0 && s < c && (Focused || !hideSelection)) { int pos = -d + ((s - v) * h); 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)); e.Renderer.DrawString(this, sel, items[s].ToString(), new Rectangle(e.Rectangle.Left, e.Rectangle.Top + pos, e.Rectangle.Width, h), false); } } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// void btnSlider_Move(object sender, MoveEventArgs e) { SkinLayer p = Skin.Layers["Control"]; int size = btnSlider.Width; int w = Width - p.ContentMargins.Horizontal - size; // Slider Button Visibility - if not visible change track length if (!btnSlider.Visible) { w = Width - p.ContentMargins.Horizontal; } int pos = e.Left; if (pos < p.ContentMargins.Left) { pos = p.ContentMargins.Left; } if (pos > w + p.ContentMargins.Left) { pos = w + p.ContentMargins.Left; } btnSlider.SetPosition(pos, 0); float px = (float)range / (float)w; Value = (int)(Math.Ceiling((pos - p.ContentMargins.Left) * px)); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void RecalcParams() { if (btnSlider != null) { if (btnSlider.Width > 12) { 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; float px = (float)range / (float)w; int pos = p.ContentMargins.Left + (int)(Math.Ceiling(Value / (float)px)); if (pos < p.ContentMargins.Left) { pos = p.ContentMargins.Left; } if (pos > w + p.ContentMargins.Left) { pos = w + p.ContentMargins.Left; } btnSlider.SetPosition(pos, 0); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { RecalcParams(); SkinLayer p = Skin.Layers["Control"]; SkinLayer l = Skin.Layers["Scale"]; float ratio = 0.66f; int h = (int)(ratio * rect.Height); int t = rect.Top + (Height - h) / 2; float px = ((float)value / (float)range); int w = (int)Math.Ceiling(px * (rect.Width - p.ContentMargins.Horizontal - btnSlider.Width)) + 2; if (w < l.SizingMargins.Vertical) { w = l.SizingMargins.Vertical; } if (w > rect.Width - p.ContentMargins.Horizontal) { w = rect.Width - p.ContentMargins.Horizontal; } 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); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer l1 = Skin.Layers["Control"]; SkinLayer l2 = Skin.Layers["Header"]; Color col = this.Color != UndefinedColor ? this.Color : Color.White; Rectangle r1 = new Rectangle(rect.Left, rect.Top + l1.OffsetY, rect.Width, rect.Height - l1.OffsetY); if (tabPages.Count <= 0) { r1 = rect; } base.DrawControl(renderer, r1, gameTime); if (tabPages.Count > 0) { Rectangle prev = new Rectangle(rect.Left, rect.Top + l2.OffsetY, 0, l2.Height); for (int i = 0; i < tabPages.Count; i++) { SpriteFont font = l2.Text.Font.Resource; Margins margins = l2.ContentMargins; Point offset = new Point(l2.OffsetX, l2.OffsetY); if (i > 0) { prev = tabPages[i - 1].HeaderRect; } tabPages[i].CalcRect(prev, font, margins, offset, i == 0); } for (int i = tabPages.Count - 1; i >= 0; i--) { int li = tabPages[i].Enabled ? l2.States.Enabled.Index : l2.States.Disabled.Index; Color lc = tabPages[i].Enabled ? l2.Text.Colors.Enabled : l2.Text.Colors.Disabled; if (i == hoveredIndex) { li = l2.States.Hovered.Index; lc = l2.Text.Colors.Hovered; } Margins m = l2.ContentMargins; Rectangle rx = tabPages[i].HeaderRect; Rectangle sx = new Rectangle(rx.Left + m.Left, rx.Top + m.Top, rx.Width - m.Horizontal, rx.Height - m.Vertical); if (i != selectedIndex) { renderer.DrawLayer(l2, rx, col, li); renderer.DrawString(l2.Text.Font.Resource, tabPages[i].Text, sx, lc, l2.Text.Alignment); } } Margins mi = l2.ContentMargins; Rectangle ri = tabPages[selectedIndex].HeaderRect; Rectangle si = new Rectangle(ri.Left + mi.Left, ri.Top + mi.Top, ri.Width - mi.Horizontal, ri.Height - mi.Vertical); renderer.DrawLayer(l2, ri, col, l2.States.Focused.Index); renderer.DrawString(l2.Text.Font.Resource, tabPages[selectedIndex].Text, si, l2.Text.Colors.Focused, l2.Text.Alignment, l2.Text.OffsetX, l2.Text.OffsetY, false); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { RecalcParams(); SkinLayer bg = Skin.Layers[strRail]; renderer.DrawLayer(bg, rect, Color.White, bg.States.Enabled.Index); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { //base.DrawControl(renderer, rect, gameTime); SkinLayer s = new SkinLayer(Skin.Layers[0]); s.Text.Alignment = alignment; renderer.DrawString(this, s, Text, rect, true, 0, 0, ellipsis); }
//////////////////////////////////////////////////////////////////////////// #endregion protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { // Draw the table column background SkinLayer l1 = Skin.Layers["Control"]; Color cl = l1.States.Enabled.Color; //renderer.DrawLayer(l1, rect, cl, 0); base.DrawControl(renderer, rect, gameTime); }
//////////////////////////////////////////////////////////////////////////// private void AdjustClientMargins() { SkinLayer layer = this.type == GroupBoxType.Normal ? this.Skin.Layers["Control"] : this.Skin.Layers["Flat"]; SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null; Vector2 size = font.MeasureString(this.Text); var cm = this.ClientMargins; cm.Top = string.IsNullOrWhiteSpace(this.Text) ? this.ClientTop : (int)size.Y; this.ClientMargins = new Margins(cm.Left, cm.Top, cm.Right, cm.Bottom); }
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { // Draw the table column background SkinLayer l1 = Skin.Layers["Control"]; Color cl = l1.States.Enabled.Color; int index = Header ? 2 : Alternate ? 1 : 0; renderer.DrawLayer(l1, rect, cl, index); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private Rectangle GetIconRect() { SkinLayer l1 = Skin.Layers[lrCaption]; SkinLayer l5 = Skin.Layers[lrIcon]; int s = l1.Height - l1.ContentMargins.Vertical; return new Rectangle(DrawingRect.Left + l1.ContentMargins.Left + l5.OffsetX, DrawingRect.Top + l1.ContentMargins.Top + l5.OffsetY, s, s); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private int LineHeight() { int h = 0; if (Items.Count > 0) { SkinLayer l = Skin.Layers["Control"]; h = (int)l.Text.Font.Resource.LineSpacing + 9; } return(h); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { BlendState bs = Manager.GraphicsDevice.BlendState; Manager.GraphicsDevice.BlendState = BlendState.NonPremultiplied; //if (this.Name == "Close.Buttom") //{ //} if (mode == ButtonMode.PushButton && pushed) { SkinLayer l = Skin.Layers[lrButton]; renderer.DrawLayer(l, rect, l.States.Pressed.Color, l.States.Pressed.Index); if (l.States.Pressed.Overlay) { renderer.DrawLayer(l, rect, l.Overlays.Pressed.Color, l.Overlays.Pressed.Index); } } else { base.DrawControl(renderer, rect, gameTime); } SkinLayer layer = Skin.Layers[lrButton]; SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null; Color col = Color.White; int ox = 0; int oy = 0; if (ControlState == ControlState.Pressed) { if (layer.Text != null) { col = layer.Text.Colors.Pressed; } ox = 1; oy = 1; } if (glyph != null) { Margins cont = layer.ContentMargins; Rectangle r = new Rectangle(rect.Left + cont.Left, rect.Top + cont.Top, rect.Width - cont.Horizontal, rect.Height - cont.Vertical); renderer.DrawGlyph(glyph, r); } else { renderer.DrawString(this, layer, Text, rect, true, ox, oy); } Manager.GraphicsDevice.BlendState = bs; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer layer = Skin.Layers["Control"]; SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null; Color col = (layer.Text != null) ? layer.Text.Colors.Enabled : Color.White; Point offset = new Point(layer.Text.OffsetX, layer.Text.OffsetY); renderer.DrawLayer(this, layer, rect); if (font != null && Text != null && Text != "") { renderer.DrawString(this, layer, Text, new Rectangle(rect.Left, rect.Top + layer.ContentMargins.Top, rect.Width, Skin.ClientMargins.Top - layer.ContentMargins.Horizontal), false, offset.X, offset.Y, false); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { base.DrawControl(renderer, rect, gameTime); if (ReadOnly && Focused) { SkinLayer lr = Skin.Layers[0]; Rectangle rc = new Rectangle(rect.Left + lr.ContentMargins.Left, rect.Top + lr.ContentMargins.Top, Width - lr.ContentMargins.Horizontal - btnDown.Width - btnUp.Width, Height - lr.ContentMargins.Vertical); renderer.Draw(Manager.Skin.Images["ListBox.Selection"].Resource, rc, Color.FromNonPremultiplied(255, 255, 255, 128)); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// internal override void Render(Renderer renderer, GameTime gameTime) { if (Visible && Shadow) { SkinControl c = Manager.Skin.Controls[skShadow]; SkinLayer l = c.Layers[lrShadow]; Color cl = Color.FromNonPremultiplied(l.States.Enabled.Color.R, l.States.Enabled.Color.G, l.States.Enabled.Color.B, Alpha); renderer.Begin(BlendingMode.Default); renderer.DrawLayer(l, new Rectangle(Left - c.OriginMargins.Left, Top - c.OriginMargins.Top, Width + c.OriginMargins.Horizontal, Height + c.OriginMargins.Vertical), cl, 0); renderer.End(); } base.Render(renderer, gameTime); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public virtual void DrawLayer(SkinLayer layer, Rectangle rect, Color color, int index) { Size imageSize = new Size(layer.Image.Resource.Width, layer.Image.Resource.Height); Size partSize = new Size(layer.Width, layer.Height); 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); }
//////////////////////////////////////////////////////////////////////////// #region //// Methods /////////// //////////////////////////////////////////////////////////////////////////// public override void Init() { base.Init(); SkinLayer l = btnClose.Skin.Layers[lrButton]; btnClose.Width = l.Width - btnClose.Skin.OriginMargins.Horizontal; btnClose.Height = l.Height - btnClose.Skin.OriginMargins.Vertical; btnClose.Left = OriginWidth - Skin.OriginMargins.Right - btnClose.Width + l.OffsetX; btnClose.Top = Skin.OriginMargins.Top + l.OffsetY; btnClose.Anchor = Anchors.Top | Anchors.Right; //SkinControl sc = new SkinControl(ClientArea.Skin); //sc.Layers[0] = Skin.Layers[lrWindow]; //ClientArea.Color = Color.Transparent; //ClientArea.BackColor = Color.Transparent; //ClientArea.Skin = sc; }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer l1 = Skin.Layers["Control"]; SkinLayer l2 = Skin.Layers["Selection"]; rs = new Rectangle[Items.Count]; renderer.DrawLayer(this, l1, rect, ControlState.Enabled); int prev = l1.ContentMargins.Left; for (int i = 0; i < Items.Count; i++) { MenuItem mi = Items[i]; int tw = (int)l1.Text.Font.Resource.MeasureString(mi.Text).X + l1.ContentMargins.Horizontal; rs[i] = new Rectangle(rect.Left + prev, rect.Top + l1.ContentMargins.Top, tw, Height - l1.ContentMargins.Vertical); prev += tw; if (ItemIndex != i) { if (mi.Enabled && Enabled) { renderer.DrawString(this, l1, mi.Text, rs[i], ControlState.Enabled, false); } else { renderer.DrawString(this, l1, mi.Text, rs[i], ControlState.Disabled, false); } } else { if (Items[i].Enabled && Enabled) { renderer.DrawLayer(this, l2, rs[i], ControlState.Enabled); renderer.DrawString(this, l2, mi.Text, rs[i], ControlState.Enabled, false); } else { renderer.DrawLayer(this, l2, rs[i], ControlState.Disabled); renderer.DrawString(this, l2, mi.Text, rs[i], ControlState.Disabled, false); } } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer layer = Skin.Layers[lrChecked]; SkinText font = Skin.Layers[lrChecked].Text; if (!state) { layer = Skin.Layers[lrCheckBox]; font = Skin.Layers[lrCheckBox].Text; } rect.Width = layer.Width; rect.Height = layer.Height; Rectangle rc = new Rectangle(rect.Left + rect.Width + 4, rect.Y, Width - (layer.Width + 4), rect.Height); renderer.DrawLayer(this, layer, rect); renderer.DrawString(this, layer, Text, rc, false, 0, 0); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public virtual void DrawString(Control control, SkinLayer layer, string text, Rectangle rect, ControlState state, bool margins, int ox, int oy, bool ellipsis) { Color col = Color.White; if (layer.Text != null) { if (margins) { Margins m = layer.ContentMargins; rect = new Rectangle(rect.Left + m.Left, rect.Top + m.Top, rect.Width - m.Horizontal, rect.Height - m.Vertical); } if (state == ControlState.Hovered && (layer.States.Hovered.Index != -1)) { col = layer.Text.Colors.Hovered; } else if (state == ControlState.Pressed) { col = layer.Text.Colors.Pressed; } else if (state == ControlState.Focused || (control.Focused && state == ControlState.Hovered && layer.States.Hovered.Index == -1)) { col = layer.Text.Colors.Focused; } else if (state == ControlState.Disabled) { col = layer.Text.Colors.Disabled; } else { col = layer.Text.Colors.Enabled; } if (text != null && text != "") { SkinText 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); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { string textnum = ""; if (numberitem < 10) { textnum = "0" + numberitem.ToString(); } else { textnum = numberitem.ToString(); } SkinLayer s = new SkinLayer(Skin.Layers[0]); renderer.Draw(backimage, rect.X, rect.Y, new Rectangle(sourceRect.X, sourceRect.Y, backimage.Width, backimage.Height), Color); if (image != null) { if (sizeMode == SizeMode.Normal) { renderer.Draw(image, rect.X, rect.Y, sourceRect, Color); } else if (sizeMode == SizeMode.Auto) { renderer.Draw(image, rect.X, rect.Y, sourceRect, Color); } else if (sizeMode == SizeMode.Stretched) { renderer.Draw(image, rect, sourceRect, Color); } else if (sizeMode == SizeMode.Centered) { int x = (rect.Width / 2) - (image.Width / 2); int y = (rect.Height / 2) - (image.Height / 2); renderer.Draw(image, x, y, sourceRect, Color); } renderer.Draw(renderer.Manager.Content.Load <Texture2D>("Content\\Temp\\slot_num"), new Rectangle(rect.X + 20, rect.Y + 22, 12, 10), Color.White); //renderer.DrawString(this, s, numberitem.ToString(), new Rectangle(rect.X + 22, rect.Y + 22, 10, 10)); renderer.DrawString(renderer.Manager.Content.Load <SpriteFont>("Content\\Fonts\\Arial"), textnum, rect.X + 22, rect.Y + 22, Color.Red); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer layer = type == GroupBoxType.Normal ? Skin.Layers["Control"] : Skin.Layers["Flat"]; SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null; Color col = (layer.Text != null) ? layer.Text.Colors.Enabled : Color.White; Point offset = new Point(layer.Text.OffsetX, layer.Text.OffsetY); Vector2 size = font.MeasureString(Text); size.Y = font.LineSpacing; Rectangle r = new Rectangle(rect.Left, rect.Top + (int)(size.Y / 2), rect.Width, rect.Height - (int)(size.Y / 2)); renderer.DrawLayer(this, layer, r); if (font != null && Text != null && Text != "") { Rectangle bg = new Rectangle(r.Left + offset.X, (r.Top - (int)(size.Y / 2)) + offset.Y, (int)size.X + layer.ContentMargins.Horizontal, (int)size.Y); renderer.DrawLayer(Manager.Skin.Controls["Control"].Layers[0], bg, new Color(64, 64, 64), 0); renderer.DrawString(this, layer, Text, new Rectangle(r.Left, r.Top - (int)(size.Y / 2), (int)(size.X), (int)size.Y), true, 0, 0, false); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { CheckLayer(Skin, "Control"); CheckLayer(Skin, "Scale"); base.DrawControl(renderer, rect, gameTime); if (Value > 0 || mode == ProgressBarMode.Infinite) { SkinLayer p = Skin.Layers["Control"]; SkinLayer l = Skin.Layers["Scale"]; Rectangle r = new Rectangle(rect.Left + p.ContentMargins.Left, rect.Top + p.ContentMargins.Top, rect.Width - p.ContentMargins.Vertical, rect.Height - p.ContentMargins.Horizontal); float perc = ((float)value / range) * 100; int w = (int)((perc / 100) * r.Width); Rectangle rx; if (mode == ProgressBarMode.Default) { if (w < l.SizingMargins.Vertical) { w = l.SizingMargins.Vertical; } rx = new Rectangle(r.Left, r.Top, w, r.Height); } else { int s = r.Left + w; if (s > r.Left + p.ContentMargins.Left + r.Width - (r.Width / 4)) { s = r.Left + p.ContentMargins.Left + r.Width - (r.Width / 4); } rx = new Rectangle(s, r.Top, (r.Width / 4), r.Height); } renderer.DrawLayer(this, l, rx); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// 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; if (pos < p.ContentMargins.Left) { pos = p.ContentMargins.Left; } if (pos > w + p.ContentMargins.Left) { pos = w + p.ContentMargins.Left; } btnSlider.SetPosition(pos, 0); float px = (float)range / (float)w; Value = (int)(Math.Ceiling((pos - p.ContentMargins.Left) * px)); }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void LoadLayerAttributes(SkinLayer sl, IEnumerable <XElement> l) { foreach (var e in l) { string name = ReadAttribute(e, "Name", null, true); SkinAttribute sa = sl.Attributes[name]; bool 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); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public SkinLayer(SkinLayer source) : base(source) { if (source != null) { this.Image = new SkinImage(source.Image); this.Width = source.Width; this.Height = source.Height; this.OffsetX = source.OffsetX; this.OffsetY = source.OffsetY; this.Alignment = source.Alignment; this.SizingMargins = source.SizingMargins; this.ContentMargins = source.ContentMargins; this.States = source.States; this.Overlays = source.Overlays; this.Text = new SkinText(source.Text); this.Attributes = new SkinList <SkinAttribute>(source.Attributes); } else { throw new Exception("Parameter for SkinLayer copy constructor cannot be null."); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public virtual void DrawLayer(Control control, SkinLayer layer, Rectangle rect, ControlState state) { Color c = Color.White; Color oc = Color.White; int i = 0; int oi = -1; SkinLayer l = layer; 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; } } 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; } } 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; } } 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; } } 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); } DrawLayer(l, rect, c, i); if (oi != -1) { DrawLayer(l, rect, oc, oi); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime) { SkinLayer l1 = captionVisible ? Skin.Layers[lrCaption] : Skin.Layers[lrFrameTop]; SkinLayer l2 = Skin.Layers[lrFrameLeft]; SkinLayer l3 = Skin.Layers[lrFrameRight]; SkinLayer l4 = Skin.Layers[lrFrameBottom]; SkinLayer l5 = Skin.Layers[lrIcon]; LayerStates s1, s2, s3, s4; SpriteFont f1 = l1.Text.Font.Resource; Color c1 = l1.Text.Colors.Enabled; if ((Focused || (Manager.FocusedControl != null && Manager.FocusedControl.Root == this.Root)) && ControlState != ControlState.Disabled) { s1 = l1.States.Focused; s2 = l2.States.Focused; s3 = l3.States.Focused; s4 = l4.States.Focused; c1 = l1.Text.Colors.Focused; } else if (ControlState == ControlState.Disabled) { s1 = l1.States.Disabled; s2 = l2.States.Disabled; s3 = l3.States.Disabled; s4 = l4.States.Disabled; c1 = l1.Text.Colors.Disabled; } else { s1 = l1.States.Enabled; s2 = l2.States.Enabled; s3 = l3.States.Enabled; s4 = l4.States.Enabled; c1 = l1.Text.Colors.Enabled; } renderer.DrawLayer(Skin.Layers[lrWindow], rect, Skin.Layers[lrWindow].States.Enabled.Color, Skin.Layers[lrWindow].States.Enabled.Index); if (borderVisible) { renderer.DrawLayer(l1, new Rectangle(rect.Left, rect.Top, rect.Width, l1.Height), s1.Color, s1.Index); renderer.DrawLayer(l2, new Rectangle(rect.Left, rect.Top + l1.Height, l2.Width, rect.Height - l1.Height - l4.Height), s2.Color, s2.Index); renderer.DrawLayer(l3, new Rectangle(rect.Right - l3.Width, rect.Top + l1.Height, l3.Width, rect.Height - l1.Height - l4.Height), s3.Color, s3.Index); renderer.DrawLayer(l4, new Rectangle(rect.Left, rect.Bottom - l4.Height, rect.Width, l4.Height), s4.Color, s4.Index); if (iconVisible && (icon != null || l5 != null) && captionVisible) { Texture2D i = (icon != null) ? icon : l5.Image.Resource; renderer.Draw(i, GetIconRect(), Color.White); } int icosize = 0; if (l5 != null && iconVisible && captionVisible) { icosize = l1.Height - l1.ContentMargins.Vertical + 4 + l5.OffsetX; } int closesize = 0; if (btnClose.Visible) { closesize = btnClose.Width - (btnClose.Skin.Layers[lrButton].OffsetX); } Rectangle r = new Rectangle(rect.Left + l1.ContentMargins.Left + icosize, rect.Top + l1.ContentMargins.Top, rect.Width - l1.ContentMargins.Horizontal - closesize - icosize, l1.Height - l1.ContentMargins.Top - l1.ContentMargins.Bottom); int ox = l1.Text.OffsetX; int oy = l1.Text.OffsetY; renderer.DrawString(f1, Text, r, c1, l1.Text.Alignment, ox, oy, true); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void LoadLayers(SkinControl sc, IEnumerable <XElement> l) { foreach (var e in l) { string name = ReadAttribute(e, "Name", null, true); bool over = ReadAttributeBool(e, "Override", false, false); SkinLayer sl = sc.Layers[name]; bool 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); string 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.Element("SizingMargins"), "Left", 0, false); ReadAttributeInt(ref sl.SizingMargins.Top, inh, e.Element("SizingMargins"), "Top", 0, false); ReadAttributeInt(ref sl.SizingMargins.Right, inh, e.Element("SizingMargins"), "Right", 0, false); ReadAttributeInt(ref sl.SizingMargins.Bottom, inh, e.Element("SizingMargins"), "Bottom", 0, false); ReadAttributeInt(ref sl.ContentMargins.Left, inh, e.Element("ContentMargins"), "Left", 0, false); ReadAttributeInt(ref sl.ContentMargins.Top, inh, e.Element("ContentMargins"), "Top", 0, false); ReadAttributeInt(ref sl.ContentMargins.Right, inh, e.Element("ContentMargins"), "Right", 0, false); ReadAttributeInt(ref sl.ContentMargins.Bottom, inh, e.Element("ContentMargins"), "Bottom", 0, false); if (e.Element("States") != null) { ReadAttributeInt(ref sl.States.Enabled.Index, inh, e.Element("States").Element("Enabled"), "Index", 0, false); int di = sl.States.Enabled.Index; ReadAttributeInt(ref sl.States.Hovered.Index, inh, e.Element("States").Element("Hovered"), "Index", di, false); ReadAttributeInt(ref sl.States.Pressed.Index, inh, e.Element("States").Element("Pressed"), "Index", di, false); ReadAttributeInt(ref sl.States.Focused.Index, inh, e.Element("States").Element("Focused"), "Index", di, false); ReadAttributeInt(ref sl.States.Disabled.Index, inh, e.Element("States").Element("Disabled"), "Index", di, false); ReadAttributeColor(ref sl.States.Enabled.Color, inh, e.Element("States").Element("Enabled"), "Color", Color.White, false); Color dc = sl.States.Enabled.Color; ReadAttributeColor(ref sl.States.Hovered.Color, inh, e.Element("States").Element("Hovered"), "Color", dc, false); ReadAttributeColor(ref sl.States.Pressed.Color, inh, e.Element("States").Element("Pressed"), "Color", dc, false); ReadAttributeColor(ref sl.States.Focused.Color, inh, e.Element("States").Element("Focused"), "Color", dc, false); ReadAttributeColor(ref sl.States.Disabled.Color, inh, e.Element("States").Element("Disabled"), "Color", dc, false); ReadAttributeBool(ref sl.States.Enabled.Overlay, inh, e.Element("States").Element("Enabled"), "Overlay", false, false); bool dv = sl.States.Enabled.Overlay; ReadAttributeBool(ref sl.States.Hovered.Overlay, inh, e.Element("States").Element("Hovered"), "Overlay", dv, false); ReadAttributeBool(ref sl.States.Pressed.Overlay, inh, e.Element("States").Element("Pressed"), "Overlay", dv, false); ReadAttributeBool(ref sl.States.Focused.Overlay, inh, e.Element("States").Element("Focused"), "Overlay", dv, false); ReadAttributeBool(ref sl.States.Disabled.Overlay, inh, e.Element("States").Element("Disabled"), "Overlay", dv, false); } if (e.Element("Overlays") != null) { ReadAttributeInt(ref sl.Overlays.Enabled.Index, inh, e.Element("Overlays").Element("Enabled"), "Index", 0, false); int di = sl.Overlays.Enabled.Index; ReadAttributeInt(ref sl.Overlays.Hovered.Index, inh, e.Element("Overlays").Element("Hovered"), "Index", di, false); ReadAttributeInt(ref sl.Overlays.Pressed.Index, inh, e.Element("Overlays").Element("Pressed"), "Index", di, false); ReadAttributeInt(ref sl.Overlays.Focused.Index, inh, e.Element("Overlays").Element("Focused"), "Index", di, false); ReadAttributeInt(ref sl.Overlays.Disabled.Index, inh, e.Element("Overlays").Element("Disabled"), "Index", di, false); ReadAttributeColor(ref sl.Overlays.Enabled.Color, inh, e.Element("Overlays").Element("Enabled"), "Color", Color.White, false); Color dc = sl.Overlays.Enabled.Color; ReadAttributeColor(ref sl.Overlays.Hovered.Color, inh, e.Element("Overlays").Element("Hovered"), "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Pressed.Color, inh, e.Element("Overlays").Element("Pressed"), "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Focused.Color, inh, e.Element("Overlays").Element("Focused"), "Color", dc, false); ReadAttributeColor(ref sl.Overlays.Disabled.Color, inh, e.Element("Overlays").Element("Disabled"), "Color", dc, false); } if (e.Element("Text") != null) { ReadAttribute(ref sl.Text.Name, inh, e.Element("Text"), "Font", null, true); ReadAttributeInt(ref sl.Text.OffsetX, inh, e.Element("Text"), "OffsetX", 0, false); ReadAttributeInt(ref sl.Text.OffsetY, inh, e.Element("Text"), "OffsetY", 0, false); tmp = sl.Text.Alignment.ToString(); ReadAttribute(ref tmp, inh, e.Element("Text"), "Alignment", "MiddleCenter", false); sl.Text.Alignment = (Alignment)Enum.Parse(typeof(Alignment), tmp, true); LoadColors(inh, e.Element("Text"), ref sl.Text.Colors); } if (e.Element("Attributes") != null) { var l2 = e.Element("Attributes").Elements("Attribute"); if (l2 != null) { LoadLayerAttributes(sl, l2); } } if (!inh) { sc.Layers.Add(sl); } } }