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.
68 lines
1.7 KiB
68 lines
1.7 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.BitmapLayer;
|
|
import com.jotuntech.sketcher.common.Layer;
|
|
import com.jotuntech.sketcher.common.User;
|
|
|
|
public class MoveCommand implements Command {
|
|
private float sx, sy, dx, dy, w, h;
|
|
|
|
public MoveCommand() {
|
|
|
|
}
|
|
|
|
public MoveCommand(float sx, float sy, float dx, float dy, float w, float h) {
|
|
this.sx = sx;
|
|
this.sy = sy;
|
|
this.dx = dx;
|
|
this.dy = dy;
|
|
this.w = w;
|
|
this.h = h;
|
|
}
|
|
|
|
public int perform(Client client, User user) {
|
|
if(user == null || user.getLayer() == null) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
if(user.isViewer()) {
|
|
return Connection.SEND_NONE;
|
|
}
|
|
|
|
if(user.getPhantomLayer().isEmpty()) {
|
|
Layer pl = (BitmapLayer) user.getPhantomLayer();
|
|
pl.setAlphaRule(AlphaComposite.SRC_OVER);
|
|
pl.setOpacity(1);
|
|
user.getLayer().copyTo(pl, null, false, sx, sy, dx, dy, w, h);
|
|
} else {
|
|
user.getPhantomLayer().copyTo(user.getPhantomLayer(), user.getLayer().getImageObserver(), true, sx, sy, dx, dy, w, h);
|
|
user.getPhantomLayer().clean();
|
|
}
|
|
|
|
return Connection.SEND_OTHERS;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
sx = in.getFloat();
|
|
sy = in.getFloat();
|
|
dx = in.getFloat();
|
|
dy = in.getFloat();
|
|
w = in.getFloat();
|
|
h = in.getFloat();
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
out.putFloat(sx);
|
|
out.putFloat(sy);
|
|
out.putFloat(dx);
|
|
out.putFloat(dy);
|
|
out.putFloat(w);
|
|
out.putFloat(h);
|
|
}
|
|
}
|
|
|