📄 emptyproject.cs
字号:
effect.SetValue("appTime", (float)appTime);
// Show frame rate
RenderText();
// Show UI
hud.OnRender(elapsedTime);
sampleUi.OnRender(elapsedTime);
}
finally
{
if (beginSceneCalled)
device.EndScene();
}
}
/// <summary>
/// Render the help and statistics text. This function uses the Font object for
/// efficient text rendering.
/// </summary>
private void RenderText()
{
/*
TextHelper txtHelper = new TextHelper(statsFont, textSprite, 15);
// Output statistics
txtHelper.Begin();
txtHelper.SetInsertionPoint(5,5);
txtHelper.SetForegroundColor(System.Drawing.Color.Yellow);
txtHelper.DrawTextLine(sampleFramework.FrameStats);
txtHelper.DrawTextLine(sampleFramework.DeviceStats);
txtHelper.SetForegroundColor(System.Drawing.Color.White);
txtHelper.DrawTextLine("Put some status text here.");
// Draw help
if (isHelpShowing)
{
txtHelper.SetInsertionPoint(10, sampleFramework.BackBufferSurfaceDescription.Height-15*6);
txtHelper.SetForegroundColor(System.Drawing.Color.DarkOrange);
txtHelper.DrawTextLine("Controls (F1 to hide):");
txtHelper.SetInsertionPoint(40, sampleFramework.BackBufferSurfaceDescription.Height-15*5);
txtHelper.DrawTextLine("Help Item Misc: X");
txtHelper.DrawTextLine("Quit: Esc");
txtHelper.DrawTextLine("Hide help: F1");
}
else
{
txtHelper.SetInsertionPoint(10, sampleFramework.BackBufferSurfaceDescription.Height-15*2);
txtHelper.SetForegroundColor(System.Drawing.Color.White);
txtHelper.DrawTextLine("Press F1 for help");
}
txtHelper.End();
*/
}
/// <summary>
/// As a convenience, the sample framework inspects the incoming windows messages for
/// keystroke messages and decodes the message parameters to pass relevant keyboard
/// messages to the application. The framework does not remove the underlying keystroke
/// messages, which are still passed to the application's MsgProc callback.
/// </summary>
private void OnKeyEvent(object sender, System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case System.Windows.Forms.Keys.F1:
isHelpShowing = !isHelpShowing;
break;
}
}
/// <summary>
/// Before handling window messages, the sample framework passes incoming windows
/// messages to the application through this callback function. If the application sets
/// noFurtherProcessing to true, the sample framework will not process the message
/// </summary>
public IntPtr OnMsgProc(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool noFurtherProcessing)
{
// Give the dialog a chance to handle the message first
noFurtherProcessing = hud.MessageProc(hWnd, msg, wParam, lParam);
if (noFurtherProcessing)
return IntPtr.Zero;
noFurtherProcessing = sampleUi.MessageProc(hWnd, msg, wParam, lParam);
if (noFurtherProcessing)
return IntPtr.Zero;
// Pass all remaining windows messages to camera so it can respond to user input
camera.HandleMessages(hWnd, msg, wParam, lParam);
return IntPtr.Zero;
}
/// <summary>
/// Initializes the application
/// </summary>
public void InitializeApplication()
{
int y = 10;
// Initialize the HUD
hud.SetLocation(-100,500);
Button option = hud.AddButton(Option,"Option", -35, y, 90,30);
Button pause = hud.AddButton(Pause,"Pause", -35, y += 34, 80,30);
Button exit = hud.AddButton(Exit,"Exit", -35, y += 34, 60,30);
Button load = hud.AddButton(Load,"Load",-35,y+=34,60,30);
Button save = hud.AddButton(Save,"Save",-35,y+=34,60,30);
// Hook the button events for when these items are clicked
option.Click += new EventHandler(OnFullscreenClicked);
pause.Click += new EventHandler(OnRefClicked);
exit.Click += new EventHandler(OnChangeDeviceClicked);
// Now add the sample specific UI
y = 10;
const int ChangeDevice=5;
const int ComboBox1 = ChangeDevice + 1;
const int CheckBox1 = ChangeDevice + 2;
const int CheckBox2 = ChangeDevice + 3;
const int Radiobutton1 = ChangeDevice + 4;
const int Radiobutton2 = ChangeDevice + 5;
const int Radiobutton3 = ChangeDevice + 6;
const int Button1 = ChangeDevice + 7;
const int Button2 = ChangeDevice + 8;
const int Radiobutton4 = ChangeDevice + 9;
const int Radiobutton5 = ChangeDevice + 10;
const int SliderControl = ChangeDevice + 11;
ComboBox cb1 = sampleUi.AddComboBox(ComboBox1, 35, y +=34, 200, 30);
for (int i = 0; i < 50; i++) cb1.AddItem("Item#" + i.ToString(), null);
sampleUi.AddCheckBox(CheckBox1, "Checkbox1", 35, y+=34, 200,30, false);
sampleUi.AddCheckBox(CheckBox2, "Checkbox2", 35, y+=34, 200,30, false);
sampleUi.AddRadioButton(Radiobutton1, 1, "Radio1G1", 35, y+=34, 200, 30, true);
sampleUi.AddRadioButton(Radiobutton2, 1, "Radio2G1", 35, y+=34, 200, 30, false);
sampleUi.AddRadioButton(Radiobutton3, 1, "Radio3G1", 35, y+=34, 200, 30, false);
sampleUi.AddSlider(SliderControl, 50,y+=24, 100, 22);
sampleUi.AddButton(Button1, "Button1", 35, y+=34, 200, 30);
sampleUi.AddButton(Button2, "Button2", 35, y+=34, 200, 30);
sampleUi.AddRadioButton(Radiobutton4, 2, "Radio1G2", 35, y+=34, 200, 30, true);
sampleUi.AddRadioButton(Radiobutton5, 2, "Radio2G2", 35, y+=34, 200, 30, false);
// If you wanted to respond to any of these you would need to add an event hook here
}
/// <summary>Called when the change device button is clicked</summary>
private void OnChangeDeviceClicked(object sender, EventArgs e)
{
sampleFramework.ShowSettingsDialog(!sampleFramework.IsD3DSettingsDialogShowing);
}
/// <summary>Called when the full screen button is clicked</summary>
private void OnFullscreenClicked(object sender, EventArgs e)
{
sampleFramework.ToggleFullscreen();
}
/// <summary>Called when the ref button is clicked</summary>
private void OnRefClicked(object sender, EventArgs e)
{
sampleFramework.ToggleReference();
}
/// <summary>
/// Entry point to the program. Initializes everything and goes into a message processing
/// loop. Idle time is used to render the scene.
/// </summary>
static int xxxMain()
{
System.Windows.Forms.Application.EnableVisualStyles();
using(Framework sampleFramework = new Framework())
{
EmptyProject sample = new EmptyProject(sampleFramework);
// Set the callback functions. These functions allow the sample framework to notify
// the application about device changes, user input, and windows messages. The
// callbacks are optional so you need only set callbacks for events you're interested
// in. However, if you don't handle the device reset/lost callbacks then the sample
// framework won't be able to reset your device since the application must first
// release all device resources before resetting. Likewise, if you don't handle the
// device created/destroyed callbacks then the sample framework won't be able to
// recreate your device resources.
sampleFramework.Disposing += new EventHandler(sample.OnDestroyDevice);
sampleFramework.DeviceLost += new EventHandler(sample.OnLostDevice);
sampleFramework.DeviceCreated += new DeviceEventHandler(sample.OnCreateDevice);
sampleFramework.DeviceReset += new DeviceEventHandler(sample.OnResetDevice);
sampleFramework.SetWndProcCallback(new WndProcCallback(sample.OnMsgProc));
sampleFramework.SetCallbackInterface(sample);
try
{
// Show the cursor and clip it when in full screen
sampleFramework.SetCursorSettings(true, true);
// Initialize
sample.InitializeApplication();
// Initialize the sample framework and create the desired window and Direct3D
// device for the application. Calling each of these functions is optional, but they
// allow you to set several options which control the behavior of the sampleFramework.
sampleFramework.Initialize( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
sampleFramework.CreateWindow("EmptyProject");
// Hook the keyboard event
sampleFramework.Window.KeyDown += new System.Windows.Forms.KeyEventHandler(sample.OnKeyEvent);
sampleFramework.CreateDevice( 0, true, Framework.DefaultSizeWidth, Framework.DefaultSizeHeight,
sample);
// Pass control to the sample framework for handling the message pump and
// dispatching render calls. The sample framework will call your FrameMove
// and FrameRender callback when there is idle time between handling window messages.
sampleFramework.MainLoop();
}
#if(DEBUG)
catch (Exception e)
{
// In debug mode show this error (maybe - depending on settings)
sampleFramework.DisplayErrorMessage(e);
#else
catch
{
// In release mode fail silently
#endif
// Ignore any exceptions here, they would have been handled by other areas
return (sampleFramework.ExitCode == 0) ? 1 : sampleFramework.ExitCode; // Return an error code here
}
// Perform any application-level cleanup here. Direct3D device resources are released within the
// appropriate callback functions and therefore don't require any cleanup code here.
return sampleFramework.ExitCode;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -