code clean up
This commit is contained in:
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewBase.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ViewBase"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Mathematics;
|
||||
using StgSharp.MVVM.ViewModel;
|
||||
@@ -73,16 +70,16 @@ namespace StgSharp.MVVM
|
||||
|
||||
private ViewPort context;
|
||||
|
||||
private delegate bool GetDataBindingEntryDelegate( string name, out DataBindingEntry entry );
|
||||
private delegate bool GetDataBindingEntryDelegate(string name, out DataBindingEntry entry);
|
||||
|
||||
public DataBindingEntry this[ string name ]
|
||||
public DataBindingEntry this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( getDataBindingEntry( name, out DataBindingEntry entry ) ) {
|
||||
if (getDataBindingEntry(name, out DataBindingEntry entry)) {
|
||||
return entry;
|
||||
}
|
||||
if( TryGetObjectReference( name, out entry ) ) {
|
||||
if (TryGetObjectReference(name, out entry)) {
|
||||
return entry;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
@@ -142,7 +139,7 @@ namespace StgSharp.MVVM
|
||||
set => _responder = value;
|
||||
}
|
||||
|
||||
public abstract void CustomizedInitialize( [NotNull]ViewModelBase viewModelBinding );
|
||||
public abstract void CustomizedInitialize([NotNull]ViewModelBase viewModelBinding);
|
||||
|
||||
/// <summary>
|
||||
/// Get the status of a certain key on the keyboard.
|
||||
@@ -153,16 +150,13 @@ namespace StgSharp.MVVM
|
||||
/// <returns>
|
||||
/// <see cref="KeyStatus" /> representing if a key is pressed or released.
|
||||
/// </returns>
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
public KeyStatus GetKeyStatus( KeyboardKey key )
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public KeyStatus GetKeyStatus(KeyboardKey key)
|
||||
{
|
||||
return InternalIO.glfwGetKey( context.ViewPortHandle, ( int )key );
|
||||
return InternalIO.glfwGetKey(context.ViewPortHandle, (int)key);
|
||||
}
|
||||
|
||||
public void InternalInitialize(
|
||||
string name,
|
||||
(int, int, int) cubeSize,
|
||||
[NotNull]ViewModelBase viewModelBinding )
|
||||
public void InternalInitialize(string name, (int, int, int) cubeSize, [NotNull]ViewModelBase viewModelBinding)
|
||||
{
|
||||
SelfName = name;
|
||||
unitCubeSize = cubeSize;
|
||||
@@ -170,18 +164,18 @@ namespace StgSharp.MVVM
|
||||
context = viewModelBinding.ViewPortBinding;
|
||||
time = viewModelBinding.frameTimeProvider;
|
||||
|
||||
CustomizedInitialize( viewModelBinding );
|
||||
CustomizedInitialize(viewModelBinding);
|
||||
}
|
||||
|
||||
public abstract bool TryGetObjectReference( string name, out DataBindingEntry entry );
|
||||
public abstract bool TryGetObjectReference(string name, out DataBindingEntry entry);
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if( usedFrame == 0 )
|
||||
if (usedFrame == 0)
|
||||
{
|
||||
if( !ValidateInitialization() ) {
|
||||
if (!ValidateInitialization()) {
|
||||
throw new InvalidOperationException(
|
||||
"This view is not correctly initialized before rendering." );
|
||||
"This view is not correctly initialized before rendering.");
|
||||
}
|
||||
}
|
||||
Show();
|
||||
@@ -190,10 +184,10 @@ namespace StgSharp.MVVM
|
||||
|
||||
public bool ValidateInitialization()
|
||||
{
|
||||
return ( _design != null ) &&
|
||||
( _render != null ) &&
|
||||
( getDataBindingEntry != null ) &&
|
||||
( _responder != null ) &&
|
||||
return (_design != null) &&
|
||||
(_render != null) &&
|
||||
(getDataBindingEntry != null) &&
|
||||
(_responder != null) &&
|
||||
_design.ValidateInitializing() &&
|
||||
_responder.ValidateInitializing() &&
|
||||
_render.ValidateInitializing();
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewDesigner.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ViewDesigner"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.Controls;
|
||||
using StgSharp.Geometries;
|
||||
@@ -69,7 +66,7 @@ namespace StgSharp.MVVM
|
||||
private List<ControllingItem> _controlList;
|
||||
protected TView _binding;
|
||||
|
||||
public ViewDesigner( TView binding )
|
||||
public ViewDesigner(TView binding)
|
||||
{
|
||||
_binding = binding;
|
||||
_controlList = new List<ControllingItem>();
|
||||
@@ -84,23 +81,23 @@ namespace StgSharp.MVVM
|
||||
int length,
|
||||
char blankFilling,
|
||||
PlainGeometryMesh tittle,
|
||||
IEnumerable<(char, PlainGeometryMesh)> charList )
|
||||
IEnumerable<(char, PlainGeometryMesh)> charList)
|
||||
{
|
||||
CharacterLineIndexImage ret = new CharacterLineIndexImage(
|
||||
length, blankFilling, tittle, charList );
|
||||
_controlList.Add( ret );
|
||||
length, blankFilling, tittle, charList);
|
||||
_controlList.Add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TriggerButton CreateKeyboardButton(
|
||||
Rectangle bonding,
|
||||
TextureProvider defaultAnimation,
|
||||
bool isEnable )
|
||||
bool isEnable)
|
||||
{
|
||||
TriggerButton ret = new TriggerButton();
|
||||
ret.BoundingBox = bonding;
|
||||
ret.Texture = defaultAnimation;
|
||||
if( isEnable )
|
||||
if (isEnable)
|
||||
{
|
||||
ret.IsDisabled = false;
|
||||
ret.Enable();
|
||||
@@ -109,7 +106,7 @@ namespace StgSharp.MVVM
|
||||
ret.IsDisabled = true;
|
||||
ret.Disable();
|
||||
}
|
||||
currentButtonGroup.AddButton( ret );
|
||||
currentButtonGroup.AddButton(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -118,17 +115,17 @@ namespace StgSharp.MVVM
|
||||
IClickTrigger rightBinding,
|
||||
IClickTrigger upBinding,
|
||||
IClickTrigger downBinding,
|
||||
IClickTrigger confirmBinding )
|
||||
IClickTrigger confirmBinding)
|
||||
where TButtonGroup: KeyboardButtonGroup, new()
|
||||
{
|
||||
TButtonGroup ret = new TButtonGroup();
|
||||
_controlList.Add( ret );
|
||||
_controlList.Add(ret);
|
||||
currentButtonGroup = ret;
|
||||
_binding.Responder[ leftBidning ] = ret.MoveLeft;
|
||||
_binding.Responder[ rightBinding ] = ret.MoveRight;
|
||||
_binding.Responder[ upBinding ] = ret.MoveUp;
|
||||
_binding.Responder[ downBinding ] = ret.MoveDown;
|
||||
_binding.Responder[ confirmBinding ] = ret.Confirm;
|
||||
_binding.Responder[leftBidning] = ret.MoveLeft;
|
||||
_binding.Responder[rightBinding] = ret.MoveRight;
|
||||
_binding.Responder[upBinding] = ret.MoveUp;
|
||||
_binding.Responder[downBinding] = ret.MoveDown;
|
||||
_binding.Responder[confirmBinding] = ret.Confirm;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewRender.cs"
|
||||
// Project: StepVisualizer
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ViewRender"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using StgSharp.HighPerformance;
|
||||
@@ -44,7 +41,7 @@ namespace StgSharp.MVVM
|
||||
protected internal interface IViewRender<out TView> where TView: ViewBase
|
||||
{
|
||||
|
||||
RenderStream this[ DataLabel renderName ] { get; }
|
||||
RenderStream this[DataLabel renderName] { get; }
|
||||
|
||||
void CustomizedInitialize();
|
||||
|
||||
@@ -59,24 +56,23 @@ namespace StgSharp.MVVM
|
||||
protected abstract class ViewRender<TView> : IViewRender<TView> where TView: ViewBase
|
||||
{
|
||||
|
||||
protected ViewRender( TView binding )
|
||||
protected ViewRender(TView binding)
|
||||
{
|
||||
_binding = binding;
|
||||
_render = new Dictionary<DataLabel, RenderStream>();
|
||||
}
|
||||
|
||||
public RenderStream this[ DataLabel renderName ]
|
||||
public RenderStream this[DataLabel renderName]
|
||||
{
|
||||
get => _render.TryGetValue( renderName, out RenderStream stream ) ?
|
||||
stream : ( null! );
|
||||
get => _render.TryGetValue(renderName, out RenderStream stream) ? stream : (null!);
|
||||
protected set
|
||||
{
|
||||
if( _render.ContainsKey( renderName ) )
|
||||
if (_render.ContainsKey(renderName))
|
||||
{
|
||||
_render[ renderName ] = value;
|
||||
_render[renderName] = value;
|
||||
} else
|
||||
{
|
||||
_render.Add( renderName, value );
|
||||
_render.Add(renderName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,26 +81,26 @@ namespace StgSharp.MVVM
|
||||
|
||||
protected ViewPort ContextBinding => _binding.context;
|
||||
|
||||
protected ViewDesigner<TView> Design => ( _binding.Designer as ViewDesigner<TView> )!;
|
||||
protected ViewDesigner<TView> Design => (_binding.Designer as ViewDesigner<TView>)!;
|
||||
|
||||
protected Dictionary<DataLabel, RenderStream> Render
|
||||
{
|
||||
get => _render;
|
||||
}
|
||||
|
||||
protected ViewResponder<TView> Responder => ( _binding.Responder as ViewResponder<TView> )!;
|
||||
protected ViewResponder<TView> Responder => (_binding.Responder as ViewResponder<TView>)!;
|
||||
|
||||
public T CreateRenderStream<T>() where T: RenderStream, new()
|
||||
{
|
||||
T ret = new T();
|
||||
ret.Initialize( _binding.context, Binding.TimeProvider );
|
||||
ret.Initialize(_binding.context, Binding.TimeProvider);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T CreateRenderStream<T>( ViewPort vp ) where T: RenderStream, new()
|
||||
public T CreateRenderStream<T>(ViewPort vp) where T: RenderStream, new()
|
||||
{
|
||||
T ret = new T();
|
||||
ret.Initialize( vp, Binding.TimeProvider );
|
||||
ret.Initialize(vp, Binding.TimeProvider);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -112,7 +108,7 @@ namespace StgSharp.MVVM
|
||||
|
||||
public IEnumerator<ViewPort> GetEnumerator()
|
||||
{
|
||||
foreach( RenderStream item in Render.Values ) {
|
||||
foreach (RenderStream item in Render.Values) {
|
||||
yield return item.BindedViewPortContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewResponder.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
// -----------------------------------------------------------------------
|
||||
// file="ViewResponder"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Controlling.UsrActivity;
|
||||
using StgSharp.MVVM.ViewModel;
|
||||
|
||||
@@ -45,11 +42,11 @@ namespace StgSharp.MVVM
|
||||
protected interface IViewResponder<out TVIew> where TVIew: ViewBase
|
||||
{
|
||||
|
||||
Action? this[ IClickTrigger trigger ] { get; set; }
|
||||
Action? this[IClickTrigger trigger] { get; set; }
|
||||
|
||||
void CustomizedInitialize( Func<IClickTrigger, string, Action> keyRegister );
|
||||
void CustomizedInitialize(Func<IClickTrigger, string, Action> keyRegister);
|
||||
|
||||
void Initialize( MethodLookUpDelegate methodGetter );
|
||||
void Initialize(MethodLookUpDelegate methodGetter);
|
||||
|
||||
void ProcessUserInput();
|
||||
|
||||
@@ -65,7 +62,7 @@ namespace StgSharp.MVVM
|
||||
private Dictionary<string, Action> nameToCallbackMap;
|
||||
private TView _binding;
|
||||
|
||||
protected ViewResponder( TView binding )
|
||||
protected ViewResponder(TView binding)
|
||||
{
|
||||
keyCallbackIndex = new Dictionary<IClickTrigger, Action>();
|
||||
nameToCallbackMap = new Dictionary<string, Action>();
|
||||
@@ -73,58 +70,54 @@ namespace StgSharp.MVVM
|
||||
}
|
||||
|
||||
#pragma warning disable CA1043
|
||||
public Action? this[ IClickTrigger trigger ]
|
||||
public Action? this[IClickTrigger trigger]
|
||||
#pragma warning restore CA1043
|
||||
{
|
||||
get => keyCallbackIndex.TryGetValue( trigger, out Action callback ) ?
|
||||
callback : null;
|
||||
get => keyCallbackIndex.TryGetValue(trigger, out Action callback) ? callback : null;
|
||||
set
|
||||
{
|
||||
if( keyCallbackIndex.TryGetValue( trigger, out Action callback ) )
|
||||
if (keyCallbackIndex.TryGetValue(trigger, out Action callback))
|
||||
{
|
||||
callback += value;
|
||||
} else
|
||||
{
|
||||
keyCallbackIndex.Add(
|
||||
trigger, value ?? throw new ArgumentNullException( nameof( value ) ) );
|
||||
trigger, value ?? throw new ArgumentNullException(nameof(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected TView Binding => _binding;
|
||||
|
||||
public abstract void CustomizedInitialize(
|
||||
Func<IClickTrigger, string, Action> keyRegister );
|
||||
public abstract void CustomizedInitialize(Func<IClickTrigger, string, Action> keyRegister);
|
||||
|
||||
public void Initialize( MethodLookUpDelegate methodGetter )
|
||||
public void Initialize(MethodLookUpDelegate methodGetter)
|
||||
{
|
||||
if( _isInitialized ) {
|
||||
if (_isInitialized) {
|
||||
return;
|
||||
}
|
||||
CustomizedInitialize(
|
||||
( trigger, name ) => {
|
||||
if( !nameToCallbackMap.TryGetValue( name, out Action ret ) )
|
||||
CustomizedInitialize((trigger, name) => {
|
||||
if (!nameToCallbackMap.TryGetValue(name, out Action ret))
|
||||
{
|
||||
if (methodGetter(name, out Action lookup))
|
||||
{
|
||||
if( methodGetter( name, out Action lookup ) )
|
||||
{
|
||||
this[ trigger ] = lookup;
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot find method named {name} in binded view model" );
|
||||
}
|
||||
this[trigger] = lookup;
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot find method named {name} in binded view model");
|
||||
}
|
||||
return ret;
|
||||
} );
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
public void ProcessUserInput()
|
||||
{
|
||||
foreach( KeyValuePair<IClickTrigger, Action> pair in keyCallbackIndex )
|
||||
foreach (KeyValuePair<IClickTrigger, Action> pair in keyCallbackIndex)
|
||||
{
|
||||
if( InternalIO.glfwGetKey( _binding.ViewHandle,
|
||||
pair.Key.TargetKeyOrButtonID ) ==
|
||||
pair.Key.TriggeredStatus ) {
|
||||
if (InternalIO.glfwGetKey(_binding.ViewHandle,
|
||||
pair.Key.TargetKeyOrButtonID) == pair.Key.TriggeredStatus) {
|
||||
pair.Value();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user