EditorSettings.cs 18 KB

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