using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace rotation_test
{
public class rotationtest : System.Windows.Forms.Form
{
Timer rotationtimer = new Timer();
Image sphere;
Image sun;
Bitmap offScreenBuffer;
float sphereX, sphereY;
double rotationfactor;
const string sphere_file_name = "..\\..\\sphere.ico";
const string sun_file_name = "..\\..\\sun.ico";
private System.ComponentModel.Container components = null;
public rotationtest()
{
sphere = Image.FromFile( sphere_file_name );
sun = Image.FromFile( sun_file_name );
InitializeComponent();
}
public void RotationTimerTick( object sender, System.EventArgs e )
{
rotationfactor += 0.025;
sphereX = 100 * (float)Math.Cos( rotationfactor ) + ( ( this.ClientSize.Width / 2 ) - 16 );
sphereY = 100 * (float)Math.Sin( rotationfactor ) + ( ( this.ClientSize.Height / 2 ) - 16 );
Invalidate();
}
public void DoPaint( Graphics g, PaintEventArgs e )
{
System.Drawing.Pen ellipsepen = new Pen( Color.Red, 1 );
g = e.Graphics;
g.DrawEllipse( ellipsepen, ( this.ClientSize.Width / 2 ) - 100, ( this.ClientSize.Height / 2 ) - 100,
200, 200 );
g.DrawImage( sphere, sphereX, sphereY );
g.DrawImage( sun, ( this.ClientSize.Width / 2 ) - 16, ( this.ClientSize.Height / 2 ) - 16 );
base.OnPaint( e );
}
private void InitializeComponent()
{
//
// rotationtest
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(792, 466);
this.ForeColor = System.Drawing.Color.Black;
this.MaximumSize = new System.Drawing.Size(800, 500);
this.MinimumSize = new System.Drawing.Size(800, 500);
this.Name = "rotationtest";
this.Text = "rotation test";
SetStyle( ControlStyles.UserPaint, true );
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
rotationtimer.Enabled = false;
rotationtimer.Interval = 30;
rotationtimer.Tick += new System.EventHandler( RotationTimerTick );
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnKeyDown( KeyEventArgs e )
{
string input = e.KeyData.ToString();
switch( input )
{
case "Enter":
rotationtimer.Enabled = true;
break;
}
Invalidate();
}
protected override void OnPaint( PaintEventArgs e )
{
Graphics gOffScreen;
Graphics g = e.Graphics;
if( offScreenBuffer == null || offScreenBuffer.Width != this.ClientSize.Width || offScreenBuffer.Height != this.ClientSize.Height )
{
offScreenBuffer = new Bitmap( this.ClientSize.Width, this.ClientSize.Height );
}
gOffScreen = Graphics.FromImage( offScreenBuffer );
DoPaint( gOffScreen, e );
gOffScreen.Dispose();
g.DrawImage( offScreenBuffer, 0, 0 );
}
[STAThread]
static void Main()
{
Application.Run( new rotationtest() );
}
}
}