/// <summary>TODO</summary> Layer NewLayer(PaintAction paintAction) { return(new Layer( Context.Allocate(Graphics, new Rectangle(Point.Empty, Size)), paintAction )); }
/// <summary>TODO</summary> internal Layer(BufferedGraphics buffer, PaintAction paintAction) { Buffer = buffer; PaintAction = paintAction; Background = Color.Transparent; IsOn = true; Resize(Buffer); }
public void AddAction(PaintAction action) { for (int i = totalIndex; i > ActionIndex; i--) { ActionList.RemoveAt(i); } ActionList.Add(action); ActionIndex++; totalIndex = ActionIndex; }
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 { } }
private void UsePaintActionOnArea(int bottom, int top, int left, int right, Color value, PaintAction action, FixedShape2D shape) { for (int y = bottom; y <= top; y++) { for (int x = left; x <= right; x++) { if (CheckBounds(x, y)) { if (shape != null) { if (shape.Contains(x, y)) { action(x, y, value); //Debug.Log("Draw"); } } else { action(x, y, value); } } } } }
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); }
/// <summary>Performs a buffered animation operation. The animation consists of a cross-fade between the contents of two buffers over a specified period of time.</summary> /// <typeparam name="TState">The type of the state that is used to determine the image to paint.</typeparam> /// <typeparam name="TParam">The type of the parameter that is passed into this method.</typeparam> /// <param name="graphics">The target DC on which the buffer is animated.</param> /// <param name="ctrl">The window in which the animations play.</param> /// <param name="bounds">Specifies the area of the target DC in which to draw.</param> /// <param name="paintAction">A method delegate that performs the painting of the control at a given state.</param> /// <param name="currentState">The current state to use to start drawing the animation.</param> /// <param name="newState">The final state to use to finish drawing the animation.</param> /// <param name="getDuration">A method delegate that gets the duration of the animation, in milliseconds.</param> /// <param name="data">User-defined data to pass to the <paramref name="paintAction"/> callback.</param> public static void PaintAnimation <TState, TParam>(Graphics graphics, IWin32Window ctrl, Rectangle bounds, PaintAction <TState, TParam> paintAction, TState currentState, TState newState, GetDuration <TState> getDuration, TParam data) { try { if (System.Environment.OSVersion.Version.Major >= 6) { // If this handle is running with a different state, stop the animations if (paintAnimationInstances.TryGetValue(ctrl.Handle, out Tuple <object, object> val)) { if (!Equals(val.Item1, currentState) || !Equals(val.Item2, newState)) { BufferedPaintStopAllAnimations(new HandleRef(ctrl, ctrl.Handle)); System.Diagnostics.Debug.WriteLine("BufferedPaintStop."); paintAnimationInstances[ctrl.Handle] = new Tuple <object, object>(currentState, newState); } } else { paintAnimationInstances.Add(ctrl.Handle, new Tuple <object, object>(currentState, newState)); } using (var hdc = new SafeDCHandle(graphics)) { if (hdc.IsInvalid) { return; } // see if this paint was generated by a soft-fade animation if (BufferedPaintRenderAnimation(new HandleRef(ctrl, ctrl.Handle), hdc)) { paintAnimationInstances.Remove(ctrl.Handle); return; } var animParams = new BP_ANIMATIONPARAMS(BP_ANIMATIONSTYLE.BPAS_LINEAR, getDuration?.Invoke(currentState, newState) ?? 0); using (var h = new BufferedAnimationPainter(ctrl, hdc, bounds, animParams, BP_PAINTPARAMS.NoClip)) { if (!h.IsInvalid) { if (h.SourceGraphics != null) { paintAction(h.SourceGraphics, bounds, currentState, data); } if (h.DestinationGraphics != null) { paintAction(h.DestinationGraphics, bounds, newState, data); } } else { // hdc.Dispose(); paintAction(graphics, bounds, newState, data); } } } } else { paintAction(graphics, bounds, newState, data); } } catch { } System.Diagnostics.Debug.WriteLine($"BufferedPaint state items = {paintAnimationInstances.Count}."); }
/// <summary>Performs a buffered animation operation. The animation consists of a cross-fade between the contents of two buffers over a specified period of time.</summary> /// <typeparam name="TState">The type of the state that is used to determine the image to paint.</typeparam> /// <param name="graphics">The target DC on which the buffer is animated.</param> /// <param name="ctrl">The window in which the animations play.</param> /// <param name="bounds">Specifies the area of the target DC in which to draw.</param> /// <param name="paintAction">A method delegate that performs the painting of the control at a given state.</param> /// <param name="currentState">The current state to use to start drawing the animation.</param> /// <param name="newState">The final state to use to finish drawing the animation.</param> /// <param name="getDuration">A method delegate that gets the duration of the animation, in milliseconds.</param> public static void PaintAnimation <TState>(Graphics graphics, IWin32Window ctrl, Rectangle bounds, PaintAction <TState, int> paintAction, TState currentState, TState newState, GetDuration <TState> getDuration) => PaintAnimation(graphics, ctrl, bounds, paintAction, currentState, newState, getDuration, 0);
/// <summary>TODO</summary> public void AddLayer(PaintAction paintAction) { Items.Add(NewLayer(paintAction)); }
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 { } }
public void AddActionToManager(PaintAction action) { GameManager.Instance.actionManager.AddAction(action); }