@@ -38,36 +38,23 @@ internal partial class ContainerWindow : ScriptableObject
3838 internal const float kButtonWidth = 16f , kButtonHeight = 16f ;
3939
4040 static internal bool macEditor => Application . platform == RuntimePlatform . OSXEditor ;
41- static internal bool linuxEditor => Application . platform == RuntimePlatform . LinuxEditor ;
4241
4342 static internal bool s_Modal = false ;
4443 private static ContainerWindow s_MainWindow ;
4544 static internal ContainerWindow mainWindow { get => s_MainWindow ; }
4645
4746 private static class Styles
4847 {
49- // Title Bar Buttons (Non)
50- public static GUIStyle buttonMin = "WinBtnMinMac" ;
51- public static GUIStyle buttonClose = macEditor ? "WinBtnCloseMac" : "WinBtnClose" ;
52- public static GUIStyle buttonMax = macEditor ? "WinBtnMaxMac" : "WinBtnMax" ;
53- public static GUIStyle buttonRestore = macEditor ? "WinBtnRestoreMac" : "WinBtnRestore" ;
54-
5548 public static float borderSize => macEditor ? osxBorderSize : winBorderSize ;
5649 public static float buttonMargin => macEditor ? osxBorderMargin : winBorderMargin ;
5750
58- public static SVC < float > buttonTop = new SVC < float > ( "--container-window-button-top-margin" ) ;
59-
6051 private static SVC < float > winBorderSize = new SVC < float > ( "--container-window-buttons-right-margin-win" ) ;
6152 private static SVC < float > osxBorderSize = new SVC < float > ( "--container-window-buttons-right-margin-osx" ) ;
6253 private static SVC < float > winBorderMargin = new SVC < float > ( "--container-window-button-left-right-margin-win" ) ;
6354 private static SVC < float > osxBorderMargin = new SVC < float > ( "--container-window-button-left-right-margin-osx" ) ;
6455 }
65-
66- private const float kButtonCountOSX = 0 ;
67- private const float kButtonCountWin = 2 ;
6856 static internal float buttonHorizontalSpace => ( kButtonWidth + Styles . buttonMargin * 2f ) ;
69- static internal float buttonStackWidth => buttonHorizontalSpace * ( macEditor || linuxEditor ? kButtonCountOSX : kButtonCountWin ) + Styles . borderSize ;
70-
57+ static internal float buttonStackWidth => Styles . borderSize ;
7158 public ContainerWindow ( )
7259 {
7360 m_PixelRect = new Rect ( 0 , 0 , 400 , 300 ) ;
@@ -656,142 +643,5 @@ internal Rect GetDropDownRect(Rect buttonRect, Vector2 minSize, Vector2 maxSize)
656643 return PopupLocationHelper . GetDropDownRect ( buttonRect , minSize , maxSize , this ) ;
657644 }
658645
659- public void HandleWindowDecorationEnd ( Rect windowPosition )
660- {
661- // No Op
662- }
663-
664- public void HandleWindowDecorationStart ( Rect windowPosition )
665- {
666- if ( ! macEditor && ! linuxEditor )
667- {
668- bool hasTitleBar = ( windowPosition . y == 0 && ( showMode != ShowMode . Utility && showMode != ShowMode . MainWindow ) && ! isPopup ) ;
669-
670- if ( ! hasTitleBar )
671- return ;
672-
673- bool hasWindowButtons = Mathf . Abs ( windowPosition . xMax - position . width ) < 2 ;
674- if ( hasWindowButtons )
675- {
676- GUIStyle min = Styles . buttonMin ;
677- GUIStyle close = Styles . buttonClose ;
678- GUIStyle maxOrRestore = maximized ? Styles . buttonRestore : Styles . buttonMax ;
679-
680- BeginTitleBarButtons ( windowPosition ) ;
681- if ( TitleBarButton ( close ) )
682- {
683- if ( InternalRequestClose ( ) )
684- {
685- Close ( ) ;
686- GUIUtility . ExitGUI ( ) ;
687- }
688- }
689-
690- var canMaximize = m_MaxSize . x == 0 || m_MaxSize . y == 0 || m_MaxSize . x >= Screen . currentResolution . width || m_MaxSize . y >= Screen . currentResolution . height ;
691- EditorGUI . BeginDisabled ( ! canMaximize ) ;
692- if ( TitleBarButton ( maxOrRestore ) )
693- ToggleMaximize ( ) ;
694- EditorGUI . EndDisabled ( ) ;
695- }
696-
697- DragTitleBar ( new Rect ( 0 , 0 , position . width , kTitleHeight ) ) ;
698- }
699- }
700-
701- private void BeginTitleBarButtons ( Rect windowPosition )
702- {
703- m_ButtonCount = 0 ;
704- m_TitleBarWidth = windowPosition . width ;
705- }
706-
707- private bool TitleBarButton ( GUIStyle style )
708- {
709- var buttonRect = new Rect ( m_TitleBarWidth - Styles . borderSize - ( buttonHorizontalSpace * ++ m_ButtonCount ) , Styles . buttonTop , kButtonWidth , kButtonHeight ) ;
710- var guiView = rootView as GUIView ;
711- if ( guiView == null )
712- {
713- var splitView = rootView as SplitView ;
714- if ( splitView != null )
715- guiView = splitView . children . Length > 0 ? splitView . children [ 0 ] as GUIView : null ;
716- }
717- if ( guiView != null )
718- guiView . MarkHotRegion ( GUIClip . UnclipToWindow ( buttonRect ) ) ;
719-
720- return GUI . Button ( buttonRect , GUIContent . none , style ) ;
721- }
722-
723- // Snapping windows
724- private static Vector2 s_LastDragMousePos ;
725- private float startDragDpi ;
726-
727- // Indicates that we are using the native title bar caption dragging.
728- private bool m_DraggingNativeTitleBarCaption = false ;
729-
730- private void DragTitleBar ( Rect titleBarRect )
731- {
732- int id = GUIUtility . GetControlID ( FocusType . Passive ) ;
733- Event evt = Event . current ;
734-
735- switch ( evt . GetTypeForControl ( id ) )
736- {
737- case EventType . Repaint :
738- if ( m_DraggingNativeTitleBarCaption )
739- m_DraggingNativeTitleBarCaption = false ;
740- EditorGUIUtility . AddCursorRect ( titleBarRect , MouseCursor . Arrow ) ;
741- break ;
742- case EventType . MouseDown :
743- // If the mouse is inside the title bar rect, we say that we're the hot control
744- if ( titleBarRect . Contains ( evt . mousePosition ) && GUIUtility . hotControl == 0 && evt . button == 0 )
745- {
746- Event . current . Use ( ) ;
747- m_DraggingNativeTitleBarCaption = true ;
748- SendCaptionEvent ( m_DraggingNativeTitleBarCaption ) ;
749- }
750- break ;
751- case EventType . MouseUp :
752- if ( m_DraggingNativeTitleBarCaption )
753- break ;
754-
755- if ( GUIUtility . hotControl == id )
756- {
757- GUIUtility . hotControl = 0 ;
758- Event . current . Use ( ) ;
759- Unsupported . SetAllowCursorLock ( true , Unsupported . DisallowCursorLockReasons . SizeMove ) ;
760- }
761- break ;
762- case EventType . MouseDrag :
763- if ( m_DraggingNativeTitleBarCaption )
764- break ;
765-
766- if ( GUIUtility . hotControl == id )
767- {
768- Vector2 mousePos = evt . mousePosition ;
769- if ( startDragDpi != GUIUtility . pixelsPerPoint )
770- {
771- // We ignore this mouse event when changing screens in multi monitor setups with
772- // different dpi scalings as funky things might/will happen
773- startDragDpi = GUIUtility . pixelsPerPoint ;
774- s_LastDragMousePos = mousePos ;
775- }
776- else
777- {
778- Vector2 movement = mousePos - s_LastDragMousePos ;
779-
780- float minimumDelta = 1.0f / GUIUtility . pixelsPerPoint ;
781-
782- if ( Mathf . Abs ( movement . x ) >= minimumDelta || Mathf . Abs ( movement . y ) >= minimumDelta )
783- {
784- Rect dragPosition = position ;
785- dragPosition . x += movement . x ;
786- dragPosition . y += movement . y ;
787- position = dragPosition ;
788-
789- GUI . changed = true ;
790- }
791- }
792- }
793- break ;
794- }
795- }
796646 }
797647} //namespace
0 commit comments