Display Image on Screen with Button at same Time?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

Something is wrong with the follow code:

hWnd = OpenWindow(0, 0, 0, 796, 550, #PB_Window_SystemMenu, "Test")
CreateGadgetList(WindowID())
LoadImage(0,"test.bmp")
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 20, 10)
StopDrawing()
ButtonGadget(15, 300, 335, 80, 24, "Quit")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
End

You must create a test.bmp to test this. If the ButtonGadget line is ; (rem'd) out, then the test.bmp image is displayed. But not the button. If the the LoadImage, StartDrawing, DrawImage, StopDrawing lines are ; (rem'd) out, then the button Quit is displayed but not the image. It's an either or situation. I can get either one to display on the window, but not both at the same time. Does anyone know what I'm doing wrong?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

Alright, I solved my problem by switching two lines to this:

hWnd = OpenWindow(0, 0, 0, 796, 550, #PB_Window_SystemMenu, "Test")

CreateGadgetList(WindowID())
ButtonGadget(15, 300, 335, 80, 24, "Quit")
LoadImage(0,"test.bmp")
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 20, 10)
StopDrawing()

Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow

End

Notice the button is created first, then the image created second. By simply putting things in this order, it works! For some reason the image must be drawn after the buttons.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

better use and ImageGadget() or you will get a lot of refresh problem...

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

Hi Fred. You are right, it stopped working. Can you give me an example of using ImageGadget(), there isn't one in the Help docs.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

For example, this code below doesn't work:

hWnd = OpenWindow(0, 0, 0, 796, 550, #PB_Window_SystemMenu, "Test")

CreateGadgetList(WindowID())
ButtonGadget(1, 315, 160, 102, 29, "Option1")
ButtonGadget(2, 315, 200, 102, 29, "Option2")

LoadImage(0,"test.bmp")
StartDrawing(WindowOutput())
DrawImage(UseImage(0), 0, 0)
StopDrawing()
ImageGadget(3, 10,10,150,150,0)
ClosePanelGadget()
SetWinBackgroundColor(hWnd, RGB( 34, 85, 136))
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 1 ; Quit...
FreeGadget (1)

Case 2 ;
FreeGadget (2)
EndSelect

EndIf

Until EventID = #PB_EventCloseWindow
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

ImageGadget needs the ImageID, not the Number, so use it like this:

ImageGadget(3, 10,10,150,150,UseImage(0))

Should work then...

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by LJ.

That did it Timo, thank you.
Post Reply