More duplicate Code removed
This commit is contained in:
Flamefire committed 2013-03-16 21:57:24 +01:00
1 parent c3cac56e1a
commit 1eef829479
7 files changed
+101 -187

No files matched your search

+9 -26
View File
@@ -664,7 +664,6 @@ namespace Vocaluxe.Base
//Check if there are inputs.
if (Devices[dev].Inputs.Count >= 1)
{
bool micfound = false;
//Check if there is one or more channels
if (Devices[dev].Inputs[0].Channels >= 1)
{
@@ -674,21 +673,16 @@ namespace Vocaluxe.Base
MicConfig[0].InputName = Devices[dev].Inputs[0].Name;
MicConfig[0].Channel = 1;
micfound = true;
}
if (Devices[dev].Inputs[0].Channels >= 2)
{
//Set this device to player 2
MicConfig[1].DeviceName = Devices[dev].Name;
MicConfig[1].DeviceDriver = Devices[dev].Driver;
MicConfig[1].InputName = Devices[dev].Inputs[0].Name;
MicConfig[1].Channel = 2;
if (Devices[dev].Inputs[0].Channels >= 2)
{
//Set this device to player 2
MicConfig[1].DeviceName = Devices[dev].Name;
MicConfig[1].DeviceDriver = Devices[dev].Driver;
MicConfig[1].InputName = Devices[dev].Inputs[0].Name;
MicConfig[1].Channel = 2;
micfound = true;
}
if (micfound)
{
return true;
return true;
}
}
}
}
@@ -820,17 +814,6 @@ namespace Vocaluxe.Base
switch (param)
{
case "songfolder":
//Check if SongFolders from config.xml are saved
if (SongFolderOld.Count == 0)
{
SongFolderOld.Clear();
SongFolderOld.AddRange(SongFolder);
SongFolder.Clear();
}
//Add parameter-value to SongFolder
SongFolder.Add(value);
break;
case "songpath":
//Check if SongFolders from config.xml are saved
if (SongFolderOld.Count == 0)
+54 -54
View File
@@ -155,40 +155,18 @@ namespace Vocaluxe.Base
class CFont:IDisposable
{
private List<CGlyph> _Glyphs;
private Hashtable _htGlyphs;
private Dictionary<char, CGlyph> _Glyphs;
private PrivateFontCollection fonts = null;
private FontFamily family;
private float SIZEh;
public string FilePath;
public Font GetFont()
{
if (fonts == null)
{
fonts = new PrivateFontCollection();
try
{
fonts.AddFontFile(FilePath);
family = fonts.Families[0];
}
catch (Exception e)
{
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
}
}
return new Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
}
public CFont(string File)
{
FilePath = File;
_Glyphs = new List<CGlyph>();
_htGlyphs = new Hashtable();
_Glyphs = new Dictionary<char, CGlyph>();
switch (CConfig.TextureQuality)
{
@@ -213,74 +191,95 @@ namespace Vocaluxe.Base
}
}
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color)
public Font GetFont()
{
AddGlyph(chr);
if (fonts == null)
{
fonts = new PrivateFontCollection();
try
{
fonts.AddFontFile(FilePath);
family = fonts.Families[0];
}
catch (Exception e)
{
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
}
}
CFonts.Height = h;
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
float factor = h / glyph.Texture.height;
float d = glyph.SIZEh / 5f * factor;
CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, glyph.Texture.width * factor, h, z), color);
return new Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
}
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight)
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color)
{
AddGlyph(chr);
CFonts.Height = h;
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
float factor = h / glyph.Texture.height;
float d = glyph.SIZEh / 5f * factor;
SRectF rect = new SRectF(x - d, y, glyph.Texture.width * factor, h, z);
CDraw.DrawTextureReflection(glyph.Texture, rect, color, rect, rspace, rheight);
STexture texture;
SRectF rect;
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CDraw.DrawTexture(texture, rect, color);
}
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end)
{
STexture texture;
SRectF rect;
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CDraw.DrawTexture(texture, rect, color, begin, end);
}
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight)
{
STexture texture;
SRectF rect;
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
}
private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect)
{
AddGlyph(chr);
CFonts.Height = h;
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
float factor = h / glyph.Texture.height;
float width = glyph.Texture.width * factor;
CGlyph glyph = _Glyphs[chr];
texture = glyph.Texture;
float factor = h / texture.height;
float width = texture.width * factor;
float d = glyph.SIZEh / 5f * factor;
CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, width, h, z), color, begin, end);
rect = new SRectF(x - d, y, width, h, z);
}
public float GetWidth(char chr)
{
AddGlyph(chr);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
CGlyph glyph = _Glyphs[chr];
float factor = CFonts.Height / glyph.Texture.height;
return glyph.width * factor;
}
public float GetHeight(char chr)
{
return CFonts.Height;
/*WTF???
AddGlyph(chr);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
CGlyph glyph = _Glyphs[chr];
float factor = CFonts.Height / glyph.Texture.height;
return glyph.Texture.height * factor;
return glyph.Texture.height * factor;*/
}
public void AddGlyph(char chr)
{
if (_htGlyphs.ContainsKey(chr))
if (_Glyphs.ContainsKey(chr))
return;
float h = CFonts.Height;
_Glyphs.Add(new CGlyph(chr, SIZEh));
_htGlyphs.Add(chr, _Glyphs.Count - 1);
_Glyphs.Add(chr, new CGlyph(chr, SIZEh));
CFonts.Height = h;
}
public void UnloadAllGlyphs()
{
foreach (CGlyph glyph in _Glyphs)
foreach (CGlyph glyph in _Glyphs.Values)
{
glyph.UnloadTexture();
}
@@ -293,6 +292,7 @@ namespace Vocaluxe.Base
{
fonts.Dispose();
fonts = null;
UnloadAllGlyphs();
}
GC.SuppressFinalize(this);
}
+1 -2
View File
@@ -192,8 +192,7 @@ namespace Vocaluxe.Base
foreach (string folder in Folders)
{
string path = Path.Combine(Environment.CurrentDirectory, folder);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
CreateFolder(path);
}
}
+29 -52
View File
@@ -27,7 +27,7 @@ namespace Vocaluxe.Lib.Draw
private bool _Run;
private Direct3D _D3D;
private Device _Device;
private Device _Device = null;
private PresentParameters _PresentParameters;
private bool _fullscreen = false;
@@ -123,52 +123,37 @@ namespace Vocaluxe.Lib.Draw
//Apply antialiasing and check if antialiasing mode is supported
#region Antialiasing
int quality = 0;
if (CConfig.AAMode == EAntiAliasingModes.x0)
int quality = 1;
MultisampleType msType;
switch (CConfig.AAMode)
{
_PresentParameters.Multisample = MultisampleType.None;
_PresentParameters.MultisampleQuality = quality;
case EAntiAliasingModes.x2:
msType = MultisampleType.TwoSamples;
break;
case EAntiAliasingModes.x4:
msType = MultisampleType.FourSamples;
break;
case EAntiAliasingModes.x8:
msType = MultisampleType.EightSamples;
break;
case EAntiAliasingModes.x16:
case EAntiAliasingModes.x32://x32 is not supported, fallback to x16
msType = MultisampleType.SixteenSamples;
break;
default:
msType = MultisampleType.None;
break;
}
else if (CConfig.AAMode == EAntiAliasingModes.x2)
if (!_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, msType, out quality))
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.TwoSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.TwoSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x4)
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.FourSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.FourSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x8)
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.EightSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.EightSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x16 || CConfig.AAMode == EAntiAliasingModes.x32) //x32 is not supported, fallback to x16
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.SixteenSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.SixteenSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
msType = MultisampleType.None;
quality = 1;
}
_PresentParameters.Multisample = msType;
_PresentParameters.MultisampleQuality = quality - 1;
#endregion Antialiasing
//Apply the VSync configuration
@@ -195,14 +180,6 @@ namespace Vocaluxe.Lib.Draw
{
_Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters);
}
catch (Exception e)
{
MessageBox.Show("Something went wrong during device creating, please check if your DirectX redistributables " +
"and graphic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109",
CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
CLog.LogError(e.Message + " - Something went wrong during device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109");
Environment.Exit(Environment.ExitCode);
}
finally
{
if (_Device == null || _Device.Disposed)
+7 -44
View File
@@ -220,16 +220,16 @@ namespace Vocaluxe.Menu
{
if (Elements != null)
{
for (int i = 0; i < Elements.Length; i++)
foreach (string elName in Elements)
{
T Element = (T)Activator.CreateInstance(typeof(T), _PartyModeID);
if (Element.LoadTheme("//root/" + _ThemeName, _ThemeBackgrounds[i], xmlReader, SkinIndex))
if (Element.LoadTheme("//root/" + _ThemeName, elName, xmlReader, SkinIndex))
{
MAddElement(Element, Elements[i]);
MAddElement(Element, elName);
}
else
{
CBase.Log.LogError("Can't load " + typeof(T).Name.Substring(1) + " \"" + Elements[i] + "\" in screen " + _ThemeName);
CBase.Log.LogError("Can't load " + typeof(T).Name.Substring(1) + " \"" + elName + "\" in screen " + _ThemeName);
}
}
}
@@ -797,11 +797,7 @@ namespace Vocaluxe.Menu
public virtual bool HandleInputThemeEditor(KeyEvent KeyEvent)
{
_UnsetHighlighted(_Selection);
if (KeyEvent.KeyPressed)
{
}
else
if (!KeyEvent.KeyPressed)
{
switch (KeyEvent.Key)
{
@@ -1311,40 +1307,7 @@ namespace Vocaluxe.Menu
private float _GetZValue(int interaction)
{
switch (_Interactions[interaction].Type)
{
case EType.TButton:
return _Buttons[_Interactions[interaction].Num].Rect.Z;
case EType.TSelectSlide:
return _SelectSlides[_Interactions[interaction].Num].Rect.Z;
case EType.TStatic:
return _Statics[_Interactions[interaction].Num].Rect.Z;
case EType.TText:
return _Texts[_Interactions[interaction].Num].Z;
case EType.TSongMenu:
return _SongMenus[_Interactions[interaction].Num].Rect.Z;
case EType.TLyric:
return _Lyrics[_Interactions[interaction].Num].Rect.Z;
case EType.TNameSelection:
return _NameSelections[_Interactions[interaction].Num].Rect.Z;
case EType.TEqualizer:
return _Equalizers[_Interactions[interaction].Num].Rect.Z;
case EType.TPlaylist:
return _Playlists[_Interactions[interaction].Num].Rect.Z;
case EType.TParticleEffect:
return _ParticleEffects[_Interactions[interaction].Num].Rect.Z;
}
return CBase.Settings.GetZFar();
return _GetZValue(_Interactions[interaction]);
}
private void _NextInteraction()
@@ -2146,7 +2109,7 @@ namespace Vocaluxe.Menu
// Statics
CStatic stat = new CStatic(_PartyModeID);
i = 1;
while (stat.LoadTheme("//root/" + _ThemeName, "Statics[" + i.ToString(), xmlReader, SkinIndex))
while (stat.LoadTheme("//root/" + _ThemeName, "Static" + i.ToString(), xmlReader, SkinIndex))
{
AddStatic(stat);
stat = new CStatic(_PartyModeID);
+1 -6
View File
@@ -642,17 +642,12 @@ namespace Vocaluxe.Menu
return false;
}
public void Draw()
{
Draw(false);
}
public void ForceDraw()
{
Draw(true);
}
public void Draw(bool ForceDraw)
public void Draw(bool ForceDraw = false)
{
if (!ForceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme)
return;
-3
View File
@@ -317,9 +317,6 @@ namespace Vocaluxe.Menu
CPlaylistSong GetPlaylistSong(int PlaylistID, int SongIndex);
}
public interface IPlaylists
{
}
[Flags]
public enum EModifier