File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed
Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,12 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
5656
5757 bool topLevel () const ;
5858
59+ int x () const ;
60+ void setX (int x);
61+
62+ int y () const ;
63+ void setY (int y);
64+
5965 std::shared_ptr<Comment> comment () const ;
6066 const std::string &commentId () const ;
6167 void setComment (std::shared_ptr<Comment> comment);
Original file line number Diff line number Diff line change @@ -313,6 +313,36 @@ bool Block::topLevel() const
313313 return (impl->parentId == " " && !impl->parent );
314314}
315315
316+ /* ! Returns the X-coordinate of the block in the code area (only for top level blocks). */
317+ int Block::x () const
318+ {
319+ return impl->x ;
320+ }
321+
322+ /* ! Sets the X-coordinate of the block in the code area (only for top level blocks). */
323+ void Block::setX (int x)
324+ {
325+ if (!topLevel ())
326+ std::cout << " warning: setting X-coordinate of a block which is not a top level block" << std::endl;
327+
328+ impl->x = x;
329+ }
330+
331+ /* ! Returns the Y-coordinate of the block in the code area (only for top level blocks). */
332+ int Block::y () const
333+ {
334+ return impl->y ;
335+ }
336+
337+ /* ! Sets the Y-coordinate of the block in the code area (only for top level blocks). */
338+ void Block::setY (int y)
339+ {
340+ if (!topLevel ())
341+ std::cout << " warning: setting Y-coordinate of a block which is not a top level block" << std::endl;
342+
343+ impl->y = y;
344+ }
345+
316346/* ! Returns the comment which is attached to this block. */
317347std::shared_ptr<Comment> Block::comment () const
318348{
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ struct BlockPrivate
3333 std::vector<std::shared_ptr<Field>> fields;
3434 std::unordered_map<int , Field *> fieldMap;
3535 bool shadow = false ;
36+ int x = 0 ;
37+ int y = 0 ;
3638 std::string commentId;
3739 std::shared_ptr<Comment> comment = nullptr ;
3840 IEngine *engine = nullptr ;
Original file line number Diff line number Diff line change @@ -194,6 +194,24 @@ TEST_F(BlockTest, TopLevel)
194194 ASSERT_TRUE (block.topLevel ());
195195}
196196
197+ TEST_F (BlockTest, X)
198+ {
199+ Block block (" " , " " );
200+ ASSERT_EQ (block.x (), 0 );
201+
202+ block.setX (12 );
203+ ASSERT_EQ (block.x (), 12 );
204+ }
205+
206+ TEST_F (BlockTest, Y)
207+ {
208+ Block block (" " , " " );
209+ ASSERT_EQ (block.y (), 0 );
210+
211+ block.setY (8 );
212+ ASSERT_EQ (block.y (), 8 );
213+ }
214+
197215TEST_F (BlockTest, Comment)
198216{
199217 Block block (" " , " " );
You can’t perform that action at this time.
0 commit comments