From: <gib...@us...> - 2007-08-21 18:41:41
|
Revision: 850 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=850&view=rev Author: gibman_dk Date: 2007-08-21 11:41:02 -0700 (Tue, 21 Aug 2007) Log Message: ----------- skinchanger plugin added. making it possible to change skins on the fly. it reacts on ; ACTION_SKIN_NEXT=9989, ACTION_SKIN_PREVIOUS=9990 Added Paths: ----------- trunk/plugins/SkinChanger/ trunk/plugins/SkinChanger/SkinChanger/ trunk/plugins/SkinChanger/SkinChanger/SkinChanger.cs trunk/plugins/SkinChanger/SkinChanger/SkinChanger.csproj trunk/plugins/SkinChanger/SkinChanger/bin/ trunk/plugins/SkinChanger/SkinChanger/bin/Debug/ trunk/plugins/SkinChanger/SkinChanger/bin/Release/ trunk/plugins/SkinChanger/SkinChanger/obj/ trunk/plugins/SkinChanger/SkinChanger.sln trunk/plugins/SkinChanger/SkinChanger.suo Added: trunk/plugins/SkinChanger/SkinChanger/SkinChanger.cs =================================================================== --- trunk/plugins/SkinChanger/SkinChanger/SkinChanger.cs (rev 0) +++ trunk/plugins/SkinChanger/SkinChanger/SkinChanger.cs 2007-08-21 18:41:02 UTC (rev 850) @@ -0,0 +1,238 @@ +using System; +using System.Collections; +using System.IO; +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; +using System.Windows.Forms; + +namespace MediaPortal.GUI.SkinChanger +{ + public class SkinChanger : ISetupForm, IPluginReceiver + { + + private string _originalSkin; + private ArrayList _skins = new ArrayList(); + private int _activeSkinIndex = -1; + + + public SkinChanger() + { + } + + #region ISetupForm Members + + public bool CanEnable() + { + return true; + } + + public string Description() + { + return "Making it possible to change skin by input device."; + } + + public bool DefaultEnabled() + { + return false; + } + + public int GetWindowId() + { + return 0; + } + + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = null; + strButtonImage = null; + strButtonImageFocus = null; + strPictureImage = null; + return false; + } + + public string Author() + { + return "gibman"; + } + + public string PluginName() + { + return "SkinChanger"; + } + + public bool HasSetup() + { + return false; + } + + public void ShowPlugin() + { + } + + #endregion + + #region IPluginReceiver Members + + public bool WndProc(ref System.Windows.Forms.Message msg) + { + return false; + } + + #endregion + + #region IPlugin Members + + public void Start() + { + //System.Diagnostics.Debugger.Launch(); + SetSkins(); + GUIWindowManager.OnNewAction += new OnActionHandler(OnNewAction); + } + + public void Stop() + { + GUIWindowManager.OnNewAction -= new OnActionHandler(OnNewAction); + } + + #endregion + + #region OnGlobalMessage routines + private void OnGlobalMessage(GUIMessage message) + { + } + + + + #endregion + + #region MediaPortal events + + void OnNewAction(Action action) + { + if (action.wID == Action.ActionType.ACTION_SKIN_NEXT) + { + SwitchToNextSkin(); + } + + if (action.wID == Action.ActionType.ACTION_SKIN_PREVIOUS) + { + SwitchToPrevSkin(); + } + } + + #endregion + + #region Private Methods + + void SaveSettings() + { + using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + xmlwriter.SetValue("skin", "name", GUIGraphicsContext.Skin); + } + } + + private void SetSkins() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + _originalSkin = xmlreader.GetValueAsString("skin", "name", "BlueTwo"); + } + + DirectoryInfo skinFolder = new DirectoryInfo(Config.GetFolder(Config.Dir.Skin)); + if (skinFolder.Exists) + { + DirectoryInfo[] skinDirList = skinFolder.GetDirectories(); + foreach (DirectoryInfo skinDir in skinDirList) + { + // + // Check if we have a home.xml located in the directory, if so we consider it as a + // valid skin directory + // + FileInfo refFile = new FileInfo(Config.GetFile(Config.Dir.Skin, skinDir.Name, "references.xml")); + if (refFile.Exists) + { + _skins.Add(skinDir.Name); + if (skinDir.FullName == GUIGraphicsContext.Skin) + { + _activeSkinIndex = _skins.Count-1; + } + } + } + } + } + + private void SwitchToNextSkin() + { + + if (_activeSkinIndex == -1 || _skins.Count == 0) + { + return; + } + string newSkin = _originalSkin; + + if (_activeSkinIndex + 1 == _skins.Count) + { + newSkin = (string)_skins[0]; + _activeSkinIndex = 0; + } + else + { + newSkin = (string)_skins[_activeSkinIndex + 1]; + _activeSkinIndex++; + } + + SwitchToSkin(newSkin); + + } + + private void SwitchToPrevSkin() + { + + if (_activeSkinIndex == -1 || _skins.Count == 0) + { + return; + } + string newSkin = _originalSkin; + + if (_activeSkinIndex - 1 == -1) + { + newSkin = (string)_skins[_skins.Count - 1]; + _activeSkinIndex = _skins.Count - 1; + } + else + { + newSkin = (string)_skins[_activeSkinIndex - 1]; + _activeSkinIndex--; + } + SwitchToSkin(newSkin); + + } + + private void SwitchToSkin(string newSkin) + { + + + // Set the skin to the selected skin and reload GUI + GUIGraphicsContext.Skin = newSkin; + SaveSettings(); + GUITextureManager.Clear(); + GUITextureManager.Init(); + GUIFontManager.LoadFonts(GUIGraphicsContext.Skin + @"\fonts.xml"); + GUIFontManager.InitializeDeviceObjects(); + GUIControlFactory.ClearReferences(); + GUIControlFactory.LoadReferences(GUIGraphicsContext.Skin + @"\references.xml"); + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + xmlreader.SetValue("general", "skinobsoletecount", 0); + bool autosize = xmlreader.GetValueAsBool("general", "autosize", true); + if (autosize && !GUIGraphicsContext.Fullscreen) + Form.ActiveForm.Size = new System.Drawing.Size(GUIGraphicsContext.SkinSize.Width, GUIGraphicsContext.SkinSize.Height); + } + GUIWindowManager.OnResize(); + } + + #endregion + + } +} Added: trunk/plugins/SkinChanger/SkinChanger/SkinChanger.csproj =================================================================== --- trunk/plugins/SkinChanger/SkinChanger/SkinChanger.csproj (rev 0) +++ trunk/plugins/SkinChanger/SkinChanger/SkinChanger.csproj 2007-08-21 18:41:02 UTC (rev 850) @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{05B44048-280D-4BED-B64E-6F0A248503B2}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>SkinChanger</RootNamespace> + <AssemblyName>SkinChanger</AssemblyName> + <StartupObject> + </StartupObject> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ItemGroup> + <Reference Include="Core, Version=0.2.2.9991, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=2.2.1.0, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\mediaportal\Core\bin\Release\Utils.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="SkinChanger.cs" /> + </ItemGroup> +</Project> \ No newline at end of file Added: trunk/plugins/SkinChanger/SkinChanger.sln =================================================================== --- trunk/plugins/SkinChanger/SkinChanger.sln (rev 0) +++ trunk/plugins/SkinChanger/SkinChanger.sln 2007-08-21 18:41:02 UTC (rev 850) @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkinChanger", "SkinChanger\SkinChanger.csproj", "{05B44048-280D-4BED-B64E-6F0A248503B2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {05B44048-280D-4BED-B64E-6F0A248503B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05B44048-280D-4BED-B64E-6F0A248503B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05B44048-280D-4BED-B64E-6F0A248503B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05B44048-280D-4BED-B64E-6F0A248503B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal Added: trunk/plugins/SkinChanger/SkinChanger.suo =================================================================== (Binary files differ) Property changes on: trunk/plugins/SkinChanger/SkinChanger.suo ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |