Is this possible?

PueloGames

09-12-2007 12:21:46

Is this possible with a single click with quickGUI?
http://img88.imageshack.us/my.php?image ... ionuf4.jpg

kungfoomasta

09-12-2007 22:42:56

Easily done. 8)

Just make a ProgressBar widget, skin it to what you've shown, and add an event such that on Left Mouse Button down, you calculate the horizontal percentage of the cursor position vs the ProgressBar position. If you wanted to support LMB down and drag the value, you would want to add an event handler for DRAGGED.

The operations needed to do it are a little advanced, but I can help you out.

Artic_Ice83

10-12-2007 09:41:36

hi.
when i saw this post i tryed to do what you say, but when i add an event handler with addEventHandler() and set the event as mouse button down, and pass the function for the handler, the compiler gives me an error...

PueloGames

10-12-2007 09:59:14

ok!, Already finished energy bar
how is the draged?
Pd: tanks

kungfoomasta

10-12-2007 17:33:44

@Artic_Ice83: Hopefully you solved this, from the other thread.

@PueloGames:


myEnergyBar->enableDragging(true);
myEnergyBar->setDraggingWidget(NULL);
myEnergyBar->addEventHandler(EVENT_DRAGGED,&myClass::myFunction,this);


This enables/simulates dragging, but actually performs no dragging, since the dragging widget is NULL. 8)

For determining the position of the mouse cursor relative to the location of the progress bar, make sure you're using the following functions:


MouseCursor::getPosition
Widget::getAbsolutePosition


The AbsolutePosition reveals the true pixel coordinates on the screen, for example if your ProgressBar is inside a container that can scroll.

Artic_Ice83

10-12-2007 21:47:27

yes, i solved it. it was an error in the event name.
when i call setDraggingWidget(), what kind of widget i have to pass to the function?

kungfoomasta

10-12-2007 22:04:36

Any widget you want! It would probably make send to pass the same instance of the widget and set that as the dragging widget.

Basically, when you click and drag the mouse over a widget, it will drag the draggingWidget.

mTitleBar->setDraggingWidget(mParent);

The titlebar's parent is the window, so clicking and dragging the titlebar will drag the window, which moves the title bar. You could also do weird things, where clicking and dragging over an object will drag another object. If you want a simple case, where you can drag a button around, you would do

myButton->setDraggingWidget(myButton);

Artic_Ice83

10-12-2007 22:57:09

Yeah!
finally i did it! but instead of an event type DRAGGED, i used an EVENT_MOUSE_BUTTON_DOWN. The handler function get the position of the mouse, the actual position of the progress bar and the width. than sets the progress on the base of the position of the mouse relatively both position of the widget and its width.
but i didn't use the function getAbsolutePosition because i don't find it in my functions list. i've called the getActualPosition of the widget....but i suppose that if the widget is in a window or panel this call doesn't return the wanted result...

kungfoomasta

10-12-2007 23:20:03

My mistake, its probably getActualPosition. :oops:

getActualPosition returns the pixel coordinates as it is shown on the screen, with 0,0 being the top left of the render window. So for example, it will tell you where a widget is between 0,0 to 800,600, or whatever your resolution is.

Setting the progress by clicking is a cool idea. Not unheard of, but I'm happy the current code base supports this without any addition, it means I've made things pretty flexible with minimal assumptions. 8)

PueloGames

11-12-2007 00:15:33

Everything works fine!
i love QuickGUI