[fltk.general] Re: [FLTK 1.3.5] Making a draggable item

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: [FLTK 1.3.5] Making a draggable item Catalin Poida 15:10 Sep 11 top right image
 
Hi Manolo,
Thank you for your suggestions.

I've managed to fix the problem regarding passing the event to the window. I've tried with FL_DRAG and other methods, but something was not right with what I've did. But in the end I've managed to make it work.

I've saw the shapewindow example, so it went easy the first part. The problem is that, as far as I understood, I need to draw with WHITE the shape of the image while setting the shape. But I cannot find how I can edit the image to convert the transparent part to white and the rest in black. Any ideas on this?
I do not understand:
"""
"With an Fl_RGB_Image with an alpha channel (depths 2 or 4), the shaped window covers the image part that is not fully transparent."
Thus, fully transparent parts of the png will be out of the window's shape.
""""
I think I understand the logic, but I can't get it right. I have something like (similar to shapewindow example) :

==================================
    auto *surf = new Fl_Image_Surface(w, h);
    Fl_Surface_Device* current = Fl_Surface_Device::surface();
    surf->set_current();
//    fl_color(FL_BLACK);
//    fl_rectf(-1, -1, w+2, h+2);
//    fl_color(FL_WHITE);
//    fl_pie(2,2,w-4,h-4,0,360);
    auto *img = new Fl_PNG_Image("item.png");
    auto *imgV2 = new Fl_RGB_Image(new Fl_Pixmap(img->copy(w, h)->data()), FL_BLACK);
    imgV2->draw(0,0);

    Fl_Window::shape(surf->image());
    delete surf;
    current->set_current();
    add(dragBox_);
    Fl_Group::end();
    Fl_Window::resizable();
==================================
The image still gets distorted and the shape is not right. What am I doing wrong? From what I understood, I need to draw with black the hole window to hide it, and the draw with white the shape I want to display.

Any ideas?

On Thursday, September 10, 2020 at 4:35:54 PM UTC+3 Manolo wrote:
Use Fl_Window::shape(const Fl_Image*) to set the shape of your window.
If you use a PNG image, the doc of that function indicates:
"With an Fl_RGB_Image with an alpha channel (depths 2 or 4), the shaped window covers the image part that is not fully transparent."
Thus, fully transparent parts of the png will be out of the window's shape.
Please, notice that if you use FLTK 1.3.5 you'll have to set your ABI level to 1.3.3 or above.

Also, I would have put the creation of the shaped window when the donor widget receives the FL_DRAG
event rather than FL_PUSH.

Class Fl_Image_Surface can be useful to create the image of the shaped window because it can
produce an image from a widget and its visual display.


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/c1616d6b-0b21-4c66-8e4e-90373327130dn%40googlegroups.com.
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2020 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.