// Window_shake.c
// 2002.8.17
// made by 허창원(Heo, Chang-won), 극동테크(Kuk Dong Tech.) (www.kdtechno.com)
// LabWindows/CVI용 소스 프로그램
#include <userint.h>
#include <utility.h>

// 함수 선언: 외부 프로그램에서 사용하려면, 이 함수 선언을 적당한 헤더파일에 넣어주세요.
// 사용예: Window_shake(panel, 2);
void Window_shake(int panel, int n);

void window_top_moveBy(int panel, int left, int top, int x, int y)
// 윈도의 위치를 이동
    // left : 윈도의 left 위치
    // top  : 윈도의 top 위치
    // x    : x축으로 이동하고자하는 값
    // y    : y축으로 이동하고자하는 값
{
    SetPanelAttribute (panel, ATTR_TOP, top+y);
    SetPanelAttribute (panel, ATTR_LEFT, left+x);
}

void Window_shake(int panel, int n)
{
    static int top, left, i, j;
 
    // 원래 윈도 위치 획득
    GetPanelAttribute (panel, ATTR_TOP, &top);
    GetPanelAttribute (panel, ATTR_LEFT, &left);

    // 윈도 흔듬
    for(i=10;i > 0;i--)
    {
        for(j=n;j > 0;j--)
        {
            window_top_moveBy(panel, left, top, 0, i);
            Delay(0.01);
            window_top_moveBy(panel, left, top, i, 0);
            Delay(0.01);
            window_top_moveBy(panel, left, top, 0, -i);
            Delay(0.01);
            window_top_moveBy(panel, left, top, -i, 0);
            Delay(0.01);
        }
    }

    // 윈도의 원래 위치를 복원
    SetPanelAttribute (panel, ATTR_TOP, top);
    SetPanelAttribute (panel, ATTR_LEFT, left);
}
