簡單的寫字板

#include <stdio.h>
#include "acllib.h"

void mouseListener(int x, int y, int button, int event)
{
    static int ox = 0; // 可讓線條從上個觸點接着開始,要否則會每次都從(0,0)開始 
    static int oy = 0;
    static int state = 0; // 初始化鼠標左鍵狀態 
    printf("x = %d, y = %d, button = %d, event = %d.\n", x, y, button, event);
    
    //鼠標左鍵按下時狀態 
    if(button == 1 && event == 0)
    {
        state = 1;
    }
    
    //鼠標左鍵擡起時狀態 
    if(button == 1 && event == 2)
    {
        state = 0;
    }
    
    //鼠標左鍵按下時開始繪圖,擡起時中止。 
    if(state == 1)
    {
        beginPaint();
        setPenColor(RED); //筆觸顏色
        setPenWidth(3);   //筆觸大小 
        line(ox, oy, x, y);
        endPaint();
    }
    ox = x;
    oy = y;
}

void keyboardListener(int key, int event)
{
    printf("key = %d, event = %d.\n", key, event);
}

int Setup()
{
    initWindow("寫字板", DEFAULT, DEFAULT, 640, 480);//初始化界面 
    
    registerMouseEvent(mouseListener);  //鼠標回調函數 
    registerKeyboardEvent(keyboardListener); //鍵盤迴調函數 
    
    return 0;
}
相關文章
相關標籤/搜索