Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redraw the swing terminal on Canvas.paint(). #78

Merged
merged 1 commit into from Mar 29, 2018
Merged

Redraw the swing terminal on Canvas.paint(). #78

merged 1 commit into from Mar 29, 2018

Conversation

ghost
Copy link

@ghost ghost commented Mar 29, 2018

Fixes #77.

This creates a private Canvas subclass that invokes an onPaint callback.

This also removes canvas.ignoreRepaint = true.
I remember reading somewhere in the Swing docs (can't seem to find it now) that it recommended canvas.setIgnoreRepaint(true), but I believe this is only necessary for real-time rendering.
I'm not sure how zircon handles animations, as this library is still new to me, but it definitely doesn't render in real-time when there are no animations playing, so repainting is needed on some platforms.

Edit: Do you know if there's any other importance to ignoring repaint?

Copy link
Member

@adam-arold adam-arold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool PR, thank you for your effort! So this just adds a callback which gets called from Swing? I guess it looks for an onPaint method?

companion object {
private fun createCanvas() = Canvas()
private class TerminalCanvas() : Canvas() {
var onPaint: (() -> Unit)? = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use lateinit var onPaint: (() -> Unit) here so you don't have to bother with the nulls

@ghost
Copy link
Author

ghost commented Mar 29, 2018

Updated to use a lateinit reference to a SwingTerminal instead of a (() -> Unit)?.

@adam-arold adam-arold merged commit b0c66c4 into Hexworks:master Mar 29, 2018
@adam-arold
Copy link
Member

Great thanks. I'll pull this out today and create a new PREVIEW version from it.

@ghost
Copy link
Author

ghost commented Mar 29, 2018

Thanks!

@adam-arold
Copy link
Member

adam-arold commented Mar 29, 2018

So I refactored it to have a default null value (like in your original commit) because it turned out that Swing calls this method before the field is initialized which leads to exceptions. 😆

@adam-arold
Copy link
Member

adam-arold commented Mar 29, 2018

You can find the new snapshot on jitpack.

@ghost
Copy link
Author

ghost commented Mar 29, 2018

It's funny how Swing was intended to hide all platform-specific nuances like this, but they're still popping up. On X11, Component.paint wouldn't be called until messages are explicitly processed in the main loop, but Windows uses a callback system where messages can be processed at any time. I didn't think about this when changing to lateinit.

@adam-arold
Copy link
Member

Me neither. At least it is now tested on all major platforms. :) I was not able to reproduce the tearing you mentioned on Windows so I would have been completely oblivious to this bug.

@ghost ghost deleted the swing-exposure branch March 29, 2018 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants