From 93c85d7d878c99cd6c1760aa9759130c83b85fcc Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Fri, 27 Aug 2021 22:26:12 +1200 Subject: [PATCH] [WIP] Adding wallpaper manipulation --- DisplayMagician/DisplayMagician.csproj | 9 + .../UIForms/DisplayProfileForm.Designer.cs | 19 ++ DisplayMagician/UIForms/DisplayProfileForm.cs | 7 + .../UIForms/ProfileSettingsForm.Designer.cs | 170 ++++++++++++++++++ .../UIForms/ProfileSettingsForm.cs | 75 ++++++++ .../UIForms/ProfileSettingsForm.resx | 120 +++++++++++++ DisplayMagicianShared/ProfileItem.cs | 3 + 7 files changed, 403 insertions(+) create mode 100644 DisplayMagician/UIForms/ProfileSettingsForm.Designer.cs create mode 100644 DisplayMagician/UIForms/ProfileSettingsForm.cs create mode 100644 DisplayMagician/UIForms/ProfileSettingsForm.resx diff --git a/DisplayMagician/DisplayMagician.csproj b/DisplayMagician/DisplayMagician.csproj index b46944a..4e12627 100644 --- a/DisplayMagician/DisplayMagician.csproj +++ b/DisplayMagician/DisplayMagician.csproj @@ -148,6 +148,12 @@ HotkeyForm.cs + + Form + + + ProfileSettingsForm.cs + Form @@ -216,6 +222,9 @@ MainForm.cs Designer + + ProfileSettingsForm.cs + SettingsForm.cs diff --git a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs index a43bae7..81115a2 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.Designer.cs @@ -59,6 +59,7 @@ namespace DisplayMagician.UIForms this.dialog_save = new System.Windows.Forms.SaveFileDialog(); this.btn_hotkey = new System.Windows.Forms.Button(); this.lbl_hotkey_assigned = new System.Windows.Forms.Label(); + this.btn_profile_settings = new System.Windows.Forms.Button(); this.menu_profiles.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).BeginInit(); this.SuspendLayout(); @@ -360,6 +361,22 @@ namespace DisplayMagician.UIForms this.lbl_hotkey_assigned.Visible = false; this.lbl_hotkey_assigned.Click += new System.EventHandler(this.lbl_hotkey_assigned_Click); // + // btn_profile_settings + // + this.btn_profile_settings.Anchor = System.Windows.Forms.AnchorStyles.None; + this.btn_profile_settings.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_profile_settings.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_profile_settings.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_profile_settings.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_profile_settings.ForeColor = System.Drawing.Color.White; + this.btn_profile_settings.Location = new System.Drawing.Point(810, 520); + this.btn_profile_settings.Name = "btn_profile_settings"; + this.btn_profile_settings.Size = new System.Drawing.Size(120, 33); + this.btn_profile_settings.TabIndex = 37; + this.btn_profile_settings.Text = "Profile Settings"; + this.btn_profile_settings.UseVisualStyleBackColor = true; + this.btn_profile_settings.Click += new System.EventHandler(this.btn_profile_settings_Click); + // // DisplayProfileForm // this.AcceptButton = this.btn_apply; @@ -369,6 +386,7 @@ namespace DisplayMagician.UIForms this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.CancelButton = this.btn_back; this.ClientSize = new System.Drawing.Size(976, 829); + this.Controls.Add(this.btn_profile_settings); this.Controls.Add(this.lbl_hotkey_assigned); this.Controls.Add(this.btn_hotkey); this.Controls.Add(this.btn_save); @@ -429,6 +447,7 @@ namespace DisplayMagician.UIForms private System.Windows.Forms.SaveFileDialog dialog_save; private System.Windows.Forms.Button btn_hotkey; private System.Windows.Forms.Label lbl_hotkey_assigned; + private System.Windows.Forms.Button btn_profile_settings; } } diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 281ddfe..228493a 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -534,5 +534,12 @@ namespace DisplayMagician.UIForms } + private void btn_profile_settings_Click(object sender, EventArgs e) + { + ProfileSettingsForm profileSettingsForm = new ProfileSettingsForm(); + profileSettingsForm.Profile = _selectedProfile; + profileSettingsForm.ShowDialog(this); + //_selectedProfile = profileSettingsForm.Profile; + } } } \ No newline at end of file diff --git a/DisplayMagician/UIForms/ProfileSettingsForm.Designer.cs b/DisplayMagician/UIForms/ProfileSettingsForm.Designer.cs new file mode 100644 index 0000000..1b5113b --- /dev/null +++ b/DisplayMagician/UIForms/ProfileSettingsForm.Designer.cs @@ -0,0 +1,170 @@ + +namespace DisplayMagician.UIForms +{ + partial class ProfileSettingsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btn_back = new System.Windows.Forms.Button(); + this.gb_general = new System.Windows.Forms.GroupBox(); + this.btn_select_wallpaper = new System.Windows.Forms.Button(); + this.txt_wallpaper_filename = new System.Windows.Forms.TextBox(); + this.cb_set_wallpaper = new System.Windows.Forms.CheckBox(); + this.label1 = new System.Windows.Forms.Label(); + this.cmb_wallpaper_display_mode = new System.Windows.Forms.ComboBox(); + this.gb_general.SuspendLayout(); + this.SuspendLayout(); + // + // btn_back + // + this.btn_back.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btn_back.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btn_back.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_back.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_back.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_back.ForeColor = System.Drawing.Color.White; + this.btn_back.Location = new System.Drawing.Point(476, 202); + this.btn_back.Name = "btn_back"; + this.btn_back.Size = new System.Drawing.Size(75, 23); + this.btn_back.TabIndex = 9; + this.btn_back.Text = "&Back"; + this.btn_back.UseVisualStyleBackColor = true; + this.btn_back.Click += new System.EventHandler(this.btn_back_Click); + // + // gb_general + // + this.gb_general.Controls.Add(this.btn_select_wallpaper); + this.gb_general.Controls.Add(this.txt_wallpaper_filename); + this.gb_general.Controls.Add(this.cb_set_wallpaper); + this.gb_general.Controls.Add(this.label1); + this.gb_general.Controls.Add(this.cmb_wallpaper_display_mode); + this.gb_general.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.gb_general.ForeColor = System.Drawing.Color.White; + this.gb_general.Location = new System.Drawing.Point(27, 21); + this.gb_general.Name = "gb_general"; + this.gb_general.Size = new System.Drawing.Size(525, 157); + this.gb_general.TabIndex = 11; + this.gb_general.TabStop = false; + this.gb_general.Text = "Wallpaper Settings"; + // + // btn_select_wallpaper + // + this.btn_select_wallpaper.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_select_wallpaper.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_select_wallpaper.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_select_wallpaper.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_select_wallpaper.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_select_wallpaper.ForeColor = System.Drawing.Color.White; + this.btn_select_wallpaper.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.btn_select_wallpaper.Location = new System.Drawing.Point(428, 68); + this.btn_select_wallpaper.Name = "btn_select_wallpaper"; + this.btn_select_wallpaper.Size = new System.Drawing.Size(75, 23); + this.btn_select_wallpaper.TabIndex = 16; + this.btn_select_wallpaper.Text = "&Select"; + this.btn_select_wallpaper.UseVisualStyleBackColor = true; + // + // txt_wallpaper_filename + // + this.txt_wallpaper_filename.Location = new System.Drawing.Point(28, 68); + this.txt_wallpaper_filename.Name = "txt_wallpaper_filename"; + this.txt_wallpaper_filename.Size = new System.Drawing.Size(394, 22); + this.txt_wallpaper_filename.TabIndex = 15; + // + // cb_set_wallpaper + // + this.cb_set_wallpaper.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.cb_set_wallpaper.AutoSize = true; + this.cb_set_wallpaper.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F); + this.cb_set_wallpaper.ForeColor = System.Drawing.Color.White; + this.cb_set_wallpaper.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.cb_set_wallpaper.Location = new System.Drawing.Point(28, 36); + this.cb_set_wallpaper.Name = "cb_set_wallpaper"; + this.cb_set_wallpaper.Size = new System.Drawing.Size(261, 20); + this.cb_set_wallpaper.TabIndex = 14; + this.cb_set_wallpaper.Text = "Set wallpaper when applying this profile"; + this.cb_set_wallpaper.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.Transparent; + this.label1.Location = new System.Drawing.Point(42, 111); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(155, 16); + this.label1.TabIndex = 13; + this.label1.Text = "Wallpaper display style: "; + // + // cmb_wallpaper_display_mode + // + this.cmb_wallpaper_display_mode.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.cmb_wallpaper_display_mode.FormattingEnabled = true; + this.cmb_wallpaper_display_mode.Items.AddRange(new object[] { + "Centered", + "Stretched", + "Tiled"}); + this.cmb_wallpaper_display_mode.Location = new System.Drawing.Point(203, 108); + this.cmb_wallpaper_display_mode.Name = "cmb_wallpaper_display_mode"; + this.cmb_wallpaper_display_mode.Size = new System.Drawing.Size(219, 24); + this.cmb_wallpaper_display_mode.TabIndex = 12; + this.cmb_wallpaper_display_mode.SelectedIndexChanged += new System.EventHandler(this.cmb_wallpaper_display_mode_SelectedIndexChanged); + // + // ProfileSettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(580, 249); + this.Controls.Add(this.gb_general); + this.Controls.Add(this.btn_back); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ProfileSettingsForm"; + this.ShowIcon = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Profile Settings"; + this.TopMost = true; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ProfileSettingsForm_FormClosing); + this.Load += new System.EventHandler(this.ProfileSettingsForm_Load); + this.gb_general.ResumeLayout(false); + this.gb_general.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button btn_back; + private System.Windows.Forms.GroupBox gb_general; + private System.Windows.Forms.CheckBox cb_set_wallpaper; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cmb_wallpaper_display_mode; + private System.Windows.Forms.TextBox txt_wallpaper_filename; + private System.Windows.Forms.Button btn_select_wallpaper; + } +} \ No newline at end of file diff --git a/DisplayMagician/UIForms/ProfileSettingsForm.cs b/DisplayMagician/UIForms/ProfileSettingsForm.cs new file mode 100644 index 0000000..4d96d3e --- /dev/null +++ b/DisplayMagician/UIForms/ProfileSettingsForm.cs @@ -0,0 +1,75 @@ +using DisplayMagicianShared; +using NHotkey; +using NHotkey.WindowsForms; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using WK.Libraries.BootMeUpNS; + +namespace DisplayMagician.UIForms +{ + + public partial class ProfileSettingsForm : Form + { + + private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + + private Dictionary wallpaperStyleText = new Dictionary(); + + public ProfileSettingsForm() + { + logger.Info($"ProfileSettingsForm/ProfileSettingsForm: Creating a ProfileSettingsForm UI Form"); + + InitializeComponent(); + + // Populate the Style dictionary + wallpaperStyleText.Add(Wallpaper.Style.Centered, "Center the Wallpaper"); + wallpaperStyleText.Add(Wallpaper.Style.Stretched, "Stretch the Wallpaper"); + wallpaperStyleText.Add(Wallpaper.Style.Tiled, "Tile the Wallpaper"); + + // Now use it to populate the Style Dropdown + cmb_wallpaper_display_mode.Items.Clear(); + cmb_wallpaper_display_mode.Items.AddRange(wallpaperStyleText.Values.ToArray()); + cmb_wallpaper_display_mode.SelectedIndex = 0; + } + + public ProfileItem Profile + { + get; + set; + } + + + private void ProfileSettingsForm_Load(object sender, EventArgs e) + { + if (Profile.SetWallpaper) + { + logger.Info($"ProfileSettingsForm/ProfileSettingsForm_Load: Profile {Profile.Name} has loaded with Set Wallpaper enabled and Wallpaper Style {Profile.WallpaperStyle.ToString("G")} and Wallpaper Filename of {Profile.WallpaperBitmapFilename}."); + cmb_wallpaper_display_mode.SelectedIndex = cmb_wallpaper_display_mode.FindStringExact(wallpaperStyleText[Profile.WallpaperStyle]); + if (Profile.WallpaperBitmapFilename != "") + { + txt_wallpaper_filename.Text = Profile.WallpaperBitmapFilename; + } + } + + } + + private void ProfileSettingsForm_FormClosing(object sender, FormClosingEventArgs e) + { + } + + private void btn_back_Click(object sender, EventArgs e) + { + Profile.SetWallpaper = cb_set_wallpaper.Checked; + Profile.WallpaperStyle = (Wallpaper.Style)cmb_wallpaper_display_mode.SelectedValue; + Profile.WallpaperBitmapFilename = txt_wallpaper_filename.Text; + this.Close(); + } + + private void cmb_wallpaper_display_mode_SelectedIndexChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/DisplayMagician/UIForms/ProfileSettingsForm.resx b/DisplayMagician/UIForms/ProfileSettingsForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DisplayMagician/UIForms/ProfileSettingsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index e881a09..f40b141 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -182,6 +182,8 @@ namespace DisplayMagicianShared public bool SetWallpaper { get; set; } + public Wallpaper.Style WallpaperStyle { get; set; } + public string WallpaperBitmapFilename{ get { @@ -314,6 +316,7 @@ namespace DisplayMagicianShared profile.ProfileDisplayIdentifiers = ProfileDisplayIdentifiers; profile.SetWallpaper = SetWallpaper; profile.WallpaperBitmapFilename = WallpaperBitmapFilename; + profile.WallpaperStyle = WallpaperStyle; return true; }