View Full Version : Dragging + Selectors
ededed
2002.08.11, 10:42 AM
I was having some trouble with a game I am making, MASTERMIND.
I wanted to drag an NSView but I didnt know how to do it so I ended up stetting the cursor to a small colored circle.
I also wanted to use selectors but I am sort of stuck there too. I fixed the problem I had another way but badly.
There are 5 CircleView:NSView
And a GameView:NSView
The gameview has 5 outlets
red, green, blue, orange and pink
on init it sets all their colors and tooltips but It should set a selector so that when a CircleView gets dragged it should call a method with two parameters giving the NSEvent* and a NSColor.
It's going to be a free open source thing when its finished by the way. :D
furballphat
2002.08.11, 05:17 PM
Don't try to move views around, just make one big view to contain all your images abd do some custom dragging code.
What can't you do with selectors?
ededed
2002.08.14, 02:46 PM
Using selectors would not be an issue if you were using one big view for everything but I wanted to have 5 views that would let you drag a color out of them. You could drag the color onto the main view. I would need selectors from the main view to detect mouse dragged events so that you would see where you were going to drop the color before you did.
In the code just now when you drag a peg the cursor changes from the arrow to a small ball the color of the peg but I really want to be able to drag an Image and then have the NSDraggingPasteboard set to the correct color. This would mean that you could play from the color picker to my mastermind game.
Iceman
2002.08.16, 11:38 AM
I don't really understand what you're talking about. Maybe you should give a source code example if it's still not fixed. I'm not too sure of what you're talking about but you should probably try this game that comes with source code-Quartzeroids is a royalty free game which explains the subviews and loading images. I think it's on idev's source code page or you could search for it at versiontracker.com.
Hope this helps,
Iceman
ededed
2002.08.17, 10:41 AM
Quartzeroids is good fun but I know how to use NSViews and SubViews. The problem is I want to be able to have an NSImage that will be dragged around with the cursor.
Like when you drag and drop a file. I want to drag and drop a peg for a game like othelo, draughts or chess.
I got selectors working and I will put them in the source code when I GET DRAGGING WORKING.
ededed
2002.08.17, 04:32 PM
PLEASE SOMEONE HELLLLLLP MEEEEEEEEE. I have been stuck on this for longer than any thing else and its such an easy problem I just can do it... and only tried twice but PLEASE. :(
ededed
2002.08.22, 03:39 PM
Does anyone know how to drag and drop stuff?
Jeff Binder
2002.08.22, 06:59 PM
What exactly are you trying to accomplish? If you need to drag between windows or views, Cocoa's drag and drop is what you want, but it seems that you're better off doing it yourself. Once you have a custom view you can draw and handle events, you should be able to manage it.
Just keep an array of objects, and keep track of which item is being dragged, if any. So when you get a mouse down event, check if it hit any item, and if so, it becomes the dragged item. A mouse up event clears the dragged item (set it to -1 or something). If you get a mouse dragged event, and something is being dragged, change its position to the new mouse location. The items you have should be object, but not necessarily views.
This gives you more control, and likely will be faster than using views. Try it, and if you have trouble then post the code and I'll look at it.
ededed
2002.08.27, 04:12 PM
Thanks JeffBinder. I want to drag between windows and applications. Most people could code a drag and drop system but It would only work within the confines of the NSView.
I really really really want to drag have an NSImage snap the the cursor like when you drag a file or a color swatch or a piece of text. I can do everything with NSPasteboards and all that rubbish inbetween but I want the code for the mouseDown event
Sorry for being so angry but I just cannot do this myself and it is so ANNOYING.
Seriously though thanks for your idea but its no what I want.
Iceman
2002.08.27, 06:35 PM
Ok maybe this code will help: http://www.macdevcenter.com/pub/a/mac/2001/11/30/cocoa.html
It's an O'Reilly tutorial called scrach pad which teaches you how to use keydown and mousedown events. It's kind of basic but it may be just enough. Also check out the other tutorials that mike beam has done: http://macdevcenter.com/pub/ct/37 .
Hope this helps :)
Iceman
ededed
2002.08.29, 12:24 PM
NO MAYBE THAT CODE WONT HELP
I AM NOT STUPID I KNOW HOW TO DO MOST THINGS WITH COCOA, I DONT NEED A TUTORIAL ON MOUSE EVENTS OK!!!!!!!!!!!!!! THE ONLY THING I CANT DO IS GET A DRAG AND DROP SYSTEM. I DONT WANT TO MAKE MY OWN DND SYSTEM BECAUSE THEN EVERYTING WOULD BE CONFINED TO THE VIEW YOU IDIOT. I WANT TO DRAG AN IMAGE ABOUT. IS THAT TO HARD FOR ANYONE TO UNDERSTAND IF YOU CANT HELP DONT TRY. ALL I NEED TO FINISH THIS RUBBISH GAME IS TO GET DRAGGING AND DROPPING WORKING I DONT WANT ANYTHING AND I CANT GET ANYTHING FROM A BUNCH OF TUTORIALS ABOUT GREEN BLOBS AND "intellegent zooming action!!!!
IS EVERYONE STUPID OR WHAT?
:mad:
:eek: Sorry if I am a tad out of line saying this but... it seems to me that everyone is trying their best to help you out. So why the above post?
ededed
2002.08.29, 01:01 PM
You are not out of line that was me.
Sorry to everyone involved. BUT I HATE THIS!!!!!.
I would like to say I have everyting working except dragging I need not a SKETCH PAD. I just want to attach a NSImage to the NSCursor and everything else wil be NSOk. OK?
Sorry ICE MAN:
It's kind of basic but it may be just enough.
No..
aarku
2002.08.29, 04:48 PM
Found the solution:
http://www.cedrusgroup.bc.ca/tutorials/mountain.jpg
And a very in-depth tutorial (http://www.cedrusgroup.bc.ca/tutorials/anger2.html) to expand on it.
Good Luck!
-Jon
furballphat
2002.08.29, 05:59 PM
Is this what you're looking for? http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/DragandDrop/index.html
With that much desperation I'm surprised you didn't just look in the programing topics of project builder's help
And no, we're not stupid, just intellectually challenged.
Iceman
2002.08.29, 07:17 PM
Haha great tutorial aarku:D. Sorry I misunderstood what you wanted ededed.
Iceman
ededed
2002.08.30, 07:28 AM
intellectually challenged FurballPhat
Thats not funny I think furball's got a furball in his throught.
I did look at the wonking project builder help and it was totally useless to me OK!!!
If your so good SEND ME SOME EXAMPLES OKOKKOKOOKOKOK!!!!!!!!
GRRR R RR R R R R RRR!!!!!!!
:mad:
ededed
2002.08.30, 07:31 AM
WHY IS THIS SO HARD FOR YOUR PUNY MINDS TO UNDERSTAND I JUST WANT TO DRAG SOMTHING ABOUT. ROOOOAAAAAR
OneSadCookie
2002.08.30, 08:22 AM
Please go and "wonking" ask your question on the "wonking" Apple Cocoa list where the people who actually know about the subject hang out and stop "wonking" insulting everybody left right and center.
The people here are trying to "wonking" help you! You won't make any "wonking" friends by being a "wonker" about it.
-- One"Wonking"SadCookie,
Moderator
OneSadCookie
2002.08.30, 08:25 AM
If you want an answer, I suggest you read this (I assume you have already):
file:///Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/DragandDrop/index.html
and then ask a specific question -- what didn't you understand? What are you having trouble implementing?
ededed
2002.09.02, 10:55 AM
Thanks OneBadCookie, I have it working now and I will post the dragging code and game on my (rubbish but free) website later.
ededed
2002.09.02, 01:43 PM
http://www.geocities.com/ed72678954/index.html
Yes, I did it.
Feanor
2002.09.02, 06:04 PM
Hehe, well, they say it's better to be angry than to bottle it up. Nice roar, btw.
Also, nice sample code.
--FÎanor
codemattic
2002.09.03, 05:57 AM
thank you ededed for posting your code.
cool!
Codemattic
PS -
Does anyone else here feel that as you learn how to do new things in Cocoa - you feel you *must* use them. Its like when the Mac first came out and designers realized that they could use dozens of fonts at the same time - and so they did - even if it wasnt a good idea design-wise. My little cocoa apps are now filled with toolbars, floating palettes, spinners, progress bars, etc... Now Im sure soon I will add much dragging and dropping - even if it makes no gui sense for what Im doing. But it *is* fun.
...and look - I can drag a red circle to the textbox and it drops the text "Red" there - and if I drag the text "Red" to a drop zone it fills it with red. Very friggin slick indeed ededed!!
ededed
2002.09.05, 03:17 PM
lol
Yes, very true.
Sheets, Toolbars, Windows with no backing, drag'n'drop, Changing the dock icon in realtime, Controlling the cursor and changing the cursor to a custom image (16*16 only just now).
Wouldn't it be great to get a cursor size 64*64 or somthing...
I think it could be done (havent tried it yet) by creating a custom NSEvent and passing that to the drag NSImage method then you may be able to set that an image of any size could follow the mouse and appear to "be" the cursor.
Any idea's.
Try dragging into TextEdit and ProjectBuilder.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.