[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Problems with Double Buffer
|
1. They are completely different. SWT.DOUBLE_BUFFER is for double buffering.
SWT.NO_BACKGROUND is useful when you are drawing the entire area of the
widget and don't need a bacgkround, thus you tell the OS not to draw it as
you will be doing that job (and if you using the whole area but only drawing
on a small part, make sure to fill the entire area with a background color
first or you'll have strange patches of nothing). See it as a flag to make
the OS do less when you do all the work for it. However, you don't want to
use this unless you are really drawing the entire visual area of the widget,
or you'll have some very odd things happen.
2. You should not be using more than _one_ GC object (per widget) or you are
wasting resources creating and disposing them. The GC you want is supplied
to you via the paintListener event.. event.gc. Use that one. You shouldn't
need to create one unless you truly have a good reason for it (such as the
special drawing I mentioned in my last reply, but that's still only one more
GC object - two total, or you need to draw when there is not a redraw()
event happening).
3. I don't really understand what you are doing in the resize listener, it's
a bit hard to tell what the code does from your snippet. Why are you
re-creating the image over and over? Is it a new image whenever the user
resizes? If not, just create it once and reuse it, creating images is not a
fast process, especially when you are resizing which calls redraw() many,
many times in a row.
Also, when you call "redraw()", if you know the area needed to redraw, call
the parameterized redraw(...) where you can specify what area needs to be
redrawn. You'll save a lot of "time" doing that. By setting some integers on
resize you will know what the old area size was compared to the new and you
can redraw only what's needed (unless of course it affects an area that is
part of the currently visible area as well, then you might need a full
redraw).
Emil
--
Emil Crumhorn
Nebula Committer
http://www.hexapixel.com/
"KiMoon" <ibatis@xxxxxxxxx> wrote in message
news:2a6ccc11af500add941f44a305203f3f$1@xxxxxxxxxxxxxxxxxx
> Thank you for your answer
> More stuff to be clear
>
>
> [1] What is the difference between SWT.DOUBLE_BUFFER and
> SWT.NO_BACKGROUND? im using Windows XP Pro, eclipse europa. what is the
> specific difference between them in usage?
>
>
> [2] The stuff (bar, line, axis, etc) shown on the screen are being drawn
> as following. Could this be any problem by getting new GC and draw every
> time?
> if(image != null) {
> GC gc = new GC(image);
> // do something
> gc.dispose();
> }
>
> [3] While screen resizing, flickering has gone; however, still when moving
> scroll-bar left to right, there's the flickering.
> and also in the middle of a bar chart, bar seems to be separated
> instantly. In other words, i could say that it is visible the bar
> redrawing quickly.
> i think i am lack of knowledge about this theory or making a simple
> mistake but unable to catch or something else.
> Somehow, can you give me any advice as you see following code below? i
> will appreciate.
>
>
> Canvas canvas = new Canvas(parent, SWT.NO_BACKGROUND | SWT.H_SCROLL |
> SWT.NO_REDRAW_RESIZE);
>
> canvas.addListener(SWT.Resize, new Listener() {
> public void handleEvent(Event event) {
> if (image != null) {
> image.dispose();
> }
>
> image = new Image(display, w, h);
> canvs.redraw();
>
> setScrollPosition();
> }
> });
>
> canvas.addListener(SWT.Paint, new Listener() {
> public void handleEvent(Event event) {
> if (manager.getProperty().getImageX() != null) {
> GC gc = event.gc;
> gc.drawImage(image, origin.x, origin.y);
> gc.dispose();
> }
> }
> });
>
> private void setScrollPosition() {
> Rectangle client =canvas.getBounds();
> Rectangle rect = image.getBounds();
> hBar.setMaximum(rect.width);
> hBar.setThumb(Math.min(rect.width, client.width));
>
> int hPage = rect.width - client.width;
> int hSelection = hBar.getSelection();
>
> if (hSelection >= hPage) {
> if (hPage <= 0) {
> hSelection = 0;
> }
> origin.x = -hSelection;
> }
>
> canvas.redraw();
> }
>