こんなショボいUIを作っていろいろやってみる。CoreGraphicsで定義されている視覚効果のemunは以下のとおり。
typedef enum {
CGSNone = 0, // No transition effect.
CGSFade, // Cross-fade.
CGSZoom, // Zoom/fade towards us.
CGSReveal, // Reveal new desktop under old.
CGSSlide, // Slide old out and new in.
CGSWarpFade, // Warp old and fade out revealing new.
CGSSwap, // Swap desktops over graphically.
CGSCube, // The well-known cube effect.
CGSWarpSwitch, // Warp old, switch and un-warp.
CGSFlip // Flip over
} CGSTransitionType;
こいつと一緒に渡すCGSTransitionOptionについては省略。CGSTransitionTypeとCGSTransitionOptionをそれぞれcombboxのアイテムに仕込んで、trans_combo.indexOfSelectedItemといった感じで選択アイテムのindexを取得する。
で、ObjCのclassのメソッドを書きなおす。
- (void)setSpaceNumberWithTransition:(NSInteger)space trans:(NSInteger)a_trans option:(NSInteger)a_option{
CGSConnection cid;
int transitionHandle;
int transitionSpec[5];
cid = _CGSDefaultConnection();
/* Set up the transition specification */
memset(transitionSpec, 0, 20); /* 20 = 0x14 */
transitionSpec[1] = a_trans;
transitionSpec[2] = a_option;
/* Set up the transition itself */
CGSNewTransition(cid, transitionSpec, &transitionHandle);
/* Switch desktop */
CGSSetWorkspace(cid, space);
/* A little pause to let the Window Server sort itself out ... */
usleep(6000);
/* ... and fire off the transition */
CGSInvokeTransition(cid, transitionHandle, 4);
}
実は引数を3つに増やしたところでハマった。引数にラベルをつける、というObjCの書法を知らなかったため、ずいぶんとあちこち探しまわったりあれこれ書き直したりして時間をくってしまった。素人だから仕方ない。
先日、木下誠氏のセミナー資料をMacRubyで書きなおしたとき、ちゃんとerror:nilみたいにしてラベル付きで引数渡しをちゃんとやっていたのに。意味がわかってなかったんだなあ。わかってよかった。
MacRuby側のソースは今のところこうなった。下手な書き方ご容赦。
def get_max
CFPreferencesAppSynchronize("com.apple.dock")
row=CFPreferencesGetAppIntegerValue("workspaces-rows", "com.apple.dock", nil)
col=CFPreferencesGetAppIntegerValue("workspaces-cols", "com.apple.dock", nil);
row * col
end
def prev_space(sender)
trans=trans_combo.indexOfSelectedItem
option=option_combo.indexOfSelectedItem
@tmp_space_no=set_space_no
@max_spaces=get_max
@tmp_space_no = @tmp_space_no -1
if @tmp_space_no == 0 then @tmp_space_no=@max_spaces end
@my_space.setSpaceNumberWithTransition(@tmp_space_no,trans:trans,option:option)
end
def next_space(sender)
end
def set_space_no
number=Pointer.new('i')
number[0]=@my_space.spaceNumber
number[0]
end
ちなみに視覚効果を「WarpFade」にするとこんなふうにSpacesが切り替わる。視覚効果を切り替えて遊んでいると大変たのしい。次はSpaces.appへのNotificationの勉強をしよう。それからマウスのイベント。
土日でどれくらい勉強できるかなあ。

0 件のコメント:
コメントを投稿