Tooltip in Paper.js - paperjs

I am a beginner in Paper.js . Please could someone tell me how to display tool tip on a paper.js object ? The tool tip should be visible when the mouse moves over the object and should disappear when the mouse moves away from the object .
Thank you.

When drawing your object you want to create a popup for, first add it to a group, then use the onMouseEnter and onMouseLeave handlers on that object:
// Create a group
var group = new Group();
// Create a dot (circle the mouse will hover)
var point = new Point(50, 50);
var dot = new Path.Circle(point, 5);
dot.fillColor = 'blue';
// Add dot to group
group.addChild(dot);
// Create onMouseEnter event for dot
dot.onMouseEnter = function(event) {
// Layout the tooltip above the dot
var tooltipRect = new Rectangle(this.position + new Point(-20, -40), new Size(40, 28));
// Create tooltip from rectangle
var tooltip = new Path.Rectangle(tooltipRect);
tooltip.fillColor = 'white';
tooltip.strokeColor = 'black';
// Name the tooltip so we can retrieve it later
tooltip.name = 'tooltip';
// Add the tooltip to the parent (group)
this.parent.addChild(tooltip);
}
// Create onMouseLeave event for dot
dot.onMouseLeave = function(event) {
// We retrieve the tooltip from its name in the parent node (group) then remove it
this.parent.children['tooltip'].remove();
}

Related

how to change the marker icon when click on it here map

After loading The heremap i set markers with custom image on it. Then After click in the marker i'm getting the bubble popup. I want to change the marker icon when click on it. How can i change the marker icon when click on it?
Code for showing bubble after click the marker as given below.
map.addObject(group);
// add 'tap' event listener, that opens info bubble, to the group
group.addEventListener('tap', function (evt) {
// event target is the marker itself, group is a parent event target
// for all objects that it contains
var bubble = new H.ui.InfoBubble(evt.target.getPosition(), {
// read custom data
content: evt.target.getData()
});
// show info bubble
ui.addBubble(bubble);
}, false);
In my application I'm changing the original color of the marker when it is clicked. Have you tried using a markerTemplate, meaning a variable where you store the svg for your marker as a string?
var markerTemplate = '<svg xmlns="http://www.w3.org/2000/svg" width="28px" height="36px">... fill="${COLOR}"/></svg>'
You can then use e.g. fill="${COLOR}" in this string and in your EventListner replace this placeholder with a new color markerTemplate.replace('${COLOR}', 'rgba(231, 0, 0, 0.7)');
Hope this helps

javafx video player timeSlider

How to make slider to move as video plays?
Initialization :
BorderPane border = new BorderPane();
HBox bar = new HBox(10);
//Button play = new Button("Play");
//Button pause = new Button("Pause");
Media:
Media media = new Media(Paths.get("C://video.mp4").toUri().toString());
MediaPlayer player = new MediaPlayer(media);
MediaView mediaView = new MediaView(player);
Positioning :
bar.getChildren().addAll(play,pause,timeSlider);
bar.setAlignment(Pos.CENTER);
border.setCenter(mediaView);
border.setBottom(bar);
Any suggestions how to make my slider move as video plays?
Edit:
Found answer :
player.currentTimeProperty().addListener((obs, oldTime, newTime) -> {
if (!timeSlider.isValueChanging()) {
timeSlider.setValue(newTime.toSeconds());
}
});
I'm working on a similar problem right now. This should work for you:
// Listen to the slider. When it changes, seek with the player.
// MediaPlayer.seek does nothing when the player is stopped, so the play/pause button's handler
// always sets the start time to the slider's current value, and then resets it to 0 after starting the player.
InvalidationListener sliderChangeListener = o-> {
Duration seekTo = Duration.seconds(timeSlider.getValue());
player.seek(seekTo);
});
timeSlider.valueProperty().addListener(sliderChangeListener);
// Link the player's time to the slider
player.currentTimeProperty().addListener(l-> {
// Temporarily remove the listener on the slider, so it doesn't respond to the change in playback time
// I thought timeSlider.isValueChanging() would be useful for this, but it seems to get stuck at true
// if the user slides the slider instead of just clicking a position on it.
timeSlider.valueProperty().removeListener(sliderChangeListener);
// Keep timeText's text up to date with the slider position.
Duration currentTime = player.getCurrentTime();
int value = (int) currentTime.toSeconds();
timeSlider.setValue(value);
// Re-add the slider listener
timeSlider.valueProperty().addListener(sliderChangeListener);
});

