I understand from the Help files that ImageGadgets do not return Events such as mouseclicks.
I think it would be useful for simple applications that involve some interaction with an image but do not need very fast drawing (using the Sprite/Screen commands) to have this functionality.
This may be related to some other topics previously discussed , e.g. viewtopic.php?t=7243 , or may provide a workaround for some problems raised there.
ImageGadget returning Events
The following code is a CustomImage (as workaround).
As you can see in the header of the code, the core of this code was originally a part of GPI's/Freedimension's (both PB users...) CustomButton snippet.
As you can see in the header of the code, the core of this code was originally a part of GPI's/Freedimension's (both PB users...) CustomButton snippet.
Code: Select all
; CustomImageGadget by Franco
;
; This code 'is ripped out' from:
;
;/ CustomButtons
;/ GPI - 28.07.2003
;/
;/ Works only with BMP, not with ICO!
;/
;/ Original Custom Buttons by freedimension
;-
Structure CustomImage
hwnd.l
normal.l
EndStructure
NewList CImage_.CustomImage()
Procedure CustomImageGadget(id.l,x.l,y.l,w.l,h.l,Image.l)
ResetList(CImage_())
AddElement(CImage_())
CImage_()\normal = CreatePatternBrush_(Image)
CImage_()\hwnd=ButtonGadget(id,x,y,w,h,"",#BS_OWNERDRAW)
ProcedureReturn CImage_()\hwnd
EndProcedure
Procedure FillImageGadgets(lParam)
*dis.DRAWITEMSTRUCT = lParam
If *dis\CtlType=#ODT_BUTTON
ResetList(CImage_())
ok=#False
Repeat
If NextElement(CImage_())
If CImage_()\hwnd=*dis\hwndItem
pic=CImage_()\normal
FillRect_(*dis\hDC, *dis\rcItem, pic)
Result=#True
ok=#True
EndIf
Else
ok=#True
EndIf
Until ok
EndIf
EndProcedure
Procedure Callback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If Message = #WM_DRAWITEM
FillImageGadgets(lParam)
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(1, 10, 150, 200, 80, #PB_Window_TitleBar|#PB_Window_SystemMenu, "Button OwnerDraw")
SetWindowCallback(@Callback())
CreateGadgetList(WindowID())
CustomImageGadget(1, 5, 5, 32, 32, LoadImage(1, "picture1.bmp"))
CustomImageGadget(2, 55, 5, 32, 32, LoadImage(2, "picture2.bmp"))
CustomImageGadget(3,110, 5, 32, 32, LoadImage(3, "picture3.bmp"))
state=1
DisableGadget(3,state)
Repeat
event = WaitWindowEvent()
If event=#PB_Event_Gadget
If EventType()=#PB_EventType_LeftClick
Debug "Pressed ImageGadget:"+Str(EventGadgetID())
EndIf
EndIf
Until event = #PB_Event_CloseWindow
Last edited by fsw on Wed Aug 27, 2003 8:36 pm, edited 1 time in total.
I am to provide the public with beneficial shocks.
Alfred Hitshock
Re: ImageGadget returning Events
yes i agree on this for both imagegadgets and textgadgetsTiuri wrote: I think it would be useful for simple applications that involve some interaction with an image but do not need very fast drawing (using the Sprite/Screen commands) to have this functionality.
.
this is posted long ago by someone (dont remember)
works for both textgadget and imagegadgets (they start returning events
setwindowlong_(GadgetID(#About),#GWL_STYLE,getwindowlong_(GadgetID(#About),#GWL_STYLE)|256)
as asimpler workaround to GPI (supperior ?) customgadget
Christos
Re: ImageGadget returning Events
plouf wrote: yes i agree on this for both imagegadgets and textgadgets
this is posted long ago by someone (dont remember)
works for both textgadget and imagegadgets (they start returning events
setwindowlong_(GadgetID(#About),#GWL_STYLE,getwindowlong_(GadgetID(#About),#GWL_STYLE)|256)
as asimpler workaround to GPI (supperior ?) customgadget



Didn't know this one, thanks.
I am to provide the public with beneficial shocks.
Alfred Hitshock