cocos2d/cocos2d-x — pull request #1108 by NatWeiss (2012-07-21 09:27:28+00:00)
Title: Adding Mac support!

Got Mac support to work with the latest branch of Cocos2d-X! :)

Resizing the Cocos2d-X Mac window works.

Full screen support works.

Audio works.

Touch input works.

Here's a video of it working:
http://www.youtube.com/watch?v=I5nqC3-GeLM

This pull request mainly features the cocos2dx/platform/mac and CocosDenshion/mac folders.

The cocos2dx/platform/mac folder started with the zip Walzer posted here:
http://cocos2d-x.org/boards/6/topics/10352

I referenced a bit of ImperialPenguin's code, a lot of Cocos2d iPhone 2.0's and got it all working with the latest idioms of Cocos2d-X 2.0. The most difficult part was realizing that CCDirectorMac is not necessary. After incorporating it's main features into EAGLView and CCEGLView, everything started working amazingly. CCWindow is from Cocos2d iPhone and helps the EAGLView setFullScreen function. Input works too, thanks to CCEventDispatcher and setting it in EAGLView's initWithFrame.

There's one function in CCImage that I couldn't get to compile so I commented it out. It's potImageData function. I'm not sure where it belongs in the Cocos2d-X 2.0 paradigm, but the example game that I tried out did not need it to function 100%.

Most of the files in CocosDenshion/mac are a copy of CocosDenshion/ios except for CDXMacOSXSupport which comes from Walzer's zip. Copying them into the CocosDenshion/mac folder allows a person to compile cleanly for Mac without the ios folder, much like how the cocos2dx/platform folder works today.

This pull request was a lot of effort, so I will leave it up to somebody else to create the HelloWorld, tests, and proj.mac folders.

--

Note that this is the second time I've submitted this pull request. This new request features a much improved CCFileUtils based on the platform/ios/CCFileUtils.m. It can detect high resolutions and load the appropriate -ipad graphics.

Also much improved is the mouse event handling in EAGLView. The previous pull request had a bug where the mouse up event was sometimes missed because it wasn't transmitting the correct id to Cocos2d-X's touch handler. This pull request uses the eventNumber as the id to accurately track the matching mouse up/dragged/down events.

Also, EAGLView's keyDown, keyUp, etc. methods which aren't actually doing anything call the super method, which effectively passes the event on to the next responder. In your typical Mac app, this will be the NSWindow. So you can catch keyUp and keyDown events in a custom NSWindow in your game's proj.mac folder.