Is there a waitevent for gadget redraw

BlitzMax Forums/MaxGUI Module/Is there a waitevent for gadget redraw

D4NM4N(Posted 2006) [#1]
what exactly tells a gadget to redraw? im guessing its the underlying os every so many millisecs. Does this generate an event?

Im trying to create a small processing window but the once the processing begins it doesnt have time to display the gadget.

sorry aboutthe tabs, theyre a lot smaller in my ide :P

Global win:TGadget=CreateWindow("SpriteForge 32bit PnG Maker",350,200,400,100,Desktop(),WINDOW_TITLEBAR)
Global pbar:TGadget=CreateProgBar(10,10,380,20,win)
Global pbar2:TGadget=CreateProgBar(10,35,380,20,win)
Global pblabel:TGadget=CreateLabel("Please Wait......",10,60,380,15,win)
Global inmapcolor:TPixmap
Global inmapalpha:TPixmap 
Global imgwidth:Int 
Global imgheight:Int 



Function pngbuilder(indir$,outdir$)
ShowGadget win

if indir="" 
			Local filter$=AppDir$+"renderer/bmp_temp"
			DebugLog filter
			Local indir$=RequestDir( "Choose a location containing 'xxxxx.bmp' and 'xxxxx_TMSK.bmp' files",filter$ )
			ChangeDir(AppDir$)	
End If

if outdir="" 
			Local filter$=AppDir$
			Local outdir$=RequestDir( "Choose a location to export files",filter$ )
			ChangeDir(AppDir$)	
End If

Local outputmap:TPixmap
outputmap=CreatePixmap(imgwidth,imgheight,PF_RGBA8888)

Local dir=ReadDir(indir)
Local processes=0
Local fnam$
	Repeat 
		 fnam$=NextFile(dir)
		If Instr(Lower(fnam$),".bmp")<>0 processes=processes+2
	Until fnam=""
CreateTimer(100)
if dir CloseDir dir

dir=ReadDir(indir)
Local page=0,evnt,proc

'MAINLOOP---------------------------------------------------------------------------------------------------------------------------------------------------------
Repeat

		 fnam$=NextFile(dir)
		DebugLog indir+" "+fnam
		if fnam="" Then 
					Notify "Sequence Complete, Pages="+page
					if dir CloseDir dir
					HideGadget win
					Return 
		EndIf
		
		If Instr(Lower(fnam$),".bmp")<>0 and Instr(Upper(fnam$),"_TMSK")=0	

		
		Select WaitEvent()
			Case EVENT_GADGETACTION						' interacted with gadget
	
			Case EVENT_WINDOWCLOSE						' close gadget
				Notify "Sequence Complete, Pages="+page
				if dir CloseDir dir
				HideGadget win
				
				Return 
				
		End Select
	  	
	  	
	  	Local filename$=StripDir(fnam$)
		DebugLog filename
		filename=StripExt(filename$)
		Local colorfile$=indir+"/"+filename+".bmp"
		Local alphafile$=indir+"/"+filename+"_TMSK"+".bmp"
		RedrawGadget(win)
		Flip()
		'if evnt=EVENT_WINDOWCLOSE Notify("Process terminated!",1)
		
		SetGadgetText(pblabel,"Loading Colormap......")
		proc=proc+1;UpdateProgBar(pbar,Float(proc)/Float(processes))
		inmapcolor:TPixmap=LoadPixmap(colorfile$)
		SetGadgetText(pblabel,"Loading Alphamap......")
		proc=proc+1;UpdateProgBar(pbar,Float(proc)/Float(processes))
		inmapalpha:TPixmap=LoadPixmap(alphafile$)
		
		if not inmapcolor or not inmapalpha  Then 
			SetGadgetText(pblabel,"Complete.")
			if not inmapcolor if page=0 Notify "Error - missing input files from "+colorfile,1
			HideGadget win
			Return
		End If ;
		
		imgwidth:Int=PixmapWidth(inmapcolor)
		imgheight:Int=PixmapHeight(inmapcolor)
		if not inmapalpha
			 Notify "Warning - missing alpha mask, expecting "+alphafile+"~nProgram will simply covert 24bit colormap to png",1
			 inmapalpha:TPixmap=CreatePixmap(imgwidth,imgheight,PF_RGB888)
		EndIf
		
		
		Local imgwidthchk:Int=PixmapWidth(inmapalpha)
		Local imgheightchk:Int=PixmapHeight(inmapalpha)
		Local problem
		if imgwidthchk<>imgwidth problem=1
		if imgheightchk<>imgheight problem=1
			
	    if problem  Notify "sizemissmatch for "+filename+".bmp and its mask",1; End
		
		outputmap:TPixmap=CreatePixmap(imgwidth,imgheight,PF_RGBA8888)
		
		SetGadgetText(pblabel,"Combining......")
		For Local b=0 to imgheight-1
			UpdateProgBar(pbar2,Float(b)/Float(imgheight-1))'/)
			
			For Local a=0 to imgwidth-1
				Local rgbacolor=ReadPixel(inmapcolor,a,b)
				Local rgbaalpha=ReadPixel(inmapalpha,a,b)
				Local Re=getRed(rgbacolor)
				Local Gr=getGreen(rgbacolor)
				Local Bl=getBlue(rgbacolor)
				Local Al=255-getRed(rgbaalpha)
				WritePixel (outputmap,a,b,getARGB(al,re,gr,bl))			
			Next
			
		Next
		Local pagestr$=page
		If Len(pagestr)=1 Then pagestr="000"+pagestr
		If Len(pagestr)=2 Then pagestr="00"+pagestr
		If Len(pagestr)=3 Then pagestr="0"+pagestr
		
		SetGadgetText(pblabel,"Saving "+outdir+"/"+filename+page+".png.....")
		SavePixmapPNG(outputmap, outdir+"/"+filename+page+".png")
		page=page+1
	EndIf
Forever
End Function




Mark Tiffany(Posted 2006) [#2]
How about EVENT_GADGETPAINT? (Possibly only on a canvas...)


Grisu(Posted 2006) [#3]
How about using a timer or eventhook?