|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Collections;
using Microsoft.DirectX.DirectDraw;
using System.IO;
namespace Demo
{
public partial class Main : Form
{
// The DirectDraw Device, used in all the application
private Device display;
// The Front Surface
private Surface front = null;
// The Back Surface
private Surface back = null;
// Surface to store the title screen
private Surface title = null;
// Surface to store the text
private Surface text = null;
// The Clipper
private Clipper clip = null;
string titlescreen = Application.StartupPath + "\\skin\\default\\main.jpg";
public static byte Banlance = 0;
public Main()
{
InitializeComponent();
InitializeGraphics();
this.Cursor.Dispose();
this.Show();
while (Created)
{
Draw();
Application.DoEvents();
}
}
public static List Songs = new List();
public static int CurrentIndex = 1;
public void InitializeGraphics()
{
// Used to describe a Surface
SurfaceDescription description = new SurfaceDescription();
// Init the Device
display = new Device();
//#if DEBUG
//display.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive);
//#else
// Set the Cooperative Level and parent,
//Setted to Full Screen Exclusive to the form)
display.SetCooperativeLevel(this,CooperativeLevelFlags.FullscreenExclusive);
// Set the resolution and color depth
//used in full screen(640x480, 16 bit color)
display.SetDisplayMode(800, 600, 16, 0, false);
//#endif
// Define the attributes for the front Surface
description.SurfaceCaps.PrimarySurface = true;
#if DEBUG
front = new Surface(description, display);
#else
description.SurfaceCaps.Flip = true;
description.SurfaceCaps.Complex = true;
// Set the Back Buffer count
description.BackBufferCount = 1;
desc. // Create the Surface with specifed description and device)
front = new Surface(description, display);
#endif
description.Clear();
#if DEBUG
description.Width = front.SurfaceDescription.Width;
description.Height = front.SurfaceDescription.Height;
description.SurfaceCaps.OffScreenPlain = true;
back = new Surface(description, display);
#else
// A Caps is a set of attributes used by most of DirectX components
SurfaceCaps caps = new SurfaceCaps();
// Yes, we are using a back buffer
caps.BackBuffer = true;
// Associate the front buffer to back buffer with specified caps
back = front.GetAttachedSurface(caps);
#endif
// Create the Clipper
clip = new Clipper(display);
/// Set the region to this form
clip.Window = this;
// Set the clipper for the front Surface
front.Clipper = clip;
// Reset the description
description.Clear();
// Create the title screen
//title = new Surface(titlescreen, description, display);
Bitmap bitmap = new Bitmap(Image.FromFile(titlescreen));
title = new Surface(bitmap, description, display);
description.Clear();
// Set the height and width of the text.
description.Width = 600;
description.Height = 16;
// OffScreenPlain means that this Surface
//is not a front, back, alpha Surface.
description.SurfaceCaps.OffScreenPlain = true;
// Create the text Surface
text = new Surface(description, display);
// Set the fore color of the text
//text.ForeColor = Color.Black;
// Set the backgroup color
text.FillColor = Color.Transparent;
//text.ColorFill(Color.Transparent);
// Draw the Text to the Surface to coords (0,0)
ColorKey ck = new ColorKey();
ck.ColorSpaceLowValue = 255;
ck.ColorSpaceHighValue = 255;
title.SetColorKey(ColorKeyFlags.SourceDraw, ck);
text.DrawText(0, 0,"This is some message",false);
}
private void Draw()
{
// If the front isn't create, ignore this function
if (front == null)
{
return;
}
// If the form is minimized, ignore this function
if (this.WindowState == FormWindowState.Minimized)
{
return;
}
try
{
// Draw the title to the back buffer using source copy blit
back.DrawFast(0, 0, title, DrawFastFlags.Wait);
// Draw the text also to the back buffer using source copy blit
back.DrawFast(10, 10, text, DrawFastFlags.Wait);
#if DEBUG
// Draw all this to the front
front.Draw(back, DrawFlags.Wait);
#else
// Doing a flip to transfer back buffer to the front, faster
front.Flip(back, FlipFlags.Wait);
#endif
}
catch (WasStillDrawingException)
{
return;
}
catch (SurfaceLostException)
{
// If we lost the surfaces, restore the surfaces
RestoreSurfaces();
}
}
private void RestoreSurfaces()
{
// Used to describe a Surface
SurfaceDescription description = new SurfaceDescription();
// Restore al the surface associed with the device
display.RestoreAllSurfaces();
// Redraw the text
//text.ColorFill(Color.Black);
// text.DrawText(0, 0, "I Love you",true);
// For the title screen, we need to
//dispose it first and then re-create it
title.Dispose();
title = null;
title = new Surface(titlescreen, description, display);
return;
}
}
}
|
|