EditorSettings.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. /// Controls sensitivity of mouse movements in the editor. This doesn't apply to mouse cursor.
  97. /// Default value is 1.0f.
  98. /// </summary>
  99. public static float MouseSensitivity
  100. {
  101. get { return Internal_GetMouseSensitivity(); }
  102. set { Internal_SetMouseSensitivity(value); }
  103. }
  104. /// <summary>
  105. /// Contains the absolute path to the last open project, if any.
  106. /// </summary>
  107. public static string LastOpenProject
  108. {
  109. get { return Internal_GetLastOpenProject(); }
  110. set { Internal_SetLastOpenProject(value); }
  111. }
  112. /// <summary>
  113. /// Determines should the last open project be automatically loaded on editor startup.
  114. /// </summary>
  115. public static bool AutoLoadLastProject
  116. {
  117. get { return Internal_GetAutoLoadLastProject(); }
  118. set { Internal_SetAutoLoadLastProject(value); }
  119. }
  120. /// <summary>
  121. /// Contains a list of most recently loaded projects.
  122. /// </summary>
  123. public static RecentProject[] RecentProjects
  124. {
  125. get
  126. {
  127. string[] paths;
  128. UInt64[] timeStamps;
  129. Internal_GetRecentProjects(out paths, out timeStamps);
  130. RecentProject[] output = new RecentProject[paths.Length];
  131. for (int i = 0; i < paths.Length; i++)
  132. output[i] = new RecentProject(paths[i], timeStamps[i]);
  133. return output;
  134. }
  135. set
  136. {
  137. int numEntries = 0;
  138. if (value != null)
  139. numEntries = value.Length;
  140. string[] paths = new string[numEntries];
  141. UInt64[] timeStamps = new UInt64[numEntries];
  142. for (int i = 0; i < numEntries; i++)
  143. {
  144. paths[i] = value[i].path;
  145. timeStamps[i] = value[i].accessTimestamp;
  146. }
  147. Internal_SetRecentProjects(paths, timeStamps);
  148. }
  149. }
  150. /// <summary>
  151. /// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
  152. /// external systems to track when they might need to reload the settings.
  153. /// </summary>
  154. public static int Hash
  155. {
  156. get { return Internal_GetHash(); }
  157. }
  158. /// <summary>
  159. /// Sets a generic floating point 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 SetFloat(string name, float value)
  164. {
  165. Internal_SetFloat(name, value);
  166. }
  167. /// <summary>
  168. /// Sets a generic integer 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 SetInt(string name, int value)
  173. {
  174. Internal_SetInt(name, value);
  175. }
  176. /// <summary>
  177. /// Sets a generic boolean 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 SetBool(string name, bool value)
  182. {
  183. Internal_SetBool(name, value);
  184. }
  185. /// <summary>
  186. /// Sets a generic string property.
  187. /// </summary>
  188. /// <param name="name">Name to record the property under.</param>
  189. /// <param name="value">Value of the property.</param>
  190. public static void SetString(string name, String value)
  191. {
  192. Internal_SetString(name, value);
  193. }
  194. /// <summary>
  195. /// Retrieves a generic floating point property.
  196. /// </summary>
  197. /// <param name="name">Name of the property to retrieve.</param>
  198. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  199. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  200. public static float GetFloat(string name, float defaultValue = 0.0f)
  201. {
  202. return Internal_GetFloat(name, defaultValue);
  203. }
  204. /// <summary>
  205. /// Retrieves a generic integer property.
  206. /// </summary>
  207. /// <param name="name">Name of the property to retrieve.</param>
  208. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  209. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  210. public static int GetInt(string name, int defaultValue = 0)
  211. {
  212. return Internal_GetInt(name, defaultValue);
  213. }
  214. /// <summary>
  215. /// Retrieves a generic boolean property.
  216. /// </summary>
  217. /// <param name="name">Name of the property to retrieve.</param>
  218. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  219. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  220. public static bool GetBool(string name, bool defaultValue = false)
  221. {
  222. return Internal_GetBool(name, defaultValue);
  223. }
  224. /// <summary>
  225. /// Retrieves a generic string property.
  226. /// </summary>
  227. /// <param name="name">Name of the property to retrieve.</param>
  228. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  229. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  230. public static String GetString(string name, string defaultValue = "")
  231. {
  232. return Internal_GetString(name, defaultValue);
  233. }
  234. /// <summary>
  235. /// Checks does a generic property with the specified name exists.
  236. /// </summary>
  237. /// <param name="name">Name of the property to check.</param>
  238. /// <returns>True if the property exists, false otherwise.</returns>
  239. public static bool HasKey(string name)
  240. {
  241. return Internal_HasKey(name);
  242. }
  243. /// <summary>
  244. /// Deletes a generic property with the specified name.
  245. /// </summary>
  246. /// <param name="name">Name of the property to delete.</param>
  247. public static void DeleteKey(string name)
  248. {
  249. Internal_DeleteKey(name);
  250. }
  251. /// <summary>
  252. /// Deletes all generic properties.
  253. /// </summary>
  254. public static void DeleteAllKeys()
  255. {
  256. Internal_DeleteAllKeys();
  257. }
  258. /// <summary>
  259. /// Saves editor settings to the disk.
  260. /// </summary>
  261. public static void Save()
  262. {
  263. Internal_Save();
  264. }
  265. [MethodImpl(MethodImplOptions.InternalCall)]
  266. private static extern bool Internal_GetMoveHandleSnapActive();
  267. [MethodImpl(MethodImplOptions.InternalCall)]
  268. private static extern void Internal_SetMoveHandleSnapActive(bool value);
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern bool Internal_GetRotateHandleSnapActive();
  271. [MethodImpl(MethodImplOptions.InternalCall)]
  272. private static extern void Internal_SetRotateHandleSnapActive(bool value);
  273. [MethodImpl(MethodImplOptions.InternalCall)]
  274. private static extern float Internal_GetMoveHandleSnapAmount();
  275. [MethodImpl(MethodImplOptions.InternalCall)]
  276. private static extern void Internal_SetMoveHandleSnapAmount(float value);
  277. [MethodImpl(MethodImplOptions.InternalCall)]
  278. private static extern float Internal_GetRotateHandleSnapAmount();
  279. [MethodImpl(MethodImplOptions.InternalCall)]
  280. private static extern void Internal_SetRotateHandleSnapAmount(float value);
  281. [MethodImpl(MethodImplOptions.InternalCall)]
  282. private static extern float Internal_GetDefaultHandleSize();
  283. [MethodImpl(MethodImplOptions.InternalCall)]
  284. private static extern void Internal_SetDefaultHandleSize(float value);
  285. [MethodImpl(MethodImplOptions.InternalCall)]
  286. private static extern int Internal_GetActiveSceneTool();
  287. [MethodImpl(MethodImplOptions.InternalCall)]
  288. private static extern void Internal_SetActiveSceneTool(int value);
  289. [MethodImpl(MethodImplOptions.InternalCall)]
  290. private static extern int Internal_GetActiveCoordinateMode();
  291. [MethodImpl(MethodImplOptions.InternalCall)]
  292. private static extern void Internal_SetActiveCoordinateMode(int value);
  293. [MethodImpl(MethodImplOptions.InternalCall)]
  294. private static extern int Internal_GetActivePivotMode();
  295. [MethodImpl(MethodImplOptions.InternalCall)]
  296. private static extern void Internal_SetActivePivotMode(int value);
  297. [MethodImpl(MethodImplOptions.InternalCall)]
  298. private static extern int Internal_GetFPSLimit();
  299. [MethodImpl(MethodImplOptions.InternalCall)]
  300. private static extern void Internal_SetFPSLimit(int value);
  301. [MethodImpl(MethodImplOptions.InternalCall)]
  302. private static extern float Internal_GetMouseSensitivity();
  303. [MethodImpl(MethodImplOptions.InternalCall)]
  304. private static extern void Internal_SetMouseSensitivity(float value);
  305. [MethodImpl(MethodImplOptions.InternalCall)]
  306. private static extern string Internal_GetLastOpenProject();
  307. [MethodImpl(MethodImplOptions.InternalCall)]
  308. private static extern void Internal_SetLastOpenProject(string value);
  309. [MethodImpl(MethodImplOptions.InternalCall)]
  310. private static extern bool Internal_GetAutoLoadLastProject();
  311. [MethodImpl(MethodImplOptions.InternalCall)]
  312. private static extern void Internal_SetAutoLoadLastProject(bool value);
  313. [MethodImpl(MethodImplOptions.InternalCall)]
  314. private static extern void Internal_GetRecentProjects(out string[] paths, out UInt64[] timestamps);
  315. [MethodImpl(MethodImplOptions.InternalCall)]
  316. private static extern void Internal_SetRecentProjects(string[] paths, UInt64[] timestamps);
  317. [MethodImpl(MethodImplOptions.InternalCall)]
  318. private static extern void Internal_SetFloat(string name, float value);
  319. [MethodImpl(MethodImplOptions.InternalCall)]
  320. private static extern void Internal_SetInt(string name, int value);
  321. [MethodImpl(MethodImplOptions.InternalCall)]
  322. private static extern void Internal_SetBool(string name, bool value);
  323. [MethodImpl(MethodImplOptions.InternalCall)]
  324. private static extern void Internal_SetString(string name, String value);
  325. [MethodImpl(MethodImplOptions.InternalCall)]
  326. private static extern float Internal_GetFloat(string name, float defaultValue);
  327. [MethodImpl(MethodImplOptions.InternalCall)]
  328. private static extern int Internal_GetInt(string name, int defaultValue);
  329. [MethodImpl(MethodImplOptions.InternalCall)]
  330. private static extern bool Internal_GetBool(string name, bool defaultValue);
  331. [MethodImpl(MethodImplOptions.InternalCall)]
  332. private static extern string Internal_GetString(string name, string defaultValue);
  333. [MethodImpl(MethodImplOptions.InternalCall)]
  334. private static extern bool Internal_HasKey(string name);
  335. [MethodImpl(MethodImplOptions.InternalCall)]
  336. private static extern void Internal_DeleteKey(string name);
  337. [MethodImpl(MethodImplOptions.InternalCall)]
  338. private static extern void Internal_DeleteAllKeys();
  339. [MethodImpl(MethodImplOptions.InternalCall)]
  340. private static extern int Internal_GetHash();
  341. [MethodImpl(MethodImplOptions.InternalCall)]
  342. private static extern void Internal_Save();
  343. }
  344. /// <summary>
  345. /// Contains data about a recently opened project.
  346. /// </summary>
  347. [StructLayout(LayoutKind.Sequential)]
  348. public struct RecentProject // Note: Must match C++ struct RecentProject
  349. {
  350. /// <summary>
  351. /// Constructs a new recently opened project object.
  352. /// </summary>
  353. /// <param name="path">Absolute path to the project.</param>
  354. /// <param name="timestamp">Timestamp when the project was last opened.</param>
  355. public RecentProject(string path, UInt64 timestamp)
  356. {
  357. this.path = path;
  358. this.accessTimestamp = timestamp;
  359. }
  360. public string path;
  361. public UInt64 accessTimestamp;
  362. }
  363. }