|
java-gnome version 4.0.19 | ||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public static interface Widget.ExposeEvent
The signal emitted when a portion or all of the Widget has been exposed and needs [re]drawing. This can happen when a Widget is first realized to the screen or when part of it has come back from being obscured (by another Window or because it was offscreen).
The event
parameter to the callback contains information
about the size of the region that was damaged or otherwise needs
redrawing. For instance, if you just wanted to know what area was
exposed, you could do:
foo.connect(new Widget.ExposeEvent() { public boolean onExposeEvent(Widget source, EventExpose event) { Rectangle rect; int width, height, x, y; rect = event.getArea(); width = rect.getWidth(); height = rect.getHeight(); x = rect.getX(); y = rect.getY(); System.out.println(width + "x" + height + " at " + x + "," + y); } }
The real purpose of Widget.ExposeEvent
, however, is to be
the the gateway to drawing. GNOME uses the excellent Cairo 2D graphics library to
draw its user interfaces, which we make available in java-gnome in
package org.freedesktop.cairo
.
Code that does drawing needs to be written a little differently than
code which just builds Widgets up into user interfaces. While we are
accustomed to doing setting up various Widgets and packing them into
Windows in our constructors, the one thing you cannot easily do there
is graphics drawing. In order to be able to construct the Context used
for drawing operations, Cairo needs the details of the [org.gnome.gdk]
Display, Screen and Window it will be drawing to, and these are not
available until the Widget has been realized and mapped. The
Widget.ExposeEvent
signal is emitted exactly at this
point, and so that's when we have the environment we need to do our
drawing.
To do drawing with Cairo you need a Context. You can instantiate one by passing the EventExpose object to the Context constructor:
foo.connect(new Widget.ExposeEvent() { public boolean onExposeEvent(Widget source, EventExpose event) { Context cr; cr = new Context(event); // start drawing } }Obviously from here you can carry on using the Cairo Graphics library to do your custom drawing. See
Context
for further details.
Method Summary | |
---|---|
boolean |
onExposeEvent(Widget source,
EventExpose event)
As with other event signals, the boolean return value indicates whether or not you wish to block further emission of the signal. |
Method Detail |
---|
boolean onExposeEvent(Widget source, EventExpose event)
false
.
|
![]() java-gnome |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |