/************************************************************/
/*★ Direct Draw で Front Surface に楕円を描画 前田 稔 ★*/
/************************************************************/
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
namespace DXDraw
{
public class DXDraw : System.Windows.Forms.Form
{
private Device draw = null; // DrawDevice object.
private Surface primary = null; // primary destination surface.
private Rectangle dest; // Window Rectangle.
public DXDraw()
{
this.Text = "DXDraw";
this.Resize += new System.EventHandler(this.DXDraw_SizeChanged);
this.SizeChanged += new System.EventHandler(this.DXDraw_SizeChanged);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.DXDraw_Paint);
CreateSurfaces(); // Call creates the surface objects.
}
//☆ Main() メソッド
static void Main()
{
using(DXDraw mf = new DXDraw())
{ Application.Run(mf);
}
}
private void DXDraw_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Draw();
}
private void DXDraw_SizeChanged(object sender, System.EventArgs e)
{
Draw();
}
// This function Draws the offscreen bitmap surface to the primary visible surface.
private void Draw()
{
if (null == primary) return;
if (FormWindowState.Minimized == WindowState) return;
try
{
dest = new Rectangle(PointToScreen(new Point(0, 0)), ClientSize);
primary.FillColor = Color.White;
primary.DrawBox(dest.Left, dest.Top, dest.Right, dest.Bottom);
primary.FillColor = Color.Blue;
primary.DrawEllipse(dest.Left + 40, dest.Top + 20, dest.Right - 40, dest.Bottom - 20);
}
catch(SurfaceLostException)
{
CreateSurfaces(); // Surface was lost. Recreate them.
}
}
// This function is where the surfaces and clipper object are created.
private void CreateSurfaces()
{
// Create new Draw Device.
draw = new Device();
draw.SetCooperativeLevel(this, CooperativeLevelFlags.Normal);
// Create new Surface
SurfaceDescription description = new SurfaceDescription();
description.SurfaceCaps.PrimarySurface = true;
primary = new Surface(description, draw);
}
}
}
|