-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
290 additions
and
55 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,71 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using NPlug.Backend; | ||
using NPlug.Vst3; | ||
|
||
namespace NPlug; | ||
|
||
public readonly struct AudioContextMenu | ||
{ | ||
private readonly IAudioContextMenuBackend _backend; | ||
internal readonly IntPtr NativeContext; | ||
|
||
public AudioContextMenu(IAudioContextMenuBackend backend, IntPtr nativeContext) | ||
{ | ||
_backend = backend; | ||
NativeContext = nativeContext; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number of menu items. | ||
/// </summary> | ||
public int ItemCount => _backend?.GetItemCount(this) ?? 0; | ||
|
||
/// <summary> | ||
/// Gets a menu item and its target (target could be not assigned). | ||
/// </summary> | ||
public void GetItem(int index, out AudioContextMenuItem item, out AudioContextMenuAction? target) | ||
{ | ||
GetSafeBackend().GetItem(this, index, out item, out target); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a menu item and its target. | ||
/// </summary> | ||
public void AddItem(in AudioContextMenuItem item, AudioContextMenuAction target) | ||
{ | ||
GetSafeBackend().AddItem(this, item, target); | ||
} | ||
|
||
/// <summary> | ||
/// Removes a menu item. | ||
/// </summary> | ||
public void RemoveItem(in AudioContextMenuItem item, AudioContextMenuAction target) | ||
{ | ||
GetSafeBackend().RemoveItem(this, item, target); | ||
} | ||
|
||
/// <summary> | ||
/// Pop-ups the menu. Coordinates are relative to the top-left position of the plug-ins view. | ||
/// </summary> | ||
public void Popup(int x, int y) | ||
{ | ||
GetSafeBackend().Popup(this, x, y); | ||
} | ||
|
||
private IAudioContextMenuBackend GetSafeBackend() | ||
{ | ||
if (_backend is null) ThrowNotInitialized(); | ||
return _backend; | ||
} | ||
|
||
[DoesNotReturn] | ||
private static void ThrowNotInitialized() | ||
{ | ||
throw new InvalidOperationException("This context menu is not initialized"); | ||
} | ||
} |
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 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
namespace NPlug; | ||
|
||
/// <summary> | ||
/// Delegate used by <see cref="AudioContextMenu"/>. | ||
/// </summary> | ||
/// <param name="tag">The associated tag to the triggered menu item (<see cref="AudioContextMenuItem.Tag"/>) </param> | ||
public delegate void AudioContextMenuAction(uint tag); |
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,13 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
namespace NPlug; | ||
|
||
/// <summary> | ||
/// A context menu item. | ||
/// </summary> | ||
/// <param name="Name">Name of the item.</param> | ||
/// <param name="Tag">Identifier tag of the item.</param> | ||
/// <param name="Flags">Flags of the item</param> | ||
public readonly record struct AudioContextMenuItem(string Name, int Tag = 0, AudioContextMenuItemFlags Flags = AudioContextMenuItemFlags.None); |
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,38 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
namespace NPlug; | ||
|
||
public enum AudioContextMenuItemFlags | ||
{ | ||
/// <summary> | ||
/// No options. | ||
/// </summary> | ||
None = 0, | ||
|
||
/// <summary> | ||
/// Item is a separator | ||
/// </summary> | ||
IsSeparator = 1 << 0, | ||
|
||
/// <summary> | ||
/// Item is disabled | ||
/// </summary> | ||
IsDisabled = 1 << 1, | ||
|
||
/// <summary> | ||
/// Item is checked | ||
/// </summary> | ||
IsChecked = 1 << 2, | ||
|
||
/// <summary> | ||
/// Item is a group start (like sub folder) | ||
/// </summary> | ||
IsGroupStart = 1 << 3 | IsDisabled, | ||
|
||
/// <summary> | ||
/// Item is a group end | ||
/// </summary> | ||
IsGroupEnd = 1 << 4 | IsSeparator, | ||
} |
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,33 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
namespace NPlug.Backend; | ||
|
||
public interface IAudioContextMenuBackend | ||
{ | ||
/// <summary> | ||
/// Gets the number of menu items. | ||
/// </summary> | ||
int GetItemCount(in AudioContextMenu contextMenu); | ||
|
||
/// <summary> | ||
/// Gets a menu item and its target (target could be not assigned). | ||
/// </summary> | ||
void GetItem(in AudioContextMenu contextMenu, int index, out AudioContextMenuItem item, out AudioContextMenuAction? target); | ||
|
||
/// <summary> | ||
/// Adds a menu item and its target. | ||
/// </summary> | ||
void AddItem(in AudioContextMenu contextMenu, in AudioContextMenuItem item, AudioContextMenuAction target); | ||
|
||
/// <summary> | ||
/// Removes a menu item. | ||
/// </summary> | ||
void RemoveItem(in AudioContextMenu contextMenu, in AudioContextMenuItem item, AudioContextMenuAction target); | ||
|
||
/// <summary> | ||
/// Pop-ups the menu. Coordinates are relative to the top-left position of the plug-ins view. | ||
/// </summary> | ||
void Popup(in AudioContextMenu contextMenu, int x, int y); | ||
} |
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.