public void Play(int L) { if (ImageList == null || ImageList.Count == 0) { return; } ObjectAnimationUsingKeyFrames da = new ObjectAnimationUsingKeyFrames(); var cellSpan = seconds / ImageList.Count; double flagKeyTime = 0; imageBrushList = new List <BitmapImage>(); foreach (var source in ImageList) { var bmp = FunctionLib.RYTFile.ReadFileByType(source, "image") as BitmapImage; if (bmp != null) { imageBrushList.Add(bmp); DiscreteObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame(); keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(flagKeyTime)); flagKeyTime += cellSpan; keyFrame.Value = bmp; da.KeyFrames.Add(keyFrame); } } da.KeyFrames.Add(new DiscreteObjectKeyFrame { Value = imageBrushList.LastOrDefault(), KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(flagKeyTime)) }); if (imageBrushList.Count == 0) { return; } Storyboard.SetTarget(da, img); Storyboard.SetTargetProperty(da, new PropertyPath(Image.SourceProperty)); SB.Children.Add(da); SB.Completed += (s, e) => { if (AnimationCompleted != null) { AnimationCompleted(this, null); } var page = LuaCommon.FindCurrentPage(img); if (page != LuaManager.GetLuaManager(L).DetailV_) { RYTong.LogLib.RYTLog.Log("animation stoped,auto dispose it .."); Dispose(); return; } Dispose(); if (StopFunctionId != 0) { LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithParam(StopFunctionId, this); } }; if (StartFunctionId != 0) { LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithParam(StartFunctionId, this); } SB.Begin(); }
static int addEventListener(int L) { if (!LuaCommon.CheckAndShowArgsError(L, LConst.Function)) { return(0); } Object control = (Object)Lua.Lua_touserdata(L, 1); int callbackF = Lua.LuaL_ref(L, Lua._LUA_REGISTRYINDEX); string eventName = Lua.Lua_tostring(L, 2); if (control != null && callbackF != 0) { var pi = control.GetType().GetProperty("View_"); var fe = pi.GetValue(control, null); bool isPinch = false; if (fe is FrameworkElement) { if (eventName.Equals("touchmove")) { EventHandler <ManipulationDeltaEventArgs> touchDeltaEventHandler = null; TouchEventRegisterInfo touchInfo = null; Dictionary <string, object> touchDict = null; if (!touchEventList.Any(c => (c.FE == fe as FrameworkElement))) { touchInfo = new TouchEventRegisterInfo(); touchEventList.Add(touchInfo); touchInfo.FE = fe as FrameworkElement; touchDict = touchInfo.TouchDict; } else { touchInfo = touchEventList.FirstOrDefault(c => (c.FE == fe as FrameworkElement)); touchDict = touchInfo.TouchDict; } (fe as FrameworkElement).ManipulationDelta += touchDeltaEventHandler = (sender, e) => { bool oldIsPinch = isPinch; isPinch = e.PinchManipulation != null; if (oldIsPinch == isPinch) { double currentOffsetY = 0; double page_OffsetY = 0; object obj = e.OriginalSource; Point OriginPoint = e.ManipulationOrigin; Point currentPoint = new Point(0, 0); Page currentPage = LuaCommon.FindCurrentPage(sender as FrameworkElement); FrameworkElement container = e.ManipulationContainer as FrameworkElement; if (container != null && container is ScrollViewer) { ScrollViewer sv = container as ScrollViewer; currentOffsetY = sv.VerticalOffset; } if (currentPage != null) { GeneralTransform generalTransform1 = currentPage.TransformToVisual(sender as UIElement); currentPoint = generalTransform1.Transform(new Point(0, 0)); ScrollViewer sv = LuaCommon.FindVisualChild <ScrollViewer>(currentPage); page_OffsetY = sv.VerticalOffset; } touchDict["target"] = control; touchDict["viewX"] = OriginPoint.X; touchDict["viewY"] = OriginPoint.Y; touchDict["contentX"] = OriginPoint.X; touchDict["contentY"] = OriginPoint.Y + currentOffsetY; touchDict["clientX"] = OriginPoint.X - currentPoint.X; touchDict["clientY"] = OriginPoint.Y - currentPoint.Y; touchDict["pageX"] = OriginPoint.X - currentPoint.X; touchDict["pageY"] = OriginPoint.Y - currentPoint.Y + page_OffsetY; RYTTouchEvent.TouchesDict["1"] = touchDict; RYTTouchEvent.TargetTouchesDict["1"] = touchDict; LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithAnyParams(callbackF, RYTTouchEvent.TouchEventDict); } }; touchInfo.TouchDeltaEventHandler = touchDeltaEventHandler; } else if (eventName.Equals("touchstart")) { EventHandler <ManipulationStartedEventArgs> touchStartedEventHandler = null; TouchEventRegisterInfo touchInfo = null; Dictionary <string, object> touchDict = null; if (!touchEventList.Any(c => (c.FE == fe as FrameworkElement))) { touchInfo = new TouchEventRegisterInfo(); touchEventList.Add(touchInfo); touchInfo.FE = fe as FrameworkElement; touchDict = touchInfo.TouchDict; } else { touchInfo = touchEventList.FirstOrDefault(c => (c.FE == fe as FrameworkElement)); touchDict = touchInfo.TouchDict; } (fe as FrameworkElement).ManipulationStarted += touchStartedEventHandler = (sender, e) => { double currentOffsetY = 0; double page_OffsetY = 0; object obj = e.OriginalSource; Point OriginPoint = e.ManipulationOrigin; Point currentPoint = new Point(0, 0); Page currentPage = LuaCommon.FindCurrentPage(sender as FrameworkElement); FrameworkElement container = e.ManipulationContainer as FrameworkElement; if (container != null && container is ScrollViewer) { ScrollViewer sv = container as ScrollViewer; currentOffsetY = sv.VerticalOffset; } if (currentPage != null) { GeneralTransform generalTransform1 = currentPage.TransformToVisual(sender as UIElement); currentPoint = generalTransform1.Transform(new Point(0, 0)); ScrollViewer sv = LuaCommon.FindVisualChild <ScrollViewer>(currentPage); page_OffsetY = sv.VerticalOffset; } touchDict["target"] = control; touchDict["viewX"] = OriginPoint.X / LuaManager.WidthScale; touchDict["viewY"] = OriginPoint.Y / LuaManager.HeightScale; touchDict["contentX"] = OriginPoint.X / LuaManager.WidthScale; touchDict["contentY"] = (OriginPoint.Y + currentOffsetY) / LuaManager.HeightScale; touchDict["clientX"] = (OriginPoint.X - currentPoint.X) / LuaManager.WidthScale; touchDict["clientY"] = (OriginPoint.Y - currentPoint.Y) / LuaManager.HeightScale; touchDict["pageX"] = (OriginPoint.X - currentPoint.X) / LuaManager.WidthScale; touchDict["pageY"] = (OriginPoint.Y - currentPoint.Y + page_OffsetY) / LuaManager.HeightScale; RYTTouchEvent.TouchesDict["1"] = touchDict; RYTTouchEvent.TargetTouchesDict["1"] = touchDict; LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithAnyParams(callbackF, RYTTouchEvent.TouchEventDict); }; touchInfo.TouchStartedEventHandler = touchStartedEventHandler; } else if (eventName.Equals("touchend")) { EventHandler <ManipulationCompletedEventArgs> dragCompletedEventHandler = null; TouchEventRegisterInfo touchInfo = null; Dictionary <string, object> touchDict = null; if (!touchEventList.Any(c => (c.FE == fe as FrameworkElement))) { touchInfo = new TouchEventRegisterInfo(); touchEventList.Add(touchInfo); touchInfo.FE = fe as FrameworkElement; touchDict = touchInfo.TouchDict; } else { touchInfo = touchEventList.FirstOrDefault(c => (c.FE == fe as FrameworkElement)); touchDict = touchInfo.TouchDict; } (fe as FrameworkElement).ManipulationCompleted += dragCompletedEventHandler = (sender, e) => { double currentOffsetY = 0; double page_OffsetY = 0; object obj = e.OriginalSource; Point OriginPoint = e.ManipulationOrigin; Point currentPoint = new Point(0, 0); Page currentPage = LuaCommon.FindCurrentPage(sender as FrameworkElement); FrameworkElement container = e.ManipulationContainer as FrameworkElement; if (container != null && container is ScrollViewer) { ScrollViewer sv = container as ScrollViewer; currentOffsetY = sv.VerticalOffset; } if (currentPage != null) { GeneralTransform generalTransform1 = currentPage.TransformToVisual(sender as UIElement); currentPoint = generalTransform1.Transform(new Point(0, 0)); ScrollViewer sv = LuaCommon.FindVisualChild <ScrollViewer>(currentPage); page_OffsetY = sv.VerticalOffset; } touchDict["target"] = control; touchDict["viewX"] = OriginPoint.X / LuaManager.WidthScale; touchDict["viewY"] = OriginPoint.Y / LuaManager.HeightScale; touchDict["contentX"] = OriginPoint.X / LuaManager.WidthScale; touchDict["contentY"] = (OriginPoint.Y + currentOffsetY) / LuaManager.HeightScale; touchDict["clientX"] = (OriginPoint.X - currentPoint.X) / LuaManager.WidthScale; touchDict["clientY"] = (OriginPoint.Y - currentPoint.Y) / LuaManager.HeightScale; touchDict["pageX"] = (OriginPoint.X - currentPoint.X) / LuaManager.WidthScale; touchDict["pageY"] = (OriginPoint.Y - currentPoint.Y + page_OffsetY) / LuaManager.HeightScale; RYTTouchEvent.TouchesDict["1"] = touchDict; RYTTouchEvent.TargetTouchesDict["1"] = touchDict; LuaManager.GetLuaManager(L).ExecuteCallBackFunctionWithAnyParams(callbackF, RYTTouchEvent.TouchEventDict); }; } else if (eventName.Equals("touchcancel")) { } } } return(0); }