How to highlight a block in a yellow bubble

1,355 views
Skip to first unread message

Abhigya jain

unread,
Aug 3, 2017, 5:42:45 AM8/3/17
to Blockly
Hi,

I want to highlight a block in a yellow bubble when i run my blocks.

I am using workspace.highlight(id) method provided by blockly. It lightens the color of the currently executing block. I would ideally want a yellow bubble to appear around the block as it highlights.

Can somebody please help me with it.

Thanks 
Abhigya

Neil Fraser

unread,
Aug 3, 2017, 6:09:47 AM8/3/17
to blo...@googlegroups.com
The highlighting is set in this function:
core/block_svg.js
Blockly.BlockSvg.prototype.setHighlighted

Because I was in a rush when programming it, at the moment it is just reusing the 'emboss' filter that's also used for bubbles.  It would be great to create a separate filter that looks better.  There's a bug open for this:
https://github.com/google/blockly/issues/750


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Nimeshka Srimal

unread,
Aug 17, 2017, 3:34:09 AM8/17/17
to Blockly
Hi Abighya,

Highlight function is in the block_svg.js. You can call the same function they call when you click on a block (it highlights the block with a yellow button when you select the block)

If that's what you want, you can change the Blockly.BlockSvg.prototype.setHighlighted function in block_svg.js. Just replace it with below;

Blockly.BlockSvg.prototype.setHighlighted = function(highlighted) {
if (!this.rendered) {
return;
}
if (highlighted) {
this.addSelect();
/*
this.svgPath_.setAttribute('filter',
'url(#' + this.workspace.options.embossFilterId + ')');
this.svgPathLight_.style.display = 'none';
*/
} else {
this.removeSelect();
/*
Blockly.utils.removeAttribute(this.svgPath_, 'filter');
delete this.svgPathLight_.style.display;
*/
}
};


If you want to keep the yellow bubble and emboss both, uncomment the lines inside the above function :)

Neil Fraser

unread,
Aug 17, 2017, 11:14:27 AM8/17/17
to blo...@googlegroups.com
Note that the above solution makes it impossible to edit programs while the program is running since random blocks are being selected and unselected.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nimeshka Srimal

unread,
Aug 18, 2017, 12:20:54 AM8/18/17
to Blockly, ro...@neil.fraser.name
this.addSelect(); is only adding a css class to the block, isn't it? Does it have any effect on the running program?

I think it's this.select(); that really selects the block?
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Neil Fraser

unread,
Aug 18, 2017, 2:58:23 AM8/18/17
to blo...@googlegroups.com
You're right.  My mistake.

To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Livio Cicala

unread,
Nov 13, 2022, 8:17:37 AM11/13/22
to Blockly
For me the:  this.addSelect()   
works ok and the hilighted bloks are selected.

But uncommenting the emboss filter lines all breaks, 
no selection, no filter, and the running is stopped too.
Reply all
Reply to author
Forward
0 new messages