private void OnSectionsListBoxDrawItem(object sender, DrawItemEventArgs e) { SettingsDialogSection section = this.sectionsListBox.Items[e.Index] as SettingsDialogSection; int x = UIUtil.ScaleWidth(4); using (IDrawingContext context = DrawingContextUtil.FromGraphics(e.Graphics, e.Bounds, false, FactorySource.PerThread)) { HighlightState disabled; context.Clear(new ColorRgba128Float?(this.BackColor)); if (e.State.HasFlag(DrawItemState.Disabled) || e.State.HasFlag(DrawItemState.Grayed)) { disabled = HighlightState.Disabled; } else if (e.State.HasFlag(DrawItemState.Selected)) { disabled = HighlightState.Checked; } else if (e.State.HasFlag(DrawItemState.HotLight) || (e.Index == this.hotTrackIndex)) { disabled = HighlightState.Hover; } else { disabled = HighlightState.Default; } RectInt32 bounds = e.Bounds.ToRectInt32(); bounds.Inflate(-1, -1); this.selectionHighlightRenderer.HighlightState = disabled; this.selectionHighlightRenderer.RenderBackground(context, bounds); SizeInt32 num4 = UIUtil.ScaleSize(section.DeviceIcon.PixelSize); RectInt32 num5 = new RectInt32(x, e.Bounds.Top + ((e.Bounds.Height - num4.Height) / 2), num4.Width, num4.Height); context.DrawBitmap(section.DeviceIcon, new RectDouble?(num5), 1.0, BitmapInterpolationMode.Linear, null); HotkeyRenderMode hotkeyRenderMode = !e.State.HasFlag(DrawItemState.NoAccelerator) ? HotkeyRenderMode.Show : HotkeyRenderMode.Hide; TextLayout resourceSource = UIText.CreateLayout(context, section.DisplayName, e.Font, null, hotkeyRenderMode, 65535.0, 65535.0); ITextLayout cachedOrCreateResource = context.GetCachedOrCreateResource <ITextLayout>(resourceSource); int num6 = num5.Right + x; float num7 = e.Bounds.Top + ((e.Bounds.Height - cachedOrCreateResource.Metrics.Height) / 2f); context.DrawTextLayout((double)num6, (double)num7, resourceSource, this.selectionHighlightRenderer.EmbeddedTextBrush, DrawTextOptions.None); if (!e.State.HasFlag(DrawItemState.NoFocusRect)) { context.DrawFocusRectangle(e.Bounds.ToRectFloat()); } } }
public PropertyBasedSettingsPage(SettingsDialogSection section) : base(section) { this.propertyCollection = this.OnCreatePropertyCollection().Clone(); this.propertyUIInfo = this.OnCreateConfigUI(this.propertyCollection.Clone()); this.propertyUI = (Control)this.propertyUIInfo.CreateConcreteControl(typeof(Control)); foreach (Property property in this.propertyCollection) { PropertyControlInfo info = this.propertyUIInfo.FindControlForPropertyName(property.Name); if (info == null) { ExceptionUtil.ThrowInvalidOperationException("Every property must have a control associated with it"); } else { Property controlsProperty = info.Property; controlsProperty.ValueChanged += (s, e) => this.PropertyValueChanged(controlsProperty, e.Value); } } base.SuspendLayout(); this.propertyUI.Location = new Point(0, 0); base.Controls.Add(this.propertyUI); base.ResumeLayout(false); }
public SettingsDialog(IServiceProvider services, AppSettings appSettings, AppSettings.ToolsSection toolBarSettings) { Validate.Begin().IsNotNull <IServiceProvider>(services, "services").IsNotNull <AppSettings>(appSettings, "appSettings").IsNotNull <AppSettings.ToolsSection>(toolBarSettings, "toolBarSettings").Check(); this.services = services; this.appSettings = appSettings; this.toolBarSettings = toolBarSettings; this.components = new Container(); List <SettingsDialogSection> items = new List <SettingsDialogSection> { new UISettingsSection(this.appSettings), new ToolsSettingsSection(this.appSettings, toolBarSettings) }; if (!WinAppModel.HasCurrentPackage) { items.Add(new UpdatesSettingsSection(this, this.appSettings)); } items.Add(new DiagnosticsSettingsSection(this.appSettings)); IPluginErrorService pluginErrorService = services.GetService <IPluginErrorService>(); if (pluginErrorService.GetPluginLoadErrors().Any <PluginErrorInfo>()) { items.Add(new PluginsSettingsSection(this.appSettings, pluginErrorService)); } this.settingsSections = items.ToArrayEx <SettingsDialogSection>(); this.settingsPages = this.settingsSections.Select <SettingsDialogSection, SettingsDialogPage>(ss => ss.CreateUI()).ToArrayEx <SettingsDialogPage>(); if (lastCurrentSection == null) { this.currentSection = this.settingsSections[0]; } else { this.currentSection = this.settingsSections.FirstOrDefault <SettingsDialogSection>(ss => (ss.GetType() == lastCurrentSection)) ?? this.settingsSections[0]; } base.SuspendLayout(); this.DoubleBuffered = true; base.ResizeRedraw = true; base.AutoHandleGlassRelatedOptimizations = true; base.IsGlassDesired = !OS.IsWin10OrLater; this.Font = System.Drawing.SystemFonts.MenuFont; this.sectionsListBox = new FlickerFreeOwnerDrawListBox(); this.sectionPanel = new PanelEx(); this.separator = new PaintDotNet.Controls.SeparatorLine(); this.closeButton = new PdnPushButton(); this.closeButton.Name = "closeButton"; this.closeButton.AutoSize = true; this.closeButton.Text = PdnResources.GetString("Form.CloseButton.Text"); this.sectionPanel.Name = "sectionPanel"; this.sectionPanel.AutoScroll = true; this.sectionPanel.HideHScroll = true; this.sectionPanel.HorizontalScroll.Enabled = false; this.sectionPanel.HorizontalScroll.Visible = false; this.sectionPanel.VerticalScroll.Enabled = true; this.sectionsListBox.Name = "sectionsListBox"; this.sectionsListBox.Items.AddRange(this.settingsSections.ToArrayEx <SettingsDialogSection>()); this.sectionsListBox.DrawMode = DrawMode.OwnerDrawFixed; this.sectionsListBox.ItemHeight = UIUtil.ScaleHeight(0x20); this.sectionsListBox.DrawItem += new DrawItemEventHandler(this.OnSectionsListBoxDrawItem); this.sectionsListBox.IntegralHeight = false; this.sectionsListBox.BorderStyle = BorderStyle.FixedSingle; this.sectionsListBox.MouseEnter += (s, e) => this.UpdateHotTrackIndex(new Point(-1, -1)); this.sectionsListBox.MouseMove += (s, e) => this.UpdateHotTrackIndex(e.Location); this.sectionsListBox.MouseLeave += (s, e) => this.UpdateHotTrackIndex(new Point(-1, -1)); this.sectionsListBox.SelectedIndex = this.settingsSections.IndexOf <SettingsDialogSection>(this.currentSection); this.sectionsListBox.SelectedIndexChanged += new EventHandler(this.OnSectionsListBoxSelectedIndexChanged); this.separator.Name = "separator"; base.Controls.Add(this.sectionsListBox); base.Controls.Add(this.sectionPanel); base.Controls.Add(this.closeButton); base.Controls.Add(this.separator); base.Icon = PdnResources.GetImageResource("Icons.MenuUtilitiesSettingsIcon.png").Reference.ToIcon(); base.AcceptButton = this.closeButton; base.CancelButton = this.closeButton; base.MinimizeBox = false; base.MaximizeBox = false; base.StartPosition = FormStartPosition.CenterParent; base.FormBorderStyle = FormBorderStyle.Sizable; base.ShowInTaskbar = false; this.Text = PdnResources.GetString("SettingsDialog.Text"); base.ClientSize = UIUtil.ScaleSize(600, 450); base.ResumeLayout(false); base.PerformLayout(); }
public SettingsDialogPage(SettingsDialogSection section) { Validate.IsNotNull <SettingsDialogSection>(section, "section"); this.section = section; }