Canvas.observe does not seem to be effective - fabricjs

I've wrote this :
// canvasRoot is a Canvas object
canvasRoot.observe('mouse:down', function() {console.log('<mouse down event>')});
But if I click anywhere on my canvas, the event does not seem to be triggered

Check if canvasRoot is an actual fabric.Canvas or the DOM canvas node ^_^
You should also use canvas.on(...) instead of canvas.observe(...) [same function anyway]
Also if you are attaching events to fabric.Canvas objects, you should attach them to "mousedown" vs "mouse:down" for canvas.
Take a look at source code for more info :)

Related

how to replace mousemove event to my robotmove event

I have a desktop robot device, which connects to a web browser(chrome) using ble(Bluetooth low energy), I have created a custom event in js code to catch some motion values when the robot moves.
but in pixijs all events are base on mouse move, how can I extend it to adapt my scenarios.
See: https://github.com/pixijs/pixi.js/blob/v6.0.0/packages/interaction/src/InteractionManager.ts#L858
I think that you would need to create your own version of InteractionManager as a plugin, and modify that method addEvents(). You would need to listen to your custom event which is fired when the robot moves.
// instead of:
self.document.addEventListener('mousemove', this.onPointerMove, true);
// do like this:
self.document.addEventListener('my_custom_robot_move', this.onPointerMove, true);
etc.
Normally the InteractionManager is registered here: https://github.com/pixijs/pixi.js/blob/fe7b2191e0311b8174a012366ff21c8e2b6dc153/bundles/pixi.js/src/index.ts#L30 - so you would need to call something like this at beginning of your js code (just after the pixi scripts are loaded probably):
Renderer.registerPlugin('interaction', MyInteractionManager);

Cannot get QWindow::fromWinId to work properly

My Qt 5.9 program (on X11 Linux) launches other applications, using QProcess.
I would like to have control over windows these applications spawn, so I obtain their winId value and use QWindow::fromWinId to get a QWindow instance.
The problem is these instances are invalid and do not represent the window they are supposed to.
If I check the winId values using xwininfo, the correct information is returned, so I know they are good.
What am I doing wrong?
Edit: An example won't help much, but here goes:
QProcess *process=new QProcess(this);
...
process.open()
... // wait until window appears
WId winId=PidToWid(process->processId()); // this function returns the Window ID in decimal format. I test this with xwininfo, it's always correct
...
QWindow *appWindow=QWindow::fromWinId(winId);
... And that's basically it. appWindow is a valid QWindow instance, but it does not relate to the actual window in any way. For example, if I close() it, it returns true but the window does not close.
Even if I provide a wrong WId on purpose, the end result is the same.
This is not proper solution with explanation why it should work, however it may be helpful for somebody...
I had the same issue with my application when I switched from Qt4 QX11EmebeddedContainer to Qt5 implementation using QWindow. What I did to resolve / fix this issue was following:
Client application:
widget->show(); //Widget had to be shown
widget->createWinId();
sendWinId(widget->winId()); //Post window handle to master app where is constructed container
Master application:
QWindow* window = QWindow::fromWinId(clientWinId);
window->show(); //This show/hide toggle did trick in combination with show in client app
window->hide();
QWidget* container = QWidget::createWindowContainer(window, parentWindowWidget);
After this I was able to control window properly through QWidget container.

Callback function for Fabric.js renderAll method?

I'm using Fabric.js and need to call a function after renderAll has fully completed. This seems like simple functionality that would exist, but my searches, documentation reading, etc. has come up empty. If anyone has a solution, I'd greatly appreciate it.
canvas.deactivateAll().renderAll();
// I need a save function called here, after the above has completed
I've tried binding to the after:render method of the canvas, but that gets called with each object, rather than all objects.
canvas.on('after:render', function() {
// call the save function here
});
I suppose what I could do is count the number of canvas objects, then increment a counter on the after:render method, then check to see if the counter === the number of objects, and if it does, then call the save function. That seems rather convoluted to me though.
(As more background, in case there is another way to achieve what I need, I need to save a canvas image, but first need to deselect all objects so the image isn't saved with the handles showing.)
I found a solution using the deactivateAllWithDispatch method, which fires the selection:cleared listener event. In that event function, I'm executing the deactivateCallback method if it's set.
canvas.on('selection:cleared', function() {
if (deactivateCallback) {
executeCallbackFunction(renderCallback, window);
deactivateCallback = null;
}
});
deactivateCallback = callback;
canvas.deactivateAllWithDispatch();
(note: the executeCallbackFunction in the above code isn't directly related to the answer, and just executes a function that has been passed in as a string)
So what you need is to deactivate all elements. I don't know why canvas.deactivateAll() isn't ok. Does this jsFiddle help you.

jscrollpane colors

I'm trying to modify the scrollbar colors for jscrollpane.
This didn't work for me:
$('a.athlete_popup_content').click(function(){
$('#box_on_top').append($content); //.athlete class is within $content
$('.athlete').jScrollPane({autoReinitialise: true});
$('.jspVerticalBar').css('width', '10px');
$('.jspTrack').css('background','lightgrey');
$('.jspDrag').css('background','black');
$('.athlete').jScrollPane({autoReinitialise: true});
});
i tried placing athlete class both before and after... it doesn't do anything... also, the second time this runs, the scrollbar doesn't appear at all.
any help?
-=update=-
For the issue where it does not appear correctly the second time, I had to destroy the jsp on close and it started working.
var element = $('.athlete').jScrollPane();
var api = element.data('jsp');
api.destroy();
I was unable to get the colors to work.
I am including the .css initially, but want to change the colors on load. I wasn't able to figure out this issue so I just modified the .css
Thanks!
Your code es working perfectly, as you can see here. If you are calling jScrollPane() on a click event then the tags you are trying to reach (.jspVerticalBar, .jspTrack, .jspDrag) are created after css() calls, then you should use .on() to attach those calls to the event.

How to attach mouse event listeners to embedded nsIWebBrowser in C++

I've embedded an nsIWebBrowser in my application. Because I'm just generating HTML for it on the fly, I'm using OpenStream, AppendToStream, and CloseStream to add content. What I need is to add event listeners for mouse movement over the web browser as well as mouse clicks. I've read documentation and tried lots of different things, but nothing I have tried has worked. For instance, the code below would seem to do the right thing, but it does nothing:
nsCOMPtr<nsIDOMWindow> domWindow;
mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!mEventTarget) {
mEventTarget = do_QueryInterface(domWindow);
if (mEventTarget)
mEventTarget->AddEventListener(NS_LITERAL_STRING("mouseover"), (nsIDOMEventListener *)mEventListener, PR_FALSE);
}
Perhaps it isn't working because this is run during initialization, but before any content is actually added. However, if I add it during AppendStream, or CloseStream, it segfaults.
Please tell me a straightforward way to do this.
Well, here's the answer:
nsCOMPtr<nsIDOMEventTarget> cpEventTarget;
nsCOMPtr<nsIDOMWindow> cpDomWin;
m_pWebBrowser->GetContentDOMWindow (getter_AddRefs(cpDomWin));
nsCOMPtr<nsIDOMWindow2> cpDomWin2 (do_QueryInterface (cpDomWin));
cpDomWin2->GetWindowRoot(getter_AddRefs(cpEventTarget));
rv = cpEventTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
m_pBrowserImpl, PR_FALSE);

Resources