private void DockPlacementTo(LinearPlacement placement, TabBarPlacement target) { var placements = placement.Placements.ToList(); foreach (var p in placements) { DockPlacementTo(p, target, DockSite.Fill, 0); } }
public PanelPlacement AppendPanelToPlacement(Panel panel, LinearPlacement target, float stretch) { var placement = new PanelPlacement { Id = panel.Id, Title = panel.Title }; target.Placements.Add(placement); target.Stretches.Add(stretch); Panels.Add(panel); return(placement); }
private static float AdjustStretch(LinearPlacement linearPlacement, float stretch, int index) { if (stretch >= 0) { return(stretch); } var currentStretch = linearPlacement.Stretches[index]; linearPlacement.Stretches[index] *= 0.75f; return(currentStretch * 0.25f); }
private void DockPlacementTo(LinearPlacement placement, PanelPlacement target) { var parent = target.Parent; if (parent is TabBarPlacement tabBarPlacement) { DockPlacementTo(placement, tabBarPlacement); } if (parent is LinearPlacement targetLinearPlacement) { DockPlacementTo(placement, targetLinearPlacement); } }
private static void RefreshDockedSize(LinearPlacement placement, Splitter splitter) { for (int i = 0; i < splitter.Nodes.Count; ++i) { var stretch = splitter.Nodes[i].AsWidget.LayoutCell.Stretch; placement.Stretches[i] = placement.Direction == LinearPlacementDirection.Horizontal ? stretch.X : stretch.Y; } float total = placement.Stretches.Aggregate((s1, s2) => s1 + s2); for (int i = 0; i < placement.Stretches.Count; ++i) { placement.Stretches[i] /= total; } }
private static void ReplacePlacement(Placement old, LinearPlacement @new, DockSite site, ref float stretch, ref int index) { var placement = old; index = site == DockSite.Bottom || site == DockSite.Right ? 1 : 0; stretch = stretch < 0 ? 0.25f : stretch; if (old.Parent != null) { var parentLinearPlacement = (LinearPlacement)old.Parent; parentLinearPlacement.Replace(old, @new); } else { placement = ((LinearPlacement)old).Placements[0]; old.Replace(placement, @new); } @new.Placements.Add(placement); @new.Stretches.Add(1 - stretch); }
private static bool CheckPlacement(LinearPlacement placement, DockSite site, out LinearPlacement newPlacement) { newPlacement = placement; if (site == DockSite.Left || site == DockSite.Right) { if (placement.Direction == LinearPlacementDirection.Horizontal) { return(true); } newPlacement = new LinearPlacement(LinearPlacementDirection.Horizontal); return(false); } if (placement.Direction == LinearPlacementDirection.Vertical) { return(true); } newPlacement = new LinearPlacement(LinearPlacementDirection.Vertical); return(false); }
private void CreateLinearWidget(Splitter container, LinearPlacement placement, float stretch, bool requestTitle) { var splitter = placement.Direction == LinearPlacementDirection.Vertical ? (Splitter) new VSplitter() : new HSplitter(); splitter.SeparatorColor = Theme.Colors.SeparatorColor; splitter.SeparatorHighlightColor = Theme.Colors.SeparatorHighlightColor; splitter.SeparatorDragColor = Theme.Colors.SeparatorDragColor; splitter.SeparatorWidth = 5f; splitter.SeparatorActiveAreaWidth = 6f; Widget rootWidget = splitter; bool hasTabBarPlacement = false; // Due to the mechanism of docking size refreshing, Placements[i] does not // correspond to Stretches[i]. In fact, in Stretches elements ordered by visibility and // location in their splitter. Visible widgets at first, hidden at last. for (int i = 0, j = 0; i < placement.Placements.Count; ++i) { if (!placement.Placements[i].AnyVisiblePanel()) { continue; } hasTabBarPlacement |= placement.Placements[i] is TabBarPlacement; CreateWidgetForPlacement(splitter, placement.Placements[i], placement.Stretches[j]); j++; } splitter.DragEnded += () => RefreshDockedSize(placement, splitter); if (requestTitle && !(hasTabBarPlacement && placement.Placements.Count == 1)) { rootWidget = WrapWithTitle(rootWidget, out var closeButton, out var title); closeButton.Clicked += () => { placement.HideThisOrDescendantPanels(); Refresh(); }; title.Text = "Tangerine"; CreateDragBehaviour(placement, rootWidget.Nodes[0].AsWidget, rootWidget); } container.Stretches.Add(stretch); container.Nodes.Add(rootWidget); }
public void DockPlacementTo(Placement placement, Placement target, DockSite site, float stretch) { var windowPlacement = Model.GetWindowByPlacement(placement); if (placement == windowPlacement) { if (windowPlacement.Placements.Count == 1) { placement = windowPlacement.Placements[0]; } else { var linearPlacement = new LinearPlacement(windowPlacement.Direction); for (var i = 0; i < windowPlacement.Placements.Count; i++) { linearPlacement.Placements.Add(windowPlacement.Placements[i].Clone()); linearPlacement.Stretches.Add(windowPlacement.Stretches[i]); } placement = linearPlacement; } windowPlacement.Placements.Clear(); } placement.Unlink(); Model.DockPlacementTo(placement, target, site, stretch); if (windowPlacement != null) { windowPlacement.Root.RemoveRedundantNodes(); if (!windowPlacement.Root.GetPanelPlacements().Any()) { Model.RemoveWindow(windowPlacement); CloseWindow(windowPlacement.WindowWidget.Window); } else { RefreshWindow(windowPlacement); } RefreshWindow(Model.GetWindowByPlacement(target)); } }
private static void DockPlacementTo(LinearPlacement placement, LinearPlacement target, int index = 0, float stretch = 0) { if (placement.Direction == target.Direction) { var placements = placement.Placements.ToList(); var stretches = placement.Stretches; for (int i = placements.Count - 1; i >= 0; --i) { target.Placements.Insert(index, placements[i]); target.Stretches.Insert(index, stretches[i] * stretch); } return; } if (placement.Placements.Count == 1) { var p = placement.Placements[0]; p.Unlink(); target.Stretches.Insert(index, stretch); target.Placements.Insert(index, p); return; } target.Placements.Insert(index, placement); target.Stretches.Insert(index, stretch); }
private TangerineApp(string[] args) { ChangeTangerineSettingsFolderIfNeed(); Orange.UserInterface.Instance = new OrangeInterface(); Orange.UserInterface.Instance.Initialize(); Widget.EnableViewCulling = false; WidgetInput.AcceptMouseBeyondWidgetByDefault = false; if (!UserPreferences.Initialize()) { UserPreferences.Instance.Clear(); UserPreferences.Instance.Add(new AppUserPreferences()); UserPreferences.Instance.Add(new UI.SceneView.SceneUserPreferences()); UserPreferences.Instance.Add(new UI.Timeline.TimelineUserPreferences()); UserPreferences.Instance.Add(new UI.FilesystemView.FilesystemUserPreferences()); UserPreferences.Instance.Add(new CoreUserPreferences()); } #if WIN TangerineSingleInstanceKeeper.Initialize(args); TangerineSingleInstanceKeeper.AnotherInstanceArgsRecieved += OpenDocumentsFromArgs; Application.Exited += () => { TangerineSingleInstanceKeeper.Instance.ReleaseInstance(); }; #endif switch (AppUserPreferences.Instance.ColorThemeKind) { case ColorTheme.ColorThemeKind.Light: SetColorTheme(ColorTheme.CreateLightTheme(), Theme.ColorTheme.CreateLightTheme()); break; case ColorTheme.ColorThemeKind.Dark: SetColorTheme(ColorTheme.CreateDarkTheme(), Theme.ColorTheme.CreateDarkTheme()); break; case ColorTheme.ColorThemeKind.Custom: { bool isDark = AppUserPreferences.Instance.ColorTheme.IsDark; ColorTheme theme = null; var flags = BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance; foreach (var category in typeof(ColorTheme).GetProperties(flags)) { var categoryValue = category.GetValue(AppUserPreferences.Instance.ColorTheme); if (categoryValue == null) { if (theme == null) { theme = isDark ? ColorTheme.CreateDarkTheme() : ColorTheme.CreateLightTheme(); } category.SetValue(AppUserPreferences.Instance.ColorTheme, category.GetValue(theme)); category.SetValue(theme, null); } } SetColorTheme(AppUserPreferences.Instance.ColorTheme, AppUserPreferences.Instance.LimeColorTheme); break; } } Application.InvalidateWindows(); LoadFont(); DockManager.Initialize(new Vector2(1024, 768)); DockManager.Instance.DocumentAreaDropFilesGesture.Recognized += new ScenesDropHandler { ShouldCreateContextMenu = false }.Handle; TangerineMenu.Create(); var mainWidget = DockManager.Instance.MainWindowWidget; mainWidget.Window.AllowDropFiles = true; mainWidget.AddChangeWatcher(() => Project.Current, _ => { SetupMainWindowTitle(mainWidget); TangerineMenu.RebuildCreateImportedTypeMenu(); }); mainWidget.AddChangeWatcher(() => CoreUserPreferences.Instance.AnimationMode, _ => Document.Current?.ForceAnimationUpdate()); mainWidget.AddChangeWatcher(() => Document.Current?.Container, _ => Document.Current?.ForceAnimationUpdate()); Application.Exiting += () => Project.Current.Close(); Application.Exited += () => { AppUserPreferences.Instance.DockState = DockManager.Instance.ExportState(); SceneUserPreferences.Instance.VisualHintsRegistry = VisualHintsRegistry.Instance; Core.UserPreferences.Instance.Save(); Orange.The.Workspace.Save(); }; var timelinePanel = new Panel("Timeline"); var inspectorPanel = new Panel("Inspector"); var searchPanel = new Panel("Hierarchy"); var animationsPanel = new Panel("Animations"); var filesystemPanel = new Panel("Filesystem"); var consolePanel = new Panel("Console"); var backupHistoryPanel = new Panel("Backups"); var documentPanel = new Panel(DockManager.DocumentAreaId, undockable: false); documentPanel.PanelWidget = documentPanel.ContentWidget; var visualHintsPanel = new Panel("Visual Hints"); var attachmentPanel = new Panel("Model3D Attachment"); var remoteScriptingPanel = new Panel("Remote Scripting"); var dockManager = DockManager.Instance; new UI.Console(consolePanel); var root = dockManager.Model.WindowPlacements.First(); var placement = new LinearPlacement(LinearPlacementDirection.Horizontal); dockManager.AddPanel(timelinePanel, root, DockSite.Top, 0.3f); dockManager.DockPlacementTo(placement, root, DockSite.Bottom, 0.6f); dockManager.AppendPanelTo(documentPanel, placement, 0.5f); var commandHandlerList = CommandHandlerList.Global; var commandsDictionary = new Dictionary <string, Command> { { animationsPanel.Id, new Command(animationsPanel.Title) }, { timelinePanel.Id, new Command(timelinePanel.Title) }, { inspectorPanel.Id, new Command(inspectorPanel.Title) }, { searchPanel.Id, new Command(searchPanel.Title) }, { filesystemPanel.Id, new Command(filesystemPanel.Title) }, { consolePanel.Id, new Command(consolePanel.Title) }, { backupHistoryPanel.Id, new Command(backupHistoryPanel.Title) }, { visualHintsPanel.Id, new Command(visualHintsPanel.Title) }, { attachmentPanel.Id, new Command(attachmentPanel.Title) }, { remoteScriptingPanel.Id, new Command(remoteScriptingPanel.Title) }, }; foreach (var pair in commandsDictionary) { commandHandlerList.Connect(pair.Value, new PanelCommandHandler(pair.Key)); TangerineMenu.PanelsMenu.Add(pair.Value); } dockManager.AddPanel(inspectorPanel, placement, DockSite.Left); var filesystemPlacement = dockManager.AddPanel(filesystemPanel, placement, DockSite.Right); dockManager.AddPanel(searchPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(animationsPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(backupHistoryPanel, filesystemPlacement, DockSite.Fill); dockManager.AddPanel(consolePanel, filesystemPlacement, DockSite.Bottom, 0.3f); dockManager.AddPanel(visualHintsPanel, placement, DockSite.Right, 0.3f).Hidden = true; dockManager.AddPanel(attachmentPanel, placement, DockSite.Bottom, 0.3f).Hidden = true; dockManager.AddPanel(remoteScriptingPanel, placement, DockSite.Right, 0.3f).Hidden = true; DockManagerInitialState = dockManager.ExportState(); var documentViewContainer = InitializeDocumentArea(dockManager); documentPanel.ContentWidget.Nodes.Add(dockManager.DocumentArea); dockManager.ImportState(AppUserPreferences.Instance.DockState); Document.CloseConfirmation += doc => { var alert = new AlertDialog($"Save the changes to document '{doc.Path}' before closing?", "Yes", "No", "Cancel"); switch (alert.Show()) { case 0: return(Document.CloseAction.SaveChanges); case 1: return(Document.CloseAction.DiscardChanges); case -1: default: return(Document.CloseAction.Cancel); } }; mainWidget.Tasks.Add(HandleMissingDocumentsTask); Project.HandleMissingDocuments += missingDocuments => { foreach (var d in missingDocuments) { missingDocumentsList.Add(d); } }; Project.DocumentReloadConfirmation += doc => { if (doc.IsModified) { var modifiedAlert = new AlertDialog($"{doc.Path}\n\nThis file has been modified by another program and has unsaved changes.\nDo you want to reload it from disk? ", "Yes", "No"); var res = modifiedAlert.Show(); if (res == 1 || res == -1) { doc.History.ExternalModification(); return(false); } return(true); } if (CoreUserPreferences.Instance.ReloadModifiedFiles) { return(true); } var alert = new AlertDialog($"{doc.Path}\n\nThis file has been modified by another program.\nDo you want to reload it from disk? ", "Yes, always", "Yes", "No"); var r = alert.Show(); if (r == 0) { CoreUserPreferences.Instance.ReloadModifiedFiles = true; return(true); } if (r == 2) { doc.History.ExternalModification(); return(false); } return(true); }; Project.TempFileLoadConfirmation += path => { var alert = new AlertDialog($"Do you want to load autosaved version of '{path}'?", "Yes", "No"); return(alert.Show() == 0); }; Project.OpenFileOutsideProjectAttempt += (string filePath) => { var projectFilePath = SearhForCitproj(filePath); if (projectFilePath != null && Project.Current.CitprojPath != projectFilePath) { var alert = new AlertDialog($"You're trying to open a document outside the project directory. Change the current project to '{Path.GetFileName(projectFilePath)}'?", "Yes", "No"); if (alert.Show() == 0) { if (FileOpenProject.Execute(projectFilePath)) { Project.Current.OpenDocument(filePath, true); } return; } } else if (projectFilePath == null) { AlertDialog.Show("Can't open a document outside the project directory"); } }; Project.Tasks = dockManager.MainWindowWidget.Tasks; Project.Tasks.Add(new AutosaveProcessor(() => AppUserPreferences.Instance.AutosaveDelay)); BackupManager.Instance.Activate(Project.Tasks); Document.NodeDecorators.AddFor <Spline>(n => n.CompoundPostPresenter.Add(new UI.SceneView.SplinePresenter())); Document.NodeDecorators.AddFor <Viewport3D>(n => n.CompoundPostPresenter.Add(new UI.SceneView.Spline3DPresenter())); Document.NodeDecorators.AddFor <Viewport3D>(n => n.CompoundPostPresenter.Add(new UI.SceneView.Animation3DPathPresenter())); Document.NodeDecorators.AddFor <Widget>(n => { if (n.AsWidget.SkinningWeights == null) { n.AsWidget.SkinningWeights = new SkinningWeights(); } }); Document.NodeDecorators.AddFor <PointObject>(n => { if ((n as PointObject).SkinningWeights == null) { (n as PointObject).SkinningWeights = new SkinningWeights(); } }); Animation.EasingEnabledChecker = (animation) => { var doc = Document.Current; return(doc == null || doc.PreviewScene || animation != doc.Animation); }; if (SceneUserPreferences.Instance.VisualHintsRegistry != null) { VisualHintsRegistry.Instance = SceneUserPreferences.Instance.VisualHintsRegistry; } VisualHintsRegistry.Instance.RegisterDefaultHints(); Document.NodeDecorators.AddFor <Node>(n => n.SetTangerineFlag(TangerineFlags.SceneNode, true)); dockManager.UnhandledExceptionOccurred += e => { AlertDialog.Show(e.Message + "\n" + e.StackTrace); var doc = Document.Current; if (doc != null) { while (doc.History.IsTransactionActive) { doc.History.EndTransaction(); } var closeConfirmation = Document.CloseConfirmation; try { Document.CloseConfirmation = d => { var alert = new AlertDialog($"Save the changes to document '{d.Path}' before closing?", "Yes", "No"); switch (alert.Show()) { case 0: return(Document.CloseAction.SaveChanges); default: return(Document.CloseAction.DiscardChanges); } }; var fullPath = doc.FullPath; if (!File.Exists(fullPath)) { doc.Save(); } var path = doc.Path; Project.Current.CloseDocument(doc); Project.Current.OpenDocument(path); } finally { Document.CloseConfirmation = closeConfirmation; } } }; Document.NodeDecorators.AddFor <ParticleEmitter>(n => n.CompoundPostPresenter.Add(new UI.SceneView.ParticleEmitterPresenter())); DocumentHistory.AddOperationProcessorTypes(new[] { typeof(Core.Operations.TimelineHorizontalShift.Processor), typeof(Core.Operations.TimelineColumnRemove.Processor), typeof(Core.Operations.RemoveKeyframeRange.Processor), typeof(Core.Operations.SelectRow.Processor), typeof(Core.Operations.RenameAnimationProcessor), typeof(Core.Operations.SetProperty.Processor), typeof(Core.Operations.SetIndexedProperty.Processor), typeof(Core.Operations.RemoveKeyframe.Processor), typeof(Core.Operations.SetKeyframe.Processor), typeof(Core.Operations.InsertFolderItem.Processor), typeof(Core.Operations.AddIntoCollection <,> .Processor), typeof(Core.Operations.RemoveFromCollection <,> .Processor), typeof(Core.Operations.InsertIntoList.Processor), typeof(Core.Operations.RemoveFromList.Processor), typeof(Core.Operations.InsertIntoList <,> .Processor), typeof(Core.Operations.RemoveFromList <,> .Processor), typeof(Core.Operations.UnlinkFolderItem.Processor), typeof(Core.Operations.MoveNodes.Processor), typeof(Core.Operations.SetMarker.Processor), typeof(Core.Operations.DeleteMarker.Processor), typeof(Core.Operations.SetComponent.Processor), typeof(Core.Operations.DeleteComponent.Processor), typeof(Core.Operations.DistortionMeshProcessor), typeof(Core.Operations.SyncFolderDescriptorsProcessor), typeof(UI.SceneView.ResolutionPreviewOperation.Processor), typeof(UI.Timeline.Operations.SelectGridSpan.Processor), typeof(UI.Timeline.Operations.DeselectGridSpan.Processor), typeof(UI.Timeline.Operations.ClearGridSelection.Processor), typeof(UI.Timeline.Operations.ShiftGridSelection.Processor), typeof(UI.Timeline.Operations.SetCurrentColumn.Processor), typeof(UI.Timeline.Operations.SelectCurveKey.Processor), typeof(TriggersValidatorOnSetProperty), typeof(TriggersValidatorOnSetKeyframe), typeof(UpdateNodesAndApplyAnimatorsProcessor), typeof(RowsSynchronizer), typeof(Core.Operations.ReplaceContents.Processor), typeof(Core.Operations.DeleteRuler.Processor), typeof(Core.Operations.CreateRuler.Processor), }); DocumentHistory.AddOperationProcessorTypes(UI.Timeline.Timeline.GetOperationProcessorTypes()); RegisterCommands(); InitializeHotkeys(); AppUserPreferences.Instance.ToolbarModel.RefreshAfterLoad(); Toolbar = new ToolbarView(dockManager.ToolbarArea, AppUserPreferences.Instance.ToolbarModel); RefreshCreateNodeCommands(); Document.AttachingViews += doc => { if (doc.Views.Count == 0) { doc.Views.AddRange(new IDocumentView[] { new UI.Inspector.Inspector(inspectorPanel.ContentWidget), new UI.Timeline.Timeline(timelinePanel), new UI.SceneView.SceneView(documentViewContainer), new Panels.HierarchyPanel(searchPanel.ContentWidget), new Panels.BackupHistoryPanel(backupHistoryPanel.ContentWidget), new Panels.AnimationsPanel(animationsPanel.ContentWidget), // Use VisualHintsPanel sigleton because we need preserve its state between documents. VisualHintsPanel.Instance ?? VisualHintsPanel.Initialize(visualHintsPanel), new AttachmentPanel(attachmentPanel), }); UI.SceneView.SceneView.ShowNodeDecorationsPanelButton.Clicked = () => dockManager.TogglePanel(visualHintsPanel); } }; var proj = AppUserPreferences.Instance.CurrentProject; if (proj != null) { try { new Project(proj).Open(); } catch { AlertDialog.Show($"Cannot open project '{proj}'. It may be deleted or be otherwise unavailable."); } } OpenDocumentsFromArgs(args); WidgetContext.Current.Root.AddChangeWatcher(() => Project.Current, project => TangerineMenu.OnProjectChanged(project)); WidgetContext.Current.Root.AddChangeWatcher(() => ProjectUserPreferences.Instance.RecentDocuments.Count == 0 ? null : ProjectUserPreferences.Instance.RecentDocuments[0], document => TangerineMenu.RebuildRecentDocumentsMenu()); WidgetContext.Current.Root.AddChangeWatcher(() => AppUserPreferences.Instance.RecentProjects.Count == 0 ? null : AppUserPreferences.Instance.RecentProjects[0], document => TangerineMenu.RebuildRecentProjectsMenu()); new UI.FilesystemView.FilesystemPane(filesystemPanel); new UI.RemoteScripting.RemoteScriptingPane(remoteScriptingPanel); RegisterGlobalCommands(); Documentation.Init(); DocumentationComponent.Clicked = page => Documentation.ShowHelp(page); }
public PanelPlacement AppendPanelTo(Panel panel, LinearPlacement targetPlacement, float stretch = 0.25f) { return(Model.AppendPanelToPlacement(panel, targetPlacement, stretch)); }