织梦CMS - 轻松建站从此开始!

罗索实验室

在MAC平台上 使用SDL 把SDL窗口加入子窗口中

jackyhwei 发布于 2010-03-03 22:38 点击:次 
The Xcode templates are for Xcode 2.1 and above. If you are running an earlier version of Xcode, install the Project Builder templates.
TAG:

Setting Up SDL in Xcode

The Xcode templates are for Xcode 2.1 and above. If you are running an earlier version of Xcode, install the Project Builder templates.

 
怎么使用Xcode templates

/Library/Application Support/Developer/3.0/Xcode /Library/Application Support/Developer/Shared/Xcode
没有这个目录,xcode 3.1怎么办? 把TemplatesForXcode 复制到下面的 目录中:
/Developer/Library/XCode/Project Templates/Application/

复制完成后,XCODE 新建工程,TemplatesForXcode出现在NEW PROJECT对话框中,其中有四个模板:

- SDL Application(全屏程序)
This is the barebones, most basic version. There is no 
customized .Nib file. While still utilizing Cocoa under 
the hood, this version may be best suited for fullscreen 
applications.

 
- SDL Cocoa Application(带菜单)
This demonstrates the integration of using native 
Cocoa Menus with an SDL Application. For applications
designed to run in Windowed mode, Mac users may appreciate 
having access to standard menus for things
like Preferences and Quiting (among other things).
 
- SDL Custom Cocoa Application(使用自定义窗体)
This application demonstrates the integration of SDL with 
native Cocoa widgets. This shows how
you can get native Cocoa widgets like buttons, sliders, 
etc. to interact/integrate with your SDL application.
 
- SDL OpenGL Application
This reuses the same SDLMain from the "SDL Application" 
temmplate, but also demonstrates how to 
bring OpenGL into the mix.









http://listas.apesol.org/pipermail/sdl-libsdl.org/2003-July/036886.html
Hi,

As requested, I've put together Cocoa integration support. I'd like to
get several people to apply the patches and run tests before including
this in 1.2.6.

Included are two patches to CVS version and new Project Builder project
files.

http://homepage.mac.com/walisser/downloads/PBProjects.tar.gz
http://homepage.mac.com/walisser/downloads/src-main-macosx-exports.patch
http://homepage.mac.com/walisser/downloads/src-video-quartz.patch

Screenshot of the sample program:
http://homepage.mac.com/walisser/downloads/sdlcocoa.png

-----------------------------
Installing the new stuff
-----------------------------

cd SDL12/src/video/quartz
patch -p0 < ~/Desktop/src-video-quarz.patch

cd SDL12/src/main/macosx/exports
patch -p0 < ~/Desktop/src-main-macosx-exports.patch

Then drop PBProjects.tar.gz in SDL12/ and unpack.

Compile SDL.framework, then you can open the example program in
SDL12/PBProjects/Project Stationary/SDL Custom Cocoa Application.
There's also new stationary for OpenGL and Nib-based SDL apps. Beware
the stationary hasn't been converted into PB's stationary format yet
and the developer install script needs to be fixed, so these projects
aren't ready to be put into CVS.

-------------------------------
How it works
-------------------------------

This will probably make little if no sense to anyone who isn't familiar
with Cocoa. You can always read up on Cocoa at
http://www.apple.com/developer. For clarification of the following, you
should consult the example code.


SDL will handle three new environment variables: SDL_NSWindowPointer,
SDL_NSQuickDrawViewPointer, and SDL_ENABLEAPPEVENTS.


SDL_NSWindowPointer contains the address of an instance of NSWindow.
However, you probably want to use a subclass or instance of
SDL_QuartzWindow because it handles window resizing and other things.
You set it by passing the integer value of the NSWindow object/pointer:

sprintf (buffer, "%d", (int)nsWindowObj);
setenv ("SDL_NSWindowPointer", buffer, 1);


SDL_NSQuickDrawViewPointer points to an instance of NSQuickDrawView.
This view controls where SDL will do its drawing, send mouse events,
etc. The view must lie within the window you passed with
SDL_NSWindowPointer. Note that YUV overlays are currently untested, but
should work. Using NSOpenGLView will probably not work.


SDL_ENABLEAPPEVENTS tells SDL to pass keyboard events to Cocoa. With
this environment variable set, Cocoa keyboard shortcuts, textboxes,
etc, will work as expected. The Cocoa objects will get the keyboard
events before the SDL event functions return them.


Before you call SDL_SetVideoMode(), you should make sure that you've
set both SDL_NSWindowPointer and SDL_NSQuickDrawViewPointer
(SDL_ENABLEAPPEVENTS is optional). Also, the window should be visible
and key. For example, call [ nsWindowObject makeKeyAndOrderFront:nil
]. There are some other optional initializations you may want, see [
MyController setupCocoaWindow ] for details.

If you want to use a resizable window, make sure you've set the
resizable properties of the window instance you pass. You can have a
fix-sized view and resizable window if you want - just ignore
SDL_VIDEORESIZE.


When you call SDL_SetVideoMode(), the environment is checked for
SDL_NSWindowPointer and SDL_NSQuickDrawViewPointer. If these are both
found, the window pointer and view pointer are stored and and the
window pointer is retained (the view pointer is not retained).

When the video mode is destroyed, the window pointer is released. The
window is also closed, so make sure the "release when closed" attribute
is not set on the window (unless you want to recreate it). If the
window closes, you'll have to make it visible and key again before
SDL_SetVideoMode() is called. You can override the window's close
method to keep it from closing until you want it to.


The sample code should be very helpful when you begin constructing your
Cocoa GUI. Let me know if you have any problems or questions.


@interface MyCustomView : NSQuickDrawView

{

}


 

@end


 

/////////////////////////////////////////////////////////////


 

 

#import <AppKit/AppKit.h>


 

// Be a subclass of SDL_QuartzWindow so SDL will

// handle the redraw problems when minimizing the window

// This class is defined in SDL.framework

@interface SDL_QuartzWindow : NSWindow

@end


 

// Also assign SDL_QuartzWindowDelegate to the window

// to perform other tasks. You can subclass this delegate

// if you want to add your own delegation methods

// This class is defined in SDL.framework

@interface SDL_QuartzWindowDelegate : NSObject

@end


 

// Declare our custom class

@interface MyCustomWindow : SDL_QuartzWindow

@end

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    // Export cocoa objects to environment

    // SDL will use these when you call SDL_SetVideoMode

    

    // The window must be visible when you call SDL_SetVideoMode,

    // and the view must lie completely within the window.

    // 

    //  The width and height passed to SDL_SetVideoMode should match

    //  the width/height of the view (the window can be any size)

    //

    // For resizing to work, you must set the appropriate

    // attributes on the window and view. Then the SDL_RESIZABLE

    //  flag will be set automatically

    //

    //  SDL will retain a reference to the window, and

    //  will release it when unsetting the video mode

    //

    //  The view is not retained (the window object manages this).

    //

    char buffer[256];

    printf ("NSWindow=%p\n", _window);

    sprintf (buffer, "%d", (int)_window);

    setenv ("SDL_NSWindowPointer", buffer, 1);

    

    printf ("NSQuickDrawView=%p\n", _view);

    sprintf (buffer, "%d", (int)_view);

    setenv ("SDL_NSQuickDrawViewPointer", buffer, 1);

 

(jacky)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www1.rosoo.net/a/201003/8650.html]
本文出处:meandmark.com 作者:jacky
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容