diff --git a/Output/Languages/Deutsch.xml b/Output/Languages/Deutsch.xml index 95beba8f..a6b5e346 100644 --- a/Output/Languages/Deutsch.xml +++ b/Output/Languages/Deutsch.xml @@ -162,6 +162,7 @@ Snapshot Snapshot speichern Snapshot löschen + Webcam Einstellungen Spiel diff --git a/Output/Languages/English.xml b/Output/Languages/English.xml index 1e063528..50fb2055 100644 --- a/Output/Languages/English.xml +++ b/Output/Languages/English.xml @@ -162,6 +162,7 @@ Take Snapshot Save Snapshot Delete Snapshot + Webcam Menu Options Game diff --git a/Output/Themes/Ambient/Screens/ScreenProfiles.xml b/Output/Themes/Ambient/Screens/ScreenProfiles.xml index 0e5cc0d6..06cf67ca 100644 --- a/Output/Themes/Ambient/Screens/ScreenProfiles.xml +++ b/Output/Themes/Ambient/Screens/ScreenProfiles.xml @@ -633,6 +633,63 @@ 26 + + + Button + + Button + + 985 + 600 + 0,00 + 150 + 50 + + + ButtonColor + + + ButtonSColor + + + 75 + 10 + + 32 + + 142 + + + ButtonTextColor + + + ButtonTextSColor + + Center + + Center + + + + Outline + + TR_SCREENPROFILES_BUTTON_WEBCAM + + + + + + 10 + 26 + + + + + + 10 + 26 + + Button diff --git a/Vocaluxe/Base/CWebcam.cs b/Vocaluxe/Base/CWebcam.cs index 78bbd2d3..cb735d77 100644 --- a/Vocaluxe/Base/CWebcam.cs +++ b/Vocaluxe/Base/CWebcam.cs @@ -4,6 +4,7 @@ using System.Text; using Vocaluxe.Lib.Webcam; using Vocaluxe.Lib.Draw; +using System.Drawing; namespace Vocaluxe.Base { @@ -36,6 +37,11 @@ namespace Vocaluxe.Base return true; } + public static Bitmap GetBitmap() + { + return _Webcam.GetBitmap(); + } + public static void Close() { _Webcam.Close(); diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 1dd9a97f..0d520e1a 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -54,6 +54,19 @@ namespace Vocaluxe.Lib.Webcam return false; } + public Bitmap GetBitmap() + { + if ((_CurrentFrame != null) && (_Webcam != null)) + { + lock (_CurrentFrame) + { + return (Bitmap)_CurrentFrame.Clone(); + } + } + else + return null; + } + public bool Init() { _WebcamDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index ad937a6d..5b0ed223 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Vocaluxe.Lib.Draw; +using System.Drawing; namespace Vocaluxe.Lib.Webcam { @@ -38,6 +39,7 @@ namespace Vocaluxe.Lib.Webcam void Close(); bool GetFrame(ref STexture Frame); + Bitmap GetBitmap(); SWebcamConfig GetConfig(); SWebcamDevice[] GetDevices(); diff --git a/Vocaluxe/Screens/CScreenProfiles.cs b/Vocaluxe/Screens/CScreenProfiles.cs index 4709bdf1..8abe12da 100644 --- a/Vocaluxe/Screens/CScreenProfiles.cs +++ b/Vocaluxe/Screens/CScreenProfiles.cs @@ -5,6 +5,8 @@ using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Menu; +using System.Drawing; +using System.IO; namespace Vocaluxe.Screens { @@ -29,13 +31,17 @@ namespace Vocaluxe.Screens private const string ButtonSave = "ButtonSave"; private const string ButtonNew = "ButtonNew"; private const string ButtonDelete = "ButtonDelete"; - private const string ButtonTakeSnapshot = "ButtonTakeSnapshot"; + private const string ButtonWebcam = "ButtonWebcam"; private const string ButtonSaveSnapshot = "ButtonSaveSnapshot"; private const string ButtonDiscardSnapshot = "ButtonDiscardSnapshot"; + private const string ButtonTakeSnapshot = "ButtonTakeSnapshot"; private const string StaticAvatar = "StaticAvatar"; private EEditMode _EditMode; + + private Lib.Draw.STexture _WebcamTexture = new Lib.Draw.STexture(-1); + private Bitmap _Snapshot = null; public CScreenProfiles() { @@ -48,7 +54,7 @@ namespace Vocaluxe.Screens _ThemeName = "ScreenProfiles"; _ScreenVersion = ScreenVersion; - _ThemeButtons = new string[] { ButtonPlayerName, ButtonExit, ButtonSave, ButtonNew, ButtonDelete, ButtonTakeSnapshot, ButtonSaveSnapshot, ButtonDiscardSnapshot }; + _ThemeButtons = new string[] { ButtonPlayerName, ButtonExit, ButtonSave, ButtonNew, ButtonDelete, ButtonWebcam, ButtonSaveSnapshot, ButtonDiscardSnapshot, ButtonTakeSnapshot }; _ThemeSelectSlides = new string[] { SelectSlideProfiles, SelectSlideDifficulty, SelectSlideAvatars, SelectSlideGuestProfile, SelectSlideActive }; _ThemeStatics = new string[] { StaticAvatar }; @@ -59,6 +65,11 @@ namespace Vocaluxe.Screens { base.LoadTheme(); + Buttons[htButtons(ButtonSaveSnapshot)].Visible = false; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = false; + Buttons[htButtons(ButtonTakeSnapshot)].Visible = false; + if (CWebcam.GetDevices().Length > 0) + Buttons[htButtons(ButtonWebcam)].Visible = true; SelectSlides[htSelectSlides(SelectSlideDifficulty)].SetValues(0); SelectSlides[htSelectSlides(SelectSlideGuestProfile)].SetValues(0); SelectSlides[htSelectSlides(SelectSlideActive)].SetValues(0); @@ -111,6 +122,35 @@ namespace Vocaluxe.Screens } else if (Buttons[htButtons(ButtonDelete)].Selected) { DeleteProfile(); + } else if (Buttons[htButtons(ButtonWebcam)].Selected && CWebcam.GetDevices().Length > 0) + { + CWebcam.Start(); + _Snapshot = CWebcam.GetBitmap(); + Buttons[htButtons(ButtonSaveSnapshot)].Visible = true; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = true; + } + else if (Buttons[htButtons(ButtonSaveSnapshot)].Selected && CWebcam.GetDevices().Length > 0) + { + string filename = "snapshot.png"; + int i = 0; + while (File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + ".png"))) + { + i++; + if (!File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + i + ".png"))) + { + filename += i; + } + } + + CWebcam.Stop(); + Buttons[htButtons(ButtonSaveSnapshot)].Visible = false; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = false; + } + else if (Buttons[htButtons(ButtonDiscardSnapshot)].Selected && CWebcam.GetDevices().Length > 0) + { + CWebcam.Stop(); + Buttons[htButtons(ButtonSaveSnapshot)].Visible = false; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = false; } break; @@ -191,6 +231,61 @@ namespace Vocaluxe.Screens CProfiles.SetActive(SelectSlides[htSelectSlides(SelectSlideProfiles)].Selection, (EOffOn)SelectSlides[htSelectSlides(SelectSlideActive)].Selection); } + else if (Buttons[htButtons(ButtonWebcam)].Selected && CWebcam.GetDevices().Length > 0) + { + _Snapshot = null; + CWebcam.Start(); + CWebcam.GetFrame(ref _WebcamTexture); + Buttons[htButtons(ButtonSaveSnapshot)].Visible = true; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = true; + Buttons[htButtons(ButtonTakeSnapshot)].Visible = true; + Buttons[htButtons(ButtonWebcam)].Visible = false; + } + else if (Buttons[htButtons(ButtonSaveSnapshot)].Selected && CWebcam.GetDevices().Length > 0) + { + string filename = "snapshot"; + int i = 0; + while (File.Exists(Path.Combine(CSettings.sFolderProfiles, filename + i + ".png"))) + { + i++; + } + _Snapshot.Save(Path.Combine(CSettings.sFolderProfiles, filename + i + ".png"), System.Drawing.Imaging.ImageFormat.Png); + CProfiles.LoadAvatars(); + LoadAvatars(); + _Snapshot = null; + CWebcam.Stop(); + CDraw.RemoveTexture(ref _WebcamTexture); + + for (int j = 0; j < CProfiles.Avatars.Length; j++) + { + if (CProfiles.Avatars[j].FileName == (filename + i + ".png")) + { + CProfiles.SetAvatar(SelectSlides[htSelectSlides(SelectSlideProfiles)].Selection, j); + break; + } + + } + + Buttons[htButtons(ButtonSaveSnapshot)].Visible = false; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = false; + Buttons[htButtons(ButtonTakeSnapshot)].Visible = false; + Buttons[htButtons(ButtonWebcam)].Visible = true; + } + else if (Buttons[htButtons(ButtonDiscardSnapshot)].Selected && CWebcam.GetDevices().Length > 0) + { + CWebcam.Stop(); + CDraw.RemoveTexture(ref _WebcamTexture); + _Snapshot = null; + Buttons[htButtons(ButtonSaveSnapshot)].Visible = false; + Buttons[htButtons(ButtonDiscardSnapshot)].Visible = false; + Buttons[htButtons(ButtonTakeSnapshot)].Visible = false; + Buttons[htButtons(ButtonWebcam)].Visible = true; + } + else if (Buttons[htButtons(ButtonTakeSnapshot)].Selected && CWebcam.GetDevices().Length > 0) + { + Buttons[htButtons(ButtonWebcam)].Visible = false; + _Snapshot = CWebcam.GetBitmap(); + } } if (MouseEvent.RB) @@ -214,7 +309,14 @@ namespace Vocaluxe.Screens int avatarNr = CProfiles.GetAvatarNr(SelectSlides[htSelectSlides(SelectSlideProfiles)].Selection); SelectSlides[htSelectSlides(SelectSlideAvatars)].Selection = avatarNr; - Statics[htStatics(StaticAvatar)].Texture = CProfiles.Avatars[avatarNr].Texture; + if (CWebcam.GetDevices().Length > 0 && _WebcamTexture.index > 0) + { + if(_Snapshot == null) + CWebcam.GetFrame(ref _WebcamTexture); + Statics[htStatics(StaticAvatar)].Texture = _WebcamTexture; + } + else + Statics[htStatics(StaticAvatar)].Texture = CProfiles.Avatars[avatarNr].Texture; } return true;