-
Notifications
You must be signed in to change notification settings - Fork 9
Exporters, Importers and Openers
A painted document is almost worthless if there's no way to get it outside of the program. Sure, you could screen cap it or even take a picture with a camera but these are less than ideal. To aid in this, Rawky has concepts to handle getting things outside and inside of the program with little effort on the user's side
These are how we get things outside the program. They take the current document and put it into a file, with the format of said file being chosen by the user. If no exporter is found for the file type a dialogue box will be shown to let the user know
First, we'll need a plugin to work with. If you already have one, keep going. If not, define a plugin. After we have one, we'll either need to implement the Exporter interface on our plugin object or create a secondary object that implements it
@Plugin(...)
object MyExporter : Exporter
The Exporter interface has a property to define the name of the exporter so we'll need to implement that
@Plugin(...)
object MyExporter : Exporter {
override val name = "MyExporter"
}
We'll also need to define the file types that our exporter will be registered to handle
@Plugin(...)
object MyExporter : Exporter {
override val name = "MyExporter"
override val extensions = mapOf(
"MyFormat" to listOf("pyt", "abc")
)
}
Next, we need to register our exporter to the exporter registry so that it'll be picked up by the program
@Plugin(...)
object MyExporter : Exporter {
override val name = "MyExporter"
override val extensions = mapOf(
"MyFormat" to listOf("pyt", "abc")
)
init {
Exporter.registry[name] = this
}
}
Now we'll need to get to the actual exporting of the document. We implement the export
function from the Exporter interface. Once inside it, we'll have access to the current document and the file chosen to write to from the export dialogue. We can then export our document into this file using our chosen format
@Plugin(...)
object MyExporter : Exporter {
override val name = "MyExporter"
override val extensions = mapOf(
"MyFormat" to listOf("pyt", "abc")
)
init {
Exporter.registry[name] = this
}
override fun export(doc: RawkyDocument, file: File) {
...
}
}
Importers, unlike Openers, are how we can introduce a file into the currently open document. Either as a new layer or onto the current one. Either into a new frame or on to the current one
- ImageIO (png, tiff)
These are how we can open files into a new document, wiping previous unsaved content