void OnParentGeometryChanged(GeometryChangedEvent geometryChangedEvent) { // Check if the parent window can no longer contain the target window. // If the window is out of bounds, make one edge clamp to the border of the // parent window. if (target.layout.xMin < 0f) { target.style.positionLeft = StyleValue <float> .Create(0f); target.style.positionRight = StyleValue <float> .Create(float.NaN); } if (target.layout.xMax > geometryChangedEvent.newRect.width) { target.style.positionLeft = StyleValue <float> .Create(float.NaN); target.style.positionRight = StyleValue <float> .Create(0f); } if (target.layout.yMax > geometryChangedEvent.newRect.height) { target.style.positionTop = StyleValue <float> .Create(float.NaN); target.style.positionBottom = StyleValue <float> .Create(0f); } if (target.layout.yMin < 0f) { target.style.positionTop = StyleValue <float> .Create(0f); target.style.positionBottom = StyleValue <float> .Create(float.NaN); } }
void HandleResizeFromTopLeft(MouseMoveEvent mouseMoveEvent) { if (!m_Dragging) { return; } Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; // Set anchor points for positioning m_Container.style.positionTop = StyleValue <float> .Create(float.NaN); m_Container.style.positionBottom = StyleValue <float> .Create(m_Container.parent.layout.height - m_Container.layout.yMax); m_Container.style.positionLeft = StyleValue <float> .Create(float.NaN); m_Container.style.positionRight = StyleValue <float> .Create(m_Container.parent.layout.width - m_Container.layout.xMax); float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); if (maintainAspectRatio) { newWidth = newHeight = Mathf.Min(newWidth, newHeight); } m_ResizeTarget.style.width = StyleValue <float> .Create(newWidth); m_ResizeTarget.style.height = StyleValue <float> .Create(newHeight); mouseMoveEvent.StopPropagation(); }
public void ApplyPosition(VisualElement target) { if (dockingLeft) { target.style.positionRight = StyleValue <float> .Create(float.NaN); target.style.positionLeft = StyleValue <float> .Create(horizontalOffset); } else { target.style.positionLeft = StyleValue <float> .Create(float.NaN); target.style.positionRight = StyleValue <float> .Create(horizontalOffset); } if (dockingTop) { target.style.positionBottom = StyleValue <float> .Create(float.NaN); target.style.positionTop = StyleValue <float> .Create(verticalOffset); } else { target.style.positionTop = StyleValue <float> .Create(float.NaN); target.style.positionBottom = StyleValue <float> .Create(verticalOffset); } }
void ApplySerializewindowLayouts(GeometryChangedEvent evt) { UnregisterCallback <GeometryChangedEvent>(ApplySerializewindowLayouts); if (m_FloatingWindowsLayout != null) { // Restore master preview layout m_FloatingWindowsLayout.previewLayout.ApplyPosition(m_MasterPreviewView); m_MasterPreviewView.previewTextureView.style.width = StyleValue <float> .Create(m_FloatingWindowsLayout.masterPreviewSize.x); m_MasterPreviewView.previewTextureView.style.height = StyleValue <float> .Create(m_FloatingWindowsLayout.masterPreviewSize.y); // Restore blackboard layout m_BlackboardProvider.blackboard.layout = m_FloatingWindowsLayout.blackboardLayout.GetLayout(this.layout); previewManager.ResizeMasterPreview(m_FloatingWindowsLayout.masterPreviewSize); } else { m_FloatingWindowsLayout = new FloatingWindowsLayout(); } // After the layout is restored from the previous session, start tracking layout changes in the blackboard. m_BlackboardProvider.blackboard.RegisterCallback <GeometryChangedEvent>(StoreBlackboardLayoutOnGeometryChanged); // After the layout is restored, track changes in layout and make the blackboard have the same behavior as the preview w.r.t. docking. RegisterCallback <GeometryChangedEvent>(HandleEditorViewChanged); }
Image CreatePreview(Texture texture) { var image = new Image { name = "preview", image = StyleValue<Texture>.Create(m_PreviewRenderHandle.texture ?? texture) }; image.AddManipulator(new Draggable(OnMouseDragPreviewMesh, true)); image.AddManipulator((IManipulator)Activator.CreateInstance(s_ContextualMenuManipulator, (Action<ContextualMenuPopulateEvent>)BuildContextualMenu)); return image; }
public NodeView() { AddStyleSheetPath("NodeView_style"); SetSize(new Vector2(1280, 720)); style.alignItems = StyleValue <Align> .Create(Align.FlexStart); SetupSobelExample(transform.position); }
void UpdatePreviewVisibility() { if (m_Expanded) { RemoveFromClassList("collapsed"); AddToClassList("expanded"); m_PreviewResizeBorderFrame.visible = true; style.positionLeft = StyleValue <float> .Create(float.NaN); style.positionBottom = StyleValue <float> .Create(float.NaN); style.positionRight = StyleValue <float> .Create(parent.layout.width - layout.xMax); style.positionTop = StyleValue <float> .Create(layout.yMin); previewTextureView.style.width = StyleValue <float> .Create(m_ExpandedPreviewSize.x); previewTextureView.style.height = StyleValue <float> .Create(m_ExpandedPreviewSize.y); } else { m_ExpandedPreviewSize = previewTextureView.layout.size; m_PreviewResizeBorderFrame.visible = false; style.positionLeft = StyleValue <float> .Create(float.NaN); style.positionBottom = StyleValue <float> .Create(float.NaN); style.positionRight = StyleValue <float> .Create(parent.layout.width - layout.xMax); style.positionTop = StyleValue <float> .Create(layout.yMin); previewTextureView.style.width = StyleValue <float> .Create(0f); previewTextureView.style.height = StyleValue <float> .Create(0f); RemoveFromClassList("expanded"); AddToClassList("collapsed"); } m_RecalculateLayout = true; }
void ApplySerializewindowLayouts(GeometryChangedEvent evt) { UnregisterCallback <GeometryChangedEvent>(ApplySerializewindowLayouts); if (m_FloatingWindowsLayout != null) { // Restore master preview layout m_FloatingWindowsLayout.previewLayout.ApplyPosition(m_MasterPreviewView); m_MasterPreviewView.previewTextureView.style.width = StyleValue <float> .Create(m_FloatingWindowsLayout.masterPreviewSize.x); m_MasterPreviewView.previewTextureView.style.height = StyleValue <float> .Create(m_FloatingWindowsLayout.masterPreviewSize.y); // Restore blackboard layout, and make sure that it remains in the view. Rect blackboardRect = m_FloatingWindowsLayout.blackboardLayout.GetLayout(this.layout); // Make sure the dimensions are sufficiently large. blackboardRect.width = Mathf.Clamp(blackboardRect.width, 160f, m_GraphView.contentContainer.layout.width); blackboardRect.height = Mathf.Clamp(blackboardRect.height, 160f, m_GraphView.contentContainer.layout.height); // Make sure that the positionining is on screen. blackboardRect.x = Mathf.Clamp(blackboardRect.x, 0f, Mathf.Max(1f, m_GraphView.contentContainer.layout.width - blackboardRect.width - blackboardRect.width)); blackboardRect.y = Mathf.Clamp(blackboardRect.y, 0f, Mathf.Max(1f, m_GraphView.contentContainer.layout.height - blackboardRect.height - blackboardRect.height)); // Set the processed blackboard layout. m_BlackboardProvider.blackboard.layout = blackboardRect; previewManager.ResizeMasterPreview(m_FloatingWindowsLayout.masterPreviewSize); } else { m_FloatingWindowsLayout = new FloatingWindowsLayout(); } // After the layout is restored from the previous session, start tracking layout changes in the blackboard. m_BlackboardProvider.blackboard.RegisterCallback <GeometryChangedEvent>(StoreBlackboardLayoutOnGeometryChanged); // After the layout is restored, track changes in layout and make the blackboard have the same behavior as the preview w.r.t. docking. RegisterCallback <GeometryChangedEvent>(HandleEditorViewChanged); }
void OnMouseMove(MouseMoveEvent evt) { if (m_Active) { // The mouse position of is corrected according to the offset within the target // element (m_LocalWorldOffset) to set the position relative to the mouse position // when the dragging started. Vector2 position = target.parent.WorldToLocal(evt.mousePosition) - m_LocalMosueOffset; // Make sure that the object remains in the parent window position.x = Mathf.Clamp(position.x, 0f, target.parent.layout.width - target.layout.width); position.y = Mathf.Clamp(position.y, 0f, target.parent.layout.height - target.layout.height); // While moving, use only the left and top position properties, // while keeping the others NaN to not affect layout. target.style.positionLeft = StyleValue <float> .Create(position.x); target.style.positionTop = StyleValue <float> .Create(position.y); target.style.positionRight = StyleValue <float> .Create(float.NaN); target.style.positionBottom = StyleValue <float> .Create(float.NaN); } }
void OnGeometryChanged(GeometryChangedEvent geometryChangedEvent) { // Make the target clamp to the border of the window if the // parent window becomes too small to contain it. if (target.parent.layout.width < target.layout.width) { if (m_WindowDockingLayout.dockingLeft) { target.style.positionLeft = StyleValue <float> .Create(0f); target.style.positionRight = StyleValue <float> .Create(float.NaN); } else { target.style.positionLeft = StyleValue <float> .Create(float.NaN); target.style.positionRight = StyleValue <float> .Create(0f); } } if (target.parent.layout.height < target.layout.height) { if (m_WindowDockingLayout.dockingTop) { target.style.positionTop = StyleValue <float> .Create(0f); target.style.positionBottom = StyleValue <float> .Create(float.NaN); } else { target.style.positionTop = StyleValue <float> .Create(float.NaN); target.style.positionBottom = StyleValue <float> .Create(0f); } } }
void OnPreviewChanged() { m_PreviewTextureView.image = StyleValue <Texture> .Create(m_PreviewRenderHandle.texture ?? Texture2D.blackTexture); m_PreviewTextureView.Dirty(ChangeType.Repaint); }
public void Initialize(AbstractNode inNode, IEdgeConnectorListener connectorListener) { AddStyleSheetPath("Styles/NodeView"); AddToClassList("Node"); if (inNode == null) { return; } var contents = this.Q("contents"); m_ConnectorListener = connectorListener; node = inNode; persistenceKey = node.guid.ToString(); var priorityField = new IntegerField() { value = node.priority, name = "priority-field", visible = CalculatePriorityVisibility(node) }; priorityField.OnValueChanged(e => node.priority = e.newValue); titleContainer.Insert(1, priorityField); m_PriorityField = priorityField; m_TitleLabel = titleContainer.First(e => e.name == "title-label"); m_TitleLabel.RegisterCallback <MouseDownEvent>(OnTitleLabelMouseDown); m_TitleField = new TextField { name = "title-field", value = inNode.name, visible = false }; m_TitleField.style.positionType = PositionType.Absolute; m_TitleField.RegisterCallback <FocusOutEvent>(e => { OnEditTitleTextFinished(); }); m_TitleField.RegisterCallback <KeyDownEvent>(OnTitleTextFieldKeyPressed); titleContainer.shadow.Add(m_TitleField); UpdateTitle(); // Add controls container var controlsContainer = new VisualElement { name = "controls" }; { m_ControlsDivider = new VisualElement { name = "divider" }; m_ControlsDivider.AddToClassList("horizontal"); controlsContainer.Add(m_ControlsDivider); m_ControlItems = new VisualElement { name = "items" }; controlsContainer.Add(m_ControlItems); // Instantiate control views from node foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false)) { var control = attribute.InstantiateControl(node, new ReflectionProperty(propertyInfo)); if (control != null) { m_ControlItems.Add(control); } } } foreach (var fieldInfo in node.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (IControlAttribute attribute in fieldInfo.GetCustomAttributes(typeof(IControlAttribute), false)) { var control = attribute.InstantiateControl(node, new ReflectionProperty(fieldInfo)); if (control != null) { m_ControlItems.Add(control); } } } } if (m_ControlItems.childCount > 0) { contents.Add(controlsContainer); } // Add port input container, which acts as a pixel cache for all port inputs m_PortInputContainer = new VisualElement { name = "portInputContainer", clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; Add(m_PortInputContainer); AddSlots(node.GetSlots <NodeSlot>()); UpdatePortInputs(); base.expanded = node.drawState.expanded; RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdatePortInputVisibilities(); SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); /*if (node is SubGraphNode) * { * RegisterCallback<MouseDownEvent>(OnSubGraphDoubleClick); * }*/ m_PortInputContainer.SendToBack(); // Remove this after updated to the correct API call has landed in trunk. ------------ VisualElement m_TitleContainer; VisualElement m_ButtonContainer; m_TitleContainer = this.Q("title"); // ----------------------------------------------------------------------------------- var settings = node as IHasSettings; if (settings != null) { m_NodeSettingsView = new NodeSettingsView(); m_NodeSettingsView.visible = false; Add(m_NodeSettingsView); m_SettingsButton = new VisualElement { name = "settings-button" }; m_SettingsButton.Add(new VisualElement { name = "icon" }); m_Settings = settings.CreateSettingsElement(); m_SettingsButton.AddManipulator(new Clickable(() => { UpdateSettingsExpandedState(); })); // Remove this after updated to the correct API call has landed in trunk. ------------ m_ButtonContainer = new VisualElement { name = "button-container" }; m_ButtonContainer.style.flexDirection = StyleValue <FlexDirection> .Create(FlexDirection.Row); m_ButtonContainer.Add(m_SettingsButton); m_ButtonContainer.Add(m_CollapseButton); m_TitleContainer.Add(m_ButtonContainer); // ----------------------------------------------------------------------------------- //titleButtonContainer.Add(m_SettingsButton); //titleButtonContainer.Add(m_CollapseButton); RegisterCallback <GeometryChangedEvent>(OnGeometryChanged); } }
public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener) { AddStyleSheetPath("Styles/MaterialNodeView"); AddToClassList("MaterialNode"); if (inNode == null) { return; } var contents = this.Q("contents"); m_ConnectorListener = connectorListener; node = inNode; persistenceKey = node.guid.ToString(); UpdateTitle(); // Add controls container var controlsContainer = new VisualElement { name = "controls" }; { m_ControlsDivider = new VisualElement { name = "divider" }; m_ControlsDivider.AddToClassList("horizontal"); controlsContainer.Add(m_ControlsDivider); m_ControlItems = new VisualElement { name = "items" }; controlsContainer.Add(m_ControlItems); // Instantiate control views from node foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false)) { m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo)); } } } if (m_ControlItems.childCount > 0) { contents.Add(controlsContainer); } if (node.hasPreview) { // Add actual preview which floats on top of the node m_PreviewContainer = new VisualElement { name = "previewContainer", clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; m_PreviewImage = new Image { name = "preview", pickingMode = PickingMode.Ignore, image = Texture2D.whiteTexture, }; { // Add preview collapse button on top of preview var collapsePreviewButton = new VisualElement { name = "collapse" }; collapsePreviewButton.Add(new VisualElement { name = "icon" }); collapsePreviewButton.AddManipulator(new Clickable(() => { node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview"); UpdatePreviewExpandedState(false); })); m_PreviewImage.Add(collapsePreviewButton); } m_PreviewContainer.Add(m_PreviewImage); // Hook up preview image to preview manager m_PreviewRenderData = previewManager.GetPreview(inNode); m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture; UpdatePreviewTexture(); // Add fake preview which pads out the node to provide space for the floating preview m_PreviewFiller = new VisualElement { name = "previewFiller" }; m_PreviewFiller.AddToClassList("expanded"); { var previewDivider = new VisualElement { name = "divider" }; previewDivider.AddToClassList("horizontal"); m_PreviewFiller.Add(previewDivider); var expandPreviewButton = new VisualElement { name = "expand" }; expandPreviewButton.Add(new VisualElement { name = "icon" }); expandPreviewButton.AddManipulator(new Clickable(() => { node.owner.owner.RegisterCompleteObjectUndo("Expand Preview"); UpdatePreviewExpandedState(true); })); m_PreviewFiller.Add(expandPreviewButton); } contents.Add(m_PreviewFiller); UpdatePreviewExpandedState(node.previewExpanded); } // Add port input container, which acts as a pixel cache for all port inputs m_PortInputContainer = new VisualElement { name = "portInputContainer", clippingOptions = ClippingOptions.ClipAndCacheContents, pickingMode = PickingMode.Ignore }; Add(m_PortInputContainer); AddSlots(node.GetSlots <MaterialSlot>()); UpdatePortInputs(); base.expanded = node.drawState.expanded; RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdatePortInputVisibilities(); SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0)); if (node is SubGraphNode) { RegisterCallback <MouseDownEvent>(OnSubGraphDoubleClick); } var masterNode = node as IMasterNode; if (masterNode != null) { if (!masterNode.IsPipelineCompatible(RenderPipelineManager.currentPipeline)) { IconBadge wrongPipeline = IconBadge.CreateError("The current render pipeline is not compatible with this node preview."); Add(wrongPipeline); VisualElement title = this.Q("title"); wrongPipeline.AttachTo(title, SpriteAlignment.LeftCenter); } } m_PortInputContainer.SendToBack(); // Remove this after updated to the correct API call has landed in trunk. ------------ VisualElement m_TitleContainer; VisualElement m_ButtonContainer; m_TitleContainer = this.Q("title"); // ----------------------------------------------------------------------------------- var settings = node as IHasSettings; if (settings != null) { m_NodeSettingsView = new NodeSettingsView(); m_NodeSettingsView.visible = false; Add(m_NodeSettingsView); m_SettingsButton = new VisualElement { name = "settings-button" }; m_SettingsButton.Add(new VisualElement { name = "icon" }); m_Settings = settings.CreateSettingsElement(); m_SettingsButton.AddManipulator(new Clickable(() => { UpdateSettingsExpandedState(); })); // Remove this after updated to the correct API call has landed in trunk. ------------ m_ButtonContainer = new VisualElement { name = "button-container" }; m_ButtonContainer.style.flexDirection = StyleValue <FlexDirection> .Create(FlexDirection.Row); m_ButtonContainer.Add(m_SettingsButton); m_ButtonContainer.Add(m_CollapseButton); m_TitleContainer.Add(m_ButtonContainer); // ----------------------------------------------------------------------------------- //titleButtonContainer.Add(m_SettingsButton); //titleButtonContainer.Add(m_CollapseButton); RegisterCallback <GeometryChangedEvent>(OnGeometryChanged); } }
public void ApplySize(VisualElement target) { target.style.width = StyleValue <float> .Create(size.x); target.style.height = StyleValue <float> .Create(size.y); }