I’ve “solved” the global mouse cursor issue by the singleton method I’ve described in post #3.
Then I was pissed that some component don’t respect setMouseCursor call.
Finally I’ve used the application with the new “global” cursor, and to find out that, after all, they don’t respect cursor in the “usual” widget interaction.
That is, when you move your mouse over a text box, you expect the cursor to change to indicate it’s an input field.
I’m back to case 1, if I want to set a global cursor, I must still allow specialized cursor for some component, or the user’ll never think it’s active.
For a coherent user interface, I can’t have the a custom cursor everywhere (with full color matching the application look and feel) and then that pop up to the white arrow or the text “|”'s cursor when hovering the component.
A global look and feel approach won’t be enough for this case.
I’m trying to figure out, with you, what would be the best method to still allow a customization of the mouse cursor, but while keeping the “basic” functionality of adaptive mouse cursor on some selected component.
Dynamic_cast aren’t slow when done coarsly. Whatever time they take, it’s slower than a compile time, type-based selection which is done in 0 instructions.
Where it is clearly worse is that a dynamic_cast algorithm is a pain to maintain (as you MUST put base class after child class in your if/else chain, you must remember to maintain this part of the code and so on…).
Sure, template are more difficult to write and understand, as, as soon as you’re upcasting to the base class the template system will fail.
But don’t put me wrong here, if every component implements:
private:
MouseCursor & getMouseCursorImpl() { return LookAndFeel::getMouseCursorFor(*this); }
with the template system I’ve written in post #9, it works and resolve to 0 instructions when compiled in.
I would then only have to write:
template<> MouseCursor & LookAndFeel::getMouseCursorFor(Slider &) { return globalCursorForSlider; }
template<> MouseCursor & LookAndFeel::getMouseCursorFor(TextEditor &) { return globalCursorForTextBox; }
MouseCursor & LookAndFeel::getMouseCursorFor(Component &) { return globalCursorForComponent; }
which is, IMHO, both more efficient (no tests generated) and simpler than:
MouseCursor & LookAndFeel::getMouseCursorFor(Component & comp)
{
if (dynamic_cast<Slider *>(&comp))
{
// This won't work for a "class ImageSlider: public Slider" BTW, while the template-based approach would.
return globalCursorForSlider;
}
// If I had done this:
// else if (dynamic_cast<ImageSlider*>(&comp)) Then it won't work
else if (dynamic_cast<TextEditor *>(&comp)) return globalCursorForTextBox;
else return globalCursor;
}
Anyway, even with a LookAndFeel approach, I would be more than happy. It just that I find this sub-optimal and hazardous…