home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 2
Skins and Design
Skinning contest: One month to go
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="FreakyJ" data-source="post: 683317" data-attributes="member: 106003"><p><strong>AW: Skinning contest: One month to go</strong></p><p></p><p>Concerning the resourceWrapper and the contentPresnert:</p><p>I think I got the point now <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" /> You use it that you have always a menu / the same menu, similar to PHP and templates where you have a main template and include the content templates^^ This would be the main usage of the resourceWrapper I guess. I will try this if I'm more advanced in the basics of MPF.</p><p>I somebody else wants to read smoe details about the contentPresenter:</p><p><a href="http://dotnet.dzone.com/articles/what-contentpresenter" target="_blank">What is a ContentPresenter? | .NET Zone</a></p><p></p><p>and a German one: <a href="http://social.msdn.microsoft.com/Forums/de-DE/wpfde/thread/a1c3b0b2-6147-463e-b6c7-20807a732294" target="_blank">wozu genau dient der ContentPresenter????</a></p><p></p><p></p><p>Sorry, I forgotten the StaticResource/ThemeResource^^</p><p></p><p>Now to the timer problem:</p><p></p><p>Oh no, I would never change the skinEngine with my little knowledge of MPF right now^^</p><p>I'm playing with the helloWorld Plugin.. okay there is nothing as it was, but playing with MPF and doing some useless stuff gives you a feeling for MPF over the time <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /></p><p></p><p>How can I block the windows message loop?!</p><p></p><p>it depends on this namespace:</p><p>[code]using System.Windows.Threading;</p><p>...</p><p>DispatcherTimer timer = new DispatcherTimer();[/code]</p><p></p><p>I really don't know what's wrong because there is no much different to my test WPF application and there it worked fine. Maybe I have to subscribe to some MessageQueue?!</p><p>In the BaseTimerControlledModel.cs you subscribe to Messages, but you only detect the "SystemState.Running" and "SystemState.ShuttingDown"...</p><p></p><p>Here is my complete Model.cs, maybe you have a hint and thanks for your great help above <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite2" alt=";)" title="Wink ;)" loading="lazy" data-shortname=";)" /></p><p></p><p>[code]#region Copyright (C) 2007-2010 Team MediaPortal</p><p></p><p>/*</p><p> Copyright (C) 2007-2010 Team MediaPortal</p><p> https://www.team-mediaportal.com</p><p></p><p> This file is part of MediaPortal 2</p><p></p><p> MediaPortal 2 is free software: you can redistribute it and/or modify</p><p> it under the terms of the GNU General Public License as published by</p><p> the Free Software Foundation, either version 3 of the License, or</p><p> (at your option) any later version.</p><p></p><p> MediaPortal 2 is distributed in the hope that it will be useful,</p><p> but WITHOUT ANY WARRANTY; without even the implied warranty of</p><p> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</p><p> GNU General Public License for more details.</p><p></p><p> You should have received a copy of the GNU General Public License</p><p> along with MediaPortal 2. If not, see <http://www.gnu.org/licenses/>.</p><p>*/</p><p></p><p>#endregion</p><p></p><p>using MediaPortal.Core.General;</p><p>using MediaPortal.UI.Presentation.Models;</p><p></p><p>using MediaPortal.UI.SkinEngine.MpfElements;</p><p>using MediaPortal.UI.SkinEngine.SkinManagement;</p><p>using MediaPortal.UI.SkinEngine.Xaml;</p><p>using MediaPortal.UI.SkinEngine.Xaml.Interfaces;</p><p>using MediaPortal.UI.SkinEngine.Controls.Visuals;</p><p>using MediaPortal.UI.SkinEngine.MpfElements.Resources;</p><p></p><p>using MediaPortal.Core;</p><p>using MediaPortal.Core.Logging;</p><p></p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Windows;</p><p>using System.Windows.Data;</p><p>using System.Windows.Documents;</p><p>using System.Windows.Input;</p><p>using System.Windows.Media;</p><p>using System.Windows.Media.Imaging;</p><p>using System.Windows.Navigation;</p><p></p><p>using System.Windows.Threading;</p><p>//using System.Windows.Media;</p><p>using System.Windows.Media.Media3D;</p><p>using System.Windows.Media.Effects;</p><p>using System.Windows.Shapes;</p><p>using System.Collections;</p><p></p><p>namespace Models.HelloWorld</p><p>{</p><p> /// <summary></p><p> /// Example for a simple model.</p><p> /// The screenfile to this model is located at:</p><p> /// /Skins/default/screens/hello_world.xaml</p><p> /// </summary></p><p> /// <remarks></p><p> /// <para></p><p> /// Models are used for providing data from the system to the skin and for executing actions (commands)</p><p> /// which are triggered by the Skin, for example by clicking a button.</p><p> /// </para></p><p> /// <para></p><p> /// All public properties can be data-bound by the skin, for example the <see cref="HelloString"/> property.</p><p> /// Note that properties, which are updated by the model and whose new value should be propagated to the</p><p> /// skin, must be backed by an instance of <see cref="AbstractProperty"/>. That instance must be made available</p><p> /// to the skin engine by publishing it under the same name as the actual property plus "Property", see for example</p><p> /// <see cref="HelloStringProperty"/>.</p><p> /// </para></p><p> /// <para></p><p> /// You can also consider to implement the interface <see cref="IWorkflowModel"/>, which makes it</p><p> /// possible to attend the screenflow = workflow of the user session. When that interface is implemented and this</p><p> /// model is registered in a workflow state as backing workflow model, the model will get notifications when the</p><p> /// GUI navigation switches to or away from its workflow state.</p><p> /// </para></p><p> /// <para></p><p> /// To make an UI model known by the system (and thus loadable by the skin), it is necessary to register it</p><p> /// in the <c>plugin.xml</c> file.</p><p> /// </para></p><p> /// </remarks></p><p> public class Model</p><p> {</p><p> // ListItem</p><p> public List<Particle> particleList = new List<Particle>();</p><p> </p><p> /// <summary></p><p> /// This is a localized string resource. Localized string resources always look like this:</p><p> /// <example></p><p> /// [Section.Name]</p><p> /// </example></p><p> /// Localized resources must be present at least in the english language, as this is the default.</p><p> /// In the english language file of this hello world plugin, you'll find the translation of this string.</p><p> /// The language file is located at: /Language/strings_en.xml</p><p> /// </summary></p><p> protected const string HELLOWORLD_RESOURCE = "[HelloWorld.HelloWorldText]";</p><p> protected const string TranslateTransform0_X_RESOURCE = "20";</p><p> protected const string TranslateTransform0_Y_RESOURCE = "20";</p><p></p><p> /// <summary></p><p> /// Another localized string resource.</p><p> /// </summary></p><p> protected const string COMMAND_TRIGGERED_RESOURCE = "[HelloWorld.ButtonTextCommandExecuted]";</p><p></p><p> /// <summary></p><p> /// This property holds a string that we will modify in this tutorial.</p><p> /// </summary></p><p> private readonly AbstractProperty _helloStringProperty;</p><p> private readonly AbstractProperty _TranslateTransform0_XProperty;</p><p> private readonly AbstractProperty _TranslateTransform0_YProperty;</p><p></p><p> /// <summary></p><p> /// Constructor... this one is called by the WorkflowManager when this model is loaded due to a screen reference.</p><p> /// </summary></p><p> public Model()</p><p> {</p><p> // In models, properties will always be WProperty instances. When using SProperties for screen databinding,</p><p> // the system might run into memory leaks.</p><p> _helloStringProperty = new WProperty(typeof(string), HELLOWORLD_RESOURCE);</p><p> _TranslateTransform0_XProperty = new WProperty(typeof(string), TranslateTransform0_X_RESOURCE);</p><p> _TranslateTransform0_YProperty = new WProperty(typeof(string), TranslateTransform0_Y_RESOURCE);</p><p> //_ParticleHost = new WProperty(typeof(string), ParticleHost);</p><p></p><p> Window_Loaded();</p><p> }</p><p> </p><p> /// <summary></p><p> /// This sample property will be accessed by the hello_world screen. Note that the data type must be the same</p><p> /// as in the instantiation of our backing property <see cref="_helloStringProperty"/>.</p><p> /// </summary></p><p> public string HelloString</p><p> {</p><p> get { return (string) _helloStringProperty.GetValue(); }</p><p> set { _helloStringProperty.SetValue(value); }</p><p> }</p><p></p><p> public string TranslateTransform0_X</p><p> {</p><p> get { return (string)_TranslateTransform0_XProperty.GetValue(); }</p><p> set { _TranslateTransform0_XProperty.SetValue(value); }</p><p> }</p><p></p><p> public string TranslateTransform0_Y</p><p> {</p><p> get { return (string)_TranslateTransform0_YProperty.GetValue(); }</p><p> set { _TranslateTransform0_YProperty.SetValue(value); }</p><p> }</p><p></p><p> /// <summary></p><p> /// This is the dependency property for our sample string. It is needed to propagate changes to the skin.</p><p> /// </summary></p><p> /// <remarks></p><p> /// <para></p><p> /// If the screen databinds to the <see cref="HelloString"/> property in a binding mode which will propagate data</p><p> /// changes from the model to the skin, the SkinEngine will attach a change handler to this property.</p><p> /// </para></p><p> /// <para></p><p> /// In other words: Every property <c>Xyz</c>, which should be able to be attached to, must be present also as</p><p> /// <c>XyzProperty</c>.</p><p> /// Only if <c>XyzProperty</c> is present in the model, value changes can be propagated to the skin.</p><p> /// </remarks></p><p> public AbstractProperty HelloStringProperty</p><p> {</p><p> get { return _helloStringProperty; }</p><p> }</p><p></p><p> public AbstractProperty TranslateTransform0_XProperty</p><p> {</p><p> get { return _TranslateTransform0_XProperty; }</p><p> }</p><p></p><p> public AbstractProperty TranslateTransform0_YProperty</p><p> {</p><p> get { return _TranslateTransform0_YProperty; }</p><p> }</p><p></p><p> /// <summary></p><p> /// Method which will be called from our screen. We will change the value of our HelloWorld string here.</p><p> /// </summary></p><p> public void ChangeHelloWorldString()</p><p> {</p><p> HelloString = COMMAND_TRIGGERED_RESOURCE;</p><p> }</p><p></p><p> DispatcherTimer timer = new DispatcherTimer();</p><p> Random random = new Random(DateTime.Now.Millisecond);</p><p></p><p> // Some general values </p><p> double MaxSize = 30;</p><p> double NumberOfParticles = 1;</p><p> int Width = 800;</p><p> int Height = 600;</p><p> /*double VerticalVelocity = 0.4;</p><p> double HorizontalVelocity = -2.2;</p><p> double elapsed = 0.1;*/</p><p></p><p> ILogger logger = ServiceRegistration.Get<ILogger>();</p><p> </p><p> public void Window_Loaded()</p><p> {</p><p> for (int i = 0; i < NumberOfParticles; i++)</p><p> {</p><p> CreateParticle();</p><p> }</p><p></p><p> timer.Interval = TimeSpan.FromMilliseconds(33.33);</p><p> timer.Tick += new EventHandler(timer_Tick);</p><p> timer.Start();</p><p></p><p> logger.Info("HelloWorld: Window_Loaded() - timer started: " + timer.IsEnabled.ToString());</p><p> HelloString = "EXECUTED";</p><p> }</p><p> </p><p> public void timer_Tick(object sender, EventArgs e)</p><p> {</p><p> logger.Info("HelloWorld: TimerTick");</p><p> // I control "particle" from their ellipse representation </p><p> //foreach (Ellipse ellipse in ParticleHost.Children)</p><p> //{</p><p> /*var p = ellipse.Tag as Particle;</p><p> var t = ellipse.RenderTransform as TranslateTransform;</p><p></p><p> // Update location </p><p> t.X += p.Velocity.X;</p><p> t.Y += p.Velocity.Y;</p><p></p><p></p><p> // Check if the particle is too high </p><p> if (t.Y < -MaxSize)</p><p> {</p><p> t.Y = Height + MaxSize;</p><p> }</p><p></p><p> // Check if the particle has gone outside </p><p> if (t.X < -MaxSize || t.X > Width + MaxSize)</p><p> {</p><p> t.X = random.NextDouble() * Width;</p><p> t.Y = Height + MaxSize;</p><p> }</p><p></p><p> // Brush & Effect </p><p> //ellipse.Fill = p.Brush;</p><p> ellipse.Fill = (Brush)Brushes.White.Clone();</p><p> // Comment this line to deactivate the Blur Effect </p><p> ellipse.Effect = p.Blur;*/</p><p> //}</p><p></p><p> //----------------------------</p><p></p><p> foreach (Particle particle in particleList)</p><p> {</p><p> TranslateTransform0_X = (ToDouble(TranslateTransform0_X) + particle.Velocity.X).ToString();</p><p> TranslateTransform0_Y = (ToDouble(TranslateTransform0_Y) + particle.Velocity.Y).ToString();</p><p></p><p> HelloString = "Transform X to " + TranslateTransform0_X;</p><p></p><p> // Check if the particle is too high </p><p> if (ToDouble(TranslateTransform0_Y) < -MaxSize)</p><p> {</p><p> TranslateTransform0_Y = (Height + MaxSize).ToString();</p><p> }</p><p></p><p> // Check if the particle has gone outside </p><p> if (ToDouble(TranslateTransform0_X) < -MaxSize || ToDouble(TranslateTransform0_X) > Width + MaxSize)</p><p> {</p><p> TranslateTransform0_X = (random.NextDouble() * Width).ToString();</p><p> TranslateTransform0_Y = (Height + MaxSize).ToString();</p><p> }</p><p> }</p><p> }</p><p> </p><p> private void CreateParticle()</p><p> {</p><p> </p><p> </p><p> // Brush (White) </p><p> //var brush = System.Windows.Media.Brushes.White.Clone();</p><p> // Opacity (0.2 <= 1) </p><p> //brush.Opacity = 0.2 + random.NextDouble() * 0.8;</p><p> // Blur effect </p><p> //var blur = new BlurEffect();</p><p> //blur.RenderingBias = RenderingBias.Performance;</p><p> // Radius (1 <= 40) </p><p> //blur.Radius = 1 + random.NextDouble() * 39;</p><p> // Ellipse </p><p> //var ellipse = new Ellipse();</p><p> // Size (from 15% to 95% of MaxSize) </p><p> //ellipse.Width = ellipse.Height = MaxSize * 0.15 + random.NextDouble() * MaxSize * 0.8;</p><p> // Starting location of the ellipse (anywhere in the scree</p><p></p><p> // extraTags adden</p><p> var p = new Particle();</p><p></p><p> // Speed</p><p> double speed = RandomWithVariance(20, 15);</p><p> double velocityMultiplier = (random.NextDouble() + 0.25) * speed;</p><p> double vX = (1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier;</p><p> // Only going from the bottom of the screen to the top (for now)</p><p> double vY = -Math.Abs((1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier);</p><p></p><p> p.Velocity = p.Velocity = new Point(vX, vY);</p><p> //p.Blur = blur;</p><p> //ellipse.Tag = p;</p><p> </p><p></p><p> //this.ParticleHost.Children.Add(ellipse);</p><p></p><p> //TranslateTransform t;</p><p></p><p> //t = new TranslateTransform();</p><p> //ellipse.RenderTransform = t;</p><p> //ellipse.RenderTransformOrigin = new Point(0.5, 0.5);</p><p> </p><p> //t.X = RandomWithVariance(Width / 2, Width / 2);</p><p> //t.Y = Height;</p><p></p><p> //----------------------------------------</p><p></p><p> // add particle to list</p><p> particleList.Add(p);</p><p></p><p> // set position</p><p> TranslateTransform0_X = RandomWithVariance(Width / 2, Width / 2).ToString();</p><p> TranslateTransform0_Y = Height.ToString();</p><p> }</p><p></p><p></p><p> private double RandomWithVariance(double midvalue, double variance)</p><p> {</p><p> double min = Math.Max(midvalue - (variance / 2), 0);</p><p> double max = midvalue + (variance / 2);</p><p> double value = min + ((max - min) * random.NextDouble());</p><p> return value;</p><p> }</p><p></p><p> #region helper functions</p><p></p><p> /// <summary></p><p> /// Wandelt in String in Double um</p><p> /// </summary></p><p> /// <param name="In"></param></p><p> /// <returns></returns></p><p> public static double ToDouble(string In)</p><p> {</p><p> In = In.Replace(",", ".");</p><p></p><p> return double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);</p><p> }</p><p></p><p> /// <summary></p><p> /// Wandelt String in Double um mit Default falls es nicht möglich ist</p><p> /// </summary></p><p> /// <param name="In"></param></p><p> /// <param name="Default"></param></p><p> /// <returns></returns></p><p> public static double ToDouble(string In, double Default)</p><p> {</p><p> double dblOut;</p><p></p><p> In = In.Replace(",", ".");</p><p></p><p> try</p><p> {</p><p> dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);</p><p> }</p><p> catch</p><p> {</p><p> dblOut = Default;</p><p> }</p><p></p><p> return dblOut;</p><p> }</p><p></p><p> /// <summary></p><p> /// Wandelt einen String in Double um (Default = 0 oder es wird eine Exception ausgelöst)</p><p> /// </summary></p><p> /// <param name="In">String</param></p><p> /// <param name="UseExceptions">True (Exception wird ausgelöst) oder False (Default 0 wird verwendet)</param></p><p> /// <returns></returns></p><p> public static double ToDouble(string In, bool UseExceptions)</p><p> {</p><p> double dblOut;</p><p></p><p> In = In.Replace(",", ".");</p><p></p><p> try</p><p> {</p><p> dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture);</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> if (UseExceptions)</p><p> throw ex;</p><p> else</p><p> dblOut = 0;</p><p> }</p><p></p><p> return dblOut;</p><p> }</p><p></p><p> #endregion</p><p> }</p><p>}</p><p>[/code]</p></blockquote><p></p>
[QUOTE="FreakyJ, post: 683317, member: 106003"] [b]AW: Skinning contest: One month to go[/b] Concerning the resourceWrapper and the contentPresnert: I think I got the point now ;) You use it that you have always a menu / the same menu, similar to PHP and templates where you have a main template and include the content templates^^ This would be the main usage of the resourceWrapper I guess. I will try this if I'm more advanced in the basics of MPF. I somebody else wants to read smoe details about the contentPresenter: [url=http://dotnet.dzone.com/articles/what-contentpresenter]What is a ContentPresenter? | .NET Zone[/url] and a German one: [url=http://social.msdn.microsoft.com/Forums/de-DE/wpfde/thread/a1c3b0b2-6147-463e-b6c7-20807a732294]wozu genau dient der ContentPresenter????[/url] Sorry, I forgotten the StaticResource/ThemeResource^^ Now to the timer problem: Oh no, I would never change the skinEngine with my little knowledge of MPF right now^^ I'm playing with the helloWorld Plugin.. okay there is nothing as it was, but playing with MPF and doing some useless stuff gives you a feeling for MPF over the time :) How can I block the windows message loop?! it depends on this namespace: [code]using System.Windows.Threading; ... DispatcherTimer timer = new DispatcherTimer();[/code] I really don't know what's wrong because there is no much different to my test WPF application and there it worked fine. Maybe I have to subscribe to some MessageQueue?! In the BaseTimerControlledModel.cs you subscribe to Messages, but you only detect the "SystemState.Running" and "SystemState.ShuttingDown"... Here is my complete Model.cs, maybe you have a hint and thanks for your great help above ;) [code]#region Copyright (C) 2007-2010 Team MediaPortal /* Copyright (C) 2007-2010 Team MediaPortal https://www.team-mediaportal.com This file is part of MediaPortal 2 MediaPortal 2 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. MediaPortal 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MediaPortal 2. If not, see <http://www.gnu.org/licenses/>. */ #endregion using MediaPortal.Core.General; using MediaPortal.UI.Presentation.Models; using MediaPortal.UI.SkinEngine.MpfElements; using MediaPortal.UI.SkinEngine.SkinManagement; using MediaPortal.UI.SkinEngine.Xaml; using MediaPortal.UI.SkinEngine.Xaml.Interfaces; using MediaPortal.UI.SkinEngine.Controls.Visuals; using MediaPortal.UI.SkinEngine.MpfElements.Resources; using MediaPortal.Core; using MediaPortal.Core.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Threading; //using System.Windows.Media; using System.Windows.Media.Media3D; using System.Windows.Media.Effects; using System.Windows.Shapes; using System.Collections; namespace Models.HelloWorld { /// <summary> /// Example for a simple model. /// The screenfile to this model is located at: /// /Skins/default/screens/hello_world.xaml /// </summary> /// <remarks> /// <para> /// Models are used for providing data from the system to the skin and for executing actions (commands) /// which are triggered by the Skin, for example by clicking a button. /// </para> /// <para> /// All public properties can be data-bound by the skin, for example the <see cref="HelloString"/> property. /// Note that properties, which are updated by the model and whose new value should be propagated to the /// skin, must be backed by an instance of <see cref="AbstractProperty"/>. That instance must be made available /// to the skin engine by publishing it under the same name as the actual property plus "Property", see for example /// <see cref="HelloStringProperty"/>. /// </para> /// <para> /// You can also consider to implement the interface <see cref="IWorkflowModel"/>, which makes it /// possible to attend the screenflow = workflow of the user session. When that interface is implemented and this /// model is registered in a workflow state as backing workflow model, the model will get notifications when the /// GUI navigation switches to or away from its workflow state. /// </para> /// <para> /// To make an UI model known by the system (and thus loadable by the skin), it is necessary to register it /// in the <c>plugin.xml</c> file. /// </para> /// </remarks> public class Model { // ListItem public List<Particle> particleList = new List<Particle>(); /// <summary> /// This is a localized string resource. Localized string resources always look like this: /// <example> /// [Section.Name] /// </example> /// Localized resources must be present at least in the english language, as this is the default. /// In the english language file of this hello world plugin, you'll find the translation of this string. /// The language file is located at: /Language/strings_en.xml /// </summary> protected const string HELLOWORLD_RESOURCE = "[HelloWorld.HelloWorldText]"; protected const string TranslateTransform0_X_RESOURCE = "20"; protected const string TranslateTransform0_Y_RESOURCE = "20"; /// <summary> /// Another localized string resource. /// </summary> protected const string COMMAND_TRIGGERED_RESOURCE = "[HelloWorld.ButtonTextCommandExecuted]"; /// <summary> /// This property holds a string that we will modify in this tutorial. /// </summary> private readonly AbstractProperty _helloStringProperty; private readonly AbstractProperty _TranslateTransform0_XProperty; private readonly AbstractProperty _TranslateTransform0_YProperty; /// <summary> /// Constructor... this one is called by the WorkflowManager when this model is loaded due to a screen reference. /// </summary> public Model() { // In models, properties will always be WProperty instances. When using SProperties for screen databinding, // the system might run into memory leaks. _helloStringProperty = new WProperty(typeof(string), HELLOWORLD_RESOURCE); _TranslateTransform0_XProperty = new WProperty(typeof(string), TranslateTransform0_X_RESOURCE); _TranslateTransform0_YProperty = new WProperty(typeof(string), TranslateTransform0_Y_RESOURCE); //_ParticleHost = new WProperty(typeof(string), ParticleHost); Window_Loaded(); } /// <summary> /// This sample property will be accessed by the hello_world screen. Note that the data type must be the same /// as in the instantiation of our backing property <see cref="_helloStringProperty"/>. /// </summary> public string HelloString { get { return (string) _helloStringProperty.GetValue(); } set { _helloStringProperty.SetValue(value); } } public string TranslateTransform0_X { get { return (string)_TranslateTransform0_XProperty.GetValue(); } set { _TranslateTransform0_XProperty.SetValue(value); } } public string TranslateTransform0_Y { get { return (string)_TranslateTransform0_YProperty.GetValue(); } set { _TranslateTransform0_YProperty.SetValue(value); } } /// <summary> /// This is the dependency property for our sample string. It is needed to propagate changes to the skin. /// </summary> /// <remarks> /// <para> /// If the screen databinds to the <see cref="HelloString"/> property in a binding mode which will propagate data /// changes from the model to the skin, the SkinEngine will attach a change handler to this property. /// </para> /// <para> /// In other words: Every property <c>Xyz</c>, which should be able to be attached to, must be present also as /// <c>XyzProperty</c>. /// Only if <c>XyzProperty</c> is present in the model, value changes can be propagated to the skin. /// </remarks> public AbstractProperty HelloStringProperty { get { return _helloStringProperty; } } public AbstractProperty TranslateTransform0_XProperty { get { return _TranslateTransform0_XProperty; } } public AbstractProperty TranslateTransform0_YProperty { get { return _TranslateTransform0_YProperty; } } /// <summary> /// Method which will be called from our screen. We will change the value of our HelloWorld string here. /// </summary> public void ChangeHelloWorldString() { HelloString = COMMAND_TRIGGERED_RESOURCE; } DispatcherTimer timer = new DispatcherTimer(); Random random = new Random(DateTime.Now.Millisecond); // Some general values double MaxSize = 30; double NumberOfParticles = 1; int Width = 800; int Height = 600; /*double VerticalVelocity = 0.4; double HorizontalVelocity = -2.2; double elapsed = 0.1;*/ ILogger logger = ServiceRegistration.Get<ILogger>(); public void Window_Loaded() { for (int i = 0; i < NumberOfParticles; i++) { CreateParticle(); } timer.Interval = TimeSpan.FromMilliseconds(33.33); timer.Tick += new EventHandler(timer_Tick); timer.Start(); logger.Info("HelloWorld: Window_Loaded() - timer started: " + timer.IsEnabled.ToString()); HelloString = "EXECUTED"; } public void timer_Tick(object sender, EventArgs e) { logger.Info("HelloWorld: TimerTick"); // I control "particle" from their ellipse representation //foreach (Ellipse ellipse in ParticleHost.Children) //{ /*var p = ellipse.Tag as Particle; var t = ellipse.RenderTransform as TranslateTransform; // Update location t.X += p.Velocity.X; t.Y += p.Velocity.Y; // Check if the particle is too high if (t.Y < -MaxSize) { t.Y = Height + MaxSize; } // Check if the particle has gone outside if (t.X < -MaxSize || t.X > Width + MaxSize) { t.X = random.NextDouble() * Width; t.Y = Height + MaxSize; } // Brush & Effect //ellipse.Fill = p.Brush; ellipse.Fill = (Brush)Brushes.White.Clone(); // Comment this line to deactivate the Blur Effect ellipse.Effect = p.Blur;*/ //} //---------------------------- foreach (Particle particle in particleList) { TranslateTransform0_X = (ToDouble(TranslateTransform0_X) + particle.Velocity.X).ToString(); TranslateTransform0_Y = (ToDouble(TranslateTransform0_Y) + particle.Velocity.Y).ToString(); HelloString = "Transform X to " + TranslateTransform0_X; // Check if the particle is too high if (ToDouble(TranslateTransform0_Y) < -MaxSize) { TranslateTransform0_Y = (Height + MaxSize).ToString(); } // Check if the particle has gone outside if (ToDouble(TranslateTransform0_X) < -MaxSize || ToDouble(TranslateTransform0_X) > Width + MaxSize) { TranslateTransform0_X = (random.NextDouble() * Width).ToString(); TranslateTransform0_Y = (Height + MaxSize).ToString(); } } } private void CreateParticle() { // Brush (White) //var brush = System.Windows.Media.Brushes.White.Clone(); // Opacity (0.2 <= 1) //brush.Opacity = 0.2 + random.NextDouble() * 0.8; // Blur effect //var blur = new BlurEffect(); //blur.RenderingBias = RenderingBias.Performance; // Radius (1 <= 40) //blur.Radius = 1 + random.NextDouble() * 39; // Ellipse //var ellipse = new Ellipse(); // Size (from 15% to 95% of MaxSize) //ellipse.Width = ellipse.Height = MaxSize * 0.15 + random.NextDouble() * MaxSize * 0.8; // Starting location of the ellipse (anywhere in the scree // extraTags adden var p = new Particle(); // Speed double speed = RandomWithVariance(20, 15); double velocityMultiplier = (random.NextDouble() + 0.25) * speed; double vX = (1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier; // Only going from the bottom of the screen to the top (for now) double vY = -Math.Abs((1.0 - (random.NextDouble() * 2.0)) * velocityMultiplier); p.Velocity = p.Velocity = new Point(vX, vY); //p.Blur = blur; //ellipse.Tag = p; //this.ParticleHost.Children.Add(ellipse); //TranslateTransform t; //t = new TranslateTransform(); //ellipse.RenderTransform = t; //ellipse.RenderTransformOrigin = new Point(0.5, 0.5); //t.X = RandomWithVariance(Width / 2, Width / 2); //t.Y = Height; //---------------------------------------- // add particle to list particleList.Add(p); // set position TranslateTransform0_X = RandomWithVariance(Width / 2, Width / 2).ToString(); TranslateTransform0_Y = Height.ToString(); } private double RandomWithVariance(double midvalue, double variance) { double min = Math.Max(midvalue - (variance / 2), 0); double max = midvalue + (variance / 2); double value = min + ((max - min) * random.NextDouble()); return value; } #region helper functions /// <summary> /// Wandelt in String in Double um /// </summary> /// <param name="In"></param> /// <returns></returns> public static double ToDouble(string In) { In = In.Replace(",", "."); return double.Parse(In, System.Globalization.CultureInfo.InvariantCulture); } /// <summary> /// Wandelt String in Double um mit Default falls es nicht möglich ist /// </summary> /// <param name="In"></param> /// <param name="Default"></param> /// <returns></returns> public static double ToDouble(string In, double Default) { double dblOut; In = In.Replace(",", "."); try { dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture); } catch { dblOut = Default; } return dblOut; } /// <summary> /// Wandelt einen String in Double um (Default = 0 oder es wird eine Exception ausgelöst) /// </summary> /// <param name="In">String</param> /// <param name="UseExceptions">True (Exception wird ausgelöst) oder False (Default 0 wird verwendet)</param> /// <returns></returns> public static double ToDouble(string In, bool UseExceptions) { double dblOut; In = In.Replace(",", "."); try { dblOut = double.Parse(In, System.Globalization.CultureInfo.InvariantCulture); } catch (Exception ex) { if (UseExceptions) throw ex; else dblOut = 0; } return dblOut; } #endregion } } [/code] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 2
Skins and Design
Skinning contest: One month to go
Contact us
RSS
Top
Bottom