标签:
#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; }
标签:
原文地址:http://my.oschina.net/u/241930/blog/526058