From 09f145ce54cff4b5599e6189ddbb347b678c26cc Mon Sep 17 00:00:00 2001 From: Arjan Meskers Date: Mon, 23 Sep 2019 20:10:14 +0200 Subject: [PATCH] Version 2.1 Added background image alignment Resize previews from screensize, instead of rendering inside bounds of preview graphics. Include versionnumber in config form title Updated version to 2.1 --- AMSoftware.Quotes/App.config | 3 + AMSoftware.Quotes/ConfigForm.Designer.cs | 211 ++++++++++-------- AMSoftware.Quotes/ConfigForm.cs | 31 ++- AMSoftware.Quotes/Program.cs | 5 +- AMSoftware.Quotes/Properties/AssemblyInfo.cs | 4 +- .../Properties/Settings.Designer.cs | 14 +- .../Properties/Settings.settings | 3 + AMSoftware.Quotes/QuoteRenderer.cs | 164 ++++++++++++-- AMSoftware.Quotes/RenderSettings.cs | 1 + .../ScreensaverApplicationContext.cs | 37 ++- AMSoftware.Quotes/_enums.cs | 8 + 11 files changed, 345 insertions(+), 136 deletions(-) diff --git a/AMSoftware.Quotes/App.config b/AMSoftware.Quotes/App.config index 62d83e1..0790a39 100644 --- a/AMSoftware.Quotes/App.config +++ b/AMSoftware.Quotes/App.config @@ -31,6 +31,9 @@ + + 0 + diff --git a/AMSoftware.Quotes/ConfigForm.Designer.cs b/AMSoftware.Quotes/ConfigForm.Designer.cs index eafc490..5ce93b3 100644 --- a/AMSoftware.Quotes/ConfigForm.Designer.cs +++ b/AMSoftware.Quotes/ConfigForm.Designer.cs @@ -49,6 +49,8 @@ private void InitializeComponent() this.okButton = new System.Windows.Forms.Button(); this.generalTabPage = new System.Windows.Forms.TabPage(); this.backgroundGroupBox = new System.Windows.Forms.GroupBox(); + this.backgroundAlignmentComboBox = new System.Windows.Forms.ComboBox(); + this.backgroundAlignmentLabel = new System.Windows.Forms.Label(); this.backgroundImageLabel = new System.Windows.Forms.Label(); this.backgroundColorLabel = new System.Windows.Forms.Label(); this.backgroundImageButton = new System.Windows.Forms.Button(); @@ -91,10 +93,9 @@ private void InitializeComponent() // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(265, 551); - this.cancelButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.cancelButton.Location = new System.Drawing.Point(199, 448); this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(100, 28); + this.cancelButton.Size = new System.Drawing.Size(75, 23); this.cancelButton.TabIndex = 16; this.cancelButton.Text = "Cancel"; this.cancelButton.UseVisualStyleBackColor = true; @@ -104,10 +105,9 @@ private void InitializeComponent() // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.Location = new System.Drawing.Point(157, 551); - this.okButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.okButton.Location = new System.Drawing.Point(118, 448); this.okButton.Name = "okButton"; - this.okButton.Size = new System.Drawing.Size(100, 28); + this.okButton.Size = new System.Drawing.Size(75, 23); this.okButton.TabIndex = 15; this.okButton.Text = "OK"; this.okButton.UseVisualStyleBackColor = true; @@ -118,58 +118,79 @@ private void InitializeComponent() this.generalTabPage.Controls.Add(this.backgroundGroupBox); this.generalTabPage.Controls.Add(this.textGroupBox); this.generalTabPage.Controls.Add(this.sourceLocationGroupBox); - this.generalTabPage.Location = new System.Drawing.Point(4, 25); - this.generalTabPage.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.generalTabPage.Location = new System.Drawing.Point(4, 22); this.generalTabPage.Name = "generalTabPage"; - this.generalTabPage.Padding = new System.Windows.Forms.Padding(11, 10, 11, 10); - this.generalTabPage.Size = new System.Drawing.Size(457, 505); + this.generalTabPage.Padding = new System.Windows.Forms.Padding(8); + this.generalTabPage.Size = new System.Drawing.Size(341, 408); this.generalTabPage.TabIndex = 0; this.generalTabPage.Text = "General"; this.generalTabPage.UseVisualStyleBackColor = true; // // backgroundGroupBox // + this.backgroundGroupBox.Controls.Add(this.backgroundAlignmentComboBox); + this.backgroundGroupBox.Controls.Add(this.backgroundAlignmentLabel); this.backgroundGroupBox.Controls.Add(this.backgroundImageLabel); this.backgroundGroupBox.Controls.Add(this.backgroundColorLabel); this.backgroundGroupBox.Controls.Add(this.backgroundImageButton); this.backgroundGroupBox.Controls.Add(this.backgroundImageTextBox); this.backgroundGroupBox.Controls.Add(this.backgroundColorButton); this.backgroundGroupBox.Controls.Add(this.backgroundColorTextBox); - this.backgroundGroupBox.Location = new System.Drawing.Point(13, 241); - this.backgroundGroupBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.backgroundGroupBox.Location = new System.Drawing.Point(10, 196); this.backgroundGroupBox.Name = "backgroundGroupBox"; - this.backgroundGroupBox.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.backgroundGroupBox.Size = new System.Drawing.Size(427, 98); + this.backgroundGroupBox.Size = new System.Drawing.Size(320, 105); this.backgroundGroupBox.TabIndex = 12; this.backgroundGroupBox.TabStop = false; this.backgroundGroupBox.Text = "Background"; // + // backgroundAlignmentComboBox + // + this.backgroundAlignmentComboBox.FormattingEnabled = true; + this.backgroundAlignmentComboBox.Items.AddRange(new object[] { + "Auto", + "Left", + "Center", + "Right"}); + this.backgroundAlignmentComboBox.Location = new System.Drawing.Point(77, 73); + this.backgroundAlignmentComboBox.Margin = new System.Windows.Forms.Padding(2); + this.backgroundAlignmentComboBox.Name = "backgroundAlignmentComboBox"; + this.backgroundAlignmentComboBox.Size = new System.Drawing.Size(238, 21); + this.backgroundAlignmentComboBox.TabIndex = 24; + this.backgroundAlignmentComboBox.SelectedIndexChanged += new System.EventHandler(this.BackgroundAlignmentComboBox_SelectedIndexChanged); + // + // backgroundAlignmentLabel + // + this.backgroundAlignmentLabel.AutoSize = true; + this.backgroundAlignmentLabel.Location = new System.Drawing.Point(6, 76); + this.backgroundAlignmentLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.backgroundAlignmentLabel.Name = "backgroundAlignmentLabel"; + this.backgroundAlignmentLabel.Size = new System.Drawing.Size(53, 13); + this.backgroundAlignmentLabel.TabIndex = 23; + this.backgroundAlignmentLabel.Text = "Alignment"; + // // backgroundImageLabel // this.backgroundImageLabel.AutoSize = true; - this.backgroundImageLabel.Location = new System.Drawing.Point(8, 62); - this.backgroundImageLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.backgroundImageLabel.Location = new System.Drawing.Point(6, 50); this.backgroundImageLabel.Name = "backgroundImageLabel"; - this.backgroundImageLabel.Size = new System.Drawing.Size(46, 17); + this.backgroundImageLabel.Size = new System.Drawing.Size(36, 13); this.backgroundImageLabel.TabIndex = 22; this.backgroundImageLabel.Text = "Image"; // // backgroundColorLabel // this.backgroundColorLabel.AutoSize = true; - this.backgroundColorLabel.Location = new System.Drawing.Point(8, 27); - this.backgroundColorLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.backgroundColorLabel.Location = new System.Drawing.Point(6, 22); this.backgroundColorLabel.Name = "backgroundColorLabel"; - this.backgroundColorLabel.Size = new System.Drawing.Size(41, 17); + this.backgroundColorLabel.Size = new System.Drawing.Size(31, 13); this.backgroundColorLabel.TabIndex = 21; this.backgroundColorLabel.Text = "Color"; // // backgroundImageButton // - this.backgroundImageButton.Location = new System.Drawing.Point(391, 55); - this.backgroundImageButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.backgroundImageButton.Location = new System.Drawing.Point(293, 45); this.backgroundImageButton.Name = "backgroundImageButton"; - this.backgroundImageButton.Size = new System.Drawing.Size(31, 28); + this.backgroundImageButton.Size = new System.Drawing.Size(23, 23); this.backgroundImageButton.TabIndex = 14; this.backgroundImageButton.Text = "..."; this.backgroundImageButton.UseVisualStyleBackColor = true; @@ -178,20 +199,18 @@ private void InitializeComponent() // backgroundImageTextBox // this.backgroundImageTextBox.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.backgroundImageTextBox.Location = new System.Drawing.Point(103, 58); - this.backgroundImageTextBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.backgroundImageTextBox.Location = new System.Drawing.Point(77, 47); this.backgroundImageTextBox.Name = "backgroundImageTextBox"; this.backgroundImageTextBox.ReadOnly = true; - this.backgroundImageTextBox.Size = new System.Drawing.Size(279, 22); + this.backgroundImageTextBox.Size = new System.Drawing.Size(210, 20); this.backgroundImageTextBox.TabIndex = 13; this.backgroundImageTextBox.TabStop = false; // // backgroundColorButton // - this.backgroundColorButton.Location = new System.Drawing.Point(391, 21); - this.backgroundColorButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.backgroundColorButton.Location = new System.Drawing.Point(293, 17); this.backgroundColorButton.Name = "backgroundColorButton"; - this.backgroundColorButton.Size = new System.Drawing.Size(31, 28); + this.backgroundColorButton.Size = new System.Drawing.Size(23, 23); this.backgroundColorButton.TabIndex = 12; this.backgroundColorButton.Text = "..."; this.backgroundColorButton.UseVisualStyleBackColor = true; @@ -200,11 +219,10 @@ private void InitializeComponent() // backgroundColorTextBox // this.backgroundColorTextBox.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.backgroundColorTextBox.Location = new System.Drawing.Point(103, 23); - this.backgroundColorTextBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.backgroundColorTextBox.Location = new System.Drawing.Point(77, 19); this.backgroundColorTextBox.Name = "backgroundColorTextBox"; this.backgroundColorTextBox.ReadOnly = true; - this.backgroundColorTextBox.Size = new System.Drawing.Size(279, 22); + this.backgroundColorTextBox.Size = new System.Drawing.Size(210, 20); this.backgroundColorTextBox.TabIndex = 11; this.backgroundColorTextBox.TabStop = false; // @@ -216,11 +234,11 @@ private void InitializeComponent() this.textGroupBox.Controls.Add(this.fontTextBox); this.textGroupBox.Controls.Add(this.fontLabel); this.textGroupBox.Controls.Add(this.fontButton); - this.textGroupBox.Location = new System.Drawing.Point(13, 95); - this.textGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textGroupBox.Location = new System.Drawing.Point(10, 77); + this.textGroupBox.Margin = new System.Windows.Forms.Padding(2); this.textGroupBox.Name = "textGroupBox"; - this.textGroupBox.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.textGroupBox.Size = new System.Drawing.Size(428, 129); + this.textGroupBox.Padding = new System.Windows.Forms.Padding(2); + this.textGroupBox.Size = new System.Drawing.Size(321, 105); this.textGroupBox.TabIndex = 11; this.textGroupBox.TabStop = false; this.textGroupBox.Text = "Text"; @@ -228,10 +246,9 @@ private void InitializeComponent() // shrinkToFitCheckBox // this.shrinkToFitCheckBox.AutoSize = true; - this.shrinkToFitCheckBox.Location = new System.Drawing.Point(103, 55); - this.shrinkToFitCheckBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.shrinkToFitCheckBox.Location = new System.Drawing.Point(77, 45); this.shrinkToFitCheckBox.Name = "shrinkToFitCheckBox"; - this.shrinkToFitCheckBox.Size = new System.Drawing.Size(148, 21); + this.shrinkToFitCheckBox.Size = new System.Drawing.Size(114, 17); this.shrinkToFitCheckBox.TabIndex = 9; this.shrinkToFitCheckBox.Text = "Shrink to fit screen"; this.shrinkToFitCheckBox.UseVisualStyleBackColor = true; @@ -245,49 +262,47 @@ private void InitializeComponent() "Left", "Center", "Right"}); - this.alignmentComboBox.Location = new System.Drawing.Point(103, 85); - this.alignmentComboBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.alignmentComboBox.Location = new System.Drawing.Point(77, 69); + this.alignmentComboBox.Margin = new System.Windows.Forms.Padding(2); this.alignmentComboBox.Name = "alignmentComboBox"; - this.alignmentComboBox.Size = new System.Drawing.Size(316, 24); + this.alignmentComboBox.Size = new System.Drawing.Size(238, 21); this.alignmentComboBox.TabIndex = 10; this.alignmentComboBox.SelectedIndexChanged += new System.EventHandler(this.AlignmentComboBox_SelectedIndexChanged); // // alignmentLabel // this.alignmentLabel.AutoSize = true; - this.alignmentLabel.Location = new System.Drawing.Point(8, 89); + this.alignmentLabel.Location = new System.Drawing.Point(6, 72); + this.alignmentLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.alignmentLabel.Name = "alignmentLabel"; - this.alignmentLabel.Size = new System.Drawing.Size(70, 17); + this.alignmentLabel.Size = new System.Drawing.Size(53, 13); this.alignmentLabel.TabIndex = 8; this.alignmentLabel.Text = "Alignment"; // // fontTextBox // this.fontTextBox.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.fontTextBox.Location = new System.Drawing.Point(103, 23); - this.fontTextBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.fontTextBox.Location = new System.Drawing.Point(77, 19); this.fontTextBox.Name = "fontTextBox"; this.fontTextBox.ReadOnly = true; - this.fontTextBox.Size = new System.Drawing.Size(279, 22); + this.fontTextBox.Size = new System.Drawing.Size(210, 20); this.fontTextBox.TabIndex = 7; this.fontTextBox.TabStop = false; // // fontLabel // this.fontLabel.AutoSize = true; - this.fontLabel.Location = new System.Drawing.Point(8, 27); - this.fontLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.fontLabel.Location = new System.Drawing.Point(6, 22); this.fontLabel.Name = "fontLabel"; - this.fontLabel.Size = new System.Drawing.Size(36, 17); + this.fontLabel.Size = new System.Drawing.Size(28, 13); this.fontLabel.TabIndex = 3; this.fontLabel.Text = "Font"; // // fontButton // - this.fontButton.Location = new System.Drawing.Point(391, 21); - this.fontButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.fontButton.Location = new System.Drawing.Point(293, 17); this.fontButton.Name = "fontButton"; - this.fontButton.Size = new System.Drawing.Size(31, 28); + this.fontButton.Size = new System.Drawing.Size(23, 23); this.fontButton.TabIndex = 8; this.fontButton.Text = "..."; this.fontButton.UseVisualStyleBackColor = true; @@ -298,11 +313,11 @@ private void InitializeComponent() this.sourceLocationGroupBox.Controls.Add(this.pathTextBox); this.sourceLocationGroupBox.Controls.Add(this.pathLabel); this.sourceLocationGroupBox.Controls.Add(this.pathButton); - this.sourceLocationGroupBox.Location = new System.Drawing.Point(13, 12); - this.sourceLocationGroupBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.sourceLocationGroupBox.Location = new System.Drawing.Point(10, 10); + this.sourceLocationGroupBox.Margin = new System.Windows.Forms.Padding(2); this.sourceLocationGroupBox.Name = "sourceLocationGroupBox"; - this.sourceLocationGroupBox.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.sourceLocationGroupBox.Size = new System.Drawing.Size(428, 65); + this.sourceLocationGroupBox.Padding = new System.Windows.Forms.Padding(2); + this.sourceLocationGroupBox.Size = new System.Drawing.Size(321, 53); this.sourceLocationGroupBox.TabIndex = 8; this.sourceLocationGroupBox.TabStop = false; this.sourceLocationGroupBox.Text = "Source"; @@ -310,11 +325,10 @@ private void InitializeComponent() // pathTextBox // this.pathTextBox.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.pathTextBox.Location = new System.Drawing.Point(103, 23); - this.pathTextBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pathTextBox.Location = new System.Drawing.Point(77, 19); this.pathTextBox.Name = "pathTextBox"; this.pathTextBox.ReadOnly = true; - this.pathTextBox.Size = new System.Drawing.Size(279, 22); + this.pathTextBox.Size = new System.Drawing.Size(210, 20); this.pathTextBox.TabIndex = 5; this.pathTextBox.TabStop = false; this.pathTextBox.Text = global::AMSoftware.Quotes.Properties.Settings.Default.SourcePath; @@ -322,20 +336,19 @@ private void InitializeComponent() // pathLabel // this.pathLabel.AutoSize = true; - this.pathLabel.Location = new System.Drawing.Point(8, 27); - this.pathLabel.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pathLabel.Location = new System.Drawing.Point(6, 22); + this.pathLabel.Margin = new System.Windows.Forms.Padding(3); this.pathLabel.Name = "pathLabel"; - this.pathLabel.Size = new System.Drawing.Size(37, 17); + this.pathLabel.Size = new System.Drawing.Size(29, 13); this.pathLabel.TabIndex = 0; this.pathLabel.Text = "Path"; this.pathLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // pathButton // - this.pathButton.Location = new System.Drawing.Point(391, 21); - this.pathButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pathButton.Location = new System.Drawing.Point(293, 17); this.pathButton.Name = "pathButton"; - this.pathButton.Size = new System.Drawing.Size(31, 28); + this.pathButton.Size = new System.Drawing.Size(23, 23); this.pathButton.TabIndex = 6; this.pathButton.Text = "..."; this.pathButton.UseVisualStyleBackColor = true; @@ -346,12 +359,11 @@ private void InitializeComponent() this.configurationTabControl.Controls.Add(this.generalTabPage); this.configurationTabControl.Controls.Add(this.previewTabPage); this.configurationTabControl.Dock = System.Windows.Forms.DockStyle.Top; - this.configurationTabControl.Location = new System.Drawing.Point(8, 7); - this.configurationTabControl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.configurationTabControl.Location = new System.Drawing.Point(6, 6); this.configurationTabControl.Name = "configurationTabControl"; this.configurationTabControl.Padding = new System.Drawing.Point(0, 0); this.configurationTabControl.SelectedIndex = 0; - this.configurationTabControl.Size = new System.Drawing.Size(465, 534); + this.configurationTabControl.Size = new System.Drawing.Size(349, 434); this.configurationTabControl.TabIndex = 1; this.configurationTabControl.SelectedIndexChanged += new System.EventHandler(this.ConfigurationTabControl_SelectedIndexChanged); // @@ -364,77 +376,80 @@ private void InitializeComponent() this.previewTabPage.Controls.Add(this.previewYearLabel); this.previewTabPage.Controls.Add(this.previewQuoteLabel); this.previewTabPage.Controls.Add(this.previewPanel); - this.previewTabPage.Location = new System.Drawing.Point(4, 25); - this.previewTabPage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.previewTabPage.Location = new System.Drawing.Point(4, 22); + this.previewTabPage.Margin = new System.Windows.Forms.Padding(2); this.previewTabPage.Name = "previewTabPage"; - this.previewTabPage.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.previewTabPage.Size = new System.Drawing.Size(457, 505); + this.previewTabPage.Padding = new System.Windows.Forms.Padding(2); + this.previewTabPage.Size = new System.Drawing.Size(341, 408); this.previewTabPage.TabIndex = 1; this.previewTabPage.Text = "Preview"; this.previewTabPage.UseVisualStyleBackColor = true; // // previewYearTextBox // - this.previewYearTextBox.Location = new System.Drawing.Point(103, 412); - this.previewYearTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.previewYearTextBox.Location = new System.Drawing.Point(77, 335); + this.previewYearTextBox.Margin = new System.Windows.Forms.Padding(2); this.previewYearTextBox.Name = "previewYearTextBox"; - this.previewYearTextBox.Size = new System.Drawing.Size(335, 22); + this.previewYearTextBox.Size = new System.Drawing.Size(252, 20); this.previewYearTextBox.TabIndex = 16; this.previewYearTextBox.Leave += new System.EventHandler(this.PreviewTextBox_Leave); // // previewAuthorTextBox // - this.previewAuthorTextBox.Location = new System.Drawing.Point(103, 383); - this.previewAuthorTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.previewAuthorTextBox.Location = new System.Drawing.Point(77, 311); + this.previewAuthorTextBox.Margin = new System.Windows.Forms.Padding(2); this.previewAuthorTextBox.Name = "previewAuthorTextBox"; - this.previewAuthorTextBox.Size = new System.Drawing.Size(335, 22); + this.previewAuthorTextBox.Size = new System.Drawing.Size(252, 20); this.previewAuthorTextBox.TabIndex = 15; this.previewAuthorTextBox.Leave += new System.EventHandler(this.PreviewTextBox_Leave); // // previewQuoteTextBox // - this.previewQuoteTextBox.Location = new System.Drawing.Point(103, 303); - this.previewQuoteTextBox.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.previewQuoteTextBox.Location = new System.Drawing.Point(77, 246); + this.previewQuoteTextBox.Margin = new System.Windows.Forms.Padding(2); this.previewQuoteTextBox.Multiline = true; this.previewQuoteTextBox.Name = "previewQuoteTextBox"; - this.previewQuoteTextBox.Size = new System.Drawing.Size(335, 74); + this.previewQuoteTextBox.Size = new System.Drawing.Size(252, 61); this.previewQuoteTextBox.TabIndex = 14; this.previewQuoteTextBox.Leave += new System.EventHandler(this.PreviewTextBox_Leave); // // previewAuthorLabel // this.previewAuthorLabel.AutoSize = true; - this.previewAuthorLabel.Location = new System.Drawing.Point(12, 386); + this.previewAuthorLabel.Location = new System.Drawing.Point(9, 314); + this.previewAuthorLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.previewAuthorLabel.Name = "previewAuthorLabel"; - this.previewAuthorLabel.Size = new System.Drawing.Size(50, 17); + this.previewAuthorLabel.Size = new System.Drawing.Size(38, 13); this.previewAuthorLabel.TabIndex = 13; this.previewAuthorLabel.Text = "Author"; // // previewYearLabel // this.previewYearLabel.AutoSize = true; - this.previewYearLabel.Location = new System.Drawing.Point(12, 411); + this.previewYearLabel.Location = new System.Drawing.Point(9, 334); + this.previewYearLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.previewYearLabel.Name = "previewYearLabel"; - this.previewYearLabel.Size = new System.Drawing.Size(38, 17); + this.previewYearLabel.Size = new System.Drawing.Size(29, 13); this.previewYearLabel.TabIndex = 12; this.previewYearLabel.Text = "Year"; // // previewQuoteLabel // this.previewQuoteLabel.AutoSize = true; - this.previewQuoteLabel.Location = new System.Drawing.Point(15, 303); + this.previewQuoteLabel.Location = new System.Drawing.Point(11, 246); + this.previewQuoteLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.previewQuoteLabel.Name = "previewQuoteLabel"; - this.previewQuoteLabel.Size = new System.Drawing.Size(47, 17); + this.previewQuoteLabel.Size = new System.Drawing.Size(36, 13); this.previewQuoteLabel.TabIndex = 11; this.previewQuoteLabel.Text = "Quote"; // // previewPanel // this.previewPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.previewPanel.Location = new System.Drawing.Point(15, 20); - this.previewPanel.Margin = new System.Windows.Forms.Padding(21, 20, 21, 20); + this.previewPanel.Location = new System.Drawing.Point(11, 16); + this.previewPanel.Margin = new System.Windows.Forms.Padding(16); this.previewPanel.Name = "previewPanel"; - this.previewPanel.Size = new System.Drawing.Size(423, 259); + this.previewPanel.Size = new System.Drawing.Size(318, 211); this.previewPanel.TabIndex = 10; this.previewPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.PreviewPanel_Paint); // @@ -442,10 +457,9 @@ private void InitializeComponent() // this.applyButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.applyButton.Enabled = false; - this.applyButton.Location = new System.Drawing.Point(373, 551); - this.applyButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.applyButton.Location = new System.Drawing.Point(280, 448); this.applyButton.Name = "applyButton"; - this.applyButton.Size = new System.Drawing.Size(100, 28); + this.applyButton.Size = new System.Drawing.Size(75, 23); this.applyButton.TabIndex = 17; this.applyButton.Text = "&Apply"; this.applyButton.UseVisualStyleBackColor = true; @@ -473,20 +487,19 @@ private void InitializeComponent() // ConfigForm // this.AcceptButton = this.okButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(481, 587); + this.ClientSize = new System.Drawing.Size(361, 477); this.Controls.Add(this.applyButton); this.Controls.Add(this.configurationTabControl); this.Controls.Add(this.okButton); this.Controls.Add(this.cancelButton); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ConfigForm"; - this.Padding = new System.Windows.Forms.Padding(8, 7, 8, 7); + this.Padding = new System.Windows.Forms.Padding(6); this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Text = "Quotes Screensaver"; this.generalTabPage.ResumeLayout(false); @@ -539,5 +552,7 @@ private void InitializeComponent() private System.Windows.Forms.Label fontLabel; private System.Windows.Forms.Button fontButton; private System.Windows.Forms.TextBox pathTextBox; + private System.Windows.Forms.ComboBox backgroundAlignmentComboBox; + private System.Windows.Forms.Label backgroundAlignmentLabel; } } \ No newline at end of file diff --git a/AMSoftware.Quotes/ConfigForm.cs b/AMSoftware.Quotes/ConfigForm.cs index 304d41b..9991aca 100644 --- a/AMSoftware.Quotes/ConfigForm.cs +++ b/AMSoftware.Quotes/ConfigForm.cs @@ -30,6 +30,7 @@ public partial class ConfigForm : Form public ConfigForm() { InitializeComponent(); + this.Text = $"{Application.ProductName} [{Application.ProductVersion}]"; _configSettings = Settings.Default; @@ -51,6 +52,17 @@ public ConfigForm() backgroundColorTextBox.Text = $"{_configSettings.BackgroundColor.Name}"; backgroundImageTextBox.Text = _configSettings.BackgroundImagePath; + + backgroundAlignmentComboBox.DataSource = new ArrayList() + { + Tuple.Create(BackgroundAlignment.Fit, "Fit"), + Tuple.Create(BackgroundAlignment.Stretch, "Stretch"), + Tuple.Create(BackgroundAlignment.Center, "Center"), + Tuple.Create(BackgroundAlignment.Tile, "Tile"), + }; + backgroundAlignmentComboBox.DisplayMember = "Item2"; + backgroundAlignmentComboBox.ValueMember = "Item1"; + backgroundAlignmentComboBox.SelectedValue = (BackgroundAlignment)_configSettings.BackgroundAlignment; } private void FontButton_Click(object sender, EventArgs e) @@ -88,6 +100,18 @@ private void AlignmentComboBox_SelectedIndexChanged(object sender, EventArgs e) } } + private void BackgroundAlignmentComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + if (backgroundAlignmentComboBox.SelectedValue != null) + { + if (backgroundAlignmentComboBox.SelectedValue is BackgroundAlignment) + { + _configSettings.BackgroundAlignment = (int)backgroundAlignmentComboBox.SelectedValue; + applyButton.Enabled = true; + } + } + } + private void PathButton_Click(object sender, EventArgs e) { openFileDialog.Filter = "Quotes XML|*.xml|All files|*.*"; @@ -117,7 +141,7 @@ private void BackgroundColorButton_Click(object sender, EventArgs e) private void BackgroundImageButton_Click(object sender, EventArgs e) { - openFileDialog.Filter = "Bitmap files|*.bmp;*.dib|JPEG|*.jpg;*.jpeg;*.jpe;*.jfif|GIF|*.gif|PNG|*.png|All Picture Files|*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.png|All files|*.*"; + openFileDialog.Filter = "All Picture Files|*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.png|Bitmap files|*.bmp;*.dib|JPEG|*.jpg;*.jpeg;*.jpe;*.jfif|GIF|*.gif|PNG|*.png|All files|*.*"; openFileDialog.Title = "Select background image"; openFileDialog.FileName = _configSettings.BackgroundImagePath; @@ -181,9 +205,10 @@ private void PreviewPanel_Paint(object sender, PaintEventArgs e) TextAlignment = (TextAlignment)_configSettings.TextAlignment, TextShrinkToFit = true, BackgroundColor = _configSettings.BackgroundColor, - BackgroundImagePath = _configSettings.BackgroundImagePath + BackgroundImagePath = _configSettings.BackgroundImagePath, + BackgroundAlignment = (BackgroundAlignment)_configSettings.BackgroundAlignment, }); - renderer.Render(q, g); + renderer.Render(q, g, Screen.FromControl(this).Bounds); } } diff --git a/AMSoftware.Quotes/Program.cs b/AMSoftware.Quotes/Program.cs index c9a1b03..c607bca 100644 --- a/AMSoftware.Quotes/Program.cs +++ b/AMSoftware.Quotes/Program.cs @@ -84,7 +84,7 @@ private static void RunPreview(int parentHwndArgument) using (Graphics g = Graphics.FromHwnd(new IntPtr(parentHwndArgument))) { - renderer.Render(quote, g); + renderer.Render(quote, g, Screen.FromHandle(new IntPtr(parentHwndArgument)).Bounds); } } @@ -109,7 +109,8 @@ private static RenderSettings InitRenderSettings() TextAlignment = (TextAlignment)Settings.Default.TextAlignment, TextShrinkToFit = Settings.Default.TextShrinkToFit, BackgroundColor = Settings.Default.BackgroundColor, - BackgroundImagePath = Settings.Default.BackgroundImagePath + BackgroundImagePath = Settings.Default.BackgroundImagePath, + BackgroundAlignment = (BackgroundAlignment)Settings.Default.BackgroundAlignment }; } diff --git a/AMSoftware.Quotes/Properties/AssemblyInfo.cs b/AMSoftware.Quotes/Properties/AssemblyInfo.cs index d996e60..ae57207 100644 --- a/AMSoftware.Quotes/Properties/AssemblyInfo.cs +++ b/AMSoftware.Quotes/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ You should have received a copy of the GNU Affero General Public License // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.*")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/AMSoftware.Quotes/Properties/Settings.Designer.cs b/AMSoftware.Quotes/Properties/Settings.Designer.cs index 1be1e92..21b1645 100644 --- a/AMSoftware.Quotes/Properties/Settings.Designer.cs +++ b/AMSoftware.Quotes/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace AMSoftware.Quotes.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -106,5 +106,17 @@ public string BackgroundImagePath { this["BackgroundImagePath"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int BackgroundAlignment { + get { + return ((int)(this["BackgroundAlignment"])); + } + set { + this["BackgroundAlignment"] = value; + } + } } } diff --git a/AMSoftware.Quotes/Properties/Settings.settings b/AMSoftware.Quotes/Properties/Settings.settings index f42f614..197704e 100644 --- a/AMSoftware.Quotes/Properties/Settings.settings +++ b/AMSoftware.Quotes/Properties/Settings.settings @@ -23,5 +23,8 @@ + + 0 + \ No newline at end of file diff --git a/AMSoftware.Quotes/QuoteRenderer.cs b/AMSoftware.Quotes/QuoteRenderer.cs index dec5d2d..443f5a9 100644 --- a/AMSoftware.Quotes/QuoteRenderer.cs +++ b/AMSoftware.Quotes/QuoteRenderer.cs @@ -33,32 +33,39 @@ public QuoteRenderer(RenderSettings settings) public void Render(Quote q, Graphics g) { - g.Clear(_settings.BackgroundColor); + RectangleF clipBounds = g.VisibleClipBounds; - if (!string.IsNullOrWhiteSpace(_settings.BackgroundImagePath)) - { - try - { - Image backgroundImage = Image.FromFile(_settings.BackgroundImagePath); - g.DrawImage(backgroundImage, g.VisibleClipBounds); - } - catch { } - } + RenderBackground(g, clipBounds); + RenderText(q, g, clipBounds); - if (q == null) - { - g.Flush(FlushIntention.Flush); - return; - } + g.Flush(FlushIntention.Flush); + } + + public void Render(Quote q, Graphics g, RectangleF measureBounds) + { + g.ScaleTransform( + g.VisibleClipBounds.Width / measureBounds.Width, + g.VisibleClipBounds.Height / measureBounds.Height, + MatrixOrder.Append); + + RenderBackground(g, measureBounds); + RenderText(q, g, measureBounds); + + g.Flush(FlushIntention.Flush); + } + + private void RenderText(Quote q, Graphics g, RectangleF displayBounds) + { + if (q == null) return; // Set a margin of 5% - float marginLeft = g.VisibleClipBounds.Width * 0.05F; - float marginTop = g.VisibleClipBounds.Height * 0.05F; + float marginLeft = displayBounds.Width * 0.05F; + float marginTop = displayBounds.Height * 0.05F; RectangleF layoutArea = new RectangleF( marginLeft, marginTop, - g.VisibleClipBounds.Width - (2.0F * marginLeft), - g.VisibleClipBounds.Height - (2.0F * marginTop) + displayBounds.Width - (2.0F * marginLeft), + displayBounds.Height - (2.0F * marginTop) ); // Print author and year of quote. @@ -90,8 +97,121 @@ public void Render(Quote q, Graphics g) DrawQuoteText(q.QuoteText, g, textFont, _settings.TextColor, layoutArea); } } + } - g.Flush(FlushIntention.Flush); + private void RenderBackground(Graphics g, RectangleF displayBounds) + { + g.Clear(_settings.BackgroundColor); + + if (!string.IsNullOrWhiteSpace(_settings.BackgroundImagePath)) + { + try + { + Image backgroundImage = Image.FromFile(_settings.BackgroundImagePath); + + switch (_settings.BackgroundAlignment) + { + case BackgroundAlignment.Fit: + DrawBackgroundFitted(g, backgroundImage, displayBounds); + break; + case BackgroundAlignment.Stretch: + DrawBackgroundStretched(g, backgroundImage, displayBounds); + break; + case BackgroundAlignment.Center: + DrawBackgroundCentered(g, backgroundImage, displayBounds); + break; + case BackgroundAlignment.Tile: + DrawBackgroundTiled(g, backgroundImage, displayBounds); + break; + default: + break; + } + } + catch { } + } + } + + private static void DrawBackgroundFitted(Graphics g, Image backgroundImage, RectangleF displayBounds) + { + float ratioScreen = displayBounds.Width / displayBounds.Height; + float ratioImage = (float)backgroundImage.Width / (float)backgroundImage.Height; + + if (ratioScreen > ratioImage) + { + float width = displayBounds.Height * ratioImage; + RectangleF destRectangle = new RectangleF( + (displayBounds.Width - width) / 2, 0, + width, displayBounds.Height); + + g.DrawImage(backgroundImage, destRectangle); + } + else + { + float height = displayBounds.Width * ratioImage; + RectangleF destRectangle = new RectangleF( + 0, (displayBounds.Height - height) / 2, + displayBounds.Width, height); + + g.DrawImage(backgroundImage, destRectangle); + } + } + + private static void DrawBackgroundStretched(Graphics g, Image backgroundImage, RectangleF displayBounds) + { + float ratioScreen = displayBounds.Width / displayBounds.Height; + float ratioImage = (float)backgroundImage.Width / (float)backgroundImage.Height; + + if (ratioScreen > ratioImage) + { + float height = backgroundImage.Width / ratioScreen; + RectangleF srcRectangle = new RectangleF( + 0, (backgroundImage.Height - height) / 2, + backgroundImage.Width, height); + + g.DrawImage(backgroundImage, displayBounds, srcRectangle, GraphicsUnit.Pixel); + } + else + { + float width = backgroundImage.Height / ratioScreen; + RectangleF srcRectangle = new RectangleF( + (backgroundImage.Width - width) / 2, 0, + width, backgroundImage.Height); + + g.DrawImage(backgroundImage, displayBounds, srcRectangle, GraphicsUnit.Pixel); + } + } + + private static void DrawBackgroundTiled(Graphics g, Image backgroundImage, RectangleF displayBounds) + { + Rectangle srcRectangle = new Rectangle(0, 0, backgroundImage.Width, backgroundImage.Height); + + int tileCountWidth = (int)Math.Ceiling(displayBounds.Width / srcRectangle.Width); + int tileCountHeight = (int)Math.Ceiling(displayBounds.Height / srcRectangle.Height); + + int offsetX = (int)Math.Round(((tileCountWidth * srcRectangle.Width) - displayBounds.Width) / 2); + int offsetY = (int)Math.Round(((tileCountHeight * srcRectangle.Height) - displayBounds.Height) / 2); ; + + for (int y = 0; y < tileCountHeight; y++) + { + for (int x = 0; x < tileCountWidth; x++) + { + Rectangle destRectangle = new Rectangle((x * srcRectangle.Width) - offsetX, (y * srcRectangle.Height) - offsetY, srcRectangle.Width, srcRectangle.Height); + g.DrawImageUnscaledAndClipped(backgroundImage, destRectangle); + } + } + } + + private static void DrawBackgroundCentered(Graphics g, Image backgroundImage, RectangleF displayBounds) + { + Rectangle destRectangle = new Rectangle() + { + Width = backgroundImage.Width, + Height = backgroundImage.Height, + X = (int)Math.Round((displayBounds.Width - backgroundImage.Width) / 2), + Y = (int)Math.Round((displayBounds.Height - backgroundImage.Height) / 2) + }; + + g.DrawImageUnscaledAndClipped(backgroundImage, destRectangle); } private static Font GetFittedFont(string text, Graphics g, Font textFont, RectangleF area) @@ -105,11 +225,11 @@ private static Font GetFittedFont(string text, Graphics g, Font textFont, Rectan if (shrinkFactorHeight < shrinkFactorWidth) { - return new Font(textFont.FontFamily, textFont.Size * shrinkFactorHeight); + return new Font(textFont.FontFamily, textFont.Size * shrinkFactorHeight, textFont.Style); } else { - return new Font(textFont.FontFamily, textFont.Size * shrinkFactorWidth); + return new Font(textFont.FontFamily, textFont.Size * shrinkFactorWidth, textFont.Style); } } diff --git a/AMSoftware.Quotes/RenderSettings.cs b/AMSoftware.Quotes/RenderSettings.cs index b238cac..73ea2e7 100644 --- a/AMSoftware.Quotes/RenderSettings.cs +++ b/AMSoftware.Quotes/RenderSettings.cs @@ -27,5 +27,6 @@ internal class RenderSettings public TextAlignment TextAlignment { get; set; } public bool TextShrinkToFit { get; set; } public string BackgroundImagePath { get; set; } + public BackgroundAlignment BackgroundAlignment { get; internal set; } } } \ No newline at end of file diff --git a/AMSoftware.Quotes/ScreensaverApplicationContext.cs b/AMSoftware.Quotes/ScreensaverApplicationContext.cs index 0b12ba7..9b10b95 100644 --- a/AMSoftware.Quotes/ScreensaverApplicationContext.cs +++ b/AMSoftware.Quotes/ScreensaverApplicationContext.cs @@ -45,29 +45,50 @@ public ScreensaverApplicationContext(QuoteReader reader, RenderSettings settings private Form InitScreen(Screen screen, RenderSettings settings) { +#if DEBUG + Form f = new Form() + { + AutoScaleMode = AutoScaleMode.Font, + BackColor = settings.BackgroundColor, + Cursor = Cursors.No, + ForeColor = settings.TextColor, + FormBorderStyle = FormBorderStyle.Sizable, + Name = "MainForm", + ShowIcon = false, + ShowInTaskbar = false, + WindowState = FormWindowState.Normal, + Bounds = screen.Bounds, + StartPosition = FormStartPosition.Manual, + Size = new Size(screen.Bounds.Width, screen.Bounds.Height), + Location = new Point(0, 0), + }; +#else Form f = new Form() { - AutoScaleDimensions = new SizeF(12F, 25F), AutoScaleMode = AutoScaleMode.Font, BackColor = settings.BackgroundColor, - ClientSize = new Size(976, 635), Cursor = Cursors.No, ForeColor = settings.TextColor, FormBorderStyle = FormBorderStyle.None, Name = "MainForm", ShowIcon = false, ShowInTaskbar = false, - WindowState = FormWindowState.Maximized, + WindowState = FormWindowState.Normal, Bounds = screen.Bounds, - StartPosition = FormStartPosition.Manual + StartPosition = FormStartPosition.Manual, + Size = new Size(screen.Bounds.Width, screen.Bounds.Height), + Location = new Point(0, 0), + TopLevel = true, + TopMost = true }; - f.Paint += RegisteredForm_Paint; - f.KeyDown += RegisteredForm_KeyDown; - f.KeyUp += RegisteredForm_KeyUp; f.MouseDown += RegisteredForm_MouseDown; f.MouseMove += RegisteredForm_MouseMove; - +#endif + f.Paint += RegisteredForm_Paint; + f.KeyUp += RegisteredForm_KeyUp; + f.KeyDown += RegisteredForm_KeyDown; + return f; } diff --git a/AMSoftware.Quotes/_enums.cs b/AMSoftware.Quotes/_enums.cs index 944d8d7..757f30e 100644 --- a/AMSoftware.Quotes/_enums.cs +++ b/AMSoftware.Quotes/_enums.cs @@ -12,4 +12,12 @@ internal enum TextAlignment Center, Right } + + internal enum BackgroundAlignment + { + Fit = 0, + Stretch, + Center, + Tile + } }