-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major changes introducing document contexts and selection command han…
…dling
- Loading branch information
Showing
51 changed files
with
743 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
<PropertyGroup> | ||
<TargetFramework>$(TargetFramework)</TargetFramework> | ||
<UseWPF>True</UseWPF> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\External\Glyph\External\Fingear\Fingear\Fingear.csproj" /> | ||
<ProjectReference Include="..\External\Glyph\Glyph.Composition\Glyph.Composition.csproj" /> | ||
<ProjectReference Include="..\External\Glyph\Glyph\Glyph.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Glyph.Composition; | ||
|
||
namespace Calame.DocumentContexts | ||
{ | ||
public interface IRootComponentsContext | ||
{ | ||
IEnumerable<IGlyphComponent> RootComponents { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Fingear.Interactives; | ||
|
||
namespace Calame.DocumentContexts | ||
{ | ||
public interface IRootInteractivesContext | ||
{ | ||
IEnumerable<IInteractive> RootInteractives { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Glyph; | ||
|
||
namespace Calame.DocumentContexts | ||
{ | ||
public interface IRootScenesContext | ||
{ | ||
IEnumerable<ISceneNode> RootScenes { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections; | ||
|
||
namespace Calame.DocumentContexts | ||
{ | ||
public interface IRootsContext | ||
{ | ||
IEnumerable Roots { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
|
||
namespace Calame.DocumentContexts | ||
{ | ||
public interface ISelectionCommandContext | ||
{ | ||
ICommand SelectCommand { get; } | ||
event EventHandler CanSelectChanged; | ||
bool CanSelect(object instance); | ||
Task SelectAsync(object instance); | ||
} | ||
|
||
public interface ISelectionCommandContext<in T> : ISelectionCommandContext | ||
{ | ||
bool CanSelect(T instance); | ||
Task SelectAsync(T instance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Threading.Tasks; | ||
using Calame.Commands.Base; | ||
using Calame.Icons; | ||
using Calame.Viewer.Commands.Base; | ||
using Gemini.Framework.Commands; | ||
|
||
namespace Calame.Viewer.Commands | ||
{ | ||
[CommandDefinition] | ||
public class ViewerDebugModeCommand : CalameCommandDefinitionBase | ||
{ | ||
public override string Text => "Viewer _Debug Mode"; | ||
public override object IconKey => CalameIconKey.ViewerDebugMode; | ||
|
||
[CommandHandler] | ||
public class CommandHandler : ViewerDocumentCommandHandlerBase<IViewerDocument, ViewerDebugModeCommand> | ||
{ | ||
protected override void UpdateStatus(Command command, IViewerDocument document) | ||
{ | ||
base.UpdateStatus(command, document); | ||
command.Checked = document?.DebugMode ?? false; | ||
} | ||
|
||
protected override Task RunAsync(Command command, IViewerDocument document) | ||
{ | ||
document.DebugMode = !document.DebugMode; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows.Input; | ||
using Calame.DocumentContexts; | ||
using Calame.Viewer.ViewModels; | ||
using Caliburn.Micro; | ||
using Fingear.Interactives; | ||
using Glyph; | ||
using Glyph.Composition; | ||
using Glyph.Engine; | ||
using Stave; | ||
|
||
namespace Calame.Viewer | ||
{ | ||
public class DebuggableViewerContexts : PropertyChangedBase, IRootsContext, IRootComponentsContext, IRootScenesContext, IRootInteractivesContext | ||
{ | ||
private ViewerViewModel _viewer; | ||
public ViewerViewModel Viewer | ||
{ | ||
get => _viewer; | ||
private set => Set(ref _viewer, value); | ||
} | ||
|
||
private IEnumerable _roots; | ||
public IEnumerable Roots | ||
{ | ||
get => _roots; | ||
private set => Set(ref _roots, value); | ||
} | ||
|
||
private IEnumerable<IGlyphComponent> _rootComponents; | ||
public IEnumerable<IGlyphComponent> RootComponents | ||
{ | ||
get => _rootComponents; | ||
private set => Set(ref _rootComponents, value); | ||
} | ||
|
||
private IEnumerable<IInteractive> _rootInteractives; | ||
public IEnumerable<IInteractive> RootInteractives | ||
{ | ||
get => _rootInteractives; | ||
private set => Set(ref _rootInteractives, value); | ||
} | ||
|
||
private bool _debugMode; | ||
public bool DebugMode | ||
{ | ||
get => _debugMode; | ||
set | ||
{ | ||
if (Set(ref _debugMode, value)) | ||
RefreshContexts(); | ||
} | ||
} | ||
|
||
public GlyphEngine Engine => _viewer.Runner.Engine; | ||
public IEnumerable<ISceneNode> RootScenes => _viewer.Runner.Engine.ProjectionManager.SceneRoots; | ||
|
||
private IGlyphComponent _userParentComponent; | ||
|
||
public IGlyphComponent UserParentComponent | ||
{ | ||
get => _userParentComponent; | ||
set | ||
{ | ||
if (_userParentComponent == value) | ||
return; | ||
|
||
_userParentComponent = value; | ||
|
||
if (!DebugMode) | ||
RefreshContexts(); | ||
} | ||
} | ||
|
||
public DebuggableViewerContexts(ViewerViewModel viewer, ISelectionCommandContext selectionCommandContext) | ||
{ | ||
Viewer = viewer; | ||
SelectCommand = new SelectionCommand(selectionCommandContext); | ||
} | ||
|
||
public void RefreshContexts() | ||
{ | ||
if (DebugMode) | ||
{ | ||
RootComponents = new IGlyphComponent[] { _viewer.Runner.Engine.Root }; | ||
RootInteractives = new IInteractive[] { _viewer.Runner.Engine.InteractionManager.Root }; | ||
} | ||
else | ||
{ | ||
RootComponents = (UserParentComponent ?? _viewer.UserRoot).Components; | ||
RootInteractives = _viewer.InteractiveModes.Where(x => x.IsUserMode).Select(x => x.Interactive); | ||
} | ||
|
||
Roots = RootComponents; | ||
CanSelectChanged?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
public ICommand SelectCommand { get; } | ||
public event EventHandler CanSelectChanged; | ||
|
||
public bool CanSelect(IGlyphComponent component) | ||
{ | ||
if (DebugMode) | ||
return CanSelectInDebugMode(component); | ||
|
||
return CanSelectInUserMode(component); | ||
} | ||
|
||
private bool CanSelectInDebugMode(IGlyphComponent component) | ||
{ | ||
return CanSelectBase(component) | ||
&& !component.AndAllParents().Any(_viewer.NotSelectableComponents.Contains); | ||
} | ||
|
||
private bool CanSelectInUserMode(IGlyphComponent component) | ||
{ | ||
return CanSelectBase(component) | ||
&& component.AllParents().Contains(UserParentComponent ?? _viewer.UserRoot); | ||
} | ||
|
||
private bool CanSelectBase(IGlyphComponent component) | ||
{ | ||
return component != null && !component.GetType().IsValueType; | ||
} | ||
|
||
private class SelectionCommand : ICommand | ||
{ | ||
private readonly ISelectionCommandContext _context; | ||
|
||
public SelectionCommand(ISelectionCommandContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public event EventHandler CanExecuteChanged | ||
{ | ||
add => _context.CanSelectChanged += value; | ||
remove => _context.CanSelectChanged -= value; | ||
} | ||
|
||
public bool CanExecute(object parameter) => _context.CanSelect(parameter); | ||
public void Execute(object parameter) => _context.SelectAsync(parameter).Wait(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
using Calame.Viewer.ViewModels; | ||
using Calame.DocumentContexts; | ||
using Calame.Viewer.ViewModels; | ||
using Gemini.Framework; | ||
using Glyph.Composition; | ||
using Glyph.Engine; | ||
|
||
namespace Calame.Viewer | ||
{ | ||
public interface IViewerDocument : IDocument, IViewerViewModelOwner, IDocumentContext<GlyphEngine>, IDocumentContext<ViewerViewModel>, IDocumentContext<IComponentFilter> | ||
public interface IViewerDocument : IDocument, IViewerViewModelOwner, | ||
IDocumentContext<ViewerViewModel>, | ||
IDocumentContext<GlyphEngine>, | ||
IDocumentContext<IRootsContext>, | ||
IDocumentContext<IRootComponentsContext>, | ||
IDocumentContext<IRootScenesContext>, | ||
IDocumentContext<IRootInteractivesContext>, | ||
IDocumentContext<ISelectionCommandContext>, | ||
IDocumentContext<ISelectionCommandContext<IGlyphComponent>>, | ||
ISelectionCommandContext<IGlyphComponent> | ||
{ | ||
ViewerViewModel Viewer { get; } | ||
bool DebugMode { get; set; } | ||
void EnableFreeCamera(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.