Skip to content

Pixel Grid Modes

abbie edited this page May 20, 2023 · 2 revisions

The pixel grid introduces an API for how pixels can be placed to it so that other control schemes may be introduced along side the usual mouse. This means that if it was implemented one could use a Guitar Hero guitar controller or even a set of Donkey Kong bongos to make pixel art

Examples

Break Down

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 extend the Mode class with our plugin object or create a secondary object that implements it

@Plugin(...)
object MyGridMode : Mode("MyMode")

Now we need to register our mode to the mode registry so that it'll be picked up by the program

@Plugin(...)
object MyGridMode : Mode("MyMode") {
    init {
        Mode.registry[name] = this
    }
}

We then need to take care of getting our mode to apply when we select it and unapply when we deselect it. For the Mouse example, these methods cause a mouse listener to be added to/removed from the pixel grid

@Plugin(...)
object MyGridMode : Mode("MyMode") {
    init {
        Mode.registry[name] = this
    }

    override fun apply() {
        ...
    }

    override fun remove() {
        ...
    }
}

And with that, we're done setting up the Rawky code. Now it's up to you to listen to whatever events get fired by what you're implementing a mode for, then add whatever that translates to pixel wise to PixelGridPanel.selectedCells and finally call PixelGridPanel.paint when whatever should trigger painting of the selected pixels occurs