我正在开发一个类似Microsoft的类似绘画的程序,用于在C上学习VGA 256色编程。
我可以在用户点击屏幕时绘制一个像素,并在按下鼠标按钮时继续绘制像素。但是,如果我在屏幕上快速移动鼠标,我就无法获得连续的线条。相反,我得到了这个结果
即使鼠标快速移动,如何使线条连续?
直到现在我的代码:
/**************************************************************************
* paint_screen *
* show main screen paint *
**************************************************************************/
void paint_screen(BITMAP *fondo){
int mantenido;
BITMAP barra,barra_color,normal_ptr_image;
int anterior_presionado;
word last_time;
word redraw,press,release;
sword dx,dy=0;
MOUSEBITMAP *mouse_new=NULL;
int i,done = 0;
accion =1;
/*Pintando fondo blanco*/
clear_screen();
/*Pintando barra de herramientas*/
load_bmp("normal.bmp",&normal_ptr_image);
load_bmp("mainbar.bmp",&barra);
load_bmp("colores.bmp",&barra_color);
set_pallete(fondo->pallete);
draw_bitmap(&barra,0,0);
draw_bitmap(&barra_color,0,180);
load_mouse(&mouse_g);
show_mouse(&mouse_g);
wait(50);
while(!done){
do { // check mouse status
anterior_presionado = press;
get_mouse_motion(&dx,&dy);
press = get_mouse_press(LEFT_BUTTON);
release = get_mouse_release(LEFT_BUTTON);
//Si el estado estaba presionado y no se ha soltado.. el boton esta mantenido
if(anterior_presionado==1 &&release==0){
mantenido =1;
}
} while (dx==0 && dy==0 && press==0 && release==0&&*my_clock==last_time);
if (release){
mouse_g.button1=0;
mantenido=0;
boton_soltado();
}
if (press){
mouse_g.button1=1;
boton_presionado();
}
//El boton se mantiene presionado
else if(mantenido){
boton_mantenido();
}
else{
release=1;
}
if (dx || dy) // calculate movement
{
new_x1 = mouse_g.x+dx;
new_y1 = mouse_g.y+dy; //Actualizamos posicion mouse
if (new_x1<0) new_x1=0;
if (new_y1<0) new_y1=0;
if (new_x1>319) new_x1=319;
if (new_y1>199) new_y1=199;
redraw=1;
}
if(redraw){
wait_for_retrace();
hide_mouse(&mouse_g);
if (mouse_new!=NULL) mouse_g.bmp=mouse_new;
mouse_g.x = new_x1;
mouse_g.y=new_y1;
show_mouse(&mouse_g);
redraw=0;
mouse_new=NULL;
}
if(new_x1>=287 && new_x1 <320
&& new_y1>=180 && new_y1 < 200 &&press){
set_mode(TEXT_MODE);
printf("Adios!!");
wait(25);
done=0;
return;
}
}
}
void realizar_accion(){
/*Caso1: Pintar pixel simple (lapiz)*/
if(accion==1){
plot_pixel(mouse_g.x,mouse_g.y,2);
plot_pixel(mouse_g.x-1,mouse_g.y,2);
plot_pixel(mouse_g.x,mouse_g.y-1,2);
plot_pixel(mouse_g.x-1,mouse_g.y-1,2);
}
}
void realizar_accion_mantenido(){
if(accion==1){
plot_pixel(mouse_g.x,mouse_g.y,2);
plot_pixel(mouse_g.x-1,mouse_g.y,2);
plot_pixel(mouse_g.x,mouse_g.y-1,2);
plot_pixel(mouse_g.x-1,mouse_g.y-1,2);
}
}
int sobre_barra(){
if(new_x1>0 && new_x1<33 &&new_y1>0 &&new_y1<181){
return 1;
}
else{
return -1;
}
}
void boton_mantenido(){
/*Verificar que este dento del buffer de dibujo....*/
if(sobre_barra()!=1){
realizar_accion_mantenido();
}
}
void boton_presionado(){
if(sobre_barra()==1){
cambiar_herramienta();
}
else{
realizar_accion();
}
}