New topic: Drag by the CENTER of a picture [SOLVED]
<http://forums.realsoftware.com/viewtopic.php?t=47597> Page 1 of 1 [ 8 posts ] Previous topic | Next topic Author Message DaveS Post subject: Drag by the CENTER of a picture [SOLVED]Posted: Sun Apr 14, 2013 7:58 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4753 Location: San Diego, CA Sounds simple... or so I thought. Here is the scenario I have a LISTBOX with 3 columns and N rows. Each cell has a picture in it. When the user clicks on a cell, I want to drag the picture (actually a FigureShape defined polygon)to a canvas.... BUT ... I want the mouse to be DEAD CENTER in the picture, regardless of where within the picture the user clicked.... The reason is when they DROP the picture.... the important X,Y coordinates are where the mouse was over the canvas when it was dropped in relation to the picture. That is... when dropped the CENTER of the picture needs to be the Canvas Mouse Coordinates. Here is my Listbox DRAGROW.... note I did not use the DRAGITEM argument from the DRAGROW event.... as there seems to be no way to nudge it.... so I opt'd from my own DragItem Mouse_X and Mouse_Y where stored during the MOUSEDOWN event Shp.DRAW draws the selected Polygon, centered in the GRAPHIC object I would have thought given a Picture that was W wide, and H tall that the cooresponding DragItem constructor would be MouseX-(w\2), MouseY-(h\2) But it doesn't seem to be.... Dim stencil_name As String Dim shape_name As String Dim x As Integer Dim p As picture Dim g As graphics Dim shp As classShape // x=InStr(current_key,"*") stencil_name=Left(current_key,x-1) shape_name=Mid(current_key,x+1) shp=New classShape(stencil_name,shape_name,0,0) shp.color_fill=&cffffff shp.width=shp.Width*zoom shp.Height=shp.Height*zoom shp.LineWidth=1 p=New picture(shp.Width,shp.Height,32) g=p.Graphics // "picture" is actually a 0,0 centered Polygon shp.Draw(g,g.width\2,g.height\2) g.ForeColor=&cff0000 g.drawrect 0,0,g.Width,g.height // Dim d As DragItem d=New DragItem(Self,mouse_x-g.width\2,mouse_y+g.height\2,g.Width,g.Height,p) d.text=current_key d.drag Return True Mouse Down Event looks like this Dim row As Integer Dim col As Integer ' Save X/Y for DragRow mouse_x=x mouse_y=y row=Me.RowFromXY(x,y) col=Me.ColumnFromXY(x,y) select_cell(row,col) ' this returns "CURRENT_KEY" used in DRAGROW _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Last edited by DaveS on Mon Apr 15, 2013 9:34 am, edited 1 time in total. Top kermit Post subject: Re: Drag by the CENTER of a picturePosted: Mon Apr 15, 2013 12:51 am Joined: Mon May 30, 2011 12:56 am Posts: 667 shp=New classShape(stencil_name,shape_name,0,0) shp.color_fill=&cffffff shp.width=shp.Width*zoom shp.Height=shp.Height*zoom .how big is the Shape when contracted in ClassShape? Is it perhaps centred on that initial size, rather than the size after these lines? Might you be better using shp.scale = zoom Top DaveS Post subject: Re: Drag by the CENTER of a picturePosted: Mon Apr 15, 2013 8:03 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4753 Location: San Diego, CA The Graphic being created is the correct size... Using SCALE is not an option, as the aspect ratio of the shape might be altered Everything is working as required, except my mouse cursor is NOT in the center of the Drag Rectangle _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top doofus Post subject: Re: Drag by the CENTER of a picturePosted: Mon Apr 15, 2013 8:55 am Joined: Thu Sep 10, 2009 2:50 am Posts: 400 Location: Santa Cruz, CA, USA DaveS wrote:I would have thought given a Picture that was W wide, and H tall that the cooresponding DragItem constructor would be MouseX-(w\2), MouseY-(h\2) But it doesn't seem to be.... :( Those mouse coordinates are old, the DragRow event doesn't start until the cursor has moved some number of pixels, so use System.MouseX/Y to get at what they really are. Also, you're passing in Self to new DragItem which is the containing window not the Listbox, that's offsetting more. Though using System.MouseXY it'll be easier to use Self. And return false at the end. Top DaveS Post subject: Re: Drag by the CENTER of a picturePosted: Mon Apr 15, 2013 9:06 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4753 Location: San Diego, CA Ok.. using System.MouseX/Y is "better" at least the cursor is always inside the shape when I drag it. However it seems to be centered on the X axis... but is 1/3 from the top (not 1/2) on the Y-axis If I change from "SELF" to "ME" (from WIndow to Listbox).... it gets even worse _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top DaveS Post subject: Re: Drag by the CENTER of a picture [SOLVED]Posted: Mon Apr 15, 2013 9:35 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4753 Location: San Diego, CA Moved all the code to MOUSEDOWN, since I was already creating my own DRAGITEM and everything now works precisely as I desire. Thanks _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top doofus Post subject: Re: Drag by the CENTER of a picture [SOLVED]Posted: Mon Apr 15, 2013 10:28 am Joined: Thu Sep 10, 2009 2:50 am Posts: 400 Location: Santa Cruz, CA, USA I mean like this, puts the cursor centered Function DragRow(drag As DragItem, row As Integer) As Boolean dim p As new Picture(80, 80, 32) p.Graphics.DrawOval(1, 1, 78, 78) dim realX As integer = System.MouseX - self.Left dim realY As integer = System.MouseY - self.Top dim d As new DragItem(self, realX - p.Width/2, realY - p.Height/2, p.Width, p.Height, p) d.Drag return false End Function Using DragRow allows for that fiddly little dragging to start the process. Top DaveS Post subject: Re: Drag by the CENTER of a picture [SOLVED]Posted: Mon Apr 15, 2013 10:38 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4753 Location: San Diego, CA Thank you... I have it working _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 8 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
