示例#1
0
 public static void Paint <TState, TParam>(Graphics graphics, Rectangle bounds, PaintAction <TState, TParam> paintAction,
                                           TState currentState, TParam data)
 {
     using (var g = new SafeDCHandle(graphics))
         using (var bp = new BufferedPaintHandle(g, bounds))
             paintAction(bp.Graphics, bounds, currentState, data);
 }
示例#2
0
            public static void Paint <TState, TParam>(Graphics g, IWin32Window w, Rectangle rc, PaintAction <TState, TParam> f, TState currentState, TState newState, uint duration, TParam optParam)
            {
                try
                {
                    if (System.Environment.OSVersion.Version.Major >= 6 && NativeMethods.BufferedPaintInit() == IntPtr.Zero)
                    {
                        using (var hdc = new SafeGDIHandle(g))
                        {
                            if (!hdc.IsInvalid)
                            {
                                // see if this paint was generated by a soft-fade animation
                                if (!NativeMethods.BufferedPaintRenderAnimation(w.Handle, hdc))
                                {
                                    NativeMethods.BufferedPaintAnimationParams animParams = new NativeMethods.BufferedPaintAnimationParams {
                                        Duration = duration
                                    };

                                    IntPtr hdcFrom, hdcTo;
                                    using (var h = new BufferedPaintHandle(w.Handle, hdc, ref rc, ref animParams, out hdcFrom, out hdcTo))
                                    {
                                        if (!h.IsInvalid)
                                        {
                                            if (hdcFrom != IntPtr.Zero)
                                            {
                                                using (Graphics gfxFrom = Graphics.FromHdc(hdcFrom))
                                                    f(gfxFrom, rc, currentState, optParam);
                                            }
                                            if (hdcTo != IntPtr.Zero)
                                            {
                                                using (Graphics gfxTo = Graphics.FromHdc(hdcTo))
                                                    f(gfxTo, rc, newState, optParam);
                                            }
                                        }
                                        else
                                        {
                                            hdc.Dispose();
                                            f(g, rc, newState, optParam);
                                        }
                                    }
                                }
                            }
                        }
                        NativeMethods.BufferedPaintUnInit();
                    }
                    else
                    {
                        f(g, rc, newState, optParam);
                    }
                }
                catch { }
            }
示例#3
0
            public static void PaintAnimation <TState, TParam>(Graphics graphics, IWin32Window ctrl, Rectangle bounds,
                                                               PaintAction <TState, TParam> paintAction, TState currentState, TState newState, int duration, TParam data)
            {
                try
                {
                    if (System.Environment.OSVersion.Version.Major >= 6)
                    {
                        using (var hdc = new SafeDCHandle(graphics))
                        {
                            if (hdc.IsInvalid)
                            {
                                goto defPaint;
                            }
                            // see if this paint was generated by a soft-fade animation
                            if (BufferedPaintRenderAnimation(new HandleRef(ctrl, ctrl.Handle), hdc))
                            {
                                return;
                            }

                            using (var h = new BufferedPaintHandle(ctrl, hdc, bounds, new BufferedPaintAnimationParams(duration)))
                            {
                                if (!h.IsInvalid)
                                {
                                    if (h.SourceGraphics != null)
                                    {
                                        paintAction(h.SourceGraphics, bounds, currentState, data);
                                    }
                                    if (h.Graphics != null)
                                    {
                                        paintAction(h.Graphics, bounds, newState, data);
                                    }
                                }
                                else
                                {
                                    goto defPaint;
                                }
                            }
                        }
                        return;
                    }
defPaint:
                    paintAction(graphics, bounds, newState, data);
                }
                catch { }
            }