Hello, I wonder how do I change my mouse event because I would like to X.Caption activates only when I right-clicked on it. thank you very much
3 Answers
If I'm correct ( other contributors, don't be afraid to correct me ), you might have to edit the internals of XTK for your needs. XTK has the "controls" defined in X.event.js
for it's event such as HoverEvent
and PanEvent
which are acquired from the Google Closure Library. You can look into the Google Closure Library more as I haven't completely reviewed it, but X.caption
is mostly derived from Goog.ui.Tooltip
which can be used with the events from Goog.ui.Popup
, Goog.ui.PopupBase
, and Goog.events
. You can try to include Goog.events
into your Javascript and define your own click event or something related to that and look through the Google Closure Library some more.
If what I just wrote in the small paragraph above is not completely correct or anything like that, there are of course basic Javascript DOM Events for clicking. I'm not quite sure how those would work with XTK because XTK uses WebGL for rendering. You can review the basic events at http://www.w3schools.com/jsref/dom_obj_event.asp. If you find any solution for yourself, you are more than welcome to contribute it to XTK.

- 314
- 1
- 2
- 13
-
Don't forget to look through the internals of XTK as they can be more useful than posting a question online. For your problem, look through `X.event.js`, `X.interactor.js`, and `X.caption.js`. – Karijuana Jul 30 '12 at 20:20
I think there are too ways no ? Change the xtk source code and compile your own version or something like this :
window.onload = function() {
myrenderer.config.HOVERING_ENABLED = false; // disabling show caption on mousehover
var mouse_x, mouse_y;
myrenderer.interactor.onMouseMove = function(event) {
mouse_x = event.offsetX;
mouse_y = event.offsetY;
}
myrenderer.interactor.onMouseDown = function(left,middle, right) {
if (right) {
var picked_id = myrenderer.pick(mouse_x, mouse_y);
if (picked_id==-1) throw new Error("No object");
var picked_object = myrenderer.get(picked_id);
var mycontainer = myrenderer.container;
var caption = new X.caption(mycontainer,mycontainer.offsetLeft + mouse_x + 10, mycontainer.offsetTop + mouse_y + 10,myrenderer.interactor);
caption.setHtml(picked_object.caption);
// use settimeout or something else to destroy the caption
}
}
}

- 2,402
- 17
- 16
The following JSFiddle shows how to do that. To actually display a tooltip etc. you can use any JS Library like jQuery UI.

- 967
- 1
- 6
- 19
-
The JSfiddle is cool, but there's a glitch on Chrome where once I kill that caption/tooltip and it's hovering over canvas, canvas still thinks youre holding the right mouse button and will start to zoom-in and -out from the XTK interactions. – Karijuana Aug 08 '12 at 19:41