wxCursor and GTK

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

wxCursor and GTK

Post by rocrail »

Hi,

for D&D I set the cursor with the selected wxImage which works perfectly under macOS and Windows. For Windows the image will be scaled down to 32x32.

But the same wxImage does not seem to be accepted or wrong interpreted by Linux/GTK. (The cursor image looks like its jammed.)
If I look in the wx gtk sources, cursor.cpp, it seems to be hard coded on how a wxImage should be interpreted...

Code: Select all

    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(image.GetData(), GDK_COLORSPACE_RGB, false, 8, w, h, w * 3, NULL, NULL);
Hard coded is the depth(8) and data row width(w*3)...

Q: How should a wxImage be prepared to be wxGTK conform?
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxCursor and GTK

Post by doublemax »

The internal format of wxImage is always the same, there is nothing you can "prepare". The problem must be somewhere else.
Use the source, Luke!
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxCursor and GTK

Post by rocrail »

There seems to be no sample in the wxWidgets source tree for the wxCursor object to use as reference.
I have no clue on how to solve this wxGTK problem. Any suggestions are very welcome. :D
Best regards,
Rob.
https://wiki.rocrail.net
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: wxCursor and GTK

Post by DavidHart »

Hi,

It must be either your code or your bitmap. I do the following without any problem:

Code: Select all

DnDSelectedCursor = wxCursor( wxGetApp().CorrectForDarkTheme(BITMAPSDIR+"DnDSelectedCursor.png") );
where the png is https://sourceforge.net/p/fourpane/git4 ... Cursor.png
There seems to be no sample in the wxWidgets source tree for the wxCursor object to use as reference.
The 'image' sample does:

Code: Select all

m_canvas->SetCursor(wxImage("cursor.png"));
Try substituting one of the above bitmaps for yours. If it still fails try substituting the code.

Regards,

David
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxCursor and GTK

Post by rocrail »

Hi David,

AFAIK there is not method SetCursor with wxImage, but only a one with wxCursor...
Best regards,
Rob.
https://wiki.rocrail.net
User avatar
rocrail
Super wx Problem Solver
Super wx Problem Solver
Posts: 293
Joined: Fri Oct 02, 2009 2:02 pm
Contact:

Re: wxCursor and GTK

Post by rocrail »

a code snippet:

Code: Select all

    wxImage cursor = renderer->GetImage()->ConvertToImage();
...
    m_Cursor = new wxCursor(cursor);
    SetCursor( *m_Cursor );
The renderer returns a wxBitmap* which is converted into a wxImage, and used for the wxCursor object.
The wxBitmap is created on the fly with a wxMemoryDC:

Code: Select all

      wxMemoryDC tmpDC;
      imageBitmap = new wxBitmap();
      imageBitmap->Create(cx * 32 * m_Scale, cy * 32 * m_Scale , 8);
      tmpDC.SelectObject(*imageBitmap);
      tmpDC.SetBackground(*wxWHITE_BRUSH);
      tmpDC.Clear();
      tmpDC.SetUserScale( m_Scale, m_Scale );
      m_Renderer->drawSvgSym( (wxPaintDC&)tmpDC, 0, 0, imageName, wItem.west, &cx, &cy );
      tmpDC.SelectObject(wxNullBitmap);
As I already stated is that this code works under both Windows and macOS. So why does it not work under Linux GTK?
Best regards,
Rob.
https://wiki.rocrail.net
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: wxCursor and GTK

Post by DavidHart »

AFAIK there is not method SetCursor with wxImage, but only a one with wxCursor...
But the wxCursor ctor has various overloads e.g. wxCursor (const wxImage &image) as used in the 'image' sample. Why not try that?
Post Reply