Copy a PGraphics Object
in
Programming Questions
•
1 year ago
I am currently developing a drawing program in which users can create multiple layers.
The layers are complex datatypes that contain a PGraphics instance.
The program is built using Android, if that's relevant.
I want the users to be able to duplicate the layers.
I have tried several approaches.
Simply assigning the duplicate to the original does not work because it will copy the path to the instance, not the instance itself.
I have tried both using the Cloneable interface, doing it to all classes needed and creating an extended version of PGraphics, as well as Serialization, but PGraphics does not implement Serializable, so I had to rewrite that.
In either scenario, it would be necessary to use a class other than PGraphics. Because of this, createGraphics() can no longer be used to initialize the PGraphics.
I have also looked at the createGraphics() source code, but could find no easy way to rewrite it.
If you know of a better solution, or perhaps one that Processing provides to solve this, I would like to know what it is.
Thank you.
The layers are complex datatypes that contain a PGraphics instance.
The program is built using Android, if that's relevant.
I want the users to be able to duplicate the layers.
I have tried several approaches.
Simply assigning the duplicate to the original does not work because it will copy the path to the instance, not the instance itself.
I have tried both using the Cloneable interface, doing it to all classes needed and creating an extended version of PGraphics, as well as Serialization, but PGraphics does not implement Serializable, so I had to rewrite that.
In either scenario, it would be necessary to use a class other than PGraphics. Because of this, createGraphics() can no longer be used to initialize the PGraphics.
I have also looked at the createGraphics() source code, but could find no easy way to rewrite it.
If you know of a better solution, or perhaps one that Processing provides to solve this, I would like to know what it is.
Thank you.
1