Beispiel #1
0
        public void Init(Window main_window)
        {
            _main_window = main_window;
            m_theatre    = new Shinengine.Theatre.Theatre(BG, Usage, SBK, AirPt, character_usage, Lines, character, ShowIn, _Contents);

            #region logo
            m_logo = new Direct2DImage(new SharpDX.Size2((int)logo_frames[0].Size.Width, (int)logo_frames[0].Size.Height), 30)
            {
                Loadedsouce = logo_frames
            };
            m_logo.DrawProc += (t, s, w, h) =>
            {
                var frames = s as List <WICBitmap>;

                if (ims == frames.Count)
                {
                    ims = 0;
                }
                t.View.BeginDraw();
                t.View.Clear(null);
                D2DBitmap parl_map = D2DBitmap.FromWicBitmap(t.View, frames[ims]);
                t.View.DrawBitmap(parl_map, 1, InterpolationMode.Anisotropic);
                t.View.EndDraw();

                ims++;
                parl_map.Dispose();
                return(DrawProcResult.Normal);
            };
            m_logo.DrawStartup(Logo);


            #endregion
        }
        public void Start(IntPtr hWnd, string path, Action endplay)
        {
            var vest = new Video(Video.VideoMode.LoadWithPlaying, path);

            dxVideo = new Direct2DImage(new SharpDX.Size2((int)vest.frameSize.Width, (int)vest.frameSize.Height), vest.Fps)
            {
                Loadedsouce = vest
            };
            dxVideo.Disposing += (Loadedsouce, s) => { (Loadedsouce as Video).Dispose(); };
            dxVideo.DrawProc  += DrawCallback;


            var video = dxVideo.Loadedsouce as Video;

            new Task(() =>
            {
                while (!video.CanRun)
                {
                    Thread.Sleep(1);
                }
                unsafe
                {
                    //       var intp = getPCM("assets.shine:09.pcm");
                    waveInit(hWnd, video.Out_channels, video.Out_sample_rate, video.Bit_per_sample, video.Out_buffer_size);


                    while (true)
                    {
                        if (!video.CanRun)
                        {
                            break;
                        }
                        if (video.EntiryPlayed && i == video.abits.Count && video.nFarm == video.bits.Count)
                        {
                            break;
                        }
                        if (i == video.abits.Count)
                        {
                            Thread.Sleep(1);
                            continue;
                        }
                        audio_time = (double)(video.abits[i]?.time_base);

                        waveWrite((byte *)video.abits[i]?.data, video.Out_buffer_size);
                        Marshal.FreeHGlobal((IntPtr)video.abits[i]?.data);
                        video.abits[i] = null;
                        i++;
                    }

                    waveClose();
                    this.Dispatcher.Invoke(endplay);
                }
            }).Start();


            video.Start();
            dxVideo.DrawStartup(BackGround);
        }
