/*-------------------------------------------------------------------------------*/ * おそらくコンパイルは通りません・・・通るかもしれませんが、Motifだったり * * 牛乳版Motifだったりが、解からないので途中止めです。 * * 解からないと書きましたが、何処まで違うのか解からないということです。 * /*-------------------------------------------------------------------------------*/ #include #define INTERVAL 100 /* コマ送りのタイミング */ #define ARC 20 /* 円のサイズ */ #define LEFT 00 /* 左端のx座標 */ #define RIGHT 200 /* 右端のx座標 */ #define Y 90 /* 円のy座標 */ #define STEP 5 /* 一コマ間の移動距離 */ #define LtoR 0 /* 左から右 */ #define RtoL 1 static GC gc; static XtIntervalId timeout_id; static int position = LEFT; static int direction = LtoR; /* 一定時間毎に呼び出されるタイムアウト・コールバックの中でコマ送り */ static void TimeoutCB(client_data, id) XtPointer client_data; XtIntervalId *id; { Widget w = (Widget)client_data; /* 以前に描いた円を消去 */ XClearArea(XtDisplay(w), XtWindow(w), position, Y, ARC, ARC, False); /* 次の円の位置を求める。現在、どちら方向を向いているか、左右の端を越えないか等 */ if (direction ==LtoR) { position += STEP; if (position > (RIGHT - ARC)) { position = (RIGHT - ARC) - (position - (RIGHT - ARC)); direction = RtoL; } } else { /* direction == RtoL */ position -=STEP; if (position < LEFT) { position = LEFT - (position - LEFT); direction = LtoR; } } /* 次の位置に円を描く */ XFillArc(XtDisplay(w), XtWindow(w), gc, position, Y, ARC, ARC, 0*64, 360*64); /*-------------------------------------------------------*/ * タイムアウト・コールバックの登録・・・ * * 注意、こうしないと、タイムアウト・コールバックは * * 二度と呼び出されない * /*-------------------------------------------------------*/ timeout_id = XtAppAddTimeOut(XtWidgetToApplicationContext(w), INTERVAL, TimeoutCB, w); } main (argc, argv) int argc; char **argv; { XtAppContext app_context; Widget toplevel, panel, canvas; Arg al[20]; int ac; XtSetLanguageProc(NULL, NULL, NULL); ac = 0; toplevel = XtAppInitialize(&app_context, "Animation", NULL, 0, &argc, argv, NULL, al, ac); ac = 0; panel = XmCreateForm(toplevel, "panel", al, ac); XtManageChild(panel); ac = 0; canvas = XmCreateDrawingArea(panel, "canvas", al, ac); XtManageChild(canvas); XtRealizeWidget(toplevel); gc = XCreateGC(XtDisplay(canvas), XtWindow(canvas), NULL, NULL); XSetForeground(XtDisolay(canvas), gc, BlackPixelofScreen(XtScreen(canvas))); /* タイムアウト。コールバックの登録 */ timeout_id = XtAppAddTimeOut(app_context, INTERVAL,TimeoutCB, canvas); XtAppMainLoop(app_context); }