// This file is part of the Noddybox.Emulation C# suite. // // Noddybox.Emulation is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Noddybox.Emulation is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Noddybox.Emulation. If not, see . // // Copyright (c) 2012 Ian Cowburn // using System; using System.IO; namespace Noddybox.Emulation.Keyboard.Schema { /// /// Provides an element for the keyboard definition. /// public class KeyboardKey { #region Properties /// /// The symbol the key will be represented by in an enumerated type. /// Type checking will only be performed by the actual keyboard implementation /// where the value will be used as a key (the other sort). /// public string KeySymbol {get; set;} /// /// The X-offset of the hit box /// public int X { get; set; } /// /// The Y-offset of the hit box /// public int Y { get; set; } /// /// The width of the hit box /// public int Width { get; set; } /// /// The height of the hit box /// public int Height { get; set; } /// /// Whether the key is sticky (stays pressed until pressed again). /// public bool Sticky { get; set; } #endregion #region Load/Save /// /// Save this object to a stream. /// /// The stream to write to. public void Save(BinaryWriter stream) { stream.Write(KeySymbol); stream.Write(X); stream.Write(Y); stream.Write(Width); stream.Write(Height); stream.Write(Sticky); } /// /// Create an instance of this object from a stream. /// /// The stream to read from. /// The KeyboardKey object. public static KeyboardKey Load(BinaryReader stream) { KeyboardKey key = new KeyboardKey(); key.KeySymbol = stream.ReadString(); key.X = stream.ReadInt32(); key.Y = stream.ReadInt32(); key.Width = stream.ReadInt32(); key.Height = stream.ReadInt32(); key.Sticky = stream.ReadBoolean(); return key; } #endregion #region Object overrides public override string ToString() { return KeySymbol; } #endregion } }