ImageGadget returning Events

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tiuri
User
User
Posts: 20
Joined: Fri Aug 15, 2003 2:44 am
Location: Canberra, Australia

ImageGadget returning Events

Post by Tiuri »

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.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

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.

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
plouf
Enthusiast
Enthusiast
Posts: 281
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Re: ImageGadget returning Events

Post by plouf »

Tiuri 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.
.
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
Christos
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: ImageGadget returning Events

Post by fsw »

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
8) 8) 8)
Didn't know this one, thanks.

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

BTW:

setwindowlong_(hGadget,#GWL_STYLE,getwindowlong_(hGadget,#GWL_STYLE)|256)

only fires LeftClickEvents...

Is there a way to get all Events going :?:

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply