Page 1 of 1

What is a Canvas Container?

Posted: Thu Feb 02, 2017 9:44 am
by Wolfram
Can someone explain me what a Canvas Container does?

Re: What is a Canvas Container?

Posted: Thu Feb 02, 2017 9:57 am
by Fred
It's a canvas where your can put gadget in it, like a ContainerGadget().

Re: What is a Canvas Container?

Posted: Thu Feb 02, 2017 10:02 am
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

Re: What is a Canvas Container?

Posted: Thu Feb 02, 2017 11:33 am
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.

Re: What is a Canvas Container?

Posted: Thu Feb 02, 2017 2:33 pm
by Fred
PureBasic does support the render gadget the same way the OS does, we don't do anything special.

Re: What is a Canvas Container?

Posted: Fri Feb 03, 2017 9:01 am
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