Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Mick P.
Earned some good credits
Earned some good credits
Posts: 145
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by Mick P. »

Sorry to do this, but I'm scratching my head looking at this (https://docs.wxwidgets.org/3.0/classwx_cursor.html) document, in the "Creating a Custom Cursor" section....

Code: Select all

static char down_bits[] = { 255, 255, 255, 255, 31,
    255, 255, 255, 31, 255, 255, 255, 31, 255, 255, 255,
    31, 255, 255, 255, 31, 255, 255, 255, 31, 255, 255,
    255, 31, 255, 255, 255, 31, 255, 255, 255, 25, 243,
    255, 255, 19, 249, 255, 255, 7, 252, 255, 255, 15, 254,
    255, 255, 31, 255, 255, 255, 191, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
    255 };
static char down_mask[] = { 240, 1, 0, 0, 240, 1,
    0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 240, 1,
    0, 0, 240, 1, 0, 0, 240, 1, 0, 0, 255, 31, 0, 0, 255,
    31, 0, 0, 254, 15, 0, 0, 252, 7, 0, 0, 248, 3, 0, 0,
    240, 1, 0, 0, 224, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0 };
#ifdef __WXMSW__
    wxBitmap down_bitmap(down_bits, 32, 32);
    wxBitmap down_mask_bitmap(down_mask, 32, 32);
    down_bitmap.SetMask(new wxMask(down_mask_bitmap));
    wxImage down_image = down_bitmap.ConvertToImage();
    down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 6);
    down_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 14);
    wxCursor down_cursor = wxCursor(down_image);
#elif defined(__WXGTK__) or defined(__WXMOTIF__)
    wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wxWHITE, wxBLACK);
#endif
As a developer I'm having a hard time understanding why this exists.

Can anyone see anything in this bifurcated code (that is recommended) that cannot be implemented inside the constructor of wxCursor?

Are the WX developers mental? Or am I missing something obvious that's not part of this document?

If the purpose of wxWidgets is not even to simplify code, but to unify code, then why is this not asinine?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by ONEEYEMAN »

Hi,
I'm not sure what you mean?
Can you give some code example of what do you think the page shuold look like?

Thank you.
Mick P.
Earned some good credits
Earned some good credits
Posts: 145
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by Mick P. »

Code: Select all

#ifdef __WXMSW__
    wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wxWHITE, wxBLACK);
#elif defined(__WXGTK__) or defined(__WXMOTIF__)
    wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wxWHITE, wxBLACK);
#endif
is what I think it should look like. I can't understand why not.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by ONEEYEMAN »

Hi,
And if you try to compile it you will get a compiler error because "down_bits" variable will not be defined, right?

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by PB »

Mick P. wrote: Fri Aug 02, 2019 5:44 pm

Code: Select all

#ifdef __WXMSW__
    wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wxWHITE, wxBLACK);
#elif defined(__WXGTK__) or defined(__WXMOTIF__)
    wxCursor down_cursor = wxCursor(down_bits, 32, 32, 6, 14,
                                    down_mask, wxWHITE, wxBLACK);
#endif
is what I think it should look like. I can't understand why not.
If the code were identical as the one you posted, why close it inside #defines?

The documentation for wxCursor ctor taking bits is not entirely correct. The declaration of the GTK/Motif only ctor is incomplete, it misses parameters for foreground and background colors, which are listed in the description only. MSW ctor does not have those parameters.

You probably meant to ask why MSW/Qt does not have the same ctor as GTK/Motif, which would do the same thing as shown in the documentation example (i.e., creating wxImage from bitmap, mask, and hotspot), sparing the user from doing that. You need to ask this on wx-dev, where the actual developers hang. This is a user forum. My guess would be that the GTK/Motif ctor is an artifact from ancient times, existing only to make porting the native applications from those platforms to wxWidgets easier.
Mick P.
Earned some good credits
Earned some good credits
Posts: 145
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by Mick P. »

What I mean is--unless the documentation is erroneous, or I'm missing something not obvious--then the branching code can live inside the constructor so that wxWidgets fulfills a (presumed) mandate of actually unifying these platforms to a reasonable degree.

This example makes me to question what is the philosophy behind this code, as any sane developer would just do this in the constructor... that means there must be a philosophical bent to it. It's not worth writing the example in the first place, when it can just go inside the constructor instead. If the constructor has all of the relevant information to be able to construct a cursor, then why would it not do so.

It's worrisome, that wxWidgets may be intentionally putting itself in the way of sane standards for users.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by ONEEYEMAN »

Hi,
And how do you propose to do it?
Different ports have different constructors...

Thank you.
Mick P.
Earned some good credits
Earned some good credits
Posts: 145
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by Mick P. »

ONEEYEMAN wrote: Sat Aug 03, 2019 2:27 pm Hi,
And how do you propose to do it?
Different ports have different constructors...

Thank you.
Add a constructor, so the case of there being inconsistencies is minimized? I.e. commonsense.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by ONEEYEMAN »

Hi,
And how you propose to do that? Do you have such constructor signature in mind?
Because if you do, I'm sure Vadim and company will be glad to hear it.

And so will I.

Thank you.
Mick P.
Earned some good credits
Earned some good credits
Posts: 145
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: Curiosity: "Creating a Custom Cursor" example... WTH is wxWidgets?

Post by Mick P. »

And how you propose to do that? Do you have such constructor signature in mind?
The identical signature obviously. I could not follow your reason for the discrepency before. I guess the documentation doesn't attempt to explain this either.

All the parameters appear represented. I guess MSW bitmaps can only be black/white? Or can they be indexed with a 2 color palette? Either way, it seems like there is enough information in the parameter list to produce the desired cursor. I feel like you're being evasive. It's unflattering if so.
Post Reply