| 1 |
namespace DxUi |
| 2 |
{ |
| 3 |
public partial class Form1 : Form |
| 4 |
{ |
| 5 |
// The d3d device |
| 6 |
private Device device = null; |
| 7 |
|
| 8 |
private Sprite Wall; |
| 9 |
private Texture Tx; |
| 10 |
|
| 11 |
string path; |
| 12 |
List<imgButtons> UiButtons = new List<imgButtons>(); |
| 13 |
|
| 14 |
public Form1() |
| 15 |
{ |
| 16 |
InitializeComponent(); |
| 17 |
path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); |
| 18 |
|
| 19 |
// Now let's setup our D3D parameters |
| 20 |
PresentParameters presentParams = new PresentParameters(); |
| 21 |
presentParams.Windowed = true; |
| 22 |
presentParams.SwapEffect = SwapEffect.Discard; |
| 23 |
|
| 24 |
// create the device |
| 25 |
device = new Device(0, DeviceType.Default, this, |
| 26 |
CreateFlags.None, presentParams); |
| 27 |
|
| 28 |
device.DeviceReset += new EventHandler(device_DeviceReset); |
| 29 |
|
| 30 |
Tx = TextureLoader.FromFile(device, path + @"\img\Wall.bmp"); |
| 31 |
Wall = new Sprite(device); |
| 32 |
|
| 33 |
device_DeviceReset(null, EventArgs.Empty); |
| 34 |
|
| 35 |
LoadSprites(); |
| 36 |
} |
| 37 |
|
| 38 |
void device_DeviceReset(object sender, EventArgs e) |
| 39 |
{ |
| 40 |
//Tx = TextureLoader.FromFile(device, path + @"\img\Wall.bmp"); |
| 41 |
} |
| 42 |
|
| 43 |
public void Render() |
| 44 |
{ |
| 45 |
try |
| 46 |
{ |
| 47 |
// start drawing commands |
| 48 |
device.BeginScene(); |
| 49 |
// clears the frame |
| 50 |
device.Clear(ClearFlags.Target, 0, 1.0f, 0); |
| 51 |
|
| 52 |
device.RenderState.AlphaBlendEnable = true; |
| 53 |
|
| 54 |
device.RenderState.SourceBlend = Blend.SourceAlpha; |
| 55 |
device.RenderState.DestinationBlend = Blend.InvDestinationAlpha; |
| 56 |
device.RenderState.AlphaTestEnable = true; |
| 57 |
|
| 58 |
Wall.Begin(SpriteFlags.AlphaBlend); |
| 59 |
|
| 60 |
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); |
| 61 |
|
| 62 |
Wall.Draw(Tx, rect, Vector3.Empty, new Vector3(0, 10, 0), Color.White); |
| 63 |
|
| 64 |
foreach (imgButtons ib in UiButtons) |
| 65 |
{ |
| 66 |
Wall.Draw(ib.ButtonNorm, ib.rectangle, Vector3.Empty, new Vector3(ib.X, ib.Y - 50, 0), Color.White); |
| 67 |
} |
| 68 |
|
| 69 |
Wall.End(); |
| 70 |
|
| 71 |
device.RenderState.AlphaBlendEnable = false; |
| 72 |
} |
| 73 |
finally |
| 74 |
{ |
| 75 |
// end the drawing commands and copy to screen |
| 76 |
device.EndScene(); |
| 77 |
device.Present(); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
protected override void OnPaintBackground(PaintEventArgs e) |
| 82 |
{ |
| 83 |
// do nothing |
| 84 |
} |
| 85 |
|
| 86 |
/// <summary> |
| 87 |
/// Called when the window needs to be repainted |
| 88 |
/// </summary> |
| 89 |
/// <param name="e">Unused</param> |
| 90 |
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) |
| 91 |
{ |
| 92 |
// Render on painting |
| 93 |
this.Render(); |
| 94 |
Thread.Sleep(50); |
| 95 |
Application.DoEvents(); |
| 96 |
// Render again |
| 97 |
this.Invalidate(); |
| 98 |
} |
| 99 |
|
| 100 |
void LoadSprites() |
| 101 |
{ |
| 102 |
XDocument btns = XDocument.Load(path + @"\UISettings.xml"); |
| 103 |
|
| 104 |
var query = from button in btns.Descendants("imgButton") |
| 105 |
select new imgButtons |
| 106 |
{ |
| 107 |
X = int.Parse((string)button.Element("XPos")), |
| 108 |
Y = int.Parse((string)button.Element("YPos")), |
| 109 |
ButtonPath = path + (string)button.Element("imgPath"), |
| 110 |
ButtonPushPath = path + (string)button.Element("pushPath"), |
| 111 |
ProgramToRun = (string)button.Element("Process"), |
| 112 |
ButtonName = (string)button.Element("ButtonName"), |
| 113 |
|
| 114 |
}; |
| 115 |
|
| 116 |
foreach (imgButtons ibtn in query) |
| 117 |
{ |
| 118 |
ibtn.CreateImages(device); |
| 119 |
ibtn.CreateClient(path); |
| 120 |
UiButtons.Add(ibtn); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |