Canvas not Updating
Blitz3D Forums/Blitz3D Beginners Area/Canvas not Updating
| ||
I'm new to B+ and am having dificulties with my program flow, after adding a toolbar lifted straight from the B+ tutorials my program will only update when the mouse is being moved. The code below loads information from a CSV file and displays each line as it is processed. Currently it will only read through the lines when the mouse is moving. window=CreateWindow("CSV Cleaner",0,0,800,600) canvas=CreateCanvas(0,0,800,600,window) SetBuffer CanvasBuffer(canvas) ; create the menu menu=WindowMenu(window) file=CreateMenu("File",0,menu) CreateMenu "Load",FILELOAD,file CreateMenu "Save",FILESAVE,file CreateMenu "Quit",FILEQUIT,file help=CreateMenu("Help",0,menu) CreateMenu "About",HELPABOUT,help UpdateWindowMenu window While Not Eof(CSVin) Cls DrawImage BGMain,0,0 CSVLineNum = CSVLineNum + 1 CSVLine$ = ReadLine(CSVin) NumCSVItems = CountItems( CSVLine$, "," ) For A = 0 To NumCSVItems - 1 item$ = Parse( CSVLine$, A, "," ) If Item$ = "" Then EmptyItems = EmptyItems + 1 CSVDataArray$(CSVLineNum,A) = item$ Next textimage("Reading CSV",15,40) textimage(CSVLine$,15,65) UpdateToolbar() FlipCanvas canvas wend This piece of code shows the UpdateToolbar function called before the FlipCanvas command in the piece of code above. Function UpdateToolbar() Select WaitEvent() Case $1001 ;menu event Select EventData() Case FILELOAD: filename=RequestFile("Load File","*.*") Case FILESAVE: filename=RequestFile("Save File",filename,True) Case FILEQUIT: End Case HELPABOUT Notify "selecting About = user interest" End Select Case $803 ;close window event End End Select End Function Also whenever load or save is called up the canvas will go black. TIA |
| ||
Try adding a CreateTimer 50 in your setup. I kind of think you should restructure your program so the canvas update is in a function that is called from Event case $4001 and use standard message handler main loop as in the UserGuide. |
| ||
The command waitevent() will actualy stop your program executing until a specified time EG waitevent(1000), or an event happens. So the behaviour you notice is the correct one, where teh mouse causes the event to happen, and thus your program can continue past waitevent(). Do as skidracer suggests, add a timer, and put your canvas update stuff in the $4001 event. |
| ||
Thanks, CreateTimer certainly works. I'm guessing that this creates 50 event a second and each event is a $4001, please correct me if I'm wrong. If not can you explain event $4001 or even better give me a link to a list of events. |
| ||
$4001 is the timer event, and x = CreateTimer (50) will generate such an event every 1/50th of a second. Use Select WaitEvent () / Case $4001 to get the timer events, and then Select EventSource () / Case x to find the timer that created it, eg.timer1 = CreateTimer (50) timer2 = CreateTimer (500) Select WaitEvent () Case $4001 Select EventSource () ; Could be EventData, can't remember off-hand! Case timer1 ; Do something every 50 ms... Case timer2 ; Do something every 500 ms... ; Etc... The docs for WaitEvent give a list of event values... http://www.blitzbasic.com/bpdocs/command.php?name=waitevent&ref=goto |
| ||
Time to forget all thing Blitz2D and learn a new. Looks good now, very pleased with the Toolbar and the ability to load without needing to write or borrow a file browser. One problem still stands, when Load is selected from the Toolbar the canvas will go black until a file is choosen and program flow is restored. |