Skip to content

Commit

Permalink
minor changes, notes tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ImAxel0 committed May 26, 2024
1 parent a8137db commit 70a24fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
9 changes: 9 additions & 0 deletions Openthesia/Drawings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public static void Tooltip(string description)
ImGui.EndTooltip();
}
}

public static void NoteTooltip(string description)
{
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35.0f);
ImGui.TextUnformatted(description);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}
}
13 changes: 12 additions & 1 deletion Openthesia/MidiFileView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Vulkan.Xlib;

namespace Openthesia;

Expand Down Expand Up @@ -54,6 +55,17 @@ public static void Render()

ImGui.PushFont(FontController.GetFontOfSize(22));

var drawList = ImGui.GetWindowDrawList();
string t1 = "Peacefully listen and visualize the piece";
drawList.AddText(new(ImGui.GetIO().DisplaySize.X / 10 + 125, ImGui.GetIO().DisplaySize.Y / 2.5f),
ImGui.GetColorU32(Vector4.One), t1);
string t2 = "Playback will wait for the right note input";
drawList.AddText(new(ImGui.GetIO().DisplaySize.X / 2.8f + 125, ImGui.GetIO().DisplaySize.Y / 2.5f),
ImGui.GetColorU32(Vector4.One), t2);
string t3 = "Separate right and left hands with colors";
drawList.AddText(new(ImGui.GetIO().DisplaySize.X / 1.6f + 125, ImGui.GetIO().DisplaySize.Y / 2.5f),
ImGui.GetColorU32(Vector4.One), t3);

ImGuiTheme.PushButton(ImGuiTheme.HtmlToVec4("#31CB15"), ImGuiTheme.HtmlToVec4("#20870E"), ImGuiTheme.HtmlToVec4("#31CB15"));
ImGui.SetCursorPos(new(ImGui.GetIO().DisplaySize.X / 10, ImGui.GetIO().DisplaySize.Y / 1.5f));
if (ImGui.Button($"View and listen", new(250, 100)))
Expand Down Expand Up @@ -94,7 +106,6 @@ public static void Render()
if (ImGui.Button($"Edit mode", new(250, 100)))
{
ScreenCanvas.SetLearningMode(false);
// set edit mode true
ScreenCanvas.SetEditMode(true);
LeftRightData.S_IsRightNote.Clear();
foreach (var n in MidiFileData.Notes)
Expand Down
28 changes: 22 additions & 6 deletions Openthesia/ScreenCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ private static void DrawPlaybackNotes()

if (IsEditMode)
{
if (ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left) && !_isRectMode)
if (ImGui.GetIO().KeyCtrl && ImGui.IsMouseDown(ImGuiMouseButton.Left) && !_isRectMode)
{
_rectStart = ImGui.GetMousePos();
_isRightRect = false;
_isRectMode = true;
}

if (ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Right) && !_isRectMode)
if (ImGui.GetIO().KeyCtrl && ImGui.IsMouseDown(ImGuiMouseButton.Right) && !_isRectMode)
{
_rectStart = ImGui.GetMousePos();
_isRightRect = true;
Expand All @@ -283,10 +283,16 @@ private static void DrawPlaybackNotes()

if (_isRectMode)
{
// only allow rect going top-left
if (ImGui.GetMousePos().Y > _rectStart.Y || ImGui.GetMousePos().X > _rectStart.X)
{
_isRectMode = false;
}

Vector4 rectCol = _isRightRect ? Settings.R_HandColor : Settings.L_HandColor;
ImGui.GetWindowDrawList().AddRect(_rectStart, ImGui.GetMousePos(), ImGui.GetColorU32(rectCol));
var v3 = new Vector3(rectCol.X, rectCol.Y, rectCol.Z);
ImGui.GetWindowDrawList().AddRectFilled(_rectStart, ImGui.GetMousePos(), ImGui.GetColorU32(new Vector4(v3, .005f)));

// to refactor, performance heavy
float rpx1;
float rpx2;
if (note.NoteName.ToString().EndsWith("Sharp"))
Expand Down Expand Up @@ -319,7 +325,12 @@ private static void DrawPlaybackNotes()
if (ImGui.IsMouseHoveringRect(new(PianoRenderer.P.X + PianoRenderer.BlackNoteToKey.GetValueOrDefault(note.NoteNumber, 0) * PianoRenderer.Width + PianoRenderer.Width * 3 / 4, py1),
new(PianoRenderer.P.X + PianoRenderer.BlackNoteToKey.GetValueOrDefault(note.NoteNumber, 0) * PianoRenderer.Width + PianoRenderer.Width * 5 / 4, py2)))
{
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
if (ShowTextNotes)
{
Drawings.NoteTooltip($"Note: {note.NoteName}\nOctave: {note.Octave}\nVelocity: {note.Velocity}" +
$"\nNumber: {note.NoteNumber}\nRight Hand: {LeftRightData.S_IsRightNote[index]}");
}

if (ImGui.IsMouseDown(ImGuiMouseButton.Left) && !_isRectMode)
{
// set left
Expand All @@ -339,7 +350,12 @@ private static void DrawPlaybackNotes()
if (ImGui.IsMouseHoveringRect(new(PianoRenderer.P.X + PianoRenderer.WhiteNoteToKey.GetValueOrDefault(note.NoteNumber, 0) * PianoRenderer.Width, py1),
new(PianoRenderer.P.X + PianoRenderer.WhiteNoteToKey.GetValueOrDefault(note.NoteNumber, 0) * PianoRenderer.Width + PianoRenderer.Width, py2)))
{
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
if (ShowTextNotes)
{
Drawings.NoteTooltip($"Note: {note.NoteName}\nOctave: {note.Octave}\nVelocity: {note.Velocity}" +
$"\nNumber: {note.NoteNumber}\nRight Hand: {LeftRightData.S_IsRightNote[index]}");
}

if (ImGui.IsMouseDown(ImGuiMouseButton.Left) && !_isRectMode)
{
// set left
Expand Down

0 comments on commit 70a24fd

Please sign in to comment.