WinBlitz3d Events Help

Blitz3D Forums/Blitz3D Programming/WinBlitz3d Events Help

Ricky Smith(Posted 2006) [#1]
Here's a short simplified example of a problem I'm having.
What I want to achieve is a trackbar and a spinner that are synchronised and that can also be manipulated via code.
In the following example If you move the trackbar the spinner updates and vice versa - you can click the Start button and the text will change to Stop - it works - but when you enable the updates to either the trackbar or the spinner via code the events generated by this prevent the button event or anything else from ever getting "heard".
If you use WB3D_FlushEvents() then you flush everything including the button event so that doesn't help.
Is what I am trying to do possible? If so how do I filter out the events generated by code rather than user manipulation ?
Any help on this would be greatly appreciated.

Include "../../../WB3DStyles.bb"

; setup gfx mode.
Graphics3D 640,480,16,2
Global switch=0
Global updatespinner=0
Global updatetrackbar=0

; install winblitz3d.
Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,300,200)
WB3D_SetQuitMessage "WinBlitz3D 3D/GUI","Sure To Quit" 
;WB3D_HideGadget RuntimeWindow_hWnd

; create winapi window, setting its title, and position on screen. use default style creation.
example_window = WB3D_CreateWindow("WB3D_CreateWindow Example",200,100,450,275,0,0)
trackbar = WB3D_CreateTrackBar%(10, 24, 200, 30,example_window,0,TBS_AUTOTICKS Or TBS_TOP Or WS_CHILD)
WB3D_SetTrackBarRange (trackbar,0,100)
WB3D_SetTrackBarPos (trackbar,0)
button=WB3D_CreateButton%("Start",10, 60, 60, 20,example_window,0)
checkspinner=WB3D_CreateCheckButton ("Update Spinner",10, 140, 160, 20,example_window,0)
checktrackbar=WB3D_CreateCheckButton ("Update Trackbar",10, 160, 160, 20,example_window,0)

thislabel = WB3D_CreateEditField("",10,100,30,20,example_window,0,0)
spinner = WB3D_CreateSpinner(40, 100,50,20,example_window,0,0)
WB3D_SetSpinnerRange (spinner,0,100)
WB3D_SetSpinnerPos (spinner,0)
; cleanup any old creation events, its better to do this before we enter the main
; event loop, when some gadgets are created they generate events.
WB3D_FlushEvents 

; setup out quit flag, and loop until the flag is set.
QUIT = 0
While Not QUIT = 1
	
	; generate an internal blitz event
	Flip
	Cls
	Text 10,10,selected
	; get an event of the event queue.
	event = WB3D_WaitEvent()
	Select event
		
		
		Case WB3D_EVENT_GADGET
			selected = WB3D_EventSource()
			
			Select selected
				Case button
					switch=Not switch
					If switch 
						WB3D_SetGadgetText(button,"Stop")
					Else
						WB3D_SetGadgetText(button,"Start")
					End If

				Case trackbar
					 WB3D_SetSpinnerPos(spinner,WB3D_GetTrackBarPos(trackbar))
				Case spinner
					 WB3D_SetTrackBarPos(trackbar,WB3D_GetSpinnerPos(spinner))
				Case checkspinner
					updatespinner= Not updatespinner
				Case checktrackbar
					updatetrackbar= Not updatetrackbar
				
				
			
			End Select


		Case WB3D_EVENT_KEYPRESS
		
			; wb_eventdata holds the key code that was pressed.
			keypressed = WB3D_EventData()
			Select keypressed
				
				Case WB3D_KEY_ESCAPE	
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
				
		Case WB3D_EVENT_WINDOW_CLOSE
		
			; wb3d_eventsource hold the handle to the window that close button was selected
			window = WB3D_EventSource()
			Select window
			
				Case example_window
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
	End Select

	If switch
		count=count+1
			If count>100 count=0
				If updatetrackbar WB3D_SetTrackBarPos (trackbar,count)
				If updatespinner WB3D_SetSpinnerPos (spinner,count)
				;WB3D_FlushEvents();This will delete all events nothing left to capture !!!
			End If	
Wend

; use notify using external winapi constants. 
WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK
WB3D_EndGUI()
EndGraphics
End



