From 9a3e2653700bb0c0272b2d6db569ddfb964b69a5 Mon Sep 17 00:00:00 2001 From: Florian Kuepper Date: Mon, 9 Jul 2012 11:09:05 +0200 Subject: [PATCH] First keyboard-handling. Still buggy. --- Vocaluxe/Lib/Playlist/CPlaylist.cs | 16 +++++ Vocaluxe/Menu/CInteraction.cs | 3 +- Vocaluxe/Menu/CMenu.cs | 4 +- Vocaluxe/Menu/CPlaylist.cs | 105 ++++++++++++++++++++++++++++- Vocaluxe/Screens/CScreenSong.cs | 5 +- 5 files changed, 124 insertions(+), 9 deletions(-) diff --git a/Vocaluxe/Lib/Playlist/CPlaylist.cs b/Vocaluxe/Lib/Playlist/CPlaylist.cs index dd77d8ff..47e59ca6 100644 --- a/Vocaluxe/Lib/Playlist/CPlaylist.cs +++ b/Vocaluxe/Lib/Playlist/CPlaylist.cs @@ -233,5 +233,21 @@ namespace Vocaluxe.Lib.Playlist { Songs.RemoveAt(SongNr); } + + public void SongDown(int SongNr) + { + if (SongNr != 0) + { + Songs.Reverse(SongNr - 1, 2); + } + } + + public void SongUp(int SongNr) + { + if (SongNr + 1 < Songs.Count) + { + Songs.Reverse(SongNr, 2); + } + } } } diff --git a/Vocaluxe/Menu/CInteraction.cs b/Vocaluxe/Menu/CInteraction.cs index 8f7afe8d..8937df1f 100644 --- a/Vocaluxe/Menu/CInteraction.cs +++ b/Vocaluxe/Menu/CInteraction.cs @@ -43,7 +43,8 @@ namespace Vocaluxe.Menu _Type == EType.TStatic || _Type == EType.TSongMenu || _Type == EType.TLyric || - _Type == EType.TSingNote); + _Type == EType.TSingNote || + _Type == EType.TPlaylist); } } diff --git a/Vocaluxe/Menu/CMenu.cs b/Vocaluxe/Menu/CMenu.cs index e27a7c51..386abe0a 100644 --- a/Vocaluxe/Menu/CMenu.cs +++ b/Vocaluxe/Menu/CMenu.cs @@ -1685,7 +1685,7 @@ namespace Vocaluxe.Menu _NameSelections[_Interactions[_Selection].Num].Selected = true; break; case EType.TPlaylist: - //_Playlists[_Interactions[_Selection].Num].Selected = true; + _Playlists[_Interactions[_Selection].Num].Selected = true; break; } } @@ -1716,7 +1716,7 @@ namespace Vocaluxe.Menu _NameSelections[_Interactions[_Selection].Num].Selected = false; break; case EType.TPlaylist: - //_Playlists[_Interactions[_Selection].Num].Selected = true; + _Playlists[_Interactions[_Selection].Num].Selected = false; break; } } diff --git a/Vocaluxe/Menu/CPlaylist.cs b/Vocaluxe/Menu/CPlaylist.cs index 617ad876..fcd641cb 100644 --- a/Vocaluxe/Menu/CPlaylist.cs +++ b/Vocaluxe/Menu/CPlaylist.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using System.Xml; using System.Xml.XPath; +using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Lib.Draw; @@ -68,10 +69,12 @@ namespace Vocaluxe.Menu public SColorF BackgroundSColor; public bool Visible; + public bool Selected; public int ActivePlaylistID = 0; public int Offset = 0; public int ActiveHover = -1; + public int CurrentPlaylistElement = -1; public CPlaylist() { @@ -90,6 +93,7 @@ namespace Vocaluxe.Menu PlaylistElementContents = new List(); Visible = false; + Selected = false; } public void Init() @@ -236,6 +240,16 @@ namespace Vocaluxe.Menu for (int i = 0; i < PlaylistElements.Count; i++ ) { + if (i == ActiveHover) + { + PlaylistElements[i].Background.Texture = CTheme.GetSkinTexture(_Theme.STextureBackgroundName); + PlaylistElements[i].Background.Color = BackgroundSColor; + } + else + { + PlaylistElements[i].Background.Texture = CTheme.GetSkinTexture(_Theme.TextureBackgroundName); + PlaylistElements[i].Background.Color = BackgroundColor; + } PlaylistElements[i].Background.Draw(); PlaylistElements[i].Cover.Draw(); PlaylistElements[i].Text1.Draw(); @@ -270,8 +284,93 @@ namespace Vocaluxe.Menu public bool HandleInput(KeyEvent kevent) { - switch (kevent.Key) + if (Visible) { + switch (kevent.Key) + { + case Keys.Up: + if (CurrentPlaylistElement == -1) + CurrentPlaylistElement = 0; + else if (CurrentPlaylistElement - 1 > 0) + CurrentPlaylistElement--; + else if (CurrentPlaylistElement - 1 == 0) + { + CurrentPlaylistElement--; + if (Offset > 0) + { + Offset--; + Update(); + } + } + ActiveHover = CurrentPlaylistElement; + return true; + + case Keys.Down: + if (CurrentPlaylistElement == -1) + CurrentPlaylistElement = 0; + else if (CurrentPlaylistElement + 1 < PlaylistElements.Count) + { + if (PlaylistElements[CurrentPlaylistElement + 1].Content != -1) + { + CurrentPlaylistElement++; + } + } + else if (CurrentPlaylistElement + 1 >= PlaylistElements.Count && CurrentPlaylistElement + Offset + 1 < PlaylistElementContents.Count) + { + if (PlaylistElementContents[CurrentPlaylistElement + Offset + 1].SongID != -1) + { + Offset++; + Update(); + } + } + ActiveHover = CurrentPlaylistElement; + return true; + + case Keys.Delete: + if (CurrentPlaylistElement != -1) + { + CPlaylists.Playlists[ActivePlaylistID].DeleteSong(PlaylistElements[CurrentPlaylistElement].Content); + UpdatePlaylist(); + return true; + } + return false; + + case Keys.PageUp: + if (CurrentPlaylistElement != -1) + { + CPlaylists.Playlists[ActivePlaylistID].SongDown(CurrentPlaylistElement+Offset); + if (CurrentPlaylistElement - 1 > -1) + { + CurrentPlaylistElement--; + ActiveHover = CurrentPlaylistElement; + } + else if(Offset > 0) + { + Offset--; + } + UpdatePlaylist(); + return true; + } + break; + + case Keys.PageDown: + if (CurrentPlaylistElement != -1) + { + CPlaylists.Playlists[ActivePlaylistID].SongUp(CurrentPlaylistElement+Offset); + if (CurrentPlaylistElement + 1 < PlaylistElements.Count) + { + CurrentPlaylistElement++; + ActiveHover = CurrentPlaylistElement; + } + else if (Offset + CurrentPlaylistElement < PlaylistElementContents.Count) + { + Offset++; + } + UpdatePlaylist(); + return true; + } + break; + } } return false; } @@ -306,6 +405,7 @@ namespace Vocaluxe.Menu PlaylistElements[i].Background.Texture = CTheme.GetSkinTexture(_Theme.STextureBackgroundName); PlaylistElements[i].Background.Color = BackgroundSColor; ActiveHover = i; + CurrentPlaylistElement = -1; } else { @@ -330,9 +430,8 @@ namespace Vocaluxe.Menu { if (ActiveHover != -1) { - PlaylistElements[ActiveHover].Background.Texture = CTheme.GetSkinTexture(_Theme.TextureBackgroundName); - PlaylistElements[ActiveHover].Background.Color = BackgroundColor; ActiveHover = -1; + CurrentPlaylistElement = -1; } } return false; diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 55dd2abf..39a8266f 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -96,12 +96,11 @@ namespace Vocaluxe.Screens public override bool HandleInput(KeyEvent KeyEvent) { base.HandleInput(KeyEvent); - + if (KeyEvent.Handled) + return true; if (Playlists[htPlaylists(Playlist)].HandleInput(KeyEvent)) - { return true; - } if (!_SongOptionsActive) {