Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] GC Code cleanup

While working on making a platform agnostic version of a Cairo backed GC, I noticed the following would simplify things greatly:

Drawable {

....

  Rectangle getBounds();

}

On Win/Mac/Linux (and I guess pretty much on all other platforms, any Drawable subclass does implement getBounds(), do declaring the method at the level of Drawable is not even a stretch. not to mention that semantically, this is pretty much the one thing you can count on from a Drawable, to be able to get its size.....

the gain would be to simplify the code that is right now replicated everywhere for getting the size of the painting surface from inside the various GC implementations.. and in my case (portable Cairo GC, then it really streamlines the implementation).

At the moment, I have had to write this, which is butt uggly, but portable whichever the implementation of the Drawable:

----- the various flavours sprinkled all over

the universal OS.gdk_drawable_get_size
mac images    OS.CGImageGetWidth
mac hiviews   OS.HIViewGetFrame
....

----------
	Rectangle getDrawableSize() {
		Rectangle r = null;
		if (this.drawable instanceof Control) {
			r = ((Control)this.drawable).getBounds();
		} else if (this.drawable instanceof Device) {
			r = ((Device)this.drawable).getBounds();
		} else if (this.drawable instanceof Image) {
			r = ((Image)this.drawable).getBounds();
		}
		return r;
	}
----------

the code would reaaaaaaally be cleaned up in many places getBounds() in Drawable... REAAAAAALLLLLLLLLLLLYYYYYYYYYYYYYYYYYYYYYYYYYYYYY

[please santa, make them see it]



Back to the top