ToolsWindow.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace AmplifyShaderEditor
  8. {
  9. public enum ToolButtonType
  10. {
  11. Update = 0,
  12. Live,
  13. OpenSourceCode,
  14. CleanUnusedNodes,
  15. //SelectShader,
  16. New,
  17. Open,
  18. Save,
  19. Library,
  20. Options,
  21. Help,
  22. MasterNode,
  23. FocusOnMasterNode,
  24. FocusOnSelection,
  25. ShowInfoWindow,
  26. ShowTipsWindow,
  27. ShowConsole,
  28. TakeScreenshot,
  29. Share
  30. }
  31. public enum ToolbarType
  32. {
  33. File,
  34. Help
  35. }
  36. public class ToolbarMenuTab
  37. {
  38. private Rect m_tabArea;
  39. private GenericMenu m_tabMenu;
  40. public ToolbarMenuTab( float x, float y, float width, float height )
  41. {
  42. m_tabMenu = new GenericMenu();
  43. m_tabArea = new Rect( x, y, width, height );
  44. }
  45. public void ShowMenu()
  46. {
  47. m_tabMenu.DropDown( m_tabArea );
  48. }
  49. public void AddItem( string itemName, GenericMenu.MenuFunction callback )
  50. {
  51. m_tabMenu.AddItem( new GUIContent( itemName ), false, callback );
  52. }
  53. }
  54. [Serializable]
  55. public sealed class ToolsWindow : MenuParent
  56. {
  57. private static readonly Color RightIconsColorOff = new Color( 1f, 1f, 1f, 0.8f );
  58. private static readonly Color LeftIconsColorOff = new Color( 1f, 1f, 1f, 0.5f );
  59. private static readonly Color RightIconsColorOn = new Color( 1f, 1f, 1f, 1.0f );
  60. private static readonly Color LeftIconsColorOn = new Color( 1f, 1f, 1f, 0.8f );
  61. private const float TabY = 9;
  62. private const float TabX = 5;
  63. private const string ShaderFileTitleStr = "Current Shader";
  64. private const string FileToolbarStr = "File";
  65. private const string HelpToolbarStr = "Help";
  66. private const string LiveShaderStr = "Live Shader";
  67. private const string LoadOnSelectionStr = "Load on selection";
  68. private const string CurrentObjectStr = "Current Object: ";
  69. public ToolsMenuButton.ToolButtonPressed ToolButtonPressedEvt;
  70. //private GUIStyle m_toolbarButtonStyle;
  71. private GUIStyle m_toggleStyle;
  72. private GUIStyle m_borderStyle;
  73. // left
  74. private ToolsMenuButton m_updateButton;
  75. private ToolsMenuButton m_liveButton;
  76. private ToolsMenuButton m_openSourceCodeButton;
  77. //middle right
  78. private ToolsMenuButton m_cleanUnusedNodesButton;
  79. private ToolsMenuButton m_focusOnMasterNodeButton;
  80. private ToolsMenuButton m_focusOnSelectionButton;
  81. // right
  82. private ToolsMenuButton m_shareButton;
  83. private ToolsMenuButton m_takeScreenshotButton;
  84. private ToolsMenuButton m_showInfoWindowButton;
  85. // hidden
  86. private ToolsMenuButton m_showTipsWindowButton;
  87. private ToolsMenuButton m_showConsoleWindowButton;
  88. //Used for collision detection to invalidate inputs on graph area
  89. private Rect m_areaLeft = new Rect( 0, 0, 140, 40 );
  90. private Rect m_areaRight = new Rect( 0, 0, 75, 40 );
  91. private Rect m_boxRect;
  92. private Rect m_borderRect;
  93. public const double InactivityRefreshTime = 0.25;
  94. private int m_currentSelected = 0;
  95. //Search Bar
  96. private const string SearchBarId = "ASE_SEARCH_BAR";
  97. private bool m_searchBarVisible = false;
  98. private bool m_selectSearchBarTextfield = false;
  99. private bool m_refreshSearchResultList = false;
  100. private Rect m_searchBarSize;
  101. private string m_searchBarValue = string.Empty;
  102. private List<ParentNode> m_searchResultNodes = new List<ParentNode>();
  103. // width and height are between [0,1] and represent a percentage of the total screen area
  104. public ToolsWindow( AmplifyShaderEditorWindow parentWindow ) : base( parentWindow, 0, 0, 0, 64, "Tools", MenuAnchor.TOP_LEFT, MenuAutoSize.NONE )
  105. {
  106. m_updateButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Update, 0, 0, -1, -1, IOUtils.UpdateOutdatedGUID, string.Empty, "Create and apply shader to material.", 5 );
  107. m_updateButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  108. m_updateButton.AddState( IOUtils.UpdateOFFGUID );
  109. m_updateButton.AddState( IOUtils.UpdateUpToDatedGUID );
  110. m_liveButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Live, 0, 0, -1, -1, IOUtils.LiveOffGUID, string.Empty, "Automatically saves shader when canvas is changed.", 50 );
  111. m_liveButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  112. m_liveButton.AddState( IOUtils.LiveOnGUID );
  113. m_liveButton.AddState( IOUtils.LivePendingGUID );
  114. //ToolsMenuButton cleanUnusedNodesButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.CleanUnusedNodes, 0, 0, -1, -1, IOUtils.CleanupOFFGUID, string.Empty, "Remove all nodes not connected to the master node.", 77 );
  115. //cleanUnusedNodesButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  116. //cleanUnusedNodesButton.AddState( IOUtils.CleanUpOnGUID );
  117. //m_list[ ( int ) ToolButtonType.CleanUnusedNodes ] = cleanUnusedNodesButton;
  118. m_openSourceCodeButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.OpenSourceCode, 0, 0, -1, -1, IOUtils.OpenSourceCodeOFFGUID, string.Empty, "Open shader file in your default shader editor.", 80, false );
  119. m_openSourceCodeButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  120. m_openSourceCodeButton.AddState( IOUtils.OpenSourceCodeONGUID );
  121. // middle right
  122. m_cleanUnusedNodesButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.CleanUnusedNodes, 0, 0, -1, -1, IOUtils.CleanupOFFGUID, string.Empty, "Remove all nodes not connected to the master node.", 77 );
  123. m_cleanUnusedNodesButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  124. m_cleanUnusedNodesButton.AddState( IOUtils.CleanUpOnGUID );
  125. m_focusOnMasterNodeButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.FocusOnMasterNode, 0, 0, -1, -1, IOUtils.FocusNodeGUID, string.Empty, "Focus on active master node.", -1, false );
  126. m_focusOnMasterNodeButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  127. m_focusOnSelectionButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.FocusOnSelection, 0, 0, -1, -1, IOUtils.FitViewGUID, string.Empty, "Focus on selection or fit to screen if none selected." );
  128. m_focusOnSelectionButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  129. // right
  130. m_shareButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.Share, 0, 0, -1, -1, IOUtils.ShareOFFGUID, string.Empty, "Share selection", 100 );
  131. m_shareButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  132. m_shareButton.AddState( IOUtils.ShareONGUID );
  133. m_takeScreenshotButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.TakeScreenshot, 0, 0, -1, -1, IOUtils.TakeScreenshotOFFGUID, string.Empty, "Take ScreenShot (WINDOWS ONLY).", 100 );
  134. m_takeScreenshotButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  135. m_takeScreenshotButton.AddState( IOUtils.TakeScreenshotONGUID );
  136. m_showInfoWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowInfoWindow, 0, 0, -1, -1, IOUtils.ShowInfoWindowGUID, string.Empty, "Open Helper Window." );
  137. m_showInfoWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  138. // hidden
  139. m_showTipsWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowTipsWindow, 0, 0, -1, -1, IOUtils.ShowTipsWindowGUID, string.Empty, "Open Quick Tips!" );
  140. m_showTipsWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  141. m_showConsoleWindowButton = new ToolsMenuButton( m_parentWindow, ToolButtonType.ShowConsole, 0, 0, -1, -1, IOUtils.ShowConsoleWindowGUID, string.Empty, "Show internal console", 74 );
  142. m_showConsoleWindowButton.ToolButtonPressedEvt += OnButtonPressedEvent;
  143. m_showConsoleWindowButton.AddState( IOUtils.ShowConsoleWindowGUID );
  144. m_searchBarSize = new Rect( 0, TabY + 4, 110, 60 );
  145. }
  146. void OnShowPortLegend()
  147. {
  148. ParentWindow.ShowPortInfo();
  149. }
  150. override public void Destroy()
  151. {
  152. base.Destroy();
  153. //for ( int i = 0; i < m_list.Length; i++ )
  154. //{
  155. // m_list[ i ].Destroy();
  156. //}
  157. //m_list = null;
  158. m_searchResultNodes.Clear();
  159. m_searchResultNodes = null;
  160. m_updateButton.Destroy();
  161. m_updateButton = null;
  162. m_liveButton.Destroy();
  163. m_liveButton = null;
  164. m_openSourceCodeButton.Destroy();
  165. m_openSourceCodeButton = null;
  166. m_focusOnMasterNodeButton.Destroy();
  167. m_focusOnMasterNodeButton = null;
  168. m_focusOnSelectionButton.Destroy();
  169. m_focusOnSelectionButton = null;
  170. m_showInfoWindowButton.Destroy();
  171. m_showInfoWindowButton = null;
  172. m_takeScreenshotButton.Destroy();
  173. m_takeScreenshotButton = null;
  174. m_shareButton.Destroy();
  175. m_shareButton = null;
  176. m_showTipsWindowButton.Destroy();
  177. m_showTipsWindowButton = null;
  178. m_cleanUnusedNodesButton.Destroy();
  179. m_cleanUnusedNodesButton = null;
  180. m_showConsoleWindowButton.Destroy();
  181. m_showConsoleWindowButton = null;
  182. }
  183. void OnButtonPressedEvent( ToolButtonType type )
  184. {
  185. if ( ToolButtonPressedEvt != null )
  186. ToolButtonPressedEvt( type );
  187. }
  188. public override void Draw( Rect parentPosition, Vector2 mousePosition, int mouseButtonId, bool hasKeyboadFocus )
  189. {
  190. base.Draw( parentPosition, mousePosition, mouseButtonId, hasKeyboadFocus );
  191. Color bufferedColor = GUI.color;
  192. m_areaLeft.x = m_transformedArea.x + TabX;
  193. m_areaRight.x = m_transformedArea.x + m_transformedArea.width - 75 - TabX;
  194. //if ( m_toolbarButtonStyle == null )
  195. //{
  196. // m_toolbarButtonStyle = new GUIStyle( UIUtils.Button );
  197. // m_toolbarButtonStyle.fixedWidth = 100;
  198. //}
  199. if ( m_toggleStyle == null )
  200. {
  201. m_toggleStyle = UIUtils.Toggle;
  202. }
  203. //for ( int i = 0; i < m_list.Length; i++ )
  204. //{
  205. // GUI.color = m_list[ i ].IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
  206. // m_list[ i ].Draw( TabX + m_transformedArea.x + m_list[ i ].ButtonSpacing, TabY );
  207. //}
  208. GUI.color = m_updateButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
  209. m_updateButton.Draw( TabX + m_transformedArea.x + m_updateButton.ButtonSpacing, TabY );
  210. GUI.color = m_liveButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
  211. m_liveButton.Draw( TabX + m_transformedArea.x + m_liveButton.ButtonSpacing, TabY );
  212. GUI.color = m_openSourceCodeButton.IsInside( mousePosition ) ? LeftIconsColorOn : LeftIconsColorOff;
  213. m_openSourceCodeButton.Draw( TabX + m_transformedArea.x + m_openSourceCodeButton.ButtonSpacing, TabY );
  214. if ( m_searchBarVisible )
  215. {
  216. m_searchBarSize.x = m_transformedArea.x + m_transformedArea.width - 320 - TabX;
  217. string currentFocus = GUI.GetNameOfFocusedControl();
  218. if ( Event.current.type == EventType.KeyDown )
  219. {
  220. KeyCode keyCode = Event.current.keyCode;
  221. if ( Event.current.shift )
  222. {
  223. if ( keyCode == KeyCode.F3 ||
  224. ( ( keyCode == KeyCode.KeypadEnter || keyCode == KeyCode.Return ) &&
  225. ( currentFocus.Equals( SearchBarId ) || string.IsNullOrEmpty( currentFocus ) ) ) )
  226. SelectPrevious();
  227. }
  228. else
  229. {
  230. if ( keyCode == KeyCode.F3 ||
  231. ( ( keyCode == KeyCode.KeypadEnter || keyCode == KeyCode.Return ) &&
  232. ( currentFocus.Equals( SearchBarId ) || string.IsNullOrEmpty( currentFocus ) ) ) )
  233. SelectNext();
  234. }
  235. }
  236. if( currentFocus.Equals( SearchBarId ) || ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && m_searchBarSize.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) ) || m_selectSearchBarTextfield )
  237. {
  238. EditorGUI.BeginChangeCheck();
  239. {
  240. GUI.SetNextControlName( SearchBarId );
  241. m_searchBarValue = EditorGUI.TextField( m_searchBarSize, m_searchBarValue, UIUtils.ToolbarSearchTextfield );
  242. }
  243. if ( EditorGUI.EndChangeCheck() )
  244. {
  245. m_refreshSearchResultList = true;
  246. }
  247. } else
  248. {
  249. GUI.Label( m_searchBarSize, m_searchBarValue, UIUtils.ToolbarSearchTextfield );
  250. }
  251. m_searchBarSize.x += m_searchBarSize.width;
  252. if ( m_parentWindow.CameraDrawInfo.CurrentEventType == EventType.MouseDown && m_searchBarSize.Contains( m_parentWindow.CameraDrawInfo.MousePosition ) )
  253. {
  254. if ( string.IsNullOrEmpty( m_searchBarValue ) )
  255. {
  256. m_searchBarVisible = false;
  257. m_refreshSearchResultList = false;
  258. }
  259. else
  260. {
  261. m_searchBarValue = string.Empty;
  262. m_searchResultNodes.Clear();
  263. m_currentSelected = -1;
  264. }
  265. }
  266. GUI.Label( m_searchBarSize, string.Empty, UIUtils.ToolbarSearchCancelButton );
  267. if ( Event.current.isKey && Event.current.keyCode == KeyCode.Escape )
  268. {
  269. m_searchBarVisible = false;
  270. m_refreshSearchResultList = false;
  271. GUI.FocusControl( null );
  272. m_selectSearchBarTextfield = false;
  273. }
  274. if ( m_refreshSearchResultList && ( m_parentWindow.CurrentInactiveTime > InactivityRefreshTime ) )
  275. {
  276. RefreshList();
  277. }
  278. }
  279. if ( m_selectSearchBarTextfield )
  280. {
  281. m_selectSearchBarTextfield = false;
  282. EditorGUI.FocusTextInControl( SearchBarId );
  283. //GUI.FocusControl( SearchBarId );
  284. }
  285. //if ( Event.current.control && Event.current.isKey && Event.current.keyCode == KeyCode.F && Event.current.type == EventType.KeyDown )
  286. if( m_parentWindow.CurrentCommandName.Equals("Find") )
  287. {
  288. if ( !m_searchBarVisible )
  289. {
  290. m_searchBarVisible = true;
  291. m_refreshSearchResultList = false;
  292. }
  293. m_selectSearchBarTextfield = true;
  294. }
  295. GUI.color = m_shareButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  296. m_shareButton.Draw( m_transformedArea.x + m_transformedArea.width - 195 - TabX, TabY );
  297. GUI.color = m_takeScreenshotButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  298. m_takeScreenshotButton.Draw( m_transformedArea.x + m_transformedArea.width - 165 - TabX, TabY );
  299. GUI.color = m_focusOnSelectionButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  300. m_focusOnSelectionButton.Draw( m_transformedArea.x + m_transformedArea.width - 120 - TabX, TabY );
  301. GUI.color = m_focusOnMasterNodeButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  302. m_focusOnMasterNodeButton.Draw( m_transformedArea.x + m_transformedArea.width - 85 - TabX, TabY );
  303. GUI.color = m_cleanUnusedNodesButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  304. m_cleanUnusedNodesButton.Draw( m_transformedArea.x + m_transformedArea.width - 50 - TabX, TabY );
  305. GUI.color = m_showInfoWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  306. m_showInfoWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 25 - TabX, TabY );
  307. //GUI.color = m_showTipsWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  308. //m_showTipsWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 190 - TabX, TabY );
  309. //GUI.color = m_showConsoleWindowButton.IsInside( mousePosition ) ? RightIconsColorOn : RightIconsColorOff;
  310. //m_showConsoleWindowButton.Draw( m_transformedArea.x + m_transformedArea.width - 195 - TabX, TabY );
  311. GUI.color = bufferedColor;
  312. }
  313. public void OnNodeRemovedFromGraph( ParentNode node )
  314. {
  315. m_searchResultNodes.Remove( node );
  316. }
  317. int m_previousNodeCount = 0;
  318. void RefreshList()
  319. {
  320. m_refreshSearchResultList = false;
  321. m_currentSelected = -1;
  322. m_searchResultNodes.Clear();
  323. if ( !string.IsNullOrEmpty( m_searchBarValue ) )
  324. {
  325. List<ParentNode> nodes = m_parentWindow.CurrentGraph.AllNodes;
  326. int count = nodes.Count;
  327. m_previousNodeCount = count;
  328. for ( int i = 0; i < count; i++ )
  329. {
  330. if ( nodes[ i ].CheckFindText( m_searchBarValue ) )
  331. {
  332. m_searchResultNodes.Add( nodes[ i ] );
  333. }
  334. }
  335. }
  336. }
  337. void SelectNext()
  338. {
  339. if ( m_refreshSearchResultList || m_parentWindow.CurrentGraph.AllNodes.Count != m_previousNodeCount )
  340. {
  341. RefreshList();
  342. }
  343. if ( m_searchResultNodes.Count > 0 )
  344. {
  345. m_currentSelected = ( m_currentSelected + 1 ) % m_searchResultNodes.Count;
  346. m_parentWindow.FocusOnNode( m_searchResultNodes[ m_currentSelected ], 1, true ,true);
  347. }
  348. }
  349. void SelectPrevious()
  350. {
  351. if ( m_refreshSearchResultList || m_parentWindow.CurrentGraph.AllNodes.Count != m_previousNodeCount )
  352. {
  353. RefreshList();
  354. }
  355. if ( m_searchResultNodes.Count > 0 )
  356. {
  357. m_currentSelected = ( m_currentSelected > 1 ) ? ( m_currentSelected - 1 ) : ( m_searchResultNodes.Count - 1 );
  358. m_parentWindow.FocusOnNode( m_searchResultNodes[ m_currentSelected ], 1, true );
  359. }
  360. }
  361. public void SetStateOnButton( ToolButtonType button, int state, string tooltip )
  362. {
  363. switch ( button )
  364. {
  365. case ToolButtonType.New:
  366. case ToolButtonType.Open:
  367. case ToolButtonType.Save:
  368. case ToolButtonType.Library:
  369. case ToolButtonType.Options:
  370. case ToolButtonType.Help:
  371. case ToolButtonType.MasterNode: break;
  372. case ToolButtonType.OpenSourceCode:
  373. {
  374. m_openSourceCodeButton.SetStateOnButton( state, tooltip );
  375. }
  376. break;
  377. case ToolButtonType.Update:
  378. {
  379. m_updateButton.SetStateOnButton( state, tooltip );
  380. }
  381. break;
  382. case ToolButtonType.Live:
  383. {
  384. m_liveButton.SetStateOnButton( state, tooltip );
  385. }
  386. break;
  387. case ToolButtonType.TakeScreenshot:
  388. {
  389. m_takeScreenshotButton.SetStateOnButton( state, tooltip );
  390. }
  391. break;
  392. case ToolButtonType.CleanUnusedNodes:
  393. //case eToolButtonType.SelectShader:
  394. {
  395. m_cleanUnusedNodesButton.SetStateOnButton( state, tooltip );
  396. }
  397. break;
  398. case ToolButtonType.FocusOnMasterNode:
  399. {
  400. m_focusOnMasterNodeButton.SetStateOnButton( state, tooltip );
  401. }
  402. break;
  403. case ToolButtonType.FocusOnSelection:
  404. {
  405. m_focusOnSelectionButton.SetStateOnButton( state, tooltip );
  406. }
  407. break;
  408. case ToolButtonType.Share:
  409. {
  410. m_shareButton.SetStateOnButton( state, tooltip );
  411. }
  412. break;
  413. case ToolButtonType.ShowInfoWindow:
  414. {
  415. m_showInfoWindowButton.SetStateOnButton( state, tooltip );
  416. }
  417. break;
  418. case ToolButtonType.ShowTipsWindow:
  419. {
  420. m_showTipsWindowButton.SetStateOnButton( state, tooltip );
  421. }
  422. break;
  423. case ToolButtonType.ShowConsole:
  424. {
  425. m_showConsoleWindowButton.SetStateOnButton( state, tooltip );
  426. }
  427. break;
  428. }
  429. }
  430. public void SetStateOnButton( ToolButtonType button, int state )
  431. {
  432. switch ( button )
  433. {
  434. case ToolButtonType.New:
  435. case ToolButtonType.Open:
  436. case ToolButtonType.Save:
  437. case ToolButtonType.Library:
  438. case ToolButtonType.Options:
  439. case ToolButtonType.Help:
  440. case ToolButtonType.MasterNode: break;
  441. case ToolButtonType.OpenSourceCode:
  442. {
  443. m_openSourceCodeButton.SetStateOnButton( state );
  444. }
  445. break;
  446. case ToolButtonType.Update:
  447. {
  448. m_updateButton.SetStateOnButton( state );
  449. }
  450. break;
  451. case ToolButtonType.Live:
  452. {
  453. m_liveButton.SetStateOnButton( state );
  454. }
  455. break;
  456. case ToolButtonType.TakeScreenshot:
  457. {
  458. m_takeScreenshotButton.SetStateOnButton( state );
  459. }
  460. break;
  461. case ToolButtonType.CleanUnusedNodes:
  462. //case eToolButtonType.SelectShader:
  463. {
  464. m_cleanUnusedNodesButton.SetStateOnButton( state );
  465. }
  466. break;
  467. case ToolButtonType.FocusOnMasterNode:
  468. {
  469. m_focusOnMasterNodeButton.SetStateOnButton( state );
  470. }
  471. break;
  472. case ToolButtonType.FocusOnSelection:
  473. {
  474. m_focusOnSelectionButton.SetStateOnButton( state );
  475. }
  476. break;
  477. case ToolButtonType.Share:
  478. {
  479. m_shareButton.SetStateOnButton( state );
  480. }
  481. break;
  482. case ToolButtonType.ShowInfoWindow:
  483. {
  484. m_showInfoWindowButton.SetStateOnButton( state );
  485. }
  486. break;
  487. case ToolButtonType.ShowTipsWindow:
  488. {
  489. m_showTipsWindowButton.SetStateOnButton( state );
  490. }break;
  491. case ToolButtonType.ShowConsole:
  492. {
  493. m_showConsoleWindowButton.SetStateOnButton( state );
  494. }
  495. break;
  496. }
  497. }
  498. public void DrawShaderTitle( MenuParent nodeParametersWindow, MenuParent paletteWindow, float availableCanvasWidth, float graphAreaHeight, string shaderName )
  499. {
  500. float leftAdjust = nodeParametersWindow.IsMaximized ? nodeParametersWindow.RealWidth : 0;
  501. float rightAdjust = paletteWindow.IsMaximized ? 0 : paletteWindow.RealWidth;
  502. m_boxRect = new Rect( leftAdjust + rightAdjust, 0, availableCanvasWidth, 35 );
  503. m_boxRect.x += paletteWindow.IsMaximized ? 0 : -paletteWindow.RealWidth;
  504. m_boxRect.width += nodeParametersWindow.IsMaximized ? 0 : nodeParametersWindow.RealWidth;
  505. m_boxRect.width += paletteWindow.IsMaximized ? 0 : paletteWindow.RealWidth;
  506. m_borderRect = new Rect( m_boxRect );
  507. m_borderRect.height = graphAreaHeight;
  508. int extra = m_searchBarVisible ? (int)m_searchBarSize.width + 20: 0;
  509. //m_boxRect.xMax -= ( paletteWindow.IsMaximized ? 195 : 230 ) + extra;
  510. //m_boxRect.xMin += nodeParametersWindow.IsMaximized ? 95 : 145;
  511. UIUtils.ToolbarMainTitle.padding.right = ( paletteWindow.IsMaximized ? 195 : 230 ) + extra;
  512. UIUtils.ToolbarMainTitle.padding.left = nodeParametersWindow.IsMaximized ? 110 : 145;
  513. if ( m_borderStyle == null )
  514. {
  515. m_borderStyle = ( ParentWindow.CurrentGraph.CurrentMasterNode == null ) ? UIUtils.GetCustomStyle( CustomStyle.ShaderFunctionBorder ) : UIUtils.GetCustomStyle( CustomStyle.ShaderBorder );
  516. }
  517. GUI.Label( m_borderRect, shaderName, m_borderStyle );
  518. GUI.Label( m_boxRect, shaderName, UIUtils.ToolbarMainTitle );
  519. }
  520. public override bool IsInside( Vector2 position )
  521. {
  522. if ( !m_isActive )
  523. return false;
  524. return m_boxRect.Contains( position ) || m_areaLeft.Contains( position ) || m_areaRight.Contains( position );
  525. }
  526. public GUIStyle BorderStyle
  527. {
  528. get { return m_borderStyle; }
  529. set { m_borderStyle = value; }
  530. }
  531. }
  532. }