c++ - Relative coordinates with slider widget containing thumb widget -


my slider had child button widget. have changed gui send mouse coordinates relative widget, if widget @ 50,50 , mouse @ 50,50, report 0,0.

this has created problems slider. when drag around button position value.

the solution have thought of take given mouse coordinate, add absolute position of button, subtract absolute position of slider.

i hoping solution did not envole absolute positioning.

i used receive absolute mouse position, when did, positioned this:

int mousepos = getorientation() == agui_horizontal ?      mouseargs.getposition().getx() - getabsoluteposition().getx() : mouseargs.getposition().gety() - getabsoluteposition().gety();  setvalue(positiontovalue(mousepos)); 

mouseargs gives mouse position relative button. not relative slider, needed.

i can obtain relative locations of widgets, don't think it.

thanks

since custom gui, i'm going make assumptions , restate question make sure i'm answering question.

you have slider widget contains thumb widget. user can click , drag thumb reposition it. gui sends mouse notifications widgets in local relative space rather absolute screen space. question how can thumb widget respond mouse events move around without having use absolute coordinates?

you can changing who's responsibility move thumb widget. should job of slider widget position thumb widget. doing way, coordinates can in slider widget's local relative space. it'd (assuming have kind of event notification):

  1. when created, slider widget registers various mouse events on child thumb widget.
  2. when thumb receives mouse events, raises event passing along local coordinate.
  3. slider widget receives these events , translates coordinate thumb local space slider local space (i.e., click_x = thumb_x + thumb_mouse_x).
  4. slider can use coordinate, in slider's local relative space, move thumb.

in general, parents should responsible children's layout.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -