You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.8 KiB
73 lines
1.8 KiB
/**
|
|
*
|
|
*/
|
|
package com.jotuntech.sketcher.client.command;
|
|
|
|
import java.awt.AlphaComposite;
|
|
import java.nio.ByteBuffer;
|
|
|
|
import com.jotuntech.sketcher.client.Client;
|
|
import com.jotuntech.sketcher.client.Command;
|
|
import com.jotuntech.sketcher.client.Connection;
|
|
import com.jotuntech.sketcher.common.Input;
|
|
import com.jotuntech.sketcher.common.Layer;
|
|
import com.jotuntech.sketcher.common.User;
|
|
|
|
|
|
public class LineCommand implements Command {
|
|
protected Input input;
|
|
|
|
/** Constructs a Daub command */
|
|
public LineCommand() {
|
|
|
|
}
|
|
|
|
/** Constructs a Daub command.
|
|
* @param user Source user.
|
|
* @param input Position of new daub. */
|
|
public LineCommand(Input input) {
|
|
this.input = input;
|
|
}
|
|
|
|
public int perform(Client client, User user) {
|
|
if(user != null && user.getLayer() != null && user.getBrush() != null) {
|
|
if(user.isViewer()) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
Layer l = user.getPhantomLayer();
|
|
l.setOpacity(Math.abs(user.getBrush().getOpacity()) / 255f);
|
|
if(user.getBrush().isLockTransparency()) {
|
|
l.setAlphaRule(AlphaComposite.SRC_ATOP);
|
|
} else if(user.getBrush().getOpacity() >= 0) {
|
|
l.setAlphaRule(AlphaComposite.SRC_OVER);
|
|
} else {
|
|
l.setAlphaRule(AlphaComposite.DST_OUT);
|
|
}
|
|
|
|
/** Draw line */
|
|
Input end = user.getPhantomLayer().line(user.getCursor(), input, user.getColor(), user.getBrush(), user.getLayer());
|
|
|
|
if(end != null) {
|
|
/** Move cursor on success */
|
|
user.setCursor(end);
|
|
|
|
/** Return and broadcast */
|
|
return Connection.SEND_OTHERS;
|
|
}
|
|
}
|
|
|
|
/** Return silently */
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
input = new Input();
|
|
input.decode(in);
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
input.encode(out);
|
|
}
|
|
}
|
|
|
|
|