GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Oct-2005, 01:15
yilmaz yilmaz is offline
New Member
 
Join Date: Oct 2005
Posts: 3
yilmaz is on a distinguished road

Transparent FLTK Window


Hi all;

How can I do an Fl_Window transparent? That is, there may be widgets on the window, but the background of the window will be transparent.

Thanks in advance...
  #2  
Old 26-Oct-2005, 17:54
MatthiasWM MatthiasWM is offline
VIP
 
Join Date: Nov 2004
Posts: 62
MatthiasWM will become famous soon enough

Re: Transparent FLTK Window


In FLTK 2, you can use fltk::ShapedWindow, IIRC. In FLTK 1, you would have to patch the library yourself.
  #3  
Old 27-Oct-2005, 00:37
yilmaz yilmaz is offline
New Member
 
Join Date: Oct 2005
Posts: 3
yilmaz is on a distinguished road

Re: Transparent FLTK Window


Thank you Matthias, it is nice to see a reply
So you mean that it is not possible to do it with version 1?

I checked the version2 source files and I see that it is not possible
to easily patch the previous one.
  #4  
Old 27-Oct-2005, 01:24
MatthiasWM MatthiasWM is offline
VIP
 
Join Date: Nov 2004
Posts: 62
MatthiasWM will become famous soon enough

Re: Transparent FLTK Window


