agate-svn-commit Mailing List for AgateLib (Page 27)
Status: Alpha
Brought to you by:
kanato
You can subscribe to this list here.
2009 |
Jan
|
Feb
|
Mar
|
Apr
(86) |
May
(77) |
Jun
|
Jul
(1) |
Aug
(31) |
Sep
(12) |
Oct
(31) |
Nov
(53) |
Dec
(39) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2010 |
Jan
(53) |
Feb
(14) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
(7) |
Dec
(13) |
2011 |
Jan
(17) |
Feb
(5) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
(21) |
Dec
|
2012 |
Jan
(6) |
Feb
(14) |
Mar
(5) |
Apr
(4) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(8) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
(5) |
Nov
(9) |
Dec
(5) |
2014 |
Jan
(3) |
Feb
(2) |
Mar
(4) |
Apr
(3) |
May
|
Jun
(5) |
Jul
(33) |
Aug
(69) |
Sep
(35) |
Oct
(4) |
Nov
(1) |
Dec
|
From: <ka...@us...> - 2009-04-19 18:08:19
|
Revision: 887 http://agate.svn.sourceforge.net/agate/?rev=887&view=rev Author: kanato Date: 2009-04-19 18:08:08 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Add ability to adjust space above and below font glyphs. Modified Paths: -------------- trunk/AgateLib/BitmapFont/BitmapFontOptions.cs trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs trunk/Tools/FontCreator/CreateFont.Designer.cs trunk/Tools/FontCreator/CreateFont.cs trunk/Tools/FontCreator/EditGlyphs.Designer.cs trunk/Tools/FontCreator/FontCreator.cs trunk/Tools/FontCreator/frmFontCreator.cs Modified: trunk/AgateLib/BitmapFont/BitmapFontOptions.cs =================================================================== --- trunk/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-19 02:14:32 UTC (rev 886) +++ trunk/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-19 18:08:08 UTC (rev 887) @@ -275,6 +275,15 @@ set { mCreateBorder = value; } } + /// <summary> + /// Indicates how much to increase the top margin of letters. Can be negative. + /// </summary> + public int TopMarginAdjust { get; set; } + + /// <summary> + /// Indicates how much to increase the bottom margin of letters. Can be negative. + /// </summary> + public int BottomMarginAdjust { get; set; } } } Modified: trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs =================================================================== --- trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 02:14:32 UTC (rev 886) +++ trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 18:08:08 UTC (rev 887) @@ -213,6 +213,7 @@ sourceSize.Width += 2; sourceSize.Height += 2; } + sourceSize.Height += options.BottomMarginAdjust + options.TopMarginAdjust; int thisWidth = sourceSize.Width + bitmapPadding; @@ -271,14 +272,17 @@ height = 0; } + int drawX = x; + int drawY = y + options.TopMarginAdjust; + if (options.CreateBorder) { - rend.DrawText(borderG, i.ToString(), new Point(x, y + 1), borderColor); - rend.DrawText(borderG, i.ToString(), new Point(x + 2, y + 1), borderColor); - rend.DrawText(borderG, i.ToString(), new Point(x + 1, y), borderColor); - rend.DrawText(borderG, i.ToString(), new Point(x + 1, y + 2), borderColor); + rend.DrawText(borderG, i.ToString(), new Point(drawX , drawY + 1), borderColor); + rend.DrawText(borderG, i.ToString(), new Point(drawX + 2, drawY + 1), borderColor); + rend.DrawText(borderG, i.ToString(), new Point(drawX + 1, drawY), borderColor); + rend.DrawText(borderG, i.ToString(), new Point(drawX + 1, drawY + 2), borderColor); - rend.DrawText(g, i.ToString(), new Point(x + 1, y + 1), System.Drawing.Color.White); + rend.DrawText(g, i.ToString(), new Point(drawX + 1, drawY + 1), System.Drawing.Color.White); if (font.SizeInPoints >= 14.0) glyphs[i].LeftOverhang = 1; @@ -287,7 +291,7 @@ } else { - rend.DrawText(g, i.ToString(), new Point(x, y), System.Drawing.Color.White); + rend.DrawText(g, i.ToString(), new Point(drawX, drawY), System.Drawing.Color.White); } glyphs[i].SourceRect = new Rectangle( Modified: trunk/Tools/FontCreator/CreateFont.Designer.cs =================================================================== --- trunk/Tools/FontCreator/CreateFont.Designer.cs 2009-04-19 02:14:32 UTC (rev 886) +++ trunk/Tools/FontCreator/CreateFont.Designer.cs 2009-04-19 18:08:08 UTC (rev 887) @@ -28,417 +28,483 @@ /// </summary> private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.cboFamily = new System.Windows.Forms.ComboBox(); - this.nudSize = new System.Windows.Forms.NumericUpDown(); - this.label3 = new System.Windows.Forms.Label(); - this.chkBold = new System.Windows.Forms.CheckBox(); - this.chkItalic = new System.Windows.Forms.CheckBox(); - this.chkUnderline = new System.Windows.Forms.CheckBox(); - this.chkStrikeout = new System.Windows.Forms.CheckBox(); - this.txtSampleText = new System.Windows.Forms.TextBox(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.renderTarget = new AgateLib.WinForms.AgateRenderTarget(); - this.zoomRenderTarget = new AgateLib.WinForms.AgateRenderTarget(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.nudOpacity = new System.Windows.Forms.NumericUpDown(); - this.label6 = new System.Windows.Forms.Label(); - this.chkBorder = new System.Windows.Forms.CheckBox(); - this.btnBorderColor = new System.Windows.Forms.Button(); - this.cboEdges = new System.Windows.Forms.ComboBox(); - this.label4 = new System.Windows.Forms.Label(); - this.chkTextRenderer = new System.Windows.Forms.CheckBox(); - this.nudScale = new System.Windows.Forms.NumericUpDown(); - this.colorDialog = new System.Windows.Forms.ColorDialog(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.label8 = new System.Windows.Forms.Label(); - this.cboBg = new System.Windows.Forms.ComboBox(); - this.btnDisplayColor = new System.Windows.Forms.Button(); - this.label5 = new System.Windows.Forms.Label(); - this.label7 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.nudSize)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); - this.groupBox1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nudOpacity)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.nudScale)).BeginInit(); - this.groupBox2.SuspendLayout(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(8, 22); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(66, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Sample Text"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(13, 30); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(60, 13); - this.label2.TabIndex = 1; - this.label2.Text = "Font Family"; - // - // cboFamily - // - this.cboFamily.DropDownHeight = 210; - this.cboFamily.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cboFamily.DropDownWidth = 300; - this.cboFamily.FormattingEnabled = true; - this.cboFamily.IntegralHeight = false; - this.cboFamily.Location = new System.Drawing.Point(79, 27); - this.cboFamily.Name = "cboFamily"; - this.cboFamily.Size = new System.Drawing.Size(145, 21); - this.cboFamily.TabIndex = 3; - this.cboFamily.SelectedIndexChanged += new System.EventHandler(this.cboFamily_SelectedIndexChanged); - // - // nudSize - // - this.nudSize.DecimalPlaces = 1; - this.nudSize.Location = new System.Drawing.Point(79, 54); - this.nudSize.Maximum = new decimal(new int[] { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.cboFamily = new System.Windows.Forms.ComboBox(); + this.nudSize = new System.Windows.Forms.NumericUpDown(); + this.label3 = new System.Windows.Forms.Label(); + this.chkBold = new System.Windows.Forms.CheckBox(); + this.chkItalic = new System.Windows.Forms.CheckBox(); + this.chkUnderline = new System.Windows.Forms.CheckBox(); + this.chkStrikeout = new System.Windows.Forms.CheckBox(); + this.txtSampleText = new System.Windows.Forms.TextBox(); + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.nudOpacity = new System.Windows.Forms.NumericUpDown(); + this.label6 = new System.Windows.Forms.Label(); + this.chkBorder = new System.Windows.Forms.CheckBox(); + this.btnBorderColor = new System.Windows.Forms.Button(); + this.cboEdges = new System.Windows.Forms.ComboBox(); + this.label4 = new System.Windows.Forms.Label(); + this.chkTextRenderer = new System.Windows.Forms.CheckBox(); + this.nudScale = new System.Windows.Forms.NumericUpDown(); + this.colorDialog = new System.Windows.Forms.ColorDialog(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.label8 = new System.Windows.Forms.Label(); + this.cboBg = new System.Windows.Forms.ComboBox(); + this.btnDisplayColor = new System.Windows.Forms.Button(); + this.label5 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.nudTopMargin = new System.Windows.Forms.NumericUpDown(); + this.renderTarget = new AgateLib.WinForms.AgateRenderTarget(); + this.zoomRenderTarget = new AgateLib.WinForms.AgateRenderTarget(); + this.nudBottomMargin = new System.Windows.Forms.NumericUpDown(); + this.label10 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.nudSize)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudOpacity)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudScale)).BeginInit(); + this.groupBox2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudTopMargin)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudBottomMargin)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(66, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Sample Text"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 25); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(60, 13); + this.label2.TabIndex = 1; + this.label2.Text = "Font Family"; + // + // cboFamily + // + this.cboFamily.DropDownHeight = 210; + this.cboFamily.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboFamily.DropDownWidth = 300; + this.cboFamily.FormattingEnabled = true; + this.cboFamily.IntegralHeight = false; + this.cboFamily.Location = new System.Drawing.Point(79, 22); + this.cboFamily.Name = "cboFamily"; + this.cboFamily.Size = new System.Drawing.Size(145, 21); + this.cboFamily.TabIndex = 3; + this.cboFamily.SelectedIndexChanged += new System.EventHandler(this.cboFamily_SelectedIndexChanged); + // + // nudSize + // + this.nudSize.DecimalPlaces = 1; + this.nudSize.Location = new System.Drawing.Point(79, 49); + this.nudSize.Maximum = new decimal(new int[] { 200, 0, 0, 0}); - this.nudSize.Minimum = new decimal(new int[] { + this.nudSize.Minimum = new decimal(new int[] { 1, 0, 0, 0}); - this.nudSize.Name = "nudSize"; - this.nudSize.Size = new System.Drawing.Size(59, 20); - this.nudSize.TabIndex = 4; - this.nudSize.Value = new decimal(new int[] { + this.nudSize.Name = "nudSize"; + this.nudSize.Size = new System.Drawing.Size(59, 20); + this.nudSize.TabIndex = 4; + this.nudSize.Value = new decimal(new int[] { 140, 0, 0, 65536}); - this.nudSize.ValueChanged += new System.EventHandler(this.nudSize_ValueChanged); - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(22, 56); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(51, 13); - this.label3.TabIndex = 5; - this.label3.Text = "Font Size"; - // - // chkBold - // - this.chkBold.AutoSize = true; - this.chkBold.Location = new System.Drawing.Point(48, 80); - this.chkBold.Name = "chkBold"; - this.chkBold.Size = new System.Drawing.Size(47, 17); - this.chkBold.TabIndex = 6; - this.chkBold.Text = "Bold"; - this.chkBold.UseVisualStyleBackColor = true; - this.chkBold.CheckedChanged += new System.EventHandler(this.chkBold_CheckedChanged); - // - // chkItalic - // - this.chkItalic.AutoSize = true; - this.chkItalic.Location = new System.Drawing.Point(48, 103); - this.chkItalic.Name = "chkItalic"; - this.chkItalic.Size = new System.Drawing.Size(48, 17); - this.chkItalic.TabIndex = 7; - this.chkItalic.Text = "Italic"; - this.chkItalic.UseVisualStyleBackColor = true; - this.chkItalic.CheckedChanged += new System.EventHandler(this.chkItalic_CheckedChanged); - // - // chkUnderline - // - this.chkUnderline.AutoSize = true; - this.chkUnderline.Location = new System.Drawing.Point(113, 80); - this.chkUnderline.Name = "chkUnderline"; - this.chkUnderline.Size = new System.Drawing.Size(71, 17); - this.chkUnderline.TabIndex = 8; - this.chkUnderline.Text = "Underline"; - this.chkUnderline.UseVisualStyleBackColor = true; - this.chkUnderline.CheckedChanged += new System.EventHandler(this.chkUnderline_CheckedChanged); - // - // chkStrikeout - // - this.chkStrikeout.AutoSize = true; - this.chkStrikeout.Location = new System.Drawing.Point(113, 103); - this.chkStrikeout.Name = "chkStrikeout"; - this.chkStrikeout.Size = new System.Drawing.Size(68, 17); - this.chkStrikeout.TabIndex = 9; - this.chkStrikeout.Text = "Strikeout"; - this.chkStrikeout.UseVisualStyleBackColor = true; - this.chkStrikeout.CheckedChanged += new System.EventHandler(this.chkStrikeout_CheckedChanged); - // - // txtSampleText - // - this.txtSampleText.Location = new System.Drawing.Point(80, 19); - this.txtSampleText.Multiline = true; - this.txtSampleText.Name = "txtSampleText"; - this.txtSampleText.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.txtSampleText.Size = new System.Drawing.Size(216, 69); - this.txtSampleText.TabIndex = 10; - this.txtSampleText.Text = "abcdefghijklmnopqrstuvwxyz\r\nABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n01234567890\r\n!@#$%^&*(),<" + - ".>/?;:\'\"-_=+\\|"; - this.txtSampleText.TextChanged += new System.EventHandler(this.txtSampleText_TextChanged); - // - // splitContainer1 - // - this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.splitContainer1.Location = new System.Drawing.Point(3, 225); - this.splitContainer1.Name = "splitContainer1"; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.renderTarget); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.zoomRenderTarget); - this.splitContainer1.Size = new System.Drawing.Size(570, 131); - this.splitContainer1.SplitterDistance = 211; - this.splitContainer1.SplitterWidth = 8; - this.splitContainer1.TabIndex = 11; - // - // renderTarget - // - this.renderTarget.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.renderTarget.Dock = System.Windows.Forms.DockStyle.Fill; - this.renderTarget.Location = new System.Drawing.Point(0, 0); - this.renderTarget.Name = "renderTarget"; - this.renderTarget.Size = new System.Drawing.Size(211, 131); - this.renderTarget.TabIndex = 0; - this.renderTarget.Resize += new System.EventHandler(this.renderTarget_Resize); - // - // zoomRenderTarget - // - this.zoomRenderTarget.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.zoomRenderTarget.Dock = System.Windows.Forms.DockStyle.Fill; - this.zoomRenderTarget.Location = new System.Drawing.Point(0, 0); - this.zoomRenderTarget.Name = "zoomRenderTarget"; - this.zoomRenderTarget.Size = new System.Drawing.Size(351, 131); - this.zoomRenderTarget.TabIndex = 1; - this.zoomRenderTarget.Resize += new System.EventHandler(this.renderTarget_Resize); - // - // groupBox1 - // - this.groupBox1.Controls.Add(this.nudOpacity); - this.groupBox1.Controls.Add(this.label6); - this.groupBox1.Controls.Add(this.chkBorder); - this.groupBox1.Controls.Add(this.btnBorderColor); - this.groupBox1.Controls.Add(this.cboEdges); - this.groupBox1.Controls.Add(this.label4); - this.groupBox1.Controls.Add(this.chkTextRenderer); - this.groupBox1.Controls.Add(this.label2); - this.groupBox1.Controls.Add(this.cboFamily); - this.groupBox1.Controls.Add(this.nudSize); - this.groupBox1.Controls.Add(this.chkStrikeout); - this.groupBox1.Controls.Add(this.chkItalic); - this.groupBox1.Controls.Add(this.label3); - this.groupBox1.Controls.Add(this.chkUnderline); - this.groupBox1.Controls.Add(this.chkBold); - this.groupBox1.Location = new System.Drawing.Point(3, 3); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(235, 216); - this.groupBox1.TabIndex = 12; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "Font Creation Options"; - // - // nudOpacity - // - this.nudOpacity.Location = new System.Drawing.Point(150, 189); - this.nudOpacity.Maximum = new decimal(new int[] { + this.nudSize.ValueChanged += new System.EventHandler(this.nudSize_ValueChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(22, 51); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(51, 13); + this.label3.TabIndex = 5; + this.label3.Text = "Font Size"; + // + // chkBold + // + this.chkBold.AutoSize = true; + this.chkBold.Location = new System.Drawing.Point(48, 75); + this.chkBold.Name = "chkBold"; + this.chkBold.Size = new System.Drawing.Size(47, 17); + this.chkBold.TabIndex = 6; + this.chkBold.Text = "Bold"; + this.chkBold.UseVisualStyleBackColor = true; + this.chkBold.CheckedChanged += new System.EventHandler(this.chkBold_CheckedChanged); + // + // chkItalic + // + this.chkItalic.AutoSize = true; + this.chkItalic.Location = new System.Drawing.Point(190, 75); + this.chkItalic.Name = "chkItalic"; + this.chkItalic.Size = new System.Drawing.Size(48, 17); + this.chkItalic.TabIndex = 7; + this.chkItalic.Text = "Italic"; + this.chkItalic.UseVisualStyleBackColor = true; + this.chkItalic.CheckedChanged += new System.EventHandler(this.chkItalic_CheckedChanged); + // + // chkUnderline + // + this.chkUnderline.AutoSize = true; + this.chkUnderline.Location = new System.Drawing.Point(113, 75); + this.chkUnderline.Name = "chkUnderline"; + this.chkUnderline.Size = new System.Drawing.Size(71, 17); + this.chkUnderline.TabIndex = 8; + this.chkUnderline.Text = "Underline"; + this.chkUnderline.UseVisualStyleBackColor = true; + this.chkUnderline.CheckedChanged += new System.EventHandler(this.chkUnderline_CheckedChanged); + // + // chkStrikeout + // + this.chkStrikeout.AutoSize = true; + this.chkStrikeout.Location = new System.Drawing.Point(170, 51); + this.chkStrikeout.Name = "chkStrikeout"; + this.chkStrikeout.Size = new System.Drawing.Size(68, 17); + this.chkStrikeout.TabIndex = 9; + this.chkStrikeout.Text = "Strikeout"; + this.chkStrikeout.UseVisualStyleBackColor = true; + this.chkStrikeout.CheckedChanged += new System.EventHandler(this.chkStrikeout_CheckedChanged); + // + // txtSampleText + // + this.txtSampleText.Location = new System.Drawing.Point(80, 19); + this.txtSampleText.Multiline = true; + this.txtSampleText.Name = "txtSampleText"; + this.txtSampleText.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.txtSampleText.Size = new System.Drawing.Size(186, 69); + this.txtSampleText.TabIndex = 10; + this.txtSampleText.Text = "abcdefghijklmnopqrstuvwxyz\r\nABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n01234567890\r\n!@#$%^&*(),<" + + ".>/?;:\'\"-_=+\\|"; + this.txtSampleText.TextChanged += new System.EventHandler(this.txtSampleText_TextChanged); + // + // splitContainer1 + // + this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.splitContainer1.Location = new System.Drawing.Point(3, 225); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.renderTarget); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.zoomRenderTarget); + this.splitContainer1.Size = new System.Drawing.Size(564, 170); + this.splitContainer1.SplitterDistance = 208; + this.splitContainer1.SplitterWidth = 8; + this.splitContainer1.TabIndex = 11; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.label10); + this.groupBox1.Controls.Add(this.nudBottomMargin); + this.groupBox1.Controls.Add(this.nudTopMargin); + this.groupBox1.Controls.Add(this.label9); + this.groupBox1.Controls.Add(this.nudOpacity); + this.groupBox1.Controls.Add(this.label6); + this.groupBox1.Controls.Add(this.chkBorder); + this.groupBox1.Controls.Add(this.btnBorderColor); + this.groupBox1.Controls.Add(this.cboEdges); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.chkTextRenderer); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.cboFamily); + this.groupBox1.Controls.Add(this.nudSize); + this.groupBox1.Controls.Add(this.chkStrikeout); + this.groupBox1.Controls.Add(this.chkItalic); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.chkUnderline); + this.groupBox1.Controls.Add(this.chkBold); + this.groupBox1.Location = new System.Drawing.Point(3, 3); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(265, 216); + this.groupBox1.TabIndex = 12; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Font Creation Options"; + // + // nudOpacity + // + this.nudOpacity.Location = new System.Drawing.Point(150, 139); + this.nudOpacity.Maximum = new decimal(new int[] { 255, 0, 0, 0}); - this.nudOpacity.Name = "nudOpacity"; - this.nudOpacity.Size = new System.Drawing.Size(54, 20); - this.nudOpacity.TabIndex = 17; - this.nudOpacity.Value = new decimal(new int[] { + this.nudOpacity.Name = "nudOpacity"; + this.nudOpacity.Size = new System.Drawing.Size(54, 20); + this.nudOpacity.TabIndex = 17; + this.nudOpacity.Value = new decimal(new int[] { 128, 0, 0, 0}); - this.nudOpacity.ValueChanged += new System.EventHandler(this.nudOpacity_ValueChanged); - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(147, 173); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(80, 13); - this.label6.TabIndex = 16; - this.label6.Text = "Border Opacity:"; - // - // chkBorder - // - this.chkBorder.AutoSize = true; - this.chkBorder.Location = new System.Drawing.Point(9, 180); - this.chkBorder.Name = "chkBorder"; - this.chkBorder.Size = new System.Drawing.Size(91, 17); - this.chkBorder.TabIndex = 15; - this.chkBorder.Text = "Create Border"; - this.chkBorder.UseVisualStyleBackColor = true; - this.chkBorder.CheckedChanged += new System.EventHandler(this.chkBorder_CheckedChanged); - // - // btnBorderColor - // - this.btnBorderColor.BackColor = System.Drawing.Color.Black; - this.btnBorderColor.Location = new System.Drawing.Point(106, 176); - this.btnBorderColor.Name = "btnBorderColor"; - this.btnBorderColor.Size = new System.Drawing.Size(32, 23); - this.btnBorderColor.TabIndex = 14; - this.btnBorderColor.UseVisualStyleBackColor = false; - this.btnBorderColor.Click += new System.EventHandler(this.btnBorderColor_Click); - // - // cboEdges - // - this.cboEdges.DropDownHeight = 210; - this.cboEdges.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cboEdges.DropDownWidth = 300; - this.cboEdges.FormattingEnabled = true; - this.cboEdges.IntegralHeight = false; - this.cboEdges.Location = new System.Drawing.Point(79, 149); - this.cboEdges.Name = "cboEdges"; - this.cboEdges.Size = new System.Drawing.Size(145, 21); - this.cboEdges.TabIndex = 12; - this.cboEdges.SelectedIndexChanged += new System.EventHandler(this.cboEdges_SelectedIndexChanged); - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(6, 152); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(67, 13); - this.label4.TabIndex = 11; - this.label4.Text = "Glyph Edges"; - // - // chkTextRenderer - // - this.chkTextRenderer.AutoSize = true; - this.chkTextRenderer.Checked = true; - this.chkTextRenderer.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkTextRenderer.Location = new System.Drawing.Point(9, 126); - this.chkTextRenderer.Name = "chkTextRenderer"; - this.chkTextRenderer.Size = new System.Drawing.Size(207, 17); - this.chkTextRenderer.TabIndex = 10; - this.chkTextRenderer.Text = "Use TextRenderer instead of Graphics"; - this.chkTextRenderer.UseVisualStyleBackColor = true; - this.chkTextRenderer.CheckedChanged += new System.EventHandler(this.chkTextRenderer_CheckedChanged); - // - // nudScale - // - this.nudScale.DecimalPlaces = 1; - this.nudScale.Location = new System.Drawing.Point(80, 123); - this.nudScale.Maximum = new decimal(new int[] { + this.nudOpacity.ValueChanged += new System.EventHandler(this.nudOpacity_ValueChanged); + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(147, 123); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(80, 13); + this.label6.TabIndex = 16; + this.label6.Text = "Border Opacity:"; + // + // chkBorder + // + this.chkBorder.AutoSize = true; + this.chkBorder.Location = new System.Drawing.Point(12, 130); + this.chkBorder.Name = "chkBorder"; + this.chkBorder.Size = new System.Drawing.Size(91, 17); + this.chkBorder.TabIndex = 15; + this.chkBorder.Text = "Create Border"; + this.chkBorder.UseVisualStyleBackColor = true; + this.chkBorder.CheckedChanged += new System.EventHandler(this.chkBorder_CheckedChanged); + // + // btnBorderColor + // + this.btnBorderColor.BackColor = System.Drawing.Color.Black; + this.btnBorderColor.Location = new System.Drawing.Point(106, 126); + this.btnBorderColor.Name = "btnBorderColor"; + this.btnBorderColor.Size = new System.Drawing.Size(32, 23); + this.btnBorderColor.TabIndex = 14; + this.btnBorderColor.UseVisualStyleBackColor = false; + this.btnBorderColor.Click += new System.EventHandler(this.btnBorderColor_Click); + // + // cboEdges + // + this.cboEdges.DropDownHeight = 210; + this.cboEdges.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboEdges.DropDownWidth = 300; + this.cboEdges.FormattingEnabled = true; + this.cboEdges.IntegralHeight = false; + this.cboEdges.Location = new System.Drawing.Point(82, 98); + this.cboEdges.Name = "cboEdges"; + this.cboEdges.Size = new System.Drawing.Size(145, 21); + this.cboEdges.TabIndex = 12; + this.cboEdges.SelectedIndexChanged += new System.EventHandler(this.cboEdges_SelectedIndexChanged); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(9, 101); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(67, 13); + this.label4.TabIndex = 11; + this.label4.Text = "Glyph Edges"; + // + // chkTextRenderer + // + this.chkTextRenderer.AutoSize = true; + this.chkTextRenderer.Checked = true; + this.chkTextRenderer.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkTextRenderer.Location = new System.Drawing.Point(9, 193); + this.chkTextRenderer.Name = "chkTextRenderer"; + this.chkTextRenderer.Size = new System.Drawing.Size(207, 17); + this.chkTextRenderer.TabIndex = 10; + this.chkTextRenderer.Text = "Use TextRenderer instead of Graphics"; + this.chkTextRenderer.UseVisualStyleBackColor = true; + this.chkTextRenderer.CheckedChanged += new System.EventHandler(this.chkTextRenderer_CheckedChanged); + // + // nudScale + // + this.nudScale.DecimalPlaces = 1; + this.nudScale.Location = new System.Drawing.Point(80, 123); + this.nudScale.Maximum = new decimal(new int[] { 20, 0, 0, 0}); - this.nudScale.Name = "nudScale"; - this.nudScale.Size = new System.Drawing.Size(120, 20); - this.nudScale.TabIndex = 14; - this.nudScale.Value = new decimal(new int[] { + this.nudScale.Name = "nudScale"; + this.nudScale.Size = new System.Drawing.Size(120, 20); + this.nudScale.TabIndex = 14; + this.nudScale.Value = new decimal(new int[] { 4, 0, 0, 0}); - this.nudScale.ValueChanged += new System.EventHandler(this.nudScale_ValueChanged); - // - // groupBox2 - // - this.groupBox2.Controls.Add(this.label8); - this.groupBox2.Controls.Add(this.cboBg); - this.groupBox2.Controls.Add(this.btnDisplayColor); - this.groupBox2.Controls.Add(this.label5); - this.groupBox2.Controls.Add(this.label1); - this.groupBox2.Controls.Add(this.txtSampleText); - this.groupBox2.Controls.Add(this.nudScale); - this.groupBox2.Location = new System.Drawing.Point(244, 3); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(302, 170); - this.groupBox2.TabIndex = 13; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Display Options"; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(8, 125); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(67, 13); - this.label8.TabIndex = 15; - this.label8.Text = "Scale Factor"; - // - // cboBg - // - this.cboBg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cboBg.FormattingEnabled = true; - this.cboBg.Items.AddRange(new object[] { + this.nudScale.ValueChanged += new System.EventHandler(this.nudScale_ValueChanged); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.label8); + this.groupBox2.Controls.Add(this.cboBg); + this.groupBox2.Controls.Add(this.btnDisplayColor); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this.txtSampleText); + this.groupBox2.Controls.Add(this.nudScale); + this.groupBox2.Location = new System.Drawing.Point(274, 3); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(272, 186); + this.groupBox2.TabIndex = 13; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Display Options"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(8, 125); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(67, 13); + this.label8.TabIndex = 15; + this.label8.Text = "Scale Factor"; + // + // cboBg + // + this.cboBg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboBg.FormattingEnabled = true; + this.cboBg.Items.AddRange(new object[] { "Dark Background", "Light Background"}); - this.cboBg.Location = new System.Drawing.Point(147, 95); - this.cboBg.Name = "cboBg"; - this.cboBg.Size = new System.Drawing.Size(149, 21); - this.cboBg.TabIndex = 13; - this.cboBg.SelectedIndexChanged += new System.EventHandler(this.cboBg_SelectedIndexChanged); - // - // btnDisplayColor - // - this.btnDisplayColor.BackColor = System.Drawing.Color.White; - this.btnDisplayColor.Location = new System.Drawing.Point(80, 94); - this.btnDisplayColor.Name = "btnDisplayColor"; - this.btnDisplayColor.Size = new System.Drawing.Size(28, 23); - this.btnDisplayColor.TabIndex = 12; - this.btnDisplayColor.UseVisualStyleBackColor = false; - this.btnDisplayColor.Click += new System.EventHandler(this.btnDisplayColor_Click); - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(19, 98); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(55, 13); - this.label5.TabIndex = 11; - this.label5.Text = "Text Color"; - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(30, 173); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(46, 13); - this.label7.TabIndex = 16; - this.label7.Text = "Scale:"; - // - // CreateFont - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.groupBox2); - this.Controls.Add(this.groupBox1); - this.Controls.Add(this.splitContainer1); - this.Name = "CreateFont"; - this.Size = new System.Drawing.Size(576, 359); - ((System.ComponentModel.ISupportInitialize)(this.nudSize)).EndInit(); - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel2.ResumeLayout(false); - this.splitContainer1.ResumeLayout(false); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.nudOpacity)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.nudScale)).EndInit(); - this.groupBox2.ResumeLayout(false); - this.groupBox2.PerformLayout(); - this.ResumeLayout(false); + this.cboBg.Location = new System.Drawing.Point(147, 95); + this.cboBg.Name = "cboBg"; + this.cboBg.Size = new System.Drawing.Size(119, 21); + this.cboBg.TabIndex = 13; + this.cboBg.SelectedIndexChanged += new System.EventHandler(this.cboBg_SelectedIndexChanged); + // + // btnDisplayColor + // + this.btnDisplayColor.BackColor = System.Drawing.Color.White; + this.btnDisplayColor.Location = new System.Drawing.Point(80, 94); + this.btnDisplayColor.Name = "btnDisplayColor"; + this.btnDisplayColor.Size = new System.Drawing.Size(28, 23); + this.btnDisplayColor.TabIndex = 12; + this.btnDisplayColor.UseVisualStyleBackColor = false; + this.btnDisplayColor.Click += new System.EventHandler(this.btnDisplayColor_Click); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(19, 98); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(55, 13); + this.label5.TabIndex = 11; + this.label5.Text = "Text Color"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(30, 173); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(46, 13); + this.label7.TabIndex = 16; + this.label7.Text = "Scale:"; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(9, 167); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(69, 13); + this.label9.TabIndex = 18; + this.label9.Text = "Margins: Top"; + // + // nudTopMargin + // + this.nudTopMargin.Location = new System.Drawing.Point(85, 165); + this.nudTopMargin.Maximum = new decimal(new int[] { + 50, + 0, + 0, + 0}); + this.nudTopMargin.Minimum = new decimal(new int[] { + 50, + 0, + 0, + -2147483648}); + this.nudTopMargin.Name = "nudTopMargin"; + this.nudTopMargin.Size = new System.Drawing.Size(53, 20); + this.nudTopMargin.TabIndex = 19; + this.nudTopMargin.ValueChanged += new System.EventHandler(this.nudTopMargin_ValueChanged); + // + // renderTarget + // + this.renderTarget.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.renderTarget.Dock = System.Windows.Forms.DockStyle.Fill; + this.renderTarget.Location = new System.Drawing.Point(0, 0); + this.renderTarget.Name = "renderTarget"; + this.renderTarget.Size = new System.Drawing.Size(208, 170); + this.renderTarget.TabIndex = 0; + this.renderTarget.Resize += new System.EventHandler(this.renderTarget_Resize); + // + // zoomRenderTarget + // + this.zoomRenderTarget.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.zoomRenderTarget.Dock = System.Windows.Forms.DockStyle.Fill; + this.zoomRenderTarget.Location = new System.Drawing.Point(0, 0); + this.zoomRenderTarget.Name = "zoomRenderTarget"; + this.zoomRenderTarget.Size = new System.Drawing.Size(348, 170); + this.zoomRenderTarget.TabIndex = 1; + this.zoomRenderTarget.Resize += new System.EventHandler(this.renderTarget_Resize); + // + // nudBottomMargin + // + this.nudBottomMargin.Location = new System.Drawing.Point(206, 165); + this.nudBottomMargin.Maximum = new decimal(new int[] { + 50, + 0, + 0, + 0}); + this.nudBottomMargin.Minimum = new decimal(new int[] { + 50, + 0, + 0, + -2147483648}); + this.nudBottomMargin.Name = "nudBottomMargin"; + this.nudBottomMargin.Size = new System.Drawing.Size(53, 20); + this.nudBottomMargin.TabIndex = 20; + this.nudBottomMargin.ValueChanged += new System.EventHandler(this.nudBottomMargin_ValueChanged); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(160, 167); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(40, 13); + this.label10.TabIndex = 21; + this.label10.Text = "Bottom"; + // + // CreateFont + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.splitContainer1); + this.Name = "CreateFont"; + this.Size = new System.Drawing.Size(570, 398); + ((System.ComponentModel.ISupportInitialize)(this.nudSize)).EndInit(); + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.ResumeLayout(false); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudOpacity)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudScale)).EndInit(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.nudTopMargin)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudBottomMargin)).EndInit(); + this.ResumeLayout(false); } @@ -473,6 +539,10 @@ private System.Windows.Forms.NumericUpDown nudScale; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; + private System.Windows.Forms.NumericUpDown nudTopMargin; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.NumericUpDown nudBottomMargin; } } Modified: trunk/Tools/FontCreator/CreateFont.cs =================================================================== --- trunk/Tools/FontCreator/CreateFont.cs 2009-04-19 02:14:32 UTC (rev 886) +++ trunk/Tools/FontCreator/CreateFont.cs 2009-04-19 18:08:08 UTC (rev 887) @@ -10,245 +10,243 @@ namespace FontCreator { - public partial class CreateFont : UserControl - { - FontBuilder sample; + public partial class CreateFont : UserControl + { + FontBuilder sample; - bool AnyDesignMode - { - get - { - Control p = this; + bool AnyDesignMode + { + get + { + Control p = this; - do - { - if (p.Site != null && p.Site.DesignMode) - return true; + do + { + if (p.Site != null && p.Site.DesignMode) + return true; - p = p.Parent; + p = p.Parent; - } while (p != null); + } while (p != null); - return false; - } - } + return false; + } + } - public CreateFont() - { - InitializeComponent(); - } + public CreateFont() + { + InitializeComponent(); + } - public FontBuilder FontBuilder { get { return sample; } } + public FontBuilder FontBuilder { get { return sample; } } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); - if (AnyDesignMode) - return; + if (AnyDesignMode) + return; - sample = new FontBuilder(); + sample = new FontBuilder(); - sample.SetRenderTarget(renderTarget, zoomRenderTarget); + sample.SetRenderTarget(renderTarget, zoomRenderTarget); - int index = 0; + int index = 0; List<string> fonts = new List<string>(); - foreach (FontFamily fam in FontFamily.Families) - { + foreach (FontFamily fam in FontFamily.Families) + { fonts.Add(fam.Name); } fonts.Sort(); foreach (string family in fonts) { - if (family == "Arial" || family.Contains("Sans Serif") && index == 0) - index = cboFamily.Items.Count; + if (family == "Arial" || family.Contains("Sans Serif") && index == 0) + index = cboFamily.Items.Count; - cboFamily.Items.Add(family); - } + cboFamily.Items.Add(family); + } - - cboFamily.SelectedIndex = index; - txtSampleText_TextChanged(null, null); - foreach (BitmapFontEdgeOptions opt in - Enum.GetValues(typeof(BitmapFontEdgeOptions))) - { - cboEdges.Items.Add(opt); - } + cboFamily.SelectedIndex = index; + txtSampleText_TextChanged(null, null); - cboEdges.SelectedItem = BitmapFontEdgeOptions.IntensityAlphaWhite; + foreach (BitmapFontEdgeOptions opt in + Enum.GetValues(typeof(BitmapFontEdgeOptions))) + { + cboEdges.Items.Add(opt); + } - cboBg.SelectedIndex = 0; - } + cboEdges.SelectedItem = BitmapFontEdgeOptions.IntensityAlphaWhite; + cboBg.SelectedIndex = 0; + } - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - if (sample == null) - return; + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); - sample.Draw(); - } + if (sample == null) + return; - private void cboFamily_SelectedIndexChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.Draw(); + } - sample.FontFamily = cboFamily.SelectedItem.ToString(); - } - - private void nudScale_ValueChanged(object sender, EventArgs e) - { - if (sample == null) - return; + private void cboFamily_SelectedIndexChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.DisplayScale = (double)nudScale.Value; - } - private void nudSize_ValueChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.FontFamily = cboFamily.SelectedItem.ToString(); + } - sample.FontSize = (float)nudSize.Value; - } - private void chkBold_CheckedChanged(object sender, EventArgs e) - { - if (sample == null) - return; + private void nudScale_ValueChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Bold = chkBold.Checked; - } - private void chkItalic_CheckedChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.DisplayScale = (double)nudScale.Value; + } + private void nudSize_ValueChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Italic = chkItalic.Checked; - } - private void chkUnderline_CheckedChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.FontSize = (float)nudSize.Value; + } + private void chkBold_CheckedChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Underline = chkUnderline.Checked; - } - private void chkStrikeout_CheckedChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.Bold = chkBold.Checked; + } + private void chkItalic_CheckedChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Strikeout = chkStrikeout.Checked; - } - private void txtSampleText_TextChanged(object sender, EventArgs e) - { - if (sample == null) - return; + sample.Italic = chkItalic.Checked; + } + private void chkUnderline_CheckedChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Text = txtSampleText.Text; - } + sample.Underline = chkUnderline.Checked; + } + private void chkStrikeout_CheckedChanged(object sender, EventArgs e) + { + if (sample == null) + return; - private void renderTarget_Resize(object sender, EventArgs e) - { - if (sample == null) - return; + sample.Strikeout = chkStrikeout.Checked; + } + private void txtSampleText_TextChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Draw(); - } + sample.Text = txtSampleText.Text; + } - private void btnBorderColor_Click(object sender, EventArgs e) - { - colorDialog.Color = btnBorderColor.BackColor; + private void nudTopMargin_ValueChanged(object sender, EventArgs e) + { + if (sample == null) + return; - if (colorDialog.ShowDialog() == DialogResult.OK) - { - btnBorderColor.BackColor = colorDialog.Color; + sample.TopMarginAdjust = (int)nudTopMargin.Value; + } - sample.Options.BorderColor = ConvertColor(colorDialog.Color); - sample.Options.BorderColor = AgateLib.Geometry.Color.FromArgb((int)nudOpacity.Value, sample.Options.BorderColor); + private void nudBottomMargin_ValueChanged(object sender, EventArgs e) + { + if (sample == null) + return; - sample.Options.CreateBorder = true; + sample.BottomMarginAdjust = (int)nudBottomMargin.Value; + } + private void renderTarget_Resize(object sender, EventArgs e) + { + if (sample == null) + return; - chkBorder.Checked = true; + sample.Draw(); + } - sample.CreateFont(); - } - } - private void nudOpacity_ValueChanged(object sender, EventArgs e) - { - sample.Options.BorderColor = AgateLib.Geometry.Color.FromArgb((int)nudOpacity.Value, sample.Options.BorderColor); + private void btnBorderColor_Click(object sender, EventArgs e) + { + colorDialog.Color = btnBorderColor.BackColor; - if (chkBorder.Checked) - { - sample.CreateFont(); - } - } + if (colorDialog.ShowDialog() == DialogResult.OK) + { + btnBorderColor.BackColor = colorDialog.Color; - private AgateLib.Geometry.Color ConvertColor(System.Drawing.Color clr) - { - return AgateLib.Geometry.Color.FromArgb(clr.R, clr.G, clr.B); - } + sample.Options.BorderColor = ConvertColor(colorDialog.Color); + sample.Options.BorderColor = AgateLib.Geometry.Color.FromArgb((int)nudOpacity.Value, sample.Options.BorderColor); - private void chkTextRenderer_CheckedChanged(object sender, EventArgs e) - { - sample.Options.UseTextRenderer = chkTextRenderer.Checked; - sample.CreateFont(); - } + sample.Options.CreateBorder = true; - private void cboBg_SelectedIndexChanged(object sender, EventArgs e) - { - sample.LightBackground = cboBg.SelectedIndex == 1; - - } + chkBorder.Checked = true; - private void btnDisplayColor_Click(object sender, EventArgs e) - { - colorDialog.Color = btnDisplayColor.BackColor; + sample.CreateFont(); + } + } + private void nudOpacity_ValueChanged(object sender, EventArgs e) + { + sample.Options.BorderColor = AgateLib.Geometry.Color.FromArgb((int)nudOpacity.Value, sample.Options.BorderColor); - if (colorDialog.ShowDialog() == DialogResult.OK) - { - btnDisplayColor.BackColor = colorDialog.Color; + if (chkBorder.Checked) + { + sample.CreateFont(); + } + } - sample.DisplayColor = ConvertColor(colorDialog.Color); - } - } + private AgateLib.Geometry.Color ConvertColor(System.Drawing.Color clr) + { + return AgateLib.Geometry.Color.FromArgb(clr.R, clr.G, clr.B); + } - private void chkBorder_CheckedChanged(object sender, EventArgs e) - { - sample.Options.CreateBorder = chkBorder.Checked; + private void chkTextRenderer_CheckedChanged(object sender, EventArgs e) + { + sample.Options.UseTextRenderer = chkTextRenderer.Checked; + sample.CreateFont(); + } - sample.CreateFont(); - } + private void cboBg_SelectedIndexChanged(object sender, EventArgs e) + { + sample.LightBackground = cboBg.SelectedIndex == 1; - private void cboEdges_SelectedIndexChanged(object sender, EventArgs e) - { - sample.Options.EdgeOptions = (BitmapFontEdgeOptions)cboEdges.SelectedItem; + } - sample.CreateFont(); - } + private void btnDisplayColor_Click(object sender, EventArgs e) + { + colorDialog.Color = btnDisplayColor.BackColor; - private void btnViewFont_Click(object sender, EventArgs e) - { - string tempImage = Path.GetTempFileName() + ".png"; + if (colorDialog.ShowDialog() == DialogResult.OK) + { + btnDisplayColor.BackColor = colorDialog.Color; - ((BitmapFontImpl)sample.Font.Impl).Surface.SaveTo(tempImage); + sample.DisplayColor = ConvertColor(colorDialog.Color); + } + } - EditGlyphs frm = new EditGlyphs(); + private void chkBorder_CheckedChanged(object sender, EventArgs e) + { + sample.Options.CreateBorder = chkBorder.Checked; - //frm.ShowDialog(this, tempImage, ((BitmapFontImpl)sample.Font.Impl).FontMetrics); - frm.Dispose(); + sample.CreateFont(); + } - try - { - File.Delete(tempImage); - } - catch { } + private void cboEdges_SelectedIndexChanged(object sender, EventArgs e) + { + sample.Options.EdgeOptions = (BitmapFontEdgeOptions)cboEdges.SelectedItem; - } + sample.CreateFont(); + } - } + + + } } \ No newline at end of file Modified: trunk/Tools/FontCreator/EditGlyphs.Designer.cs =================================================================== --- trunk/Tools/FontCreator/EditGlyphs.Designer.cs 2009-04-19 02:14:32 UTC (rev 886) +++ trunk/Tools/FontCreator/EditGlyphs.Designer.cs 2009-04-19 18:08:08 UTC (rev 887) @@ -28,102 +28,102 @@ /// </summary> private void InitializeComponent() { - this.pctImage = new System.Windows.Forms.PictureBox(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.splitContainer2 = new System.Windows.Forms.SplitContainer(); - this.lstItems = new System.Windows.Forms.ListBox(); - this.properties = new System.Windows.Forms.PropertyGrid(); - ((System.ComponentModel.ISupportInitialize)(this.pctImage)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); - this.splitContainer2.Panel1.SuspendLayout(); - this.splitContainer2.Panel2.SuspendLayout(); - this.splitContainer2.SuspendLayout(); - this.SuspendLayout(); - // - // pctImage - // - this.pctImage.BackColor = System.Drawing.Color.White; - this.pctImage.Dock = System.Windows.Forms.DockStyle.Fill; - this.pctImage.Location = new System.Drawing.Point(0, 0); - this.pctImage.Name = "pctImage"; - this.pctImage.Size = new System.Drawing.Size(218, 271); - this.pctImage.TabIndex = 0; - this.pctImage.TabStop = false; - this.pctImage.Paint += new System.Windows.Forms.PaintEventHandler(this.pctImage_Paint); - // - // splitContainer1 - // - this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 0); - this.splitContainer1.Name = "splitContainer1"; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.pctImage); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); - this.splitContainer1.Size = new System.Drawing.Size(576, 271); - this.splitContainer1.SplitterDistance = 218; - this.splitContainer1.TabIndex = 2; - // - // splitContainer2 - // - this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer2.Location = new System.Drawing.Point(0, 0); - this.splitContainer2.Name = "splitContainer2"; - this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer2.Panel1 - // - this.splitContainer2.Panel1.Controls.Add(this.lstItems); - // - // splitContainer2.Panel2 - // - this.splitContainer2.Panel2.Controls.Add(this.properties); - this.splitContainer2.Size = new System.Drawing.Size(354, 271); - this.splitContainer2.SplitterDistance = 71; - this.splitContainer2.TabIndex = 0; - // - // lstItems - // - this.lstItems.ColumnWidth = 20; - this.lstItems.Dock = System.Windows.Forms.DockStyle.Fill; - this.lstItems.FormattingEnabled = true; - this.lstItems.HorizontalScrollbar = true; - this.lstItems.Location = new System.Drawing.Point(0, 0); - this.lstItems.MultiColumn = true; - this.lstItems.Name = "lstItems"; - this.lstItems.Size = new System.Drawing.Size(354, 69); - this.lstItems.TabIndex = 0; - this.lstItems.SelectedIndexChanged += new System.EventHandler(this.lstItems_SelectedIndexChanged); - // - // properties - // - this.properties.Dock = System.Windows.Forms.DockStyle.Fill; - this.properties.Location = new System.Drawing.Point(0, 0); - this.properties.Name = "properties"; - this.properties.Size = new System.Drawing.Size(354, 196); - this.properties.TabIndex = 1; - // - // EditGlyphs - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.splitContainer1); - this.Name = "EditGlyphs"; - this.Size = new System.Drawing.Size(576, 271); - ((System.ComponentModel.ISupportInitialize)(this.pctImage)).EndInit(); - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel2.ResumeLayout(false); - this.splitContainer1.ResumeLayout(false); - this.splitContainer2.Panel1.ResumeLayout(false); - this.splitContainer2.Panel2.ResumeLayout(false); - this.splitContainer2.ResumeLayout(false); - this.Re... [truncated message content] |
From: <ka...@us...> - 2009-04-19 02:14:35
|
Revision: 886 http://agate.svn.sourceforge.net/agate/?rev=886&view=rev Author: kanato Date: 2009-04-19 02:14:32 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Fix minor bugs in resetting state after creating font. Fix creating font if the font already exists in the resource. Format with tabs instead of spaces. Modified Paths: -------------- trunk/Tools/FontCreator/FontCreator.cs trunk/Tools/FontCreator/frmFontCreator.cs Modified: trunk/Tools/FontCreator/FontCreator.cs =================================================================== --- trunk/Tools/FontCreator/FontCreator.cs 2009-04-19 02:13:45 UTC (rev 885) +++ trunk/Tools/FontCreator/FontCreator.cs 2009-04-19 02:14:32 UTC (rev 886) @@ -12,318 +12,338 @@ namespace FontCreator { - public class FontBuilder - { - private string mText; - private object mRenderTarget; - private object mZoomRenderTarget; + public class FontBuilder + { + private string mText; + private object mRenderTarget; + private object mZoomRenderTarget; - DisplayWindow wind; - DisplayWindow zoomWind; - FontSurface font; - Surface bgDark, bgLight; + DisplayWindow wind; + DisplayWindow zoomWind; + FontSurface font; + Surface bgDark, bgLight; - BitmapFontOptions mOptions = new BitmapFontOptions(); + BitmapFontOptions mOptions = new BitmapFontOptions(); - public FontSurface Font - { - get { return font; } - } + public FontSurface Font + { + get { return font; } + } - private void SetStyle(FontStyle fontStyle, bool value) - { - if (value) - { - mOptions.FontStyle = mOptions.FontStyle | fontStyle; - } - else - { - mOptions.FontStyle = mOptions.FontStyle & ~fontStyle; - } + private void SetStyle(FontStyle fontStyle, bool value) + { + if (value) + { + mOptions.FontStyle = mOptions.FontStyle | fontStyle; + } + else + { + mOptions.FontStyle = mOptions.FontStyle & ~fontStyle; + } - CreateFont(); - } - private bool StyleContains(FontStyle fontStyle) - { - return (mOptions.FontStyle & fontStyle) == fontStyle; - } + CreateFont(); + } + private bool StyleContains(FontStyle fontStyle) + { + return (mOptions.FontStyle & fontStyle) == fontStyle; + } - public bool Underline - { - get { return StyleContains(FontStyle.Underline); } - set { SetStyle(FontStyle.Underline, value); } - } - public bool Strikeout - { - get { return StyleContains(FontStyle.Strikeout); } - set { SetStyle(FontStyle.Strikeout, value); } - } - public bool Italic - { - get { return StyleContains(FontStyle.Italic); } - set { SetStyle(FontStyle.Italic, value); } - } - public bool Bold - { - get { return StyleContains(FontStyle.Bold); } - set { SetStyle(FontStyle.Bold, value); } - } + public bool Underline + { + get { return StyleContains(FontStyle.Underline); } + set { SetStyle(FontStyle.Underline, value); } + } + public bool Strikeout + { + get { return StyleContains(FontStyle.Strikeout); } + set { SetStyle(FontStyle.Strikeout, value); } + } + public bool Italic + { + get { return StyleContains(FontStyle.Italic); } + set { SetStyle(FontStyle.Italic, value); } + } + public bool Bold + { + get { return StyleContains(FontStyle.Bold); } + set { SetStyle(FontStyle.Bold, value); } + } - public float FontSize - { - get { return mOptions.SizeInPoints; } - set - { - mOptions.SizeInPoints = value; - CreateFont(); - } - } + public float FontSize + { + get { return mOptions.SizeInPoints; } + set + { + mOptions.SizeInPoints = value; + CreateFont(); + } + } - public object RenderTarget - { - get { return mRenderTarget; } - } - public string FontFamily - { - get { return mOptions.FontFamily; } - set - { - mOptions.FontFamily = value; - CreateFont(); - } - } + public object RenderTarget + { + get { return mRenderTarget; } + } + public string FontFamily + { + get { return mOptions.FontFamily; } + set + { + mOptions.FontFamily = value; + CreateFont(); + } + } - private bool mDarkBackground; + private bool mDarkBackground; - private Color mColor; + private Color mColor; - public Color DisplayColor - { - get { return mColor; } - set { mColor = value; } - } - private double mDisplayScale = 4.0; + public Color DisplayColor + { + get { return mColor; } + set { mColor = value; } + } + private double mDisplayScale = 4.0; - public double DisplayScale - { - get { return mDisplayScale; } - set { mDisplayScale = value; } - } + public double DisplayScale + { + get { return mDisplayScale; } + set { mDisplayScale = value; } + } - public bool LightBackground - { - get { return mDarkBackground; } - set - { - mDarkBackground = value; - Draw(); - } - } + public bool LightBackground + { + get { return mDarkBackground; } + set + { + mDarkBackground = value; + Draw(); + } + } - public void SetRenderTarget(object render, object zoomRender) - { - mRenderTarget = render; - mZoomRenderTarget = zoomRender; + public void SetRenderTarget(object render, object zoomRender) + { + mRenderTarget = render; + mZoomRenderTarget = zoomRender; - if (wind != null) - { - wind.Dispose(); - zoomWind.Dispose(); - bgDark.Dispose(); - bgLight.Dispose(); - } + if (wind != null) + { + wind.Dispose(); + zoomWind.Dispose(); + bgDark.Dispose(); + bgLight.Dispose(); + } - zoomWind = DisplayWindow.CreateFromControl(zoomRender); - wind = DisplayWindow.CreateFromControl(render); - //wind = new DisplayWindow(render); - //zoomWind = new DisplayWindow(zoomRender); + zoomWind = DisplayWindow.CreateFromControl(zoomRender); + wind = DisplayWindow.CreateFromControl(render); + //wind = new DisplayWindow(render); + //zoomWind = new DisplayWindow(zoomRender); - bgDark = new Surface("bgdark.png"); - bgLight = new Surface("bglight.png"); + bgDark = new Surface("bgdark.png"); + bgLight = new Surface("bglight.png"); - DisplayColor = Color.White; - } + DisplayColor = Color.White; + } - public void CreateFont() - { - if (string.IsNullOrEmpty(FontFamily)) - return; - if (font != null) - font.Dispose(); + public void CreateFont() + { + if (string.IsNullOrEmpty(FontFamily)) + return; + if (font != null) + font.Dispose(); - font = new FontSurface(mOptions); + font = new FontSurface(mOptions); - Draw(); - } + Draw(); + } - FontStyle Style - { - get - { - return - (Bold ? FontStyle.Bold : 0) | - (Italic ? FontStyle.Italic : 0) | - (Underline ? FontStyle.Underline : 0) | - (Strikeout ? FontStyle.Strikeout : 0); - } - } - public BitmapFontOptions Options - { - get { return mOptions; } - } + FontStyle Style + { + get + { + return + (Bold ? FontStyle.Bold : 0) | + (Italic ? FontStyle.Italic : 0) | + (Underline ? FontStyle.Underline : 0) | + (Strikeout ? FontStyle.Strikeout : 0); + } + } + public BitmapFontOptions Options + { + get { return mOptions; } + } - public string Text - { - get { return mText; } - set - { - mText = value; - Draw(); - } - } + public string Text + { + get { return mText; } + set + { + mText = value; + Draw(); + } + } - public FontBuilder() - { - StringBuilder b = new StringBuilder(); + public FontBuilder() + { + StringBuilder b = new StringBuilder(); - b.AppendLine("Sample Text"); - b.AppendLine("abcdefghijklm ABCDEFGHIJKLM"); - b.AppendLine("nopqrstuvwxyz NOPQRSTUVWXYZ"); - b.AppendLine("01234567890"); - b.AppendLine("!@#$%^&*(),<.>/?;:'\"-_=+\\|"); + b.AppendLine("Sample Text"); + b.AppendLine("abcdefghijklm ABCDEFGHIJKLM"); + b.AppendLine("nopqrstuvwxyz NOPQRSTUVWXYZ"); + b.AppendLine("01234567890"); + b.AppendLine("!@#$%^&*(),<.>/?;:'\"-_=+\\|"); - mText = b.ToString(); + mText = b.ToString(); - mOptions.UseTextRenderer = true; - } + mOptions.UseTextRenderer = true; + } - public void Draw() - { - if (zoomWind == null) - return; + public void Draw() + { + if (zoomWind == null) + return; - Display.RenderTarget = zoomWind; - Display.BeginFrame(); - Display.Clear(); + Display.RenderTarget = zoomWind; + Display.BeginFrame(); + Display.Clear(); - font.SetScale(mDisplayScale, mDisplayScale); + font.SetScale(mDisplayScale, mDisplayScale); + ((BitmapFontImpl)font.Impl).InterpolationHint = InterpolationMode.Fastest; - DrawBackground(); - DrawText(); + DrawBackground(); + DrawText(); - Display.EndFrame(); + Display.EndFrame(); - Display.RenderTarget = wind; - Display.BeginFrame(); - Display.Clear(); + Display.RenderTarget = wind; + Display.BeginFrame(); + Display.Clear(); - font.SetScale(1.0, 1.0); + font.SetScale(1.0, 1.0); + ((BitmapFontImpl)font.Impl).InterpolationHint = InterpolationMode.Nicest; - DrawBackground(); - DrawText(); + DrawBackground(); + DrawText(); - Display.EndFrame(); + Display.EndFrame(); - Core.KeepAlive(); - } + Core.KeepAlive(); + } - private void DrawBackground() - { - Surface background = LightBackground ? bgLight : bgDark; + private void DrawBackground() + { + Surface background = LightBackground ? bgLight : bgDark; - for (int x = 0; x < Display.RenderTarget.Width; x += background.DisplayWidth) - { - for (int y = 0; y < Display.RenderTarget.Height; y += background.DisplayHeight) - { - background.Draw(x, y); - } - } - } + for (int x = 0; x < Display.RenderTarget.Width; x += background.DisplayWidth) + { + for (int y = 0; y < Display.RenderTarget.Height; y += background.DisplayHeight) + { + background.Draw(x, y); + } + } + } - private void DrawText() - { - if (font == null) - return; + private void DrawText() + { + if (font == null) + return; - font.Color = DisplayColor; - font.DrawText(Text); - } + font.Color = DisplayColor; + font.DrawText(Text); + } - internal void SaveFont(string resourceFile, string fontName, string imageFile) - { - AgateResourceCollection resources; + internal bool SaveFont(string resourceFile, string fontName, string imageFile) + { + AgateResourceCollection resources; - if (File.Exists(resourceFile)) - resources = AgateResourceLoader.LoadResources(resourceFile); - else - resources = new AgateResourceCollection(); + if (File.Exists(resourceFile)) + resources = AgateResourceLoader.LoadResources(resourceFile); + else + resources = new AgateResourceCollection(); - if (Path.IsPathRooted(resourceFile) == false) - { - resourceFile = Path.Combine(Directory.GetCurrentDirectory(), resourceFile); - } + if (Path.IsPathRooted(resourceFile) == false) + { + resourceFile = Path.Combine(Directory.GetCurrentDirectory(), resourceFile); + } - string localImagePath; - string dir = Path.GetDirectoryName(resourceFile); + string localImagePath; + string dir = Path.GetDirectoryName(resourceFile); - if (Path.IsPathRooted(imageFile) == false) - { - localImagePath = imageFile; - imageFile = Path.Combine(Path.GetDirectoryName(resourceFile), imageFile); - } - else - localImagePath = GetRelativePath(dir, imageFile); + if (Path.IsPathRooted(imageFile) == false) + { + localImagePath = imageFile; + imageFile = Path.Combine(Path.GetDirectoryName(resourceFile), imageFile); + } + else + localImagePath = GetRelativePath(dir, imageFile); - SaveImage(imageFile); + SaveImage(imageFile); - localImagePath = localImagePath.Replace(Path.DirectorySeparatorChar.ToString(), "/"); + localImagePath = localImagePath.Replace(Path.DirectorySeparatorChar.ToString(), "/"); - BitmapFontResource res = new BitmapFontResource(fontName); - res.Image = localImagePath; - res.FontMetrics = ((BitmapFontImpl)Font.Impl).FontMetrics.Clone(); + BitmapFontResource res = new BitmapFontResource(fontName); + res.Image = localImagePath; + res.FontMetrics = ((BitmapFontImpl)Font.Impl).FontMetrics.Clone(); - resources.Add(res); + if (resources.Contains(res.Name)) + { + if (System.Windows.Forms.MessageBox.Show( + "The specified resource file already contains a resource named \"" + + res.Name + "\"." + Environment.NewLine + + "Would you like to overwrite it?", res.Name + " already exists", + System.Windows.Forms.MessageBoxButtons.YesNo, + System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) + { + resources.Remove(res.Name); + } + else + { + return false; + } + } + resources.Add(res); - AgateResourceLoader.SaveResources(resources, resourceFile); - } + AgateResourceLoader.SaveResources(resources, resourceFile); - private void SaveImage(string imageFile) - { - EnsureDirectoryExists(Path.GetDirectoryName(imageFile)); + return true; + } - ((BitmapFontImpl)Font.Impl).Surface.SaveTo(imageFile); - } + private void SaveImage(string imageFile) + { + EnsureDirectoryExists(Path.GetDirectoryName(imageFile)); - private void EnsureDirectoryExists(string dirname) - { - if (Directory.Exists(dirname)) - return; + ((BitmapFontImpl)Font.Impl).Surface.SaveTo(imageFile); + } - string parentDir = Path.GetDirectoryName(dirname); + private void EnsureDirectoryExists(string dirname) + { + if (Directory.Exists(dirname)) + return; - if (Directory.Exists(parentDir) == false) - EnsureDirectoryExists(parentDir); + string parentDir = Path.GetDirectoryName(dirname); - Directory.CreateDirectory(dirname); - } + if (Directory.Exists(parentDir) == false) + EnsureDirectoryExists(parentDir); - private string GetRelativePath(string dir, string imageFile) - { - if (dir.EndsWith(Path.DirectorySeparatorChar.ToString()) == false) - dir += Path.DirectorySeparatorChar; + Directory.CreateDirectory(dirname); + } - for (int i = 0; i < dir.Length; i++) - { - if (imageFile.StartsWith(dir.Substring(0, i)) == false) - { - return imageFile.Substring(i - 1); - } - } + private string GetRelativePath(string dir, string imageFile) + { + if (dir.EndsWith(Path.DirectorySeparatorChar.ToString()) == false) + dir += Path.DirectorySeparatorChar; + for (int i = 0; i < dir.Length; i++) + { + if (imageFile.StartsWith(dir.Substring(0, i)) == false) + { + return imageFile.Substring(i - 1); + } + } - return imageFile.Substring(dir.Length); - } - } + + return imageFile.Substring(dir.Length); + } + } } \ No newline at end of file Modified: trunk/Tools/FontCreator/frmFontCreator.cs =================================================================== --- trunk/Tools/FontCreator/frmFontCreator.cs 2009-04-19 02:13:45 UTC (rev 885) +++ trunk/Tools/FontCreator/frmFontCreator.cs 2009-04-19 02:14:32 UTC (rev 886) @@ -10,132 +10,137 @@ namespace FontCreator { - public partial class frmFontCreator : Form - { - int mCurrentPage; + public partial class frmFontCreator : Form + { + int mCurrentPage; - public frmFontCreator() - { - InitializeComponent(); + public frmFontCreator() + { + InitializeComponent(); - Icon = AgateLib.WinForms.FormUtil.AgateLibIcon; - CurrentPage = 1; - } + Icon = AgateLib.WinForms.FormUtil.AgateLibIcon; + CurrentPage = 1; + } - AgateLib.DisplayLib.FontSurface AgateFont - { - get { return this.createFont1.FontBuilder.Font; } - } - int CurrentPage - { - get { return mCurrentPage; } - set - { - pnlCreateFont.Visible = false; - pnlEditGlyphs.Visible = false; - pnlSaveFont.Visible = false; + AgateLib.DisplayLib.FontSurface AgateFont + { + get { return this.createFont1.FontBuilder.Font; } + } + int CurrentPage + { + get { return mCurrentPage; } + set + { + pnlCreateFont.Visible = false; + pnlEditGlyphs.Visible = false; + pnlSaveFont.Visible = false; - Panel pnl = null; + Panel pnl = null; - switch (value) - { - case 1: - pnl = pnlCreateFont; - break; + switch (value) + { + case 1: + pnl = pnlCreateFont; + break; - case 2: - string tempImage = Path.GetTempFileName() + ".png"; + case 2: + string tempImage = Path.GetTempFileName() + ".png"; - ((BitmapFontImpl)AgateFont.Impl).Surface.SaveTo(tempImage); + ((BitmapFontImpl)AgateFont.Impl).Surface.SaveTo(tempImage); - editGlyphs1.SetFont(tempImage, ((BitmapFontImpl)AgateFont.Impl).FontMetrics); + editGlyphs1.SetFont(tempImage, ((BitmapFontImpl)AgateFont.Impl).FontMetrics); - pnl = pnlEditGlyphs; - break; + pnl = pnlEditGlyphs; + break; - case 3: - pnl = pnlSaveFont; - break; + case 3: + pnl = pnlSaveFont; + break; - default: - throw new InvalidOperationException("Wrong page number!"); - } + default: + throw new InvalidOperationException("Wrong page number!"); + } - pnl.Dock = DockStyle.Fill; - pnl.Visible = true; + pnl.Dock = DockStyle.Fill; + pnl.Visible = true; - mCurrentPage = value; - } - } + mCurrentPage = value; - public void SaveFont() - { - //sample.SaveFont(frm.ResourceFilename, frm.FontName, frm.ImageFilename); - createFont1.FontBuilder.SaveFont( - saveFont1.ResourceFilename, - saveFont1.FontName, - saveFont1.ImageFilename); - } - private void btnPrevious_Click(object sender, EventArgs e) - { - CurrentPage--; + if (CurrentPage == 1) + btnPrevious.Enabled = false; + else + btnPrevious.Enabled = true; - if (CurrentPage == 1) - btnPrevious.Enabled = false; + if (CurrentPage == 3) + { + btnNext.Enabled = saveFont1.ValidInput; + btnNext.Text = "Finish"; + } + else + { + btnNext.Enabled = true; + btnNext.Text = "Next >>"; + } + } + } - btnNext.Enabled = true; - btnNext.Text = "Next >>"; - } - private void btnNext_Click(object sender, EventArgs e) - { - if (CurrentPage == 3) - { - SaveFont(); + public bool SaveFont() + { + return createFont1.FontBuilder.SaveFont( + saveFont1.ResourceFilename, + saveFont1.FontName, + saveFont1.ImageFilename); + } - switch (MessageBox.Show(this, - "Successfully saved font. Create a new font?" + Environment.NewLine + - "Click yes to start over, no to quit.", "Font Complete", MessageBoxButtons.YesNoCancel, - MessageBoxIcon.Information, MessageBoxDefaultButton.Button2)) - { - case DialogResult.Yes: - CurrentPage = 1; - saveFont1.ResetControls(); - break; + private void btnPrevious_Click(object sender, EventArgs e) + { + CurrentPage--; - case DialogResult.No: - this.Close(); - break; - } + } + private void btnNext_Click(object sender, EventArgs e) + { + if (CurrentPage == 3) + { + if (SaveFont() == false) + return; - return; - } + switch (MessageBox.Show(this, + "Successfully saved font. Create a new font?" + Environment.NewLine + + "Click yes to start over, no to quit.", "Font Complete", MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Information, MessageBoxDefaultButton.Button2)) + { + case DialogResult.Yes: + CurrentPage = 1; + saveFont1.ResetControls(); + break; - CurrentPage++; + case DialogResult.No: + this.Close(); + break; + } - if (CurrentPage == 3) - { - btnNext.Enabled = saveFont1.ValidInput; - btnNext.Text = "Finish"; - } + return; + } - btnPrevious.Enabled = true; - } + CurrentPage++; - private void btnPrevious_MouseEnter(object sender, EventArgs e) - { - if (CurrentPage == 2) - pnlWarning.Visible = true; - } - private void btnPrevious_MouseLeave(object sender, EventArgs e) - { - pnlWarning.Visible = false; - } + } - private void saveFont1_ValidInputChanged(object sender, EventArgs e) - { - btnNext.Enabled = saveFont1.ValidInput; - btnNext.Text = "Finish"; - } - } + private void btnPrevious_MouseEnter(object sender, EventArgs e) + { + if (CurrentPage == 2) + pnlWarning.Visible = true; + } + private void btnPrevious_MouseLeave(object sender, EventArgs e) + { + pnlWarning.Visible = false; + } + + private void saveFont1_ValidInputChanged(object sender, EventArgs e) + { + btnNext.Enabled = saveFont1.ValidInput; + btnNext.Text = "Finish"; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 02:13:51
|
Revision: 885 http://agate.svn.sourceforge.net/agate/?rev=885&view=rev Author: kanato Date: 2009-04-19 02:13:45 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Skip glyphs which are reported to be zero width when creating bitmap font. Modified Paths: -------------- trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs Modified: trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs =================================================================== --- trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 02:13:06 UTC (rev 884) +++ trunk/Drivers/AgateLib.WinForms/BitmapFontUtil.cs 2009-04-19 02:13:45 UTC (rev 885) @@ -203,6 +203,11 @@ for (char i = range.StartChar; i <= range.EndChar; i++) { Size sourceSize = rend.MeasureText(g, i.ToString()); + + // skip glyphs which are not in the font. + if (sourceSize.Width == 0) + continue; + if (options.CreateBorder) { sourceSize.Width += 2; @@ -256,6 +261,9 @@ { for (char i = range.StartChar; i <= range.EndChar; i++) { + if (glyphs.ContainsKey(i) == false) + continue; + if (x + glyphs[i].Width > bitmapSize.Width) { x = rend.Padding; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 02:13:14
|
Revision: 884 http://agate.svn.sourceforge.net/agate/?rev=884&view=rev Author: kanato Date: 2009-04-19 02:13:06 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Include InterpolationHint on BitmapFontImpl. Skip glyphs which are reported to be zero width in BitmapFontOptions.cs. Modified Paths: -------------- trunk/AgateLib/BitmapFont/BitmapFontImpl.cs trunk/AgateLib/BitmapFont/BitmapFontOptions.cs Modified: trunk/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- trunk/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-19 02:12:09 UTC (rev 883) +++ trunk/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-19 02:13:06 UTC (rev 884) @@ -81,6 +81,15 @@ } /// <summary> + /// Gets or sets the interpolation hint for the underlying surface. + /// </summary> + public InterpolationMode InterpolationHint + { + get { return mSurface.InterpolationHint; } + set { mSurface.InterpolationHint = value; } + } + + /// <summary> /// Disposes of the object. /// </summary> public override void Dispose() Modified: trunk/AgateLib/BitmapFont/BitmapFontOptions.cs =================================================================== --- trunk/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-19 02:12:09 UTC (rev 883) +++ trunk/AgateLib/BitmapFont/BitmapFontOptions.cs 2009-04-19 02:13:06 UTC (rev 884) @@ -81,6 +81,10 @@ } } + public override string ToString() + { + return ((int)mStartChar).ToString() + " - " + ((int)mEndChar).ToString(); + } } private string mFamily; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 02:12:12
|
Revision: 883 http://agate.svn.sourceforge.net/agate/?rev=883&view=rev Author: kanato Date: 2009-04-19 02:12:09 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Include Prociono as built in font. Modified Paths: -------------- branches/gui-3.2/AgateLib/AgateApplication.cs branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs branches/gui-3.2/AgateLib/InternalResources/Data.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.resx branches/gui-3.2/AgateLib/Resources/AgateResourceCollection.cs Added Paths: ----------- branches/gui-3.2/AgateLib/InternalResources/Prociono.zip Modified: branches/gui-3.2/AgateLib/AgateApplication.cs =================================================================== --- branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-19 02:12:09 UTC (rev 883) @@ -79,7 +79,7 @@ CreateDisplayWindow(); - font = new FontSurface("Arial", 12.0f); + font = FontSurface.Prociono11; if (InitParams.ShowSplashScreen) { Modified: branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/DisplayLib/FontSurface.cs 2009-04-19 02:12:09 UTC (rev 883) @@ -105,7 +105,7 @@ if (res is BitmapFontResource) { - Surface surf = new Surface(bmpFont.Image); + Surface surf = new Surface(resources.FileProvider, bmpFont.Image); impl = new BitmapFontImpl(surf, bmpFont.FontMetrics); } @@ -325,5 +325,18 @@ { impl.DrawText(0, 0, mTransformer.Transform(text)); } + + #region --- Built-in Fonts --- + + public static FontSurface Prociono11 + { + get { return InternalResources.Data.Prociono11; } + } + public static FontSurface Prociono14 + { + get { return InternalResources.Data.Prociono14; } + } + + #endregion } } Modified: branches/gui-3.2/AgateLib/InternalResources/Data.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/InternalResources/Data.cs 2009-04-19 02:12:09 UTC (rev 883) @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using AgateLib.DisplayLib; +using AgateLib.Resources; using AgateLib.Utility; namespace AgateLib.InternalResources @@ -10,9 +11,17 @@ internal static class Data { static TgzFileProvider mProvider = new TgzFileProvider("images", DataResources.images); + static ZipFileProvider mProcionoProvider = new ZipFileProvider("Prociono", DataResources.Prociono); + static AgateResourceCollection mFontResources; static Surface mPoweredBy; + static FontSurface mProciono11, mProciono14; + private static void LoadFonts() + { + mFontResources = new AgateResourceCollection(mProcionoProvider); + } + internal static Surface PoweredBy { get @@ -25,5 +34,32 @@ return mPoweredBy; } } + + internal static FontSurface Prociono11 + { + get + { + LoadFonts(); + + if (mProciono11 == null) + mProciono11 = new FontSurface(mFontResources, "Prociono-11"); + + return mProciono11; + } + } + + internal static FontSurface Prociono14 + { + get + { + LoadFonts(); + + if (mProciono14 == null) + mProciono14 = new FontSurface(mFontResources, "Prociono-14"); + + return mProciono14; + } + } + } } Modified: branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs 2009-04-19 02:12:09 UTC (rev 883) @@ -73,5 +73,12 @@ return ((byte[])(obj)); } } + + internal static byte[] Prociono { + get { + object obj = ResourceManager.GetObject("Prociono", resourceCulture); + return ((byte[])(obj)); + } + } } } Modified: branches/gui-3.2/AgateLib/InternalResources/DataResources.resx =================================================================== --- branches/gui-3.2/AgateLib/InternalResources/DataResources.resx 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/InternalResources/DataResources.resx 2009-04-19 02:12:09 UTC (rev 883) @@ -124,4 +124,7 @@ <data name="images" type="System.Resources.ResXFileRef, System.Windows.Forms"> <value>images.tar.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </data> + <data name="Prociono" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>Prociono.zip;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </data> </root> \ No newline at end of file Added: branches/gui-3.2/AgateLib/InternalResources/Prociono.zip =================================================================== (Binary files differ) Property changes on: branches/gui-3.2/AgateLib/InternalResources/Prociono.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: branches/gui-3.2/AgateLib/Resources/AgateResourceCollection.cs =================================================================== --- branches/gui-3.2/AgateLib/Resources/AgateResourceCollection.cs 2009-04-19 02:11:26 UTC (rev 882) +++ branches/gui-3.2/AgateLib/Resources/AgateResourceCollection.cs 2009-04-19 02:12:09 UTC (rev 883) @@ -47,6 +47,13 @@ public AgateResourceCollection(string filename) : this(AgateFileProvider.Resources.GetProvider(filename), filename) { } + /// <summary> + /// Equivalent to calling new AgateResourceCollection(fileProvider, "Resources.xml"); + /// </summary> + /// <param name="fileProvider"></param> + public AgateResourceCollection(IFileProvider fileProvider) + : this(fileProvider, "Resources.xml") + { } public AgateResourceCollection(IFileProvider fileProvider, string filename) { FileProvider = fileProvider; @@ -55,6 +62,7 @@ Load(filename); } + private void Load(string filename) { using (Stream s = FileProvider.OpenRead(filename)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-19 02:11:42
|
Revision: 882 http://agate.svn.sourceforge.net/agate/?rev=882&view=rev Author: kanato Date: 2009-04-19 02:11:26 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Rename ControlFont to WidgetFont. Modified Paths: -------------- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-18 23:35:47 UTC (rev 881) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-19 02:11:26 UTC (rev 882) @@ -100,20 +100,20 @@ DrawStretchImage(location, size, image, Scheme.TextBoxStretchRegion); - Scheme.ControlFont.DisplayAlignment = OriginAlignment.TopLeft; + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.TopLeft; SetControlFontColor(textBox); location.X += Scheme.TextBoxStretchRegion.X; location.Y += Scheme.TextBoxStretchRegion.Y; - Scheme.ControlFont.DrawText( + Scheme.WidgetFont.DrawText( location, textBox.Text); if (textBox.HasFocus) { - size = Scheme.ControlFont.StringDisplaySize( + size = Scheme.WidgetFont.StringDisplaySize( textBox.Text.Substring(0, textBox.InsertionPoint)); Point loc = new Point( @@ -123,7 +123,7 @@ loc = textBox.PointToScreen(loc); loc.Y++; - DrawInsertionPoint(textBox, loc, Scheme.ControlFont.FontHeight - 2, + DrawInsertionPoint(textBox, loc, Scheme.WidgetFont.FontHeight - 2, Timing.TotalMilliseconds - textBox.IPTime); } } @@ -138,7 +138,7 @@ Display.DrawLine(location, new Point(location.X, location.Y + size), - Scheme.ControlFont.Color); + Scheme.WidgetFont.Color); } private Size CalcMinTextBoxSize(TextBox textBox) @@ -146,7 +146,7 @@ Size retval = new Size(); retval.Width = 40; - retval.Height = Scheme.ControlFont.FontHeight; + retval.Height = Scheme.WidgetFont.FontHeight; retval.Height += Scheme.TextBox.SurfaceHeight - Scheme.TextBoxStretchRegion.Height; return retval; @@ -192,13 +192,13 @@ destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; - Scheme.ControlFont.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.ControlFont.DrawText(destPoint, checkbox.Text); + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); } private Size CalcMinCheckBoxSize(CheckBox checkbox) { - Size text = Scheme.ControlFont.StringDisplaySize(checkbox.Text); + Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); Size box = Scheme.CheckBox.SurfaceSize; return new Size( @@ -212,7 +212,7 @@ Point local = checkBox.PointToClient(screenLocation); int right = Scheme.CheckBox.SurfaceWidth + - Scheme.ControlFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + Scheme.WidgetFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; if (local.X > right) return false; @@ -246,13 +246,13 @@ destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; - Scheme.ControlFont.DisplayAlignment = OriginAlignment.CenterLeft; - Scheme.ControlFont.DrawText(destPoint, checkbox.Text); + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.WidgetFont.DrawText(destPoint, checkbox.Text); } private Size CalcMinRadioButtonSize(RadioButton checkbox) { - Size text = Scheme.ControlFont.StringDisplaySize(checkbox.Text); + Size text = Scheme.WidgetFont.StringDisplaySize(checkbox.Text); Size box = Scheme.CheckBox.SurfaceSize; return new Size( @@ -266,7 +266,7 @@ Point local = checkBox.PointToClient(screenLocation); int right = Scheme.CheckBox.SurfaceWidth + - Scheme.ControlFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + Scheme.WidgetFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; if (local.X > right) return false; @@ -288,13 +288,13 @@ SetControlFontColor(label); - Scheme.ControlFont.DisplayAlignment = label.TextAlignment; - Scheme.ControlFont.DrawText(location, label.Text); + Scheme.WidgetFont.DisplayAlignment = label.TextAlignment; + Scheme.WidgetFont.DrawText(location, label.Text); } private Size CalcMinLabelSize(Label label) { - Size retval = Scheme.ControlFont.StringDisplaySize(label.Text); + Size retval = Scheme.WidgetFont.StringDisplaySize(label.Text); return retval; } @@ -329,7 +329,7 @@ // Draw button text SetControlFontColor(button); - Scheme.ControlFont.DisplayAlignment = OriginAlignment.Center; + Scheme.WidgetFont.DisplayAlignment = OriginAlignment.Center; location = Origin.Calc(OriginAlignment.Center, button.Size); // drop the text down a bit if the button is being pushed. @@ -339,14 +339,14 @@ location.Y++; } - Scheme.ControlFont.DrawText( + Scheme.WidgetFont.DrawText( button.PointToScreen(location), button.Text); } private Size CalcMinButtonSize(Button button) { - Size textSize = Scheme.ControlFont.StringDisplaySize(button.Text); + Size textSize = Scheme.WidgetFont.StringDisplaySize(button.Text); Size buttonBorder = new Size( Scheme.Button.SurfaceWidth - Scheme.ButtonStretchRegion.Width, Scheme.Button.SurfaceHeight - Scheme.ButtonStretchRegion.Height); @@ -540,9 +540,9 @@ private void SetControlFontColor(Widget widget) { if (widget.Enabled) - Scheme.ControlFont.Color = Scheme.FontColor; + Scheme.WidgetFont.Color = Scheme.FontColor; else - Scheme.ControlFont.Color = Scheme.FontColorDisabled; + Scheme.WidgetFont.Color = Scheme.FontColorDisabled; } } Modified: branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-18 23:35:47 UTC (rev 881) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs 2009-04-19 02:11:26 UTC (rev 882) @@ -26,7 +26,7 @@ void SetDefaults(IFileProvider files) { - ControlFont = new FontSurface("Sans Serif", 8); + WidgetFont = new FontSurface("Prociono", 8); TitleFont = new FontSurface("Sans Serif", 10); CenterTitle = true; @@ -150,7 +150,7 @@ mInsertionPointBlinkTime = value; } } - public FontSurface ControlFont { get; set; } + public FontSurface WidgetFont { get; set; } public FontSurface TitleFont { get; set; } public bool CenterTitle { get; set; } public int DropShadowSize { get; set; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 23:35:58
|
Revision: 881 http://agate.svn.sourceforge.net/agate/?rev=881&view=rev Author: kanato Date: 2009-04-18 23:35:47 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Add Gui files. Modified Paths: -------------- branches/gui-3.2/AgateLib/AgateApplication.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.Designer.cs branches/gui-3.2/AgateLib/InternalResources/DataResources.resx Added Paths: ----------- branches/gui-3.2/AgateLib/Gui/ branches/gui-3.2/AgateLib/Gui/AgateGuiException.cs branches/gui-3.2/AgateLib/Gui/Button.cs branches/gui-3.2/AgateLib/Gui/CheckBox.cs branches/gui-3.2/AgateLib/Gui/Container.cs branches/gui-3.2/AgateLib/Gui/GuiRoot.cs branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs branches/gui-3.2/AgateLib/Gui/ILayoutPerformer.cs branches/gui-3.2/AgateLib/Gui/Label.cs branches/gui-3.2/AgateLib/Gui/Layout/ branches/gui-3.2/AgateLib/Gui/Layout/BoxLayoutBase.cs branches/gui-3.2/AgateLib/Gui/Layout/Grid.cs branches/gui-3.2/AgateLib/Gui/Layout/HorizontalBox.cs branches/gui-3.2/AgateLib/Gui/Layout/VerticalBox.cs branches/gui-3.2/AgateLib/Gui/LayoutExpand.cs branches/gui-3.2/AgateLib/Gui/Panel.cs branches/gui-3.2/AgateLib/Gui/RadioButton.cs branches/gui-3.2/AgateLib/Gui/TextBox.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs branches/gui-3.2/AgateLib/Gui/ThemeEngines/MercuryScheme.cs branches/gui-3.2/AgateLib/Gui/Widget.cs branches/gui-3.2/AgateLib/Gui/WidgetList.cs branches/gui-3.2/AgateLib/Gui/Window.cs branches/gui-3.2/AgateLib/InternalResources/agate-black-gui.zip branches/gui-3.2/Tests/GuiTests/ branches/gui-3.2/Tests/GuiTests/RenderGui.cs Modified: branches/gui-3.2/AgateLib/AgateApplication.cs =================================================================== --- branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-18 22:52:35 UTC (rev 880) +++ branches/gui-3.2/AgateLib/AgateApplication.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -45,6 +45,7 @@ DisplayWindow mWindow; AppInitParameters mInitParams; FontSurface font; + Gui.GuiRoot mGui; double totalSplashTime = 0; bool splashFadeDone = false; @@ -91,11 +92,17 @@ { Update(Display.DeltaTime); + if (GuiRoot != null) + GuiRoot.DoUpdate(); + Display.RenderTarget = mWindow; Display.BeginFrame(); Render(); + if (GuiRoot != null) + GuiRoot.Draw(); + Display.EndFrame(); Core.KeepAlive(); } @@ -292,6 +299,24 @@ get { return mWindow; } } + public Gui.GuiRoot GuiRoot + { + get { return mGui; } + set + { + if (value == null && mGui == null) + return; + + if (mGui != null) + mGui.EnableInteraction = false; + + mGui = value; + + if (mGui != null) + mGui.EnableInteraction = true; + } + } + #endregion /// <summary> Added: branches/gui-3.2/AgateLib/Gui/AgateGuiException.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/AgateGuiException.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/AgateGuiException.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; + +namespace AgateLib.Gui +{ + [global::System.Serializable] + public class AgateGuiException : AgateException + { + // + // For guidelines regarding the creation of new exception types, see + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp + // and + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp + // + + public AgateGuiException() { } + public AgateGuiException(string message) : base(message) { } + public AgateGuiException(string message, Exception inner) : base(message, inner) { } + protected AgateGuiException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) + : base(info, context) { } + } + +} Added: branches/gui-3.2/AgateLib/Gui/Button.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Button.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Button.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.InputLib; + +namespace AgateLib.Gui +{ + public class Button : Widget + { + public Button() { Name = "Button"; } + public Button(string text) { Name = text; Text = text; } + + bool mouseDownIn = false; + + public override bool CanHaveFocus + { + get + { + return true; + } + } + internal bool DrawActivated + { + get { return mouseDownIn && MouseIn; } + } + internal bool IsDefaultButton + { + get + { + Container p = this.Parent; + + while (p is Window == false) + p = p.Parent; + + return ((Window)p).AcceptButton == this; + } + } + + protected internal override void OnMouseDown(InputEventArgs e) + { + if (Enabled == false) + return; + + mouseDownIn = true; + } + protected internal override void OnMouseUp(InputEventArgs e) + { + mouseDownIn = false; + + if (MouseIn) + OnClick(); + } + + private void OnClick() + { + if (Click != null) + Click(this, EventArgs.Empty); + } + public event EventHandler Click; + } +} Added: branches/gui-3.2/AgateLib/Gui/CheckBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/CheckBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/CheckBox.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class CheckBox : Widget + { + public CheckBox() + { + Name = "Checkbox"; + } + public CheckBox(string text) + { + Name = text; + Text = text; + } + private bool mChecked; + + public bool Checked + { + get { return mChecked; } + set + { + mChecked = value; + + OnCheckChanged(); + } + } + + + bool mouseDownIn; + protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) + { + if (Enabled == false) + return; + + mouseDownIn = true; + } + protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) + { + if (MouseIn && mouseDownIn) + Checked = !Checked; + + mouseDownIn = false; + + } + + + private void OnCheckChanged() + { + if (CheckChanged != null) + CheckChanged(this, EventArgs.Empty); + } + + public event EventHandler CheckChanged; + } +} Added: branches/gui-3.2/AgateLib/Gui/Container.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Container.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Container.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,258 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; +using AgateLib.InputLib; +using System.Diagnostics; + +namespace AgateLib.Gui +{ + public abstract class Container : Widget + { + WidgetList mChildren; + Rectangle mClientArea; + ILayoutPerformer mLayout = new Layout.VerticalBox(); + bool mLayoutSuspended; + + public Container() + { + mChildren = new WidgetList(this); + mChildren.ListUpdated += new EventHandler(mChildren_ListUpdated); + } + + internal bool AnyChildCanHaveFocus + { + get + { + for (int i = 0; i < mChildren.Count; i++) + { + if (mChildren[i].CanHaveFocus) + return true; + + if (mChildren[i] is Container) + { + if (((Container)mChildren[i]).AnyChildCanHaveFocus) + return true; + } + } + + return false; + } + } + public Rectangle ClientArea { get { return mClientArea; } } + public Size ClientSize + { + get { return mClientArea.Size; } + set + { + Size = Root.ThemeEngine.RequestClientAreaSize(this, value); + } + } + public virtual ILayoutPerformer Layout + { + get { return mLayout; } + set + { + mLayout = value; + RedoLayout(); + } + } + + public override Point PointToScreen(Point p) + { + return base.PointToScreen( + new Point(p.X + ClientArea.X, p.Y + ClientArea.Y)); + } + public override Point PointToClient(Point p) + { + Point retval = base.PointToClient(p); + + retval.X -= ClientArea.X; + retval.Y -= ClientArea.Y; + + return retval; + } + protected override void OnResize() + { + if (Root == null) + return; + + mClientArea = Root.ThemeEngine.GetClientArea(this); + DoLayoutPrivate(); + + base.OnResize(); + } + protected override void OnParentChanged() + { + if (Parent == null) + return; + + OnResize(); + base.OnParentChanged(); + } + + public void SuspendLayout() + { + mLayoutSuspended = true; + + foreach (Container child in mChildren) + { + child.SuspendLayout(); + } + } + public void ResumeLayout() + { + mLayoutSuspended = false; + + RedoLayout(); + + foreach (Widget child in mChildren) + { + if (child is Container == false) + continue; + + ((Container)child).ResumeLayout(); + } + + } + protected internal override void RecalcSizeRange() + { + if (mLayoutSuspended) + return; + if (Root == null) + return; + + try + { + InLayout = true; + + MinSize = Layout.RecalcMinSize(this); + } + finally + { + InLayout = false; + } + } + + void mChildren_ListUpdated(object sender, EventArgs e) + { + DoLayoutPrivate(); + } + + public WidgetList Children + { + get { return mChildren; } + } + + protected internal override void UpdateGui() + { + for (int i = 0; i < Children.Count; i++) + Children[i].UpdateGui(); + + base.UpdateGui(); + } + + void DoLayoutPrivate() + { + RedoLayout(); + Invalidate(); + } + + internal bool InLayout { get; private set; } + + public virtual void RedoLayout() + { + if (mLayoutSuspended) + return; + if (Root == null) + return; + if (InLayout) + return; + + try + { + InLayout = true; + + RecalcSizeRange(); + Layout.DoLayout(this); + } + finally + { + InLayout = false; + } + } + protected override void DoDraw() + { + base.DoDraw(); + + foreach (var child in Children.VisibleItems) + child.Draw(); + } + + protected internal override bool AcceptFocusOnMouseDown + { + get { return false; } + } + + protected internal override bool AcceptInputKey(KeyCode keyCode) + { + return Layout.AcceptInputKey(keyCode); + } + + //Widget FindMouseInControl(Point screenMousePoint) + //{ + // foreach (Widget child in mChildren) + // { + // if (child.ContainsScreenPoint(screenMousePoint) == true) + // return child; + // } + + // return null; + //} + + + internal Widget NearestChildTo(Point pt, bool skipDisabled) + { + int distance = int.MaxValue; + Widget retval = null; + + foreach (Widget child in Children) + { + if (child.Enabled == false && skipDisabled) + continue; + + Point center = new Point( + child.Location.X + child.Width / 2, + child.Location.Y + child.Height / 2); + + int dist = Math.Abs(center.X - pt.X) + Math.Abs(center.Y - pt.Y); + + if (dist < distance) + { + retval = child; + distance = dist; + } + } + + return retval; + } + + internal Widget CanMoveFocus(Widget currentFocus, Direction direction) + { + if (this.Children.Contains(currentFocus) == false) + throw new ArgumentException("currentFocus does not belong to this container."); + + return Layout.CanMoveFocus(this, currentFocus, direction); + } + } + + public enum Direction + { + Up, + Down, + Left, + Right, + } + +} \ No newline at end of file Added: branches/gui-3.2/AgateLib/Gui/GuiRoot.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/GuiRoot.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/GuiRoot.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,514 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.Geometry; +using AgateLib.DisplayLib; +using AgateLib.InputLib; + +namespace AgateLib.Gui +{ + public sealed class GuiRoot : Container + { + IGuiThemeEngine themeEngine = new ThemeEngines.Mercury(); + + public GuiRoot() + { + Name = "root"; + Layout = new Layout.Grid(); + } + public GuiRoot(IGuiThemeEngine themeEngine) + { + this.themeEngine = themeEngine; + } + protected internal override void UpdateGui() + { + this.Size = Display.RenderTarget.Size; + + base.UpdateGui(); + } + protected internal override void RecalcSizeRange() + { + } + public IGuiThemeEngine ThemeEngine + { + get { return themeEngine; } + set + { + if (value == null) + throw new ArgumentNullException("RenderEngine must not be null."); + + themeEngine = value; + } + } + public override ILayoutPerformer Layout + { + get + { + return base.Layout; + } + set + { + if (value is Layout.Grid == false) + throw new ArgumentException("Root Gui object cannot have any other layout than Grid!"); + + base.Layout = value; + } + } + + public void DoUpdate() + { + OnUpdate(); + UpdateGui(); + } + bool isRunning = false; + + public void Run() + { + if (isRunning) + return; + + try + { + isRunning = true; + + EnableInteraction = true; + + while (Display.CurrentWindow.IsClosed == false) + { + OnUpdate(); + + Display.BeginFrame(); + + OnDrawBehindGui(); + Draw(); + + Display.EndFrame(); + Core.KeepAlive(); + } + } + finally + { + isRunning = false; + + EnableInteraction = false; + } + } + + bool mInteractionEnabled = false; + public bool EnableInteraction + { + get { return mInteractionEnabled; } + set + { + if (value == mInteractionEnabled) + return; + + if (value) + AttachEvents(); + else + DetachEvents(); + + mInteractionEnabled = value; + } + } + private void DetachEvents() + { + Mouse.MouseDown -= new InputEventHandler(Mouse_MouseDown); + Mouse.MouseMove -= new InputEventHandler(Mouse_MouseMove); + Mouse.MouseUp -= new InputEventHandler(Mouse_MouseUp); + Mouse.MouseDoubleClick -= new InputEventHandler(Mouse_MouseDoubleClickEvent); + Keyboard.KeyDown -= new InputEventHandler(Keyboard_KeyDown); + Keyboard.KeyUp -= new InputEventHandler(Keyboard_KeyUp); + } + private void AttachEvents() + { + Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown); + Mouse.MouseMove += new InputEventHandler(Mouse_MouseMove); + Mouse.MouseUp += new InputEventHandler(Mouse_MouseUp); + Mouse.MouseDoubleClick += new InputEventHandler(Mouse_MouseDoubleClickEvent); + Keyboard.KeyDown += new InputEventHandler(Keyboard_KeyDown); + Keyboard.KeyUp += new InputEventHandler(Keyboard_KeyUp); + } + + void Keyboard_KeyUp(InputEventArgs e) + { + SendKeyUp(e); + } + void Keyboard_KeyDown(InputEventArgs e) + { + SendKeyDown(e); + } + + void Mouse_MouseDoubleClickEvent(InputEventArgs e) + { + SendMouseDoubleClick(e); + } + void Mouse_MouseUp(InputEventArgs e) + { + SendMouseUp(e); + } + void Mouse_MouseMove(InputEventArgs e) + { + SendMouseMove(e); + } + void Mouse_MouseDown(InputEventArgs e) + { + SendMouseDown(e); + } + + private void OnDrawBehindGui() + { + if (DrawBehindGui != null) + DrawBehindGui(this, EventArgs.Empty); + } + private void OnUpdate() + { + if (Update != null) + Update(this, EventArgs.Empty); + + UpdateGui(); + + } + + public event EventHandler DrawBehindGui; + public event EventHandler Update; + + + #region --- Directing Mouse Input to Child Controls --- + + Widget directMouseInput; + Widget lastMouseIn; + + // TODO: Clean these methods up a bit. + protected internal override void SendMouseDown(InputEventArgs e) + { + Widget child = FindWidgetWithMouse(e.MousePosition); + if (child == null) + { + directMouseInput = this; + OnMouseDown(e); + } + else + { + Debug.Print("Sending mouse down to {0}", child); + if (child.AcceptFocusOnMouseDown) + { + FocusControl = child; + } + + directMouseInput = child; + directMouseInput.SendMouseDown(e); + } + } + + protected internal override void SendMouseUp(InputEventArgs e) + { + if (directMouseInput == null || directMouseInput == this) + OnMouseUp(e); + else + { + Debug.Print("Sending mouse up to {0}", directMouseInput); + directMouseInput.SendMouseUp(e); + } + + directMouseInput = null; + } + protected internal override void SendMouseMove(InputEventArgs e) + { + Widget child = FindWidgetWithMouse(e.MousePosition); + + // TODO: This should send MouseEnter/MouseLeave events + // to the parents of child and lastMouseIn, if the mouse + // has entered or left them. + if (child != lastMouseIn) + { + if (lastMouseIn != null) + lastMouseIn.SendMouseLeave(); + + if (child != null) + child.SendMouseEnter(); + } + + lastMouseIn = child; + + if (directMouseInput == this) + OnMouseMove(e); + else if (directMouseInput != null) + directMouseInput.SendMouseMove(e); + else if (child != null) + child.SendMouseMove(e); + else + OnMouseMove(e); + } + protected internal override void SendMouseDoubleClick(InputEventArgs e) + { + Widget child = FindWidgetWithMouse(e.MousePosition); + if (child == null) + { + OnMouseDoubleClick(e); + return; + } + + child.OnMouseDoubleClick(e); + } + + Widget FindWidgetWithMouse(Point screenMousePoint) + { + Container parent = this; + Widget retval = null; + Widget current = null; + + while ((current = FindContainerChildWithMouse(parent, screenMousePoint)) != null) + { + retval = current; + + if (current is Container) + { + parent = (Container)current; + } + else + break; + } + + if (retval != null) + return retval; + else if (parent == this) + return null; + else + return parent; + + } + + Widget FindContainerChildWithMouse(Container parent, Point screenMousePoint) + { + foreach (Widget child in parent.Children) + { + if (child.ContainsScreenPoint(screenMousePoint) == false) + continue; + if (child.HitTest(screenMousePoint) == false) + continue; + + return child; + } + + return null; + } + + #endregion + #region --- Directing Keyboard Input to Child Controls --- + + Widget focusControl; + + public Widget FocusControl + { + get { return focusControl; } + set + { + if (value.Enabled == false) + return; + + if (value.AcceptFocusOnMouseDown == false) + return; + + if (focusControl != null) + focusControl.OnLoseFocus(); + + focusControl = value; + + if (focusControl != null) + focusControl.OnGainFocus(); + } + } + + protected internal override void SendKeyDown(InputEventArgs e) + { + if (IsControlKey(e.KeyCode)) + { + if (focusControl != null) + { + Widget widget = focusControl; + + if (WidgetAcceptControlKey(ref widget, e)) + { + widget.SendKeyDown(e); + return; + } + } + + ProcessControlKey(e); + return; + } + + + if (focusControl != null) + { + focusControl.SendKeyDown(e); + } + } + + protected internal override void SendKeyUp(InputEventArgs e) + { + if (focusControl == null) + return; + + if (IsControlKey(e.KeyCode)) + { + if (focusControl != null) + { + Widget widget = focusControl; + + if (WidgetAcceptControlKey(ref widget, e)) + { + widget.SendKeyUp(e); + return; + } + } + } + + if (focusControl != null) + { + if (CheckControlKey(focusControl, e)) + return; + focusControl.SendKeyUp(e); + } + } + + + private bool WidgetAcceptControlKey(ref Widget widget, InputEventArgs e) + { + return widget.AcceptInputKey(e.KeyCode); + + //while (widget.AcceptInputKey(e.KeyCode) == false) + //{ + // widget = widget.Parent; + + // if (widget == this) + // return false; + //} + + //return true; + } + + + private void ProcessControlKey(InputEventArgs e) + { + switch (e.KeyCode) + { + case KeyCode.Up: + MoveFocus(Direction.Up); + break; + + case KeyCode.Down: + MoveFocus(Direction.Down); + break; + + case KeyCode.Left: + MoveFocus(Direction.Left); + break; + + case KeyCode.Right: + MoveFocus(Direction.Right); + break; + } + } + + private void MoveFocus(Direction direction) + { + if (focusControl == null) + { + // TODO: set focus to a control. + return; + } + + if (focusControl.Parent == this) + return; + + Widget newFocus = focusControl.Parent.CanMoveFocus(focusControl, direction); + + if (newFocus != null) + { + SetFocusControl(newFocus, direction, WidgetPoint(focusControl)); + return; + } + + + // Ok, parent can't move focus in that direction. we need to go up another level. + Container current = focusControl.Parent; + + while (current != this) + { + newFocus = current.Parent.CanMoveFocus(current, direction); + if (newFocus != null) + break; + + current = current.Parent; + } + + if (newFocus == null) + return; + + SetFocusControl(newFocus, direction, WidgetPoint(focusControl)); + + } + + private Point WidgetPoint(Widget focusControl) + { + return new Point( + focusControl.Location.X + focusControl.Width / 2, + focusControl.Location.Y + focusControl.Height / 2); + } + + private bool CheckControlKey(Widget widget, InputEventArgs e) + { + if (focusControl == null) + return false; + + switch (e.KeyCode) + { + case KeyCode.Up: + case KeyCode.Left: + case KeyCode.Down: + case KeyCode.Right: + case KeyCode.Tab: + return widget.AcceptInputKey(e.KeyCode); + } + + return false; + } + + bool IsControlKey(KeyCode key) + { + switch (key) + { + case KeyCode.Up: + case KeyCode.Left: + case KeyCode.Down: + case KeyCode.Right: + case KeyCode.Tab: + return true; + } + + return false; + } + + #endregion + + + internal void SetFocusControl(Widget newFocus, Direction direction, Point nearPoint) + { + if (newFocus.CanHaveFocus) + { + FocusControl = newFocus; + return; + } + + if (newFocus is Container) + { + SetFocusControl(((Container)newFocus).NearestChildTo(nearPoint, true), direction, nearPoint); + } + } + } +} Added: branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/IGuiThemeEngine.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui +{ + public interface IGuiThemeEngine + { + /// <summary> + /// Draws the specified widget to the screen. + /// </summary> + /// <param name="widget"></param> + void DrawWidget(Widget widget); + + /// <summary> + /// Calculates and returns the minimum size for the widget. + /// </summary> + /// <param name="widget"></param> + /// <returns></returns> + Size CalcMinSize(Widget widget); + + /// <summary> + /// Calculates and returns the maximum size for the widget. + /// </summary> + /// <param name="widget"></param> + /// <returns></returns> + Size CalcMaxSize(Widget widget); + + /// <summary> + /// Gets the minimum margin area around the widget required by the theme. + /// </summary> + /// <param name="widget"></param> + /// <returns></returns> + int ThemeMargin(Widget widget); + + /// <summary> + /// Returns the area for the client space in + /// the widget, given its size. + /// </summary> + /// <param name="widget"></param> + /// <returns></returns> + Rectangle GetClientArea(Container widget); + /// <summary> + /// Returns the size the container widget should be to + /// have the specified client area. + /// </summary> + /// <param name="widget"></param> + /// <param name="clientSize"></param> + /// <returns></returns> + Size RequestClientAreaSize(Container widget, Size clientSize); + + /// <summary> + /// Returns true if the point specified in inside the area of the widget where a mouse + /// click would count as hitting the control. + /// </summary> + /// <param name="widget"></param> + /// <param name="screenLocation"></param> + /// <returns></returns> + bool HitTest(Widget widget, Point screenLocation); + } +} Added: branches/gui-3.2/AgateLib/Gui/ILayoutPerformer.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ILayoutPerformer.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ILayoutPerformer.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui +{ + public interface ILayoutPerformer + { + void DoLayout(Container container); + + Size RecalcMinSize(Container container); + + bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode); + + Widget CanMoveFocus(Container container, Widget currentFocus, Direction direction); + } +} Added: branches/gui-3.2/AgateLib/Gui/Label.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Label.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Label.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class Label : Widget + { + public Label() { Name = "Label"; } + public Label(string text) + { + Name = text; + Text = text; + + TextAlignment = AgateLib.DisplayLib.OriginAlignment.CenterLeft; + } + + public DisplayLib.OriginAlignment TextAlignment { get; set; } + } +} Added: branches/gui-3.2/AgateLib/Gui/Layout/BoxLayoutBase.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Layout/BoxLayoutBase.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Layout/BoxLayoutBase.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,326 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui.Layout +{ + public abstract class BoxLayoutBase : ILayoutPerformer + { + bool doingLayout = false; + List<int> sizes = new List<int>(); + Container container; + + + + public Size RecalcMinSize(Container container) + { + this.container = container; + return RecalcMinSizeInternal(); + } + + protected Size RecalcMinSizeBox(bool horizontal) + { + _horizontal = horizontal; + + Size minSize = new Size(); + int totalSize = 0; + + foreach (Widget child in container.Children) + { + child.RecalcSizeRange(); + + minSize.Width = Math.Max(minSize.Width, child.MinSize.Width + child.ThemeMargin * 2); + minSize.Height = Math.Max(minSize.Height, child.MinSize.Height + child.ThemeMargin * 2); + + totalSize += GetMinSize(child) + child.ThemeMargin * 2; + } + + return SetSize(minSize, totalSize); + } + + public void DoLayout(Container container) + { + if (doingLayout) + return; + + this.container = container; + + try + { + doingLayout = true; + + DoLayoutInternal(); + } + finally + { + doingLayout = false; + } + } + + protected abstract void DoLayoutInternal(); + protected abstract Size RecalcMinSizeInternal(); + + bool _horizontal; + protected void DoBoxLayout(bool horizontal) + { + _horizontal = horizontal; + + int containerSize = GetContainerSize(); + int totalMinSize = 0; + int expandCount = 0; + int shrinkCount = 0; + sizes.Clear(); + + foreach (Widget child in container.Children.VisibleItems) + { + int minSize = GetMinSize(child) + child.ThemeMargin * 2; + + switch (child.LayoutExpand) + { + case LayoutExpand.Default: + totalMinSize += minSize; + break; + + case LayoutExpand.ExpandToMax: + expandCount++; + break; + + case LayoutExpand.ShrinkToMin: + totalMinSize += minSize; + shrinkCount++; + break; + } + } + + int extraSpace = containerSize - totalMinSize; + if (extraSpace < 0) + extraSpace = 0; + + if (expandCount == 0) + { + if (shrinkCount < container.Children.VisibleItems.Count() + && extraSpace > 0) + { + int expandSize = extraSpace / + (container.Children.VisibleItems.Count() - shrinkCount); + + ShareSpace(expandSize); + } + else + ShareSpaceEqually(extraSpace); + + } + else + { + int expandSize = extraSpace / expandCount; + + SetMinSizes(expandSize); + } + } + + private void SetMinSizes(int expandSize) + { + int loc = 0; + + foreach (Widget child in container.Children.VisibleItems) + { + int size; + loc += child.ThemeMargin; + + switch (child.LayoutExpand) + { + case LayoutExpand.Default: + case LayoutExpand.ShrinkToMin: + size = GetMinSize(child); + break; + + case LayoutExpand.ExpandToMax: + size = expandSize; + break; + + default: + throw new NotImplementedException(); + } + + if (loc + size > GetSize(container.Size)) + throw new AgateGuiException("Container size is not right."); + + SetLocation(child, loc); + SetSize(child, size); + + loc += size + child.ThemeMargin; + } + } + + private void ShareSpace(int extraSpace) + { + int loc = 0; + int containerSize = GetContainerSize(); + + int totalExtraSpace = 0; + int nonMaxedControls = 0; + foreach (Widget child in container.Children.VisibleItems) + { + int size = GetMinSize(child); + int maxSize = GetMaxSize(child); + + if (size + extraSpace > maxSize) + { + totalExtraSpace += size + extraSpace - maxSize; + } + else + nonMaxedControls++; + } + + foreach (Widget child in container.Children.VisibleItems) + { + loc += child.ThemeMargin; + + int size = GetMinSize(child); + int maxSize = GetMaxSize(child); + + if (child.LayoutExpand != LayoutExpand.ShrinkToMin) + size += extraSpace; + + if (size > maxSize) + size = maxSize; + else if (nonMaxedControls > 0 && totalExtraSpace > 0) + { + size += totalExtraSpace / nonMaxedControls; + } + + SetLocation(child, loc); + SetSize(child, size); + + loc += size + child.ThemeMargin; + } + + } + private void ShareSpaceEqually(int extraSpace) + { + if (extraSpace < 0) + throw new ArgumentOutOfRangeException("extraSpace must be positive."); + + int loc = 0; + int containerSize = GetContainerSize(); + int expandSize = extraSpace / container.Children.VisibleItems.Count(); + + foreach (Widget child in container.Children.VisibleItems) + { + int minSize = GetMinSize(child); + int size; + loc += child.ThemeMargin; + + if (child.LayoutExpand == LayoutExpand.ShrinkToMin) + size = minSize; + else + size = minSize + expandSize; + + SetLocation(child, loc); + SetSize(child, size); + + loc += size + child.ThemeMargin; + } + + } + int GetSize(Size size) + { + if (_horizontal) + return size.Width; + else + return size.Height; + } + int GetMinSize(Widget widget) + { + return GetSize(widget.MinSize); + } + int GetMaxSize(Widget widget) + { + return GetSize(widget.MaxSize); + } + + private Size SetSize(Size size, int value) + { + if (_horizontal) + return new Size(value, size.Height); + else + return new Size(size.Width, value); + } + void SetSize(Widget widget, int value) + { + if (_horizontal) + widget.Size = new Size(value, container.ClientArea.Height - widget.ThemeMargin * 2); + else + widget.Size = new Size(container.ClientArea.Width - widget.ThemeMargin * 2, value); + } + void SetLocation(Widget widget, int value) + { + if (_horizontal) + widget.Location = new Point(value, widget.ThemeMargin); + else + widget.Location = new Point(widget.ThemeMargin, value); + } + + int GetContainerSize() + { + if (_horizontal) + return container.ClientArea.Width; + else + return container.ClientArea.Height; + } + + public virtual bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) + { + return false; + + } + + + protected GuiRoot Root(Widget widget) + { + if (widget is GuiRoot) + return (GuiRoot)widget; + else + return Root(widget.Parent); + } + protected int GetParentIndex(Container container, Widget widget) + { + if (widget is GuiRoot) + throw new AgateGuiException("Specified widget is not a child of the container."); + + if (widget.Parent == container) + return container.Children.IndexOf(widget); + else + return GetParentIndex(container, widget.Parent); + } + + + public abstract Widget CanMoveFocus(Container container, Widget currentFocus, Direction direction); + + + protected Widget GetNextChild(Container container, int index, int direction) + { + for (index += direction; index >= 0 && index < container.Children.Count; index += direction) + { + Widget child = container.Children[index]; + + if (child is Container) + { + if (((Container)child).AnyChildCanHaveFocus) + return child; + } + if (child.CanHaveFocus == false) + continue; + if (child.Enabled == false) + continue; + + return child; + } + + return null; + } + + } +} Added: branches/gui-3.2/AgateLib/Gui/Layout/Grid.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Layout/Grid.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Layout/Grid.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui.Layout +{ + public class Grid : ILayoutPerformer + { + + public bool DoingLayout + { + get { return false; } + } + + public void DoLayout(Container container) + { + return; + } + + + public Size RecalcMinSize(Container container) + { + return container.Size; + } + + + public bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) + { + return false; + } + + + public Widget CanMoveFocus(Container container, Widget currentFocus, Direction direction) + { + return null; + } + + } +} Added: branches/gui-3.2/AgateLib/Gui/Layout/HorizontalBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Layout/HorizontalBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Layout/HorizontalBox.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui.Layout +{ + public class HorizontalBox : BoxLayoutBase + { + protected override void DoLayoutInternal() + { + DoBoxLayout(true); + } + + protected override Size RecalcMinSizeInternal() + { + return RecalcMinSizeBox(true); + } + + public override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) + { + switch (keyCode) + { + case AgateLib.InputLib.KeyCode.Right: + case AgateLib.InputLib.KeyCode.Left: + return true; + + default: + return false; + } + } + + public override Widget CanMoveFocus(Container container, Widget currentFocus, Direction direction) + { + if (direction == Direction.Up || direction == Direction.Down) + return null; + + GuiRoot root = Root(container); + int index = GetParentIndex(container, currentFocus); + + + switch (direction) + { + case Direction.Left: + return GetNextChild(container, index, -1); + + case Direction.Right: + return GetNextChild(container, index, 1); + } + + throw new InvalidOperationException(); + } + + + } +} \ No newline at end of file Added: branches/gui-3.2/AgateLib/Gui/Layout/VerticalBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Layout/VerticalBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Layout/VerticalBox.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; + +namespace AgateLib.Gui.Layout +{ + public class VerticalBox : BoxLayoutBase + { + protected override void DoLayoutInternal() + { + DoBoxLayout(false); + } + + protected override Size RecalcMinSizeInternal() + { + return RecalcMinSizeBox(false); + } + + public override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) + { + switch (keyCode) + { + case AgateLib.InputLib.KeyCode.Up: + case AgateLib.InputLib.KeyCode.Down: + return true; + + default: + return false; + } + } + + public override Widget CanMoveFocus(Container container, Widget currentFocus, Direction direction) + { + if (direction == Direction.Right || direction == Direction.Left) + return null; + + GuiRoot root = Root(container); + int index = GetParentIndex(container, root.FocusControl); + + switch (direction) + { + case Direction.Up: + return GetNextChild(container, index, -1); + + case Direction.Down: + return GetNextChild(container, index, 1); + + } + + throw new InvalidOperationException(); + } + } +} \ No newline at end of file Added: branches/gui-3.2/AgateLib/Gui/LayoutExpand.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/LayoutExpand.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/LayoutExpand.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public enum LayoutExpand + { + Default, + ExpandToMax, + ShrinkToMin, + } +} Added: branches/gui-3.2/AgateLib/Gui/Panel.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/Panel.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/Panel.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class Panel : Container + { + } +} Added: branches/gui-3.2/AgateLib/Gui/RadioButton.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/RadioButton.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/RadioButton.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class RadioButton : Widget + { + public RadioButton() + { + Name = "RadioButton"; + } + public RadioButton(string text) + { + Name = text; + Text = text; + } + private bool mChecked; + + public bool Checked + { + get { return mChecked; } + set + { + if (value == mChecked) + return; + + mChecked = value; + + if (value == true && Parent != null) + { + foreach (Widget w in Parent.Children) + { + RadioButton rad = w as RadioButton; + + if (rad == null || rad == this) + continue; + + rad.Checked = false; + } + } + + OnCheckChanged(); + } + } + + + bool mouseDownIn; + protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) + { + if (Enabled == false) + return; + + mouseDownIn = true; + } + protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) + { + if (MouseIn && mouseDownIn) + Checked = !Checked; + + mouseDownIn = false; + } + + private void OnCheckChanged() + { + if (CheckChanged != null) + CheckChanged(this, EventArgs.Empty); + } + + public event EventHandler CheckChanged; + } +} Added: branches/gui-3.2/AgateLib/Gui/TextBox.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/TextBox.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/TextBox.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class TextBox : Widget + { + int mInsertionPoint; + + public override bool CanHaveFocus + { + get { return true; } + } + public int InsertionPoint + { + get { return mInsertionPoint; } + set + { + if (value < 0) value = 0; + if (value > Text.Length) value = Text.Length; + + mInsertionPoint = value; + } + } + protected internal override void SendKeyDown(AgateLib.InputLib.InputEventArgs e) + { + ResetIPBlinking(); + + switch (e.KeyCode) + { + case AgateLib.InputLib.KeyCode.Left: + InsertionPoint--; + break; + + case AgateLib.InputLib.KeyCode.Right: + InsertionPoint++; + break; + + case AgateLib.InputLib.KeyCode.Home: + InsertionPoint = 0; + break; + + case AgateLib.InputLib.KeyCode.End: + InsertionPoint = Text.Length; + break; + + case AgateLib.InputLib.KeyCode.BackSpace: + if (InsertionPoint == 0) + break; + + if (InsertionPoint == Text.Length) + { + InsertionPoint--; + Text = Text.Substring(0, Text.Length - 1); + } + else + { + InsertionPoint--; + Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); + } + + break; + + case AgateLib.InputLib.KeyCode.Delete: + if (InsertionPoint == Text.Length) + break; + else if (InsertionPoint == 0) + Text = Text.Substring(1); + else + Text = Text.Substring(0, InsertionPoint) + Text.Substring(InsertionPoint + 1); + + break; + + default: + if (InsertionPoint == Text.Length) + Text += e.KeyString; + else if (InsertionPoint == 0) + Text = e.KeyString + Text; + else + Text = Text.Substring(0, InsertionPoint) + e.KeyString + Text.Substring(InsertionPoint); + + InsertionPoint++; + + break; + } + } + + protected internal override bool AcceptInputKey(AgateLib.InputLib.KeyCode keyCode) + { + switch (keyCode) + { + case AgateLib.InputLib.KeyCode.Left: + case AgateLib.InputLib.KeyCode.Right: + return true; + default: + return false; + } + } + public override string Text + { + get + { + return base.Text; + } + set + { + base.Text = value; + + if (InsertionPoint > Text.Length) + InsertionPoint = Text.Length; + + ResetIPBlinking(); + } + } + + private void ResetIPBlinking() + { + IPTime = Timing.TotalMilliseconds; + } + //public bool MultiLine { get; set; } + + internal double IPTime { get; set; } + + } +} Added: branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs =================================================================== --- branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs (rev 0) +++ branches/gui-3.2/AgateLib/Gui/ThemeEngines/Mercury.cs 2009-04-18 23:35:47 UTC (rev 881) @@ -0,0 +1,549 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using System.Diagnostics; + +namespace AgateLib.Gui.ThemeEngines +{ + public class Mercury : IGuiThemeEngine + { + public Mercury() + : this(MercuryScheme.CreateDefaultScheme()) + { } + public Mercury(MercuryScheme scheme) + { + this.Scheme = scheme; + } + + public MercuryScheme Scheme { get; set; } + public static bool DebugOutlines { get; set; } + + #region --- Interface Dispatchers --- + + public void DrawWidget(Widget widget) + { + if (widget is GuiRoot) + return; + + if (DebugOutlines) + { + Display.DrawRect(new Rectangle(widget.ScreenLocation, widget.Size), + Color.Red); + } + + if (widget is Window) DrawWindow((Window)widget); + if (widget is Label) DrawLabel((Label)widget); + if (widget is Button) DrawButton((Button)widget); + if (widget is CheckBox) DrawCheckbox((CheckBox)widget); + if (widget is RadioButton) DrawRadioButton((RadioButton)widget); + if (widget is TextBox) DrawTextBox((TextBox)widget); + } + + + public Size RequestClientAreaSize(Container widget, Size clientSize) + { + throw new NotImplementedException(); + } + public Size CalcMinSize(Widget widget) + { + if (widget is Label) return CalcMinLabelSize((Label)widget); + if (widget is Button) return CalcMinButtonSize((Button)widget); + if (widget is CheckBox) return CalcMinCheckBoxSize((CheckBox)widget); + if (widget is TextBox) return CalcMinTextBoxSize((TextBox)widget); + if (widget is RadioButton) return CalcMinRadioButtonSize((RadioButton)widget); + + return Size.Empty; + } + public Size CalcMaxSize(Widget widget) + { + if (widget is TextBox) return CalcTextBoxMaxSize((TextBox)widget); + + return new Size(9000, 9000); + } + public bool HitTest(Widget widget, Point screenLocation) + { + if (widget is Button) return HitTestButton((Button)widget, screenLocation); + if (widget is CheckBox) return HitTestCheckBox((CheckBox)widget, screenLocation); + if (widget is TextBox) return HitTestTextBox((TextBox)widget, screenLocation); + + return true; + } + + public int ThemeMargin(Widget widget) + { + if (widget is Button) return Scheme.ButtonMargin; + if (widget is CheckBox) return Scheme.CheckBoxMargin; + if (widget is TextBox) return Scheme.TextBoxMargin; + + return 0; + } + + #endregion + + #region --- TextBox --- + + private void DrawTextBox(TextBox textBox) + { + Surface image = Scheme.TextBox; + + if (textBox.Enabled == false) + image = Scheme.TextBoxDisabled; + else if (textBox.MouseIn) + image = Scheme.TextBoxHover; + + Point location = textBox.PointToScreen(new Point(0, 0)); + Size size = textBox.Size; + + DrawStretchImage(location, size, + image, Scheme.TextBoxStretchRegion); + + Scheme.ControlFont.DisplayAlignment = OriginAlignment.TopLeft; + + SetControlFontColor(textBox); + + location.X += Scheme.TextBoxStretchRegion.X; + location.Y += Scheme.TextBoxStretchRegion.Y; + + Scheme.ControlFont.DrawText( + location, + textBox.Text); + + if (textBox.HasFocus) + { + size = Scheme.ControlFont.StringDisplaySize( + textBox.Text.Substring(0, textBox.InsertionPoint)); + + Point loc = new Point( + size.Width + Scheme.TextBoxStretchRegion.X, + Scheme.TextBoxStretchRegion.Y); + + loc = textBox.PointToScreen(loc); + loc.Y++; + + DrawInsertionPoint(textBox, loc, Scheme.ControlFont.FontHeight - 2, + Timing.TotalMilliseconds - textBox.IPTime); + } + } + + private void DrawInsertionPoint(Widget widget, Point location, int size, double time) + { + int val = (int)time / Scheme.InsertionPointBlinkTime; + //Debug.Print("{0} {1}", time, val); + + if (val % 2 == 1) + return; + + Display.DrawLine(location, + new Point(location.X, location.Y + size), + Scheme.ControlFont.Color); + } + + private Size CalcMinTextBoxSize(TextBox textBox) + { + Size retval = new Size(); + + retval.Width = 40; + retval.Height = Scheme.ControlFont.FontHeight; + retval.Height += Scheme.TextBox.SurfaceHeight - Scheme.TextBoxStretchRegion.Height; + + return retval; + } + private Size CalcTextBoxMaxSize(TextBox textBox) + { + Size retval = CalcMinTextBoxSize(textBox); + + retval.Width = 9000; + + return retval; + } + + private bool HitTestTextBox(TextBox textBox, Point screenLocation) + { + Point local = textBox.PointToClient(screenLocation); + + return true; + } + + #endregion + #region --- CheckBox --- + + private void DrawCheckbox(CheckBox checkbox) + { + Surface surf; + + if (checkbox.Enabled == false && checkbox.Checked) surf = Scheme.CheckBoxCheckedDisabled; + else if (checkbox.Enabled == false) surf = Scheme.CheckBoxDisabled; + else if (checkbox.Checked && checkbox.MouseIn) surf = Scheme.CheckBoxCheckedHover; + else if (checkbox.Checked) surf = Scheme.CheckBoxChecked; + else if (checkbox.MouseIn) surf = Scheme.CheckBoxHover; + else + surf = Scheme.CheckBox; + + Point destPoint = checkbox.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); + + surf.DisplayAlignment = OriginAlignment.CenterLeft; + surf.Draw(destPoint); + + SetControlFontColor(checkbox); + + destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; + + Scheme.ControlFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.ControlFont.DrawText(destPoint, checkbox.Text); + } + + private Size CalcMinCheckBoxSize(CheckBox checkbox) + { + Size text = Scheme.ControlFont.StringDisplaySize(checkbox.Text); + Size box = Scheme.CheckBox.SurfaceSize; + + return new Size( + box.Width + Scheme.CheckBoxSpacing + text.Width, + Math.Max(box.Height, text.Height)); + } + + + private bool HitTestCheckBox(CheckBox checkBox, Point screenLocation) + { + Point local = checkBox.PointToClient(screenLocation); + + int right = Scheme.CheckBox.SurfaceWidth + + Scheme.ControlFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + + if (local.X > right) + return false; + + return true; + } + + + #endregion + #region --- CheckBox --- + + private void DrawRadioButton(RadioButton checkbox) + { + Surface surf; + + if (checkbox.Enabled == false && checkbox.Checked) surf = Scheme.CheckBoxCheckedDisabled; + else if (checkbox.Enabled == false) surf = Scheme.CheckBoxDisabled; + else if (checkbox.Checked && checkbox.MouseIn) surf = Scheme.CheckBoxCheckedHover; + else if (checkbox.Checked) surf = Scheme.CheckBoxChecked; + else if (checkbox.MouseIn) surf = Scheme.CheckBoxHover; + else + surf = Scheme.CheckBox; + + Point destPoint = checkbox.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); + + surf.DisplayAlignment = OriginAlignment.CenterLeft; + surf.Draw(destPoint); + + SetControlFontColor(checkbox); + + destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; + + Scheme.ControlFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.ControlFont.DrawText(destPoint, checkbox.Text); + } + + private Size CalcMinRadioButtonSize(RadioButton checkbox) + { + Size text = Scheme.ControlFont.StringDisplaySize(checkbox.Text); + Size box = Scheme.CheckBox.SurfaceSize; + + return new Size( + box.Width + Scheme.CheckBoxSpacing + text.Width, + Math.Max(box.Height, text.Height)); + } + + + private bool HitTestRadioButton(RadioButton checkBox, Point screenLocation) + { + Point local = checkBox.PointToClient(screenLocation); + + int right = Scheme.CheckBox.SurfaceWidth + + Scheme.ControlFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + + if (local.X > right) + return false; + + return true; + } + + + #endregion + #region --- Label --- + + private void DrawLabel(Label label) + { + Point location = new Point(); + + location = DisplayLib.Origin.Calc(label.TextAlignment, label.Size); + location.X += label.ScreenLocation.X; + location.Y += label.ScreenLocation.Y; + + SetControlFontColor(label); + + Scheme.ControlFont.DisplayAlignment = label.TextAlignment; + Scheme.ControlFont.DrawText(location, label.Text); + } + + private Size CalcMinLabelSize(Label label) + { + Size retval = Scheme.ControlFont.StringDisplaySize(label.Text); + + return retval; + } + + #endregion + #region --- Button --- + + private void DrawButton(Button button) + { + Surface image = Scheme.Button; + bool isDefault = button.IsDefaultButton; + + if (button.Enabled == false) + image = Scheme.ButtonDisabled; + else if (button.DrawActivated) + image = Scheme.ButtonPressed; + else if (isDefault && button.MouseIn) + image = Scheme.ButtonDefaultHover; + else if (isDefault) + image = Scheme.ButtonDefault; + else if (button.MouseIn) + image = Scheme.ButtonHover; + else if (button.HasFocus) + image = Scheme.ButtonHover; + + Point location = button.PointToScreen(Point.Empty); + Size size = new Size(button.Width, button.Height); + + DrawStretchImage(location, size, + image, Scheme.ButtonStretchRegion); + + // Draw button text + SetControlFontColor(button); + + Scheme.ControlFont.DisplayAlignment = OriginAlignment.Center; + location = Origin.Calc(OriginAlignment.Center, button.Size); + + // drop the text down a bit if the button is being pushed. + if (button.DrawActivated) + { + location.X++; + location.Y++; + } + + Scheme.ControlFont.DrawText( + button.PointToScreen(location), + button.Text); + } + + private Size CalcMinButtonSize(Button button) + { + Size textSize = Scheme.ControlFont.StringDisplaySize(button.Text); + Size buttonBorder = new Size( + Scheme.Button.SurfaceWidth - Scheme.ButtonStretchRegion.Width, + Scheme.Button.SurfaceHeight - Scheme.ButtonStretchRegion.Height); + + textSize.Width += Scheme.ButtonTextPadding * 2; + textSize.Height += Scheme.ButtonTextPadding * 2; + + return new Size( + textSize.Width + buttonBorder.Width, + textSize.Height + buttonBorder.Height); + } + + private bool HitTestButton(Button button, Point screenLocation) + { + Point local = button.PointToClient(screenLocation); + + return true; + } + + #endregion + #region --- Window --- + + public void DrawWindow(Window window) + { + DrawWindowBackground(window); + DrawWindowTitle(window); + DrawWindowDecorations(window); + } + + // TODO: fix this + public int WindowTitlebarSize + { + get { return Scheme.TitleFont.FontHeight + 6; } + } + + protected virtual void DrawWindowBackground(Window window) + { + if (window.ShowTitleBar) + { + DrawStretchImage(window.Parent.PointToScreen( + new Point(window.Location.X, window.Location.Y + this.WindowTitlebarSize)), + window.Size, Scheme.WindowWithTitle, Scheme.WindowWithTitleStretchRegion); + + } + else + throw new NotImplementedException(); + } + + private void DrawDropShadow(Rectangle rect) + { + for (int i = 0; i <= Scheme.DropShadowSize; i++) + { + Color fadeColor = Color.Red;// Scheme.WindowBorderColor; + fadeColor.A = (byte)( + fadeColor.A * (Scheme.DropShadowSize - i) / (2 * Scheme.DropShadowSize)); + + Display.DrawRect(rect, fadeColor); + + rect.X--; + rect.Y--; + rect.Width += 2; + rect.Height += 2; + } + } + protected virtual void DrawWindowTitle(Window window) + { + Point windowLocation = window.ScreenLocation; + + DrawStretchImage(windowLocation, + new Size(window.Width, WindowTitlebarSize), Scheme.WindowTitleBar, + Scheme.WindowTitleBarStretchRegion); + + Point fontPosition = new Point(windowLocation.X + 8, windowLocation.Y + 3); + if (Scheme.CenterTitle) + { + fontPosition.X = windowLocation.X + window.Width / 2; + fontPosition.Y = windowLocation.Y + WindowTitlebarSize / 2; + Scheme.TitleFont.DisplayAlignment = OriginAlignment.Center; + } + + Scheme.TitleFont.Color = Scheme.FontColor; + + Scheme.TitleFont.DrawText( + fontPosition, + window.Text); + + Scheme.TitleFont.DisplayAlignment = OriginAlignment.TopLeft; + } + protected virtual void DrawWindowDecorations(Window window) + { + Scheme.CloseButton.DisplayAlignment = OriginAlignment.TopRight; + Scheme.CloseButton.Draw( + new Point(window.ScreenLocation.X + window.Size.Width, + window.ScreenLocation.Y)); + } + + #endregion + + + //private bool PointInMargin(Widget widget, Point localPoint, int margin) + //{ + // if (localPoint.X < margin) return true; + // if (localPoint.Y < margin) return true; + // if (localPoint.X >= widget.Width - margin) return true; + // if (localPoint.Y >= widget.Height - margin) return true; + + // return false; + //} + + + private void DrawStretchImage(Point loc, Size size, + Surface surface, Rectangle stretchRegion) + { + Rectangle scaled = new Rectangle( + loc.X + stretchRegion.X, + loc.Y + stretchRegion.Y, + size.Width - (surface.SurfaceWidth - stretchRegion.Right) - stretchRegion.X, + size.Height - (surface.SurfaceHeight - stretchRegion.Bottom) - stretchRegion.Y); + + // draw top left + surface.Draw( + new Rectangle(0, 0, stretchRegion.Left, stretchRegion.Top), + new Rectangle(loc.X, loc.Y, stretchRegion.Left, stretchRegion.Top)); + + // draw top middle + surface.Draw( + new Rectangle(stretchRegion.Left, 0, stretchRegion.Width, stretchRegion.Top), + new Rectangle(loc.X + stretchRegion.Left, loc.Y, + scaled.Width, str... [truncated message content] |
From: <ka...@us...> - 2009-04-18 22:52:51
|
Revision: 880 http://agate.svn.sourceforge.net/agate/?rev=880&view=rev Author: kanato Date: 2009-04-18 22:52:35 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Start branch for GUI based on 0.3.2 code base. Added Paths: ----------- branches/gui-3.2/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:50:25
|
Revision: 879 http://agate.svn.sourceforge.net/agate/?rev=879&view=rev Author: kanato Date: 2009-04-18 22:50:21 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Correct null reference exception if radio button was set checked but parent property is null. Modified Paths: -------------- branches/gui/Gui/RadioButton.cs Modified: branches/gui/Gui/RadioButton.cs =================================================================== --- branches/gui/Gui/RadioButton.cs 2009-04-18 22:48:45 UTC (rev 878) +++ branches/gui/Gui/RadioButton.cs 2009-04-18 22:50:21 UTC (rev 879) @@ -28,7 +28,7 @@ mChecked = value; - if (value == true) + if (value == true && Parent != null) { foreach (Widget w in Parent.Children) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:48:50
|
Revision: 878 http://agate.svn.sourceforge.net/agate/?rev=878&view=rev Author: kanato Date: 2009-04-18 22:48:45 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Remove gui-3.1 branch which didn't have any of the right stuff in it. Removed Paths: ------------- branches/gui-3.1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:47:15
|
Revision: 877 http://agate.svn.sourceforge.net/agate/?rev=877&view=rev Author: kanato Date: 2009-04-18 22:47:10 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Add radio button control. Modified Paths: -------------- branches/gui/Gui/CheckBox.cs branches/gui/Gui/Tester/RenderGui.cs branches/gui/Gui/ThemeEngines/Graphite.cs Added Paths: ----------- branches/gui/Gui/RadioButton.cs Modified: branches/gui/Gui/CheckBox.cs =================================================================== --- branches/gui/Gui/CheckBox.cs 2009-04-18 22:31:41 UTC (rev 876) +++ branches/gui/Gui/CheckBox.cs 2009-04-18 22:47:10 UTC (rev 877) @@ -5,55 +5,55 @@ namespace AgateLib.Gui { - public class CheckBox : Widget - { - public CheckBox() - { - Name = "Checkbox"; - } - public CheckBox(string text) - { - Name = text; - Text = text; - } - private bool mChecked; + public class CheckBox : Widget + { + public CheckBox() + { + Name = "Checkbox"; + } + public CheckBox(string text) + { + Name = text; + Text = text; + } + private bool mChecked; - public bool Checked - { - get { return mChecked; } - set - { - mChecked = value; + public bool Checked + { + get { return mChecked; } + set + { + mChecked = value; - OnCheckChanged(); - } - } + OnCheckChanged(); + } + } - bool mouseDownIn; - protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) - { - if (Enabled == false) - return; + bool mouseDownIn; + protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) + { + if (Enabled == false) + return; - mouseDownIn = true; - } - protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) - { - if (MouseIn && mouseDownIn) - Checked = !Checked; + mouseDownIn = true; + } + protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) + { + if (MouseIn && mouseDownIn) + Checked = !Checked; - mouseDownIn = false; + mouseDownIn = false; - } + } - private void OnCheckChanged() - { - if (CheckChanged != null) - CheckChanged(this, EventArgs.Empty); - } + private void OnCheckChanged() + { + if (CheckChanged != null) + CheckChanged(this, EventArgs.Empty); + } - public event EventHandler CheckChanged; - } + public event EventHandler CheckChanged; + } } Copied: branches/gui/Gui/RadioButton.cs (from rev 762, branches/gui/Gui/CheckBox.cs) =================================================================== --- branches/gui/Gui/RadioButton.cs (rev 0) +++ branches/gui/Gui/RadioButton.cs 2009-04-18 22:47:10 UTC (rev 877) @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.Gui +{ + public class RadioButton : Widget + { + public RadioButton() + { + Name = "RadioButton"; + } + public RadioButton(string text) + { + Name = text; + Text = text; + } + private bool mChecked; + + public bool Checked + { + get { return mChecked; } + set + { + if (value == mChecked) + return; + + mChecked = value; + + if (value == true) + { + foreach (Widget w in Parent.Children) + { + RadioButton rad = w as RadioButton; + + if (rad == null || rad == this) + continue; + + rad.Checked = false; + } + } + + OnCheckChanged(); + } + } + + + bool mouseDownIn; + protected internal override void OnMouseDown(AgateLib.InputLib.InputEventArgs e) + { + if (Enabled == false) + return; + + mouseDownIn = true; + } + protected internal override void OnMouseUp(AgateLib.InputLib.InputEventArgs e) + { + if (MouseIn && mouseDownIn) + Checked = !Checked; + + mouseDownIn = false; + } + + private void OnCheckChanged() + { + if (CheckChanged != null) + CheckChanged(this, EventArgs.Empty); + } + + public event EventHandler CheckChanged; + } +} Modified: branches/gui/Gui/Tester/RenderGui.cs =================================================================== --- branches/gui/Gui/Tester/RenderGui.cs 2009-04-18 22:31:41 UTC (rev 876) +++ branches/gui/Gui/Tester/RenderGui.cs 2009-04-18 22:47:10 UTC (rev 877) @@ -55,7 +55,7 @@ for (int i = 0; i < 4; i++) { - rightPanel.Children.Add(new Button("right " + i.ToString())); + rightPanel.Children.Add(new RadioButton("Radio " + i.ToString())); if (i % 2 == 1) leftPanel.Children.Add(new Button("Button Left " + i.ToString())); @@ -63,7 +63,7 @@ rightPanel.Children[i].Enabled = false; } - hideMouse = rightPanel.Children[0] as Button; + hideMouse = leftPanel.Children[0] as Button; hideMouse.Text = "Hide Mouse Pointer"; hideMouse.Click += new EventHandler(hideMouse_Click); hideMouse.Enabled = true; @@ -76,9 +76,9 @@ vsync_CheckChanged(this, EventArgs.Empty); rightPanel.Children.Add(vsync); - rightPanel.Children.Add(new CheckBox("Test box 2")); - rightPanel.Children.Add(new CheckBox { Text = "Disabled", Enabled = false }); - rightPanel.Children.Add(new CheckBox { Text = "Disabled Checked", Enabled = false, Checked = true }); + rightPanel.Children.Add(new RadioButton("Test box 2")); + rightPanel.Children.Add(new RadioButton { Text = "Disabled", Enabled = false }); + rightPanel.Children.Add(new RadioButton { Text = "Disabled Checked", Enabled = false, Checked = true }); leftPanel.Children.Add(info); Modified: branches/gui/Gui/ThemeEngines/Graphite.cs =================================================================== --- branches/gui/Gui/ThemeEngines/Graphite.cs 2009-04-18 22:31:41 UTC (rev 876) +++ branches/gui/Gui/ThemeEngines/Graphite.cs 2009-04-18 22:47:10 UTC (rev 877) @@ -40,6 +40,7 @@ if (widget is Label) DrawLabel((Label)widget); if (widget is Button) DrawButton((Button)widget); if (widget is CheckBox) DrawCheckbox((CheckBox)widget); + if (widget is RadioButton) DrawRadioButton((RadioButton)widget); if (widget is TextBox) DrawTextBox((TextBox)widget); } @@ -54,6 +55,7 @@ if (widget is Button) return CalcMinButtonSize((Button)widget); if (widget is CheckBox) return CalcMinCheckBoxSize((CheckBox)widget); if (widget is TextBox) return CalcMinTextBoxSize((TextBox)widget); + if (widget is RadioButton) return CalcMinRadioButtonSize((RadioButton)widget); return Size.Empty; } @@ -222,6 +224,60 @@ #endregion + #region --- CheckBox --- + + private void DrawRadioButton(RadioButton checkbox) + { + Surface surf; + + if (checkbox.Enabled == false && checkbox.Checked) surf = Scheme.CheckBoxCheckedDisabled; + else if (checkbox.Enabled == false) surf = Scheme.CheckBoxDisabled; + else if (checkbox.Checked && checkbox.MouseIn) surf = Scheme.CheckBoxCheckedHover; + else if (checkbox.Checked) surf = Scheme.CheckBoxChecked; + else if (checkbox.MouseIn) surf = Scheme.CheckBoxHover; + else + surf = Scheme.CheckBox; + + Point destPoint = checkbox.PointToScreen( + Origin.Calc(OriginAlignment.CenterLeft, checkbox.Size)); + + surf.DisplayAlignment = OriginAlignment.CenterLeft; + surf.Draw(destPoint); + + SetControlFontColor(checkbox); + + destPoint.X += surf.DisplayWidth + Scheme.CheckBoxSpacing; + + Scheme.ControlFont.DisplayAlignment = OriginAlignment.CenterLeft; + Scheme.ControlFont.DrawText(destPoint, checkbox.Text); + } + + private Size CalcMinRadioButtonSize(RadioButton checkbox) + { + Size text = Scheme.ControlFont.StringDisplaySize(checkbox.Text); + Size box = Scheme.CheckBox.SurfaceSize; + + return new Size( + box.Width + Scheme.CheckBoxSpacing + text.Width, + Math.Max(box.Height, text.Height)); + } + + + private bool HitTestRadioButton(RadioButton checkBox, Point screenLocation) + { + Point local = checkBox.PointToClient(screenLocation); + + int right = Scheme.CheckBox.SurfaceWidth + + Scheme.ControlFont.StringDisplayWidth(checkBox.Text) + Scheme.CheckBoxSpacing * 2; + + if (local.X > right) + return false; + + return true; + } + + + #endregion #region --- Label --- private void DrawLabel(Label label) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:31:47
|
Revision: 876 http://agate.svn.sourceforge.net/agate/?rev=876&view=rev Author: kanato Date: 2009-04-18 22:31:41 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Fix formatting in tests. Modified Paths: -------------- trunk/Tests/AgateTestAttribute.cs trunk/Tests/AudioTests/AudioPlayer/AudioPlayer.cs trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.Designer.cs trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.cs trunk/Tests/CoreTests/App.cs trunk/Tests/CoreTests/ErrorReport/ErrorReport.cs trunk/Tests/CoreTests/ErrorReport/frmErrorReport.Designer.cs trunk/Tests/CoreTests/ErrorReport/frmErrorReport.cs trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs trunk/Tests/CoreTests/RefCounters.cs trunk/Tests/CoreTests/TgzProviderTester.cs trunk/Tests/CoreTests/Timers/Timers.cs trunk/Tests/CoreTests/Timers/frmTimers.Designer.cs trunk/Tests/CoreTests/Timers/frmTimers.cs trunk/Tests/DisplayTests/BasicDrawing/DrawingTester.Designer.cs trunk/Tests/DisplayTests/BasicDrawing/DrawingTester.cs trunk/Tests/DisplayTests/BasicSprite.cs trunk/Tests/DisplayTests/Interpolation.cs trunk/Tests/DisplayTests/LightingTest/LightingTest.cs trunk/Tests/DisplayTests/LightingTest/LightingTestForm.Designer.cs trunk/Tests/DisplayTests/LightingTest/LightingTestForm.cs trunk/Tests/DisplayTests/MultipleWindows/MultipleRenderTargetExample.Designer.cs trunk/Tests/DisplayTests/MultipleWindows/MultipleRenderTargetExample.cs trunk/Tests/DisplayTests/MultipleWindows/MultipleWindowTest.cs trunk/Tests/DisplayTests/Ortho.cs trunk/Tests/DisplayTests/PixelBufferTest/PixelBufferForm.Designer.cs trunk/Tests/DisplayTests/PixelBufferTest/PixelBufferForm.cs trunk/Tests/DisplayTests/PixelBufferTest/PixelBufferTest.cs trunk/Tests/DisplayTests/RotatingSpriteTester.cs trunk/Tests/DisplayTests/ScreenCapture.cs trunk/Tests/DisplayTests/SpriteTester/SpriteTester.cs trunk/Tests/DisplayTests/SpriteTester/frmChooseSprite.Designer.cs trunk/Tests/DisplayTests/SpriteTester/frmChooseSprite.cs trunk/Tests/DisplayTests/SpriteTester/frmSpriteTester.Designer.cs trunk/Tests/DisplayTests/SpriteTester/frmSpriteTester.cs trunk/Tests/DisplayTests/SurfaceTester/SurfaceTester.cs trunk/Tests/DisplayTests/SurfaceTester/frmSurfaceTester.Designer.cs trunk/Tests/DisplayTests/TestPacker/TestPacker.cs trunk/Tests/DisplayTests/TestPacker/frmTestPacker.Designer.cs trunk/Tests/DisplayTests/TestPacker/frmTestPacker.cs trunk/Tests/DisplayTests/TileTester/TileTester.cs trunk/Tests/DisplayTests/TileTester/frmTileTester.Designer.cs trunk/Tests/DisplayTests/TileTester/frmTileTester.cs trunk/Tests/DisplayTests/Tiling.cs trunk/Tests/Fonts/BitmapFonts.cs trunk/Tests/Fonts/FontLineTester.cs trunk/Tests/Fonts/Fonts.cs trunk/Tests/IAgateTest.cs trunk/Tests/InputTests/Input/InputTester.cs trunk/Tests/InputTests/Input/frmInputTester.Designer.cs trunk/Tests/Launcher.cs trunk/Tests/frmLauncher.Designer.cs trunk/Tests/frmLauncher.cs Modified: trunk/Tests/AgateTestAttribute.cs =================================================================== --- trunk/Tests/AgateTestAttribute.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/AgateTestAttribute.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -5,18 +5,18 @@ namespace Tests { - [global::System.AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] - sealed class AgateTestAttribute : Attribute - { - // This is a positional argument - public AgateTestAttribute(string name, string category) - { - Name = name; - Category = category; - } + [global::System.AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] + sealed class AgateTestAttribute : Attribute + { + // This is a positional argument + public AgateTestAttribute(string name, string category) + { + Name = name; + Category = category; + } - public string Name { get; private set; } - public string Category { get; private set; } + public string Name { get; private set; } + public string Category { get; private set; } - } + } } Modified: trunk/Tests/AudioTests/AudioPlayer/AudioPlayer.cs =================================================================== --- trunk/Tests/AudioTests/AudioPlayer/AudioPlayer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/AudioTests/AudioPlayer/AudioPlayer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -8,35 +8,35 @@ namespace Tests.AudioTester { - class AudioTester : IAgateTest - { - /// <summary> - /// The main entry point for the application. - /// </summary> - public void Main(string[] args) - { - using (AgateLib.AgateSetup setup = new AgateLib.AgateSetup("Agate Audio Tester", args)) - { - setup.AskUser = true; - setup.Initialize(false, true, false); - if (setup.WasCanceled) - return; + class AudioTester : IAgateTest + { + /// <summary> + /// The main entry point for the application. + /// </summary> + public void Main(string[] args) + { + using (AgateLib.AgateSetup setup = new AgateLib.AgateSetup("Agate Audio Tester", args)) + { + setup.AskUser = true; + setup.Initialize(false, true, false); + if (setup.WasCanceled) + return; - Application.Run(new frmAudioTester()); - } - } + Application.Run(new frmAudioTester()); + } + } - #region IAgateTest Members + #region IAgateTest Members - public string Name - { - get { return "Audio Player"; } - } - public string Category - { - get { return "Audio"; } - } + public string Name + { + get { return "Audio Player"; } + } + public string Category + { + get { return "Audio"; } + } - #endregion - } + #endregion + } } \ No newline at end of file Modified: trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.Designer.cs =================================================================== --- trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.Designer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.Designer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -3,268 +3,268 @@ // namespace Tests.AudioTester { - partial class frmAudioTester - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; + partial class frmAudioTester + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.btnStopAll = new System.Windows.Forms.Button(); - this.btnSound = new System.Windows.Forms.Button(); - this.lstFiles = new System.Windows.Forms.ListBox(); - this.btnMusic = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); - this.panValue = new System.Windows.Forms.NumericUpDown(); - this.label2 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.folderBrowser = new System.Windows.Forms.FolderBrowserDialog(); - this.statusLabel = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.btnPlayLastSound = new System.Windows.Forms.Button(); - this.timer1 = new System.Windows.Forms.Timer(this.components); - this.label3 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.panValue)).BeginInit(); - this.SuspendLayout(); - // - // btnStopAll - // - this.btnStopAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnStopAll.Location = new System.Drawing.Point(329, 285); - this.btnStopAll.Name = "btnStopAll"; - this.btnStopAll.Size = new System.Drawing.Size(75, 23); - this.btnStopAll.TabIndex = 7; - this.btnStopAll.Text = "Stop All"; - this.btnStopAll.UseVisualStyleBackColor = true; - this.btnStopAll.Click += new System.EventHandler(this.btnStop_Click); - // - // btnSound - // - this.btnSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnSound.Location = new System.Drawing.Point(293, 227); - this.btnSound.Name = "btnSound"; - this.btnSound.Size = new System.Drawing.Size(111, 23); - this.btnSound.TabIndex = 6; - this.btnSound.Text = "Play as Sound"; - this.btnSound.UseVisualStyleBackColor = true; - this.btnSound.Click += new System.EventHandler(this.btnSound_Click); - // - // lstFiles - // - this.lstFiles.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.lstFiles.FormattingEnabled = true; - this.lstFiles.Location = new System.Drawing.Point(12, 64); - this.lstFiles.Name = "lstFiles"; - this.lstFiles.Size = new System.Drawing.Size(236, 225); - this.lstFiles.TabIndex = 5; - // - // btnMusic - // - this.btnMusic.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnMusic.Location = new System.Drawing.Point(293, 256); - this.btnMusic.Name = "btnMusic"; - this.btnMusic.Size = new System.Drawing.Size(111, 23); - this.btnMusic.TabIndex = 4; - this.btnMusic.Text = "Play as Music"; - this.btnMusic.UseVisualStyleBackColor = true; - this.btnMusic.Click += new System.EventHandler(this.btnMusic_Click); - // - // label1 - // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(281, 64); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(42, 13); - this.label1.TabIndex = 8; - this.label1.Text = "Volume"; - // - // numericUpDown1 - // - this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.numericUpDown1.DecimalPlaces = 2; - this.numericUpDown1.Increment = new decimal(new int[] { + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.btnStopAll = new System.Windows.Forms.Button(); + this.btnSound = new System.Windows.Forms.Button(); + this.lstFiles = new System.Windows.Forms.ListBox(); + this.btnMusic = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.panValue = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.folderBrowser = new System.Windows.Forms.FolderBrowserDialog(); + this.statusLabel = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.btnPlayLastSound = new System.Windows.Forms.Button(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.label3 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.panValue)).BeginInit(); + this.SuspendLayout(); + // + // btnStopAll + // + this.btnStopAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnStopAll.Location = new System.Drawing.Point(329, 285); + this.btnStopAll.Name = "btnStopAll"; + this.btnStopAll.Size = new System.Drawing.Size(75, 23); + this.btnStopAll.TabIndex = 7; + this.btnStopAll.Text = "Stop All"; + this.btnStopAll.UseVisualStyleBackColor = true; + this.btnStopAll.Click += new System.EventHandler(this.btnStop_Click); + // + // btnSound + // + this.btnSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnSound.Location = new System.Drawing.Point(293, 227); + this.btnSound.Name = "btnSound"; + this.btnSound.Size = new System.Drawing.Size(111, 23); + this.btnSound.TabIndex = 6; + this.btnSound.Text = "Play as Sound"; + this.btnSound.UseVisualStyleBackColor = true; + this.btnSound.Click += new System.EventHandler(this.btnSound_Click); + // + // lstFiles + // + this.lstFiles.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lstFiles.FormattingEnabled = true; + this.lstFiles.Location = new System.Drawing.Point(12, 64); + this.lstFiles.Name = "lstFiles"; + this.lstFiles.Size = new System.Drawing.Size(236, 225); + this.lstFiles.TabIndex = 5; + // + // btnMusic + // + this.btnMusic.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnMusic.Location = new System.Drawing.Point(293, 256); + this.btnMusic.Name = "btnMusic"; + this.btnMusic.Size = new System.Drawing.Size(111, 23); + this.btnMusic.TabIndex = 4; + this.btnMusic.Text = "Play as Music"; + this.btnMusic.UseVisualStyleBackColor = true; + this.btnMusic.Click += new System.EventHandler(this.btnMusic_Click); + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(281, 64); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(42, 13); + this.label1.TabIndex = 8; + this.label1.Text = "Volume"; + // + // numericUpDown1 + // + this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDown1.DecimalPlaces = 2; + this.numericUpDown1.Increment = new decimal(new int[] { 1, 0, 0, 131072}); - this.numericUpDown1.Location = new System.Drawing.Point(329, 62); - this.numericUpDown1.Maximum = new decimal(new int[] { + this.numericUpDown1.Location = new System.Drawing.Point(329, 62); + this.numericUpDown1.Maximum = new decimal(new int[] { 1, 0, 0, 0}); - this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(63, 20); - this.numericUpDown1.TabIndex = 9; - this.numericUpDown1.Value = new decimal(new int[] { + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(63, 20); + this.numericUpDown1.TabIndex = 9; + this.numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 0}); - this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); - // - // panValue - // - this.panValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.panValue.DecimalPlaces = 2; - this.panValue.Increment = new decimal(new int[] { + this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); + // + // panValue + // + this.panValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.panValue.DecimalPlaces = 2; + this.panValue.Increment = new decimal(new int[] { 1, 0, 0, 131072}); - this.panValue.Location = new System.Drawing.Point(329, 88); - this.panValue.Maximum = new decimal(new int[] { + this.panValue.Location = new System.Drawing.Point(329, 88); + this.panValue.Maximum = new decimal(new int[] { 1, 0, 0, 0}); - this.panValue.Minimum = new decimal(new int[] { + this.panValue.Minimum = new decimal(new int[] { 1, 0, 0, -2147483648}); - this.panValue.Name = "panValue"; - this.panValue.Size = new System.Drawing.Size(63, 20); - this.panValue.TabIndex = 11; - this.panValue.ValueChanged += new System.EventHandler(this.panValue_ValueChanged); - // - // label2 - // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(281, 90); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(26, 13); - this.label2.TabIndex = 10; - this.label2.Text = "Pan"; - // - // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.button1.Location = new System.Drawing.Point(329, 23); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 12; - this.button1.Text = "Browse..."; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // statusLabel - // - this.statusLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.statusLabel.Location = new System.Drawing.Point(12, 306); - this.statusLabel.Name = "statusLabel"; - this.statusLabel.Size = new System.Drawing.Size(275, 40); - this.statusLabel.TabIndex = 13; - this.statusLabel.Text = "label3"; - // - // textBox1 - // - this.textBox1.Location = new System.Drawing.Point(12, 25); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(295, 20); - this.textBox1.TabIndex = 14; - this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); - // - // btnPlayLastSound - // - this.btnPlayLastSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btnPlayLastSound.Location = new System.Drawing.Point(274, 180); - this.btnPlayLastSound.Name = "btnPlayLastSound"; - this.btnPlayLastSound.Size = new System.Drawing.Size(130, 23); - this.btnPlayLastSound.TabIndex = 15; - this.btnPlayLastSound.Text = "Play Last Sound"; - this.btnPlayLastSound.UseVisualStyleBackColor = true; - this.btnPlayLastSound.Click += new System.EventHandler(this.btnPlayLastSound_Click); - // - // timer1 - // - this.timer1.Enabled = true; - this.timer1.Interval = 20; - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(12, 9); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(91, 13); - this.label3.TabIndex = 16; - this.label3.Text = "Path to audio files"; - // - // frmAudioTester - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(416, 345); - this.Controls.Add(this.label3); - this.Controls.Add(this.btnPlayLastSound); - this.Controls.Add(this.textBox1); - this.Controls.Add(this.statusLabel); - this.Controls.Add(this.button1); - this.Controls.Add(this.panValue); - this.Controls.Add(this.label2); - this.Controls.Add(this.numericUpDown1); - this.Controls.Add(this.label1); - this.Controls.Add(this.btnStopAll); - this.Controls.Add(this.btnSound); - this.Controls.Add(this.lstFiles); - this.Controls.Add(this.btnMusic); - this.Name = "frmAudioTester"; - this.Text = "Audio Tester"; - this.Load += new System.EventHandler(this.frmAudioTester_Load); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.panValue)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.panValue.Name = "panValue"; + this.panValue.Size = new System.Drawing.Size(63, 20); + this.panValue.TabIndex = 11; + this.panValue.ValueChanged += new System.EventHandler(this.panValue_ValueChanged); + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(281, 90); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(26, 13); + this.label2.TabIndex = 10; + this.label2.Text = "Pan"; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(329, 23); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 12; + this.button1.Text = "Browse..."; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // statusLabel + // + this.statusLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.statusLabel.Location = new System.Drawing.Point(12, 306); + this.statusLabel.Name = "statusLabel"; + this.statusLabel.Size = new System.Drawing.Size(275, 40); + this.statusLabel.TabIndex = 13; + this.statusLabel.Text = "label3"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(12, 25); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(295, 20); + this.textBox1.TabIndex = 14; + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); + // + // btnPlayLastSound + // + this.btnPlayLastSound.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnPlayLastSound.Location = new System.Drawing.Point(274, 180); + this.btnPlayLastSound.Name = "btnPlayLastSound"; + this.btnPlayLastSound.Size = new System.Drawing.Size(130, 23); + this.btnPlayLastSound.TabIndex = 15; + this.btnPlayLastSound.Text = "Play Last Sound"; + this.btnPlayLastSound.UseVisualStyleBackColor = true; + this.btnPlayLastSound.Click += new System.EventHandler(this.btnPlayLastSound_Click); + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Interval = 20; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(91, 13); + this.label3.TabIndex = 16; + this.label3.Text = "Path to audio files"; + // + // frmAudioTester + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(416, 345); + this.Controls.Add(this.label3); + this.Controls.Add(this.btnPlayLastSound); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.statusLabel); + this.Controls.Add(this.button1); + this.Controls.Add(this.panValue); + this.Controls.Add(this.label2); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.label1); + this.Controls.Add(this.btnStopAll); + this.Controls.Add(this.btnSound); + this.Controls.Add(this.lstFiles); + this.Controls.Add(this.btnMusic); + this.Name = "frmAudioTester"; + this.Text = "Audio Tester"; + this.Load += new System.EventHandler(this.frmAudioTester_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.panValue)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); - } + } - #endregion + #endregion - private System.Windows.Forms.Button btnStopAll; - private System.Windows.Forms.Button btnSound; - private System.Windows.Forms.ListBox lstFiles; - private System.Windows.Forms.Button btnMusic; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.NumericUpDown numericUpDown1; - private System.Windows.Forms.NumericUpDown panValue; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Button button1; - private System.Windows.Forms.FolderBrowserDialog folderBrowser; - private System.Windows.Forms.Label statusLabel; - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.Button btnPlayLastSound; - private System.Windows.Forms.Timer timer1; - private System.Windows.Forms.Label label3; - } + private System.Windows.Forms.Button btnStopAll; + private System.Windows.Forms.Button btnSound; + private System.Windows.Forms.ListBox lstFiles; + private System.Windows.Forms.Button btnMusic; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.NumericUpDown panValue; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.FolderBrowserDialog folderBrowser; + private System.Windows.Forms.Label statusLabel; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button btnPlayLastSound; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Label label3; + } } Modified: trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.cs =================================================================== --- trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/AudioTests/AudioPlayer/frmAudioPlayer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -13,44 +13,44 @@ namespace Tests.AudioTester { - public partial class frmAudioTester : Form - { - AgateLib.AudioLib.SoundBuffer mSound; - AgateLib.AudioLib.Music mMusic; + public partial class frmAudioTester : Form + { + AgateLib.AudioLib.SoundBuffer mSound; + AgateLib.AudioLib.Music mMusic; - public frmAudioTester() - { - InitializeComponent(); + public frmAudioTester() + { + InitializeComponent(); - Icon = AgateLib.WinForms.FormUtil.AgateLibIcon; + Icon = AgateLib.WinForms.FormUtil.AgateLibIcon; - statusLabel.Text = ""; + statusLabel.Text = ""; - textBox1.Text = Directory.GetCurrentDirectory(); - } + textBox1.Text = Directory.GetCurrentDirectory(); + } - private void frmAudioTester_Load(object sender, EventArgs e) - { - FillMusicListBox(); - } + private void frmAudioTester_Load(object sender, EventArgs e) + { + FillMusicListBox(); + } - private void btnMusic_Click(object sender, EventArgs e) - { - string text = lstFiles.SelectedItem as string; + private void btnMusic_Click(object sender, EventArgs e) + { + string text = lstFiles.SelectedItem as string; - if (string.IsNullOrEmpty(text)) - return; + if (string.IsNullOrEmpty(text)) + return; #if !DEBUG try { #endif - AgateLib.AudioLib.Music music = new AgateLib.AudioLib.Music(text); - mMusic = music; + AgateLib.AudioLib.Music music = new AgateLib.AudioLib.Music(text); + mMusic = music; - music.Volume = (double)numericUpDown1.Value; - music.Pan = (double)panValue.Value; - music.Play(); + music.Volume = (double)numericUpDown1.Value; + music.Pan = (double)panValue.Value; + music.Play(); #if !DEBUG } catch (Exception error) @@ -59,35 +59,35 @@ statusLabel.Text = "Error: " + error.Message; } #endif - } + } - private void btnPlayLastSound_Click(object sender, EventArgs e) - { - if (mSound == null) - return; + private void btnPlayLastSound_Click(object sender, EventArgs e) + { + if (mSound == null) + return; - mSound.Play(); - } + mSound.Play(); + } - private void btnSound_Click(object sender, EventArgs e) - { - string text = lstFiles.SelectedItem as string; + private void btnSound_Click(object sender, EventArgs e) + { + string text = lstFiles.SelectedItem as string; - if (string.IsNullOrEmpty(text)) - return; + if (string.IsNullOrEmpty(text)) + return; #if !DEBUG try { #endif - AgateLib.AudioLib.SoundBuffer snd = new AgateLib.AudioLib.SoundBuffer(text); + AgateLib.AudioLib.SoundBuffer snd = new AgateLib.AudioLib.SoundBuffer(text); - snd.Volume = (double)numericUpDown1.Value; - snd.Pan = (double)panValue.Value; - snd.Play(); + snd.Volume = (double)numericUpDown1.Value; + snd.Pan = (double)panValue.Value; + snd.Play(); - mSound = snd; + mSound = snd; #if !DEBUG } catch (Exception error) @@ -96,84 +96,84 @@ statusLabel.Text = "Error: " + error.Message; } #endif - } + } - private void btnStop_Click(object sender, EventArgs e) - { - AgateLib.AudioLib.Audio.StopAll(); - } + private void btnStop_Click(object sender, EventArgs e) + { + AgateLib.AudioLib.Audio.StopAll(); + } - private void FillMusicListBox() - { - lstFiles.Items.Clear(); + private void FillMusicListBox() + { + lstFiles.Items.Clear(); - string[] files = Directory.GetFiles(Directory.GetCurrentDirectory()); - string extensions = ".mid .mp3 .wav .wma .ogg"; + string[] files = Directory.GetFiles(Directory.GetCurrentDirectory()); + string extensions = ".mid .mp3 .wav .wma .ogg"; - foreach (string filename in files) - { - string ext = Path.GetExtension(filename); + foreach (string filename in files) + { + string ext = Path.GetExtension(filename); - if (extensions.Contains(ext.ToLower())) - { - lstFiles.Items.Add(Path.GetFileName(filename)); - } - } - } + if (extensions.Contains(ext.ToLower())) + { + lstFiles.Items.Add(Path.GetFileName(filename)); + } + } + } - private void numericUpDown1_ValueChanged(object sender, EventArgs e) - { - if (mSound != null) - mSound.Volume = (double)numericUpDown1.Value; - if (mMusic != null) - mMusic.Volume = (double)numericUpDown1.Value; - } + private void numericUpDown1_ValueChanged(object sender, EventArgs e) + { + if (mSound != null) + mSound.Volume = (double)numericUpDown1.Value; + if (mMusic != null) + mMusic.Volume = (double)numericUpDown1.Value; + } - private void panValue_ValueChanged(object sender, EventArgs e) - { + private void panValue_ValueChanged(object sender, EventArgs e) + { - if (mSound != null) - mSound.Pan = (double)panValue.Value; - if (mMusic != null) - mMusic.Pan = (double)panValue.Value; - } + if (mSound != null) + mSound.Pan = (double)panValue.Value; + if (mMusic != null) + mMusic.Pan = (double)panValue.Value; + } - private void button1_Click(object sender, EventArgs e) - { - folderBrowser.SelectedPath = Directory.GetCurrentDirectory(); + private void button1_Click(object sender, EventArgs e) + { + folderBrowser.SelectedPath = Directory.GetCurrentDirectory(); - if (folderBrowser.ShowDialog() == DialogResult.OK) - { - textBox1.Text = folderBrowser.SelectedPath; - } - } + if (folderBrowser.ShowDialog() == DialogResult.OK) + { + textBox1.Text = folderBrowser.SelectedPath; + } + } - private void textBox1_TextChanged(object sender, EventArgs e) - { - try - { - Directory.SetCurrentDirectory(textBox1.Text); + private void textBox1_TextChanged(object sender, EventArgs e) + { + try + { + Directory.SetCurrentDirectory(textBox1.Text); - //AgateFileProvider.Music.Clear(); - //AgateFileProvider.Sounds.Clear(); + //AgateFileProvider.Music.Clear(); + //AgateFileProvider.Sounds.Clear(); - //AgateFileProvider.Music.AddPath("."); - //AgateFileProvider.Sounds.AddPath("."); + //AgateFileProvider.Music.AddPath("."); + //AgateFileProvider.Sounds.AddPath("."); - FillMusicListBox(); - } - catch (Exception ex) - { - } - } + FillMusicListBox(); + } + catch (Exception ex) + { + } + } - private void timer1_Tick(object sender, EventArgs e) - { - AgateLib.Core.KeepAlive(); - } + private void timer1_Tick(object sender, EventArgs e) + { + AgateLib.Core.KeepAlive(); + } - } + } } \ No newline at end of file Modified: trunk/Tests/CoreTests/App.cs =================================================================== --- trunk/Tests/CoreTests/App.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/App.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -5,25 +5,25 @@ namespace Tests.AppTester { - class App : AgateApplication, IAgateTest - { - public void Main(string[] args) - { - Run(args); - } + class App : AgateApplication, IAgateTest + { + public void Main(string[] args) + { + Run(args); + } - protected override AppInitParameters GetAppInitParameters() - { - var retval = base.GetAppInitParameters(); - retval.AllowResize = true; - return retval; - } + protected override AppInitParameters GetAppInitParameters() + { + var retval = base.GetAppInitParameters(); + retval.AllowResize = true; + return retval; + } - #region IAgateTest Members + #region IAgateTest Members - public string Name { get { return "App Tester"; } } - public string Category { get { return "Core"; } } + public string Name { get { return "App Tester"; } } + public string Category { get { return "Core"; } } - #endregion - } + #endregion + } } Modified: trunk/Tests/CoreTests/ErrorReport/ErrorReport.cs =================================================================== --- trunk/Tests/CoreTests/ErrorReport/ErrorReport.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/ErrorReport/ErrorReport.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -5,25 +5,25 @@ namespace Tests.ErrorReportTester { - class ErrorReportTester : IAgateTest - { - /// <summary> - /// The main entry point for the application. - /// </summary> - [STAThread] - public void Main(string[] args) - { - AgateLib.Core.Initialize(); + class ErrorReportTester : IAgateTest + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + public void Main(string[] args) + { + AgateLib.Core.Initialize(); - new frmErrorReportTester().ShowDialog(); - } + new frmErrorReportTester().ShowDialog(); + } - #region IAgateTest Members + #region IAgateTest Members - public string Name { get { return "Error Report Tester"; } } - public string Category { get { return "Core"; } } + public string Name { get { return "Error Report Tester"; } } + public string Category { get { return "Core"; } } - #endregion - } + #endregion + } } \ No newline at end of file Modified: trunk/Tests/CoreTests/ErrorReport/frmErrorReport.Designer.cs =================================================================== --- trunk/Tests/CoreTests/ErrorReport/frmErrorReport.Designer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/ErrorReport/frmErrorReport.Designer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -1,33 +1,33 @@ namespace Tests.ErrorReportTester { - partial class frmErrorReportTester - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; + partial class frmErrorReportTester + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmErrorReportTester)); this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); @@ -70,12 +70,12 @@ this.ResumeLayout(false); this.PerformLayout(); - } + } - #endregion + #endregion - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.Button button1; - } + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } } Modified: trunk/Tests/CoreTests/ErrorReport/frmErrorReport.cs =================================================================== --- trunk/Tests/CoreTests/ErrorReport/frmErrorReport.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/ErrorReport/frmErrorReport.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -9,64 +9,64 @@ namespace Tests.ErrorReportTester { - public partial class frmErrorReportTester : Form - { - public frmErrorReportTester() - { - InitializeComponent(); + public partial class frmErrorReportTester : Form + { + public frmErrorReportTester() + { + InitializeComponent(); - AgateLib.Core.Initialize(); - } + AgateLib.Core.Initialize(); + } - private void button1_Click(object sender, EventArgs e) - { - GenerateErrors(); + private void button1_Click(object sender, EventArgs e) + { + GenerateErrors(); - FillTextBox(); - } + FillTextBox(); + } - private static void GenerateErrors() - { - AgateLib.Core.ReportError(ErrorLevel.Comment, "Test comment about application condition", null); - - try - { - System.IO.File.Open("file not there.txt", System.IO.FileMode.Open); - } - catch (Exception e) - { - AgateLib.Core.ReportError(ErrorLevel.Warning, "File not there.", e); - } + private static void GenerateErrors() + { + AgateLib.Core.ReportError(ErrorLevel.Comment, "Test comment about application condition", null); - try - { - System.IO.File.Open("important missing file.dll", System.IO.FileMode.Open); - } - catch (Exception e) - { - AgateLib.Core.ReportError(ErrorLevel.Fatal, "Missing file", e); - } + try + { + System.IO.File.Open("file not there.txt", System.IO.FileMode.Open); + } + catch (Exception e) + { + AgateLib.Core.ReportError(ErrorLevel.Warning, "File not there.", e); + } - try - { - throw new InvalidOperationException("Something went wrong!"); - } - catch (Exception e) - { - AgateLib.Core.ReportError(ErrorLevel.Bug, "Oops, a bug.", e); - } + try + { + System.IO.File.Open("important missing file.dll", System.IO.FileMode.Open); + } + catch (Exception e) + { + AgateLib.Core.ReportError(ErrorLevel.Fatal, "Missing file", e); + } - // unhandled error - //throw new Exception("This exception is unhandled!"); - } + try + { + throw new InvalidOperationException("Something went wrong!"); + } + catch (Exception e) + { + AgateLib.Core.ReportError(ErrorLevel.Bug, "Oops, a bug.", e); + } - private void FillTextBox() - { - System.IO.TextReader r = new System.IO.StreamReader(AgateLib.Core.ErrorFile); + // unhandled error + //throw new Exception("This exception is unhandled!"); + } - textBox1.Text = r.ReadToEnd(); + private void FillTextBox() + { + System.IO.TextReader r = new System.IO.StreamReader(AgateLib.Core.ErrorFile); - r.Dispose(); - } - } + textBox1.Text = r.ReadToEnd(); + + r.Dispose(); + } + } } \ No newline at end of file Modified: trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs =================================================================== --- trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/Performance/frmPerformance.Designer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -3,34 +3,34 @@ // namespace Tests.PerformanceTester { - partial class frmPerformanceTester - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; + partial class frmPerformanceTester + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPerformanceTester)); this.listView1 = new System.Windows.Forms.ListView(); this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); @@ -86,9 +86,9 @@ this.Text = "Performance Test Results"; this.ResumeLayout(false); - } + } - #endregion + #endregion private System.Windows.Forms.ListView listView1; private System.Windows.Forms.ColumnHeader columnHeader1; Modified: trunk/Tests/CoreTests/RefCounters.cs =================================================================== --- trunk/Tests/CoreTests/RefCounters.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/RefCounters.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -9,42 +9,42 @@ namespace Tests.RefCounterTester { - class Program : IAgateTest - { - public void Main(string[] args) - { - Ref<TestClass> myref = new Ref<TestClass>(new TestClass()); - Ref<TestClass> newref = new Ref<TestClass>(myref); + class Program : IAgateTest + { + public void Main(string[] args) + { + Ref<TestClass> myref = new Ref<TestClass>(new TestClass()); + Ref<TestClass> newref = new Ref<TestClass>(myref); - newref.Dispose(); - myref.Dispose(); + newref.Dispose(); + myref.Dispose(); - Console.WriteLine("Press a key to finish."); - Console.ReadKey(false); - } + Console.WriteLine("Press a key to finish."); + Console.ReadKey(false); + } - #region IAgateTest Members + #region IAgateTest Members - public string Name { get { return "Ref Counter Tester"; } } - public string Category { get { return "Core"; } } + public string Name { get { return "Ref Counter Tester"; } } + public string Category { get { return "Core"; } } - #endregion + #endregion - class TestClass : IDisposable - { - public TestClass() - { - System.Console.WriteLine("TestClass Created."); - } - ~TestClass() - { - System.Console.WriteLine("TestClass Destroyed."); - } + class TestClass : IDisposable + { + public TestClass() + { + System.Console.WriteLine("TestClass Created."); + } + ~TestClass() + { + System.Console.WriteLine("TestClass Destroyed."); + } - public void Dispose() - { - System.Console.WriteLine("TestClass Disposed."); - } - } - } + public void Dispose() + { + System.Console.WriteLine("TestClass Disposed."); + } + } + } } \ No newline at end of file Modified: trunk/Tests/CoreTests/TgzProviderTester.cs =================================================================== --- trunk/Tests/CoreTests/TgzProviderTester.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/TgzProviderTester.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -8,46 +8,46 @@ namespace Tests.TgzProviderTester { - class TgzProviderTester : IAgateTest - { - public void Main(string [] args) - { - var tgz = new TgzFileProvider("Data/dogs.tar.gz"); + class TgzProviderTester : IAgateTest + { + public void Main(string[] args) + { + var tgz = new TgzFileProvider("Data/dogs.tar.gz"); - using (AgateSetup setup = new AgateSetup()) - { - setup.AskUser = true; - setup.Initialize(true, false, false); - if (setup.WasCanceled) - return; + using (AgateSetup setup = new AgateSetup()) + { + setup.AskUser = true; + setup.Initialize(true, false, false); + if (setup.WasCanceled) + return; - DisplayWindow wind = DisplayWindow.CreateWindowed( - "TgzFileProvider Tester", 800, 600, false); + DisplayWindow wind = DisplayWindow.CreateWindowed( + "TgzFileProvider Tester", 800, 600, false); - Surface surf = new Surface(tgz, "dogs.png"); - Surface surf2 = new Surface(tgz, "bigpaddle.png"); + Surface surf = new Surface(tgz, "dogs.png"); + Surface surf2 = new Surface(tgz, "bigpaddle.png"); - PixelBuffer pix = surf.ReadPixels(); + PixelBuffer pix = surf.ReadPixels(); - while (wind.IsClosed == false) - { - Display.BeginFrame(); - Display.Clear(Color.Blue); - - surf.Draw(); - surf2.Draw(10, 490); + while (wind.IsClosed == false) + { + Display.BeginFrame(); + Display.Clear(Color.Blue); - Display.EndFrame(); - Core.KeepAlive(); - } - } - } + surf.Draw(); + surf2.Draw(10, 490); - #region IAgateTest Members + Display.EndFrame(); + Core.KeepAlive(); + } + } + } - public string Name { get { return "Tar.gzip File Provider"; } } - public string Category { get { return "Core"; } } + #region IAgateTest Members - #endregion - } + public string Name { get { return "Tar.gzip File Provider"; } } + public string Category { get { return "Core"; } } + + #endregion + } } Modified: trunk/Tests/CoreTests/Timers/Timers.cs =================================================================== --- trunk/Tests/CoreTests/Timers/Timers.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/Timers/Timers.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -8,34 +8,34 @@ namespace Tests.TimerTester { - class TimerTester : IAgateTest - { - public void Main(string [] args) - { - frmTimerTester frm = new frmTimerTester(); - frm.Show(); + class TimerTester : IAgateTest + { + public void Main(string[] args) + { + frmTimerTester frm = new frmTimerTester(); + frm.Show(); - Core.Initialize(); + Core.Initialize(); - Application.DoEvents(); - System.Threading.Thread.Sleep(0); + Application.DoEvents(); + System.Threading.Thread.Sleep(0); - double startTime = Timing.TotalMilliseconds; + double startTime = Timing.TotalMilliseconds; - while (frm.Visible) - { - frm.UpdateControls(Timing.TotalMilliseconds - startTime); + while (frm.Visible) + { + frm.UpdateControls(Timing.TotalMilliseconds - startTime); - Application.DoEvents(); - System.Threading.Thread.Sleep(0); - } - } + Application.DoEvents(); + System.Threading.Thread.Sleep(0); + } + } - #region IAgateTest Members + #region IAgateTest Members - public string Name { get { return "Timers"; } } - public string Category { get { return "Core"; } } + public string Name { get { return "Timers"; } } + public string Category { get { return "Core"; } } - #endregion - } + #endregion + } } \ No newline at end of file Modified: trunk/Tests/CoreTests/Timers/frmTimers.Designer.cs =================================================================== --- trunk/Tests/CoreTests/Timers/frmTimers.Designer.cs 2009-04-18 22:28:00 UTC (rev 875) +++ trunk/Tests/CoreTests/Timers/frmTimers.Designer.cs 2009-04-18 22:31:41 UTC (rev 876) @@ -3,307 +3,307 @@ // namespace Tests.TimerTester { - partial class frmTimerTester - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; + partial class frmTimerTester + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmTimerTester)); - this.label1 = new System.Windows.Forms.Label(); - this.txtTimer = new System.Windows.Forms.TextBox(); - this.btnPause = new System.Windows.Forms.Button(); - this.btnResume = new System.Windows.Forms.Button(); - this.btnForceResume = new System.Windows.Forms.Button(); - this.label2 = new System.Windows.Forms.Label(); - this.btnCustomForceResume = new System.Windows.Forms.Button(); - this.btnCustomResume = new System.Windows.Forms.Button(); - this.btnCustomPause = new System.Windows.Forms.Button(); - this.btnCustomReset = new System.Windows.Forms.Button(); - this.txtCustomTimer = new System.Windows.Forms.TextBox(); - this.btnPauseAll = new System.Windows.Forms.Button(); - this.btnResumeAll = new System.Windows.Forms.Button(); - this.btnForceAll = new System.Windows.Forms.Button(); - this.label3 = new System.Windows.Forms.Label(); - this.txtEnv = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.txtDeltaTime = new System.Windows.Forms.TextBox(); - this.txtDeltaTimeAvg = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // label1 - // - this.label1.Location = new System.Drawing.Point(55, 15); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(111, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Application Timer"; - this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - // - // txtTimer - // - this.txtTimer.Location = new System.Drawing.Point(172, 12); - this.txtTimer.Name = "txtTimer"; - this.txtTimer.Size = new System.Drawing.Size(100, 20); - this.txtTimer.TabIndex = 1; - this.txtTimer.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; - // - // btnPause - // - this.btnPause.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnPause.Location = new System.Drawing.Point(287, 12); - this.btnPause.Name = "btnPause"; - this.btnPause.Size = new System.Drawing.Size(75, 23); - this.btnPause.TabIndex = 3; - this.btnPause.Text = "Pause"; - this.btnPause.UseVisualStyleBackColor = true; - this.btnPause.Click += new System.EventHandler(this.btnPause_Click); - // - // btnResume - // - this.btnResume.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnResum... [truncated message content] |
From: <ka...@us...> - 2009-04-18 22:28:10
|
Revision: 875 http://agate.svn.sourceforge.net/agate/?rev=875&view=rev Author: kanato Date: 2009-04-18 22:28:00 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Fix title of ZipProviderTester.cs Modified Paths: -------------- trunk/Tests/CoreTests/ZipProviderTester.cs Modified: trunk/Tests/CoreTests/ZipProviderTester.cs =================================================================== --- trunk/Tests/CoreTests/ZipProviderTester.cs 2009-04-18 22:26:54 UTC (rev 874) +++ trunk/Tests/CoreTests/ZipProviderTester.cs 2009-04-18 22:28:00 UTC (rev 875) @@ -9,48 +9,48 @@ namespace Tests.CoreTests { - class ZipProviderTester : IAgateTest - { - public void Main(string[] args) - { - var zip = new ZipFileProvider("Data/dogs.zip"); + class ZipProviderTester : IAgateTest + { + public void Main(string[] args) + { + var zip = new ZipFileProvider("Data/dogs.zip"); - using (AgateSetup setup = new AgateSetup()) - { - setup.AskUser = true; - setup.Initialize(true, false, false); - if (setup.WasCanceled) - return; + using (AgateSetup setup = new AgateSetup()) + { + setup.AskUser = true; + setup.Initialize(true, false, false); + if (setup.WasCanceled) + return; - DisplayWindow wind = DisplayWindow.CreateWindowed( - "TgzFileProvider Tester", 800, 600, false); + DisplayWindow wind = DisplayWindow.CreateWindowed( + "ZipFileProvider Tester", 800, 600, false); - Surface surf = new Surface(zip, "dogs.png"); - Surface surf2 = new Surface(zip, "bigpaddle.png"); - Surface surf3 = new Surface(zip, "other/bg-bricks.png"); + Surface surf = new Surface(zip, "dogs.png"); + Surface surf2 = new Surface(zip, "bigpaddle.png"); + Surface surf3 = new Surface(zip, "other/bg-bricks.png"); - PixelBuffer pix = surf.ReadPixels(); + PixelBuffer pix = surf.ReadPixels(); - while (wind.IsClosed == false) - { - Display.BeginFrame(); - Display.Clear(Color.Blue); + while (wind.IsClosed == false) + { + Display.BeginFrame(); + Display.Clear(Color.Blue); - surf.Draw(); - surf2.Draw(10, 490); - surf3.Draw(100, 100); + surf.Draw(); + surf2.Draw(10, 490); + surf3.Draw(100, 100); - Display.EndFrame(); - Core.KeepAlive(); - } - } - } + Display.EndFrame(); + Core.KeepAlive(); + } + } + } - #region IAgateTest Members + #region IAgateTest Members - public string Name { get { return "Zip Provider"; } } - public string Category { get { return "Core"; } } + public string Name { get { return "Zip Provider"; } } + public string Category { get { return "Core"; } } - #endregion - } + #endregion + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:27:03
|
Revision: 874 http://agate.svn.sourceforge.net/agate/?rev=874&view=rev Author: kanato Date: 2009-04-18 22:26:54 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Improve error checking in AgateSandBoxLoader.cs. Modified Paths: -------------- trunk/AgateLib/Drivers/AgateSandBoxLoader.cs Modified: trunk/AgateLib/Drivers/AgateSandBoxLoader.cs =================================================================== --- trunk/AgateLib/Drivers/AgateSandBoxLoader.cs 2009-04-18 22:21:43 UTC (rev 873) +++ trunk/AgateLib/Drivers/AgateSandBoxLoader.cs 2009-04-18 22:26:54 UTC (rev 874) @@ -41,8 +41,23 @@ return retval.ToArray(); } - foreach (Type t in ass.GetTypes()) + Type[] types; + + try { + types = ass.GetTypes(); + } + catch (Exception e) + { + System.Diagnostics.Trace.WriteLine(string.Format( + "Could not load types in the file {0}. Check to make sure its dependencies are available. " + + "Caught exception {1}. {2}", file, e.GetType().ToString(), e.Message)); + + return retval.ToArray(); + } + + foreach (Type t in types) + { if (t.IsAbstract) continue; if (typeof(AgateDriverReporter).IsAssignableFrom(t) == false) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-18 22:21:59
|
Revision: 873 http://agate.svn.sourceforge.net/agate/?rev=873&view=rev Author: kanato Date: 2009-04-18 22:21:43 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Remove old files. Rename Pong/Program.cs to Pong/Pong.cs. Add ShootTheTraps example. Modified Paths: -------------- trunk/Examples/BallBuster.Net/BallBuster.Net.csproj trunk/Examples/Examples.sln trunk/Examples/Pong/Pong.csproj Added Paths: ----------- trunk/Examples/Pong/Pong.cs trunk/Examples/ShootTheTraps/ trunk/Examples/ShootTheTraps/App.cs trunk/Examples/ShootTheTraps/Arrow.cs trunk/Examples/ShootTheTraps/GameObject.cs trunk/Examples/ShootTheTraps/Particle.cs trunk/Examples/ShootTheTraps/Properties/ trunk/Examples/ShootTheTraps/Properties/AssemblyInfo.cs trunk/Examples/ShootTheTraps/ShootTheTraps.csproj trunk/Examples/ShootTheTraps/ShootTraps.cs trunk/Examples/ShootTheTraps/Trap.cs trunk/Examples/ShootTheTraps/Vector.cs Removed Paths: ------------- trunk/Examples/CreateWindowExample/ trunk/Examples/Pong/Program.cs Modified: trunk/Examples/BallBuster.Net/BallBuster.Net.csproj =================================================================== --- trunk/Examples/BallBuster.Net/BallBuster.Net.csproj 2009-04-16 02:19:28 UTC (rev 872) +++ trunk/Examples/BallBuster.Net/BallBuster.Net.csproj 2009-04-18 22:21:43 UTC (rev 873) @@ -29,6 +29,7 @@ <IsWebBootstrapper>false</IsWebBootstrapper> <UseApplicationTrust>false</UseApplicationTrust> <BootstrapperEnabled>true</BootstrapperEnabled> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -49,6 +50,9 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> + <Reference Include="System.Core"> + <RequiredTargetFramework>3.5</RequiredTargetFramework> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="ball.cs" /> Modified: trunk/Examples/Examples.sln =================================================================== --- trunk/Examples/Examples.sln 2009-04-16 02:19:28 UTC (rev 872) +++ trunk/Examples/Examples.sln 2009-04-18 22:21:43 UTC (rev 873) @@ -5,8 +5,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgateOTK", "..\Drivers\AgateOTK\AgateOTK.csproj", "{CAB8A0C1-0000-0000-0000-000000000000}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateWindowExample", "CreateWindowExample\CreateWindowExample.csproj", "{FBA15345-5D2C-440A-8BE0-83FA53BEDBCF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong.csproj", "{436641C4-846C-42D0-8E8F-95F70E211D22}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BallBuster.Net", "BallBuster.Net\BallBuster.Net.csproj", "{DD3CF4AA-02CC-4881-AFB1-6F10DFA1F8AF}" @@ -19,6 +17,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgateMDX", "..\Drivers\AgateMDX\AgateMDX.csproj", "{E1F85711-0000-0000-0000-000000000000}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShootTheTraps", "ShootTheTraps\ShootTheTraps.csproj", "{50743D1B-A19E-42F1-842F-65FAD6D168C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,10 +33,6 @@ {CAB8A0C1-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {CAB8A0C1-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU {CAB8A0C1-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {FBA15345-5D2C-440A-8BE0-83FA53BEDBCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FBA15345-5D2C-440A-8BE0-83FA53BEDBCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FBA15345-5D2C-440A-8BE0-83FA53BEDBCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FBA15345-5D2C-440A-8BE0-83FA53BEDBCF}.Release|Any CPU.Build.0 = Release|Any CPU {436641C4-846C-42D0-8E8F-95F70E211D22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {436641C4-846C-42D0-8E8F-95F70E211D22}.Debug|Any CPU.Build.0 = Debug|Any CPU {436641C4-846C-42D0-8E8F-95F70E211D22}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -61,6 +57,10 @@ {E1F85711-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {E1F85711-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU {E1F85711-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU + {50743D1B-A19E-42F1-842F-65FAD6D168C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50743D1B-A19E-42F1-842F-65FAD6D168C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50743D1B-A19E-42F1-842F-65FAD6D168C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50743D1B-A19E-42F1-842F-65FAD6D168C3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Copied: trunk/Examples/Pong/Pong.cs (from rev 872, trunk/Examples/Pong/Program.cs) =================================================================== --- trunk/Examples/Pong/Pong.cs (rev 0) +++ trunk/Examples/Pong/Pong.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,217 @@ +using System; +using System.Collections.Generic; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; + +namespace Pong +{ + class Program + { + + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main(string[] args) + { + new Program().Run(args); + } + + FontSurface font; + int[] score = new int[2]; + string[] names = new string[] { "Player", "CPU" }; + + Vector2 ball, ballvelocity; + Vector2[] paddle = new Vector2[2]; + + const int paddleHeight = 80; + const int paddleWidth = 16; + const int borderSize = paddleWidth; + const int ballSize = paddleWidth; + const int displayWidth = 800; + const int playAreaWidth = 700; + const int displayHeight = 600; + const float paddleSpeed = 150.0f; + + Color paddleColor = Color.LightGray; + Color ballColor = Color.LightGray; + + void Run(string[] args) + { + using (AgateSetup setup = new AgateSetup(args)) + { + setup.Initialize(true, false, false); + if (setup.WasCanceled) + return; + + DisplayWindow wind = DisplayWindow.CreateWindowed + ("Pong Example", displayWidth, displayHeight); + + font = new FontSurface("Sans Serif", 14); + + paddle[0] = new Vector2(50, displayHeight / 2); + paddle[1] = new Vector2(playAreaWidth - 50 - paddleWidth, displayHeight / 2); + ball = new Vector2(playAreaWidth / 2, displayHeight / 2); + ballvelocity = new Vector2(-70, 70); + + while (wind.IsClosed == false) + { + Display.BeginFrame(); + Display.Clear(Color.DarkGray); + + DrawBorder(); + DrawPaddles(); + DrawBall(); + DrawScore(); + + Display.EndFrame(); + Core.KeepAlive(); + + if (Keyboard.Keys[KeyCode.Escape]) + wind.Dispose(); + + float time_s = (float)Display.DeltaTime / 1000.0f; + + UpdatePaddles(time_s); + UpdateBall(time_s); + + } + } + } + + private void DrawScore() + { + int x = playAreaWidth + borderSize * 3 / 2; + int y = borderSize * 2; + + font.DrawText(x, y, "Score"); + + for (int i = 0; i < 2; i++) + { + y += font.StringDisplayHeight("M") * 2; + font.DrawText(x, y, names[i]); + + y += font.StringDisplayHeight("M"); + font.DrawText(x, y, score[i].ToString()); + } + } + + private void UpdateBall(float time_s) + { + bool newBall = false; + + ball += ballvelocity * time_s; + + // collision with bottom wall + if (ball.Y + ballSize > displayHeight - borderSize && ballvelocity.Y > 0) + ballvelocity.Y *= -1; + + // collision with top wall + if (ball.Y < borderSize && ballvelocity.Y < 0) + ballvelocity.Y *= -1; + + if (ball.X < borderSize) + { + newBall = true; + score[1]++; + } + else if (ball.X + ballSize > playAreaWidth) + { + newBall = true; + score[0]++; + } + + if (newBall) + { + ball = new Vector2(playAreaWidth / 2, displayHeight / 2); + ballvelocity = new Vector2(-90, 90); + } + + // check for paddles + bool increaseSpeed = false; + + if (ball.X < paddle[0].X + paddleWidth && ballvelocity.X < 0) + { + if (ball.Y + ballSize - 1 >= paddle[0].Y && + ball.Y <= paddle[0].Y + paddleHeight) + { + ballvelocity.X *= -1; + increaseSpeed = true; + } + } + if (ball.X + ballSize >= paddle[1].X && ballvelocity.X > 0) + { + if (ball.Y + ballSize - 1 >= paddle[1].Y && + ball.Y <= paddle[1].Y + paddleHeight) + { + ballvelocity.X *= -1; + increaseSpeed = true; + } + } + + if (increaseSpeed) + { + ballvelocity.X += Math.Sign(ballvelocity.X) * 10.0f; + ballvelocity.Y += Math.Sign(ballvelocity.Y) * 10.0f; + } + } + + private void UpdatePaddles(float time_s) + { + float paddleMove = paddleSpeed * time_s; + + if (Keyboard.Keys[KeyCode.Down]) paddle[0].Y += paddleMove; + if (Keyboard.Keys[KeyCode.Up]) paddle[0].Y -= paddleMove; + + // do AI + if (ballvelocity.X > 0) + { + if (ball.Y + ballSize * 2 > paddle[1].Y + paddleHeight) paddle[1].Y += paddleMove; + if (ball.Y - ballSize < paddle[1].Y) paddle[1].Y -= paddleMove; + } + + for (int i = 0; i < 2; i++) + { + paddle[i].Y = Math.Max(paddle[i].Y, borderSize); + paddle[i].Y = Math.Min(paddle[i].Y, displayHeight - borderSize - paddleHeight); + } + } + + private void DrawBall() + { + Display.FillRect(new Rectangle((int)ball.X, (int)ball.Y, ballSize, ballSize), ballColor); + } + + private void DrawPaddles() + { + for (int i = 0; i < 2; i++) + { + Display.FillRect( + new Rectangle((int)paddle[i].X, (int)paddle[i].Y, paddleWidth, paddleHeight), paddleColor); + } + } + + private void DrawBorder() + { + Color borderColor = paddleColor; + + Display.FillRect(new Rectangle(0, 0, displayWidth, borderSize), borderColor); + Display.FillRect(new Rectangle(0, 0, borderSize, displayHeight), borderColor); + Display.FillRect(new Rectangle(0, displayHeight - borderSize, displayWidth, borderSize), borderColor); + Display.FillRect(new Rectangle(displayWidth - borderSize, 0, borderSize, displayHeight), borderColor); + Display.FillRect(new Rectangle(playAreaWidth - borderSize, 0, borderSize, displayHeight), borderColor); + + } + + void Mouse_MouseMove(InputEventArgs e) + { + int deltaY = e.MousePosition.Y - displayHeight / 2; + + paddle[0].Y += deltaY; + + Mouse.Position = new Point(displayWidth / 2, displayHeight / 2); + } + } +} \ No newline at end of file Modified: trunk/Examples/Pong/Pong.csproj =================================================================== --- trunk/Examples/Pong/Pong.csproj 2009-04-16 02:19:28 UTC (rev 872) +++ trunk/Examples/Pong/Pong.csproj 2009-04-18 22:21:43 UTC (rev 873) @@ -2,7 +2,7 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.21022</ProductVersion> + <ProductVersion>9.0.30729</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{436641C4-846C-42D0-8E8F-95F70E211D22}</ProjectGuid> <OutputType>WinExe</OutputType> @@ -14,6 +14,7 @@ <OldToolsVersion>2.0</OldToolsVersion> <UpgradeBackupLocation> </UpgradeBackupLocation> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -34,6 +35,9 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> + <Reference Include="System.Core"> + <RequiredTargetFramework>3.5</RequiredTargetFramework> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="Pong.cs" /> @@ -67,6 +71,10 @@ <Project>{1AC2AEF6-2EF1-4A8B-8D2D-0480D6EDE65D}</Project> <Name>AgateDrawing</Name> </ProjectReference> + <ProjectReference Include="..\..\Drivers\AgateLib.WinForms\AgateLib.WinForms.csproj"> + <Project>{8C84DA52-0000-0000-0000-000000000000}</Project> + <Name>AgateLib.WinForms</Name> + </ProjectReference> <ProjectReference Include="..\..\drivers\AgateOTK\AgateOTK.csproj"> <Project>{B8476DD4-981E-47CD-A8C2-9E28E84A156D}</Project> <Name>AgateOTK</Name> Deleted: trunk/Examples/Pong/Program.cs =================================================================== --- trunk/Examples/Pong/Program.cs 2009-04-16 02:19:28 UTC (rev 872) +++ trunk/Examples/Pong/Program.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -1,217 +0,0 @@ -using System; -using System.Collections.Generic; -using AgateLib; -using AgateLib.DisplayLib; -using AgateLib.Geometry; -using AgateLib.InputLib; - -namespace Pong -{ - class Program - { - - /// <summary> - /// The main entry point for the application. - /// </summary> - [STAThread] - static void Main(string[] args) - { - new Program().Run(args); - } - - FontSurface font; - int[] score = new int[2]; - string[] names = new string[] { "Player", "CPU" }; - - Vector2 ball, ballvelocity; - Vector2[] paddle = new Vector2[2]; - - const int paddleHeight = 80; - const int paddleWidth = 16; - const int borderSize = paddleWidth; - const int ballSize = paddleWidth; - const int displayWidth = 600; - const int playAreaWidth = 700; - const int displayHeight = 600; - const float paddleSpeed = 150.0f; - - Color paddleColor = Color.LightGray; - Color ballColor = Color.LightGray; - - void Run(string[] args) - { - using (AgateSetup setup = new AgateSetup(args)) - { - setup.Initialize(true, false, false); - if (setup.WasCanceled) - return; - - DisplayWindow wind = DisplayWindow.CreateWindowed - ("Pong Example", displayWidth, displayHeight); - - font = new FontSurface("Sans Serif", 14); - - paddle[0] = new Vector2(50, displayHeight / 2); - paddle[1] = new Vector2(playAreaWidth - 50 - paddleWidth, displayHeight / 2); - ball = new Vector2(playAreaWidth / 2, displayHeight / 2); - ballvelocity = new Vector2(-70, 70); - - while (wind.IsClosed == false) - { - Display.BeginFrame(); - Display.Clear(Color.DarkGray); - - DrawBorder(); - DrawPaddles(); - DrawBall(); - DrawScore(); - - Display.EndFrame(); - Core.KeepAlive(); - - if (Keyboard.Keys[KeyCode.Escape]) - wind.Dispose(); - - float time_s = (float)Display.DeltaTime / 1000.0f; - - UpdatePaddles(time_s); - UpdateBall(time_s); - - } - } - } - - private void DrawScore() - { - int x = playAreaWidth + borderSize * 3 / 2; - int y = borderSize * 2; - - font.DrawText(x, y, "Score"); - - for (int i = 0; i < 2; i++) - { - y += font.StringDisplayHeight("M") * 2; - font.DrawText(x, y, names[i]); - - y += font.StringDisplayHeight("M"); - font.DrawText(x, y, score[i].ToString()); - } - } - - private void UpdateBall(float time_s) - { - bool newBall = false; - - ball += ballvelocity * time_s; - - // collision with bottom wall - if (ball.Y + ballSize > displayHeight - borderSize && ballvelocity.Y > 0) - ballvelocity.Y *= -1; - - // collision with top wall - if (ball.Y < borderSize && ballvelocity.Y < 0) - ballvelocity.Y *= -1; - - if (ball.X < borderSize) - { - newBall = true; - score[1]++; - } - else if (ball.X + ballSize > playAreaWidth) - { - newBall = true; - score[0]++; - } - - if (newBall) - { - ball = new Vector2(playAreaWidth / 2, displayHeight / 2); - ballvelocity = new Vector2(-90, 90); - } - - // check for paddles - bool increaseSpeed = false; - - if (ball.X < paddle[0].X + paddleWidth && ballvelocity.X < 0) - { - if (ball.Y + ballSize - 1 >= paddle[0].Y && - ball.Y <= paddle[0].Y + paddleHeight) - { - ballvelocity.X *= -1; - increaseSpeed = true; - } - } - if (ball.X + ballSize >= paddle[1].X && ballvelocity.X > 0) - { - if (ball.Y + ballSize - 1 >= paddle[1].Y && - ball.Y <= paddle[1].Y + paddleHeight) - { - ballvelocity.X *= -1; - increaseSpeed = true; - } - } - - if (increaseSpeed) - { - ballvelocity.X += Math.Sign(ballvelocity.X) * 10.0f; - ballvelocity.Y += Math.Sign(ballvelocity.Y) * 10.0f; - } - } - - private void UpdatePaddles(float time_s) - { - float paddleMove = paddleSpeed * time_s; - - if (Keyboard.Keys[KeyCode.Down]) paddle[0].Y += paddleMove; - if (Keyboard.Keys[KeyCode.Up]) paddle[0].Y -= paddleMove; - - // do AI - if (ballvelocity.X > 0) - { - if (ball.Y + ballSize * 2 > paddle[1].Y + paddleHeight) paddle[1].Y += paddleMove; - if (ball.Y - ballSize < paddle[1].Y) paddle[1].Y -= paddleMove; - } - - for (int i = 0; i < 2; i++) - { - paddle[i].Y = Math.Max(paddle[i].Y, borderSize); - paddle[i].Y = Math.Min(paddle[i].Y, displayHeight - borderSize - paddleHeight); - } - } - - private void DrawBall() - { - Display.FillRect(new Rectangle((int)ball.X, (int)ball.Y, ballSize, ballSize), ballColor); - } - - private void DrawPaddles() - { - for (int i = 0; i < 2; i++) - { - Display.FillRect( - new Rectangle((int)paddle[i].X, (int)paddle[i].Y, paddleWidth, paddleHeight), paddleColor); - } - } - - private void DrawBorder() - { - Color borderColor = paddleColor; - - Display.FillRect(new Rectangle(0, 0, displayWidth, borderSize), borderColor); - Display.FillRect(new Rectangle(0, 0, borderSize, displayHeight), borderColor); - Display.FillRect(new Rectangle(0, displayHeight - borderSize, displayWidth, borderSize), borderColor); - Display.FillRect(new Rectangle(displayWidth - borderSize, 0, borderSize, displayHeight), borderColor); - Display.FillRect(new Rectangle(playAreaWidth - borderSize, 0, borderSize, displayHeight), borderColor); - - } - - void Mouse_MouseMove(InputEventArgs e) - { - int deltaY = e.MousePosition.Y - displayHeight / 2; - - paddle[0].Y += deltaY; - - Mouse.Position = new Point(displayWidth / 2, displayHeight / 2); - } - } -} \ No newline at end of file Added: trunk/Examples/ShootTheTraps/App.cs =================================================================== --- trunk/Examples/ShootTheTraps/App.cs (rev 0) +++ trunk/Examples/ShootTheTraps/App.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,246 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; + +namespace ShootTheTraps +{ + class App : AgateApplication + { + /// <summary> + /// The main entry point for the application. + /// </summary> + [STAThread] + static void Main(string[] args) + { + new App().Run(args); + } + + // Game declarations + //int mDelay = 10; // time in milliseconds to wait + int mDisplayedScore = 0; + double mGameOverTime = 0; + double mLevelTime = 0; + double mBonusTime = 0; + + ShootTraps mGame; + + // graphics declaration + FontSurface mFont; + + protected override void Initialize() + { + mFont = new FontSurface("Tahoma", 16); + + Mouse.MouseDown += new InputEventHandler(Mouse_MouseDown); + + NewGame(); + } + protected override void Update(double time_ms) + { + mGame.Update(Display.DeltaTime); + UpdateDisplay(); + } + protected override void Render() + { + Display.Clear(Color.LightBlue); + + mGame.Draw(); + DrawDisplay(); + } + + void Mouse_MouseDown(InputEventArgs e) + { + if (ContinueYet) + { + NewGame(); + return; + } + if (mLevelTime != 0) + return; + if (mBonusTime != 0) + return; + + // left click + if ((e.MouseButtons & Mouse.MouseButtons.Primary) != 0) + { + mGame.FireArrow(e.MousePosition.X, e.MousePosition.Y); + } + // right click + if ((e.MouseButtons & Mouse.MouseButtons.Secondary) != 0) + { + // make sure that the score is done updating. + if (mGame.Score == mDisplayedScore) + mGame.FireTraps(); + } + } + + private void NewGame() + { + mGame = new ShootTraps(Display.RenderTarget.Width, Display.RenderTarget.Height - 50); + mDisplayedScore = 0; + mGameOverTime = 0; + + mLevelTime = Timing.TotalMilliseconds; + + if (mLevelTime == 0) + mLevelTime = 1; + } + public double GameOverTime + { + get + { + return mGameOverTime; + } + } + + private bool ContinueYet + { + get + { + if (mGame.GameOver == false) + return false; + + if (Timing.TotalMilliseconds - mGameOverTime > 5000) + return true; + else + return false; + } + } + + public void UpdateDisplay() + { + const int displayIncrement = 2; + + if (Math.Abs(mGame.Score - mDisplayedScore) < displayIncrement) + mDisplayedScore = mGame.Score; + + if (mGame.Score > mDisplayedScore) + mDisplayedScore += displayIncrement; + else if (mGame.Score < mDisplayedScore) + mDisplayedScore -= displayIncrement; + + } + public void DrawDisplay() + { + mFont.Color = Color.White; + mFont.SetScale(1, 1); + + int fontHeight = mFont.StringDisplayHeight("M"); + + Point textStart = new Point(10, Display.RenderTarget.Height - 52); + + Display.FillRect(new Rectangle(0, textStart.Y + 2, Display.RenderTarget.Width, 50), Color.Black); + + mFont.DrawText(textStart.X, textStart.Y, "Score: " + mDisplayedScore); + mFont.DrawText(textStart.X, textStart.Y + fontHeight, "Need: " + + Math.Max(0, mGame.LevelRequirement - mGame.PointsThisLevel + (mGame.Score - mDisplayedScore))); + + textStart.X = Display.RenderTarget.Width / 2; + + mFont.DrawText(textStart.X, textStart.Y, "Level: " + mGame.Level); + mFont.DrawText(textStart.X, textStart.Y + fontHeight, "Pulls Left: " + mGame.PullsLeft); + + if (mGame.Score != mDisplayedScore && mGame.AddedBonus && mGame.TrapsHit > 1) + { + if (mBonusTime == 0) + mBonusTime = Timing.TotalMilliseconds; + } + + if (mBonusTime != 0) + { + mFont.SetScale(2, 2); + + CenterText(mFont, 160, "HIT " + mGame.TrapsHit + " TRAPS", Color.White, Color.Black); + + Color bonusColor = Color.White; + + if (Timing.TotalMilliseconds % 500 < 250) + bonusColor = Color.Yellow; + + CenterText(mFont, 160 + (int)(fontHeight * mFont.ScaleHeight), "BONUS: " + mGame.BonusPoints, bonusColor, Color.Black); + + if (Timing.TotalMilliseconds - mBonusTime > 2000) + { + mBonusTime = 0; + } + } + else if (mGame.GameOver && mDisplayedScore == mGame.Score) + { + if (mGameOverTime == 0) + mGameOverTime = Timing.TotalMilliseconds; + + double deltaTime = Math.Min((Timing.TotalMilliseconds - mGameOverTime) / 3000, 1); + + double extraScaleFactor = -3 * (1.1 - Math.Pow(deltaTime, 2)); + + double scale = 3 + extraScaleFactor; + + mFont.SetScale(scale, scale); + + CenterText(mFont, (int)(200 + fontHeight - scale * fontHeight / 2.0), + "GAME OVER", Color.White, Color.Black); + + mFont.SetScale(1.5, 1.5); + + if (ContinueYet) + CenterText(mFont, 240 + (int)(fontHeight * mFont.ScaleHeight), "Click to restart", Color.White, Color.Black); + } + else if ((mGame.CanAdvanceLevel && mGame.Score == mDisplayedScore) || mLevelTime != 0) + { + if (mGame.CanAdvanceLevel) + { + mGame.NextLevel(); + mLevelTime = Timing.TotalMilliseconds; + } + + mFont.SetScale(2, 2); + + int width = Display.RenderTarget.Width; + int x = (int)(width * (1 - (Timing.TotalMilliseconds - mLevelTime) / 2300.0)); + + DrawBorderedText(mFont, x, 160, "Level " + mGame.Level, Color.White, Color.Black); + + if (Timing.TotalMilliseconds - mLevelTime > 3000) + mLevelTime = 0; + } + } + + private void CenterText(FontSurface font, int y, string text, Color color) + { + Size size = font.StringDisplaySize(text); + + int x = (Display.RenderTarget.Width - size.Width) / 2; + + font.Color = color; + font.DrawText(x, y, text); + } + private void CenterText(FontSurface font, int y, string text, Color color, Color borderColor) + { + Size size = font.StringDisplaySize(text); + + int x = (Display.RenderTarget.Width - size.Width) / 2; + + DrawBorderedText(font, x, y, text, color, borderColor); + + + } + + private static void DrawBorderedText(FontSurface font, int x, int y, string text, Color color, Color borderColor) + { + font.Color = borderColor; + font.DrawText(x + 1, y, text); + font.DrawText(x, y + 1, text); + font.DrawText(x - 1, y, text); + font.DrawText(x, y - 1, text); + + font.Color = color; + font.DrawText(x, y, text); + } + } + +} Added: trunk/Examples/ShootTheTraps/Arrow.cs =================================================================== --- trunk/Examples/ShootTheTraps/Arrow.cs (rev 0) +++ trunk/Examples/ShootTheTraps/Arrow.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace ShootTheTraps +{ + public class Arrow : GameObject + { + const int LENGTH = 10; + static int sXMax; + const int YMIN = -20; + const int YMAX = 1000; + const int XMIN = -20; + + /// <summary> + /// Allows the game engine to set how far to the right is too far for an arrow to travel. + /// </summary> + public static int XMax + { + get { return sXMax; } + set { sXMax = value; } + } + + public Arrow() + { + //acceleration.my = gravity; + } + + /// <summary> + /// Draws a short line for the arrow. + /// </summary> + public override void Draw() + { + Vector3d direction = Velocity.Normalize(); + + Display.DrawLine( + (int)Position.X, (int)Position.Y, + (int)(Position.X + direction.X * LENGTH), (int)(Position.Y + direction.Y * LENGTH), Color.Black); + } + + /// <summary> + /// Delete the arrow if it has gone outside the bounds of the screen. + /// </summary> + public override bool DeleteMe + { + get + { + if (Position.X < XMIN || Position.X > sXMax) + return true; + else if (Position.Y < YMIN || Position.Y > YMAX) + return true; + + return false; + } + } + + } + +} Added: trunk/Examples/ShootTheTraps/GameObject.cs =================================================================== --- trunk/Examples/ShootTheTraps/GameObject.cs (rev 0) +++ trunk/Examples/ShootTheTraps/GameObject.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using AgateLib; +using AgateLib.Geometry; + +namespace ShootTheTraps +{ + public abstract class GameObject + { + + /// <summary> + /// Position of the object. This is automatically updated from + /// acceleration and velocity during the call to Update(). + /// </summary> + public Vector3d Position; + /// <summary> + /// Velocity of the object. This is automatically updated from + /// acceleration during the call to Update(). + /// </summary> + public Vector3d Velocity; + /// <summary> + /// Acceleration of the object based on its position at the start + /// of this frame. The object or application is responsible for + /// updating this if it changes. */ + /// </summary> + public Vector3d Acceleration; + + public bool mDoDeleteObjects = false; + + private Vector3d mOldAcceleration; + + /// <summary> + /// The value for gravity, in pixels / second / second. + /// </summary> + public const float GRAVITY = 300; + + /// Creates a new instance of GameObject + /// </summary> + public GameObject() + { + Position = new Vector3d(); + Velocity = new Vector3d(); + Acceleration = new Vector3d(); + mOldAcceleration = new Vector3d(); + } + + /// <summary> + /// Integrates motion equations to calculate new position. + /// UpdateDisplay Acceleration before calling this. + /// </summary> + public void Update(double milliseconds) + { + double seconds = milliseconds / 1000.0; + + // here we do a velocity verlet scheme + Position += + Velocity * seconds + + mOldAcceleration * (0.5 * seconds * seconds); + + Vector3d vel2 = Velocity + mOldAcceleration * (0.5 * seconds); + Velocity = vel2 + Acceleration * (0.5 * seconds); + + mOldAcceleration = Acceleration; + } + + /// <summary> + /// Draws the object to the specified graphics context. + /// Must be overriden. + /// </summary> + public abstract void Draw(); + /// <summary> + /// Returns true if the object should be deleted. Should be overriden + /// so objects can notify the controller when they no longer need to be + /// considered. */ + /// </summary> + public virtual bool DeleteMe + { + get { return false; } + } + /// <summary> + /// Returns an array of objects to be added when this object is deleted. + /// This allows for objects to create "particle effects" or the like + /// when destroyed. + /// Returns null to add nothing. + /// </summary> + public List<GameObject> DeleteObjects() + { + if (mDoDeleteObjects == false) + return null; + else + return DeleteObjectsInternal(); + } + + /// <summary> + /// Actual implementation of DeleteObjects is done here. + /// Override this in derived classes. + /// </summary> + protected virtual List<GameObject> DeleteObjectsInternal() + { + return null; + } + } + +} \ No newline at end of file Added: trunk/Examples/ShootTheTraps/Particle.cs =================================================================== --- trunk/Examples/ShootTheTraps/Particle.cs (rev 0) +++ trunk/Examples/ShootTheTraps/Particle.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace ShootTheTraps +{ + public class Particle : GameObject + { + double mCreateTime; + Color mColor; + int alpha = 255; + + /// Creates a new instance of Particle */ + public Particle(Color clr) + { + Acceleration.Y = GRAVITY; + + mCreateTime = Timing.TotalMilliseconds; + mColor = clr; + } + + public override void Draw() + { + double now = Timing.TotalMilliseconds; + + alpha = (int)(255 * (1 - (now - mCreateTime) / 1000.0)); + if (alpha < 0) + alpha = 0; + + Display.DrawRect((int)Position.X, (int)Position.Y, 1, 1, Color.FromArgb(alpha, mColor)); + } + + public override bool DeleteMe + { + get + { + if (alpha <= 0) + return true; + else + return false; + } + } + } + +} Added: trunk/Examples/ShootTheTraps/Properties/AssemblyInfo.cs =================================================================== --- trunk/Examples/ShootTheTraps/Properties/AssemblyInfo.cs (rev 0) +++ trunk/Examples/ShootTheTraps/Properties/AssemblyInfo.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShootTheTraps")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShootTheTraps")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("86a6b13c-3e20-482d-adca-8cd48c0a52b2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Added: trunk/Examples/ShootTheTraps/ShootTheTraps.csproj =================================================================== --- trunk/Examples/ShootTheTraps/ShootTheTraps.csproj (rev 0) +++ trunk/Examples/ShootTheTraps/ShootTheTraps.csproj 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,78 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>9.0.30729</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{50743D1B-A19E-42F1-842F-65FAD6D168C3}</ProjectGuid> + <OutputType>WinExe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>ShootTheTraps</RootNamespace> + <AssemblyName>ShootTheTraps</AssemblyName> + <FileUpgradeFlags> + </FileUpgradeFlags> + <OldToolsVersion>2.0</OldToolsVersion> + <UpgradeBackupLocation> + </UpgradeBackupLocation> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core"> + <RequiredTargetFramework>3.5</RequiredTargetFramework> + </Reference> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="App.cs" /> + <Compile Include="Arrow.cs" /> + <Compile Include="GameObject.cs" /> + <Compile Include="Particle.cs" /> + <Compile Include="ShootTraps.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Trap.cs" /> + <Compile Include="Vector.cs"> + <SubType>Code</SubType> + </Compile> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\AgateLib\AgateLib.csproj"> + <Project>{198C4842-0000-0000-0000-000000000000}</Project> + <Name>AgateLib</Name> + </ProjectReference> + <ProjectReference Include="..\..\Drivers\AgateLib.WinForms\AgateLib.WinForms.csproj"> + <Project>{8C84DA52-0000-0000-0000-000000000000}</Project> + <Name>AgateLib.WinForms</Name> + </ProjectReference> + <ProjectReference Include="..\..\Drivers\AgateOTK\AgateOTK.csproj"> + <Project>{CAB8A0C1-0000-0000-0000-000000000000}</Project> + <Name>AgateOTK</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: trunk/Examples/ShootTheTraps/ShootTraps.cs =================================================================== --- trunk/Examples/ShootTheTraps/ShootTraps.cs (rev 0) +++ trunk/Examples/ShootTheTraps/ShootTraps.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,369 @@ +using System; +using System.Collections.Generic; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.InputLib; + +namespace ShootTheTraps +{ + + public class ShootTraps + { + List<GameObject> mGameObjects; + Random mRandom; + + readonly int yvalue; + readonly int halfx; + readonly int yvelScale; + readonly int xvelScale; + + readonly int xpos; + readonly int ypos; + + const int ARROWSPEED = 800; + const int MAXARROWS = 4; + + private int mScore; + + int[] mXVals; + + int mLevel = 0; + int mPullsLeft = 0; + int mTrapsHit = 0; + int mBonusPoints = 0; + int mPointsThisLevel = 0; + + + bool mGameOver = false; + bool mBonusDone = false; + bool mCanAdvanceLevel = true; + + /// <summary> + /// Creates a new instance of ShootTraps + /// </summary> + /// <param name="width"></param> + /// <param name="height"></param> + public ShootTraps(int width, int height) + { + if (width <= 0 || height <= 0) throw new ArgumentOutOfRangeException(); + + mGameObjects = new List<GameObject>(); + mRandom = new Random(); + + halfx = width / 2; + yvalue = height - 10; + yvelScale = (int)Math.Sqrt(2 * Trap.GRAVITY * (height - 10)); + xvelScale = (int)width / 2; + + xpos = halfx; + ypos = yvalue - 5; + + + mXVals = new int[4]; + + mXVals[0] = 10; + mXVals[1] = 40; + + mXVals[2] = 2 * halfx - mXVals[1]; + mXVals[3] = 2 * halfx - mXVals[0]; + + //this.width = width; + //this.height = height; + + Arrow.XMax = width + 10; + + } + + private void AddScore(int points) + { + mScore += points; + mPointsThisLevel += points; + } + public void NextLevel() + { + if (mCanAdvanceLevel == false) + return; + + mCanAdvanceLevel = false; + + mLevel++; + mPullsLeft = Math.Min(12 + 2 * mLevel, 21); + + mPointsThisLevel = 0; + } + + public void Update(double milliseconds) + { + UpdateAllObjects(milliseconds); + CheckForCollisions(); + + CalcBonus(); + + DeleteObjects(); + } + public void Draw() + { + foreach (GameObject obj in mGameObjects) + { + obj.Draw(); + } + + } + + private void DeleteObjects() + { + for (int i = 0; i < mGameObjects.Count; i++) + { + if (mGameObjects[i].DeleteMe) + { + List<GameObject> extras = mGameObjects[i].DeleteObjects(); + + mGameObjects.RemoveAt(i--); + + if (extras != null) + mGameObjects.AddRange(extras); + } + } + } + + private void CalcBonus() + { + if (TrapCount != 0) + return; + if (mBonusDone) + return; + + mBonusDone = true; + mBonusPoints = 0; + + if (mTrapsHit > 1) + mBonusPoints = 250 * (mTrapsHit - 1); + + AddScore(mBonusPoints); + + // check for game over conditions + if (mPullsLeft == 0) + { + if (mPointsThisLevel >= LevelRequirement) + mCanAdvanceLevel = true; + else + mGameOver = true; + } + } + + private void CheckForCollisions() + { + + // check for collisions + foreach (GameObject obj in mGameObjects) + { + if (!(obj is Arrow)) + continue; + + Arrow ar = (Arrow)obj; + + foreach (GameObject t in mGameObjects) + { + if (!(t is Trap)) + continue; + + Trap trap = (Trap)t; + + if (trap.ContainsPoint(ar.Position) && trap.DeleteMe == false) + { + trap.SetDeleteMeFlag(); + trap.mDoDeleteObjects = true; + + mTrapsHit++; + + int score = 50; + + if (trap.Color == Color.White) + score = 100; + + AddScore(score); + } + } + } + } + + private void UpdateAllObjects(double milliseconds) + { + foreach (GameObject obj in mGameObjects) + { + obj.Update(milliseconds); + } + } + + + + public void FireArrow(int towardsX, int towardsY) + { + if (ArrowCount >= MAXARROWS) + return; + if (mGameOver) + return; + + Vector3d direction = new Vector3d(towardsX - xpos, towardsY - ypos, 0).Normalize(); + + if (direction.Y > 0) + { + direction.Y = 0; + + if (direction.X == 0) + direction.X = 1; + + direction = direction.Normalize(); + } + + Arrow ar = new Arrow(); + + ar.Position.X = xpos; + ar.Position.Y = ypos; + + ar.Velocity.X = direction.X * ARROWSPEED; + ar.Velocity.Y = direction.Y * ARROWSPEED; + + mGameObjects.Add(ar); + } + + public void FireTraps() + { + if (mGameObjects.Count > 0) + return; + if (mGameOver) + return; + if (mPullsLeft <= 0) + return; + + mPullsLeft--; + mBonusDone = false; + mTrapsHit = 0; + mBonusPoints = 0; + + int maxTraps = mLevel / 2 + 2; + if (maxTraps > 8) + maxTraps = 8; + + int r = mRandom.Next(maxTraps) + 1; + + if (mPullsLeft == 0) + r = maxTraps; + + for (int i = 0; i < r; i++) + { + Trap t = new Trap(); + + int xpos = mRandom.Next(mXVals.Length); + + t.Position.X = mXVals[xpos]; + t.Position.Y = yvalue; + + t.FinalY = yvalue + 50; + + t.Velocity.X = 10 + mRandom.Next(xvelScale - 10); + t.Velocity.Y = -yvelScale * (1 - mRandom.Next(50) / 200.0); + + if (t.Position.X > halfx) + t.Velocity.X *= -1; + + mGameObjects.Add(t); + } + + } + + public int ArrowCount + { + get + { + int result = 0; + + foreach (GameObject obj in mGameObjects) + { + if (obj is Arrow) + result++; + } + + return result; + } + } + + public int TrapCount + { + get + { + return mGameObjects.Count - ArrowCount; + } + } + + public bool CanAdvanceLevel + { + get + { + return mCanAdvanceLevel; + } + } + public bool GameOver + { + get + { + return mGameOver; + } + } + public int Level + { + get + { + return mLevel; + } + } + public int PullsLeft + { + get + { + return mPullsLeft; + } + } + public int TrapsHit + { + get + { + return mTrapsHit; + } + } + public bool AddedBonus + { + get + { + return mBonusDone; + } + } + public int BonusPoints + { + get + { + return mBonusPoints; + } + } + public int LevelRequirement + { + get + { + return 1000 * mLevel; + } + } + public int PointsThisLevel + { + get { return mPointsThisLevel; } + set { mPointsThisLevel = value; } + } + + public int Score + { + get { return mScore; } + set { mScore = value; } + } + } + +} \ No newline at end of file Added: trunk/Examples/ShootTheTraps/Trap.cs =================================================================== --- trunk/Examples/ShootTheTraps/Trap.cs (rev 0) +++ trunk/Examples/ShootTheTraps/Trap.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; + +namespace ShootTheTraps +{ + public class Trap : GameObject + { + const int width = 14; + const int height = 8; + int mFinalY = 0; + Color mColor = Color.Red; + + bool delete = false; + + static Random sRandom; + static Color[] sColors = { Color.White, Color.Blue, Color.Red, Color.Purple, Color.Yellow, + Color.Green }; + + /// Creates a new instance of Trap */ + public Trap() + { + if (sRandom == null) + sRandom = new Random(); + + // only gravity affects this object. + Acceleration = new Vector3d(0, GRAVITY, 0); + + mColor = sColors[sRandom.Next(sColors.Length)]; + } + + /// <summary> + /// The highest (low on screen) value that the trap can get before it + /// should be deleted. + /// </summary> + public int FinalY + { + get { return mFinalY; } + set { mFinalY = value; } + } + + public void SetDeleteMeFlag() + { + delete = true; + } + + public bool ContainsPoint(Vector3d pt) + { + Vector3d dist = Position - pt; + + // formula for oval + dist.X /= width; + dist.Y /= height; + + if (dist.Magnitude <= 1) + return true; + else + return false; + } + + public override void Draw() + { + Display.FillRect((int)Position.X - width / 2, (int)Position.Y - height / 2, width, height, Color); + + if (Position.Y > mFinalY && Velocity.Y > 0) + delete = true; + else + delete = false; + } + + public override bool DeleteMe + { + get + { + return delete; + } + } + + public Color Color + { + get { return mColor; } + set { mColor = value; } + } + + const int NUMPARTICLES = 20; + const double particleSpeed = 100; + + protected override List<GameObject> DeleteObjectsInternal() + { + List<GameObject> retval = new List<GameObject>(); + Vector3d totalVelocity = new Vector3d(0, 0, 0); + + for (int i = 0; i < NUMPARTICLES; i++) + { + Particle p = new Particle(Color); + + p.Position = Position; + + p.Velocity.X = sRandom.NextDouble() * 2 - 1; + p.Velocity.Y = sRandom.NextDouble() * 2 - 1; + + p.Velocity = p.Velocity.Normalize() * (sRandom.NextDouble() * particleSpeed); + + totalVelocity = totalVelocity + p.Velocity; + retval.Add(p); + } + + // now apply conservation of momentum, by giving a small portion + // of the excess momentum to each particle + Vector3d give = totalVelocity * (-1.0 / NUMPARTICLES); + + for (int i = 0; i < NUMPARTICLES; i++) + { + Particle p = (Particle)retval[i]; + + p.Velocity = p.Velocity + Velocity + give; + } + + + return retval; + } + + } +} \ No newline at end of file Added: trunk/Examples/ShootTheTraps/Vector.cs =================================================================== --- trunk/Examples/ShootTheTraps/Vector.cs (rev 0) +++ trunk/Examples/ShootTheTraps/Vector.cs 2009-04-18 22:21:43 UTC (rev 873) @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ShootTheTraps +{ + public struct Vector3d + { + public double mX, mY, mZ; + + public double X + { + get { return mX; } + set { mX = value; } + } + + + public double Y + { + get { return mY; } + set { mY = value; } + } + + public double Z + { + get { return mZ; } + set { mZ = value; } + } + + public Vector3d(double _x, double _y, double _z) + { + mX = _x; + mY = _y; + mZ = _z; + } + public Vector3d(int _x, int _y, int _z) + { + mX = (double)_x; + mY = (double)_y; + mZ = (double)_z; + } + + public Vector3d(Vector3d copy) + { + mX = copy.mX; + mY = copy.mY; + mZ = copy.mZ; + } + + public static Vector3d operator *(Vector3d a, double scaleFactor) + { + Vector3d result = new Vector3d(a); + + result.mX *= scaleFactor; + result.mY *= scaleFactor; + result.mZ *= scaleFactor; + + return result; + } + public static Vector3d operator +(Vector3d a, Vector3d b) + { + Vector3d result = new Vector3d(a); + + result.mX += b.mX; + result.mY += b.mY; + result.mZ += b.mZ; + + return result; + } + public static Vector3d operator -(Vector3d a, Vector3d b) + { + Vector3d result = new Vector3d(a); + + result.mX -= b.mX; + result.mY -= b.mY; + result.mZ -= b.mZ; + + return result; + + } + + public double MagnitudeSquared + { + get + { + return mX * mX + mY * mY + mZ * mZ; + } + } + public double Magnitude + { + get + { + return Math.Sqrt(MagnitudeSquared); + } + } + + public Vector3d Normalize() + { + double mag = Magnitude; + + return new Vector3d(mX / mag, mY / mag, mZ / mag); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-16 02:19:30
|
Revision: 872 http://agate.svn.sourceforge.net/agate/?rev=872&view=rev Author: kanato Date: 2009-04-16 02:19:28 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Add basic sprite tester. Added Paths: ----------- trunk/Tests/Data/boxsprite.png trunk/Tests/DisplayTests/BasicSprite.cs Added: trunk/Tests/Data/boxsprite.png =================================================================== (Binary files differ) Property changes on: trunk/Tests/Data/boxsprite.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Tests/DisplayTests/BasicSprite.cs =================================================================== --- trunk/Tests/DisplayTests/BasicSprite.cs (rev 0) +++ trunk/Tests/DisplayTests/BasicSprite.cs 2009-04-16 02:19:28 UTC (rev 872) @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib; +using AgateLib.DisplayLib; +using AgateLib.Geometry; +using AgateLib.Sprites; + +namespace Tests.DisplayTests +{ + class BasicSprite : AgateApplication, IAgateTest + { + #region IAgateTest Members + + public string Name + { + get { return "Basic Sprite"; } + } + + public string Category + { + get { return "Display"; } + } + + public void Main(string[] args) + { + Run(args); + } + + #endregion + + Sprite p; + + protected override void Initialize() + { + p = new Sprite("Data/boxsprite.png", new Size(96,96)); + p.AnimationType = SpriteAnimType.PingPong; + p.TimePerFrame = 250; + p.StartAnimation(); + } + + protected override void Update(double time_ms) + { + p.Update(time_ms); + } + protected override void Render() + { + Display.Clear(Color.Blue); + + p.Draw(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-16 01:24:27
|
Revision: 871 http://agate.svn.sourceforge.net/agate/?rev=871&view=rev Author: kanato Date: 2009-04-16 01:24:21 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Fixed two sprite bugs: 1. Frames would not be carved if the source surface was exactly the right size 2. Sprites with only one frame would sometimes crash. Modified Paths: -------------- trunk/AgateLib/Sprites/Sprite.cs Modified: trunk/AgateLib/Sprites/Sprite.cs =================================================================== --- trunk/AgateLib/Sprites/Sprite.cs 2009-04-15 07:23:30 UTC (rev 870) +++ trunk/AgateLib/Sprites/Sprite.cs 2009-04-16 01:24:21 UTC (rev 871) @@ -363,7 +363,7 @@ location.Y += size.Height; } - } while (location.Y + size.Height < surface.SurfaceHeight); + } while (location.Y + size.Height <= surface.SurfaceHeight); } @@ -756,7 +756,7 @@ get { return mCurrentFrameIndex; } set { - if (mFrames.Count == 0) + if (mFrames.Count <= 1) { mCurrentFrameIndex = 0; return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 07:23:30
|
Revision: 870 http://agate.svn.sourceforge.net/agate/?rev=870&view=rev Author: kanato Date: 2009-04-15 07:23:30 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Fix build issues with sprite interface move. Modified Paths: -------------- trunk/AgateLib/Sprites/ISprite.cs trunk/AgateLib/Sprites/ISpriteFrame.cs Modified: trunk/AgateLib/Sprites/ISprite.cs =================================================================== --- trunk/AgateLib/Sprites/ISprite.cs 2009-04-15 07:22:33 UTC (rev 869) +++ trunk/AgateLib/Sprites/ISprite.cs 2009-04-15 07:23:30 UTC (rev 870) @@ -18,6 +18,7 @@ // using System; using System.Collections.Generic; +using AgateLib.DisplayLib; using AgateLib.Geometry; namespace AgateLib.Sprites Modified: trunk/AgateLib/Sprites/ISpriteFrame.cs =================================================================== --- trunk/AgateLib/Sprites/ISpriteFrame.cs 2009-04-15 07:22:33 UTC (rev 869) +++ trunk/AgateLib/Sprites/ISpriteFrame.cs 2009-04-15 07:23:30 UTC (rev 870) @@ -17,6 +17,7 @@ // Contributor(s): Erik Ylvisaker // using System; +using AgateLib.DisplayLib; using AgateLib.Geometry; namespace AgateLib.Sprites This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 07:22:49
|
Revision: 869 http://agate.svn.sourceforge.net/agate/?rev=869&view=rev Author: kanato Date: 2009-04-15 07:22:33 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Update namespaces for sprite interfaces. Modified Paths: -------------- trunk/AgateLib/Sprites/ISprite.cs trunk/AgateLib/Sprites/ISpriteFrame.cs Modified: trunk/AgateLib/Sprites/ISprite.cs =================================================================== --- trunk/AgateLib/Sprites/ISprite.cs 2009-04-15 07:21:14 UTC (rev 868) +++ trunk/AgateLib/Sprites/ISprite.cs 2009-04-15 07:22:33 UTC (rev 869) @@ -18,11 +18,10 @@ // using System; using System.Collections.Generic; +using AgateLib.Geometry; -namespace AgateLib.DisplayLib +namespace AgateLib.Sprites { - using Geometry; - /// <summary> /// Basic interface implemented by different sprite classes. /// </summary> Modified: trunk/AgateLib/Sprites/ISpriteFrame.cs =================================================================== --- trunk/AgateLib/Sprites/ISpriteFrame.cs 2009-04-15 07:21:14 UTC (rev 868) +++ trunk/AgateLib/Sprites/ISpriteFrame.cs 2009-04-15 07:22:33 UTC (rev 869) @@ -17,11 +17,10 @@ // Contributor(s): Erik Ylvisaker // using System; +using AgateLib.Geometry; -namespace AgateLib.DisplayLib +namespace AgateLib.Sprites { - using Geometry; - /// <summary> /// Basic interface implemented by a particular frame in a sprite. /// </summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 07:21:20
|
Revision: 868 http://agate.svn.sourceforge.net/agate/?rev=868&view=rev Author: kanato Date: 2009-04-15 07:21:14 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Update changelog. Modified Paths: -------------- trunk/ChangeLog.txt Modified: trunk/ChangeLog.txt =================================================================== --- trunk/ChangeLog.txt 2009-04-15 07:20:01 UTC (rev 867) +++ trunk/ChangeLog.txt 2009-04-15 07:21:14 UTC (rev 868) @@ -1,3 +1,6 @@ +Version 0.3.2 +=================== +Moved ISprite and ISpriteFrame to Sprites namespace. Version 0.3.1 =================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 07:20:03
|
Revision: 867 http://agate.svn.sourceforge.net/agate/?rev=867&view=rev Author: kanato Date: 2009-04-15 07:20:01 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Moved ISprite and ISpriteFrame to Sprites folder & namespace. Added Paths: ----------- trunk/AgateLib/Sprites/ISprite.cs trunk/AgateLib/Sprites/ISpriteFrame.cs Removed Paths: ------------- trunk/AgateLib/DisplayLib/ISprite.cs trunk/AgateLib/DisplayLib/ISpriteFrame.cs Deleted: trunk/AgateLib/DisplayLib/ISprite.cs =================================================================== --- trunk/AgateLib/DisplayLib/ISprite.cs 2009-04-15 06:53:54 UTC (rev 866) +++ trunk/AgateLib/DisplayLib/ISprite.cs 2009-04-15 07:20:01 UTC (rev 867) @@ -1,173 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; -using System.Collections.Generic; - -namespace AgateLib.DisplayLib -{ - using Geometry; - - /// <summary> - /// Basic interface implemented by different sprite classes. - /// </summary> - public interface ISprite : ISurface, IDisposable - { - /// <summary> - /// Shows the next frame in the sequence. This pays attention - /// to whether the animation is playing forwards or reverse. - /// </summary> - void AdvanceFrame(); - - /// <summary> - /// Updates the animation of the sprite, using the DeltaTime given - /// by the Display object. - /// </summary> - void Update(); - /// <summary> - /// Updates the animation of the sprite, using the given frame time. - /// </summary> - /// <param name="time_ms">The amount of time to consider passed, in milliseconds.</param> - void Update(double time_ms); - - /// <summary> - /// Gets or sets an enum value indicating what type of animation is happening. - /// Looping - The animation will play from beginning to end and then restart. - /// PingPong - The animation will play from beginning to end and then from end to beginning (continuously). - /// Once - The animation plays once, and then shows its first frame. - /// OnceHoldLast - The animation plays once, and leaves the last frame on. - /// </summary> - SpriteAnimType AnimationType { get; set; } - /// <summary> - /// Gets the currently displaying frame. - /// </summary> - ISpriteFrame CurrentFrame { get; } - /// <summary> - /// The index of the current frame. - /// </summary> - int CurrentFrameIndex { get; set; } - /// <summary> - /// Gets or sets a flag which indicates: - /// True if the animation is running. - /// False if a single frame will be shown indefinitely. - /// </summary> - bool IsAnimating { get; set; } - /// <summary> - /// Gets or sets a flag which indicates whether or not this animation plays in - /// reverse instead. - /// </summary> - bool PlayReverse { get; set; } - - /// <summary> - /// Gets height of the sprite. - /// </summary> - int SpriteHeight { get; } - /// <summary> - /// Gets the size of the sprite. - /// </summary> - Size SpriteSize { get; } - /// <summary> - /// Gets width of the sprite. - /// </summary> - int SpriteWidth { get; } - /// <summary> - /// Restarts the animation. - /// </summary> - void StartAnimation(); - - /// <summary> - /// Gets the list of SpriteFrame objects in this sprite. - /// </summary> - Sprites.IFrameList Frames { get; } - - /// <summary> - /// The amount of time each frame should display, in milliseconds. - /// </summary> - double TimePerFrame { get; set; } - /// <summary> - /// If Visible is set to false, all calls to Draw overloads are ignored. - /// </summary> - bool Visible { get; set; } - - - /// <summary> - /// Event which is raised when the animation is started. - /// </summary> - event SpriteEventHandler AnimationStarted; - - /// <summary> - /// Event which is raised when the animation is stopped. - /// </summary> - event SpriteEventHandler AnimationStopped; - /// <summary> - /// Event which is raised when the play direction is changed, as - /// in the PingPong type. - /// </summary> - event SpriteEventHandler PlayDirectionChanged; - } - - /// <summary> - /// Event handler type for sprite events. - /// </summary> - /// <param name="caller"></param> - public delegate void SpriteEventHandler(ISprite caller); - - /// <summary> - /// Enum indicating the different types of automatic animation that - /// take place. - /// </summary> - public enum SpriteAnimType - { - /// <summary> - /// Specifies that the sprite animation should go from - /// frame 0 to the end, and start back at frame 0 to repeat. - /// </summary> - Looping, - /// <summary> - /// Specifies that the sprite animation should go from - /// frame 0 to the end, and then go back down to frame 0. This - /// cycle repeats indefinitely. - /// </summary> - PingPong, - /// <summary> - /// Specifies that the sprite animation should go from - /// frame 0 to the end and stop, but show frame 0 once the animation - /// is finished. - /// </summary> - Once, - /// <summary> - /// Specifies that the sprite animation should go from - /// frame 0 to the end and stop there, with the last frame - /// shown. - /// </summary> - OnceHoldLast, - /// <summary> - /// Specifies that the sprite animation should go from - /// frame 0 to the end, and then disappear. The Visible - /// property of the Sprite object is set to false once - /// the animation is complete. - /// </summary> - OnceDisappear, - - /// <summary> - /// Specifies that the sprite animation should go twice. - /// </summary> - Twice, - } - -} Deleted: trunk/AgateLib/DisplayLib/ISpriteFrame.cs =================================================================== --- trunk/AgateLib/DisplayLib/ISpriteFrame.cs 2009-04-15 06:53:54 UTC (rev 866) +++ trunk/AgateLib/DisplayLib/ISpriteFrame.cs 2009-04-15 07:20:01 UTC (rev 867) @@ -1,49 +0,0 @@ -// The contents of this file are subject to the Mozilla Public License -// Version 1.1 (the "License"); you may not use this file except in -// compliance with the License. You may obtain a copy of the License at -// http://www.mozilla.org/MPL/ -// -// Software distributed under the License is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// The Original Code is AgateLib. -// -// The Initial Developer of the Original Code is Erik Ylvisaker. -// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. -// All Rights Reserved. -// -// Contributor(s): Erik Ylvisaker -// -using System; - -namespace AgateLib.DisplayLib -{ - using Geometry; - - /// <summary> - /// Basic interface implemented by a particular frame in a sprite. - /// </summary> - public interface ISpriteFrame - { - /// <summary> - /// Draws the frame. - /// </summary> - /// <param name="dest_x"></param> - /// <param name="dest_y"></param> - /// <param name="rotationCenterX"></param> - /// <param name="rotationCenterY"></param> - void Draw(float dest_x, float dest_y, float rotationCenterX, float rotationCenterY); - - /// <summary> - /// Gets the surface object the frame is drawn from - /// </summary> - Surface Surface { get; } - - /// <summary> - /// Gets the source rectangle on the surface the frame is drawn from. - /// </summary> - Rectangle SourceRect { get; } - } -} Added: trunk/AgateLib/Sprites/ISprite.cs =================================================================== --- trunk/AgateLib/Sprites/ISprite.cs (rev 0) +++ trunk/AgateLib/Sprites/ISprite.cs 2009-04-15 07:20:01 UTC (rev 867) @@ -0,0 +1,173 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; +using System.Collections.Generic; + +namespace AgateLib.DisplayLib +{ + using Geometry; + + /// <summary> + /// Basic interface implemented by different sprite classes. + /// </summary> + public interface ISprite : ISurface, IDisposable + { + /// <summary> + /// Shows the next frame in the sequence. This pays attention + /// to whether the animation is playing forwards or reverse. + /// </summary> + void AdvanceFrame(); + + /// <summary> + /// Updates the animation of the sprite, using the DeltaTime given + /// by the Display object. + /// </summary> + void Update(); + /// <summary> + /// Updates the animation of the sprite, using the given frame time. + /// </summary> + /// <param name="time_ms">The amount of time to consider passed, in milliseconds.</param> + void Update(double time_ms); + + /// <summary> + /// Gets or sets an enum value indicating what type of animation is happening. + /// Looping - The animation will play from beginning to end and then restart. + /// PingPong - The animation will play from beginning to end and then from end to beginning (continuously). + /// Once - The animation plays once, and then shows its first frame. + /// OnceHoldLast - The animation plays once, and leaves the last frame on. + /// </summary> + SpriteAnimType AnimationType { get; set; } + /// <summary> + /// Gets the currently displaying frame. + /// </summary> + ISpriteFrame CurrentFrame { get; } + /// <summary> + /// The index of the current frame. + /// </summary> + int CurrentFrameIndex { get; set; } + /// <summary> + /// Gets or sets a flag which indicates: + /// True if the animation is running. + /// False if a single frame will be shown indefinitely. + /// </summary> + bool IsAnimating { get; set; } + /// <summary> + /// Gets or sets a flag which indicates whether or not this animation plays in + /// reverse instead. + /// </summary> + bool PlayReverse { get; set; } + + /// <summary> + /// Gets height of the sprite. + /// </summary> + int SpriteHeight { get; } + /// <summary> + /// Gets the size of the sprite. + /// </summary> + Size SpriteSize { get; } + /// <summary> + /// Gets width of the sprite. + /// </summary> + int SpriteWidth { get; } + /// <summary> + /// Restarts the animation. + /// </summary> + void StartAnimation(); + + /// <summary> + /// Gets the list of SpriteFrame objects in this sprite. + /// </summary> + Sprites.IFrameList Frames { get; } + + /// <summary> + /// The amount of time each frame should display, in milliseconds. + /// </summary> + double TimePerFrame { get; set; } + /// <summary> + /// If Visible is set to false, all calls to Draw overloads are ignored. + /// </summary> + bool Visible { get; set; } + + + /// <summary> + /// Event which is raised when the animation is started. + /// </summary> + event SpriteEventHandler AnimationStarted; + + /// <summary> + /// Event which is raised when the animation is stopped. + /// </summary> + event SpriteEventHandler AnimationStopped; + /// <summary> + /// Event which is raised when the play direction is changed, as + /// in the PingPong type. + /// </summary> + event SpriteEventHandler PlayDirectionChanged; + } + + /// <summary> + /// Event handler type for sprite events. + /// </summary> + /// <param name="caller"></param> + public delegate void SpriteEventHandler(ISprite caller); + + /// <summary> + /// Enum indicating the different types of automatic animation that + /// take place. + /// </summary> + public enum SpriteAnimType + { + /// <summary> + /// Specifies that the sprite animation should go from + /// frame 0 to the end, and start back at frame 0 to repeat. + /// </summary> + Looping, + /// <summary> + /// Specifies that the sprite animation should go from + /// frame 0 to the end, and then go back down to frame 0. This + /// cycle repeats indefinitely. + /// </summary> + PingPong, + /// <summary> + /// Specifies that the sprite animation should go from + /// frame 0 to the end and stop, but show frame 0 once the animation + /// is finished. + /// </summary> + Once, + /// <summary> + /// Specifies that the sprite animation should go from + /// frame 0 to the end and stop there, with the last frame + /// shown. + /// </summary> + OnceHoldLast, + /// <summary> + /// Specifies that the sprite animation should go from + /// frame 0 to the end, and then disappear. The Visible + /// property of the Sprite object is set to false once + /// the animation is complete. + /// </summary> + OnceDisappear, + + /// <summary> + /// Specifies that the sprite animation should go twice. + /// </summary> + Twice, + } + +} Added: trunk/AgateLib/Sprites/ISpriteFrame.cs =================================================================== --- trunk/AgateLib/Sprites/ISpriteFrame.cs (rev 0) +++ trunk/AgateLib/Sprites/ISpriteFrame.cs 2009-04-15 07:20:01 UTC (rev 867) @@ -0,0 +1,49 @@ +// The contents of this file are subject to the Mozilla Public License +// Version 1.1 (the "License"); you may not use this file except in +// compliance with the License. You may obtain a copy of the License at +// http://www.mozilla.org/MPL/ +// +// Software distributed under the License is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// The Original Code is AgateLib. +// +// The Initial Developer of the Original Code is Erik Ylvisaker. +// Portions created by Erik Ylvisaker are Copyright (C) 2006-2009. +// All Rights Reserved. +// +// Contributor(s): Erik Ylvisaker +// +using System; + +namespace AgateLib.DisplayLib +{ + using Geometry; + + /// <summary> + /// Basic interface implemented by a particular frame in a sprite. + /// </summary> + public interface ISpriteFrame + { + /// <summary> + /// Draws the frame. + /// </summary> + /// <param name="dest_x"></param> + /// <param name="dest_y"></param> + /// <param name="rotationCenterX"></param> + /// <param name="rotationCenterY"></param> + void Draw(float dest_x, float dest_y, float rotationCenterX, float rotationCenterY); + + /// <summary> + /// Gets the surface object the frame is drawn from + /// </summary> + Surface Surface { get; } + + /// <summary> + /// Gets the source rectangle on the surface the frame is drawn from. + /// </summary> + Rectangle SourceRect { get; } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 06:54:00
|
Revision: 866 http://agate.svn.sourceforge.net/agate/?rev=866&view=rev Author: kanato Date: 2009-04-15 06:53:54 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Rename FontSurfaceState to FontState. Add missing Cache/FontStateCache.cs from previous commit. Added Paths: ----------- branches/font/AgateLib/DisplayLib/Cache/ branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs branches/font/AgateLib/DisplayLib/FontState.cs Added: branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs =================================================================== --- branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs (rev 0) +++ branches/font/AgateLib/DisplayLib/Cache/FontStateCache.cs 2009-04-15 06:53:54 UTC (rev 866) @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AgateLib.DisplayLib.Cache +{ + public abstract class FontStateCache + { + protected internal abstract FontStateCache Clone(); + + protected internal virtual void OnTextChanged(FontState fontState) + { + } + protected internal virtual void OnLocationChanged(FontState fontState) + { + } + protected internal virtual void OnDisplayAlignmentChanged(FontState fontState) + { + } + protected internal virtual void OnColorChanged(FontState fontState) + { + } + protected internal virtual void OnScaleChanged(FontState fontState) + { + } + } +} Added: branches/font/AgateLib/DisplayLib/FontState.cs =================================================================== --- branches/font/AgateLib/DisplayLib/FontState.cs (rev 0) +++ branches/font/AgateLib/DisplayLib/FontState.cs 2009-04-15 06:53:54 UTC (rev 866) @@ -0,0 +1,163 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.Geometry; +using AgateLib.DisplayLib.Cache; + +namespace AgateLib.DisplayLib +{ + public class FontState : ICloneable + { + private OriginAlignment mAlignment = OriginAlignment.TopLeft; + private Color mColor = Color.White; + private double mScaleWidth = 1.0; + private double mScaleHeight = 1.0; + private PointF mLocation; + private string mText; + private FontStateCache mCache; + + /// <summary> + /// Gets or sets the text that is displayed when drawn. + /// </summary> + public string Text + { + get { return mText; } + set + { + mText = value; + + if (Cache != null) + Cache.OnTextChanged(this); + } + } + /// <summary> + /// Gets or sets the location where text is drawn. + /// </summary> + public PointF Location + { + get { return mLocation; } + set + { + mLocation = value; + + if (Cache != null) + Cache.OnLocationChanged(this); + } + } + /// <summary> + /// Sets how to interpret the point given to DrawText methods. + /// </summary> + public OriginAlignment DisplayAlignment + { + get { return mAlignment; } + set + { + mAlignment = value; + + if (Cache != null) + Cache.OnDisplayAlignmentChanged(this); + } + } + /// <summary> + /// Sets the color of the text to be drawn. + /// </summary> + public Color Color + { + get { return mColor; } + set + { + mColor = value; + + if (Cache != null) + Cache.OnColorChanged(this); + } + } + /// <summary> + /// Sets the alpha value of the text to be drawn. + /// </summary> + public double Alpha + { + get { return mColor.A / 255.0; } + set + { + if (value < 0) value = 0; + if (value > 1.0) value = 1.0; + + mColor = Color.FromArgb((int)(value * 255), mColor); + + if (Cache != null) + Cache.OnColorChanged(this); + } + } + /// <summary> + /// Gets or sets the amount the width is scaled when the text is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleWidth + { + get { return mScaleWidth; } + set + { + mScaleWidth = value; + + if (Cache != null) + Cache.OnScaleChanged(this); + } + } + /// <summary> + /// Gets or sets the amount the height is scaled when the text is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleHeight + { + get { return mScaleHeight; } + set + { + mScaleHeight = value; + + if (Cache != null) + Cache.OnScaleChanged(this); + } + } + /// <summary> + /// This value is used by the implementation to optimize rendering this state object. + /// Do not set this value unless you know what you are doing, or writing an implementation + /// of FontSurfaceImpl. + /// </summary> + public FontStateCache Cache + { + get { return mCache; } + set { mCache = value; } + } + + #region --- ICloneable Members --- + + public FontState Clone() + { + FontState retval = new FontState(); + + retval.mAlignment = mAlignment; + retval.mColor = mColor; + retval.mScaleWidth = mScaleWidth; + retval.mScaleHeight = mScaleHeight; + retval.mLocation = mLocation; + retval.mText = mText; + + if (mCache != null) + { + retval.mCache = mCache.Clone(); + } + + return retval; + } + + object ICloneable.Clone() + { + return Clone(); + } + + #endregion + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 06:39:46
|
Revision: 865 http://agate.svn.sourceforge.net/agate/?rev=865&view=rev Author: kanato Date: 2009-04-15 06:39:44 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Simplified FontSurfaceImpl class so implementations are easier. FontSurface drawing is entirely based around FontState object now. Modified Paths: -------------- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs branches/font/AgateLib/DisplayLib/FontSurface.cs branches/font/AgateLib/ImplementationBase/FontSurfaceImpl.cs branches/font/Drivers/AgateDrawing/Drawing_FontSurface.cs branches/font/Drivers/AgateMDX/MDX1_FontSurface.cs Modified: branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs =================================================================== --- branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-15 04:44:43 UTC (rev 864) +++ branches/font/AgateLib/BitmapFont/BitmapFontImpl.cs 2009-04-15 06:39:44 UTC (rev 865) @@ -25,376 +25,355 @@ using AgateLib.Geometry; using AgateLib.ImplementationBase; using AgateLib.Resources; +using AgateLib.DisplayLib.Cache; namespace AgateLib.BitmapFont { - /// <summary> - /// Provides a basic implementation for the use of non-system fonts provided - /// as a bitmap. - /// - /// To construct a bitmap font, call the appropriate static FontSurface method. - /// </summary> - public class BitmapFontImpl : FontSurfaceImpl - { - Surface mSurface; + /// <summary> + /// Provides a basic implementation for the use of non-system fonts provided + /// as a bitmap. + /// + /// To construct a bitmap font, call the appropriate static FontSurface method. + /// </summary> + public class BitmapFontImpl : FontSurfaceImpl + { + Surface mSurface; - FontMetrics mFontMetrics; + FontMetrics mFontMetrics; - int mCharHeight; - double mAverageCharWidth; + int mCharHeight; + double mAverageCharWidth; - /// <summary> - /// Constructs a BitmapFontImpl, assuming the characters in the given file - /// are all the same size, and are in their ASCII order. - /// </summary> - /// <param name="filename"></param> - /// <param name="characterSize"></param> - public BitmapFontImpl(string filename, Size characterSize) - { - mFontMetrics = new FontMetrics(); + #region --- Cache Class --- - mSurface = new Surface(filename); - mCharHeight = characterSize.Height; + class BitmapFontCache : FontStateCache + { + public bool NeedsRefresh = true; + public RectangleF[] SrcRects; + public RectangleF[] DestRects; + public int DisplayTextLength; - ExtractMonoSpaceAsciiFont(characterSize); - } + protected internal override FontStateCache Clone() + { + BitmapFontCache cache = new BitmapFontCache(); - /// <summary> - /// Constructs a BitmapFontImpl, taking the passed surface as the source for - /// the characters. The source rectangles for each character are passed in. - /// </summary> - /// <param name="surface">Surface which contains the image data for the font glyphs.</param> - /// <param name="fontMetrics">FontMetrics structure which describes how characters - /// are laid out.</param> - public BitmapFontImpl(Surface surface, FontMetrics fontMetrics) - { - mFontMetrics = (FontMetrics) ((ICloneable)fontMetrics).Clone(); - float maxHeight = 0; + cache.SrcRects = (RectangleF[])SrcRects.Clone(); + cache.DestRects = (RectangleF[])DestRects.Clone(); - foreach (KeyValuePair<char, GlyphMetrics> kvp in mFontMetrics) - { - if (kvp.Value.SourceRect.Height > maxHeight) - maxHeight = kvp.Value.SourceRect.Height; - } + return cache; + } - mCharHeight = (int)Math.Ceiling(maxHeight); - mSurface = surface; - } + protected internal override void OnTextChanged(FontState fontState) + { + NeedsRefresh = true; + } + protected internal override void OnDisplayAlignmentChanged(FontState fontState) + { + NeedsRefresh = true; + } + protected internal override void OnLocationChanged(FontState fontState) + { + NeedsRefresh = true; + } + } - /// <summary> - /// Disposes of the object. - /// </summary> - public override void Dispose() - { - mSurface.Dispose(); - } - /// <summary> - /// Gets the font metric information. - /// </summary> - /// <returns></returns> - public FontMetrics FontMetrics - { - get { return mFontMetrics; } - } - /// <summary> - /// Gets the surface containing the glyphs. - /// </summary> - /// <returns></returns> - public Surface Surface - { - get { return mSurface; } - } + #endregion - private void ExtractMonoSpaceAsciiFont(Size characterSize) - { - int x = 0; - int y = 0; - char val = '\0'; + /// <summary> + /// Constructs a BitmapFontImpl, assuming the characters in the given file + /// are all the same size, and are in their ASCII order. + /// </summary> + /// <param name="filename"></param> + /// <param name="characterSize"></param> + public BitmapFontImpl(string filename, Size characterSize) + { + mFontMetrics = new FontMetrics(); - while (y + characterSize.Height <= mSurface.SurfaceHeight) - { - Rectangle src = new Rectangle(x, y, characterSize.Width, characterSize.Height); + mSurface = new Surface(filename); + mCharHeight = characterSize.Height; - mFontMetrics[val] = new GlyphMetrics(src); + ExtractMonoSpaceAsciiFont(characterSize); + } - val++; - x += characterSize.Width; + /// <summary> + /// Constructs a BitmapFontImpl, taking the passed surface as the source for + /// the characters. The source rectangles for each character are passed in. + /// </summary> + /// <param name="surface">Surface which contains the image data for the font glyphs.</param> + /// <param name="fontMetrics">FontMetrics structure which describes how characters + /// are laid out.</param> + public BitmapFontImpl(Surface surface, FontMetrics fontMetrics) + { + mFontMetrics = (FontMetrics)((ICloneable)fontMetrics).Clone(); + float maxHeight = 0; - if (x + characterSize.Width > mSurface.SurfaceWidth) - { - y += characterSize.Height; - x = 0; - } - } + foreach (KeyValuePair<char, GlyphMetrics> kvp in mFontMetrics) + { + if (kvp.Value.SourceRect.Height > maxHeight) + maxHeight = kvp.Value.SourceRect.Height; + } - CalcAverageCharWidth(); - } + mCharHeight = (int)Math.Ceiling(maxHeight); + mSurface = surface; + } - private void CalcAverageCharWidth() - { - double total = 0; - int count = 0; + /// <summary> + /// Disposes of the object. + /// </summary> + public override void Dispose() + { + mSurface.Dispose(); + } + /// <summary> + /// Gets the font metric information. + /// </summary> + /// <returns></returns> + public FontMetrics FontMetrics + { + get { return mFontMetrics; } + } + /// <summary> + /// Gets the surface containing the glyphs. + /// </summary> + /// <returns></returns> + public Surface Surface + { + get { return mSurface; } + } - foreach (GlyphMetrics glyph in mFontMetrics.Values) - { - total += glyph.SourceRect.Width; - count++; - } + private void ExtractMonoSpaceAsciiFont(Size characterSize) + { + int x = 0; + int y = 0; + char val = '\0'; - mAverageCharWidth = total / (double)count; - } + while (y + characterSize.Height <= mSurface.SurfaceHeight) + { + Rectangle src = new Rectangle(x, y, characterSize.Width, characterSize.Height); - /// <summary> - /// Overrides the base Color method to catch color changes to set them on the surface. - /// </summary> - public override Color Color - { - get - { - return base.Color; - } - set - { - base.Color = value; + mFontMetrics[val] = new GlyphMetrics(src); - mSurface.Color = value; - } - } - /// <summary> - /// Measures the width of the text. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public override int StringDisplayWidth(string text) - { - if (string.IsNullOrEmpty(text)) - return 0; + val++; + x += characterSize.Width; - double highestLineWidth = 0; + if (x + characterSize.Width > mSurface.SurfaceWidth) + { + y += characterSize.Height; + x = 0; + } + } - string[] lines = text.Split('\n'); + CalcAverageCharWidth(); + } - for (int i = 0; i < lines.Length; i++) - { - string line = lines[i]; - double lineWidth = 0; + private void CalcAverageCharWidth() + { + double total = 0; + int count = 0; - for (int j = 0; j < line.Length; j++) - { - lineWidth += mFontMetrics[line[j]].Width; - } + foreach (GlyphMetrics glyph in mFontMetrics.Values) + { + total += glyph.SourceRect.Width; + count++; + } - if (lineWidth > highestLineWidth) - highestLineWidth = lineWidth; + mAverageCharWidth = total / (double)count; + } - } + public override Size StringDisplaySize(FontState state, string text) + { + if (string.IsNullOrEmpty(text)) + return Size.Empty; - return (int)Math.Ceiling(highestLineWidth * ScaleWidth); - } - /// <summary> - /// Measures the height of the text - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public override int StringDisplayHeight(string text) - { - if (string.IsNullOrEmpty(text)) - return 0; + int CRcount = 0; + int i = 0; + double highestLineWidth = 0; - int CRcount = 0; - int i = 0; + // measure width + string[] lines = text.Split('\n'); + for (i = 0; i < lines.Length; i++) + { + string line = lines[i]; + double lineWidth = 0; - do - { - i = text.IndexOf('\n', i + 1); + for (int j = 0; j < line.Length; j++) + { + lineWidth += mFontMetrics[line[j]].Width; + } - if (i == -1) - break; + if (lineWidth > highestLineWidth) + highestLineWidth = lineWidth; + } - CRcount++; + // measure height + do + { + i = text.IndexOf('\n', i + 1); - } while (i != -1); + if (i == -1) + break; - if (text[text.Length - 1] == '\n') - CRcount--; + CRcount++; - return (int)(mCharHeight * (CRcount + 1) * ScaleHeight); - } - /// <summary> - /// Measures the size of the text. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public override Size StringDisplaySize(string text) - { - return new Size(StringDisplayWidth(text), StringDisplayHeight(text)); - } + } while (i != -1); - /// <summary> - /// Returns the height of characters in the font. - /// </summary> - public override int FontHeight - { - get { return mCharHeight; } - } + if (text[text.Length - 1] == '\n') + CRcount--; - private void GetRects(string text, RectangleF[] srcRects, RectangleF[] destRects, out int rectCount) - { - double destX = 0; - double destY = 0; - int height = mCharHeight; + return new Size((int)Math.Ceiling(highestLineWidth * state.ScaleWidth), + (int)(mCharHeight * (CRcount + 1) * state.ScaleHeight)); + } - rectCount = 0; + /// <summary> + /// Returns the height of characters in the font. + /// </summary> + public override int FontHeight + { + get { return mCharHeight; } + } - for (int i = 0; i < text.Length; i++) - { - switch (text[i]) - { - case '\r': - // ignore '\r' characters that are followed by '\n', because - // the line break on Windows is these two characters in succession. - if (i + 1 < text.Length && text[i + 1] == '\n') - { - break; - } + private void GetRects(RectangleF[] srcRects, RectangleF[] destRects, out int rectCount, + string text, double ScaleHeight, double ScaleWidth) + { + double destX = 0; + double destY = 0; + int height = mCharHeight; - // this '\r' is not followed by a '\n', so treat it like any other character. - goto default; + rectCount = 0; - case '\n': - destX = 0; - destY += height * this.ScaleHeight; - break; + for (int i = 0; i < text.Length; i++) + { + switch (text[i]) + { + case '\r': + // ignore '\r' characters that are followed by '\n', because + // the line break on Windows is these two characters in succession. + if (i + 1 < text.Length && text[i + 1] == '\n') + { + break; + } - default: - GlyphMetrics glyph = mFontMetrics[text[i]]; + // this '\r' is not followed by a '\n', so treat it like any other character. + goto default; - destX = Math.Max(0, destX - glyph.LeftOverhang * ScaleWidth); + case '\n': + destX = 0; + destY += height * ScaleHeight; + break; - srcRects[rectCount] = new RectangleF( - glyph.SourceRect.X, glyph.SourceRect.Y, - glyph.SourceRect.Width, glyph.SourceRect.Height); + default: + GlyphMetrics glyph = mFontMetrics[text[i]]; - destRects[rectCount] = new RectangleF((float)destX, (float)destY, - (float)(srcRects[rectCount].Width * ScaleWidth), - (float)(srcRects[rectCount].Height * ScaleHeight)); + destX = Math.Max(0, destX - glyph.LeftOverhang * ScaleWidth); - destX += destRects[rectCount].Width - glyph.RightOverhang * ScaleWidth; + srcRects[rectCount] = new RectangleF( + glyph.SourceRect.X, glyph.SourceRect.Y, + glyph.SourceRect.Width, glyph.SourceRect.Height); - rectCount++; - break; - } - } - } + destRects[rectCount] = new RectangleF((float)destX, (float)destY, + (float)(srcRects[rectCount].Width * ScaleWidth), + (float)(srcRects[rectCount].Height * ScaleHeight)); - RectangleF[] cacheSrcRects; - RectangleF[] cacheDestRects; + destX += destRects[rectCount].Width - glyph.RightOverhang * ScaleWidth; - /// <summary> - /// Draws the text to the screen. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public override void DrawText(int destX, int destY, string text) - { - if (string.IsNullOrEmpty(text)) - return; + rectCount++; + break; + } + } + } - if (cacheSrcRects == null || text.Length > cacheSrcRects.Length) - { - cacheSrcRects = new RectangleF[text.Length]; - cacheDestRects = new RectangleF[text.Length]; - } + private static BitmapFontCache GetCache(FontState state) + { + BitmapFontCache cache = state.Cache as BitmapFontCache; - RectangleF[] srcRects = cacheSrcRects; - RectangleF[] destRects = cacheDestRects; + if (cache == null) + { + cache = new BitmapFontCache(); + state.Cache = cache; + } - DrawTextImpl(destX, destY, text, srcRects, destRects); - } + if (cache.SrcRects == null || + cache.SrcRects.Length < state.Text.Length) + { + cache.SrcRects = new RectangleF[state.Text.Length]; + cache.DestRects = new RectangleF[state.Text.Length]; + } - private void DrawTextImpl(int destX, int destY, string text, - RectangleF[] srcRects, RectangleF[] destRects) - { - // this variable counts the number of rectangles actually used to display text. - // It may be less then text.Length because carriage return characters - // don't need any rects. - int displayTextLength; - GetRects(text, srcRects, destRects, out displayTextLength); + return cache; + } - if (DisplayAlignment != OriginAlignment.TopLeft) - { - Point value = Origin.Calc(DisplayAlignment, StringDisplaySize(text)); + /// <summary> + /// Draws the text to the screen. + /// </summary> + /// <param name="state"></param> + public override void DrawText(FontState state) + { + BitmapFontCache cache = GetCache(state); - destX -= value.X; - destY -= value.Y; - } + RefreshCache(state, cache); - for (int i = 0; i < displayTextLength; i++) - { - destRects[i].X += destX; - destRects[i].Y += destY; - } + mSurface.Color = state.Color; + mSurface.DrawRects(cache.SrcRects, cache.DestRects, 0, cache.DisplayTextLength); + } - mSurface.DrawRects(srcRects, destRects, 0, displayTextLength); - } + private void RefreshCache(FontState state, BitmapFontCache cache) + { - /// <summary> - /// Draws the text to the screen. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public override void DrawText(double destX, double destY, string text) - { - DrawText((int)destX, (int)destY, text); - } + if (cache.NeedsRefresh) + { + // this variable counts the number of rectangles actually used to display text. + // It may be less then text.Length because carriage return characters + // don't need any rects. + GetRects(cache.SrcRects, cache.DestRects, out cache.DisplayTextLength, + state.Text, state.ScaleHeight, state.ScaleWidth); - /// <summary> - /// Draws the text to the screen. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public override void DrawText(Point destPt, string text) - { - DrawText(destPt.X, destPt.Y, text); - } + PointF dest = state.Location; - /// <summary> - /// Draws the text to the screen. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public override void DrawText(PointF destPt, string text) - { - DrawText(destPt.X, destPt.Y, text); - } - - } + if (state.DisplayAlignment != OriginAlignment.TopLeft) + { + Point value = Origin.Calc(state.DisplayAlignment, + StringDisplaySize(state, state.Text)); - /// <summary> - /// Enum which indicates how pixels along glyph edges are processed. - /// </summary> - public enum BitmapFontEdgeOptions - { - /// <summary> - /// Calculates the intensity of the pixel, and sets the pixel to white - /// with an alpha value equal to its intensity. - /// </summary> - IntensityAlphaWhite, + dest.X -= value.X; + dest.Y -= value.Y; + } - /// <summary> - /// Preserves the color of the pixel, and sets the alpha to the intensity of - /// the pixel. - /// </summary> - IntensityAlphaColor, + for (int i = 0; i < cache.DisplayTextLength; i++) + { + cache.DestRects[i].X += dest.X; + cache.DestRects[i].Y += dest.Y; + } - /// <summary> - /// Performs no processing on edges and leaves them as is. - /// Note that this will result in edges which are not at all transparent. - /// </summary> - None, - } + cache.NeedsRefresh = false; + } + } + } + + /// <summary> + /// Enum which indicates how pixels along glyph edges are processed. + /// </summary> + public enum BitmapFontEdgeOptions + { + /// <summary> + /// Calculates the intensity of the pixel, and sets the pixel to white + /// with an alpha value equal to its intensity. + /// </summary> + IntensityAlphaWhite, + + /// <summary> + /// Preserves the color of the pixel, and sets the alpha to the intensity of + /// the pixel. + /// </summary> + IntensityAlphaColor, + + /// <summary> + /// Performs no processing on edges and leaves them as is. + /// Note that this will result in edges which are not at all transparent. + /// </summary> + None, + } + + } \ No newline at end of file Modified: branches/font/AgateLib/DisplayLib/FontSurface.cs =================================================================== --- branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-15 04:44:43 UTC (rev 864) +++ branches/font/AgateLib/DisplayLib/FontSurface.cs 2009-04-15 06:39:44 UTC (rev 865) @@ -28,452 +28,494 @@ namespace AgateLib.DisplayLib { - /// <summary> - /// Enumeration which allows selection of font styles when creating - /// a font from the OS. This enum has the FlagsAttribute, so its members - /// can be combined in a bitwise fashion. - /// </summary> - [Flags] - public enum FontStyle - { - /// <summary> - /// No style is applied. - /// </summary> - None = 0, - /// <summary> - /// Make the font bold. - /// </summary> - Bold = 1, - /// <summary> - /// Use italics. - /// </summary> - Italic = 2, - /// <summary> - /// Strikeout through the font glyphs. - /// </summary> - Strikeout = 4, - /// <summary> - /// Underline beneath the glyphs. - /// </summary> - Underline = 8, - } + /// <summary> + /// Enumeration which allows selection of font styles when creating + /// a font from the OS. This enum has the FlagsAttribute, so its members + /// can be combined in a bitwise fashion. + /// </summary> + [Flags] + public enum FontStyle + { + /// <summary> + /// No style is applied. + /// </summary> + None = 0, + /// <summary> + /// Make the font bold. + /// </summary> + Bold = 1, + /// <summary> + /// Use italics. + /// </summary> + Italic = 2, + /// <summary> + /// Strikeout through the font glyphs. + /// </summary> + Strikeout = 4, + /// <summary> + /// Underline beneath the glyphs. + /// </summary> + Underline = 8, + } - /// <summary> - /// Class which represents a font to draw on the screen. - /// <remarks>When creating a FontSurface, if you are going to be - /// scaling the font, it usually looks much better to make a large font - /// and scale it to a smaller size, rather than vice-versa.</remarks> - /// </summary> - public sealed class FontSurface : IDisposable - { - internal FontSurfaceImpl impl; - private StringTransformer mTransformer = StringTransformer.None; + /// <summary> + /// Class which represents a font to draw on the screen. + /// <remarks>When creating a FontSurface, if you are going to be + /// scaling the font, it usually looks much better to make a large font + /// and scale it to a smaller size, rather than vice-versa.</remarks> + /// </summary> + public sealed class FontSurface : IDisposable + { + internal FontSurfaceImpl impl; + private StringTransformer mTransformer = StringTransformer.None; + FontState mState = new FontState(); - /// <summary> - /// Creates a FontSurface object from the given fontFamily. - /// </summary> - /// <param name="fontFamily"></param> - /// <param name="sizeInPoints"></param> - public FontSurface(string fontFamily, float sizeInPoints) - : this(fontFamily, sizeInPoints, FontStyle.None) - { } + /// <summary> + /// Creates a FontSurface object from the given fontFamily. + /// </summary> + /// <param name="fontFamily"></param> + /// <param name="sizeInPoints"></param> + public FontSurface(string fontFamily, float sizeInPoints) + : this(fontFamily, sizeInPoints, FontStyle.None) + { } - /// <summary> - /// Creates a FontSurface object from the given fontFamily. - /// </summary> - /// <param name="fontFamily"></param> - /// <param name="sizeInPoints"></param> - /// <param name="style"></param> - public FontSurface(string fontFamily, float sizeInPoints, FontStyle style) - { - if (sizeInPoints < 1) - throw new ArgumentOutOfRangeException("Font size must be positive and non-zero, but was " + - sizeInPoints.ToString() + "."); + /// <summary> + /// Creates a FontSurface object from the given fontFamily. + /// </summary> + /// <param name="fontFamily"></param> + /// <param name="sizeInPoints"></param> + /// <param name="style"></param> + public FontSurface(string fontFamily, float sizeInPoints, FontStyle style) + { + if (sizeInPoints < 1) + throw new ArgumentOutOfRangeException("Font size must be positive and non-zero, but was " + + sizeInPoints.ToString() + "."); - impl = Display.Impl.CreateFont(fontFamily, sizeInPoints, style); + impl = Display.Impl.CreateFont(fontFamily, sizeInPoints, style); - Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); - } - /// <summary> - /// Constructs a FontSurface object from a resource. - /// </summary> - /// <param name="resources"></param> - /// <param name="resourceName"></param> - public FontSurface(AgateResourceCollection resources, string resourceName) - { - AgateResource res = resources[resourceName]; - BitmapFontResource bmpFont = res as BitmapFontResource; + Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); + } + /// <summary> + /// Constructs a FontSurface object from a resource. + /// </summary> + /// <param name="resources"></param> + /// <param name="resourceName"></param> + public FontSurface(AgateResourceCollection resources, string resourceName) + { + AgateResource res = resources[resourceName]; + BitmapFontResource bmpFont = res as BitmapFontResource; - if (res is BitmapFontResource) - { - Surface surf = new Surface(bmpFont.Image); + if (res is BitmapFontResource) + { + Surface surf = new Surface(bmpFont.Image); - impl = new BitmapFontImpl(surf, bmpFont.FontMetrics); - } - else - throw new AgateResourceException(string.Format( - "The resource {0} is of type {1} which cannot be used to construct a font.", - resourceName, res.GetType().Name)); - } - /// <summary> - /// Creates a bitmap font using the options passed in. The Display driver - /// must be capable of this, which is indicated in Display.Caps.CanCreateBitmapFont. - /// </summary> - /// <param name="bitmapOptions"></param> - public FontSurface(BitmapFontOptions bitmapOptions) - { - impl = Display.Impl.CreateFont(bitmapOptions); + impl = new BitmapFontImpl(surf, bmpFont.FontMetrics); + } + else + throw new AgateResourceException(string.Format( + "The resource {0} is of type {1} which cannot be used to construct a font.", + resourceName, res.GetType().Name)); + } + /// <summary> + /// Creates a bitmap font using the options passed in. The Display driver + /// must be capable of this, which is indicated in Display.Caps.CanCreateBitmapFont. + /// </summary> + /// <param name="bitmapOptions"></param> + public FontSurface(BitmapFontOptions bitmapOptions) + { + impl = Display.Impl.CreateFont(bitmapOptions); - Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); - } + Display.DisposeDisplay += new Display.DisposeDisplayHandler(Dispose); + } - /// <summary> - /// Private initializer to tell it what impl to use. - /// </summary> - /// <param name="implToUse"></param> - private FontSurface(FontSurfaceImpl implToUse) - { - impl = implToUse; - } + /// <summary> + /// Private initializer to tell it what impl to use. + /// </summary> + /// <param name="implToUse"></param> + private FontSurface(FontSurfaceImpl implToUse) + { + impl = implToUse; + } - /// <summary> - /// Returns the implementation object. - /// </summary> - public FontSurfaceImpl Impl - { - get { return impl; } - } - /// <summary> - /// This function loads a monospace bitmap font from the specified image file. - /// Only the character size is given. It is assumed that all ASCII characters - /// from 0 to 255 are present, in order from left to right, and top to bottom. - /// </summary> - /// <remarks> - /// [Experimental - The API is likely to change in the future.] - /// </remarks> - /// <param name="filename"></param> - /// <param name="characterSize"></param> - /// <returns></returns> - public static FontSurface BitmapMonospace(string filename, Size characterSize) - { - FontSurfaceImpl impl = new BitmapFontImpl(filename, characterSize); + /// <summary> + /// Returns the implementation object. + /// </summary> + public FontSurfaceImpl Impl + { + get { return impl; } + } + /// <summary> + /// This function loads a monospace bitmap font from the specified image file. + /// Only the character size is given. It is assumed that all ASCII characters + /// from 0 to 255 are present, in order from left to right, and top to bottom. + /// </summary> + /// <remarks> + /// [Experimental - The API is likely to change in the future.] + /// </remarks> + /// <param name="filename"></param> + /// <param name="characterSize"></param> + /// <returns></returns> + public static FontSurface BitmapMonospace(string filename, Size characterSize) + { + FontSurfaceImpl impl = new BitmapFontImpl(filename, characterSize); - return new FontSurface(impl); - } + return new FontSurface(impl); + } - /// <summary> - /// Disposes of this object. - /// </summary> - public void Dispose() - { - if (impl != null) - impl.Dispose(); + /// <summary> + /// Disposes of this object. + /// </summary> + public void Dispose() + { + if (impl != null) + impl.Dispose(); - impl = null; - } + impl = null; + } - /// <summary> - /// Gets or sets how strings are transformed when they are drawn to the screen. - /// This is useful for bitmap fonts which contain only all uppercase letters, for - /// example. - /// </summary> - public StringTransformer StringTransformer - { - get { return mTransformer; } - set - { - mTransformer = value; + /// <summary> + /// Gets or sets how strings are transformed when they are drawn to the screen. + /// This is useful for bitmap fonts which contain only all uppercase letters, for + /// example. + /// </summary> + public StringTransformer StringTransformer + { + get { return mTransformer; } + set + { + mTransformer = value; - if (value == null) - mTransformer = StringTransformer.None; - } - } + if (value == null) + mTransformer = StringTransformer.None; + } + } - /// <summary> - /// Sets the interpretation of the draw point used. - /// </summary> - public OriginAlignment DisplayAlignment - { - get { return impl.DisplayAlignment; } - set { impl.DisplayAlignment = value; } - } - /// <summary> - /// Sets the color of the font. - /// </summary> - public Color Color - { - get { return impl.Color; } - set { impl.Color = value; } - } - /// <summary> - /// Sets the transparency of the font. - /// 0.0 is fully transparent - /// 1.0 is completely opaque. - /// </summary> - public double Alpha - { - get { return impl.Alpha; } - set { impl.Alpha = value; } - } + /// <summary> + /// Gets or sets the state of the font object. + /// </summary> + public FontState State + { + get { return mState; } + set + { + if (value == null) + throw new ArgumentNullException("Cannot set state to a null value. If you wish to reset the state, set it to a new FontState object."); - /// <summary> - /// Sets the scale of the font. - /// </summary> - /// <param name="x"></param> - /// <param name="y"></param> - public void SetScale(double x, double y) - { - impl.SetScale(x, y); - } - /// <summary> - /// Gets the scale of the font. - /// </summary> - /// <param name="x"></param> - /// <param name="y"></param> - public void GetScale(out double x, out double y) - { - impl.GetScale(out x, out y); - } - /// <summary> - /// Gets or sets the amount the width is scaled when the text is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleWidth - { - get { return impl.ScaleWidth; } - set { impl.ScaleWidth = value; } - } - /// <summary> - /// Gets or sets the amount the height is scaled when the text is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleHeight - { - get { return impl.ScaleHeight; } - set { impl.ScaleHeight = value; } - } + mState = value; + } + } + /// <summary> + /// Sets how to interpret the point given to DrawText methods. + /// </summary> + public OriginAlignment DisplayAlignment + { + get { return mState.DisplayAlignment; } + set { mState.DisplayAlignment = value; } + } + /// <summary> + /// Sets the color of the text to be drawn. + /// </summary> + public Color Color + { + get { return mState.Color; } + set { mState.Color = value; } + } + /// <summary> + /// Sets the alpha value of the text to be drawn. + /// </summary> + public double Alpha + { + get { return mState.Alpha; } + set { mState.Alpha = value; } + } + /// <summary> + /// Gets or sets the amount the width is scaled when the text is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleWidth + { + get { return mState.ScaleWidth; } + set { mState.ScaleWidth = value; } + } + /// <summary> + /// Gets or sets the amount the height is scaled when the text is drawn. + /// 1.0 is no scaling. + /// </summary> + public double ScaleHeight + { + get { return mState.ScaleHeight; } + set { mState.ScaleHeight = value; } + } + /// <summary> + /// Sets ScaleWidth and ScaleHeight. + /// </summary> + /// <param name="x"></param> + /// <param name="y"></param> + public void SetScale(double x, double y) + { + ScaleWidth = x; + ScaleHeight = y; + } + /// <summary> + /// Gets ScaleWidth and ScaleHeight. + /// </summary> + /// <param name="x"></param> + /// <param name="y"></param> + public void GetScale(out double x, out double y) + { + x = ScaleWidth; + y = ScaleHeight; + } - /// <summary> - /// Measures the display width of the specified string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public int StringDisplayWidth(string text) { return impl.StringDisplayWidth(text); } - /// <summary> - /// Measures the display height of the specified string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public int StringDisplayHeight(string text) { return impl.StringDisplayHeight(text); } - /// <summary> - /// Measures the display size of the specified string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public Size StringDisplaySize(string text) { return impl.StringDisplaySize(text); } - - /// <summary> - /// Gets the height in pixels of a single line of text. - /// </summary> - public int FontHeight - { - get { return impl.FontHeight; } - } + /// <summary> + /// Measures the display width of the specified string. + /// </summary> + /// <param name="text"></param> + /// <returns></returns> + public int StringDisplayWidth(string text) + { + return StringDisplaySize(text).Width; + } + /// <summary> + /// Measures the display height of the specified string. + /// </summary> + /// <param name="text"></param> + /// <returns></returns> + public int StringDisplayHeight(string text) + { + return StringDisplaySize(text).Height; + } + /// <summary> + /// Measures the display size of the specified string. + /// </summary> + /// <param name="text"></param> + /// <returns></returns> + public Size StringDisplaySize(string text) + { + return impl.StringDisplaySize(mState, text); + } - public TextImageLayout TextImageLayout { get; set; } + /// <summary> + /// Gets the height in pixels of a single line of text. + /// </summary> + public int FontHeight + { + get { return impl.FontHeight; } + } - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public void DrawText(int destX, int destY, string text) - { - impl.DrawText(destX, destY, mTransformer.Transform(text)); - } - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public void DrawText(double destX, double destY, string text) - { - impl.DrawText(destX, destY, mTransformer.Transform(text)); - } - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public void DrawText(Point destPt, string text) - { - impl.DrawText(destPt.X, destPt.Y, mTransformer.Transform(text)); - } - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public void DrawText(PointF destPt, string text) - { - impl.DrawText(destPt.X, destPt.Y, mTransformer.Transform(text)); - } - /// <summary> - /// Draws the specified string at the origin. - /// </summary> - /// <param name="text"></param> - public void DrawText(string text) - { - impl.DrawText(0, 0, mTransformer.Transform(text)); - } + public TextImageLayout TextImageLayout { get; set; } + /// <summary> + /// Draws the specified string at the specified location. + /// </summary> + /// <param name="destX"></param> + /// <param name="destY"></param> + /// <param name="text"></param> + public void DrawText(int destX, int destY, string text) + { + mState.Location = new PointF(destX, destY); + mState.Text = mTransformer.Transform(text); - Regex substituteMatch = new Regex(@"\{[0-9]+(:.*)?\}|\r\n|\n"); - Regex indexMatch = new Regex(@"[0-9]+"); - - public void DrawText(int destX, int destY, string formatString, params object[] args) - { - var matches = substituteMatch.Matches(formatString); + DrawText(mState); + } + /// <summary> + /// Draws the specified string at the specified location. + /// </summary> + /// <param name="destX"></param> + /// <param name="destY"></param> + /// <param name="text"></param> + public void DrawText(double destX, double destY, string text) + { + mState.Location = new PointF((float)destX, (float)destY); + mState.Text = mTransformer.Transform(text); - if (matches.Count == 0) - { - DrawText(destX, destY, formatString); - return; - } + DrawText(mState); + } + /// <summary> + /// Draws the specified string at the specified location. + /// </summary> + /// <param name="destPt"></param> + /// <param name="text"></param> + public void DrawText(Point destPt, string text) + { + mState.Location = new PointF(destPt.X, destPt.Y); + mState.Text = mTransformer.Transform(text); - int lastIndex = 0; - string result = string.Empty; - Point dest; + DrawText(mState); + } + /// <summary> + /// Draws the specified string at the specified location. + /// </summary> + /// <param name="destPt"></param> + /// <param name="text"></param> + public void DrawText(PointF destPt, string text) + { + mState.Location = destPt; + mState.Text = mTransformer.Transform(text); - dest = Point.Empty; + DrawText(mState); + } + /// <summary> + /// Draws the specified string at the origin. + /// </summary> + /// <param name="text"></param> + public void DrawText(string text) + { + mState.Location = PointF.Empty; + mState.Text = mTransformer.Transform(text); - TextLayout layout = new TextLayout(); - int lineHeight = FontHeight; - int spaceAboveLine = 0; - int lineIndex = 0; + DrawText(mState); + } - for (int i = 0; i < matches.Count; i++) - { - string format = formatString.Substring(matches[i].Index, matches[i].Length); + public void DrawText(FontState state) + { + impl.DrawText(state); + } - result += formatString.Substring(lastIndex, matches[i].Index - lastIndex); + Regex substituteMatch = new Regex(@"\{[0-9]+(:.*)?\}|\r\n|\n"); + Regex indexMatch = new Regex(@"[0-9]+"); - if (format == "\r\n" || format == "\n") - { - PushLayoutText(lineIndex, layout, ref dest, result); - result = string.Empty; + public void DrawText(int destX, int destY, string formatString, params object[] args) + { + var matches = substituteMatch.Matches(formatString); - ShiftLine(layout, spaceAboveLine, lineIndex); + if (matches.Count == 0) + { + DrawText(destX, destY, formatString); + return; + } - dest.X = 0; - dest.Y += lineHeight; - - lineIndex++; - lineHeight = FontHeight; + int lastIndex = 0; + string result = string.Empty; + Point dest; - spaceAboveLine = 0; - } - else - { - var argsIndexText = indexMatch.Match(format); - int argsIndex = int.Parse(argsIndexText.ToString()); + dest = Point.Empty; - object obj = args[argsIndex]; + TextLayout layout = new TextLayout(); + int lineHeight = FontHeight; + int spaceAboveLine = 0; + int lineIndex = 0; - if (obj is ISurface) - { - PushLayoutText(lineIndex, layout, ref dest, result); - PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine, (ISurface)obj); - result = string.Empty; - } - else - { - result += ConvertToString(obj, format); - } - } - lastIndex = matches[i].Index + matches[i].Length; - } + for (int i = 0; i < matches.Count; i++) + { + string format = formatString.Substring(matches[i].Index, matches[i].Length); - result += formatString.Substring(lastIndex); - PushLayoutText(lineIndex, layout, ref dest, result); - ShiftLine(layout, spaceAboveLine, lineIndex); + result += formatString.Substring(lastIndex, matches[i].Index - lastIndex); - layout.Translate(new Point(destX, destY)); - layout.DrawAll(); - } + if (format == "\r\n" || format == "\n") + { + PushLayoutText(lineIndex, layout, ref dest, result); + result = string.Empty; - private static void ShiftLine(TextLayout layout, int lineShift, int lineIndex) - { - foreach (var item in layout.Where(x => x.LineIndex == lineIndex)) - { - item.Location = new Point( - item.Location.X, item.Location.Y + lineShift); - } - } + ShiftLine(layout, spaceAboveLine, lineIndex); - private void PushLayoutImage(int lineIndex, TextLayout layout, ref Point dest, ref int lineHeight, - ref int spaceAboveLine, ISurface surface) - { - int newSpaceAbove; - LayoutSurface t = new LayoutSurface { Location = dest, Surface = surface, LineIndex = lineIndex }; - t.State = surface.State.Clone(); + dest.X = 0; + dest.Y += lineHeight; - var update = Origin.Calc(DisplayAlignment, surface.SurfaceSize); + lineIndex++; + lineHeight = FontHeight; - lineHeight = Math.Max(lineHeight, surface.DisplayHeight); - dest.X += surface.DisplayWidth; - - switch (TextImageLayout) - { - case TextImageLayout.InlineTop: - break; - case TextImageLayout.InlineCenter: - newSpaceAbove = (surface.DisplayHeight - FontHeight) / 2; - t.Y -= newSpaceAbove; - spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove); - - break; + spaceAboveLine = 0; + } + else + { + var argsIndexText = indexMatch.Match(format); + int argsIndex = int.Parse(argsIndexText.ToString()); - case TextImageLayout.InlineBottom: - newSpaceAbove = surface.DisplayHeight - FontHeight; - t.Y -= newSpaceAbove; - spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove); + object obj = args[argsIndex]; - break; - } + if (obj is ISurface) + { + PushLayoutText(lineIndex, layout, ref dest, result); + PushLayoutImage(lineIndex, layout, ref dest, ref lineHeight, ref spaceAboveLine, (ISurface)obj); + result = string.Empty; + } + else + { + result += ConvertToString(obj, format); + } + } + lastIndex = matches[i].Index + matches[i].Length; + } - layout.Add(t); - } + result += formatString.Substring(lastIndex); + PushLayoutText(lineIndex, layout, ref dest, result); + ShiftLine(layout, spaceAboveLine, lineIndex); - private void PushLayoutText(int lineIndex, TextLayout layout, ref Point dest, string text) - { - if (string.IsNullOrEmpty(text)) - return; + layout.Translate(new Point(destX, destY)); + layout.DrawAll(); + } - LayoutText t = new LayoutText { Font = this, Location = dest, Text = text, LineIndex = lineIndex }; + private static void ShiftLine(TextLayout layout, int lineShift, int lineIndex) + { + foreach (var item in layout.Where(x => x.LineIndex == lineIndex)) + { + item.Location = new Point( + item.Location.X, item.Location.Y + lineShift); + } + } - layout.Add(t); + private void PushLayoutImage(int lineIndex, TextLayout layout, ref Point dest, ref int lineHeight, + ref int spaceAboveLine, ISurface surface) + { + int newSpaceAbove; + LayoutSurface t = new LayoutSurface { Location = dest, Surface = surface, LineIndex = lineIndex }; + t.State = surface.State.Clone(); - var size = StringDisplaySize(text); - var update = Origin.Calc(DisplayAlignment, size); + var update = Origin.Calc(DisplayAlignment, surface.SurfaceSize); - dest.X += size.Width; - } + lineHeight = Math.Max(lineHeight, surface.DisplayHeight); + dest.X += surface.DisplayWidth; + switch (TextImageLayout) + { + case TextImageLayout.InlineTop: + break; + case TextImageLayout.InlineCenter: + newSpaceAbove = (surface.DisplayHeight - FontHeight) / 2; + t.Y -= newSpaceAbove; + spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove); - private string ConvertToString(object obj, string format) - { - return obj.ToString(); - } + break; - } + case TextImageLayout.InlineBottom: + newSpaceAbove = surface.DisplayHeight - FontHeight; + t.Y -= newSpaceAbove; + spaceAboveLine = Math.Max(spaceAboveLine, newSpaceAbove); - public enum TextImageLayout - { - InlineTop, - InlineCenter, - InlineBottom, - } + break; + } + + layout.Add(t); + } + + private void PushLayoutText(int lineIndex, TextLayout layout, ref Point dest, string text) + { + if (string.IsNullOrEmpty(text)) + return; + + LayoutText t = new LayoutText { Font = this, Location = dest, Text = text, LineIndex = lineIndex }; + + layout.Add(t); + + var size = StringDisplaySize(text); + var update = Origin.Calc(DisplayAlignment, size); + + dest.X += size.Width; + } + + + private string ConvertToString(object obj, string format) + { + return obj.ToString(); + } + + } + + public enum TextImageLayout + { + InlineTop, + InlineCenter, + InlineBottom, + } } Modified: branches/font/AgateLib/ImplementationBase/FontSurfaceImpl.cs =================================================================== --- branches/font/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-04-15 04:44:43 UTC (rev 864) +++ branches/font/AgateLib/ImplementationBase/FontSurfaceImpl.cs 2009-04-15 06:39:44 UTC (rev 865) @@ -25,145 +25,35 @@ namespace AgateLib.ImplementationBase { - /// <summary> - /// Implements a FontSurface - /// </summary> - public abstract class FontSurfaceImpl : IDisposable - { - private OriginAlignment mAlignment = OriginAlignment.TopLeft; - private Color mColor = Color.White; - private double mScaleWidth = 1.0; - private double mScaleHeight = 1.0; - - /// <summary> - /// Measures the width of the given string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public abstract int StringDisplayWidth(string text); - /// <summary> - /// Measures the height of the given string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public abstract int StringDisplayHeight(string text); - /// <summary> - /// Measures the size of the given string. - /// </summary> - /// <param name="text"></param> - /// <returns></returns> - public abstract Size StringDisplaySize(string text); + /// <summary> + /// Implements a FontSurface + /// </summary> + public abstract class FontSurfaceImpl : IDisposable + { + /// <summary> + /// Measures the size of the given string. + /// </summary> + /// <param name="state"></param> + /// <param name="text"></param> + /// <returns></returns> + public abstract Size StringDisplaySize(FontState state, string text); + /// <summary> + /// Gets the height of a single line of text. + /// </summary> + public abstract int FontHeight { get; } - /// <summary> - /// Gets the height of a single line of text. - /// </summary> - public virtual int FontHeight - { - get { return StringDisplayHeight("M"); } - } + /// <summary> + /// Draws text to the screen. + /// </summary> + /// <param name="state"></param> + public abstract void DrawText(FontState state); - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public abstract void DrawText(int destX, int destY, string text); - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destX"></param> - /// <param name="destY"></param> - /// <param name="text"></param> - public abstract void DrawText(double destX, double destY, string text); - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public abstract void DrawText(Point destPt, string text); - /// <summary> - /// Draws the specified string at the specified location. - /// </summary> - /// <param name="destPt"></param> - /// <param name="text"></param> - public abstract void DrawText(PointF destPt, string text); + /// <summary> + /// Disposes of unmanaged resources. + /// </summary> + public abstract void Dispose(); - /// <summary> - /// Sets how to interpret the point given to DrawText methods. - /// </summary> - public virtual OriginAlignment DisplayAlignment - { - get { return mAlignment; } - set { mAlignment = value; } - } - /// <summary> - /// Sets the color of the text to be drawn. - /// </summary> - public virtual Color Color - { - get { return mColor; } - set { mColor = value; } - } - /// <summary> - /// Sets the alpha value of the text to be drawn. - /// </summary> - public virtual double Alpha - { - get { return mColor.A / 255.0; } - set - { - if (value < 0) value = 0; - if (value > 1.0) value = 1.0; - mColor = Color.FromArgb((int)(value * 255), mColor); - } - } - /// <summary> - /// Gets or sets the amount the width is scaled when the text is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleWidth - { - get { return mScaleWidth; } - set { mScaleWidth = value; } - } - /// <summary> - /// Gets or sets the amount the height is scaled when the text is drawn. - /// 1.0 is no scaling. - /// </summary> - public double ScaleHeight - { - get { return mScaleHeight; } - set { mScaleHeight = value; } - } - /// <summary> - /// Sets ScaleWidth and ScaleHeight. - /// </summary> - /// <param name="x"></param> - /// <param name="y"></param> - public virtual void SetScale(double x, double y) - { - ScaleWidth = x; - ScaleHeight = y; - } - /// <summary> - /// Gets ScaleWidth and ScaleHeight. - /// </summary> - /// <param name="x"></param> - /// <param name="y"></param> - public virtual void GetScale(out double x, out double y) - { - x = ScaleWidth; - y = ScaleHeight; - } + } - /// <summary> - /// Disposes of unmanaged resources. - /// </summary> - public abstract void Dispose(); - - - } - } Modified: branches/font/Drivers/AgateDrawing/Drawing_FontSurface.cs =================================================================== --- branches/font/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-04-15 04:44:43 UTC (rev 864) +++ branches/font/Drivers/AgateDrawing/Drawing_FontSurface.cs 2009-04-15 06:39:44 UTC (rev 865) @@ -26,107 +26,87 @@ namespace AgateLib.DisplayLib.SystemDrawing { - using AgateLib.DisplayLib; - using WinForms; + using AgateLib.DisplayLib; + using WinForms; - class Drawing_FontSurface : FontSurfaceImpl - { - Font mFont; + class Drawing_FontSurface : FontSurfaceImpl + { + Font mFont; - public Drawing_FontSurface(string fontFamily, float sizeInPoints, FontStyle style) - { - System.Drawing.FontStyle drawingStyle = System.Drawing.FontStyle.Regular; + public Drawing_FontSurface(string fontFamily, float sizeInPoints, FontStyle style) + { + System.Drawing.FontStyle drawingStyle = System.Drawing.FontStyle.Regular; - if ((style & FontStyle.Bold) > 0) - drawingStyle |= System.Drawing.FontStyle.Bold; - if ((style & FontStyle.Italic) > 0) - drawingStyle |= System.Drawing.FontStyle.Italic; - if ((style & FontStyle.Strikeout) > 0) - drawingStyle |= System.Drawing.FontStyle.Strikeout; - if ((style & FontStyle.Underline) > 0) - drawingStyle |= System.Drawing.FontStyle.Underline; + if ((style & FontStyle.Bold) > 0) + drawingStyle |= System.Drawing.FontStyle.Bold; + if ((style & FontStyle.Italic) > 0) + drawingStyle |= System.Drawing.FontStyle.Italic; + if ((style & FontStyle.Strikeout) > 0) + drawingStyle |= System.Drawing.FontStyle.Strikeout; + if ((style & FontStyle.Underline) > 0) + drawingStyle |= System.Drawing.FontStyle.Underline; - mFont = new Font(fontFamily, sizeInPoints, drawingStyle); - } - public override void Dispose() - { - mFont = null; - } + mFont = new Font(fontFamily, sizeInPoints, drawingStyle); + } + public override void Dispose() + { + mFont = null; + } - public override void DrawText(Geometry.Point dest_pt, string text) - { - DrawText(new Geometry.PointF((float)dest_pt.X, (float)dest_pt.Y), text); + public override int FontHeight + { + get { return mFont.Height; } + } + public override void DrawText(FontState state) + { + Geometry.PointF shift = Origin.CalcF(state.DisplayAlignment, + StringDisplaySize(state, state.Text)); - } - public override void DrawText(Geometry.PointF dest_pt, string text) - { - Geometry.PointF dest = Origin.CalcF(DisplayAlignment, StringDisplaySize(text)); + PointF dest_pt = Interop.Convert(state.Location); + dest_pt.X -= shift.X; + dest_pt.Y -= shift.Y; - dest_pt.X -= dest.X; - dest_pt.Y -= dest.Y; + Drawing_Display disp = Display.Impl as Drawing_Display; + Graphics g = disp.FrameGraphics; - Drawing_Display disp = Display.Impl as Drawing_Display; - Graphics g = disp.FrameGraphics; + GraphicsState g_state = g.Save(); + double scalex = state.ScaleWidth, scaley = state.ScaleHeight; - GraphicsState state = g.Save(); - double scalex, scaley; + g.TranslateTransform(dest_pt.X, dest_pt.Y); + g.ScaleTransform((float)scalex, (float)scaley); - GetScale(out scalex, out scaley); + g.DrawString(state.Text, mFont, + new SolidBrush(Interop.Convert(state.Color)), Point.Empty); - ... [truncated message content] |
From: <ka...@us...> - 2009-04-15 04:44:47
|
Revision: 864 http://agate.svn.sourceforge.net/agate/?rev=864&view=rev Author: kanato Date: 2009-04-15 04:44:43 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Refactored AgateOTK to use OtkShader class as a base for ArbShader and GlslShader. Modified Paths: -------------- branches/agate-3d/Drivers/AgateOTK/ArbShader.cs branches/agate-3d/Drivers/AgateOTK/GL_Display.cs branches/agate-3d/Drivers/AgateOTK/GlslShader.cs Added Paths: ----------- branches/agate-3d/Drivers/AgateOTK/OtkShader.cs Modified: branches/agate-3d/Drivers/AgateOTK/ArbShader.cs =================================================================== --- branches/agate-3d/Drivers/AgateOTK/ArbShader.cs 2009-04-15 04:02:03 UTC (rev 863) +++ branches/agate-3d/Drivers/AgateOTK/ArbShader.cs 2009-04-15 04:44:43 UTC (rev 864) @@ -7,7 +7,7 @@ namespace AgateOTK { - class ArbShader : ShaderProgram + class ArbShader : OtkShader { int programHandle; Dictionary<string, int> mUniforms = new Dictionary<string, int>(); @@ -31,7 +31,7 @@ get { return vertex; } } - public int Handle + public override int Handle { get { return programHandle; } } Modified: branches/agate-3d/Drivers/AgateOTK/GL_Display.cs =================================================================== --- branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-15 04:02:03 UTC (rev 863) +++ branches/agate-3d/Drivers/AgateOTK/GL_Display.cs 2009-04-15 04:44:43 UTC (rev 864) @@ -434,24 +434,24 @@ } - GlslShader mCurrentShader; + OtkShader mCurrentShader; public override AgateLib.DisplayLib.Shaders.ShaderProgram Shader { get { - return mCurrentShader; + return mCurrentShader; } set { if (value == null) return; - if (value is GlslShader == false) - throw new AgateLib.AgateException(string.Format( - "Shader type is {0} but must be GlslShader.", typeof(ValueType))); + if (value is OtkShader == false) + throw new AgateLib.AgateException(string.Format( + "Shader type is {0} but must be IGlShader.", value.GetType())); - mCurrentShader = (GlslShader)value; + mCurrentShader = (OtkShader)value; if (mCurrentShader == null) { Modified: branches/agate-3d/Drivers/AgateOTK/GlslShader.cs =================================================================== --- branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-15 04:02:03 UTC (rev 863) +++ branches/agate-3d/Drivers/AgateOTK/GlslShader.cs 2009-04-15 04:44:43 UTC (rev 864) @@ -7,7 +7,7 @@ namespace AgateOTK { - class GlslShader : ShaderProgram + class GlslShader : OtkShader { struct UniformInfo { @@ -88,7 +88,6 @@ mAttributeNames = mAttributes.Select(x => x.Name).ToList(); } - private void LoadUniforms() { int count; @@ -149,7 +148,7 @@ get { return vertex; } } - public int Handle + public override int Handle { get { return programHandle; } } Added: branches/agate-3d/Drivers/AgateOTK/OtkShader.cs =================================================================== --- branches/agate-3d/Drivers/AgateOTK/OtkShader.cs (rev 0) +++ branches/agate-3d/Drivers/AgateOTK/OtkShader.cs 2009-04-15 04:44:43 UTC (rev 864) @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using AgateLib.DisplayLib.Shaders; + +namespace AgateOTK +{ + public abstract class OtkShader : ShaderProgram + { + public abstract int Handle { get; } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2009-04-15 04:02:06
|
Revision: 863 http://agate.svn.sourceforge.net/agate/?rev=863&view=rev Author: kanato Date: 2009-04-15 04:02:03 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Added Paths: ----------- tags/release-0.3.1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |