librocket and mousecliking


I got a silly problem using librocket, but I think with good advice, it will be ok.

I am using collisionTraverser to pick up panda node in the space.

I accepted some panda mouse events to determine when a user click or not, and determine if there is a pickup event:

	self.accept("mouse1", self.setMouseBtn, [0, 1])
		self.accept("mouse1-up", self.setMouseBtn, [0, 0])
		self.accept("mouse2", self.setMouseBtn, [1, 1])
		self.accept("mouse2-up", self.setMouseBtn, [1, 0])

and code for pickup

if self.mousebtn[2]==1:
			self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())

			if self.pq.getNumEntries() > 0:

When a pick up is detected, I open a librocket window to diplay information about the object.

But when I move the window, I use mouse click, and in my case, left mouse click is using for firing.

How to avoid to fire when I move with the title bar, a librocket window?
How can I pause the panda event? or something like this?

thank you

The answer to this question interest me very much as well.
Did you find something to work around this issue ?

EDIT: Forget it. I had an idea and searched the API for a solution. Turns out there’s a very easy one. Check this out:

Rocket::Core::Context* context = _levelUi.GetContext();

  if (context->GetHoverElement() != context->GetRootElement())
    return ;

You just have to put something like this in your Panda3D callback for mouse clicking.
It checks the current hovered element for a libRocket’s context: if it is different to the root of said context, then one of your document is hovered and you must intercept the event.

I’m not sure how you would do that with the Python bindings, but I suppose it’s doable.

Has someone found a pythonic solution for this? Pandas Python-reference doesn’t list any of those functions, although I assume, that they exist. The official API reference is only in C++ as well.

Currently, I use the following code:

python, general UI-Code:

  def addCoverRegion(cls,name,box):
  def removeCoverRegion(cls,name):
    del UI.coverRegions[name]
  def isOnUI(cls,x,y):
    for r in UI.coverRegions.itervalues():
      if(x>=r[0] and x<r[2] and y>=r[1] and y<r[3]):
        return True
    return False


  def mouse1(self):
    if base.mouseWatcherNode.hasMouse():
      if UI.isOnUI(,
      <regular code>

rml for each window:

def close():

It works, as I currently use pixel-accurate rml design. But that’s obviously not the most elegant solution.

Solved it, here is the solution for whomever may be converned.

Mouseevents are now completely handled in rocket and only then passed to panda.


def screenClick():
<div id="field" style="position:absolute;left:0px;top:0px;width:100%;height:100%;z-index:-1;" onClick="screenClick()"></div>
<Other UI code>

The div-element catched all clicks on it and then calls the UI function which was formerly called through a Panda event. Other UI elements have a higher z-index and thus the function is only called for locations, that don’t have other UI elements on top of it, i.e. the gamefield. This also allows for resizing / relocating of all other elements, without updating any code.

The post is very good.

Do you fire up the Panda event in UI.fieldClick?

I know this thread is a few months old, but if anyone else is interested there’s a shorter way. Python does indeed have the required c++ bindings, they’re just written strangely.

def mouseIsNotOnUi(self):
    return context.hover_element == context.root_element