Kev(Posted 2006) [#2]
Hi smiff


If so how do I filter out the events generated by code rather than user manipulation



this is not possable under winblitz3d at the moment.

im unsure on what your trying to do? is it this. add the code below before the while-wend loop.


WB3D_SetButtonState checktrackbar,True
updatetrackbar= Not updatetrackbar
switch=Not switch
WB3D_SetGadgetText(button,"Start")



if this is not what your after can you explain a little more. maybe i drunk a little to much beer and its as clear as day?

kev


Ricky Smith(Posted 2006) [#3]
Those checkboxes and variables are just to switch conditions so you could see the events working and then not - they are irrelevant to the issue.
Here's a more basic example - Once you hit Start the button no longer responds :
Include "../../../WB3DStyles.bb"

; setup gfx mode.
Graphics3D 640,480,16,2
Global switch=0

; install winblitz3d.
Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,300,200)
WB3D_SetQuitMessage "WinBlitz3D 3D/GUI","Sure To Quit" 
;WB3D_HideGadget RuntimeWindow_hWnd

; create winapi window, setting its title, and position on screen. use default style creation.
example_window = WB3D_CreateWindow("WB3D_CreateWindow Example",200,100,450,275,0,0)
trackbar = WB3D_CreateTrackBar%(10, 24, 200, 30,example_window,0,TBS_AUTOTICKS Or TBS_TOP Or WS_CHILD)
WB3D_SetTrackBarRange (trackbar,0,100)
WB3D_SetTrackBarPos (trackbar,0)
button=WB3D_CreateButton%("Start",10, 60, 60, 20,example_window,0)

thislabel = WB3D_CreateEditField("",10,100,30,20,example_window,0,0)
spinner = WB3D_CreateSpinner(40, 100,50,20,example_window,0,0)
WB3D_SetSpinnerRange (spinner,0,100)
WB3D_SetSpinnerPos (spinner,0)
; cleanup any old creation events, its better to do this before we enter the main
; event loop, when some gadgets are created they generate events.
WB3D_FlushEvents 

; setup out quit flag, and loop until the flag is set.
QUIT = 0
While Not QUIT = 1
	
	; generate an internal blitz event
	Flip
	Cls
	Text 10,10,selected
	; get an event of the event queue.
	event = WB3D_WaitEvent()
	Select event
		
		
		Case WB3D_EVENT_GADGET
			selected = WB3D_EventSource()
			
			Select selected
				Case button
					switch=Not switch
					If switch 
						WB3D_SetGadgetText(button,"Stop")
					Else
						WB3D_SetGadgetText(button,"Start")
					End If

				Case trackbar
					 WB3D_SetSpinnerPos(spinner,WB3D_GetTrackBarPos(trackbar))
				Case spinner
					 WB3D_SetTrackBarPos(trackbar,WB3D_GetSpinnerPos(spinner))
				
				
				
			
			End Select


		Case WB3D_EVENT_KEYPRESS
		
			; wb_eventdata holds the key code that was pressed.
			keypressed = WB3D_EventData()
			Select keypressed
				
				Case WB3D_KEY_ESCAPE	
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
				
		Case WB3D_EVENT_WINDOW_CLOSE
		
			; wb3d_eventsource hold the handle to the window that close button was selected
			window = WB3D_EventSource()
			Select window
			
				Case example_window
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
	End Select

	If switch
		count=count+1
			If count>100 count=0
				WB3D_SetTrackBarPos (trackbar,count)
				WB3D_SetSpinnerPos (spinner,count)
				;WB3D_FlushEvents();This will delete all events nothing left to capture !!!
			End If	
Wend

; use notify using external winapi constants. 
WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK
WB3D_EndGUI()
EndGraphics
End

Basically what I am trying to do is have a trackbar and a spinner synchronised - when manipulated by the user. I also want to be able to manipulate them via code in the main program loop so flushing events is not an option because this flushes everything.
In the example the trackbar and spinner are synched - if you move one the other updates. If you try and manipulate the gadgets via code ,however , the resulting flood of events prevents any other event from beiing dealt with.
If there is no way to manipulate the gadgets via code without generating a lot of events that cannot be filtered or flushed out then I will have to rethink.


Pepsi(Posted 2006) [#4]
That second example worked for me for a while until I decided to continuely click on the spinner button a whole bunch of times. After I did that, the stop button would not respond anymore for me.

I feel something is loosing focus.

The code I put up in the "winblitz3d: limit min sizing help" thread has a wierd behaviour when I try to access the window menu with the alt-key combinations. Sometimes the alt-key combo will not respond quick enough for the menu to be highlighted. If I loose focus of my entire application and then come back to it, I am unable to even access the window menu with the alt key alone. But, I did notice if I press a button, Im able to access the window's menu again with the alt-key combos.

hrmmmm... focus...


Ricky Smith(Posted 2006) [#5]
Yes "sometimes" I can get it working when just updating the trackbar but never when updating the spinner. There's something not quite right about the way events are handled.
It would be great if code-generated changes to the gadgets did not generate events at all like other gui libs.


Kev(Posted 2006) [#6]

It would be great if code-generated changes to the gadgets did not generate events at all like other gui libs.



how would this function? i cant quite figure a way to easy add this. any ideas?

kev


Kev(Posted 2006) [#7]
Hi Smiff.

Ive added WB3D_GenerateEvents(state) to WinBlitz3D, this enables you to control when winblitz3d will generate events.

using WB3D_GenerateEvents() seems to correct the problem here.

	If switch
		count=count+1
			If count>100 count=0
				WB3D_GenerateEvents False
				WB3D_SetTrackBarPos (trackbar,count)
				WB3D_SetSpinnerPos (spinner,count)
				WB3D_GenerateEvents True
				;WB3D_FlushEvents();This will delete all events nothing left to capture !!!
			End If	



the experimental update can be downloaded from here.

http://www.winblitz3d.co.uk/WinBlitz3D_V1.1_Experimental.zip

kev


Ricky Smith(Posted 2006) [#8]
Thanks Kev - that's excellent news- Looks like it will do the job nicely- my PC just died last night - it had been suffering for quite a while now but finally gave up the fight - hopefully be back up & running with a new system asap and I'll give it a go !!


Pepsi(Posted 2006) [#9]
Hiya, I tried it out and it worked smoothly for me. Seems to work!


John Blackledge(Posted 2006) [#10]
Kev - on the ball as usual, and fixed within a day. Well done!


Ricky Smith(Posted 2006) [#11]
Just tried it but it still doesn't work on my system - can't understand it. The stop button still refuses to respond even with wrapping the setgadget statements with the new command. I think I need to take a break !


Kev(Posted 2006) [#12]
Smiff, whats your system spec? i recall danny having some problems on a lower spec pc. can you provide the full code causing the problem, if this is possable email it to me.

can you also try using WB3D_StartEvents and WB3D_StopEvents, other than this i could add a temp command to see how many items are on the event queue.

ive a feeling its not the event queue, but possably some calculation you could possably be doing while updating the spinner and trackbar thats causing missed events? could this be possable?


kev


Ricky Smith(Posted 2006) [#13]
Double post


Ricky Smith(Posted 2006) [#14]
Kev - System spec as follows:
AMD Athlon 2600+(1.92Ghz) 1Gig DDR, WinXP Home SP2
Nvidia 6200 256mb.
I also thought it must be something else causing the problem until I tried it in the test code.
The code is exactly the same as the last simplified example with the WB3D_GenerateEvents added :

If this works for you then perhaps the problem is system related ?!?
I have tries the start/stop events - I will try again using both commands to see if that helps.
Thanks once again for your help with this = a temp command to see the number of events in the queue would be very helpful - might give some idea of what is happening.


Kev(Posted 2006) [#15]
Hi Smiff

download www.winblitz3d.co.uk/WinBlitz3D_V1.1_Experimental.zip

ive added WB3D_QueueSize() this will return the total number of events in the queue.

using the example below i see '1' event on the queue, only when moving the trackbar with the mouse does this increase.

please try and report back your findings, we will try and get to the bottom of this problem.

Include "WB3DStyles.bb"

; setup gfx mode.
Graphics3D 640,480,16,2
Global switch=0

; install winblitz3d.
Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,300,200)
WB3D_SetQuitMessage "WinBlitz3D 3D/GUI","Sure To Quit" 
;WB3D_HideGadget RuntimeWindow_hWnd

; create winapi window, setting its title, and position on screen. use default style creation.
example_window = WB3D_CreateWindow("WB3D_CreateWindow Example",200,100,450,275,0,0)
trackbar = WB3D_CreateTrackBar%(10, 24, 200, 30,example_window,0,TBS_AUTOTICKS Or TBS_TOP Or WS_CHILD Or WS_VISABLE)
WB3D_SetTrackBarRange (trackbar,0,100)
WB3D_SetTrackBarPos (trackbar,0)
button=WB3D_CreateButton%("Start",10, 60, 60, 20,example_window,0)

thislabel = WB3D_CreateEditField("",10,100,30,20,example_window,0,0)
spinner = WB3D_CreateSpinner(40, 100,50,20,example_window,0,0)
WB3D_SetSpinnerRange (spinner,0,100)
WB3D_SetSpinnerPos (spinner,0)
; cleanup any old creation events, its better to do this before we enter the main
; event loop, when some gadgets are created they generate events.
WB3D_FlushEvents 

; setup out quit flag, and loop until the flag is set.
QUIT = 0
While Not QUIT = 1
	
	; generate an internal blitz event
	Flip
	Cls
	Text 10,10,selected
	Text 10,40,WB3D_QueueSize()
	
	; get an event of the event queue.
	event = WB3D_WaitEvent()
	Select event
		
		
		Case WB3D_EVENT_GADGET
			selected = WB3D_EventSource()
			WB3D_GenerateEvents False
			Select selected
				Case button
					switch=Not switch
					If switch 
						WB3D_SetGadgetText(button,"Stop")
					Else
						WB3D_SetGadgetText(button,"Start")
					End If

				Case trackbar
					 WB3D_SetSpinnerPos(spinner,WB3D_GetTrackBarPos(trackbar))
				Case spinner
					 WB3D_SetTrackBarPos(trackbar,WB3D_GetSpinnerPos(spinner))
				
				
				
			
			End Select
			WB3D_GenerateEvents True

		Case WB3D_EVENT_KEYPRESS
		
			; wb_eventdata holds the key code that was pressed.
			keypressed = WB3D_EventData()
			Select keypressed
				
				Case WB3D_KEY_ESCAPE	
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
				
		Case WB3D_EVENT_WINDOW_CLOSE
		
			; wb3d_eventsource hold the handle to the window that close button was selected
			window = WB3D_EventSource()
			Select window
			
				Case example_window
					
					; set the flag to leave the loop.
					QUIT = 1
					
			End Select
	End Select
	
	If switch
		count=count+1
			If count>100 count=0
				WB3D_GenerateEvents False
				WB3D_SetTrackBarPos (trackbar,count)
				WB3D_SetSpinnerPos (spinner,count)
				WB3D_GenerateEvents True
			End If	

	

Wend

; use notify using external winapi constants. 
WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK
WB3D_EndGUI()
EndGraphics
End


kev


Ricky Smith(Posted 2006) [#16]
OK have run a few tests - the trackbar and spinner events are now stopped by the WB3D_GenerateEvents true/false function. That works nicely, however, the button events still get queued up - its as if the WB3D_WaitEvent() command is timing out when you're manipulating the gadgets by code in this fashion.

Here's a short clip to demonstrate - (wmv) 1Mb

http://pacemakeranimation.net/tutorials/wb3d.wmv


Ricky Smith(Posted 2006) [#17]
I have found the problem !! I removed the blitzcc.exe.manifest file from my bin directory and just using the standard version of the Common Controls it works fine !
I could kick myself up the backside !!
The XP version of the Common Controls has a lot more events that WB3d sees - the gotfocus(), mouseover(), lostfocus() events all seem to be captured unlike with the Standard version.
Probably in need of some kind of event hook functionality to get it working properly.
Damnation ! - I was quite liking the XP look.


Kev(Posted 2006) [#18]
Hi Smiff

I will setup blitzcc.exe with a manifest and see if its possable to handle these extra events.

BTW does your example work when setting a manifest to your compiled .exe? i wonder if this is a problem with manifest's or with the way blitzcc.exe and the use of manifests.

*EDIT fixed the event system when moving the trackbar, i will upload the fixed version later for you to try.

kev


Ricky Smith(Posted 2006) [#19]
Kev the example behaves the same when setting the manifest to a compiled exe as when setting it to the blitzcc.exe.


Kev(Posted 2006) [#20]
HI Smiff

in my haste i edited the above post only to find my last additions broke the event system on other gadgets. although i can confirm that when using xp manifest events become strange. the manifest does indeed generate WM_MOUSEHOVER and WM_MOUSELEAVE events. im currently looking into why the event system is processing multipul events that should not be processed.

can you add WB3D_FlushEvents to the trackbar case statement, here this stops events going above 2.


				Case trackbar
					 WB3D_FlushEvents
					 WB3D_SetSpinnerPos(spinner,WB3D_GetTrackBarPos(trackbar))



kev


Ricky Smith(Posted 2007) [#21]
Any news on the events with XP manifest issue ?


Kev(Posted 2007) [#22]
Hi Ricky

Ive still to find a fix for the manifest issue, the strange thing is most all the gadgets work correctly when a manifest is used.

kev