wxGLCanvas and mouse position and keyhit/down

BlitzMax Forums/Brucey's Modules/wxGLCanvas and mouse position and keyhit/down

plash(Posted 2008) [#1]
I'm rewriting the fry designer (see sig) in wx, using a wxGLCanvas for the graphics.

Since frygui uses the normal mousehit/down and mousex/y functions I decided to find a way to allow those to work instead of hacking it to use wxevents (I didn't want to modify brl.polledevents, although it would've been easy to do that way). The 'wx.mod\samples\graphics_tests\graphics_switch_test.bmx' sample had what I needed to get started, however keys aren't registering and the mouse position is off.

Any thoughts?

NOTE: I am using a wxGLCanvas instead of just wxglmax2d in a standard graphics window (like the graphic test sample), although the sample didn't seem to get keys either.

EDIT: Actually, MouseX() and MouseY() are returning the mouse position on the whole screen, instead of just the frame.


Brucey(Posted 2008) [#2]
Have you tried my example key handling code mentioned HERE ?

It should allow you to use a standard Max2D-style update method where you check for keys.


Brucey(Posted 2008) [#3]
Hmm... the mouse works fine in the graphics_switch_test on Mac... go figure :-p

(trying to remember where I actually used that key-handling code! - for an example)


Brucey(Posted 2008) [#4]
Okay... a cut/paste job from some working (on Mac at least) code :


Type MyCanvas Extends wxGLCanvas

	Field timer:wxTimer


	Method OnInit()
		SetBackgroundStyle(wxBG_STYLE_CUSTOM)
	
		timer = New wxTimer.Create(Self)

		EnablePolledInput(Self)

		ConnectAny(wxEVT_TIMER, OnTick)
		ConnectAny(wxEVT_KEY_DOWN, OnKeyDown)
		ConnectAny(wxEVT_KEY_UP, OnKeyUp)

		timer.Start(17)
	End Method

	Function OnTick(event:wxEvent)
		wxWindow(event.parent).Refresh()
	End Function
	
	Function OnKeyDown(event:wxEvent)
		Local evt:wxKeyEvent = wxKeyEvent(event)
		EmitEvent(CreateEvent( EVENT_KEYDOWN, event.parent, MapWxKeyCodeToBlitz(evt.GetKeyCode())))
		event.Skip()
	End Function

	Function OnKeyUp(event:wxEvent)
		Local evt:wxKeyEvent = wxKeyEvent(event)
		EmitEvent(CreateEvent( EVENT_KEYUP, event.parent, MapWxKeyCodeToBlitz(evt.GetKeyCode())))
		event.Skip()
	End Function

	Method OnPaint(event:wxPaintEvent)
		Render()
	End Method

	Method Render()

		SetGraphics CanvasGraphics2D( Self )
		
		If KeyDown(key_up) Then
			' ...
		End If

		Cls

			' ...

		Flip
	
	End Method
End Type




plash(Posted 2008) [#5]
The mouse is fine in the graphics_switch_test, but its using a standard graphics window instead of a wxGLCanvas.

I'll test the key code you linked to.


Brucey(Posted 2008) [#6]
but its using a standard graphics window

heh... so it is, by jove....


plash(Posted 2008) [#7]
Keys work now, I tried EnablePolledInput(Self) and it didn't register anything, changed it back to EnablePolledInput() (which is what I had the first time, from the sample) and the mousehits and keyhits were working again.. mouse position is still buggerd though.


Brucey(Posted 2008) [#8]
How's about this :




plash(Posted 2008) [#9]
Ahha! Thanks Brucey.

I'll sneak back in later for graphviz in wxWidgets ;)

EDIT: This should also work for the mouse wheel (untested):
			Case wxEVT_MOUSEWHEEL
				EmitEvent(CreateEvent(EVENT_MOUSEWHEEL, event.Parent, evt.GetWheelRotation()))



CASO(Posted 2008) [#10]
Thanks for wxMax Brucey!
This is some really handy code for converting pre-wxMax code!