Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Feb 27, 2020 12:14 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Any Hope of this Not Flickering?
PostPosted: Sun Mar 25, 2012 3:20 am 

Joined: Sun Mar 25, 2012 3:07 am
Posts: 1
Ok, there is so much information on flicker on Windows that I am getting completely lost in it.

If this has been answered before and someone can provide a link, I'd be eternally grateful.

I have an application that is essentially mimicking a scratch off lottery ticket. I am using a canvas into which I draw an image with a mask. When a user click-drags over the canvas, that part of the image mask is cleared and I refresh the image.

Right now I literally copy the mask onto the image on the drag event after I have updated the mask.

Is there any hope at all that this can be done on windows without flicker?

I have written an application that does this that of course works beautifully in Mac but windows is horrifically ugly and I get constant flicker when dragging. I would really like to have live updating so I can see what I am scratching off as it is removed but this is looking less and less likely.

Reply with quote  
 Post subject: Re: Any Hope of this Not Flickering?
PostPosted: Sun Mar 25, 2012 6:00 am 

Joined: Thu Oct 01, 2009 4:53 pm
Posts: 51
You should check for double buffering with the Canvas. When it works with Mac and it does not with Windows, this is likely.


Tom Prins

Reply with quote  
 Post subject: Re: Any Hope of this Not Flickering?
PostPosted: Sun Mar 25, 2012 7:49 am 
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
Here's what you need to know about drawing and flicker.


With one change. At the end, I mention it is good practice to always double buffer, even on Mac. This is not true, as you'll see a massive performance hit under Cocoa.

Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.

Reply with quote  
 Post subject: Re: Any Hope of this Not Flickering?
PostPosted: Sun Mar 25, 2012 11:05 am 

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Here is code that I promise is flicker-free.
Forget erase background
Forget double buffer

This technique involves having the static background (the card) as the backdrop of the canvas.
And painting the foil over the top on demand.
But ONLY the changed area: not the full canvas.

Code follows:

Create a Window, place on it a Canvas (Canvas1)
Give the window 2 properties:

foil as picture
card as picture

Window Open Event:
(All this does is to create a simple card image with 4 words on it, plus a same size foil image which is flat grey and has the words 'Scratch Me' on it. Substitute your own fancy image for card if you like)

card = new picture (canvas1.width,canvas1.height,32) = canvas1.height /6 "WIN", canvas1.width /6,canvas1.height/6 "LOSE", canvas1.width - canvas1.width /3,canvas1.height/6 "LOSE", canvas1.width /6,canvas1.height - canvas1.height/6 "WIN",canvas1.width - canvas1.width /3,canvas1.height - canvas1.height/6

foil = newpicture (canvas1.width,canvas1.height,32)
foil.Mask = newpicture(canvas1.width,canvas1.height,32) = &cd0d0d0
foil.Graphics.fillrect 0,0,foil.width-1,foil.height -1 = canvas1.height /5 = &c000000
foil.Graphics.DrawString "Scratch me!",foil.width/6,foil.height/2 = &c000000 0,0,foil.width-1,foil.height -1

foil.Transparent =1

canvas1.Backdrop = card

Canvas1 Mouse Move Event:

static xx as integer
static yy as integer

if x <> xx or y <> yy then = &cffffff
//too lazy to test for negative values x-4,y-4,8,8
me.refreshrect x-4,y-4,8,8,false
end try

//record last known position of the mouse.
//no point in redrawing if the mouse hasn't moved
xx = x
yy = y
end if

Canvas1 Paint event:

if foil = nil then
g.drawpicture foil,0,0
end if

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group