Window Events

Linux specific forum
larry
New User
New User
Posts: 9
Joined: Fri Sep 02, 2005 7:31 pm

Window Events

Post 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
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post 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
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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
Post Reply