texture.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5. namespace swf_texture {
  6. public partial class TextureForm: Form {
  7. TextureBrush tb;
  8. private string filename;
  9. public TextureForm (string[] args)
  10. {
  11. filename = args.Length > 0 ? args [1] : String.Empty;
  12. InitializeComponent ();
  13. tb = new TextureBrush (pictureBox1.Image);
  14. }
  15. private void textBox1_TextChanged (object sender, EventArgs e)
  16. {
  17. try {
  18. float f = Single.Parse (rotationTextBox.Text);
  19. tb.RotateTransform (f);
  20. rotationTextBox.BackColor = SystemColors.Window;
  21. }
  22. catch {
  23. rotationTextBox.BackColor = Color.Red;
  24. }
  25. finally {
  26. Invalidate ();
  27. Update ();
  28. }
  29. }
  30. private void TextureForm_Paint (object sender, PaintEventArgs e)
  31. {
  32. e.Graphics.FillRectangle (tb, e.Graphics.VisibleClipBounds);
  33. }
  34. private void resetButton_Click (object sender, EventArgs e)
  35. {
  36. tb.Transform = new Matrix ();
  37. Invalidate ();
  38. Update ();
  39. }
  40. /// <summary>
  41. /// Required designer variable.
  42. /// </summary>
  43. private System.ComponentModel.IContainer components = null;
  44. /// <summary>
  45. /// Clean up any resources being used.
  46. /// </summary>
  47. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  48. protected override void Dispose (bool disposing)
  49. {
  50. if (disposing && (components != null)) {
  51. components.Dispose ();
  52. }
  53. base.Dispose (disposing);
  54. }
  55. #region Windows Form Designer generated code
  56. /// <summary>
  57. /// Required method for Designer support - do not modify
  58. /// the contents of this method with the code editor.
  59. /// </summary>
  60. private void InitializeComponent ()
  61. {
  62. // System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager (typeof (TextureForm));
  63. this.pictureBox1 = new System.Windows.Forms.PictureBox ();
  64. this.rotationTextBox = new System.Windows.Forms.TextBox ();
  65. this.label1 = new System.Windows.Forms.Label ();
  66. this.resetButton = new System.Windows.Forms.Button ();
  67. ((System.ComponentModel.ISupportInitialize) (this.pictureBox1)).BeginInit ();
  68. this.SuspendLayout ();
  69. //
  70. // pictureBox1
  71. //
  72. // this.pictureBox1.Image = ((System.Drawing.Image) (resources.GetObject ("pictureBox1.Image")));
  73. if (filename.Length > 0) {
  74. this.pictureBox1.Image = Image.FromFile (filename);
  75. } else {
  76. Bitmap b = new Bitmap (32, 32);
  77. using (Graphics g = Graphics.FromImage (b)) {
  78. g.DrawLine (Pens.Red, 0, 0, 32, 32);
  79. }
  80. this.pictureBox1.Image = b;
  81. }
  82. this.pictureBox1.Location = new System.Drawing.Point (12, 217);
  83. this.pictureBox1.Name = "pictureBox1";
  84. this.pictureBox1.Size = new System.Drawing.Size (73, 80);
  85. this.pictureBox1.TabIndex = 0;
  86. this.pictureBox1.TabStop = false;
  87. //
  88. // rotationTextBox
  89. //
  90. this.rotationTextBox.Location = new System.Drawing.Point (94, 233);
  91. this.rotationTextBox.Name = "rotationTextBox";
  92. this.rotationTextBox.Size = new System.Drawing.Size (44, 20);
  93. this.rotationTextBox.TabIndex = 1;
  94. this.rotationTextBox.Text = "0";
  95. this.rotationTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  96. this.rotationTextBox.TextChanged += new System.EventHandler (this.textBox1_TextChanged);
  97. //
  98. // label1
  99. //
  100. this.label1.AutoSize = true;
  101. this.label1.Location = new System.Drawing.Point (91, 217);
  102. this.label1.Name = "label1";
  103. this.label1.Size = new System.Drawing.Size (47, 13);
  104. this.label1.TabIndex = 2;
  105. this.label1.Text = "Rotation";
  106. //
  107. // resetButton
  108. //
  109. this.resetButton.Location = new System.Drawing.Point (94, 274);
  110. this.resetButton.Name = "resetButton";
  111. this.resetButton.Size = new System.Drawing.Size (75, 23);
  112. this.resetButton.TabIndex = 3;
  113. this.resetButton.Text = "Reset";
  114. this.resetButton.UseVisualStyleBackColor = true;
  115. this.resetButton.Click += new System.EventHandler (this.resetButton_Click);
  116. //
  117. // TextureForm
  118. //
  119. this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 13F);
  120. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  121. this.ClientSize = new System.Drawing.Size (292, 309);
  122. this.Controls.Add (this.resetButton);
  123. this.Controls.Add (this.label1);
  124. this.Controls.Add (this.rotationTextBox);
  125. this.Controls.Add (this.pictureBox1);
  126. this.Name = "TextureForm";
  127. this.Text = "SWF Texture Demo";
  128. this.Paint += new System.Windows.Forms.PaintEventHandler (this.TextureForm_Paint);
  129. ((System.ComponentModel.ISupportInitialize) (this.pictureBox1)).EndInit ();
  130. this.ResumeLayout (false);
  131. this.PerformLayout ();
  132. }
  133. #endregion
  134. private System.Windows.Forms.PictureBox pictureBox1;
  135. private System.Windows.Forms.TextBox rotationTextBox;
  136. private System.Windows.Forms.Label label1;
  137. private System.Windows.Forms.Button resetButton;
  138. static void Main (string[] args)
  139. {
  140. Application.EnableVisualStyles ();
  141. Application.SetCompatibleTextRenderingDefault (false);
  142. Application.Run (new TextureForm (args));
  143. }
  144. }
  145. }