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

added infix-command-blocks

parent 345837eb
No related branches found
No related tags found
1 merge request!1Dev preferences
...@@ -7,7 +7,6 @@ import java.awt.geom.Point2D; ...@@ -7,7 +7,6 @@ import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import edu.mit.blocks.renderable.RenderableBlock; import edu.mit.blocks.renderable.RenderableBlock;
import edu.mit.blocks.codeblocks.rendering.BlockShapeUtil; import edu.mit.blocks.codeblocks.rendering.BlockShapeUtil;
/** /**
...@@ -47,7 +46,13 @@ public class InfixBlockShape extends BlockShape { ...@@ -47,7 +46,13 @@ public class InfixBlockShape extends BlockShape {
if (block.hasAfterConnector() && !rb.isCollapsed()) { if (block.hasAfterConnector() && !rb.isCollapsed()) {
//control connector if necessary //control connector if necessary
// Trying left-aligned ports // Trying left-aligned ports
Point2D p = BCS.addControlConnectorShape(gpBottom, (float) COMMAND_PORT_OFFSET + blockCornerRadius, true);
//added by letsgoING
//TODO: TEST
BlockConnector socket = block.getSocketAt(0);
int socketLabelOffset = (int) Math.max(socket.getLabel().length(), COMMAND_PORT_OFFSET);
Point2D p = BCS.addControlConnectorShape(gpBottom, socketLabelOffset + blockCornerRadius, true);
rb.updateSocketPoint(block.getAfterConnector(), p); rb.updateSocketPoint(block.getAfterConnector(), p);
} }
...@@ -55,20 +60,32 @@ public class InfixBlockShape extends BlockShape { ...@@ -55,20 +60,32 @@ public class InfixBlockShape extends BlockShape {
//for each socket in the iterator //for each socket in the iterator
int socketCounter = 0; //need to use this to determine which socket we're on int socketCounter = 0; //need to use this to determine which socket we're on
for (BlockConnector curSocket : block.getSockets()) { for (BlockConnector curSocket : block.getSockets()) {
//if bottom socket //if bottom socket
if (curSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) { if (curSocket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
//move away from bottom left corner //move away from bottom left corner
if (socketCounter > 0) { if(!block.isCommandBlock()) {
gpBottom.lineTo( if (socketCounter > 0) {
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER, gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getY()); (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER,
}else { (float) gpBottom.getCurrentPoint().getY());
gpBottom.lineTo( }else {
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER, gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getY()); (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER,
} (float) gpBottom.getCurrentPoint().getY());
}
} else { //added by letsgoING
//TODO: TEST
if (socketCounter > 0) {
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + rb.getSocketLabelWidth(socketCounter),
(float) gpBottom.getCurrentPoint().getY());
}else {
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + rb.getBlockLabelWidth() + rb.getSocketLabelWidth(socketCounter),
(float) gpBottom.getCurrentPoint().getY());
}
}
//move down so bevel doesn't screw up from connecting infinitely sharp corner //move down so bevel doesn't screw up from connecting infinitely sharp corner
...@@ -150,16 +167,22 @@ public class InfixBlockShape extends BlockShape { ...@@ -150,16 +167,22 @@ public class InfixBlockShape extends BlockShape {
//System.out.println("gpbottom starting point: "+gpBottom.getCurrentPoint()); //System.out.println("gpbottom starting point: "+gpBottom.getCurrentPoint());
//// draw RIGHT to create divider //// //// draw RIGHT to create divider ////
if (socketCounter < block.getNumSockets() - 1) { if(!block.isCommandBlock()) {
if (socketCounter < block.getNumSockets() - 1) {
gpBottom.lineTo( //need to add the width of the block label. warning: this assumes that there is only one block label
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER + rb.accomodateLabelsWidth(),
(float) gpBottom.getCurrentPoint().getY());
} else {
gpBottom.lineTo( //need to add the width of the block label. warning: this assumes that there is only one block label
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER,
(float) gpBottom.getCurrentPoint().getY());
}
}else {
gpBottom.lineTo( //need to add the width of the block label. warning: this assumes that there is only one block label gpBottom.lineTo( //need to add the width of the block label. warning: this assumes that there is only one block label
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER + rb.accomodateLabelsWidth(), (float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_MIDDLE_SPACER +5 ,
(float) gpBottom.getCurrentPoint().getY());
} else {
gpBottom.lineTo(
(float) gpBottom.getCurrentPoint().getX() + BOTTOM_SOCKET_SIDE_SPACER,
(float) gpBottom.getCurrentPoint().getY()); (float) gpBottom.getCurrentPoint().getY());
} }
socketCounter++; socketCounter++;
} }
} }
...@@ -241,46 +264,47 @@ public class InfixBlockShape extends BlockShape { ...@@ -241,46 +264,47 @@ public class InfixBlockShape extends BlockShape {
int width = super.determineBlockWidth(); int width = super.determineBlockWidth();
int socketCounter = 0;
int bottomSocketWidth = 0; int bottomSocketWidth = 0;
if(block.isCommandBlock()) {
bottomSocketWidth += COMMAND_PORT_OFFSET;
}
for (BlockConnector socket : block.getSockets()) { for (BlockConnector socket : block.getSockets()) {
if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) { if (socket.getPositionType() == BlockConnector.PositionType.BOTTOM) {
if (socket.getBlockID() == Block.NULL) { if (socket.getBlockID() == Block.NULL) {
//3 socket spacers = left of socket, between connectors, right of socket //3 socket spacers = left of socket, between connectors, right of socket
bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER; bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER;
if(block.isCommandBlock()) {//added by letsgoING for new setVariableBlock test
//TODO get correct size of socket
bottomSocketWidth += rb.accomodateLabelsWidth();
}
} else { //a block is connected to socket } else { //a block is connected to socket
//TODO get their assigned width from rb //TODO get their assigned width from rb
if (rb.getSocketSpaceDimension(socket) != null) { if (rb.getSocketSpaceDimension(socket) != null) {
bottomSocketWidth += rb.getSocketSpaceDimension(socket).width; bottomSocketWidth += rb.getSocketSpaceDimension(socket).width;
if(block.isCommandBlock()) {//added by letsgoING for new setVariableBlock test }
//TODO get correct size of socket
bottomSocketWidth += rb.accomodateLabelsWidth();
}
}
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
// if it's a mirror plug, subtract for the other side, too. // if it's a mirror plug, subtract for the other side, too.
if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) { if (rb.getWorkspace().getEnv().getBlock(socket.getBlockID()).getPlug().getPositionType() == BlockConnector.PositionType.MIRROR) {
bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH; bottomSocketWidth -= BlockConnectorShape.NORMAL_DATA_PLUG_WIDTH;
} }
} }
bottomSocketWidth += rb.getSocketLabelWidth(socketCounter) + 1;
} }
bottomSocketWidth += BOTTOM_SOCKET_MIDDLE_SPACER;
bottomSocketWidth += BOTTOM_SOCKET_SIDE_SPACER;
socketCounter++;
} }
//bottomSocketWidth += 2 * BOTTOM_SOCKET_MIDDLE_SPACER; //TODO need to decide for a size of the middle spacer and how to place them
//bottomSocketWidth += 2 * BOTTOM_SOCKET_SIDE_SPACER;
/* if (bottomSocketWidth > width) {
bottomSocketWidth += 2 * BOTTOM_SOCKET_MIDDLE_SPACER; //TODO need to decide for a size of the middle spacer and how to place them
bottomSocketWidth += 2 * BOTTOM_SOCKET_SIDE_SPACER;
if (bottomSocketWidth > width) {
return (bottomSocketWidth + rb.accomodateLabelsWidth()); return (bottomSocketWidth + rb.accomodateLabelsWidth());
} }
*/
width += bottomSocketWidth;
//width += bottomSocketWidth;
width = bottomSocketWidth + rb.getBlockLabelWidth();// + rb.accomodateLabelsWidth();
//make sure its even //make sure its even
if (width % 2 == 1) { if (width % 2 == 1) {
......
...@@ -35,13 +35,15 @@ class NameLabel extends BlockLabel { ...@@ -35,13 +35,15 @@ class NameLabel extends BlockLabel {
} }
if (rb.getBlock().isInfix()) { if (rb.getBlock().isInfix()) {
//added by letsgoING for new setVariableBlock test //added by letsgoING for new setVariableBlock test
if(rb.getBlock().isCommandBlock()) { /* if(rb.getBlock().isCommandBlock()) {
if (!rb.getBlock().getSocketAt(0).hasBlock()) { if (!rb.getBlock().getSocketAt(0).hasBlock()) {
x += 60; x += 0;
} else { } else {
x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width+30; x += rb.getSocketSpaceDimension(rb.getBlock().getSocketAt(0)).width+30;
} }
}else { }else {
*/
if(!rb.getBlock().isCommandBlock()) {
if (!rb.getBlock().getSocketAt(0).hasBlock()) { if (!rb.getBlock().getSocketAt(0).hasBlock()) {
x += 30; x += 30;
} else { } else {
......
...@@ -693,6 +693,43 @@ public class RenderableBlock extends JComponent implements SearchableElement, ...@@ -693,6 +693,43 @@ public class RenderableBlock extends JComponent implements SearchableElement,
} }
return width; return width;
} }
/**
* Determine the width necessary to accommodate for placed block labels. Used to
* determine the position of sockets
*
* @return int pixel width needed for the labels
*/
public int getBlockLabelWidth() {
int width = 0;
if (getBlock().hasPageLabel()) {
width += Math.max(blockLabel.getAbstractWidth(),
pageLabel.getAbstractWidth());
width += getControlLabelsWidth();
} else {
width += blockLabel.getAbstractWidth();
width += getControlLabelsWidth() + 4;
}
return width;
}
/**
* Determine the width necessary to accommodate for placed socket labels. Used to
* determine the position of sockets.
* by letsgoING
* @return int pixel width needed for the labels
*/
public int getSocketLabelWidth(int socketPosition) {
int width = 0;
SocketLabel label = socketTags.get(socketPosition).getLabel();
if (label != null) {
width = label.getAbstractWidth();
}
return width;
}
/** /**
* Returns the width of the page label on this block; if page label is not * Returns the width of the page label on this block; if page label is not
......
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