Page 1 of 1

Window Events

Posted: Thu Sep 29, 2005 5:25 pm
by larry
I have some questions about events and the way they operate. It could be my misunderstanding or bugs under Linux. The following code demonstrates the issues:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Test")
CreateGadgetList(WindowID())
result = LoadImage(1,"graphics/but5.bmp")
If(result=0) 
  Debug "Can't Load Image"
EndIf

ImageGadget(2, 10, 10, 200, 60, UseImage(1))
ButtonImageGadget(3, 10, 110, 179, 60, UseImage(1))
ButtonGadget(4,10,210,100,50,"Test")

Repeat
  Event.l = WaitWindowEvent()
  Eventtype = EventType()
  Id = EventGadgetID()
  
  Debug "Event  "+Str(Event)
  Debug "Event Type "+Str(Eventtype)
  Debug "Gadget ID "+Str(Id)
  Debug " "
 
Until Event = #PB_Event_CloseWindow 
A) Mousing over ButtonGadget and ButtonImageGadget produces all 0’s for Event, Event Type, and Gadget Ids. Why have any event if you can’t distinguish which gadget it is on?
B) Mousing over ImageGadget does nothing.
C) Left click works on ButtonGadget and ButtonImageGadget, but not on ImageGadget.
D) Right click does not return correct values anywhere.
E) Left click in Window, outside of Gadgets, returns an Event but not the Left Click event. I can’t wait for a ‘0’ event, as in my real program I can not use WaitWindowEvent, and WindowEvent returns a constant string of ‘0’ events.

This test program runs quite different under Windows. Any thoughts?
Fedora Core 4 PB 3.94

Posted: Fri Oct 07, 2005 9:39 am
by walker
Hi,

this is because of the "incorrect" order of WaitWindowEvent(), EventGadgetId() and EventType()....

After The WaitWindowEvent you have to check weather it's a GadgetEvent or a MenuEvent.

After knowing this, you can query the gadget which fired the event. After this, you finally can check the Event that happened (Click, doubleclick etc.)

Btw. The Button and ImageButton doesn't support the EventType (see help)

On Linux the ImageGadget does not fire any Event... so this is maybe a bug... I'll check this out and report it in the BUG-Forum...

Code: Select all

OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Test")
CreateGadgetList(WindowID())
result = LoadImage(1,"graphics/but5.bmp")
If(result=0)
  Debug "Can't Load Image"
EndIf

ImageGadget(2, 10, 10, 200, 60, UseImage(1))
ButtonImageGadget(3, 10, 110, 179, 60, UseImage(1))
ButtonGadget(4,10,210,100,50,"Test") 

Repeat
  Event.l = WaitWindowEvent()
      
If event = #PB_EventGadget
    Id = EventGadgetID()
    If id = 2
        Eventtype = EventType()
    EndIf
    
    Debug "Event  "+Str(Event)
    Debug "Event Type "+Str(Eventtype)
    Debug "Gadget ID "+Str(Id)
    Debug " "
EndIf
 
Until Event = #PB_Event_CloseWindow

Ulf

Posted: Fri Oct 07, 2005 12:44 pm
by Nik
I think another thing that prevents you from problems like flickering especially when you have a lot of code within the event loop is checking until event.l=0

Example:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Test")
CreateGadgetList(WindowID())
result = LoadImage(1,"graphics/but5.bmp")
If(result=0)
  Debug "Can't Load Image"
EndIf

ImageGadget(2, 10, 10, 200, 60, UseImage(1))
ButtonImageGadget(3, 10, 110, 179, 60, UseImage(1))
ButtonGadget(4,10,210,100,50,"Test")

Repeat
;A lot of Code withinh the loop

Repeat
  Event.l = WindowEvent()
     
If event = #PB_EventGadget
    Id = EventGadgetID()
    If id = 2
        Eventtype = EventType()
    EndIf
   
    Debug "Event  "+Str(Event)
    Debug "Event Type "+Str(Eventtype)
    Debug "Gadget ID "+Str(Id)
    Debug " "
EndIf
if Event = #PB_Event_CloseWindow : End : Endif
Until Event=0
delay(1)
;Here it wouldn´t be a problem to write a lot of code too
forever