Canvas containter gadgets gets greyed-out automatically

Just starting out? Need help? Post your questions and find answers here.
hrcoder
New User
New User
Posts: 5
Joined: Sat Apr 01, 2017 1:54 am
Location: USA

Canvas containter gadgets gets greyed-out automatically

Post by hrcoder »

Hello PureBasic community,
A NewB.

In the following code when I display a ImageGadget that has a 32 bit image depth, all my Canvas container gadgets are greyed-out.

I do not think this is normal, this may be a bug, but I am a newb and the mistake maybe because of my lack of Purebasic knowledge.
Please run and review the code that I posted and explain to me what my mistake is, or give pointers on where to find the answer.

Thanks in advance.

If this is a bug, could an administrator please move this topic to the appropriate bug report.

Thanks again for any assistants.

Note: I only tested the code on PureBasic6.00 Beta 7(x86).

Code: Select all

EnableExplicit

Procedure.i OtherImage(imgW.i, imgH.i, imgD.i = 24)
  Protected img = CreateImage(#PB_Any, imgW, imgH, imgD)
  If IsImage(img)
    StartDrawing(ImageOutput(img))
      Box(0, 0, imgW, imgH, $ECE9D8)
      DrawingMode(#PB_2DDrawing_Gradient)
      BackColor(RGB(255, 0, 0))
      FrontColor(RGB(128, 0, 0))
      CircularGradient(40,40, 40)
      Circle(50, 50, 16)
      DrawRotatedText(13, 2, "Other", 315, RGB(255, 0, 0))
      DrawRotatedText(70, 58, "Image", 315, RGB(255, 0, 0))
      StopDrawing()
  Else
    MessageRequester("OtherImage Error", "variable img is not a valid image object", #PB_MessageRequester_Ok|#PB_MessageRequester_Warning)    
  EndIf
  ProcedureReturn img
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Test Canvas Container and ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ;SetWindowColor(0, RGB(240, 255, 255)); un-comment this line, then only image with depth 32 is greyed-out on Canvas
  
  Define loadedImg
  Define imgFileName.s = #PB_Compiler_Home + "examples\sources\Data\PureBasic.bmp"
  
  CanvasGadget(#PB_Any, 0, 0, 300, 400, #PB_Canvas_Container) ; comment line and all ImageGadgets are displayed
  
    TextGadget(#PB_Any, 5, 0, 390, 25, "Canvas Container Gadgets", #PB_Text_Border|#PB_Text_Center)
    
    loadedImg = LoadImage(#PB_Any, imgFileName)    
    If IsImage(loadedImg)
      ImageGadget(#PB_Any, 50, 40, 200, 100, ImageID(loadedImg))  ; image depth 24 bits 
    EndIf
      
    ImageGadget(#PB_Any, 10, 150, 200, 100, ImageID(OtherImage(100, 100))) ; image depth 24 bits
    
    ; Comment the following line and Canvas gadgets are Not greyed-out
    ImageGadget(#PB_Any, 150, 260, 200, 100, ImageID(OtherImage(100, 100, 32))) ; image depth 32 bits 
    
  CloseGadgetList() ; comment this line and CanvasGadget line, then all Gadgets are shown correctly (eliminate the Canvas Container)
  
  ; Other MainWindow gadgets
  TextGadget(#PB_Any, 305, 25, 190, 25, "MainWindow Other Gadgets", #PB_Text_Border|#PB_Text_Center)
  
  ; Comment SetWindowColor line and the Canvas ImageGadet that has a image depth of 32 bits, then
  ; un-comment the following line and the Canvas gadgets will be greyed-out as well. Mysterious behavior.
  ;ImageGadget(#PB_Any, 310, 260, 200, 100, ImageID(OtherImage(100, 100, 32))) ; image depth 32 bits
  

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

User avatar
Danilo
Addict
Addict
Posts: 3038
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Canvas containter gadgets gets greyed-out automatically

Post by Danilo »

Works fine on macOS.

Just had to convert backslash to slash in the path to the image:

Code: Select all

Define imgFileName.s = #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp"
and change the TextGadget color from white to another color to actually see it on the white canvas:

Code: Select all

Define txt = TextGadget(#PB_Any, 5, 0, 390, 25, "Canvas Container Gadgets", #PB_Text_Border|#PB_Text_Center)
SetGadgetColor(txt,#PB_Gadget_FrontColor,RGB($FF,$00,$FF))
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8285
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Canvas containter gadgets gets greyed-out automatically

Post by netmaestro »

The ImageGadget seems to behave differently when it contains a 32bit image. However, in all cases, 32bit or 24bit, the gadget will work as expected if you follow the documentation for it:
ImageGadget Doc wrote:The gadget adjusts its width and height to fit the displayed image. The specified width and height are only used when no image is displayed.
You aren't displaying the imagegadgets as placeholders so you need to remove the width and height values you put in there. With 0,0 for width and height (which is correct when the gadget contains an image) all works as expected on Windows too:

Code: Select all

EnableExplicit

Procedure.i OtherImage(imgW.i, imgH.i, imgD.i = 24)
  Protected img = CreateImage(#PB_Any, imgW, imgH, imgD)
  If IsImage(img)
    StartDrawing(ImageOutput(img))
      Box(0, 0, imgW, imgH, $ECE9D8)
      DrawingMode(#PB_2DDrawing_Gradient)
      BackColor(RGB(255, 0, 0))
      FrontColor(RGB(128, 0, 0))
      CircularGradient(40,40, 40)
      Circle(50, 50, 16)
      DrawRotatedText(13, 2, "Other", 315, RGB(255, 0, 0))
      DrawRotatedText(70, 58, "Image", 315, RGB(255, 0, 0))
      StopDrawing()
  Else
    MessageRequester("OtherImage Error", "variable img is not a valid image object", #PB_MessageRequester_Ok|#PB_MessageRequester_Warning)    
  EndIf
  ProcedureReturn img
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Test Canvas Container and ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(240, 255, 255)); un-comment this line, then only image with depth 32 is greyed-out on Canvas
  
  Define loadedImg
  Define imgFileName.s = #PB_Compiler_Home + "examples\sources\Data\PureBasic.bmp"
  
  CanvasGadget(#PB_Any, 0, 0, 300, 400, #PB_Canvas_Container) ; comment line and all ImageGadgets are displayed
  
    TextGadget(#PB_Any, 5, 0, 390, 25, "Canvas Container Gadgets", #PB_Text_Border|#PB_Text_Center)
    
    loadedImg = LoadImage(#PB_Any, imgFileName)    
    If IsImage(loadedImg)
      ImageGadget(#PB_Any, 50, 40, 0, 0, ImageID(loadedImg))  ; image depth 24 bits 
    EndIf
      
    ImageGadget(#PB_Any, 10, 150, 0, 0, ImageID(OtherImage(100, 100))) ; image depth 24 bits
    
    ; Comment the following line and Canvas gadgets are Not greyed-out
    ImageGadget(#PB_Any, 150, 260, 0, 0, ImageID(OtherImage(100, 100, 32))) ; image depth 32 bits 
    
  CloseGadgetList() ; comment this line and CanvasGadget line, then all Gadgets are shown correctly (eliminate the Canvas Container)
  
  ; Other MainWindow gadgets
  TextGadget(#PB_Any, 305, 25, 190, 25, "MainWindow Other Gadgets", #PB_Text_Border|#PB_Text_Center)
  
  ; Comment SetWindowColor line and the Canvas ImageGadet that has a image depth of 32 bits, then
  ; un-comment the following line and the Canvas gadgets will be greyed-out as well. Mysterious behavior.
  ;ImageGadget(#PB_Any, 310, 260, 200, 100, ImageID(OtherImage(100, 100, 32))) ; image depth 32 bits
  

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
I don't know if there's something here you could call a bug or not, but it seems that if all works properly when the doc is followed, probably not.
BERESHEIT
hrcoder
New User
New User
Posts: 5
Joined: Sat Apr 01, 2017 1:54 am
Location: USA

Re: Canvas containter gadgets gets greyed-out automatically

Post by hrcoder »

Thank you netmaestro.
I will read and follow the documentation more thoroughly from now on.
Post Reply