Page 1 of 1

Canvas vs Image

Posted: Sun Jun 19, 2016 9:46 pm
by barryem
I'm a little confused about when to use an Image gadget and when to use a Canvas gadget. Could someone discuss their differences a bit? And the different ways they might be used?

For example, I'm making a little drawing program as a way to learn a bit about graphics in PB and I'm using a canvas for the drawing area. Actually that code came from the sample included with PB. Then I used another canvas for the palette. I began wondering if there was any reason I should have used an image gadget instead. It does have to deal with both left and right mouse cllicks and will probably deal with gradients and alpha down the road as I learn more about this.

Any discussion or tips are appreciated. By the way I'm hoping for some discussion about this and not a simple answer about which to use, although that might be nice too. This isn't a problem I'm trying to solve. I just want to undestand it more.

Barry

Re: Canvas vs Image

Posted: Sun Jun 19, 2016 10:07 pm
by Little John
Two main differences are:

Re: Canvas vs Image

Posted: Sun Jun 19, 2016 10:10 pm
by barryem
Thank you! That helps a lot.

Barry

Re: Canvas vs Image

Posted: Sun Jun 19, 2016 10:24 pm
by davido
Hi Little John,

I always thought that the CanvasGadget did not support the Alpha channel.
However, the demo code from RotateCoordinates from the VectorDrawing Library, appears to contradict that as it clearly shows the Alpha channel working.
What am I missing?

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)    
    
    If StartVectorDrawing(CanvasVectorOutput(0))
      VectorFont(LoadFont(0, "Times New Roman", 60, #PB_Font_Bold))

      VectorSourceColor(RGBA(0, 0, 255, 128))
      MovePathCursor(50, 50)
      DrawVectorText("Test")
    
      ScaleCoordinates(0.7, 0.9)
    
      VectorSourceColor(RGBA(255, 0, 0, 128))
      MovePathCursor(50, 50)
      DrawVectorText("Test")    
    
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

Re: Canvas vs Image

Posted: Mon Jun 20, 2016 1:06 am
by netmaestro
No. An image of any depth can accept the results of alphablended output. If the canvasgadget actually did support the alpha channel then the canvas background would be the same as the window background with this code:

Code: Select all

If OpenWindow(0, 0, 0, 600, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(255,0,255))
    CanvasGadget(0, 0, 0, 400, 200)    
    
    If StartVectorDrawing(CanvasVectorOutput(0))
      VectorFont(LoadFont(0, "Times New Roman", 60, #PB_Font_Bold))

      VectorSourceColor(RGBA(0, 0, 255, 128))
      MovePathCursor(50, 50)
      DrawVectorText("Test")
    
      ScaleCoordinates(0.7, 0.9)
    
      VectorSourceColor(RGBA(255, 0, 0, 128))
      MovePathCursor(50, 50)
      DrawVectorText("Test")    
    
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

Re: Canvas vs Image

Posted: Mon Jun 20, 2016 2:52 am
by barryem
I had no idea about the vector drawing library. Thanks for calling my attention to it. I just might have some fun with that. :)

Barry

Re: Canvas vs Image

Posted: Mon Jun 20, 2016 5:45 am
by davido
@netmaestro,
Thank you for the explanation, I now understand. :)

Re: Canvas vs Image

Posted: Mon Jun 20, 2016 5:44 pm
by Little John
Hi davido,

what can I say? Netmaestro was faster. :-)

Re: Canvas vs Image

Posted: Sat Jun 25, 2016 7:35 pm
by barryem
I'm playing with doing things on imagegadgets and canvasgadgets and I don't see any obvious way to copy an image to a canvas. Is there a way to do that?

Thanks,
Barry

Re: Canvas vs Image

Posted: Sat Jun 25, 2016 7:37 pm
by netmaestro
SetGadgetAttribute(#Canvas, #PB_Canvas_Image, ImageID(-image#-))

Re: Canvas vs Image

Posted: Sun Jun 26, 2016 2:35 pm
by barryem
Thank you!

Barry