Skip to content
Snippets Groups Projects
Commit 8e54e8a8 authored by Anian Bühler's avatar Anian Bühler
Browse files

redesigned infixBlockShape and added "Command"-connectors

parent ce38c100
No related branches found
No related tags found
No related merge requests found
......@@ -43,13 +43,19 @@ public class InfixBlockShape extends BlockShape {
//curve down and right
BlockShapeUtil.cornerTo(gpBottom, botLeftCorner, botRightCorner, blockCornerRadius);
//added by letsgoING for new setVariableBlock test
if (block.hasAfterConnector() && !rb.isCollapsed()) {
//control connector if necessary
// Trying left-aligned ports
Point2D p = BCS.addControlConnectorShape(gpBottom, (float) COMMAND_PORT_OFFSET + blockCornerRadius, true);
rb.updateSocketPoint(block.getAfterConnector(), p);
}
/// BOTTOM SOCKETS
//for each socket in the iterator
int socketCounter = 0; //need to use this to determine which socket we're on
for (BlockConnector curSocket : block.getSockets()) {
//if bottom socket
if (curSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
......@@ -58,17 +64,22 @@ public class InfixBlockShape extends BlockShape {
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER,
(float) gpBottom.getCurrentPoint().getY());
} else {
} else if(block.isCommandBlock()) { //TODO: check //added by letsgoING for new setVariableBlock test
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER,
(float) gpBottom.getCurrentPoint().getY());
} else {
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER ,
(float) gpBottom.getCurrentPoint().getY());
}
//move down so bevel doesn't screw up from connecting infinitely sharp corner
// as occurs from a curved port
BlockShapeUtil.lineToRelative(gpBottom, 0, -0.1f);
//////////////////////
//begin drawing socket
//////////////////////
......@@ -232,27 +243,46 @@ public class InfixBlockShape extends BlockShape {
//System.out.println("determining block width");
int width = super.determineBlockWidth();
//if the sum of bottom sockets is greater than the calculated width, then use it
int bottomSocketWidth = 0;
for (BlockConnector socket : block.getSockets()) {
if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
if (socket.getBlockID() == Block.NULL) {
//3 socket spacers = left of socket, between connectors, right of socket
bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER;
} else { //a block is connected to socket
//TODO get their assigned width from rb
if (rb.getSocketSpaceDimension(socket) != null) {
bottomSocketWidth += rb.getSocketSpaceDimension(socket).width;
}
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
// if it's a mirror plug, subtract for the other side, too.
if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) {
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
//added by letsgoING for new setVariableBlock test
if (block.isCommandBlock()) {
for (BlockConnector socket : block.getSockets()) {
if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
if (socket.getBlockID() == Block.NULL) {
//3 socket spacers = left of socket, between connectors, right of socket
bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER + BOTTOM_SOCKET_MIDDLE_SPACER;
} else { //a block is connected to socket
//TODO get their assigned width from rb
if (rb.getSocketSpaceDimension(socket) != null) {
bottomSocketWidth += rb.getSocketSpaceDimension(socket).width;
}
}
}
}
}
//if the sum of bottom sockets is greater than the calculated width, then use it
else {
for (BlockConnector socket : block.getSockets()) {
if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
if (socket.getBlockID() == Block.NULL) {
//3 socket spacers = left of socket, between connectors, right of socket
bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER;
} else { //a block is connected to socket
//TODO get their assigned width from rb
if (rb.getSocketSpaceDimension(socket) != null) {
bottomSocketWidth += rb.getSocketSpaceDimension(socket).width;
}
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
// if it's a mirror plug, subtract for the other side, too.
if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) {
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
}
}
}
}
}
bottomSocketWidth += 2 * BOTTOM_SOCKET_MIDDLE_SPACER; //TODO need to decide for a size of the middle spacer and how to place them
......
......@@ -34,11 +34,20 @@ class NameLabel extends BlockLabel {
x += 4 + BlockConnectorShape.getConnectorDimensions(rb.getBlock().getPlug()).width;
}
if (rb.getBlock().isInfix()) {
if (!rb.getBlock().getSocketAt(0).hasBlock()) {
x += 30;
} else {
x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width;
}
//added by letsgoING for new setVariableBlock test
if(rb.getBlock().isCommandBlock()) {
if (!rb.getBlock().getSocketAt(0).hasBlock()) {
x += 60;
} else {
x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width+30;
}
}else {
if (!rb.getBlock().getSocketAt(0).hasBlock()) {
x += 30;
} else {
x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width;
}
}
}
if (rb.getBlockWidget() == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment