c++ - How can I make a window transparent in Windows, Mac OS X, and Linux using FLTK? -
i'm writing application in c++ using fltk 1.3.2. code utilize create main window transparent on windows 7 or 8:
class="lang-cpp prettyprint-override">// given: // fl_window *my_fltk_window; // bool is_transparent; hwnd hwnd = fl_xid(my_fltk_window); long_ptr exstyle = getwindowlongptr(hwnd, gwl_exstyle); if (!(exstyle & ws_ex_layered)) { setwindowlongptr(hwnd, gwl_exstyle, exstyle | ws_ex_layered); } setlayeredwindowattributes(hwnd, 0, is_transparent ? 192 : 255, lwa_alpha); it works fine: set code in callback function, assign button or menu item, , clicking toggles window transparency. however, i'd cross-platform, don't have experience os x or linux apis. should match effect of windows code?
edit: got work in os x. main file calls function:
class="lang-cpp prettyprint-override">#include "my-cocoa-wrappers.h" setwindowtransparency(my_fltk_window, is_transparent ? 0.75 : 1.0); then created my-cocoa-wrappers.h:
class="lang-cpp prettyprint-override">#ifndef my_cocoa_wrappers_h #define my_cocoa_wrappers_h #include <fl/x.h> #include <fl/fl_window.h> void setwindowtransparency(fl_window *w, double alpha); #endif and my-cocoa-wrappers.mm:
class="lang-objective-c prettyprint-override">#import <cocoa/cocoa.h> #include "my-cocoa-wrappers.h" void setwindowtransparency(fl_window *w, double alpha) { [fl_xid(w) setalphavalue:alpha]; } the makefile took care of compiling my-cocoa-wrappers.mm objective-c instead of c++.
edit 2: , here solution linux by sanel zukan depends on x11, not gtk+ expected need:
class="lang-cpp prettyprint-override">atom atom = xinternatom(fl_display, "_net_wm_window_opacity", false); uint32_t opacity = is_transparent ? 0xc0000000 : 0xffffffff; xchangeproperty(fl_display, fl_xid(my_fltk_window), atom, xa_cardinal, 32, propmodereplace, (unsigned char *)&opacity, 1);
here solution mac os x. main file calls function:
class="lang-cpp prettyprint-override">#include "my-cocoa-wrappers.h" setwindowtransparency(my_fltk_window, is_transparent ? 0.75 : 1.0); then created my-cocoa-wrappers.h:
class="lang-cpp prettyprint-override">#ifndef my_cocoa_wrappers_h #define my_cocoa_wrappers_h #include <fl/x.h> #include <fl/fl_window.h> void setwindowtransparency(fl_window *w, double alpha); #endif and my-cocoa-wrappers.mm:
class="lang-objective-c prettyprint-override">#import <cocoa/cocoa.h> #include "my-cocoa-wrappers.h" void setwindowtransparency(fl_window *w, double alpha) { [fl_xid(w) setalphavalue:alpha]; } the makefile took care of compiling my-cocoa-wrappers.mm objective-c instead of c++.
and here solution linux by sanel zukan depends on x11, not gtk+ expected need:
class="lang-cpp prettyprint-override">atom atom = xinternatom(fl_display, "_net_wm_window_opacity", false); uint32_t opacity = is_transparent ? 0xc0000000 : 0xffffffff; xchangeproperty(fl_display, fl_xid(my_fltk_window), atom, xa_cardinal, 32, propmodereplace, (unsigned char *)&opacity, 1); c++ linux osx user-interface fltk
No comments:
Post a Comment