示例#1
0
文件: TestJob.cpp 项目: asyr625/tinia
bool TestJob::init()
{


   m_model->addStateListener(this);
   tinia::model::Viewer viewer;
   viewer.height = 500;
   viewer.width = 500;
   m_model->addElement("viewer", viewer);
   m_model->addElement<std::string>( "boundingbox", "-1.1 -1.1 -1.1 1.1 1.1 1.1" );
   m_model->addElement<int>( "renderlist", 0 );

   m_model->addElement<bool>("myTab", false);
   m_model->addAnnotation("myTab", "My tab");
      m_model->addElement<bool>("myBool", false);
   m_model->addElement<std::string>("myVal", "THIS WORKS!");

   const char* restrictions[] = {"select1", "select2", "select3", "select4"};
   m_model->addElementWithRestriction<std::string>("myVal2", "select3",
                                                       &restrictions[0], &restrictions[4]);

   m_model->addAnnotation("myVal2", "My special value");

   m_model->addConstrainedElement<int>("myIntBA", 5,0, 900);
   m_model->addConstrainedElement<double>("myDouble", 10., 0., 11.);
   m_model->addElement<bool>("myButton", false);

   m_model->addElement<bool>( "details", true, "Popup" );

   m_model->addAnnotation("myButton", "My pushButton");

   tinia::model::File file;
   m_model->addElement("SpecialFile", file);
   m_model->addAnnotation("SpecialFile", "Open file");
   m_model->addElement("SpecialFileName", file.name());

   using namespace tinia::model::gui;
   TabLayout* root = new TabLayout();
   HorizontalLayout *superLayout = new HorizontalLayout();

   Grid *mainGrid = new Grid(16, 1);
   //superLayout->addChild(mainGrid);
   Tab *mainTab = new Tab("myTab");
   mainTab->setChild(superLayout);
   root->addChild(mainTab);


   TabLayout *subTablayout = new TabLayout();
   Tab* subTab = new Tab("myBool");

   subTablayout->addChild(subTab);

   subTab->setChild(mainGrid);

   superLayout->addChild(subTablayout);

   // Simple Label-input-layout
   Grid *input1Grid = new Grid(4,3);
   mainGrid->setChild(0,0, input1Grid);
   input1Grid->setChild(0, 0, new Label("myVal"));
   input1Grid->setChild(0, 1, (new TextInput("myVal"))->setEnabledKey( "myTab", true ) );

   input1Grid->setChild(1,0, new Label("myVal2"));
   input1Grid->setChild(1,1, new ComboBox("myVal2"));

   input1Grid->setChild(2,0, new Label("myVal2"));
   input1Grid->setChild(2,1, new RadioButtons("myVal2"));

   PopupButton* popup = new PopupButton("details", false);
   input1Grid->setChild(2, 2, popup );
   popup->setEnabledKey( "myTab" );

   PopupButton* popup2 = new PopupButton( "myVal", true );
   input1Grid->setChild(3, 2, popup2 );

   popup2->setChild( new TextInput("myVal" ) );


   ElementGroup* popup_group = new ElementGroup( "myTab", true );
   popup->setChild( popup_group );
   popup_group->setChild( new RadioButtons( "myVal2" ) );


   mainGrid->setChild(1, 0, new SpinBox("myIntBA"));
   mainGrid->setChild(2, 0, new TextInput("myIntBA"));
   mainGrid->setChild(3, 0, new CheckBox("myTab"));
   mainGrid->setChild(4, 0, new CheckBox("myTab"));
   mainGrid->setChild(5, 0, new Button("myButton"));
   mainGrid->setChild(6, 0, new HorizontalSlider("myIntBA"));
   mainGrid->setChild(8,0, new DoubleSpinBox("myDouble"));
   mainGrid->setChild(9, 0, new CheckBox("myBool"));
   mainGrid->setChild(10, 0, new VerticalExpandingSpace());
   mainGrid->setChild(11, 0, new Label("myDouble", true ) );
   mainGrid->setChild(12, 0, new FileDialogButton("SpecialFile"));
   mainGrid->setChild(13, 0, new Label("SpecialFileName", true));

   ElementGroup* elemGroup = new ElementGroup("myTab", false);
   elemGroup->setVisibilityKey( "myTab" );

   elemGroup->setChild( new TextInput("myVal") );
   mainGrid->setChild(7, 0, elemGroup);

   Grid* canvasGrid = new Grid(2,1);
   Canvas *canvas = new Canvas("viewer", "renderlist", "boundingbox" );

   canvasGrid->setChild(0,0, canvas);
   VerticalLayout* verticalLayout = new VerticalLayout;
   verticalLayout->setVisibilityKey( "myBool" );
   verticalLayout->addChild(elemGroup);
   verticalLayout->addChild(elemGroup);
   verticalLayout->addChild(elemGroup);
   canvasGrid->setChild(1,0, verticalLayout);
   superLayout->addChild(canvasGrid);
   m_model->setGUILayout(root, DESKTOP);



   // ---- Set up renderlist data

   // Geometry for a simple line segment cube
   float wire_cube_pos[12*2*3] = {
       0.f, 0.f, 0.f,  1.f, 0.f, 0.f,
       0.f, 1.f, 0.f,  1.f, 1.f, 0.f,
       0.f, 0.f, 0.f,  0.f, 1.f, 0.f,
       1.f, 0.f, 0.f,  1.f, 1.f, 0.f,
       0.f, 0.f, 0.f,  0.f, 0.f, 1.f,
       0.f, 1.f, 0.f,  0.f, 1.f, 1.f,
       1.f, 0.f, 0.f,  1.f, 0.f, 1.f,
       1.f, 1.f, 0.f,  1.f, 1.f, 1.f,
       0.f, 0.f, 1.f,  1.f, 0.f, 1.f,
       0.f, 1.f, 1.f,  1.f, 1.f, 1.f,
       0.f, 0.f, 1.f,  0.f, 1.f, 1.f,
       1.f, 0.f, 1.f,  1.f, 1.f, 1.f,
   };
   m_renderlist_db.createBuffer( "wire_cube_pos" )->set( wire_cube_pos, 12*2*3 );
   m_renderlist_db.createAction<tinia::renderlist::Draw>( "wire_cube_draw" )
           ->setNonIndexed( tinia::renderlist::PRIMITIVE_LINES, 0, 12*2 );
   // Solid color shader
   std::string solid_vs =
           "uniform mat4 MVP;\n"
           "attribute vec3 position;\n"
           "void\n"
           "main()\n"
           "{\n"
           "    gl_Position = MVP * vec4( position, 1.0 );\n"
           "}\n";
   std::string solid_fs =
           "#ifdef GL_ES\n"
           "precision highp float;\n"
           "#endif\n"
           "uniform vec3 color;\n"
           "void\n"
           "main()\n"
           "{\n"
           "    gl_FragColor = vec4( color, 1.0 );\n"
           "}\n";
   m_renderlist_db.createShader( "solid" )
           ->setVertexStage( solid_vs )
           ->setFragmentStage( solid_fs );
   m_renderlist_db.createAction<tinia::renderlist::SetShader>( "solid_use" )
           ->setShader( "solid" );
   m_renderlist_db.createAction<tinia::renderlist::SetUniforms>( "solid_orient" )
           ->setShader( "solid" )
           ->setSemantic( "MVP", tinia::renderlist::SEMANTIC_MODELVIEW_PROJECTION_MATRIX );
   m_renderlist_db.createAction<tinia::renderlist::SetUniforms>( "solid_white" )
           ->setShader( "solid" )
           ->setFloat3( "color", 1.f, 1.f, 1.f );
   m_renderlist_db.createAction<tinia::renderlist::SetUniforms>( "solid_green" )
           ->setShader( "solid" )
           ->setFloat3( "color", 0.f, 1.f, 0.f );

   // Combine the wire cube geometry with the solid shader
   m_renderlist_db.createAction<tinia::renderlist::SetInputs>( "solid_wire_cube_input" )
           ->setShader( "solid" )
           ->setInput( "position", "wire_cube_pos", 3 );

   // Position and scale the two instances, encoded as a transform matric and its inverse
   float shape0_to_world[16] = {
       2.f, 0.f, 0.f, -1.0f,
       0.f, 2.f, 0.f, -1.0f,
       0.f, 0.f, 2.f, -1.0f,
       0.f, 0.f, 0.f,  1.f,
   };
   float shape0_from_world[16] = {
       0.5f,  0.f,  0.f,  1.0f,
       0.f,  0.5f,  0.f,  1.0f,
       0.f,  0.f,  0.5f,  1.0f,
       0.f,  0.f,  0.f,   1.f,
   };
   m_renderlist_db.createAction<tinia::renderlist::SetLocalCoordSys>( "shape0_pos" )
           ->setOrientation( shape0_from_world, shape0_to_world );

   float shape1_to_world[16] = {
       1.f, 0.f, 0.f, -0.5f,
       0.f, 1.f, 0.f, -0.5f,
       0.f, 0.f, 1.f, -0.5f,
       0.f, 0.f, 0.f,  1.f,
   };
   float shape1_from_world[16] = {
       1.f,  0.f,  0.f,  0.5f,
       0.f,  1.f,  0.f,  0.5f,
       0.f,  0.f,  1.f,  0.5f,
       0.f,  0.f,  0.f,   1.f,
   };
   m_renderlist_db.createAction<tinia::renderlist::SetLocalCoordSys>( "shape1_pos" )
           ->setOrientation( shape1_from_world, shape1_to_world );

   // Set up draw order
   m_renderlist_db.drawOrderClear()
           ->drawOrderAdd( "solid_use")
           ->drawOrderAdd( "solid_wire_cube_input" )

           ->drawOrderAdd( "shape0_pos" )      // sets transform matrices
           ->drawOrderAdd( "solid_orient" )    // updates uniforms
           ->drawOrderAdd( "solid_white" )     // set color uniform
           ->drawOrderAdd( "wire_cube_draw" )  // invoke draw call

           ->drawOrderAdd( "shape1_pos" )
           ->drawOrderAdd( "solid_orient" )
           ->drawOrderAdd( "solid_green" )
           ->drawOrderAdd( "wire_cube_draw" );

   m_renderlist_db.process();
   m_model->updateElement<int>( "renderlist", m_renderlist_db.latest() );

   glewInit();
#ifndef __APPLE__
   static const GLfloat quad[ 4*4 ] = {
        1.f, -1.f, 0.f, 1.f,
        1.f,  1.f, 0.f, 1.f,
       -1.f, -1.f, 0.f, 1.f,
       -1.f,  1.f, 0.f, 1.f
   };
   glGenVertexArrays( 1, &m_gpgpu_quad_vertex_array );
   glBindVertexArray( m_gpgpu_quad_vertex_array );
   glGenBuffers( 1, &m_gpgpu_quad_buffer );
   glBindBuffer( GL_ARRAY_BUFFER, m_gpgpu_quad_buffer );
   glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW );
   glVertexPointer( 4, GL_FLOAT, 0, NULL );
   glEnableClientState( GL_VERTEX_ARRAY );
   glBindBuffer( GL_ARRAY_BUFFER, 0 );
   glBindVertexArray( 0 );
   CHECK_GL;

   glBindVertexArray( m_gpgpu_quad_vertex_array );
   glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
   glBindVertexArray( 0 );
   CHECK_GL;
