Refresh canvas while scrolling

BlitzMax Forums/MaxGUI Module/Refresh canvas while scrolling

Adam Novagen(Posted 2016) [#1]
So I'm still working on that little editor tool for myself. Right now, I have a canvas on a scrollpanel. Said canvas updates and redraws according to a 60FPS timer. However, whenever I scroll around, the canvas completely stops being drawn until I let go of the scrollbars, like so:



Is this just the nature of the beast for canvases in MaxGUI, or is there actually a way for me to redraw the canvas while I'm moving the scrollbars around?


Derron(Posted 2016) [#2]
Can't you call the (re)paint methods of the canvas?


bye
Ron


Kryzon(Posted 2016) [#3]
That's BlitzMax behaviour, it's accumulating mouse events until you release the mouse click.

The simplest way to repaint the canvas per each scrollbar move is to modify MaxGUI at this point:
https://github.com/blitz-research/blitzmax/blob/master/mod/maxgui.mod/win32maxguiex.mod/win32maxguiex.bmx#L3883

...to call a function that you specify:
		If (index <> _value) Then
			PostGuiEvent EVENT_GADGETACTION,index
			_value = index
			If _callback Then _callback() 'Added this. '_callback' must be added as 'Field _callback()' at the start of Type TWindowsSlider.
		EndIf


Then rebuild MaxGUI (you'll need MinGW) and use it like this:
myScrollBar=CreateSlider(10,10,16,100,window,SLIDER_VERTICAL)

TWindowsSlider( myScrollBar )._callback = bla

Function bla()
	Print "asldflasdf"
	'Obviously, repaint the canvas here.
End Function



Henri(Posted 2016) [#4]
Hi,

before modifying MaxGUI there is an example in Blitzmax folder for drawing canvas in a hook:



-Henri


Kryzon(Posted 2016) [#5]
That example doesn't use scrollbar events to redraw the canvas, it would be necessary to test with them to make sure that it still works for the problem at the top.
It uses a timer to redraw the canvas 100 times per second which should accommodate for any scrolling, I hope, but I still prefer that "callback" style of only redrawing it when it's necessary.

A more clean way would be to replace that '_callback' function pointer (in the example that I posted) with a hook ID, so that at that point in the MaxGUI code it uses the RunHooks function.
This means each scrollbar would have a hook ID that you can attach as many hooks as you want to. It is still just calling functions but at least you're using a more familiar way of doing that.


Adam Novagen(Posted 2016) [#6]
Actually, in the case of this little tool, constantly updating the canvas is fine since it's already supposed to be doing that 60 times a second anyway.

Thank you both for the help; I ended up frankencoding Henri's suggestion in. Normally I'd be appalled at such a hackjob but this program is really only for single-purpose personal use so all that matters is whether it works as desired. Implementing it was a pain, because I have no experience with hooks and only understand about 60% of BlitzMax OOP, so I barely understood how the code worked and it was mostly a case of "okay, let's comment this out, copy this here, stick my thumb in this bit and see what happens." Had a weird experience where Flip caused the program to freeze altogether, but setting sync to 0 instead of -1 took care of that so I've shrugged and moved on.


TAS(Posted 2016) [#7]
Actually any MaxGUI program that uses scroll bars should have an hook handler;

AddHook(EmitEventHook,MainHook)

Function MainHook:Object(iId,tData:Object,tContext:Object)
Local Event:TEvent=TEvent(tData)
Select Event.Source
........ check all slider gadgets
Return Null if handle
Return Event if not
end select
end function