Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
make the cursor work
Browse files Browse the repository at this point in the history
  • Loading branch information
LingFeng-bbben committed Mar 23, 2023
1 parent e0371a6 commit d024585
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
5 changes: 3 additions & 2 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ private void FumenContent_SelectionChanged(object sender, RoutedEventArgs e)
}
//Console.WriteLine("SelectionChanged");
SimaiProcess.ClearNoteListPlayedState();
DrawCusor(time);
ghostCusorPositionTime = (float)time;
DrawWave();
}
private void FumenContent_TextChanged(object sender, TextChangedEventArgs e)
{
Expand Down Expand Up @@ -505,7 +506,7 @@ private void WaveViewZoomOut_Click(object sender, RoutedEventArgs e)
}
private void MusicWave_MouseWheel(object sender, MouseWheelEventArgs e)
{
ScrollWave(e.Delta);
ScrollWave(-e.Delta);
}
private void MusicWave_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Expand Down
67 changes: 21 additions & 46 deletions MainWindowCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public partial class MainWindow : Window
double songLength = 0;
float sampleTime = 0.02f;
float deltatime = 8f;
float ghostCusorPositionTime = 0f;
EditorControlMethod lastEditorState;

double lastMousePointX; //Used for drag scroll
Expand Down Expand Up @@ -99,6 +100,7 @@ long GetRawFumenPosition()
}
void SeekTextFromTime()
{
//Console.WriteLine("SeekText");
var time = Bass.BASS_ChannelBytes2Seconds(bgmStream, Bass.BASS_ChannelGetPosition(bgmStream));
List<SimaiTimingPoint> timingList = new List<SimaiTimingPoint>();
timingList.AddRange(SimaiProcess.timinglist);
Expand Down Expand Up @@ -126,7 +128,7 @@ public void ScrollToFumenContentSelection(int positionX, int positionY)
SetBgmPosition(time);
//Console.WriteLine("SelectionChanged");
SimaiProcess.ClearNoteListPlayedState();
DrawCusor(time);
ghostCusorPositionTime = (float)time;
}

//*FIND AND REPLACE
Expand Down Expand Up @@ -508,7 +510,7 @@ void AddGesture( string keyGusture,string command)


//*UI DRAWING
Timer visualEffectRefreshTimer = new Timer(16);
Timer visualEffectRefreshTimer = new Timer(5);
Timer currentTimeRefreshTimer = new Timer(100);
public Timer chartChangeTimer = new Timer(1000); // 谱面变更延迟解析]\

Expand Down Expand Up @@ -838,61 +840,35 @@ private void DrawWave()
graphics.DrawLine(pen, xSlide, y, xSlideRight, y);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
}



}

}




graphics.Flush();
graphics.Dispose();
backBitmap.Dispose();
MusicWave.Source = writableBitmap;
//MusicWave.Width = waveLevels.Length * zoominPower;
writableBitmap.AddDirtyRect(new Int32Rect(0, 0, writableBitmap.PixelWidth, writableBitmap.PixelHeight));
writableBitmap.Unlock();
}));
//isDrawing = false;
}
private async void DrawCusor(double ghostCusorPositionTime = 0)
{
/* var writableBitmap = new WriteableBitmap(waveLevels.Length * zoominPower, 74, 72, 72, PixelFormats.Pbgra32, null);
writableBitmap.Lock();
//the process starts
Bitmap backBitmap = new Bitmap(waveLevels.Length * zoominPower, 74, writableBitmap.BackBufferStride,
System.Drawing.Imaging.PixelFormat.Format32bppArgb, writableBitmap.BackBuffer);
Graphics graphics = Graphics.FromImage(backBitmap);
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Green, zoominPower);
await Task.Run(() =>
{
try
if ((playStartTime - currentTime) <= deltatime)
{
//Draw play Start time
pen = new System.Drawing.Pen(System.Drawing.Color.Red, 5);
float x1 = (float)(playStartTime / sampleTime) * zoominPower;
float x1 = (float)((playStartTime / step) - startindex) * linewidth;
PointF[] tranglePoints = { new PointF(x1 - 2, 0), new PointF(x1 + 2, 0), new PointF(x1, 3.46f) };
graphics.DrawPolygon(pen, tranglePoints);
}
if ((ghostCusorPositionTime - currentTime) <= deltatime)
{
//Draw ghost cusor
pen = new System.Drawing.Pen(System.Drawing.Color.Orange, 5);
float x2 = (float)(ghostCusorPositionTime / sampleTime) * zoominPower;
float x2 = (float)((ghostCusorPositionTime / step) - startindex) * linewidth;
PointF[] tranglePoints2 = { new PointF(x2 - 2, 0), new PointF(x2 + 2, 0), new PointF(x2, 3.46f) };
graphics.DrawPolygon(pen, tranglePoints2);
}
catch { }
});
graphics.Flush();
graphics.Dispose();
backBitmap.Dispose();
MusicWaveCusor.Source = writableBitmap;
MusicWaveCusor.Width = waveLevels.Length * zoominPower;
writableBitmap.AddDirtyRect(new Int32Rect(0, 0, writableBitmap.PixelWidth, writableBitmap.PixelHeight));
writableBitmap.Unlock();*/

graphics.Flush();
graphics.Dispose();
backBitmap.Dispose();
MusicWave.Source = writableBitmap;
//MusicWave.Width = waveLevels.Length * zoominPower;
writableBitmap.AddDirtyRect(new Int32Rect(0, 0, writableBitmap.PixelWidth, writableBitmap.PixelHeight));
writableBitmap.Unlock();
}));
//isDrawing = false;
}

// This update less frequently. set the time text.
Expand Down Expand Up @@ -1036,9 +1012,8 @@ void TogglePlay(PlayMethod playMethod = PlayMethod.Normal)
});
break;
}

ghostCusorPositionTime = (float)CusorTime;
DrawWave();
DrawCusor(CusorTime); //then the wave could be draw
}
void TogglePause()
{
Expand Down
3 changes: 3 additions & 0 deletions SoundEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ private void SoundEffectUpdate()
Dispatcher.Invoke(() =>
{
if ((bool)FollowPlayCheck.IsChecked)
{
ghostCusorPositionTime = (float)nearestTime;
SeekTextFromTime();
}
});
}

Expand Down

0 comments on commit d024585

Please sign in to comment.