#endif
   CHECK_GL;



    return true;
}
示例#2
0
BOOST_FIXTURE_TEST_CASE(ExposedModelGUITestCase, ExposedModelFixture)
{
   model::Viewer viewer;
   viewer.height = 500;
   viewer.width = 500;
   model.addElement("viewer", viewer);
   model.addElement<bool>("myTab", false);
      model.addElement<bool>("myBool", false);
   model.addElement<std::string>("myVal", "THIS WORKS!");

   const char* restrictions[] = {"select1", "select2", "select3", "select4"};
   model.addElementWithRestriction<std::string>("myVal2", "select1",
                                                       &restrictions[0], &restrictions[4]);

   model.addConstrainedElement<int>("myIntBA", 5,0, 900);
   model.addConstrainedElement<double>("myDouble", 10., 0., 11.);
   model.addElement<bool>("myButton", false);


   using namespace model::gui;
   TabLayout* root = new TabLayout();
   HorizontalLayout *superLayout = new HorizontalLayout();

   Grid *mainGrid = new Grid(10, 1);
   superLayout->addChild(mainGrid);
   Tab *mainTab = new Tab("myTab");
   mainTab->setChild(superLayout);
   root->addChild(mainTab);

   // Used to hold our two input fields.


   // Simple Label-input-layout
   Grid *input1Grid = new Grid(3,2);
   mainGrid->setChild(0,0, input1Grid);
   input1Grid->setChild(0, 0, new Label("myVal"));
   input1Grid->setChild(0, 1, new TextInput("myVal"));

   input1Grid->setChild(1,0, new Label("myVal2"));
   input1Grid->setChild(1,1, new ComboBox("myVal2"));

   input1Grid->setChild(2,0, new Label("myVal2"));
   input1Grid->setChild(2,1, new RadioButtons("myVal2"));

   mainGrid->setChild(1, 0, new SpinBox("myIntBA"));
   mainGrid->setChild(2, 0, new TextInput("myIntBA"));
   mainGrid->setChild(3, 0, new CheckBox("myTab"));
   mainGrid->setChild(4, 0, new CheckBox("myTab"));
   mainGrid->setChild(5, 0, new Button("myButton"));
   mainGrid->setChild(6, 0, new HorizontalSlider("myIntBA"));
   mainGrid->setChild(8,0, new DoubleSpinBox("myDouble"));
   mainGrid->setChild(9, 0, new CheckBox("myBool"));

   ElementGroup* elemGroup = new ElementGroup("myTab", false);

   elemGroup->setChild(new TextInput("myVal"));
   mainGrid->setChild(7, 0, elemGroup);

   Grid* canvasGrid = new Grid(2,1);
   Canvas *canvas = new Canvas("viewer");

   canvasGrid->setChild(0,0, canvas);
   VerticalLayout* verticalLayout = new VerticalLayout;
   verticalLayout->setVisibilityKey( "myBool" );

   canvasGrid->setChild(1,0, verticalLayout);
   superLayout->addChild(canvasGrid);


   model.setGUILayout(root, DESKTOP);

   std::vector<model::StateSchemaElement> elements;
   model.getFullStateSchema(elements);
   
}