Beispiel #3
0
        public Character(Theatre father, string name, string template, bool canshow = true, double?time = null, bool isAscy = true, double vel_x = 0, double vel_y = 0)
        {
            var layer = father.CharacterLayer;

            m_father = father;
            ManualResetEvent msbn = new ManualResetEvent(false);

            _name = name;

            if (time == null)
            {
                time = SharedSetting.SwitchSpeed;
            }
            layer.Dispatcher.Invoke(new Action(() =>
            {
                whereIsShowed = layer;

                Init_action = Stage.LoadBitmap(template);

                shower = new Image
                {
                    Width             = Init_action.Size.Width * (layer.Height / Init_action.Size.Height),
                    Height            = layer.Height,
                    VerticalAlignment = VerticalAlignment.Bottom,
                    Stretch           = Stretch.Fill,

                    Margin = new Thickness(vel_x, 0, 0, vel_y)
                };
                if (time != 0 || !canshow)
                {
                    shower.Opacity = 0;
                }
                whereIsShowed.Children.Add(shower);

                Direct2DImage direct2DImage = new Direct2DImage(new Size2((int)shower.Width, (int)shower.Height), 30);
                direct2DImage.DrawProc     += (View, Souce, Width, Height) =>
                {
                    D2DBitmap m_bp = D2DBitmap.FromWicBitmap(View.View, Init_action, new BitmapProperties1(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

                    View.View.BeginDraw();
                    View.View.Clear(null);

                    View.View.DrawBitmap(m_bp,
                                         new RawRectangleF(0, 0, Width, Height),
                                         1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                         new RawRectangleF(0, 0, Init_action.Size.Width, Init_action.Size.Height));

                    View.View.EndDraw();

                    m_bp.Dispose();
                    return(DrawProcResult.Death);
                };

                direct2DImage.Disposing += (e, s) =>
                {
                    Last_Draw = s.LastDraw;
                    msbn.Set();
                };

                direct2DImage.DrawStartup(shower);
            }));
            msbn.WaitOne();
            msbn.Dispose();
            if (!canshow)
            {
                return;
            }


            EasyAmal aml = new EasyAmal(shower, "(Opacity)", 0.0, 1.0, (double)time);

            aml.Start(isAscy);
        }//已经确认过安全的代码,再次修改需要小心
Beispiel #4
0
        }//已经确认过安全的代码,再次修改需要小心

        public void SwitchTo(int area, int index, double?time = null, bool isAysn = false)
        {
            if (time == null)
            {
                time = SharedSetting.TextSpeed;
            }

            if (time < 1.0 / 30.0 && time != 0)
            {
                throw new Exception("time can not be less than 1/30s");
            }
            Rect targetArea = ChAreas[area].area;

            WICBitmap rost_pitch = ChAreas[area].switches[index];

            shower.Dispatcher.Invoke(() =>
            {
                dx_switch = new Direct2DImage(new Size2((int)shower.Width, (int)shower.Height), 30)//////////////AAA
                {
                };
            });
            double soul_rate = 0;

            shower.Dispatcher.Invoke(() => { soul_rate = whereIsShowed.Height / Init_action.Size.Height; });
            dx_switch.FirstDraw += (e, v, w, h) =>
            {
                D2DBitmap m_ipq = D2DBitmap.FromWicBitmap(e.View, Last_Draw);/////////////////AAA
                e.View.BeginDraw();
                e.View.Clear(null);

                e.View.DrawBitmap(m_ipq,
                                  new RawRectangleF(0, 0, w, h),
                                  1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                  new RawRectangleF(0, 0, Last_Draw.Size.Width, Last_Draw.Size.Height));

                e.View.EndDraw();

                m_ipq.Dispose();//////////////////BB
                return;
            };
            ManualResetEvent msbn = new ManualResetEvent(false);//////////////////AAA

            if (time == 0)
            {
                dx_switch.DrawProc += (e, v, w, h) =>
                {
                    D2DBitmap m_ipq  = D2DBitmap.FromWicBitmap(e.View, Init_action);
                    D2DBitmap m_ipq2 = D2DBitmap.FromWicBitmap(e.View, rost_pitch);

                    e.View.BeginDraw();

                    e.View.DrawBitmap(m_ipq,
                                      new RawRectangleF(0, 0, w, h),
                                      1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                      new RawRectangleF(0, 0, Init_action.Size.Width, Init_action.Size.Height));

                    e.View.DrawBitmap(m_ipq2,
                                      new RawRectangleF(
                                          (float)(targetArea.Left * soul_rate),
                                          (float)(targetArea.Top * soul_rate),
                                          (float)(targetArea.Right * soul_rate),
                                          (float)(targetArea.Bottom * soul_rate)
                                          ),
                                      1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                      new RawRectangleF(0, 0, rost_pitch.Size.Width, rost_pitch.Size.Height));

                    e.View.EndDraw();

                    m_ipq.Dispose();
                    m_ipq2.Dispose();
                    if (!isAysn)
                    {
                        msbn.Set();
                    }
                    return(DrawProcResult.Death);
                };
                dx_switch.Disposing += (e, s) =>
                {
                    if (Last_Draw != null)
                    {
                        if (!Last_Draw.IsDisposed)
                        {
                            Last_Draw.Dispose();
                        }
                    }
                    Last_Draw = s.LastDraw;
                };
            }
            else
            {
                double interrase = 1 / ((double)time * 30);
                double varb      = 0;

                D2DBitmap m_ipq  = D2DBitmap.FromWicBitmap(dx_switch.m_d2d_info.View, Last_Draw);  //////////////AAA
                D2DBitmap m_ipq2 = D2DBitmap.FromWicBitmap(dx_switch.m_d2d_info.View, rost_pitch); ///////////////AAA
                D2DBitmap m_ipq3 = D2DBitmap.FromWicBitmap(dx_switch.m_d2d_info.View, Init_action);
                dx_switch.DrawProc += (e, v, w, h) =>
                {
                    e.View.BeginDraw();
                    e.View.Clear(null);

                    #region 两次绘图
                    e.View.DrawBitmap(m_ipq,
                                      new RawRectangleF(0, 0, w, h),
                                      1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                      new RawRectangleF(0, 0, Last_Draw.Size.Width, Last_Draw.Size.Height));

                    e.View.DrawBitmap(m_ipq3,
                                      new RawRectangleF(0, 0, w, h),
                                      (float)varb, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                      new RawRectangleF(0, 0, Init_action.Size.Width, Init_action.Size.Height));

                    e.View.DrawBitmap(m_ipq2,
                                      new RawRectangleF(
                                          (float)(targetArea.Left * soul_rate),
                                          (float)(targetArea.Top * soul_rate),
                                          (float)(targetArea.Right * soul_rate),
                                          (float)(targetArea.Bottom * soul_rate)
                                          ),
                                      (float)varb, SharpDX.Direct2D1.BitmapInterpolationMode.Linear,
                                      new RawRectangleF(0, 0, rost_pitch.Size.Width, rost_pitch.Size.Height));
                    #endregion

                    e.View.EndDraw();
                    if (varb > 1)
                    {
                        m_ipq.Dispose();
                        m_ipq2.Dispose();

                        if (!isAysn)
                        {
                            msbn.Set();
                        }
                        return(DrawProcResult.Death);//////////////////BB
                    }
                    varb += interrase;

                    return(DrawProcResult.Normal);
                };

                dx_switch.Disposing += (e, s) =>
                {
                    if (Last_Draw != null)
                    {
                        if (!Last_Draw.IsDisposed)
                        {
                            Last_Draw.Dispose();
                        }
                    }
                    Last_Draw = s.LastDraw;
                    m_ipq.Dispose();  //////////////////BB
                    m_ipq2.Dispose(); //////////////////BB
                    m_ipq3.Dispose();
                };
            }
            // Last_Draw.Dispose();

            shower.Dispatcher.Invoke(() => { dx_switch.DrawStartup(shower); });
            if (!isAysn)
            {
                msbn.WaitOne();
                msbn.Dispose();//////////////////BB
            }
            msbn.Dispose();
        }//已经确认过安全的代码,再次修改需要小心