EditorSettings.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using BansheeEngine;
  12. namespace BansheeEditor
  13. {
  14. /// <summary>
  15. /// Contains various settings that are applied globally to the editor. Settings will persist through editor sessions.
  16. /// </summary>
  17. internal static class EditorSettings
  18. {
  19. /// <summary>
  20. /// Determines if snapping for move handle is active. When active the move handle can only be moved in increments
  21. /// specified by <see cref="MoveHandleSnapAmount"/>.
  22. /// </summary>
  23. public static bool MoveHandleSnapActive
  24. {
  25. get { return Internal_GetMoveHandleSnapActive(); }
  26. set { Internal_SetMoveHandleSnapActive(value); }
  27. }
  28. /// <summary>
  29. /// Determines if snapping for rotate handle is active. When active the rotate handle can only be rotated in
  30. /// increments specified by <see cref="RotateHandleSnapAmount"/>.
  31. /// </summary>
  32. public static bool RotateHandleSnapActive
  33. {
  34. get { return Internal_GetRotateHandleSnapActive(); }
  35. set { Internal_SetRotateHandleSnapActive(value); }
  36. }
  37. /// <summary>
  38. /// Determines size of the increments the move handle can be moved when <see cref="MoveHandleSnapActive"/> is
  39. /// active.
  40. /// </summary>
  41. public static float MoveHandleSnapAmount
  42. {
  43. get { return Internal_GetMoveHandleSnapAmount(); }
  44. set { Internal_SetMoveHandleSnapAmount(value); }
  45. }
  46. /// <summary>
  47. /// Determines size of the increments the rotate handle can be moved when <see cref="RotateHandleSnapActive"/> is
  48. /// active.
  49. /// </summary>
  50. public static Degree RotateHandleSnapAmount
  51. {
  52. get { return Internal_GetRotateHandleSnapAmount(); }
  53. set { Internal_SetRotateHandleSnapAmount(value.Degrees); }
  54. }
  55. /// <summary>
  56. /// Determines the default size for all handles.
  57. /// </summary>
  58. public static float DefaultHandleSize
  59. {
  60. get { return Internal_GetDefaultHandleSize(); }
  61. set { Internal_SetDefaultHandleSize(value); }
  62. }
  63. /// <summary>
  64. /// Determines the active tool shown in the scene view.
  65. /// </summary>
  66. public static SceneViewTool ActiveSceneTool
  67. {
  68. get { return (SceneViewTool)Internal_GetActiveSceneTool(); }
  69. set { Internal_SetActiveSceneTool((int)value); }
  70. }
  71. /// <summary>
  72. /// Determines the coordinate mode used by the tools in the scene view.
  73. /// </summary>
  74. public static HandleCoordinateMode ActiveCoordinateMode
  75. {
  76. get { return (HandleCoordinateMode)Internal_GetActiveCoordinateMode(); }
  77. set { Internal_SetActiveCoordinateMode((int)value); }
  78. }
  79. /// <summary>
  80. /// Determines the pivot mode used by the tools in the scene view.
  81. /// </summary>
  82. public static HandlePivotMode ActivePivotMode
  83. {
  84. get { return (HandlePivotMode)Internal_GetActivePivotMode(); }
  85. set { Internal_SetActivePivotMode((int)value); }
  86. }
  87. /// <summary>
  88. /// Maximum number of frames per second the editor is allowed to execute. Zero means infinite.
  89. /// </summary>
  90. public static int FPSLimit
  91. {
  92. get { return Internal_GetFPSLimit(); }
  93. set { Internal_SetFPSLimit(value); }
  94. }
  95. /// <summary>
  96. /// Contains the absolute path to the last open project, if any.
  97. /// </summary>
  98. public static string LastOpenProject
  99. {
  100. get { return Internal_GetLastOpenProject(); }
  101. set { Internal_SetLastOpenProject(value); }
  102. }
  103. /// <summary>
  104. /// Determines should the last open project be automatically loaded on editor startup.
  105. /// </summary>
  106. public static bool AutoLoadLastProject
  107. {
  108. get { return Internal_GetAutoLoadLastProject(); }
  109. set { Internal_SetAutoLoadLastProject(value); }
  110. }
  111. /// <summary>
  112. /// Contains a list of most recently loaded projects.
  113. /// </summary>
  114. public static RecentProject[] RecentProjects
  115. {
  116. get
  117. {
  118. string[] paths;
  119. UInt64[] timeStamps;
  120. Internal_GetRecentProjects(out paths, out timeStamps);
  121. RecentProject[] output = new RecentProject[paths.Length];
  122. for (int i = 0; i < paths.Length; i++)
  123. output[i] = new RecentProject(paths[i], timeStamps[i]);
  124. return output;
  125. }
  126. set
  127. {
  128. int numEntries = 0;
  129. if (value != null)
  130. numEntries = value.Length;
  131. string[] paths = new string[numEntries];
  132. UInt64[] timeStamps = new UInt64[numEntries];
  133. for (int i = 0; i < numEntries; i++)
  134. {
  135. paths[i] = value[i].path;
  136. timeStamps[i] = value[i].accessTimestamp;
  137. }
  138. Internal_SetRecentProjects(paths, timeStamps);
  139. }
  140. }
  141. /// <summary>
  142. /// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
  143. /// external systems to track when they might need to reload the settings.
  144. /// </summary>
  145. public static int Hash
  146. {
  147. get { return Internal_GetHash(); }
  148. }
  149. /// <summary>
  150. /// Sets a generic floating point property.
  151. /// </summary>
  152. /// <param name="name">Name to record the property under.</param>
  153. /// <param name="value">Value of the property.</param>
  154. public static void SetFloat(string name, float value)
  155. {
  156. Internal_SetFloat(name, value);
  157. }
  158. /// <summary>
  159. /// Sets a generic integer property.
  160. /// </summary>
  161. /// <param name="name">Name to record the property under.</param>
  162. /// <param name="value">Value of the property.</param>
  163. public static void SetInt(string name, int value)
  164. {
  165. Internal_SetInt(name, value);
  166. }
  167. /// <summary>
  168. /// Sets a generic boolean property.
  169. /// </summary>
  170. /// <param name="name">Name to record the property under.</param>
  171. /// <param name="value">Value of the property.</param>
  172. public static void SetBool(string name, bool value)
  173. {
  174. Internal_SetBool(name, value);
  175. }
  176. /// <summary>
  177. /// Sets a generic string property.
  178. /// </summary>
  179. /// <param name="name">Name to record the property under.</param>
  180. /// <param name="value">Value of the property.</param>
  181. public static void SetString(string name, String value)
  182. {
  183. Internal_SetString(name, value);
  184. }
  185. /// <summary>
  186. /// Retrieves a generic floating point property.
  187. /// </summary>
  188. /// <param name="name">Name of the property to retrieve.</param>
  189. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  190. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  191. public static float GetFloat(string name, float defaultValue = 0.0f)
  192. {
  193. return Internal_GetFloat(name, defaultValue);
  194. }
  195. /// <summary>
  196. /// Retrieves a generic integer property.
  197. /// </summary>
  198. /// <param name="name">Name of the property to retrieve.</param>
  199. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  200. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  201. public static int GetInt(string name, int defaultValue = 0)
  202. {
  203. return Internal_GetInt(name, defaultValue);
  204. }
  205. /// <summary>
  206. /// Retrieves a generic boolean property.
  207. /// </summary>
  208. /// <param name="name">Name of the property to retrieve.</param>
  209. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  210. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  211. public static bool GetBool(string name, bool defaultValue = false)
  212. {
  213. return Internal_GetBool(name, defaultValue);
  214. }
  215. /// <summary>
  216. /// Retrieves a generic string property.
  217. /// </summary>
  218. /// <param name="name">Name of the property to retrieve.</param>
  219. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  220. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  221. public static String GetString(string name, string defaultValue = "")
  222. {
  223. return Internal_GetString(name, defaultValue);
  224. }
  225. /// <summary>
  226. /// Checks does a generic property with the specified name exists.
  227. /// </summary>
  228. /// <param name="name">Name of the property to check.</param>
  229. /// <returns>True if the property exists, false otherwise.</returns>
  230. public static bool HasKey(string name)
  231. {
  232. return Internal_HasKey(name);
  233. }
  234. /// <summary>
  235. /// Deletes a generic property with the specified name.
  236. /// </summary>
  237. /// <param name="name">Name of the property to delete.</param>
  238. public static void DeleteKey(string name)
  239. {
  240. Internal_DeleteKey(name);
  241. }
  242. /// <summary>
  243. /// Deletes all generic properties.
  244. /// </summary>
  245. public static void DeleteAllKeys()
  246. {
  247. Internal_DeleteAllKeys();
  248. }
  249. /// <summary>
  250. /// Saves editor settings to the disk.
  251. /// </summary>
  252. public static void Save()
  253. {
  254. Internal_Save();
  255. }
  256. [MethodImpl(MethodImplOptions.InternalCall)]
  257. private static extern bool Internal_GetMoveHandleSnapActive();
  258. [MethodImpl(MethodImplOptions.InternalCall)]
  259. private static extern void Internal_SetMoveHandleSnapActive(bool value);
  260. [MethodImpl(MethodImplOptions.InternalCall)]
  261. private static extern bool Internal_GetRotateHandleSnapActive();
  262. [MethodImpl(MethodImplOptions.InternalCall)]
  263. private static extern void Internal_SetRotateHandleSnapActive(bool value);
  264. [MethodImpl(MethodImplOptions.InternalCall)]
  265. private static extern float Internal_GetMoveHandleSnapAmount();
  266. [MethodImpl(MethodImplOptions.InternalCall)]
  267. private static extern void Internal_SetMoveHandleSnapAmount(float value);
  268. [MethodImpl(MethodImplOptions.InternalCall)]
  269. private static extern float Internal_GetRotateHandleSnapAmount();
  270. [MethodImpl(MethodImplOptions.InternalCall)]
  271. private static extern void Internal_SetRotateHandleSnapAmount(float value);
  272. [MethodImpl(MethodImplOptions.InternalCall)]
  273. private static extern float Internal_GetDefaultHandleSize();
  274. [MethodImpl(MethodImplOptions.InternalCall)]
  275. private static extern void Internal_SetDefaultHandleSize(float value);
  276. [MethodImpl(MethodImplOptions.InternalCall)]
  277. private static extern int Internal_GetActiveSceneTool();
  278. [MethodImpl(MethodImplOptions.InternalCall)]
  279. private static extern void Internal_SetActiveSceneTool(int value);
  280. [MethodImpl(MethodImplOptions.InternalCall)]
  281. private static extern int Internal_GetActiveCoordinateMode();
  282. [MethodImpl(MethodImplOptions.InternalCall)]
  283. private static extern void Internal_SetActiveCoordinateMode(int value);
  284. [MethodImpl(MethodImplOptions.InternalCall)]
  285. private static extern int Internal_GetActivePivotMode();
  286. [MethodImpl(MethodImplOptions.InternalCall)]
  287. private static extern void Internal_SetActivePivotMode(int value);
  288. [MethodImpl(MethodImplOptions.InternalCall)]
  289. private static extern int Internal_GetFPSLimit();
  290. [MethodImpl(MethodImplOptions.InternalCall)]
  291. private static extern void Internal_SetFPSLimit(int value);
  292. [MethodImpl(MethodImplOptions.InternalCall)]
  293. private static extern string Internal_GetLastOpenProject();
  294. [MethodImpl(MethodImplOptions.InternalCall)]
  295. private static extern void Internal_SetLastOpenProject(string value);
  296. [MethodImpl(MethodImplOptions.InternalCall)]
  297. private static extern bool Internal_GetAutoLoadLastProject();
  298. [MethodImpl(MethodImplOptions.InternalCall)]
  299. private static extern void Internal_SetAutoLoadLastProject(bool value);
  300. [MethodImpl(MethodImplOptions.InternalCall)]
  301. private static extern void Internal_GetRecentProjects(out string[] paths, out UInt64[] timestamps);
  302. [MethodImpl(MethodImplOptions.InternalCall)]
  303. private static extern void Internal_SetRecentProjects(string[] paths, UInt64[] timestamps);
  304. [MethodImpl(MethodImplOptions.InternalCall)]
  305. private static extern void Internal_SetFloat(string name, float value);
  306. [MethodImpl(MethodImplOptions.InternalCall)]
  307. private static extern void Internal_SetInt(string name, int value);
  308. [MethodImpl(MethodImplOptions.InternalCall)]
  309. private static extern void Internal_SetBool(string name, bool value);
  310. [MethodImpl(MethodImplOptions.InternalCall)]
  311. private static extern void Internal_SetString(string name, String value);
  312. [MethodImpl(MethodImplOptions.InternalCall)]
  313. private static extern float Internal_GetFloat(string name, float defaultValue);
  314. [MethodImpl(MethodImplOptions.InternalCall)]
  315. private static extern int Internal_GetInt(string name, int defaultValue);
  316. [MethodImpl(MethodImplOptions.InternalCall)]
  317. private static extern bool Internal_GetBool(string name, bool defaultValue);
  318. [MethodImpl(MethodImplOptions.InternalCall)]
  319. private static extern string Internal_GetString(string name, string defaultValue);
  320. [MethodImpl(MethodImplOptions.InternalCall)]
  321. private static extern bool Internal_HasKey(string name);
  322. [MethodImpl(MethodImplOptions.InternalCall)]
  323. private static extern void Internal_DeleteKey(string name);
  324. [MethodImpl(MethodImplOptions.InternalCall)]
  325. private static extern void Internal_DeleteAllKeys();
  326. [MethodImpl(MethodImplOptions.InternalCall)]
  327. private static extern int Internal_GetHash();
  328. [MethodImpl(MethodImplOptions.InternalCall)]
  329. private static extern void Internal_Save();
  330. }
  331. /// <summary>
  332. /// Contains data about a recently opened project.
  333. /// </summary>
  334. [StructLayout(LayoutKind.Sequential)]
  335. public struct RecentProject // Note: Must match C++ struct RecentProject
  336. {
  337. /// <summary>
  338. /// Constructs a new recently opened project object.
  339. /// </summary>
  340. /// <param name="path">Absolute path to the project.</param>
  341. /// <param name="timestamp">Timestamp when the project was last opened.</param>
  342. public RecentProject(string path, UInt64 timestamp)
  343. {
  344. this.path = path;
  345. this.accessTimestamp = timestamp;
  346. }
  347. public string path;
  348. public UInt64 accessTimestamp;
  349. }
  350. }