What is a Canvas Container?

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 608
Joined: Thu May 30, 2013 4:39 pm

What is a Canvas Container?

Post by Wolfram »

Can someone explain me what a Canvas Container does?
macOS Catalina 10.15.7
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: What is a Canvas Container?

Post by Fred »

It's a canvas where your can put gadget in it, like a ContainerGadget().
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: What is a Canvas Container?

Post by walbus »

Primary you can as sample output Buttons or other gadgets on a window, but not on a canvas

Set you now the container flag on a canvas gadget, you can output all gadgets at the same directly on canvas

You can draw all you want on the canvas and the buttons or other gadgets will not influence

All graphic options works now behind the buttons and gadgets

The Gadgets are displaying on the canvas container same sprites

This is a very important new feature
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: What is a Canvas Container?

Post by Mistrel »

Out of curiosity, is this a workaround for PureBasic not supporting the render order of gadgets? I would think that this could be accomplished with a ContainerGadget containing both a CanvasGadget and another control but not if the canvas gadget is rendered on top.
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: What is a Canvas Container?

Post by Fred »

PureBasic does support the render gadget the same way the OS does, we don't do anything special.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: What is a Canvas Container?

Post by applePi »

it is good addition thanks

Code: Select all

OpenWindow(0, 0, 0, 300, 300, "Canvas Container", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   #Button = 4  
   CanvasGadget(0, 40, 40, 210, 200, #PB_Canvas_Container)
   EditorGadget(1, 0, 0, 200, 30, #PB_Editor_WordWrap)
   ButtonGadget(#Button, 0, 40, 60, 40, "Stop/Rot")
   OpenGLGadget(2, 0, 105, 100, 100)
   CloseGadgetList()
   
  AddGadgetItem(1, 0, "Thats Hot")
 
  ;SetActiveGadget(0)
  Global run = 1
  If StartDrawing(CanvasOutput(0))
     Circle(160, 120, 7, RGB(0, 0, 250))
     Circle(160, 150, 10, RGB(255, 0, 0))
     StopDrawing()
   EndIf
  x.f=100
  If StartDrawing(CanvasOutput(0))
  For i=0 To 1000
    y.f=Sin(x)*20
    Plot(x,y+80,RGB(255,0,0))
    x+0.1
  Next
  StopDrawing()
  EndIf
  
  glDrawBuffer_(#GL_FRONT_AND_BACK) 
  
  Repeat
    Repeat 
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_Gadget
          If EventGadget() = #Button
            run ! 1
          EndIf
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until EventID = 0
  
  glMatrixMode_(#GL_PROJECTION)
  glLoadIdentity_()
  ;gluPerspective(	GLdouble fovy,GLdouble aspect, GLdouble zNear, GLdouble zFar);
  gluPerspective_(30, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 100.0)
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glLoadIdentity_()
  glTranslatef_(0.0, 0.0, -8.0)
  If run
  rot+1
  glRotatef_(rot*run, 0, 1, 0)
  Else
  glRotatef_(rot, 0, 1, 0)
  EndIf
  glColor3f_(1.0, 1.0, 1.0)
  glBegin_(#GL_TRIANGLES)      ; Start drawing a triangle
    glColor3f_ ( 1.5,  0.0, 0.0) ; Set top point of triangle to Red
    glVertex3f_( 0.0,  1.5, 0.0) ; First point of the triangle
    glColor3f_ ( 0.0,  1.5, 0.0) ; Set left point of triangle to Green
    glVertex3f_(-1.5, -1.5, 0.0) ; Second point of the triangle
    glColor3f_ ( 0.0,  0.0, 1.5) ; Set right point of triangle to Blue
    glVertex3f_( 1.5, -1.5, 0.0) ; Third point of the triangle
   glEnd_()                     ; Don
        
   SetGadgetAttribute(2, #PB_OpenGL_FlipBuffers, #True)
    
 Until Quit = #True 
  
 End
 
Post Reply