I used to have a patched version for quite a while since I depended on that feature. Unfortunatly, as the project died, the patch was lost (don't you hate those dot com crashes? ;-)

I am not sure if I can get a patch out before the end of the year, but I really want this feature back to give my software this distinct touch. If I do, I will send a message to the fltk.org user group.
  #5  
Old 20-Nov-2005, 09:55
oksid oksid is offline
New Member
 
Join Date: Nov 2005
Posts: 6
oksid is on a distinguished road

Re: Transparent FLTK Window


Quote:
Originally Posted by MatthiasWM
I used to have a patched version for quite a while since I depended on that feature. Unfortunatly, as the project died, the patch was lost (don't you hate those dot com crashes? ;-)

I have a copy of your patch.
I've included it in my own patch, fltk-utf8
http://www.oksidizer.com/fltk.html

Here it is :

CPP / C++ / C Code:
// Copyright 1998-1999 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@easysw.com".
//

#ifndef Fl_Shaped_Window_H
#define Fl_Shaped_Window_H

#include <FL/Fl_Window.H>
#include <FL/Fl_Bitmap.H>

class FL_EXPORT Fl_Shaped_Window : public Fl_Window {
  public:
    Fl_Shaped_Window(int W, int H, const char *l = 0)
      : Fl_Window(W,H,l) { set_flag(8); shape_ = 0; lw = lh = 0; changed = 0; }
    Fl_Shaped_Window(int X, int Y, int W, int H, const char *l = 0)
      : Fl_Window(X,Y,W,H,l) { set_flag(8); shape_ = 0; lw = lh = 0; }
    void shape(Fl_Bitmap* b) { shape_ = b; changed = 1; }
    void shape(Fl_Bitmap& b) { shape(&b); }

  protected:
    virtual void draw();
    Fl_Bitmap* shape_;
    int lw, lh;
    int changed;
};


#endif

//////////////////////////////////////////

/////////////////////////////////////////
#include <FL/Fl_Shaped_Window.H>
#include <FL/x.H>

#ifdef _WIN32
static HRGN bitmap2region(Fl_Bitmap*);
#elif (defined(__MACOS__) && !USE_X11)
// Not yet implemented for Apple
#elif NANO_X
// for microwindows too ;-)
#elif DJGPP
// for microwindows too ;-)
#else
#include <X11/extensions/shape.h>
#endif

// maybe one day we'll want to be able to resize the clip mask
// when the window resized
static Fl_Bitmap* resize_bitmap(Fl_Bitmap*, int, int);

void Fl_Shaped_Window::draw() {
  if ((lw != w() || lh != h() || changed) && shape_) {
    // size of window has change since last time
    lw = w(); lh = h();
    Fl_Bitmap* mask = resize_bitmap(shape_, w(), h());
#ifdef _WIN32
    HRGN region = bitmap2region(mask);
    SetWindowRgn(fl_xid(this), region, TRUE);
#elif (defined(__MACOS__) && !USE_X11)
    // not yet implemented for Apple
#elif NANO_X
#elif DJGPP
#else
    Pixmap pmask = XCreateBitmapFromData(fl_display, fl_xid(this),
                  (const char*)mask->array, mask->w(), mask->h());
    hide();
    XShapeCombineMask(fl_display, fl_xid(this), ShapeBounding, 0, 0,
                      pmask, ShapeSet);
    show();
    if (pmask != None) XFreePixmap(fl_display, pmask);
#endif
    changed = 0;
  }
  Fl_Window::draw();
}

// maybe one day we'll want to be able to resize the clip mask
// bitmap when the window is resized
static Fl_Bitmap* resize_bitmap(Fl_Bitmap* bitmap, int /*W*/, int /*H*/) {
  return bitmap; // CET - FIXME - someday...
}

#ifdef _WIN32
#include <malloc.h>
static inline BYTE bit(int x) { return (BYTE)(1 << (x % 8)); }

// Windows uses regions only to specify the clip mask of a window therefore
// we must convert our bitmap to a region.
// Much of this code is "borrowed" from the Windows version of GTK
// (also LGPLed).  Their code was based on code originally written by
// Jean-Edouard Lachand-Robert.  Ain't open source great?
//
// Modified by me to use an Fl_Bitmap, to not hog memory, to not leak memory
// (I hope) and to allow bitmaps of arbitrary dimensions. -CET
static HRGN bitmap2region(Fl_Bitmap* bitmap) {
  HRGN hRgn = 0;
  /* For better performances, we will use the ExtCreateRegion()
   * function to create the region. This function take a RGNDATA
   * structure on entry. We will add rectangles by amount of
   * ALLOC_UNIT number in this structure.
   */
  #define ALLOC_UNIT  100
  DWORD maxRects = ALLOC_UNIT;

  RGNDATA* pData = (RGNDATA*)malloc(sizeof(RGNDATAHEADER)+(sizeof(RECT)*maxRects));
  pData->rdh.dwSize = sizeof(RGNDATAHEADER);
  pData->rdh.iType = RDH_RECTANGLES;
  pData->rdh.nCount = pData->rdh.nRgnSize = 0;
  SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);

  const int bpl = (bitmap->w()+7)/8; // number of bytes per line of pixels
  BYTE* p8 = (BYTE*)bitmap->array;
  BYTE* p;
  for (int y = 0; y < bitmap->h(); y++) {
    /* Scan each bitmap row from left to right*/
    for (int x = 0; x < bitmap->w(); x++) {
      /* Search for a continuous range of "non transparent pixels"*/
      int x0 = x;
      while (x < bitmap->w()) {
        p = p8 + x / 8;
        if (!((*p) & bit(x))) break; /* This pixel is "transparent"*/
        x++;
      }

      if (x > x0) {
        RECT* pr;
        /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
         * in the region
         */
        if (pData->rdh.nCount >= maxRects) {
          maxRects += ALLOC_UNIT;
          pData = (RGNDATA*)realloc(pData, sizeof(RGNDATAHEADER)
                                    + (sizeof(RECT)*maxRects));
    	}
        pr = (RECT*)&pData->Buffer;
        SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1);
        if (x0 < pData->rdh.rcBound.left)
          pData->rdh.rcBound.left = x0;
        if (y < pData->rdh.rcBound.top)
          pData->rdh.rcBound.top = y;
        if (x > pData->rdh.rcBound.right)
          pData->rdh.rcBound.right = x;
        if (y+1 > pData->rdh.rcBound.bottom)
          pData->rdh.rcBound.bottom = y+1;
        pData->rdh.nCount++;

        /* On Windows98, ExtCreateRegion() may fail if the
         * number of rectangles is too large (ie: >
         * 4000). Therefore, we have to create the region by
         * multiple steps.
         */
        if (pData->rdh.nCount == 2000) {
          HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER)
                                   + (sizeof(RECT)*maxRects), pData);
          if (hRgn) {
            CombineRgn(hRgn, hRgn, h, RGN_OR);
            DeleteObject(h);
          } else hRgn = h;
          pData->rdh.nCount = 0;
          SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
        }
      }
    }

    /* Go to next row */
    p8 += bpl;
  }

  /* Create or extend the region with the remaining rectangles*/
  HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER)
		      + (sizeof(RECT)*maxRects), pData);
  if (hRgn) {
    CombineRgn(hRgn, hRgn, h, RGN_OR);
    DeleteObject(h);
  } else hRgn = h;

  free(pData); // I've created the region so I can free this now, right?

  return hRgn;

}
#endif
Last edited by LuciWiz : 22-Nov-2005 at 03:02. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #6  
Old 25-Nov-2005, 02:48
MatthiasWM MatthiasWM is offline
VIP
 
Join Date: Nov 2004
Posts: 62
MatthiasWM will become famous soon enough

Re: Transparent FLTK Window


Hey Oksid,

thanks a lot! Nothing seems to get lost in this Net ;-)
  #7  
Old 23-May-2007, 08:01
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,108
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: Transparent FLTK Window


We have been playing with this code in this thread if anyone is interested.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FLTK && fluid In Motion cable_guy_67 FLTK Forum 4 20-Mar-2008 03:52
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
log window in fltk podarok FLTK Forum 5 11-May-2005 02:23
Win32 Window Shading behavior (like linux) WillyumYum C++ Forum 3 18-Apr-2005 14:36
Changing window start colour Rosdahale C++ Forum 5 19-Jan-2005 15:51

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.