//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// 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); } } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void TrackItem(int x, int y) { if (Items != null && Items.Count > 0) { SkinText font = Skin.Layers["Control"].Text; int h = LineHeight(); y -= Skin.Layers["Control"].ContentMargins.Top; int i = (int)((float)y / h); if (i < Items.Count) { if (i != ItemIndex && Items[i].Enabled) { if (ChildMenu != null) { this.HideMenu(false); } if (i >= 0 && i != ItemIndex) { Items[i].SelectedInvoke(new EventArgs()); } Focused = true; ItemIndex = i; timer = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds; } else if (!Items[i].Enabled && ChildMenu == null) { ItemIndex = -1; } } Invalidate(); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public virtual void AutoHeight(int maxItems) { if (items != null && items.Count < maxItems) { maxItems = items.Count; } if (maxItems < 3) { //maxItems = 3; sbVert.Visible = false; pane.Width = Width - Skin.Layers["Control"].ContentMargins.Horizontal - 1; } else { pane.Width = Width - sbVert.Width - Skin.Layers["Control"].ContentMargins.Horizontal - 1; sbVert.Visible = true; } SkinText font = Skin.Layers["Control"].Text; if (items != null && items.Count > 0) { int h = (int)font.Font.Resource.MeasureString(items[0].ToString()).Y; Height = (h * maxItems) + (Skin.Layers["Control"].ContentMargins.Vertical);// - Skin.OriginMargins.Vertical); } else { Height = 32; } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// public SkinText(SkinText source) : base(source) { if (source != null) { this.Font = new SkinFont(source.Font); this.OffsetX = source.OffsetX; this.OffsetY = source.OffsetY; this.Alignment = source.Alignment; this.Colors = source.Colors; } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void AutoSize() { SkinText font = Skin.Layers["Control"].Text; if (Items != null && Items.Count > 0) { Height = (LineHeight() * Items.Count) + (Skin.Layers["Control"].ContentMargins.Vertical - Skin.OriginMargins.Vertical); Width = LineWidth() + (Skin.Layers["Control"].ContentMargins.Horizontal - Skin.OriginMargins.Horizontal) + font.OffsetX; } else { Height = 16; Width = 16; } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void TrackItem(int x, int y) { if (items != null && items.Count > 0 && (pane.ControlRect.Contains(new Point(x, y)))) { SkinText font = Skin.Layers["Control"].Text; int h = (int)font.Font.Resource.MeasureString(items[0].ToString()).Y; int d = (int)(((sbVert.Value % 10) / 10f) * h); int i = (int)Math.Floor((sbVert.Value / 10f) + ((float)y / h)); if (i >= 0 && i < Items.Count && i >= (int)Math.Floor((float)sbVert.Value / 10f) && i < (int)Math.Ceiling((float)(sbVert.Value + sbVert.PageSize) / 10f)) { ItemIndex = i; } Focused = true; } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// 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); } } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// private void ItemsChanged() { if (items != null && items.Count > 0) { SkinText font = Skin.Layers["Control"].Text; int h = (int)font.Font.Resource.MeasureString(items[0].ToString()).Y; int sizev = Height - Skin.Layers["Control"].ContentMargins.Vertical; sbVert.Range = items.Count * 10; sbVert.PageSize = (int)Math.Floor((float)sizev * 10 / h); Invalidate(); } else if (items == null || items.Count <= 0) { sbVert.Range = 1; sbVert.PageSize = 1; Invalidate(); } }
//////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// 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."); } }