Rubber banding in BlitzMax
BlitzMax Forums/BlitzMax Beginners Area/Rubber banding in BlitzMax
| ||
How do you do clean, smooth rubber banding in BlitzMax (in a MaxGui window on a canvas that is) - perhaps something similar to what happens when you drag the mouse on the Mac desktop ? I wrote many things in BlitzPlus for years and have downloaded the trial version of BlitzMax because I now have a Mac. So far it seems excellent but this one thing I cannot yet get to work decently after a few days trying. What I want is something equivalent to the following in BlitzPlus, which works fine. I used arrays of pixels then to redraw areas of the canvas but I'm sure a very simple standard method of events and flips must exist in BlitzMax to achieve such a common effect.Function zoomout() .l4 WaitEvent() If EventID()=$201 Then mx1=MouseX(workarea1) my1=MouseY(workarea1) Color 255,255,255 For i=0 To 800 pix(i)=ReadPixel(i,my1) Next For i=0 To 600 piy(i)=ReadPixel(mx1,i) Next While MouseDown(1) mx2=MouseX(workarea1) my2=MouseY(workarea1) For i=0 To 800 pixu(i)=ReadPixel(i,my2) Next For i=0 To 600 piyu(i)=ReadPixel(mx2,i) Next Line mx1,my1,mx2,my1 Line mx1,my1,mx1,my2 Line mx1,my2,mx2,my2 Line mx2,my1,mx2,my2 FlipCanvas workarea1 For i=0 To 800 WritePixel i,my1,pix(i) Next For i=0 To 600 WritePixel mx1,i,piy(i) Next For i=0 To 800 WritePixel i,my2,pixu(i) Next For i=0 To 600 WritePixel mx2,i,piyu(i) Next Wend Line mx1,my1,mx2,my1 Line mx1,my1,mx1,my2 Line mx1,my2,mx2,my2 Line mx2,my1,mx2,my2 If mx1=mx2 Or my1=my2 Then Return EndIf If mx1>mx2 Then mxswap=mx1 mx1=mx2 mx2=mxswap EndIf dxiu=mx2 dxil=mx1 If my1>my2 Then myswap=my1 my1=my2 my2=myswap EndIf 'Do some calculations with selected area. dyiu=my2 dyil=my1 dxiuf#=Float(dxiu) dxilf#=Float(dxil) dyilf#=Float(dyil) dyiuf#=Float(dyiu) newdxl#=dxl#-dxilf#*dxdiff#/800 newdxu#=dxu#+dxdiff#-dxiuf#*dxdiff#/800 newdyu#=dyu#+dyilf#*dydiff#/600 newdyl#=dyl#-dydiff+dyiuf#*dydiff#/600 dxl#=newdxl# dxu#=newdxu# dyl#=newdyl# dyu#=newdyu# dxdiff#=dxu#-dxl# dydiff#=dyu#-dyl# cx#=0.5*(dxl#+dxu#) cy#=0.5*(dyl#+dyu#) draw() Else Goto l4 EndIf End Function |
| ||
what's rubber banding? Cheers Charlie |
| ||
I think he means like when you hold down the mouse on your desktop (windows) and drag a rectangle around icons. I know how to do it, but not with MaxGui since I don't own it. |
| ||
do you want to grap only things on the canvas background picture , or do you plan also to send messages to the other gadgets to tell them that they are "grapped" what is the target og the rubber band? what will you select? |
| ||
I do not need to grab anything, just select the four corner points for calculations. A picture is drawn on the canvas and the functions which use the rubber banding select new coordinates for redrawing the picture - zoom in, zoom out, move centre and so on. Of course the drawn canvas has to be preserved during the process, which should be smooth and clear. Once the mouse button is raised it does not matter whether or not the box or rectangle remains as it will be drawn over anyway. I've tried many ways but there is something simple I haven't understood which works differently in BlitzMax from in BlitzPlus. |
| ||
why not simply draw the picture on the canvas and on it the rubber band every time the mouse has been moved? sorry i have no maxgui here, so i wrote it in blitz3d, but the way sould be the same on a canvas Graphics 800,600 SeedRnd MilliSecs() Image=CreateImage(800,600) For i=0 To 1000 SetColor Rand(155),Rand(155),Rand(155) DrawRect Rand(0,800),Rand(0,600),Rand(0,60),Rand(0,60) Next GrabImage image,0,0 SetColor 255,255,255 Global RubberX%,RubberY% RubberX=-1 Repeat Cls DrawImage image,0,0 If MouseDown(1) Then If RubberX=-1 Then RubberX=MouseX() RubberY=MouseY() Else DrawNotFilledRect RubberX,RubberY,MouseX(),MouseY() EndIf Else RubberX=-1 EndIf Flip Until KeyHit(Key_Escape) Function DrawNotFilledRect(X1%, Y1%, X2%, Y2%) DrawLine x1,y1,x1,y2 DrawLine x2,y1,x2,y2 DrawLine x1,y1,x2,y1 DrawLine x1,y2,x2,y2 End Function |
| ||
Thanks very much for that. My problem therefore lies, not in the method, but in lack of understanding about the exact timing and effect of the various Event commands involving the mouse in MaxGui. I'll spend a few hours writing little programs printing event data until I work out what they all do. Thanks again for your time. |
| ||
Okay, I've sorted it all out now. As well as failing to understand event checking I had not set the blend to solid. Owing to the nature of my background this was producing a mess of random lines. As is often the case, what we assume is one mistake is actually several. Thanks to all who answered. |