Page 1 of 1

A generic error?!

Posted: Fri Apr 21, 2006 07:40
by PeakGao
Hi,
I try to use CEGUI, but i found a generic error about event's fire-occasion.

my english is poor, :) so please see example.

in your code: (eg)

Code: Select all

void Listbox::onMouseButtonDown(MouseEventArgs& e)
{
   // base class processing
   Window::onMouseButtonDown(e);

   if (e.button == LeftButton)
   {
   // ignore
   }

}


in "Window::onMouseButtonDown(e)", will fire "MouseButtonDown" event. what is event? event means something had happened! in the proccess of above, "Window::onMouseButtonDown(e)" had fired event, but "Listbox::onMouseButtonDown" does not begin handle itself code, so i think that you should move the code "Window::onMouseButtonDown(e)" to end of the function.

see the error raises some question:
-- lua code

Code: Select all

function onMouseDownHandler(args)
   local mouseArgs = CEGUI.toMouseEventArgs(args)
   local listbox = CEGUI.toListbox(mouseArgs.window)
   local selectedItem = listbox:getFirstSelectedItem()    -- there, selectedItem equal to nil, for listbox does not begin to handle itself code
   local index = listbox:getItemIndex(selectedItem)
   if mouseArgs.button == 0 then -- left button
      -- something
   elseif  mouseArgs.button == 1 then -- right button
      -- something
   end
end


in cegui library, has a great lot of the same code.
is my idea wrong or ...?

Posted: Tue Apr 25, 2006 16:27
by lindquist
You can work around this by subscribing to the SelectionChanged event instead.

This event is fired in your //ignore block of Listbox::onMouseButtonDown.

But I agree to some extent that the base class handling should be moved to the bottom.

I'm adding a ticket to our tracker so I can discuss it with the team. The "issue" is that applying the "fix" will change the order events are fired.

Posted: Thu Apr 27, 2006 03:16
by PeakGao
lindquist wrote:You can work around this by subscribing to the SelectionChanged event instead.

This event is fired in your //ignore block of Listbox::onMouseButtonDown.

But I agree to some extent that the base class handling should be moved to the bottom.

I'm adding a ticket to our tracker so I can discuss it with the team. The "issue" is that applying the "fix" will change the order events are fired.



for my handler depend on mouse actions, so i use MouseButtnDown event instead of SelectionChanged event. in the CEGUI, SelectionChanged event do not only depend on mouse actions, e.g. Listbox::setItemSelectState(...)