NSWindow [ASOC]
NSWindow Class
|
詳細 |
|
NSWindow class
(* プロパティの作成 *)
property theWindow : missing value
|
NSWindowを操作するために用います。
theWindowはすでに用意されていて、すでに最初のNSWindowオブジェクトにも関連付けが
されています。
新しくNSWindowを追加する場合は別途に用意する必要があります。
(* タイトル *)
set windowTitle to theWindow's title() --|タイトルの取得|
theWindow's setTitle_("text") --|タイトルの変更|
|
NSWindowのタイトルバーに表示される文字の取得と設定
(* 透過設定 *)
set f to theWindow's Opaque --|透過の確認|
theWindow's setOpaque_(bool) --|透過を設定|
|
背景を透明(clearColor)などの透けている場合に許可をしていないと、シャドウのグレー色が
表示されてしまいます。
透過を許可している場合は表示に負荷がかかるため、多数使用する場合は注意。
別の不透明度を変更した場合はシャドウグレーも比例して変化するので、今回の例からは外れます。
(* 背景色の設定 *)
set theColor to theWindow's BackgroundColor() --|Windowのバックグラウンド色を取得|
theWindow's setBackgroundColor_(theColor) --|Windowのバックグラウンド色を変更|
|
--固有色で設定
set theColor to current application's class "NSColor"'s redColor --|赤|
set theColor to current application's class "NSColor"'s greenColor --|緑|
set theColor to current application's class "NSColor"'s blueColor --|青|
set theColor to current application's class "NSColor"'s clearColor --|透明|
他に、cyanColor,magentaColor,yellowColor,orangeColor,purpleColor,brownColor,
blackColor,darkGrayColor,grayColor,lightGrayColor,whiteColor など
--数値で設定(RGB + Alpha値を0.0~1.0で設定)
set {r,g,b,a} to {0.0, 0.5, 0.2, 1.0}
set theColor to current application's class "NSColor"'s ¬
colorWithCalibratedRed_green_blue_alpha_(r,g,b,a)
(* NSWindowの不透明度の設定 *)
set a to theWindow's AlphaValue() --|不透明度を確認|
theWindow's setAlphaValue_(n) --|不透明度の変更|
|
不透明度(アルファ値)の設定をします。(透明度ではなく、"不透明"度)
n は0.0~1.0までの実数で、1が不透明、0が透明になります。
(* NSWindowの位置 *)
set thePoint to current application's class "NSPoint"'s NSMakePoint(150,0) theWindow's setFrameTopLeftPoint_(thePoint) --|ウインドウを左上角の座標で移動|
theWindow's setContentSize_({x,y}) --|ウインドウを左下角の座標で移動|
|
※ 画面(デスクトップ)左上を原点{0, 0}とした位置。
(* 中央へ移動 *)
theWindow's |center|() --|ウインドウをセンターに移動|
|
左右はセンターに移動されるものの、天地はやや上にずれてしまうので、使い所を注意。
(* 限界サイズの設定 *)
theWindow's setMaxSize_({size_w,size_h}) --|Windowの最大サイズを変更| theWindow's setMinSize_({size_w,size_h}) --|Windowの最小サイズを変更|
|
リサイズ時の最小、最大サイズを設定。
(* バックグラウンドでの移動の許可 *)
theWindow's setMovableByWindowBackground_(bool)
|
bool値をtrueにしてマウスでバックグラウンドでプレス&ドラックでのウインドウの移動を許可をする。
(未設定時はfalse)
(* 位置やサイズを自動で記憶 *)
theWindow's setFrameAutosaveName_("keyword") --|Windowの位置情報を自動で記録・再現|
|
アプリケーション終了時に指定したNSWindowの位置を記憶し次回の起動時に自動で再現
させることができる。キーワードはなんでも構わない。他のアプリケーションと同じキー
ワードであっても別々に記憶されるので、単体で考えれば良い。
再現はすでにNSWindowが開いた後では遅いのでNSWindowオブジェクトが読み込まれる
前の awakeFromNibの中に記入することが好ましい。
(* 表示順位を移動 *)
theWindow's orderFront_(me) --|ウインドウの表示順位を最前へ| theWindow's orderBack_(me) --|ウインドウの表示順位を後ろへ|
|
他のアプリケーションのウインドウにも影響します。
(* NSWindowを表示から除外 *)
theWindow's orderOut_(me) --|ウインドウを表示リストから外します(非表示に)|
|
NSWindowがスクリーンリストから削除される。つまり非表示になる。orderFrontで再表示できる。
(* NSWindowに貼られたViewの取得 *)
set mainView to theWindow's contentView() --|Content Viewを取得|
|
NSWindow直下のView(contentView)を取得する。
(* NSWindowのデバイス番号の確認 *)
set n to theWindow's windowNumber() --|デバイス番号を取得|
|
NSWindowのウインドウデバイスのウインドウ番号の取得。
(* NSWindowの除外時のメモリー解放 *)
set n to theWindow's oneShot()
|
値がtrueの場合、ウィンドウがスクリーンリストから削除されると解放。別のウィンドウデバイスが
画面に戻ったときに作成されます。
値がfalseの場合、ウィンドウデバイスは再利用されます。
スクリーンリストから削除されたときにウィンドウデバイスを解放するとメモリ節約とパフォーマンス
が向上します。
|
作成 |
|
(* 新規でウインドウを作成 *)
set windowRect to current application's NSMakeRect(150, 200, 600, 400) set windowStyleMask to 3 --|0:バー無, 1:バー有, 2:バー無, 3:ボタン配置済みバー有| set windowBacking to 1 --|どのようなバッファかを指定し、値はNSBackingStoreTypeに記述| set WindowDefer to false --|画面上に移動するまで、ウィンドウ・デバイスの作成を延期させるか| set sabWindow1 to current application's class "NSWindow"'s alloc()'s initWithContentRect_styleMask_backing_defer_(windowRect,windowStyleMask,windowBacking,WindowDefer) tell sabWindow1 setBackgroundColor_(current application's NSColor's lightGrayColor) orderFront_(me) end tell
|
|
コメント 0