EVENT_GADGETPAINT prevents update?

BlitzMax Forums/MaxGUI Module/EVENT_GADGETPAINT prevents update?

remz(Posted 2007) [#1]
Hi, I think that the event EVENT_GADGETPAINT used by Canvas prevents anything from being updated while it's in progress. This behavior is most probably only on Mac OS, because on WinXP I didn't had this 'bug' in my app.
Here's the code:
SuperStrict

Global MainWindow:TGadget = CreateWindow("Click and drag mouse to move slider", 100, 100, 400, 300)
Global MainCanvas:TGadget = CreateCanvas(0,0,300,200, MainWindow)
Global Slider:TGadget = CreateSlider(0,240,400,15, MainWindow, SLIDER_HORIZONTAL | SLIDER_SCROLLBAR)
SetSliderRange(slider, 50, 250)
Global global_slide_pos:Int = 0

AddHook EmitEventHook,MyHook

Repeat
	WaitEvent() 
	If EventID() = EVENT_APPTERMINATE Or EventID() = EVENT_WINDOWCLOSE Then End
Forever

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
	
	If Event.source=MainCanvas And Event.ID=EVENT_GADGETPAINT
		' Update here: it doesn't work!
		UpdateSlider() 
		Return Null
	EndIf

	If Event.ID=EVENT_MOUSEMOVE
		If(event.data = 1) Then
			global_slide_pos = event.x
			' Update here: it works!
			'UpdateSlider() 
		EndIf
	EndIf
	
	Return tData
End Function

Function UpdateSlider()
	SetSliderValue(slider, global_slide_pos)
	SetGadgetText(MainWindow, "Slider pos="+ global_slide_pos)
End Function

You'll see UpdateSlider at two differents place: in the example shown (inside GADGETPAINT), nothing happens if you click and drag the mouse around. However, if you resize the window, the slider and window title will get updated. Seems like the gadgets are 'dirty' but don't get drawn.

If you comment UpdateSlider and then uncommented the one in EVENT_MOUSEMOVE, then the program behaves correctly: the slider should move when you click and drag.
Can anyone confirm?


DavidDC(Posted 2007) [#2]
I'm wondering if you aren't missing a RedrawGadget(MainCanvas) in your MouseMove and Click event handling?

- David


SebHoll(Posted 2008) [#3]
This appears to be because Cocoa locks any drawing to the confines of your canvas until your return from your event - as such, although you may perform actions on other gadgets, they will not be redrawn at all (as they are outside the clipping region of the screen). Short of redrawing all other windows when returning from EVENT_GADGETPAINT, there isn't much MaxGUI can do about this as this is by Cocoa's design.

As such, it should probably be written in the docs that EVENT_GADGETPAINT should only be used to paint the concerned canvas and actions on other gadgets shouldn't be performed when repsonding to this event using hooks.