Avatars can now be recorded from webcam in profile screen

This commit is contained in:
Stephan Sundermann committed 2012-12-07 23:33:46 +01:00
1 parent 6073d625fb
commit 183cdbb996
7 files changed
+185 -3

No files matched your search

+1
View File
@@ -162,6 +162,7 @@
<TR_SCREENPROFILES_BUTTON_TAKESNAPSHOT>Snapshot</TR_SCREENPROFILES_BUTTON_TAKESNAPSHOT>
<TR_SCREENPROFILES_BUTTON_SAVESNAPSHOT>Snapshot speichern</TR_SCREENPROFILES_BUTTON_SAVESNAPSHOT>
<TR_SCREENPROFILES_BUTTON_DISCARDSNAPSHOT>Snapshot löschen</TR_SCREENPROFILES_BUTTON_DISCARDSNAPSHOT>
<TR_SCREENPROFILES_BUTTON_WEBCAM>Webcam</TR_SCREENPROFILES_BUTTON_WEBCAM>
<!--ScreenOptions-->
<TR_SCREENO_OPTIONS>Einstellungen</TR_SCREENO_OPTIONS>
<TR_SCREENO_BUTTON_GAME>Spiel</TR_SCREENO_BUTTON_GAME>
+1
View File
@@ -162,6 +162,7 @@
<TR_SCREENPROFILES_BUTTON_TAKESNAPSHOT>Take Snapshot</TR_SCREENPROFILES_BUTTON_TAKESNAPSHOT>
<TR_SCREENPROFILES_BUTTON_SAVESNAPSHOT>Save Snapshot</TR_SCREENPROFILES_BUTTON_SAVESNAPSHOT>
<TR_SCREENPROFILES_BUTTON_DISCARDSNAPSHOT>Delete Snapshot</TR_SCREENPROFILES_BUTTON_DISCARDSNAPSHOT>
<TR_SCREENPROFILES_BUTTON_WEBCAM>Webcam</TR_SCREENPROFILES_BUTTON_WEBCAM>
<!--ScreenOptions-->
<TR_SCREENO_OPTIONS>Menu Options</TR_SCREENO_OPTIONS>
<TR_SCREENO_BUTTON_GAME>Game</TR_SCREENO_BUTTON_GAME>
@@ -633,6 +633,63 @@
<Height>26</Height>
</SReflection>
</ButtonTakeSnapshot>
<ButtonWebcam>
<!--<Skin>: Texture name-->
<Skin>Button</Skin>
<!--<SkinSelected>: Texture name for selected button-->
<SkinSelected>Button</SkinSelected>
<!--<X>, <Y>, <Z>, <W>, <H>: Button position, width and height-->
<X>985</X>
<Y>600</Y>
<Z>0,00</Z>
<W>150</W>
<H>50</H>
<!--<Color>: Button color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>ButtonColor</Color>
<!--<SColor>: Selected button color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>ButtonSColor</SColor>
<Text>
<!--<X>, <Y>: Text position-->
<X>75</X>
<Y>10</Y>
<!--<H>: Text height-->
<H>32</H>
<!--<MaxW>: Maximum text width (if exists)-->
<MaxW>142</MaxW>
<!--<Color>: Text color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>ButtonTextColor</Color>
<!--<SColor>: Selected Text color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>ButtonTextSColor</SColor>
<!--<Align>: Text align horizontal: Left, Center, Right-->
<Align>Center</Align>
<!--<HAlign>: Text align vertical (on downsizing): Top, Center, Bottom-->
<HAlign>Center</HAlign>
<!--<Style>: Text style: Normal, Italic, Bold, BoldItalic-->
<Style>Bold</Style>
<!--<Font>: Text font name-->
<Font>Outline</Font>
<!--<Text>: Nothing or translation tag-->
<Text>TR_SCREENPROFILES_BUTTON_WEBCAM</Text>
</Text>
<!--<Reflection> If exists:-->
<!-- <Space>: Reflection Space-->
<!-- <Height>: Reflection Height-->
<Reflection>
<Space>10</Space>
<Height>26</Height>
</Reflection>
<!--<SReflection> If exists:-->
<!-- <Space>: Reflection Space of selected button-->
<!-- <Height>: Reflection Height of selected button-->
<SReflection>
<Space>10</Space>
<Height>26</Height>
</SReflection>
</ButtonWebcam>
<ButtonSaveSnapshot>
<!--<Skin>: Texture name-->
<Skin>Button</Skin>
+6
View File
@@ -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();
+13
View File
@@ -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);
+2
View File
@@ -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();
+105 -3
View File
@@ -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<EGameDifficulty>(0);
SelectSlides[htSelectSlides(SelectSlideGuestProfile)].SetValues<EOffOn>(0);
SelectSlides[htSelectSlides(SelectSlideActive)].SetValues<EOffOn>(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;