?? dxmutgui.cs
字號:
// Make sure there's a texture to create
if ((tn.Filename == null) || (tn.Filename.Length == 0))
return;
// Find the texture
string path = Utility.FindMediaFile(tn.Filename);
// Create the new texture
ImageInformation info = new ImageInformation();
tn.Texture = TextureLoader.FromFile(device, path, D3DX.Default, D3DX.Default, D3DX.Default, Usage.None,
Format.Unknown, Pool.Managed, (Filter)D3DX.Default, (Filter)D3DX.Default, 0, ref info);
// Store dimensions
tn.Width = (uint)info.Width;
tn.Height = (uint)info.Height;
}
#region Device event callbacks
/// <summary>
/// Called when the device is created
/// </summary>
public void OnCreateDevice(Device d)
{
// Store device
device = d;
// create fonts and textures
for (int i = 0; i < fontCache.Count; i++)
CreateFont(i);
for (int i = 0; i < textureCache.Count; i++)
CreateTexture(i);
dialogSprite = new Sprite(d); // Create the sprite
}
/// <summary>
/// Called when the device is reset
/// </summary>
public void OnResetDevice(Device device)
{
foreach(FontNode fn in fontCache)
fn.Font.OnResetDevice();
if (dialogSprite != null)
dialogSprite.OnResetDevice();
// Create new state block
dialogStateBlock = new StateBlock(device, StateBlockType.All);
}
/// <summary>
/// Clear any resources that need to be lost
/// </summary>
public void OnLostDevice()
{
foreach(FontNode fn in fontCache)
{
if ( (fn.Font != null) && (!fn.Font.Disposed) )
fn.Font.OnLostDevice();
}
if (dialogSprite != null)
dialogSprite.OnLostDevice();
if (dialogStateBlock != null)
{
dialogStateBlock.Dispose();
dialogStateBlock = null;
}
}
/// <summary>
/// Destroy any resources and clear the caches
/// </summary>
public void OnDestroyDevice()
{
foreach(FontNode fn in fontCache)
{
if (fn.Font != null)
fn.Font.Dispose();
}
foreach(TextureNode tn in textureCache)
{
if (tn.Texture != null)
tn.Texture.Dispose();
}
if (dialogSprite != null)
{
dialogSprite.Dispose();
dialogSprite = null;
}
if (dialogStateBlock != null)
{
dialogStateBlock.Dispose();
dialogStateBlock = null;
}
}
#endregion
}
#endregion
/// <summary>
/// All controls must be assigned to a dialog, which handles
/// input and rendering for the controls.
/// </summary>
public class Dialog
{
#region Static Data
public const int WheelDelta = 120;
public static readonly ColorValue WhiteColorValue = new ColorValue(0.82f, 0.96f, 0.15f, 1.0f);
public static readonly ColorValue TransparentWhite = new ColorValue(1.0f, 1.0f, 1.0f, 0.0f);
public static readonly ColorValue BlackColorValue = new ColorValue(0.97f, 0.62f, 0.21f, 1.0f);
private static Control controlFocus = null; // The control which has focus
private static Control controlMouseOver = null; // The control which is hovered over
private static Control controlMouseDown = null; // The control which the mouse was pressed on
private static double timeRefresh = 0.0;
/// <summary>Set the static refresh time</summary>
public static void SetRefreshTime(float time) { timeRefresh = time; }
#endregion
#region Instance Data
// Sample framework
private Framework parent = null;
public Framework SampleFramework { get { return parent; } }
// Vertex information
private CustomVertex.TransformedColoredTextured[] vertices;
// Timing
private double timeLastRefresh;
// Control/Elements
private ArrayList controlList = new ArrayList();
private ArrayList defaultElementList = new ArrayList();
// Captions
private bool hasCaption;
private string caption;
private int captionHeight;
private Element captionElement;
private bool isDialogMinimized;
// Dialog information
private int dialogX, dialogY, width, height;
// Colors
private ColorValue topLeftColor, topRightColor, bottomLeftColor, bottomRightColor;
// Fonts/Textures
private ArrayList textureList = new ArrayList(); // Index into texture cache
private ArrayList fontList = new ArrayList(); // Index into font cache
// Dialogs
private Dialog nextDialog;
private Dialog prevDialog;
// User Input control
private bool usingNonUserEvents;
private bool usingKeyboardInput;
private bool usingMouseInput;
#endregion
#region Simple Properties/Methods
/// <summary>Is the dilaog using non user events</summary>
public bool IsUsingNonUserEvents { get { return usingNonUserEvents; } set { usingNonUserEvents = value; } }
/// <summary>Is the dilaog using keyboard input</summary>
public bool IsUsingKeyboardInput { get { return usingKeyboardInput; } set { usingKeyboardInput = value; } }
/// <summary>Is the dilaog using mouse input</summary>
public bool IsUsingMouseInput { get { return usingMouseInput; } set { usingMouseInput = value; } }
/// <summary>Is the dilaog minimized</summary>
public bool IsMinimized { get { return isDialogMinimized; } set { isDialogMinimized = value; } }
/// <summary>Called to set dialog's location</summary>
public void SetLocation(int x, int y) { dialogX = x; dialogY = y; UpdateVertices(); }
/// <summary>The dialog's location</summary>
public System.Drawing.Point Location {
get {return new System.Drawing.Point(dialogX, dialogY); }
set { dialogX = value.X; dialogY = value.Y; UpdateVertices(); }
}
/// <summary>Called to set dialog's size</summary>
public void SetSize(int w, int h) { width = w; height = h; UpdateVertices();}
/// <summary>Dialogs width</summary>
public int Width { get { return width; } set { width = value; } }
/// <summary>Dialogs height</summary>
public int Height { get { return height; } set { height = value; } }
/// <summary>Called to set dialog's caption</summary>
public void SetCaptionText(string text) { caption = text; }
/// <summary>The dialog's caption height</summary>
public int CaptionHeight { get { return captionHeight; } set { captionHeight = value; } }
/// <summary>Called to set dialog's caption enabled state</summary>
public void SetCaptionEnabled(bool isEnabled) { hasCaption = isEnabled; }
/// <summary>Called to set dialog's border colors</summary>
public void SetBackgroundColors(ColorValue topLeft, ColorValue topRight, ColorValue bottomLeft, ColorValue bottomRight)
{
topLeftColor = topLeft; topRightColor = topRight; bottomLeftColor = bottomLeft; bottomRightColor = bottomRight;
UpdateVertices();
}
/// <summary>Called to set dialog's border colors</summary>
public void SetBackgroundColors(ColorValue allCorners) { SetBackgroundColors(allCorners, allCorners, allCorners, allCorners); }
#endregion
/// <summary>
/// Create a new instance of the dialog class
/// </summary>
public Dialog(Framework sample)
{
parent = sample; // store this for later use
// Initialize to default state
dialogX = 0; dialogY = 0; width = 0; height = 0;
hasCaption = false; isDialogMinimized = false;
caption = string.Empty;
captionHeight = 18;
topLeftColor = topRightColor = bottomLeftColor = bottomRightColor = new ColorValue();
timeLastRefresh = 0.0f;
nextDialog = this; // Only one dialog
prevDialog = this; // Only one dialog
usingNonUserEvents = false;
usingKeyboardInput = false;
usingMouseInput = true;
InitializeDefaultElements();
}
/// <summary>
/// Initialize the default elements for this dialog
/// </summary>
private void InitializeDefaultElements()
{
SetTexture(0, "UI\\DXUTControls.dds");
SetFont(0, "Arial", 14, FontWeight.Normal);
//-------------------------------------
// Element for the caption
//-------------------------------------
captionElement = new Element();
captionElement.SetFont(0, WhiteColorValue, DrawTextFormat.Left | DrawTextFormat.VerticalCenter);
captionElement.SetTexture(0, System.Drawing.Rectangle.FromLTRB(17, 269, 241, 287),new ColorValue(0.988f,0.89f,0.73f,1.0f));
captionElement.TextureColor.States[(int)ControlState.Normal] = new ColorValue(0.988f,0.89f,0.73f,1.0f);
captionElement.FontColor.States[(int)ControlState.Normal] = new ColorValue(0.988f,0.89f,0.73f,1.0f);
// Pre-blend as we don't need to transition the state
captionElement.TextureColor.Blend(ControlState.Normal, 10.0f);
captionElement.FontColor.Blend(ControlState.Normal, 10.0f);
Element e = new Element();
//-------------------------------------
// StaticText
//-------------------------------------
e.SetFont(0);
e.FontColor.States[(int)ControlState.Disabled] = new ColorValue(0.75f, 0.75f, 0.75f, 0.75f);
// Assign the element
SetDefaultElement(ControlType.StaticText, StaticText.TextElement, e);
//-------------------------------------
// Button - Button
//-------------------------------------
e.SetTexture(0, System.Drawing.Rectangle.FromLTRB(0, 0, 136, 54));
e.SetFont(0);
e.TextureColor.States[(int)ControlState.Normal] = new ColorValue(1.0f, 1.0f, 1.0f, 0.55f);
e.TextureColor.States[(int)ControlState.Pressed] = new ColorValue(1.0f, 1.0f, 1.0f, 0.85f);
e.FontColor.States[(int)ControlState.MouseOver] = BlackColorValue;
// Assign the element
SetDefaultElement(ControlType.Button, Button.ButtonLayer, e);
//-------------------------------------
// Button - Fill Layer
//-------------------------------------
e.SetTexture(0, System.Drawing.Rectangle.FromLTRB(136, 0, 252, 54), TransparentWhite);
e.TextureColor.States[(int)ControlState.MouseOver] = new ColorValue(1.0f, 1.0f, 1.0f, 0.6f);
e.TextureColor.States[(int)ControlState.Pressed] = new ColorValue(0,0,0, 0.25f);
e.TextureColor.States[(int)ControlState.Focus] = new ColorValue(1.0f, 1.0f, 1.0f, 0.05f);
// Assign the element
SetDefaultElement(ControlType.Button, Button.FillLayer, e);
//-------------------------------------
// CheckBox - Box
//-------------------------------------
e.SetTexture(0, System.Drawing.Rectangle.FromLTRB(0, 54, 27, 81));
e.SetFont(0, WhiteColorValue, DrawTextFormat.Left | DrawTextFormat.VerticalCenter);
e.FontColor.States[(int)ControlState.Disabled] = new ColorValue(0.8f, 0.8f, 0.8f, 0.8f);
e.TextureColor.States[(int)ControlState.Normal] = new ColorValue(1.0f, 1.0f, 1.0f, 0.55f);
e.TextureColor.States[(int)ControlState.Focus] = new ColorValue(1.0f, 1.0f, 1.0f, 0.8f);
e.TextureColor.States[(int)ControlState.Pressed] = WhiteColorValue;
// Assign the element
SetDefaultElement(ControlType.CheckBox, Checkbox.BoxLayer, e);
//-------------------------------------
// CheckBox - Check
//-------------------------------------
e.SetTexture(0, System.Drawing.Rectangle.FromLTRB(27, 54, 54, 81));
// Assign the element
SetDefaultElement(ControlType.CheckBox, Checkbox.CheckLayer, e);
//-------------------------------------
// RadioButton - Box
//-------------------------------------
e.SetTexture(0, System.Drawing.Rectangle.FromLTRB(54, 54, 81, 81));
e.SetFont(0, WhiteColorValue, DrawTextFormat.Left | DrawTextFormat.VerticalCenter);
e.FontColor.States[(int)ControlState.Disabled] = new ColorValue(0.8f, 0.8f, 0.8f, 0.8f);
e.TextureColor.States[(int)ControlState.Normal] = new ColorValue(1.0f, 1.0f, 1.0f, 0.55f);
e.TextureColor.States[(int)ControlState.Focus] = new ColorValue(1.0f, 1.0f, 1.0f, 0.8f);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -