protected WordAnimation(CaptionWord w, CaptionTextBlock t) { //Construct lists TextEffects = new List <TextEffect>(); Animations = new List <AnimationTimeline>(); AnimationTargets = new List <AnimationTargetString>(); }
public static WordAnimation CreateWordAnimation(CaptionWord w, CaptionTextBlock t) { WordAnimation animation; animation = null; //TODO: remove this when all classes created switch (w.Emotion) { case Emotion.Happy: animation = new HappyWordAnimation(w, t); break; case Emotion.Sad: break; case Emotion.Fear: break; case Emotion.Anger: break; default: //unkown or no emotion //TODO: explicitly define this behaviour throw new Exception("No emotion specified"); } return(animation); }
/// <summary> /// Loads a single CaptionWord into the controls assosiated with this class. /// </summary> /// <param name="cw">The CaptionWord to load.</param> public void LoadWord(CaptionWord cw) { //Set CaptionWord SelectedCaptionWord = cw; //Set Emotion SetGB_EmotionType(cw.Emotion); //Set Intensity only if there is an emotion set for this word. if (cw.Emotion == Emotion.None || cw.Emotion == Emotion.Unknown) { ClearGB_Intensity(); GB_Intensity.Enabled = false; } else { SetGB_Intensity(cw.Intensity); } }
/// <summary> /// Sets the background colour of the text specified by the arguments. Preserves the previous /// selection, restoring it after highlighting is done. /// </summary> /// <param name="word">The CaptionWord to highlight.</param> /// <param name="style">The CaptionStyle to use.</param> public void SetTextBackgroundColour(CaptionWord word, CaptionStyle style) { this.SetTextBackgroundColour(word.BeginIndex, word.Length, style.TextColour, style.BackColour); }
/// <summary> /// Constructs a CaptionWordSelectedEventArgs with a specified CaptionWord. /// </summary> /// <param name="selectedWord">The selected CaptionWord.</param> public CaptionWordSelectedEventArgs(CaptionWord selectedWord) { this.SelectedWord = selectedWord; }
/// <summary> /// Reads in an engine.xml file and turns it into a CaptionList, SpeakerSet and engine /// Settings. /// </summary> /// <param name="path">The Path to the engine.xml file.</param> /// <returns>A 3-Tuple containing a CaptionList, a SpeakerSet, and a Settings /// object in that specific order.</returns> public static Tuple <List <Caption>, Dictionary <string, Speaker>, SettingsXml> ParseEngineXml(string path) { var captionList = new List <Caption>(); var speakerSet = new Dictionary <string, Speaker>(); var settings = new SettingsXml(); XmlReaderSettings readerSettings = new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true }; using (XmlReader r = XmlReader.Create(path, readerSettings)) { while (r.Read()) { //Look for start elements only. if (!r.IsStartElement()) { continue; } // Get element name and switch on it. switch (r.Name) { case XmlElements.Enact: break; case XmlElements.Settings: r.Read(); r.AssertNode(XmlElements.Meta); settings.Base = r.GetNonNullAttribute(XmlAttributes.Base); settings.Spacing = r.GetNonNullAttribute(XmlAttributes.WordSpacing); settings.SeparateEmotionWords = r.GetNonNullAttribute(XmlAttributes.SeparateEmotionWords); r.Read(); r.AssertNode(XmlElements.Playback); settings.Playback.AutoPlay = r.GetBoolAttribute(XmlAttributes.AutoPlay); settings.Playback.AutoRewind = r.GetBoolAttribute(XmlAttributes.AutoRewind); settings.Playback.Seek = r.GetNonNullAttribute(XmlAttributes.Seek); settings.Playback.AutoSize = r.GetBoolAttribute(XmlAttributes.AutoSize); settings.Playback.Scale = r.GetIntAttribute(XmlAttributes.Scale); settings.Playback.Volume = r.GetIntAttribute(XmlAttributes.Volume); settings.Playback.ShowCaptions = r.GetBoolAttribute(XmlAttributes.ShowCaptions); r.Read(); r.AssertNode(XmlElements.Skin); settings.Skin.Source = r.GetNonNullAttribute(XmlAttributes.Source); settings.Skin.AutoHide = r.GetBoolAttribute(XmlAttributes.AutoHide); settings.Skin.FadeTime = r.GetIntAttribute(XmlAttributes.FadeTime); settings.Skin.BackGroundAlpha = r.GetIntAttribute(XmlAttributes.BackgroundAlpha); settings.Skin.BackgroundColour = r.GetNonNullAttribute(XmlAttributes.BackgroundColour); r.Read(); r.AssertNode(XmlElements.Video); settings.VideoSource = r.GetNonNullAttribute(XmlAttributes.Source); r.Read(); r.AssertNode(XmlElements.Emotions); r.Read(); r.AssertNode(XmlElements.Happy); settings.Happy.Fps = r.GetNonNullAttribute(XmlAttributes.FPS); settings.Happy.Duration = r.GetNonNullAttribute(XmlAttributes.Duration); settings.Happy.AlphaBegin = r.GetNonNullAttribute(XmlAttributes.AlphaBegin); settings.Happy.AlphaFinish = r.GetNonNullAttribute(XmlAttributes.AlphaFinish); settings.Happy.ScaleBegin = r.GetNonNullAttribute(XmlAttributes.ScaleBegin); settings.Happy.ScaleFinish = r.GetNonNullAttribute(XmlAttributes.ScaleFinish); settings.Happy.YFinish = r.GetNonNullAttribute(XmlAttributes.YFinish); r.Read(); r.AssertNode(XmlElements.Sad); settings.Sad.Fps = r.GetNonNullAttribute(XmlAttributes.FPS); settings.Sad.Duration = r.GetNonNullAttribute(XmlAttributes.Duration); settings.Sad.AlphaBegin = r.GetNonNullAttribute(XmlAttributes.AlphaBegin); settings.Sad.AlphaFinish = r.GetNonNullAttribute(XmlAttributes.AlphaFinish); settings.Sad.ScaleBegin = r.GetNonNullAttribute(XmlAttributes.ScaleBegin); settings.Sad.ScaleFinish = r.GetNonNullAttribute(XmlAttributes.ScaleFinish); settings.Sad.YFinish = r.GetNonNullAttribute(XmlAttributes.YFinish); r.Read(); r.AssertNode(XmlElements.Fear); settings.Fear.Fps = r.GetNonNullAttribute(XmlAttributes.FPS); settings.Fear.Duration = r.GetNonNullAttribute(XmlAttributes.Duration); settings.Fear.ScaleBegin = r.GetNonNullAttribute(XmlAttributes.ScaleBegin); settings.Fear.ScaleFinish = r.GetNonNullAttribute(XmlAttributes.ScaleFinish); settings.Fear.VibrateX = r.GetNonNullAttribute(XmlAttributes.VibrateX); settings.Fear.VibrateY = r.GetNonNullAttribute(XmlAttributes.VibrateY); r.Read(); r.AssertNode(XmlElements.Anger); settings.Anger.Fps = r.GetNonNullAttribute(XmlAttributes.FPS); settings.Anger.Duration = r.GetNonNullAttribute(XmlAttributes.Duration); settings.Anger.ScaleBegin = r.GetNonNullAttribute(XmlAttributes.ScaleBegin); settings.Anger.ScaleFinish = r.GetNonNullAttribute(XmlAttributes.ScaleFinish); settings.Anger.VibrateX = r.GetNonNullAttribute(XmlAttributes.VibrateX); settings.Anger.VibrateY = r.GetNonNullAttribute(XmlAttributes.VibrateY); break; case XmlElements.Speakers: break; //Do Nothing case XmlElements.Speaker: r.AssertNode(XmlElements.Speaker); string name = r.GetNonNullAttribute(XmlAttributes.Name); Speaker s = new Speaker(name); r.Read(); r.AssertNode(XmlElements.Background); //Create background colour based on xml paramaters bool visible = r.GetBoolAttribute(XmlAttributes.Visible); double alphaD = r.GetDoubleAttribute(XmlAttributes.Alpha); int colourCode = r.GetHexAttribute(XmlAttributes.Colour); int alpha = (int)((visible) ? alphaD * 0xFF : 0x00); // Bitshift alpha to the most significant byte of the integer s.Font.BackgroundColour = Color.FromArgb(alpha << 24 | colourCode); r.Read(); r.AssertNode(XmlElements.Font); s.Font.Family = r.GetNonNullAttribute(XmlAttributes.Name); s.Font.Size = r.GetIntAttribute(XmlAttributes.Size); s.Font.ForegroundColour = Color.FromArgb(alpha << 24 | r.GetHexAttribute(XmlAttributes.Colour)); s.Font.Bold = r.GetIntAttribute(XmlAttributes.Bold); r.ReadStartElement(XmlElements.Font); //Add to speakerSet speakerSet[s.Name] = s; break; case XmlElements.Captions: break; //Do Nothing case XmlElements.Caption: r.AssertNode(XmlElements.Caption); Caption c = new Caption { Begin = r.GetNonNullAttribute(XmlAttributes.Begin), End = r.GetNonNullAttribute(XmlAttributes.End), Speaker = speakerSet[r.GetNonNullAttribute(XmlAttributes.Speaker)], Location = (ScreenLocation)r.GetIntAttribute(XmlAttributes.Location), Alignment = (Alignment)r.GetIntAttribute(XmlAttributes.Align) }; List <LibEnACT.CaptionWord> wordList = new List <LibEnACT.CaptionWord>(); while (r.Read()) { //If the Node is an end element, then the reader has parsed //through all of this caption's words. if (r.NodeType == XmlNodeType.EndElement && r.Name.Equals(XmlElements.Caption)) { break; } if (r.NodeType == XmlNodeType.Element && r.Name.Equals(XmlElements.Word)) { r.AssertNode(XmlElements.Word); //Doublecheck, it's the only way to be sure. Emotion e = (Emotion)r.GetIntAttribute(XmlAttributes.Emotion); Intensity i = (Intensity)r.GetIntAttribute(XmlAttributes.Intensity); //Get word from node and add it to the list CaptionWord word = new CaptionWord(e, i, r.ReadString(), 0); wordList.Add(word); } } c.SetWordList(wordList); captionList.Add(c); break; default: throw new ArgumentException("Value '" + r.Name + "' is not a valid node", r.Name); } }//Enact } return(Tuple.Create(captionList, speakerSet, settings)); }
/// <summary> /// Gets the Color of a CaptionWord given the specified CaptionWord. /// </summary> /// <param name="cw">The CaptionWord to get the style of.</param> /// <returns></returns> public static CaptionStyle GetColourOf(CaptionWord cw) { return(GetStyleOf(cw.Emotion, cw.Intensity)); }
/// <summary> /// Creates a new instance of a HappyWordAnimation. Initializes the animation based on the /// specified paramaters. /// </summary> /// <param name="w">The CaptionWord to base the animation off of.</param> /// begins.</param> /// <param name="t">The Textblock that this animation will be applied to.</param> public HappyWordAnimation(CaptionWord w, CaptionTextBlock t) : base(w, t) { //Settings dependent on intensity double dur = 0; double scalefinish = 0; double yFinish = 0; switch (w.Intensity) { case Intensity.Low: dur = 0.75; scalefinish = 1.1; yFinish = 20; break; case Intensity.Medium: dur = 0.65; scalefinish = 1.2; yFinish = 40; break; case Intensity.High: dur = 0.60; scalefinish = 1.3; yFinish = 40; break; case Intensity.None: default: //TODO handle exception break; } //Animation duration Duration duration = TimeSpan.FromSeconds(dur); StringBuilder b = new StringBuilder(t.Caption.Text); //Formatted text up until the index of the caption var captionFT = new FormattedText ( b.ToString(0, w.BeginIndex), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(t.FontFamily, t.FontStyle, t.FontWeight, t.FontStretch), t.FontSize, Brushes.Black //Colour does not matter here ); //Formatted text of the emotive caption word var wordFT = new FormattedText ( w.Text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(t.FontFamily, t.FontStyle, t.FontWeight, t.FontStretch), t.FontSize, Brushes.Black //Colour does not matter here ); TextEffect e1 = new TextEffect { PositionStart = w.BeginIndex, PositionCount = w.Length, Transform = new ScaleTransform { //TODO: Fix centering CenterX = captionFT.Width + wordFT.Width / 2, CenterY = captionFT.Height, }, }; this.TextEffects.Add(e1); DoubleAnimationUsingKeyFrames a1 = new DoubleAnimationUsingKeyFrames { BeginTime = TimeSpan.FromSeconds(t.Caption.Begin), Duration = duration, }; a1.KeyFrames.Add(new LinearDoubleKeyFrame(0.5, KeyTime.FromPercent(0))); a1.KeyFrames.Add(new LinearDoubleKeyFrame(scalefinish, KeyTime.FromPercent(0.5))); a1.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.FromPercent(1))); this.Animations.Add(a1); this.AnimationTargets.Add(new AnimationTargetString("Transform.ScaleX", 0)); //Make second animation for y scale DoubleAnimationUsingKeyFrames a2 = a1.Clone(); this.Animations.Add(a2); this.AnimationTargets.Add(new AnimationTargetString("Transform.ScaleY", 0)); TextEffect e2 = new TextEffect //Yfinish effect { PositionStart = w.BeginIndex, PositionCount = w.Length, Transform = new TranslateTransform(), }; this.TextEffects.Add(e2); DoubleAnimationUsingKeyFrames a3 = new DoubleAnimationUsingKeyFrames { BeginTime = TimeSpan.FromSeconds(t.Caption.Begin), Duration = duration, }; a3.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(0))); a3.KeyFrames.Add(new LinearDoubleKeyFrame(-yFinish, KeyTime.FromPercent(0.5))); a3.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(1))); this.Animations.Add(a3); this.AnimationTargets.Add(new AnimationTargetString("Transform.Y", 1)); //alpha effect TextEffect e3 = new TextEffect() { PositionStart = w.BeginIndex, PositionCount = w.Length, }; e3.Foreground = t.Foreground; this.TextEffects.Add(e3); ColorAnimationUsingKeyFrames a4 = new ColorAnimationUsingKeyFrames { BeginTime = TimeSpan.FromSeconds(t.Caption.Begin), Duration = duration, }; System.Windows.Media.Color fgColor = t.Caption.Speaker.Font.ForegroundColour.ToMediaColor(); a4.KeyFrames.Add(new LinearColorKeyFrame(fgColor, KeyTime.FromPercent(0))); a4.KeyFrames.Add(new LinearColorKeyFrame(Color.FromArgb(100, fgColor.R, fgColor.G, fgColor.B), KeyTime.FromPercent(0.5))); a4.KeyFrames.Add(new LinearColorKeyFrame(fgColor, KeyTime.FromPercent(1))); this.Animations.Add(a4); this.AnimationTargets.Add(new AnimationTargetString("Foreground." + SolidColorBrush.ColorProperty.ToString(), 2)); }