MJW Posted October 1, 2020 Share Posted October 1, 2020 I'm updating a plugin that uses the clipboard, and I believe I read fairly recently that there were new PDN routines for accessing it. However I did several forum searches, and couldn't find anything. Could someone either give me a link, or better yet, provide a description of the new methods. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted October 1, 2020 Share Posted October 1, 2020 Just let CodeLab write the code for you. CodeLab: File > New, choose the Clipboard Effect choose your canvas. Generate code to see what you get. // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: #region UICode #endregion // Working surface Surface wrk = null; private Surface clipboardSurface = null; private bool readClipboard = false; protected override void OnDispose(bool disposing) { if (disposing) { // Release any surfaces or effects you've created wrk?.Dispose(); wrk = null; clipboardSurface?.Dispose(); clipboardSurface = null; } base.OnDispose(disposing); } // This single-threaded function is called after the UI changes and before the Render function is called // The purpose is to prepare anything you'll need in the Render function void PreRender(Surface dst, Surface src) { if (wrk == null) { wrk = new Surface(src.Size); } if (!readClipboard) { readClipboard = true; clipboardSurface = Services.GetService<IClipboardService>().TryGetSurface(); } // Copy from the Clipboard to the wrk surface for (int y = 0; y < wrk.Size.Height; y++) { if (IsCancelRequested) return; for (int x = 0; x < wrk.Size.Width; x++) { if (clipboardSurface != null) { //wrk[x,y] = clipboardSurface.GetBilinearSample(x, y); //wrk[x,y] = clipboardSurface.GetBilinearSampleClamped(x, y); wrk[x,y] = clipboardSurface.GetBilinearSampleWrapped(x, y); } else { wrk[x,y] = Color.Transparent; } } } } // Here is the main multi-threaded render function // The dst canvas is broken up into rectangles and // your job is to write to each pixel of that rectangle void Render(Surface dst, Surface src, Rectangle rect) { // Step through each row of the current rectangle for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; // Step through each pixel on the current row of the rectangle for (int x = rect.Left; x < rect.Right; x++) { ColorBgra SrcPixel = src[x,y]; ColorBgra WrkPixel = wrk[x,y]; ColorBgra DstPixel = dst[x,y]; ColorBgra CurrentPixel = WrkPixel; // TODO: Add additional pixel processing code here dst[x,y] = CurrentPixel; } } } 1 1 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted October 1, 2020 Author Share Posted October 1, 2020 (edited) Thanks, BoltBait! Edited October 1, 2020 by MJW Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.