Transparent Container Gadget

Just starting out? Need help? Post your questions and find answers here.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

I have revisisted this post - this time with an eye to actually understand the replies.

netmaestro, this question is for you and your first reply
first, why are you looking for the #Black color?

And why the region makes the background invisible? I dont get the connection?

Can you explain please

KingLestat
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

When you apply a region to a window, the operating system considers all portions of the window rectangle which don't fall inside the defined region to be outside the window, even though they are inside the full window rectangle. These "outside" portions are ignored for painting and receiving events, in effect they don't exist as far as your window is concerned.

The method I used to create the region is an old standby, that of generating a region from a bitmap. You create a bitmap that's all black except where you want the window's region to be, and then paint those areas white. Feed the bitmap to the region scanner procedure and it removes everything black from the region, leaving only what was white. Once the region is applied to the window, its usable region, that which gets painted and receives events, mirrors the non-black portions of the bitmap.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here's perhaps a quicker way of creating a region encompassing just the child controls of a container etc:

Code: Select all

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
SetWindowColor(0, #White) 
CreateGadgetList(WindowID(0)) 
ContainerGadget(0, 10,10,300,220) 
StringGadget(1,10,10,100,20,"") 
ButtonGadget(2,120,10,50,20,"OK") 
CloseGadgetList() 

mainrgn = CreateRectRgn_(GadgetX(1),GadgetY(1), GadgetX(1)+GadgetWidth(1),GadgetY(1)+GadgetHeight(1))
temprgn = CreateRectRgn_(GadgetX(2),GadgetY(2), GadgetX(2)+GadgetWidth(2),GadgetY(2)+GadgetHeight(2))
CombineRgn_(mainrgn, mainrgn, temprgn, #RGN_OR) 

DeleteObject_(temprgn) 

SetWindowRgn_(GadgetID(0),mainrgn,1) 
Repeat:Until WaitWindowEvent()=#WM_CLOSE 
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

well, expect another month for me to understand that
and thanks for the new example
But in practice how does it work with making an image?
ie how do I make an image instead of making it white? And if the image contains black pixels...will that negate the process?
I apologize for my slow cogwheels!

Ie I sort of understand that if I trap the #WM_ERASEBKGND message I do my own background. Yes - it took a long time, but now it makes sense. But with regions, besides building a black and white image, what do I do to put my image in?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Transparent Container Gadget

Post by rsts »

The last post regarding how to make it work with an image background was never answered?
is that because it was overlooked, or because we don't know how?

I can get each of the methods here to work, however I can not get any of them to work if the window background is an image -

Code: Select all

If StartDrawing(WindowOutput(0))
   
          DrawAlphaImage(ImageID(#img),0,0)
          StopDrawing()
          ValidateRect_(WindowID(0),0)
      EndIf
results in the containerGadget NOT being transparent, where it is if the window is merely colored.

Any way to have a transparent container on an image drawn window? And can be refreshed when the window is moved/minimized/etc?

(and the optional icing on the cake, resizable?)

cheers
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Transparent Container Gadget

Post by RASHAD »

Hi rsts
It is very old thread
Next snippet tested with PB 4.5 x86 Win 7 x64

Code: Select all

Result = LoadImage(0, "girl2.bmp")
hBrush = CreatePatternBrush_(ImageID(0))
OpenWindow(0,0,0,640,480,"", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered) 
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
;InvalidateRect_(WindowID(0), 0, 1)
ContainerGadget(1, 10,10,300,220) 
StringGadget(2,10,10,100,20,"") 
ButtonGadget(3,120,10,50,20,"OK") 
CloseGadgetList() 

SetClassLongPtr_(GadgetID(1),#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH))

Repeat:Until WaitWindowEvent()=#WM_CLOSE 
I hope it is OK
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Transparent Container Gadget

Post by rsts »

Hello again, Mr Rashad.

As old as it is, the thread is a baby compared to me :)

I had tried your suggestion, and unfortunately, in my window, the technique does not work. I'll need to create an easily testable version of my window to demonstrate the problem.

Be back soon.

cheers
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Transparent Container Gadget

Post by RASHAD »

Hi rsts
I tested the code with XP x32 SP2 and it worked fine too
Under any circumstances I do not care ,I want the cake :D

Have a good day sir
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Transparent Container Gadget

Post by rsts »

RASHAD wrote:Hi rsts
I tested the code with XP x32 SP2 and it worked fine too
Under any circumstances I do not care ,I want the cake :D

Have a good day sir
Oh yes, your example works fine.

It's just when I apply the technique to my window code that I have a problem. I'll cut things down and provide an example of my problem.

cheers

And once again, as I trimmed things down to prepare a suitable example, I found the error of my ways in a misnamed/misused id.

Many thanks for providing a working example using an image.

Best regards
hss
User
User
Posts: 69
Joined: Thu Mar 08, 2007 6:02 pm

Re: Transparent Container Gadget

Post by hss »

Tip: to preserve transparency for moving/resizable gadgets,
use SetWindowLong_ w/ #WS_CLIPCHILDREN param

Code: Select all


Procedure __test(x)
  
  Repeat
    x+10
    ResizeGadget(2,x,#PB_Ignore,#PB_Ignore,#PB_Ignore)
    ResizeGadget(3,#PB_Ignore,x,#PB_Ignore,#PB_Ignore)
    Delay(1000)
  ForEver

EndProcedure

UseJPEGImageDecoder()

Result=LoadImage(0,#PB_Compiler_Home+"\Examples\Sources\Data\clouds.jpg")
hBrush=CreatePatternBrush_(ImageID(0))
OpenWindow(0,0,0,525,555,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)


; comment/uncomment next line to see difference -
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_CLIPCHILDREN)
SetClassLongPtr_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)

ContainerGadget(1, 10,10,300,220)
StringGadget(2,10,10,100,20,"")
ButtonGadget(3,120,10,50,20,"OK")


SetClassLongPtr_(GadgetID(1),#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH))
CreateThread(@__test(),1)


Repeat:Until WaitWindowEvent()=#WM_CLOSE   


RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Transparent Container Gadget

Post by RASHAD »

How about this?

Code: Select all

Procedure __test(x)
 
  Repeat
    x+10
    ResizeGadget(2,x,#PB_Ignore,#PB_Ignore,#PB_Ignore)
    ResizeGadget(3,#PB_Ignore,x,#PB_Ignore,#PB_Ignore)
    InvalidateRect_(WindowID(0),0,1)
    Delay(1000)
  ForEver

EndProcedure

;UseJPEGImageDecoder()

Result=LoadImage(0,"girl2.bmp")
hBrush=CreatePatternBrush_(ImageID(0))
OpenWindow(0,0,0,525,555,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)


; comment/uncomment next line to see difference -
;SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_CLIPCHILDREN)
SetClassLongPtr_(WindowID(0),#GCL_HBRBACKGROUND,hBrush)

ContainerGadget(1, 10,10,300,220)
StringGadget(2,10,10,100,20,"")
ButtonGadget(3,120,10,50,20,"OK")


SetClassLongPtr_(GadgetID(1),#GCL_HBRBACKGROUND,GetStockObject_(#NULL_BRUSH))
CreateThread(@__test(),1)


Repeat:Until WaitWindowEvent()=#WM_CLOSE  

Egypt my love
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Transparent Container Gadget

Post by Rook Zimbabwe »

I have a stupid idea... If you want a bunch of transparent buttons... why not use borderless (and possibly skinned) child windows and as each window gets trhe focus it does what you want that button to do or it says to parent to do what you want it to do...

that could work for just a bunch of buttons on the desktop etc...

just a weird idea. :mrgreen:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply