Mouse positioning a canvas in real-time?

BlitzMax Forums/MaxGUI Module/Mouse positioning a canvas in real-time?

Richard Betson(Posted 2010) [#1]
I am trying to position a canvas using EventX (mouse) in real-time with no luck. If I have to use a 'hook' I could use some help on how to do this. Here is my code example:

Import maxgui.Drivers

Global win:Tgadget=CreateWindow("test",100,100,400,400,Null,WINDOW_TITLEBAR|WINDOW_TOOL)
Global canv:Tgadget=CreateCanvas(190,0,20,200,win)
Global label:tgadget=CreateLabel("",20,222,40,200,win)
Global mdown
Global winx=190
CreateTimer(60)

While Not KeyHit(KEY_ESCAPE)
	WaitEvent()
	
	Select EventSource()
		Case canv
			SetGraphics (CanvasGraphics(canv)) 		
			Cls
			Flip

	End Select	

	Select EventID()
		Case EVENT_MOUSEENTER
			SetPointer( POINTER_SIZEWE )
		Case EVENT_MOUSELEAVE
			SetPointer( POINTER_DEFAULT )
		Case EVENT_MOUSEDOWN
			mdown=True
		Case EVENT_MOUSEUP
			mdown=False
			'winx=winx+x
			'SetGadgetShape(canv,winx,0,20,200)
		Case EVENT_TIMERTICK
			x=EventX()
			If mdown=True
				If x<0 Or x>0 Then winx=winx+x
				SetGadgetText(label,winx)
				SetGadgetShape(canv,winx,0,20,200)
				RedrawGadget(canv)
				RedrawGadget(label)
			EndIf
		Case EVENT_GADGETPAINT 

		Case EVENT_WINDOWCLOSE
			End
	End Select

Wend


Basically what I am trying to do here is click on the canvas and drag it left or right.

Ideas?

Thanks

Last edited 2010


Zeke(Posted 2010) [#2]
Import maxgui.Drivers

Global win:Tgadget=CreateWindow("test",100,100,400,400,Null,WINDOW_TITLEBAR|WINDOW_TOOL)
Global canv:Tgadget=CreateCanvas(190,0,20,200,win)
Global label:tgadget=CreateLabel("",20,222,40,200,win)
Global mdown
Global winx=190,x
CreateTimer(60)

While Not KeyHit(KEY_ESCAPE)
	WaitEvent()
	

	Select EventID()
		Case EVENT_MOUSEENTER
			SetPointer( POINTER_SIZEWE )
		Case EVENT_MOUSELEAVE
			SetPointer( POINTER_DEFAULT )
		Case EVENT_MOUSEDOWN
			mdown=True
		Case EVENT_MOUSEUP
			mdown=False
			'winx=winx+x
			'SetGadgetShape(canv,winx,0,20,200)
		Case event_MOUSEMOVE
			x = EventX()
			
		Case EVENT_TIMERTICK
			'x=EventX()
			If mdown=True
				If x < 0 Or x > 0 Then winx = winx + x
				SetGadgetText(label,winx)
				SetGadgetShape(canv,winx,0,20,200)
				RedrawGadget(canv)
				RedrawGadget(label)
			EndIf
		Case EVENT_GADGETPAINT 
			Select EventSource()
				Case canv
					SetGraphics (CanvasGraphics(canv)) 		
					Cls
					Flip
		
			End Select	
		Case EVENT_WINDOWCLOSE
			End
	End Select

Wend



Richard Betson(Posted 2010) [#3]
Very cool Zeke. Thanks, but. . .

@Everyone
The reason I asked about this is I have setup my own splitter. Maxgui does not support horizontal splitters (as far as I know) so I wrote my own. I am having a very weird problem when splitting two tabbers. They will move wildly left and right and I thought I had coded it wrong so I posted the above trying to figure out what was wrong.

This code example shows this wild behavior. I can not figure out why this does this. This code should work fine. It did at one time in MaxGUI.

Try this out and see what happens. Just click on the black canvas (the splitter) and move it left and right. As you do it will start wildly moving left and right. The more you do it the wilder it gets.

Import maxgui.Drivers

Global win:Tgadget=CreateWindow("test",0,0,DesktopWidth(),DesktopHeight(),Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_STATUS)
Global canv:Tgadget=CreateCanvas(190,0,20,ClientHeight(win),win)
'Global label:tgadget=CreateLabel("",20,222,40,200,win)
Global tabber:Tgadget=CreateTabber(0,0,189,ClientHeight(win),win)
Global tabber_2:Tgadget=CreateTabber(210,0,ClientWidth(win)-189,ClientHeight(win),win)
Global texta:Tgadget=CreateTextArea(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
Global texta_2:Tgadget=CreateTextArea(0,0,ClientWidth(tabber_2),ClientHeight(tabber_2),tabber_2)

SetGadgetLayout tabber,1,1,1,1
SetGadgetLayout tabber_2,0,1,1,1
SetGadgetLayout texta,1,1,1,1
SetGadgetLayout texta_2,1,1,1,0

Global mdown
Global winx=190,x
CreateTimer(60)
For i=0 To 10000
i2=i2+1
If i2=64
	a$=a$+Chr(13)
	a$=a$+i
	i2=0
Else
a$=a$+i
EndIf
Next

SetGadgetText(texta,a)
SetGadgetText(texta_2,a)

While Not KeyHit(KEY_ESCAPE)
	WaitEvent()
	

	Select EventID()
		Case EVENT_MOUSEENTER
			SetPointer( POINTER_SIZEWE )
		Case EVENT_MOUSELEAVE
			SetPointer( POINTER_DEFAULT )
		Case EVENT_MOUSEDOWN
			mdown=True
		Case EVENT_MOUSEUP
			mdown=False
			'winx=winx+x
			'SetGadgetShape(canv,winx,0,20,200)
		Case event_MOUSEMOVE
			x = EventX()
			
		Case EVENT_TIMERTICK
			If mdown=True
				If x < 0 Or x > 0 Then winx = GadgetWidth(tabber) + x
				SetGadgetShape(tabber,0,0,winx,ClientHeight(win))
				SetGadgetShape(tabber_2,winx,0,ClientWidth(win)-winx,ClientHeight(win))
				SetGadgetShape(canv,winx,0,20,ClientHeight(win))
				RedrawGadget(canv)

			EndIf
		Case EVENT_GADGETPAINT 
			Select EventSource()
				Case canv
					SetGraphics (CanvasGraphics(canv)) 		
					Cls
					Flip
		
			End Select	
		Case EVENT_WINDOWCLOSE
			End
	End Select

Wend


I have tried most everything I can think of. Help. :)

Thanks!

Last edited 2010


Richard Betson(Posted 2010) [#4]
double post..bla:/

Last edited 2010


Zeke(Posted 2010) [#5]
you can use horizontal splitters. CreateSplitter(x,y,w,h,parent,SPLIT_HORIZONTAL,handle_size)

also you can change splitter from vertical to horizontal using SetSplitterOrientation() function.


Richard Betson(Posted 2010) [#6]
Ok cool but I would still like to figure out above I have other uses for it.:) Looks to me like a bug. But not sure.

Last edited 2010


jsp(Posted 2010) [#7]
Here you go.
I have edit your code and put comments where I changed it.
In general I don't like that design (sorry:).
I would recommend to use panels wherever possible, only when you need to draw something a canvas is needed.





Richard Betson(Posted 2010) [#8]
@jsp

Thank you very much. I really appreciated the comments within the code, most excellent. Yes I should have used panels.

Thanks to you and Zeke. I'll email you and Zeke that case of beer;)