Page 1 of 1
Change transparency of window
Posted: Sun Apr 10, 2011 10:11 am
by Shardik
On MacOS X 10.0 and later it is very easy to change the transparency of your window:
Code: Select all
ImportC ""
SetWindowAlpha(WindowRef.L, AlphaValue.F)
EndImport
OpenWindow(0, 200, 100, 300, 60, "Change window's transparency")
TrackBarGadget(0, 10, 10, 280, 20, 0, 100)
SetGadgetState(0, 0)
TextGadget(1, 15, 35, 40, 20, "0%")
TextGadget(2, 260, 35, 40, 20, "100%")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
SetWindowAlpha(WindowID(0), 1.0 - GetGadgetState(0) / 100.0)
EndIf
EndSelect
ForEver
Re: Change transparency of window
Posted: Sat Aug 27, 2011 6:33 pm
by delikanli_19_82
very good solution. thank you shardik.
thx
kurt
Re: Change transparency of window
Posted: Sat Aug 27, 2011 7:06 pm
by WilliamL
That's pretty neat but what would you use it for?
Re: Change transparency of window
Posted: Sat Aug 27, 2011 9:18 pm
by delikanli_19_82
i am working on an own cross-platform toolkit for purebasic. and the forms (windows) shell be able to transparent also.
Re: Change transparency of window
Posted: Thu Mar 13, 2014 2:17 pm
by vwidmer
Sorry if this is stupid but using the code posted above I am getting this error.
Code: Select all
Undefined symbols for architecture x86_64:
"_SetWindowAlpha", referenced from:
_Case1 in purebasic.o
PStub_SetWindowAlpha in purebasic.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Am I doing something wrong? I am on a MBP runing 10.9.2
Re: Change transparency of window
Posted: Thu Mar 13, 2014 5:11 pm
by Mindphazer
I think this code was using carbon, which is not supported anymore.
Maybe this could help :
http://www.purebasic.fr/english/viewtop ... 52#p393352
Re: Change transparency of window
Posted: Thu Mar 13, 2014 5:23 pm
by Shardik
Mindphaser is right. My code example runs only with the Carbon framework. At the time of my posting the only available framework was Carbon. With PB 5.00 the default framework changed to Cocoa. So to run my above code example you have to use PB 5.11 or older. In PB 5.00 to 5.11 you have to set the "Library Subsystem:" to "Carbon" in "Compiler/Compiler options...". In PB 4.61 or older the code example runs without anything to change (even on OS X 10.9.2 Mavericks).
Beginning with PB 5.20 the subsystem Carbon was removed...
For your conveniance I have ported the code example to Cocoa:
Code: Select all
Define Alpha.CGFloat
OpenWindow(0, 200, 100, 300, 60, "Change window's transparency")
TrackBarGadget(0, 10, 10, 280, 20, 0, 100)
SetGadgetState(0, 0)
TextGadget(1, 15, 35, 40, 20, "0%")
TextGadget(2, 260, 35, 40, 20, "100%")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
Alpha = 1.0 - GetGadgetState(0) / 100.0
CocoaMessage(0, WindowID(0), "setAlphaValue:@", @Alpha)
EndIf
EndSelect
ForEver
Re: Change transparency of window
Posted: Thu Mar 13, 2014 6:23 pm
by Mindphazer
Nice example Shardik
Thank you

Re: Change transparency of window
Posted: Thu Mar 13, 2014 6:57 pm
by Shardik
Mindphazer wrote:Nice example Shardik
Thank you

You are welcome.
Here is an improved example which uses BindEvent() for a real time change of the transparency while dragging the trackbar knob:
Code: Select all
Procedure TrackBarChangedCallback()
Protected Alpha.CGFloat = 1.0 - GetGadgetState(0) / 100.0
CocoaMessage(0, WindowID(0), "setAlphaValue:@", @Alpha)
EndProcedure
OpenWindow(0, 200, 100, 300, 60, "Change window's transparency")
TrackBarGadget(0, 10, 10, 280, 20, 0, 100)
SetGadgetState(0, 0)
BindEvent(#PB_Event_Gadget, @TrackBarChangedCallback(), 0, 0)
TextGadget(1, 15, 35, 40, 20, "0%")
TextGadget(2, 260, 35, 40, 20, "100%")
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow