Commiting the accessibility work from Ankit Choudary. First of 4 sequential patches. Adding mouse mode for Brush, Line and Erase tools.

This commit is contained in:
Pere Pujal i Carabantes 2010-06-23 22:36:13 +00:00
parent 801fcd72b9
commit 93b737d8a7

View file

@ -1979,13 +1979,13 @@ enum
SHAPE_TOOL_MODE_DONE SHAPE_TOOL_MODE_DONE
}; };
int flagmouse,xnew,ynew,eraflag,lineflag;
/* --- MAIN LOOP! --- */ /* --- MAIN LOOP! --- */
static void mainloop(void) static void mainloop(void)
{ {
int done, which, old_x, old_y, new_x, new_y, int done, which, old_x, old_y, new_x, new_y,
line_start_x, line_start_y, shape_tool_mode, line_start_x, line_start_y, line_end_x, line_end_y, shape_tool_mode,
shape_ctr_x, shape_ctr_y, shape_outer_x, shape_outer_y, shape_ctr_x, shape_ctr_y, shape_outer_x, shape_outer_y,
old_stamp_group; old_stamp_group;
int num_things; int num_things;
@ -2012,8 +2012,6 @@ static void mainloop(void)
do_draw = 0; do_draw = 0;
old_x = 0; old_x = 0;
old_y = 0; old_y = 0;
line_start_x = 0;
line_start_y = 0;
shape_ctr_x = 0; shape_ctr_x = 0;
shape_ctr_y = 0; shape_ctr_y = 0;
shape_outer_x = 0; shape_outer_x = 0;
@ -3778,7 +3776,9 @@ static void mainloop(void)
/* Start painting! */ /* Start painting! */
rec_undo_buffer(); rec_undo_buffer();
xnew = event.button.x - r_canvas.x;
ynew = event.button.y - r_canvas.y;
flagmouse++;
/* (Arbitrarily large, so we draw once now) */ /* (Arbitrarily large, so we draw once now) */
reset_brush_counter(); reset_brush_counter();
@ -3808,18 +3808,42 @@ static void mainloop(void)
rec_undo_buffer(); rec_undo_buffer();
line_start_x = old_x; if (lineflag%2 == 0)
line_start_y = old_y; {
line_start_x = event.button.x - r_canvas.x;
line_start_y = event.button.y - r_canvas.y;
}
if (lineflag%2 != 0)
{
line_end_x = event.button.x - r_canvas.x;
line_end_y = event.button.y - r_canvas.y;
line_xor(line_start_x, line_start_y, line_start_x, line_start_y);
line_xor(line_start_x, line_start_y, line_end_x, line_end_y);
/* (Arbitrarily large, so we draw once now) */ brush_draw(line_start_x, line_start_y,
reset_brush_counter(); event.button.x - r_canvas.x,
event.button.y - r_canvas.y, 1);
/* brush_draw(old_x, old_y, old_x, old_y, 1); fixes sf #1934883? */ brush_draw(event.button.x - r_canvas.x,
event.button.y - r_canvas.y,
event.button.x - r_canvas.x,
event.button.y - r_canvas.y, 1);
update_screen(line_start_x + r_canvas.x,
line_start_y + r_canvas.y, line_start_x + r_canvas.x,
line_start_y + r_canvas.y);
update_screen(line_start_x + r_canvas.x,
line_start_y + r_canvas.y, line_end_x + r_canvas.x,
line_end_y + r_canvas.y);
playsound(screen, 1, SND_LINE_START, 1, event.button.x, playsound(screen, 1, SND_LINE_START, 1, event.button.x,
SNDDIST_NEAR); SNDDIST_NEAR);
draw_tux_text(TUX_BORED, TIP_LINE_START, 1); draw_tux_text(TUX_BORED, TIP_LINE_START, 1);
} }
/* (Arbitrarily large, so we draw once now) */
lineflag++;
reset_brush_counter();
/* brush_draw(old_x, old_y, old_x, old_y, 1); fixes sf #1934883? */
}
else if (cur_tool == TOOL_SHAPES) else if (cur_tool == TOOL_SHAPES)
{ {
if (shape_tool_mode == SHAPE_TOOL_MODE_DONE) if (shape_tool_mode == SHAPE_TOOL_MODE_DONE)
@ -3908,7 +3932,7 @@ static void mainloop(void)
/* Erase! */ /* Erase! */
rec_undo_buffer(); rec_undo_buffer();
eraflag++;
do_eraser(old_x, old_y); do_eraser(old_x, old_y);
} }
else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL) else if (cur_tool == TOOL_TEXT || cur_tool == TOOL_LABEL)
@ -4394,6 +4418,8 @@ static void mainloop(void)
{ {
/* Tools: */ /* Tools: */
int most = 14; int most = 14;
flagmouse = 0;
eraflag = 0;
if (NUM_TOOLS > most + TOOLOFFSET) if (NUM_TOOLS > most + TOOLOFFSET)
{ {
@ -4441,6 +4467,9 @@ static void mainloop(void)
} }
else if (HIT(r_sfx)) else if (HIT(r_sfx))
{ {
flagmouse = 0;
eraflag = 0;
/* Sound player buttons: */ /* Sound player buttons: */
if (cur_tool == TOOL_STAMP && use_sound && !mute && if (cur_tool == TOOL_STAMP && use_sound && !mute &&
@ -4458,6 +4487,9 @@ static void mainloop(void)
} }
else if (HIT(r_colors)) else if (HIT(r_colors))
{ {
flagmouse = 0;
eraflag = 0;
/* Color picker: */ /* Color picker: */
if (colors_are_selectable) if (colors_are_selectable)
@ -4467,6 +4499,9 @@ static void mainloop(void)
} }
else if (HIT(r_toolopt)) else if (HIT(r_toolopt))
{ {
flagmouse = 0;
eraflag = 0;
/* mouse cursor code /* mouse cursor code
WARNING: this must be kept in sync with the mouse-click WARNING: this must be kept in sync with the mouse-click
and mouse-click code. (it isn't, currently!) */ and mouse-click code. (it isn't, currently!) */
@ -4552,8 +4587,18 @@ static void mainloop(void)
{ {
/* Canvas: */ /* Canvas: */
if (cur_tool == TOOL_BRUSH) if (flagmouse%2 != 0 && cur_tool == TOOL_BRUSH)
{
brush_draw(xnew, ynew, event.motion.x - r_canvas.x, event.motion.y - r_canvas.y, 1);
playsound(screen, 0, paintsound(img_cur_brush_w), 0,event.motion.x, SNDDIST_NEAR);
xnew=event.motion.x - r_canvas.x;
ynew=event.motion.y - r_canvas.y;
}
else if (flagmouse%2 == 0 && cur_tool == TOOL_BRUSH)
{
do_setcursor(cursor_brush); do_setcursor(cursor_brush);
}
else if (cur_tool == TOOL_STAMP) else if (cur_tool == TOOL_STAMP)
do_setcursor(cursor_tiny); do_setcursor(cursor_tiny);
else if (cur_tool == TOOL_LINES) else if (cur_tool == TOOL_LINES)
@ -4583,8 +4628,9 @@ static void mainloop(void)
else if (cur_tool == TOOL_MAGIC) else if (cur_tool == TOOL_MAGIC)
do_setcursor(cursor_wand); do_setcursor(cursor_wand);
else if (cur_tool == TOOL_ERASER) else if (cur_tool == TOOL_ERASER && eraflag%2 == 0)
do_setcursor(cursor_tiny); do_setcursor(cursor_tiny);
} }
else else
{ {
@ -4594,32 +4640,7 @@ static void mainloop(void)
if (button_down) if (button_down)
{ {
if (cur_tool == TOOL_BRUSH) if (cur_tool == TOOL_SHAPES)
{
/* Pushing button and moving: Draw with the brush: */
brush_draw(old_x, old_y, new_x, new_y, 1);
playsound(screen, 0, paintsound(img_cur_brush_w), 0,
event.button.x, SNDDIST_NEAR);
}
else if (cur_tool == TOOL_LINES)
{
/* Still pushing button, while moving:
Draw XOR where line will go: */
line_xor(line_start_x, line_start_y, old_x, old_y);
line_xor(line_start_x, line_start_y, new_x, new_y);
update_screen(line_start_x + r_canvas.x,
line_start_y + r_canvas.y, old_x + r_canvas.x,
old_y + r_canvas.y);
update_screen(line_start_x + r_canvas.x,
line_start_y + r_canvas.y, new_x + r_canvas.x,
new_y + r_canvas.y);
}
else if (cur_tool == TOOL_SHAPES)
{ {
/* Still pushing button, while moving: /* Still pushing button, while moving:
Draw XOR where shape will go: */ Draw XOR where shape will go: */
@ -4670,12 +4691,7 @@ static void mainloop(void)
update_rect.x + update_rect.w, update_rect.x + update_rect.w,
update_rect.y + update_rect.h); update_rect.y + update_rect.h);
} }
else if (cur_tool == TOOL_ERASER)
{
/* Still pushing, and moving - Erase! */
do_eraser(new_x, new_y);
}
} }
@ -4691,6 +4707,8 @@ static void mainloop(void)
h = active_stamp->h; h = active_stamp->h;
} }
else else
{
if (eraflag%2 == 0)
{ {
if (cur_eraser < NUM_ERASERS / 2) if (cur_eraser < NUM_ERASERS / 2)
{ {
@ -4704,9 +4722,11 @@ static void mainloop(void)
(((NUM_ERASERS / 2) - (cur_eraser - NUM_ERASERS / 2) - 1) * (((NUM_ERASERS / 2) - (cur_eraser - NUM_ERASERS / 2) - 1) *
((ERASER_MAX - ERASER_MIN) / ((NUM_ERASERS / 2) - 1)))); ((ERASER_MAX - ERASER_MIN) / ((NUM_ERASERS / 2) - 1))));
} }
h = w; h = w;
} }
else if (eraflag%2 != 0)
do_eraser(new_x,new_y);
}
if (old_x >= 0 && old_x < r_canvas.w && if (old_x >= 0 && old_x < r_canvas.w &&
old_y >= 0 && old_y < r_canvas.h) old_y >= 0 && old_y < r_canvas.h)
@ -4721,6 +4741,8 @@ static void mainloop(void)
old_y + (CUR_STAMP_H + 1) / 2 + r_canvas.y); old_y + (CUR_STAMP_H + 1) / 2 + r_canvas.y);
} }
else else
{
if (eraflag%2 == 0)
{ {
rect_xor(old_x - w / 2, old_y - h / 2, rect_xor(old_x - w / 2, old_y - h / 2,
old_x + w / 2, old_y + h / 2); old_x + w / 2, old_y + h / 2);
@ -4731,6 +4753,7 @@ static void mainloop(void)
old_y + h / 2 + r_canvas.y); old_y + h / 2 + r_canvas.y);
} }
} }
}
if (new_x >= 0 && new_x < r_canvas.w && if (new_x >= 0 && new_x < r_canvas.w &&
new_y >= 0 && new_y < r_canvas.h) new_y >= 0 && new_y < r_canvas.h)
@ -4745,6 +4768,8 @@ static void mainloop(void)
old_y + (CUR_STAMP_H + 1) / 2 + r_canvas.y); old_y + (CUR_STAMP_H + 1) / 2 + r_canvas.y);
} }
else else
{
if (eraflag%2 == 0)
{ {
rect_xor(new_x - w / 2, new_y - h / 2, rect_xor(new_x - w / 2, new_y - h / 2,
new_x + w / 2, new_y + h / 2); new_x + w / 2, new_y + h / 2);
@ -4756,6 +4781,7 @@ static void mainloop(void)
} }
} }
} }
}
else if (cur_tool == TOOL_SHAPES && else if (cur_tool == TOOL_SHAPES &&
shape_tool_mode == SHAPE_TOOL_MODE_ROTATE) shape_tool_mode == SHAPE_TOOL_MODE_ROTATE)
{ {