Display of two PB "images"

Just starting out? Need help? Post your questions and find answers here.
sospel
User
User
Posts: 16
Joined: Wed Sep 17, 2008 3:34 pm

Display of two PB "images"

Post by sospel »

Hello!
I have a small problem of display : to compare the behavior of two graphs, I created two "images" in a window to draw a graph in each image. The problem is that only the window and its two images display at once, but graphs appear only if I minimize the window to open again it then, either that I "move" it out of the screen, to return it in the middle of the screen ??!!
To show you what I made, I simplified the program by replacing graphs by one "BOX" and a "CIRCLE".
Could anybody say to me what I badly programmed ?
And also, a supplementary question: why images numbers are the same?
Thank you in advance for your help !!
Sospel
--------------------------------------------------------------
Here is my program :

Code: Select all

   ;
   ; open window n°0 :  ----------------------------------------
   ; 
   ValOptions = 0
   ValOptions = ValOptions | #PB_Window_SystemMenu
   ValOptions = ValOptions | #PB_Window_MinimizeGadget
   ValOptions = ValOptions | #PB_Window_SizeGadget
   N_WinMain = 0
   winhight.F  = 680
   winlarg.F   = winhight * Sqr(2)
   title$         = "MAIN WINDOW"
   OpenWindow(N_WinMain,20,20,winlarg,winhight,title$, ValOptions)
   SetWindowColor(N_WinMain, RGB(192, 83, 70))
   H_WinMain = WindowID(N_WinMain)
   CreateGadgetList(H_WinMain)
   ;
   ; open "image" n°1 ------------------------------------
   N_Image1   = 1
   imaghight.F = winhight * 0.90
   imaglarg.F   = winlarg  * 0.45
   CreateImage(N_Image1,imaglarg,imaghight,32)
   ImageGadget(N_Image1,10,20,0,0,ImageID(N_Image1))
   ident1 = ImageOutput(N_Image1)
   If StartDrawing(ImageOutput(N_Image1))
       Box (80,20,100,200,RGB(221, 120, 34))
       DrawText(100,30,Str(ident1),RGB(0,0,0))
       StopDrawing()   
   EndIf
   ;
   ; open "image" n°2 -------------------------------------
   N_Image2    = 2
   imaghight.F = winhight * 0.60
   imaglarg.F  = winlarg * 0.45
   CreateImage(N_Image2,imaglarg,imaghight,32)
   ImageGadget(N_Image2,500,100,0,0,ImageID(N_Image2))
   ident2 = ImageOutput(N_Image2)
   If StartDrawing(ImageOutput(N_Image2))
        Circle (120,150,90,RGB($40,$40,$FF))
        DrawText(100,100,Str(ident2),RGB(0,0,0))
       StopDrawing()   
   EndIf
   ;
   Repeat 
   Until WaitWindowEvent () = #PB_Event_CloseWindow  
   ;
  End
[/code]
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You need to reposition the ImageGadget() commands :

Code: Select all

; open window n°0 :  ---------------------------------------- 
   ; 
   ValOptions = 0 
   ValOptions = ValOptions | #PB_Window_SystemMenu 
   ValOptions = ValOptions | #PB_Window_MinimizeGadget 
   ValOptions = ValOptions | #PB_Window_SizeGadget 
   N_WinMain = 0 
   winhight.F  = 680 
   winlarg.F   = winhight * Sqr(2) 
   title$         = "MAIN WINDOW" 
   OpenWindow(N_WinMain,20,20,winlarg,winhight,title$, ValOptions) 
   SetWindowColor(N_WinMain, RGB(192, 83, 70)) 
   H_WinMain = WindowID(N_WinMain) 
   CreateGadgetList(H_WinMain) 
   ; 
   ; open "image" n°1 ------------------------------------ 
   N_Image1   = 1 
   imaghight.F = winhight * 0.90 
   imaglarg.F   = winlarg  * 0.45 
   CreateImage(N_Image1,imaglarg,imaghight,32) 
   ident1 = ImageOutput(N_Image1) 
   If StartDrawing(ImageOutput(N_Image1)) 
       Box (80,20,100,200,RGB(221, 120, 34)) 
       DrawText(100,30,Str(ident1),RGB(0,0,0)) 
       StopDrawing()    
   EndIf 
   ImageGadget(N_Image1,10,20,0,0,ImageID(N_Image1)) 
   ; 
   ; open "image" n°2 ------------------------------------- 
   N_Image2    = 2 
   imaghight.F = winhight * 0.60 
   imaglarg.F  = winlarg * 0.45 
   CreateImage(N_Image2,imaglarg,imaghight,32) 
   ident2 = ImageOutput(N_Image2) 
   If StartDrawing(ImageOutput(N_Image2)) 
        Circle (120,150,90,RGB($40,$40,$FF)) 
        DrawText(100,100,Str(ident2),RGB(0,0,0)) 
       StopDrawing()    
   EndIf 
   ImageGadget(N_Image2,500,100,0,0,ImageID(N_Image2)) 
   ; 
   Repeat 
   Until WaitWindowEvent () = #PB_Event_CloseWindow  
   ; 
  End
I may look like a mule, but I'm not a complete ass.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

> You need to reposition the ImageGadget() commands :

if the program gets more complicated, this maybe not sufficent.

point is, you have to reassign the images to the gadgets to force a refresh.
so, each time you actualized the images, call a SetGadgetState(N_Image2, ImageID(N_Image2))
oh... and have a nice day.
sospel
User
User
Posts: 16
Joined: Wed Sep 17, 2008 3:34 pm

Display of two PB "images"

Post by sospel »

OK, these answers clear up my problem :D

Thanks to srod and Kaeru Gaman

Sospel
Post Reply