- 追加された行はこの色です。
- 削除された行はこの色です。
*第10回目 Cocoaでフルスクリーンモード [#rc50d9a6]
Cocoaアプリケーションでフルスクリーンを実現する方法です。
サンプルプログラムはESCキーを押すと終了します。
**プログラム作成 [#m6234ec5]
***MyOpenGLView.h [#jd93665b]
@interface MyOpenGLView:NSOpenGLView
{
NSWindow *fullscreen_window;
}
@end
***MyOpenGLView.m [#z480190b]
- (void)awakeFromNib
{
[[self window] makeFirstResponder:self];
unsigned int window_style;
NSRect screen_rect;
window_style = NSBorderlessWindowMask;
screen_rect = [[NSScreen mainScreen] frame];
fullscreen_window = [[NSWindow alloc] initWithContentRect:screen_rect styleMask:window_style backing:NSBackingStoreBuffered defer:NO];
if(fullscreen_window != nil)
{
[fullscreen_window setReleasedWhenClosed:YES];
[fullscreen_window setContentView:self];
[fullscreen_window makeKeyAndOrderFront:self];
[fullscreen_window setLevel:NSScreenSaverWindowLevel - 1];
[fullscreen_window makeFirstResponder:self];
}
[NSCursor hide];
}
NSOpenGLViewから派生したクラスのawakeFromNibに上記のコードを追加するだけ。
解像度はWindowsのDirectXと違い画面の解像度そのままでフルスクリーン化されるので注意が必要です。
***各行の説明 [#ya9be637]
-[[self window] makeFirstResponder:self];
ファーストレスポンダ指定。
-screen_rect = [[NSScreen mainScreen] frame];
画面のサイズを取得。
-fullscreen_window = [[NSWindow alloc] initWithContentRect:screen_rect styleMask:window_style backing:NSBackingStoreBuffered defer:NO];
フルスクリーン化。
-[fullscreen_window setReleasedWhenClosed:YES];
ウインドウが無くなったらメモリを開放。
-[fullscreen_window setContentView:self];
表示内容は自分自身。
-[fullscreen_window makeKeyAndOrderFront:self];
キーウインドウに設定。
-[fullscreen_window setLevel:NSScreenSaverWindowLevel - 1];
描画優先順位をスクリーンセーバーよりも1だけ下に設定。
-[fullscreen_window makeFirstResponder:self];
新しいウインドウもファーストレスポンダを引き継ぐ。
-[NSCursor hide]
カーソルを消す。
**サンプルプログラム [#p945c542]
#ref(http://www.ripple.gr.jp/~kuran_kuran/bin/download/fullscreen_source_20090615.zip)~
[[前に戻る>プログラミング]]