Adding padding/boundary to Raphael path for leniency on mouseover events - raphael

Consider a path (which is a line) drawn out with Raphael with a mouseover event that sets the cursor to hover. For a thin path/line it is difficult to hover the mouse over that path.
Is there a way to add an invisible border/padding/boundary to the path so that it is easier to hover over the path?

A really simple way to accomplish that would be as follows:
Duplicate the path you're using as a hover trigger with element.clone
Move the clone in front of the current path with element.insertAfter
Use element.attr to set the clone's opacity to just above 0, so that it is effectively invisible but still receives click events, and to have a stroke-width property equal to the original path's stroke-width + your desired margin;
Add your hover events to the cloned element.
This will give you a invisible path much thicker than the original that is capable of receiving mouse events in place of the original, thinner path.
I've mocked this up here, with a cursor property set so you'll see crosshairs when the mouse is over the surrogate path.

Related

Qt - how to glue two windows and move them together?

Like the qmmp(Qt) music player ui design, these two or three windows are in fact in the same window, because there is only a dock icon, and these windows can move together and attach to each other.
I read the source code, it seems use QDockWidget. But I really don't know the details how to get it.
When you manually move the secondary window, in this case - the playlist, you check where the manual move ends, and if it is on the edges of the primary window, you glue it by simply binding its position to the position and dimensions of the primary window.
Since the window position and dimensions are properties, they have notification signals, so you can connect those to a function that automatically moves the glued window.
And finally, when you attempt to manually move the secondary window, you un-glue by disconnecting.
You can easily support offset gluing instead of a purely horizontal or vertical one, by calculating and storing the positioning offset and applying it on every primary window move.
If the drop happens within a given threshold of the primary window you can snap to the edge. If you factor in the mouse position relative to the dragged window, you can even snap particular edges together.

How to select a specific sprite and move it in SDL

I'm making a chess game, where I have a box shaped selector, now I want to select a sprite with that box and move it in a specific location with the selection box.
Any link or code?
You keep track of the position of everything.
Poll for events, see where the mouse is. If in the rectangle of a piece, put the selector on top of the piece (assuming you have colorkeying or alpha). You should be able to listen to keyboard input and move the selector based on that.
When mouse clicks, see where the selector is. Find the piece that's under it, and remember it.
When mouse clicks again, see where the selector is now. Check if moving there is valid. If yes, move the piece you remember to the new position.

Scrolling in C++ Builder RadioGroup

I have RadioGroup with many buttons. Now when I add an item, they become smaller and smaller. How is it possible to make them scrollable?
TRadioGroup does not natively support scrolling. However, what you can do instead is the following:
place a TGroupBox on your UI.
place a TScrollBox onto the TGroupBox, set its Align property to alClient, and its BorderStyle property to bsNone.
place a TRadioGroup onto the TScrollBox, clear its Caption property, and set its Left property to -2 and its Top property to -15 (or whatever the TRadioGroup.Font is set to plus a few extra pixels). This positioning is needed because you cannot turn off the TRadioGroup's borders or the space reserved for its Caption.
Tweak the TScrollBox.HorzScrollBar.Range and TScrollBox.VertScrollBar.Range properties so they do not scroll far enough to see the TRadioGroup's right and bottom borders.
This way, the buttons appear as if they are part of the TGroupBox, but with the added scrollbar(s).
RadioGroup->Items->Count
TRadioGroup component doesn't have an embedded scrollbar, but you can put the radio group on a TScrollBox for a similar effect.
You can use the Buttons collection to refer each button, e.g.
RadioGroup->Buttons[0]->Height = 5;
RadioGroup->Buttons[1]->Top = RadioGroup->Buttons[0]->Top + 10;
Anyway a TComboBox could also be a good choice.

Relative coordinates with slider widget containing thumb widget

My slider had a child button widget. I have recently changed my gui to send the mouse coordinates as relative to the widget, so if the widget is at 50,50 and the mouse is at 50,50, it will now report as 0,0.
This has created some problems for my slider. When I would drag around the button it would position to value.
The only solution I have thought of is to take the given mouse coordinate, add back the absolute position of the button, then subtract the absolute position of the slider.
I was however hoping for a solution that did not envole absolute positioning.
I used to receive the absolute mouse position, when I did, I positioned it like this:
int mousePos = getOrientation() == AGUI_HORIZONTAL ?
mouseArgs.getPosition().getX() - getAbsolutePosition().getX() :
mouseArgs.getPosition().getY() - getAbsolutePosition().getY();
setValue(positionToValue(mousePos));
mouseArgs gives the mouse position relative to the button. Not relative to the slider, which is what would be needed.
I can obtain the relative locations of the widgets, but I don't think that would do it.
Thanks
Since this is a custom GUI, I'm going to make some assumptions and restate your question to make sure I'm answering your question.
You have a slider widget that contains a thumb widget. The user can click and drag the thumb to reposition it. Your GUI sends mouse notifications to your widgets in local relative space rather than absolute screen space. Your question is how can the thumb widget respond to the mouse events to move itself around without having to use absolute coordinates?
You can do this by changing who's responsibility it is to move the thumb widget. It should be the job of the slider widget to position its thumb widget. By doing it that way, all your coordinates can be in the slider widget's local relative space. Basically it'd be something like (assuming you have some kind of event notification):
When created, the slider widget registers for the various mouse events on its child thumb widget.
When the thumb receives mouse events, it raises the event passing along its local coordinate.
Slider widget receives these events and translates the coordinate from thumb local space to slider local space (i.e., click_x = thumb_x + thumb_mouse_x).
Slider can then use this coordinate, which is in the slider's local relative space, to move the thumb.
In general, parents should be responsible for their children's layout.

Finding current mouse position in QT

This is my first attempt at writing a QT app, and I'm just trying to get a feel for how it works. My goal is to have a 400x400 widget which knows the exact position of the mouse when the mouse is hovering over it. For example, if the mouse was hovering in the top left corner, the position might be 10,10 (or something similar). If the mouse is in the bottom right corner, it might say 390,390.
Eventually, these coordinates will be displayed in a label on the main window, but that should be trivial. I'm stuck at the actual fetching of the coordinates. Any ideas?
For your widget, you must enable mouse tracking.
Then, you can either install an event filter, paying attention to mouse events and looking for the move event, or you can inherit from QWidget and override the mouse event, looking for mouse move events.
http://doc.qt.io/qt-4.8/qwidget.html#mouseTracking-prop
http://doc.qt.io/qt-4.8/eventsandfilters.html
http://doc.qt.io/qt-4.8/qmouseevent.html
If you are ever in a situation when you don't need actual tracking, just position at the moment, you can use QCursor::pos().