EditorSettings.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 BansheeEngine;
  7. namespace BansheeEditor
  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. /// Retrieves a generic floating point property.
  194. /// </summary>
  195. /// <param name="name">Name of the property to retrieve.</param>
  196. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  197. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  198. public static float GetFloat(string name, float defaultValue = 0.0f)
  199. {
  200. return Internal_GetFloat(name, defaultValue);
  201. }
  202. /// <summary>
  203. /// Retrieves a generic integer 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 int GetInt(string name, int defaultValue = 0)
  209. {
  210. return Internal_GetInt(name, defaultValue);
  211. }
  212. /// <summary>
  213. /// Retrieves a generic boolean 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 bool GetBool(string name, bool defaultValue = false)
  219. {
  220. return Internal_GetBool(name, defaultValue);
  221. }
  222. /// <summary>
  223. /// Retrieves a generic string 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 String GetString(string name, string defaultValue = "")
  229. {
  230. return Internal_GetString(name, defaultValue);
  231. }
  232. /// <summary>
  233. /// Checks does a generic property with the specified name exists.
  234. /// </summary>
  235. /// <param name="name">Name of the property to check.</param>
  236. /// <returns>True if the property exists, false otherwise.</returns>
  237. public static bool HasKey(string name)
  238. {
  239. return Internal_HasKey(name);
  240. }
  241. /// <summary>
  242. /// Deletes a generic property with the specified name.
  243. /// </summary>
  244. /// <param name="name">Name of the property to delete.</param>
  245. public static void DeleteKey(string name)
  246. {
  247. Internal_DeleteKey(name);
  248. }
  249. /// <summary>
  250. /// Deletes all generic properties.
  251. /// </summary>
  252. public static void DeleteAllKeys()
  253. {
  254. Internal_DeleteAllKeys();
  255. }
  256. /// <summary>
  257. /// Saves editor settings to the disk.
  258. /// </summary>
  259. public static void Save()
  260. {
  261. Internal_Save();
  262. }
  263. [MethodImpl(MethodImplOptions.InternalCall)]
  264. private static extern bool Internal_GetMoveHandleSnapActive();
  265. [MethodImpl(MethodImplOptions.InternalCall)]
  266. private static extern void Internal_SetMoveHandleSnapActive(bool value);
  267. [MethodImpl(MethodImplOptions.InternalCall)]
  268. private static extern bool Internal_GetRotateHandleSnapActive();
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern void Internal_SetRotateHandleSnapActive(bool value);
  271. [MethodImpl(MethodImplOptions.InternalCall)]
  272. private static extern float Internal_GetMoveHandleSnapAmount();
  273. [MethodImpl(MethodImplOptions.InternalCall)]
  274. private static extern void Internal_SetMoveHandleSnapAmount(float value);
  275. [MethodImpl(MethodImplOptions.InternalCall)]
  276. private static extern float Internal_GetRotateHandleSnapAmount();
  277. [MethodImpl(MethodImplOptions.InternalCall)]
  278. private static extern void Internal_SetRotateHandleSnapAmount(float value);
  279. [MethodImpl(MethodImplOptions.InternalCall)]
  280. private static extern float Internal_GetDefaultHandleSize();
  281. [MethodImpl(MethodImplOptions.InternalCall)]
  282. private static extern void Internal_SetDefaultHandleSize(float value);
  283. [MethodImpl(MethodImplOptions.InternalCall)]
  284. private static extern int Internal_GetActiveSceneTool();
  285. [MethodImpl(MethodImplOptions.InternalCall)]
  286. private static extern void Internal_SetActiveSceneTool(int value);
  287. [MethodImpl(MethodImplOptions.InternalCall)]
  288. private static extern int Internal_GetActiveCoordinateMode();
  289. [MethodImpl(MethodImplOptions.InternalCall)]
  290. private static extern void Internal_SetActiveCoordinateMode(int value);
  291. [MethodImpl(MethodImplOptions.InternalCall)]
  292. private static extern int Internal_GetActivePivotMode();
  293. [MethodImpl(MethodImplOptions.InternalCall)]
  294. private static extern void Internal_SetActivePivotMode(int value);
  295. [MethodImpl(MethodImplOptions.InternalCall)]
  296. private static extern int Internal_GetFPSLimit();
  297. [MethodImpl(MethodImplOptions.InternalCall)]
  298. private static extern void Internal_SetFPSLimit(int value);
  299. [MethodImpl(MethodImplOptions.InternalCall)]
  300. private static extern float Internal_GetMouseSensitivity();
  301. [MethodImpl(MethodImplOptions.InternalCall)]
  302. private static extern void Internal_SetMouseSensitivity(float value);
  303. [MethodImpl(MethodImplOptions.InternalCall)]
  304. private static extern string Internal_GetLastOpenProject();
  305. [MethodImpl(MethodImplOptions.InternalCall)]
  306. private static extern void Internal_SetLastOpenProject(string value);
  307. [MethodImpl(MethodImplOptions.InternalCall)]
  308. private static extern bool Internal_GetAutoLoadLastProject();
  309. [MethodImpl(MethodImplOptions.InternalCall)]
  310. private static extern void Internal_SetAutoLoadLastProject(bool value);
  311. [MethodImpl(MethodImplOptions.InternalCall)]
  312. private static extern void Internal_GetRecentProjects(out string[] paths, out UInt64[] timestamps);
  313. [MethodImpl(MethodImplOptions.InternalCall)]
  314. private static extern void Internal_SetRecentProjects(string[] paths, UInt64[] timestamps);
  315. [MethodImpl(MethodImplOptions.InternalCall)]
  316. private static extern void Internal_SetFloat(string name, float value);
  317. [MethodImpl(MethodImplOptions.InternalCall)]
  318. private static extern void Internal_SetInt(string name, int value);
  319. [MethodImpl(MethodImplOptions.InternalCall)]
  320. private static extern void Internal_SetBool(string name, bool value);
  321. [MethodImpl(MethodImplOptions.InternalCall)]
  322. private static extern void Internal_SetString(string name, String value);
  323. [MethodImpl(MethodImplOptions.InternalCall)]
  324. private static extern float Internal_GetFloat(string name, float defaultValue);
  325. [MethodImpl(MethodImplOptions.InternalCall)]
  326. private static extern int Internal_GetInt(string name, int defaultValue);
  327. [MethodImpl(MethodImplOptions.InternalCall)]
  328. private static extern bool Internal_GetBool(string name, bool defaultValue);
  329. [MethodImpl(MethodImplOptions.InternalCall)]
  330. private static extern string Internal_GetString(string name, string defaultValue);
  331. [MethodImpl(MethodImplOptions.InternalCall)]
  332. private static extern bool Internal_HasKey(string name);
  333. [MethodImpl(MethodImplOptions.InternalCall)]
  334. private static extern void Internal_DeleteKey(string name);
  335. [MethodImpl(MethodImplOptions.InternalCall)]
  336. private static extern void Internal_DeleteAllKeys();
  337. [MethodImpl(MethodImplOptions.InternalCall)]
  338. private static extern int Internal_GetHash();
  339. [MethodImpl(MethodImplOptions.InternalCall)]
  340. private static extern void Internal_Save();
  341. }
  342. /// <summary>
  343. /// Contains data about a recently opened project.
  344. /// </summary>
  345. [StructLayout(LayoutKind.Sequential)]
  346. public struct RecentProject // Note: Must match C++ struct RecentProject
  347. {
  348. /// <summary>
  349. /// Constructs a new recently opened project object.
  350. /// </summary>
  351. /// <param name="path">Absolute path to the project.</param>
  352. /// <param name="timestamp">Timestamp when the project was last opened.</param>
  353. public RecentProject(string path, UInt64 timestamp)
  354. {
  355. this.path = path;
  356. this.accessTimestamp = timestamp;
  357. }
  358. public string path;
  359. public UInt64 accessTimestamp;
  360. }
  361. /** @} */
  362. }