public void processMouseClick(Point mousePoint, int mouseButton) {
int x = (int) mousePoint.getX();
int y = (int) mousePoint.getY();
EditStatus editStatus = application.getEditStatus();
Picture picture = application.getPicture();
// Is it the LEFT mouse button?
if (mouseButton == MouseEvent.BUTTON1) {
// Is a tool active?
if (editStatus.getTool() != ToolType.NONE) {
// Register the new left mouse click in the edit status.
editStatus.addClickPoint();
// Get the 'adjusted' X & Y position back from the edit status.
Point pictureClickPoint = editStatus.getClickPoint();
x = (int) pictureClickPoint.getX();
y = (int) pictureClickPoint.getY();
// Get the previous mouse click point for use with Line, Pen, Step.
int previousX = 0;
int previousY = 0;
Point previousClickPoint = editStatus.getPreviousClickPoint();
if (previousClickPoint != null) {
previousX = (int) previousClickPoint.getX();
previousY = (int) previousClickPoint.getY();
}
// If a given tool is active then update the AGI picture.
if (editStatus.isFillActive()) {
picture.fill(x, y);
if (editStatus.isFirstClick()) {
picture.addPictureCode(PictureCodeType.DRAW_FILL);
}
picture.addPictureCode(PictureCodeType.FILL_POINT_DATA, x, y);
} else if (editStatus.isLineActive()) {
switch (editStatus.getNumOfClicks()) {
case 1:
picture.addPictureCode(PictureCodeType.DRAW_LINE);
picture.addPictureCode(x, y);
picture.putPixel(x, y);
break;
default:
picture.addPictureCode(x, y);
picture.drawLine(previousX, previousY, x, y);
break;
}
} else if (editStatus.isPenActive()) {
int disp = 0;
int dX = 0;
int dY = 0;
switch (editStatus.getNumOfClicks()) {
case 1:
picture.addPictureCode(PictureCodeType.DRAW_SHORT_LINE);
picture.addPictureCode(x, y);
picture.putPixel(x, y);
break;
default:
dX = adjustForPen(x - previousX, 6);
dY = adjustForPen(y - previousY, 7);
x = previousX + dX;
y = previousY + dY;
if (dX < 0) {
disp = (0x80 | ((((-1) * dX) - 0) << 4));
} else {
disp = (dX << 4);
}
if (dY < 0) {
disp |= (0x08 | (((-1) * dY) - 0));
} else {
disp |= dY;
}
picture.addPictureCode(PictureCodeType.RELATIVE_POINT_DATA, disp, new Point(x, y));
picture.drawLine(previousX, previousY, x, y);
editStatus.setClickPoint(new Point(x, y));
break;
}
} else if (editStatus.isBrushActive()) {
int patNum = 0;
if (editStatus.isFirstClick()) {
picture.addPictureCode(PictureCodeType.SET_BRUSH_TYPE);
picture.addPictureCode(PictureCodeType.BRUSH_TYPE_DATA, editStatus.getBrushCode());
picture.addPictureCode(PictureCodeType.DRAW_BRUSH_POINT);
}
patNum = (((new java.util.Random().nextInt(255)) % 0xEE) >> 1) & 0x7F;
picture.plotPattern(patNum, x, y);
if (editStatus.getBrushTexture() == BrushTexture.SPRAY) {
picture.addPictureCode(PictureCodeType.BRUSH_PATTERN_DATA, patNum << 1);
}
picture.addPictureCode(PictureCodeType.BRUSH_POINT_DATA, x, y);
} else if (editStatus.isStepActive()) {
int dX = 0;
int dY = 0;
switch (editStatus.getNumOfClicks()) {
case 1:
break;
case 2:
dX = x - previousX;
dY = y - previousY;
if (Math.abs(dX) > Math.abs(dY)) { /* X or Y corner */
y = previousY;
editStatus.setStepType(StepType.XCORNER);
picture.addPictureCode(PictureCodeType.DRAW_HORIZONTAL_STEP_LINE);
picture.addPictureCode(previousX, previousY);
picture.addPictureCode(PictureCodeType.X_POSITION_DATA, x, new Point(x, y));
} else {
x = previousX;
editStatus.setStepType(StepType.YCORNER);
picture.addPictureCode(PictureCodeType.DRAW_VERTICAL_STEP_LINE);
picture.addPictureCode(previousX, previousY);
picture.addPictureCode(PictureCodeType.Y_POSITION_DATA, y, new Point(x, y));
}
picture.drawLine(previousX, previousY, x, y);
editStatus.setClickPoint(new Point(x, y));
break;
default:
if ((editStatus.isXCornerActive() && ((editStatus.getNumOfClicks() % 2) > 0)) || (editStatus.isYCornerActive() && ((editStatus.getNumOfClicks() % 2) == 0))) {
// X and Y corners toggle different direction based on number of clicks.
x = previousX;
picture.addPictureCode(PictureCodeType.Y_POSITION_DATA, y, new Point(x, y));
} else {
y = previousY;
picture.addPictureCode(PictureCodeType.X_POSITION_DATA, x, new Point(x, y));
}
picture.drawLine(previousX, previousY, x, y);
editStatus.setClickPoint(new Point(x, y));
break;
}
}
}
}
// Is it the RIGHT mouse button?
if (mouseButton == MouseEvent.BUTTON3) {
// Right-clicking on the AGI picture will clear the current tool selection.
if ((editStatus.getNumOfClicks() == 1) && (editStatus.isStepActive())) {
// Single point line support for the Step tool.
// Get the 'adjusted' X & Y position back from the edit status.
editStatus.addClickPoint();
Point pictureClickPoint = editStatus.getClickPoint();
x = (int) pictureClickPoint.getX();
y = (int) pictureClickPoint.getY();
// Get the previous mouse click point for use with single point Step.
int previousX = 0;
int previousY = 0;
Point previousClickPoint = editStatus.getPreviousClickPoint();
if (previousClickPoint != null) {
previousX = (int) previousClickPoint.getX();
previousY = (int) previousClickPoint.getY();
}
// The X/Y corner decision for single point is based on where right click was.
int dX = x - previousX;
int dY = y - previousY;
if (Math.abs(dX) > Math.abs(dY)) { /* X or Y corner */
picture.addPictureCode(PictureCodeType.DRAW_HORIZONTAL_STEP_LINE);
picture.addPictureCode(previousX, previousY);
} else {
picture.addPictureCode(PictureCodeType.DRAW_VERTICAL_STEP_LINE);
picture.addPictureCode(previousX, previousY);
}
picture.putPixel(previousX, previousY);
}
if (editStatus.getNumOfClicks() > 0) {
// If a tool is active (i.e. has a least one click) then right click resets
// number of clicks, which allows the user to move to new location.
editStatus.resetTool();