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

In repaint! allow specifying region to repaint #191

Open
m-r-hunt opened this issue Apr 18, 2015 · 3 comments
Open

In repaint! allow specifying region to repaint #191

m-r-hunt opened this issue Apr 18, 2015 · 3 comments

Comments

@m-r-hunt
Copy link

I've been doing some custom painting, and I was having some performance problems. I'm in a situation where I know I only need to repaint a small area of my canvas, but the repaint! macro causes a full repaint of the whole canvas. I tried conspiring behind it's back to only repaint the region I know needs painting, but the rest of the canvas gets blanked out.

After searching the swing docs, it looks like the solution is to specify a dirty region to repaint, rather than repainting the whole component. There's no way to do this (as far as I can tell) in seesaw, the repaint! function always repaints whole components.

I can solve my problem (I think) by manually calling the swing repaint methods, but it would be nice if there was a seesaw way to do this.

@m-r-hunt
Copy link
Author

Proposed function:

(repaint-region! [widget1 rect1] [widget2 rect2] ...)

or something like that.

@m-r-hunt
Copy link
Author

Gif of what happens when you try to be too clever for your own good:

@m-r-hunt
Copy link
Author

Here's the core of a method to do this. I'm too tired to make it work nicely with multiple widgets/rectangles right now.

Yes you have to deconstruct the rectangle like that because java.awt.component repaint methods won't take a java.awt.rectangle2D, only x y w h in the argument list. (I think it makes sense for the seesaw interface to take a seesaw.graphics/rect even though the underlying swing/awt code is dumb)

(defn repaint-region!
  "Repaint only a specified rectangle"
  [widget rect]
  (.repaint (seesaw.core/to-widget widget) 
            (.getX rect) 
            (.getY rect) 
            (.getWidth rect) 
            (.getHeight rect)))

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

No branches or pull requests

1 participant