Fred wrote:Theorically gadgets overlapping is not supported in PB. But on Windows (and only on Windows) you can try to put your button directly in the ImageGadget() by using UseGadgetList(GadgetID(#YourImageGadget)).
Your answer surprised me and got me all excited. I tried it immediately, and found that it works great visually, but is severely handicapped functionnally.
It seems that EventGadget() only sees the imageGadget.
Any idea on how to catch the GadgetIDs of those buttons clearly visible (and seemingly functional) on the picture ?
A solution, if it exists (!) would be much appreciated...
===================
Forget the above.
using another method, the code below now works fine:
Code: Select all
; ==============================================
; Blue - octobre 2007
;; Window with picture as a background for controls
;;=================================================
;;#imageName = "D:\Projets\PureBasic\Marqueur\bones.jpg"
#imageNameA = "bones.jpg" ;; picture is 344 X 341
#imageNameB = "bonesG.png" ;; a light gray copy of above
Enumeration
#imageFond
#imageB
#txtBox
#strBox
#bouton1
#bouton2
#bouton3
#cmdImage
#cmdQuit
EndEnumeration
Declare.L TellMe(id.L)
Declare.L ChangeImage()
;****************************************************
;- initializing pictures
; Plugins
UseJPEGImageDecoder()
UsePNGImageDecoder()
Global JamesBones,JamesGhost ;; handles for pictures
JamesBones = CatchImage(#imageFond, ?bones)
JamesGhost = CatchImage(#imageB, ?ghost)
DataSection
bones: IncludeBinary #imageNameA
ghost: IncludeBinary #imageNameB
EndDataSection
;****************************************************
;- creating the window
imgW = ImageWidth(#imageFond)
imgH = ImageHeight(#imageFond)
;; #wintype = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
#wintype = #WS_POPUP
hWnd = OpenWindow(0, 200, 300, imgW+20, imgH+20, "ImageGadget", #winType)
If 0 = hWnd
End
EndIf
SetWindowColor(0, $AA9900)
;- installing gadgets
If 0 = CreateGadgetList(hWnd)
End
EndIf
;; a key to quickly close the window
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
#gX = 16 : gY = imgH - 13 - 2*25 : #gW = 90
ImageGadget(#imageFond, 10, 10, 100, 83, JamesBones)
TextGadget( #txtBox, #gX, 30, 200, 16, "Simple sample")
StringGadget(#strBox, #gX, 50, 200, 20, "a string for the road", #PB_String_BorderLess)
ButtonGadget(#bouton1, #gX, gY , #gW, 20, " He did", #PB_Button_Left)
ButtonGadget(#bouton2, #gX, gY+25, #gW, 20, "Something")
ButtonGadget(#bouton3, #gX, gY+50, #gW, 20, "Right ", #PB_Button_Right)
ButtonGadget(#cmdQuit, imgW-60, imgH - 13, 60, 20, "Quit")
ButtonGadget(#cmdImage, imgW-60-5-50, imgH - 13, 50, 20, "Ghost")
;; netMaaestro's suggestion - works perfectly
DisableGadget(#imageFond, 1)
HideGadget(#txtBox,1) ;; force Windows to display this control
HideGadget(#txtBox,0)
;****************************************************
;- main application loop *************************
Repeat
EventID = WaitWindowEvent()
If #PB_Event_Menu = EventID
kbd = EventMenu()
Select kbd
Case #PB_Shortcut_Escape: End
;;Case whatever: yes, real soon now
EndSelect
EndIf
If #PB_Event_Gadget = EventID
GadgetID = EventGadget()
Select GadgetID
Case #bouton1 To #bouton3 : TellMe(GadgetID)
Case #cmdImage : ChangeImage()
Case #cmdQuit: End
EndSelect
ElseIf #PB_Event_CloseWindow = EventID
End
EndIf
ForEver
Procedure.L ChangeImage()
For i = #txtBox To #cmdQuit
HideGadget(i,1)
Next
If GetGadgetData(#cmdImage) = 1
SetGadgetData(#cmdImage,0)
SetGadgetState(#imageFond,JamesBones)
SetGadgetText(#cmdImage,"Ghost")
Else
SetGadgetText(#cmdImage,"Bones")
SetGadgetData(#cmdImage,1)
SetGadgetState(#imageFond, JamesGhost)
EndIf
For i = #txtBox To #cmdQuit
HideGadget(i,0)
Next
EndProcedure
Procedure TellMe(id.L)
SetGadgetText(#txtBox, GetGadgetText(id))
;; MessageRequester("Info", "We have a Gadget with ID #" + Str(id) +".", 0)
EndProcedure