public override void UpdateAndDraw(ListBox control, TimeSpan time) { if (!control.IsDirty) { return; } int columnOffset; int columnEnd; int startingRow; int endingRow; Cell appearance = GetStateAppearance(control.State); Cell scrollBarAppearance = ScrollBarTheme.GetStateAppearance(control.State); Cell borderAppearance = BorderTheme.GetStateAppearance(control.State); // Redraw the control control.Surface.Fill( appearance.Foreground, appearance.Background, appearance.Glyph); if (DrawBorder) { endingRow = control.Height - 2; startingRow = 1; columnOffset = 1; columnEnd = control.Width - 2; control.Surface.DrawBox(new Rectangle(0, 0, control.Width, control.Height), new Cell(borderAppearance.Foreground, borderAppearance.Background, 0), null, BorderLineStyle); } else { endingRow = control.Height; startingRow = 0; columnOffset = 0; columnEnd = control.Width; control.Surface.Fill(borderAppearance.Foreground, borderAppearance.Background, 0, null); } int offset = control.IsSliderVisible ? control.Slider.Value : 0; for (int i = 0; i < endingRow; i++) { var itemIndexRelative = i + offset; if (itemIndexRelative < control.Items.Count) { ControlStates state = 0; if (Helpers.HasFlag(control.State, ControlStates.MouseOver) && control.RelativeIndexMouseOver == itemIndexRelative) { Helpers.SetFlag(ref state, ControlStates.MouseOver); } if (control.State.HasFlag(ControlStates.MouseLeftButtonDown)) { Helpers.SetFlag(ref state, ControlStates.MouseLeftButtonDown); } if (control.State.HasFlag(ControlStates.MouseRightButtonDown)) { Helpers.SetFlag(ref state, ControlStates.MouseRightButtonDown); } if (control.State.HasFlag(ControlStates.Disabled)) { Helpers.SetFlag(ref state, ControlStates.Disabled); } if (itemIndexRelative == control.SelectedIndex) { Helpers.SetFlag(ref state, ControlStates.Selected); } ItemTheme.Draw(control.Surface, new Rectangle(columnOffset, i + startingRow, columnEnd, 1), control.Items[itemIndexRelative], state); } } if (control.IsSliderVisible) { control.Slider.IsDirty = true; control.Slider.Update(time); var y = control.SliderRenderLocation.Y; for (var ycell = 0; ycell < control.Slider.Height; ycell++) { control.Surface.SetGlyph(control.SliderRenderLocation.X, y, control.Slider.Surface[0, ycell].Glyph); control.Surface.SetCellAppearance(control.SliderRenderLocation.X, y, control.Slider.Surface[0, ycell]); y++; } } control.IsDirty = Helpers.HasFlag(control.State, ControlStates.MouseOver); }
/// <inheritdoc /> public override void UpdateAndDraw(ControlBase control, TimeSpan time) { if (!(control is ListBox listbox)) { return; } if (!listbox.IsDirty) { return; } RefreshTheme(control.ThemeColors, control); int columnOffset; int columnEnd; int startingRow; int endingRow; Cell appearance = GetStateAppearance(listbox.State); Cell scrollBarAppearance = ScrollBarTheme.GetStateAppearance(listbox.State); Cell borderAppearance = BorderTheme.GetStateAppearance(listbox.State); // Redraw the control listbox.Surface.Fill( appearance.Foreground, appearance.Background, appearance.Glyph); if (DrawBorder) { endingRow = listbox.Height - 2; startingRow = 1; columnOffset = 1; columnEnd = listbox.Width - 2; listbox.Surface.DrawBox(new Rectangle(0, 0, listbox.Width, listbox.Height), new Cell(borderAppearance.Foreground, borderAppearance.Background, 0), null, BorderLineStyle); } else { endingRow = listbox.Height; startingRow = 0; columnOffset = 0; columnEnd = listbox.Width; listbox.Surface.Fill(borderAppearance.Foreground, borderAppearance.Background, 0, null); } ShowHideScrollBar(listbox); int offset = listbox.IsScrollBarVisible ? listbox.ScrollBar.Value : 0; for (int i = 0; i < endingRow; i++) { int itemIndexRelative = i + offset; if (itemIndexRelative < listbox.Items.Count) { ControlStates state = 0; if (Helpers.HasFlag(listbox.State, ControlStates.MouseOver) && listbox.RelativeIndexMouseOver == itemIndexRelative) { Helpers.SetFlag(ref state, ControlStates.MouseOver); } if (listbox.State.HasFlag(ControlStates.MouseLeftButtonDown)) { Helpers.SetFlag(ref state, ControlStates.MouseLeftButtonDown); } if (listbox.State.HasFlag(ControlStates.MouseRightButtonDown)) { Helpers.SetFlag(ref state, ControlStates.MouseRightButtonDown); } if (listbox.State.HasFlag(ControlStates.Disabled)) { Helpers.SetFlag(ref state, ControlStates.Disabled); } if (itemIndexRelative == listbox.SelectedIndex) { Helpers.SetFlag(ref state, ControlStates.Selected); } listbox.ItemTheme.Draw(listbox.Surface, new Rectangle(columnOffset, i + startingRow, columnEnd, 1), listbox.Items[itemIndexRelative], state); } } if (listbox.IsScrollBarVisible) { listbox.ScrollBar.IsDirty = true; listbox.ScrollBar.Update(time); int y = listbox.ScrollBarRenderLocation.Y; for (int ycell = 0; ycell < listbox.ScrollBar.Height; ycell++) { listbox.Surface.SetGlyph(listbox.ScrollBarRenderLocation.X, y, listbox.ScrollBar.Surface[0, ycell].Glyph); listbox.Surface.SetCellAppearance(listbox.ScrollBarRenderLocation.X, y, listbox.ScrollBar.Surface[0, ycell]); y++; } } listbox.IsDirty = Helpers.HasFlag(listbox.State, ControlStates.MouseOver); }