amStock (Flex) programmatic scroll

I would like to scroll the amcharts flex stock chart programmatically on it's horizontal axis, in other words along the time axis.
I need to do this, because I need to scroll one period at a time and would like to hook this up to keyboard events.
I couldn't find anything in the documentation here: http://flex.amcharts.com/stock_class_reference/com/amcharts/stock/package-detail.html
I've also tried mucking around with the period selector to see whether I can change the values on it, but no luck there.
You should simply set some interval and zoom chart each time. For example:
private function initialZoom():void
{
var firstDate:Date = dataSet.dataProvider[0].date;
var endDate:Date = new Date(firstDate);
endDate.setDate(endDate.getDate() + 20);
chart.zoom(firstDate, endDate);
setInterval(zoomChart, 1000);
}
private function zoomChart():void
{
var startDate:Date = new Date(chart.startDate);
var endDate:Date = new Date(chart.endDate);
startDate.setDate(startDate.getDate() + 1);
endDate.setDate(endDate.getDate() + 1);
chart.zoom(startDate, endDate);
}
initialZoom should be called on dataUpdated event fired by AmStockChart. Note, you shouldn't set any period as "selected" in order this to work.

Check transparency

I have swf file(900x600) and main part of that file is transparense.
So I want by clicking in swf file know either user clicks on transaprent part of image or not...
I can get mouse coordinates by
event.localX
event.localY
So how to know in clicked part swf is transparent or not?
First of all, be sure, that you have some transparent sprite on background of your swf - otherwise you won't receive event.
Second, do not use pure local coordinates, they can contain local coordinates of another inner object, while you need them from root. For example, I've used stage's coordinates
If you receive mouse event, add mouse event listener to the root of that swf and write following:
var bmd:BitmapData = new BitmapData(1, 1, true, 0);
var pt:Point = new Point();
var m:Matrix = new Matrix();
m.translate(-e.stageX, -e.stageY);
bmd.draw(this, m);
var transparent:Boolean = !bmd.hitTest(pt, 0x00, pt);
trace('color: '+bmd.getPixel32(0,0).toString(16));
trace('is tranparent? ' + transparent);
bmd.dispose();
You can add an event listener on the stage for a mouse click, and check if e.target == stage.
Here is the code:
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.CLICK, hClick);
function hClick(e : MouseEvent) : void
{
trace(e.target == stage); // true if we click on the transparent zone, false if we hit a symbol on the stage.
}
Not the best or cleanest code but it should work.
This is not tested code I just whipped it up.
private function handleMouseDown(event:MouseEvent):void {
var pt:Point = new Point(event.localX, event.localY);
pt = event.target.globalToLocal(pt);
var tmp:int = int( (new uint( event.target.getPixel32(pt.x,pt.y) ).toString(16)).substr(0,2) );
if( tmp != 0 ){
trace( 'is transparent' )
}
}

Flex 4 Drag-n-Drop with custom DragProxy

I'm doing the drag an drop of an ItemRenderer manually (DataGrid) and want to know how to generate a custom DragProxy of a component that hasn't been added to the display list.
I tried something like this but didn't work:
private function doDrag(event:MouseEvent):void
{
var dragSource:DragSource = new DragSource();
dragSource.addData(data, 'dnd_format');
//var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(this));
var btn:Button = new Button();
btn.label = 'New Button';
var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(btn));
var dragProxy:Image = new Image();
dragProxy.source = bm;
DragManager.doDrag(this, dragSource, event, dragProxy,0,0, 0.6);
}
So, I want to be able to create the DragProxy using a component, the button is just an example.
Any ideas?
My guess is that this is not working because you are trying to get a bitmap from a component that was just created and has not been added to the stage. I would try testing this code with using an embedded image as the drag proxy first. If that works, then try getting a bitmap from a component that exists on the stage. My guess is that both cases will work.

Resources