void Game::run() { quit = false; DisplayWindowDescription desc; desc.set_title("ClanLib TileMap Example"); desc.set_size(Size(640, 480), true); desc.set_allow_resize(false); DisplayWindow window(desc); Slot slot_quit = window.sig_window_close().connect(this, &Game::on_window_close); Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Game::on_input_up); Canvas canvas(window); clan::XMLResourceDocument xml_resource_document("resources.xml"); ResourceManager resources = clan::XMLResourceManager::create(xml_resource_document); TileMap map; map.load(canvas, "tavern", resources, xml_resource_document); // Run until someone presses escape, or closes the window while (!quit) { int x = window.get_ic().get_mouse().get_x() - canvas.get_width(); int y = window.get_ic().get_mouse().get_y() - canvas.get_height(); // ** Enable these 3 lines to display the example magnified ** //Mat4f matrix = Mat4f::scale( 2.0f, 2.0f, 1.0f); //x /= 2; y /= 2; //canvas.set_modelview(matrix); map.set_scroll(x, y); canvas.clear(Colorf::black); map.draw(canvas); // Flip the display, showing on the screen what we have drawed since last call to flip() window.flip(1); // This call processes user input and other events KeepAlive::process(0); } }
DisplayWindow::DisplayWindow( const std::string &title, int width, int height, bool start_fullscreen, bool allow_resize, int flipping_buffers) { DisplayWindowDescription description; description.set_title(title); description.set_size(Size(width, height), false); description.set_fullscreen(start_fullscreen); if (start_fullscreen) { description.show_caption(false); } description.set_allow_resize(allow_resize); description.set_flipping_buffers(flipping_buffers); *this = DisplayWindow(description); }
// The start of the Application int Raycasting::start(const std::vector<std::string> &args) { //Remove the need to send physic world to every object. Instead send just the description. //Fix having two fixtures working weirdly. quit = false; int window_x_size = 640; int window_y_size = 480; // Set the window DisplayWindowDescription desc; desc.set_title("ClanLib Raycasting Example"); desc.set_size(Size(window_x_size, window_y_size), true); desc.set_allow_resize(false); DisplayWindow window(desc); // Connect the Window close event Slot slot_quit = window.sig_window_close().connect(this, &Raycasting::on_window_close); // Connect a keyboard handler to on_key_up() Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Raycasting::on_input_up); // Create the canvas Canvas canvas(window); //Setup physic world PhysicsWorldDescription phys_desc; phys_desc.set_gravity(0.0f,10.0f); phys_desc.set_sleep(true); phys_desc.set_physic_scale(100); phys_desc.set_timestep(1.0f/200.0f); PhysicsWorld phys_world(phys_desc); //Get the Physics Context PhysicsContext pc = phys_world.get_pc(); //Setup ground body BodyDescription ground_desc(phys_world); ground_desc.set_position(Vec2f((float)window_x_size/2.0f,(float)window_y_size)); ground_desc.set_type(body_static); Body ground(pc, ground_desc); //Setup ground fixture PolygonShape ground_shape(phys_world); ground_shape.set_as_box((float)window_x_size/2,20.0f); FixtureDescription fixture_desc(phys_world); fixture_desc.set_shape(ground_shape); Fixture ground_fixture(pc, ground, fixture_desc); //Setup box body BodyDescription box_desc(phys_world); box_desc.set_position(Vec2f(10.0f,10.0f)); box_desc.set_type(body_dynamic); box_desc.set_linear_velocity(Vec2f(100.0f,0.0f)); Body box(pc, box_desc); box_desc.set_position(Vec2f((float)window_x_size-50.0f,100.0f)); box_desc.set_linear_velocity(Vec2f(-80.0f,0.0f)); Body box2(pc, box_desc); //Setup box fixture PolygonShape box_shape(phys_world); box_shape.set_as_box(30.0f, 30.0f); FixtureDescription fixture_desc2(phys_world); fixture_desc2.set_shape(box_shape); fixture_desc2.set_restitution(0.6f); fixture_desc2.set_friction(0.0005f); Fixture box_fixture(pc, box, fixture_desc2); Fixture box_fixture2(pc, box2, fixture_desc2); Vec2f ground_pos = ground.get_position(); unsigned int last_time = System::get_time(); //Setup debug draw. PhysicsDebugDraw debug_draw(phys_world); debug_draw.set_flags(f_shape|f_aabb); GraphicContext gc = canvas.get_gc(); PhysicsQueryAssistant qa = phys_world.get_qa(); clan::Font font(canvas, "Tahoma", 12); // Set raycast points Pointf p1(300,500); Pointf p2(100,100); // Set query rect; Rectf rect1(400.0f, 380.0f, Sizef(50.0f,50.0f)); // Run until someone presses escape while (!quit) { unsigned int current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; canvas.clear(); //Raycast font.draw_text(canvas, 10,20, "Raycasting..."); qa.raycast_first(p1, p2); if(qa.has_query_result()) { font.draw_text(canvas, 100,20, "Found object !"); canvas.draw_line(p1,p2, Colorf::green); } else canvas.draw_line(p1, p2, Colorf::red); //Raycast //Query font.draw_text(canvas, 10,35, "Querying..."); qa.query_any(rect1); if(qa.has_query_result()) { font.draw_text(canvas, 100,35, "Found object !"); canvas.draw_box(rect1, Colorf::green); } else canvas.draw_box(rect1, Colorf::red); //Query phys_world.step(); debug_draw.draw(canvas); canvas.flush(); window.flip(1); // This call processes user input and other events KeepAlive::process(0); System::sleep(10); } return 0; }
FlexTable::FlexTable() { #if defined(WIN32) && !defined(__MINGW32__) clan::D3DTarget::set_current(); #else clan::OpenGLTarget::set_current(); #endif // Create a source for our resources FileResourceDocument doc(FileSystem("../../ThemeAero")); ResourceManager resources = FileResourceManager::create(doc); // Mark this thread as the UI thread ui_thread = UIThread(resources); // Create a window: DisplayWindowDescription desc; desc.set_title("UICore: Flex Table"); desc.set_allow_resize(true); desc.set_size(Sizef(1400, 800), false); window = std::make_shared<TopLevelWindow>(desc); // Exit run loop when close is clicked or ESC pressed. auto pRootView = window->root_view(); pRootView->slots.connect(pRootView->sig_close(), [&](CloseEvent &e) { RunLoop::exit(); }); pRootView->slots.connect(pRootView->sig_key_press(), [&](clan::KeyEvent &e) { if (e.key() == clan::Key::escape) RunLoop::exit(); } ); // Need for receive a keyboard events. pRootView->set_focus(); window->root_view()->style()->set("background-color: white;"); // Main window icons window->display_window().set_small_icon(clan::PixelBuffer("Resources/app_icon_16x16.png", doc.get_file_system())); window->display_window().set_large_icon(clan::PixelBuffer("Resources/app_icon_32x32.png", doc.get_file_system())); auto outer_view = window->root_view()->add_child<clan::View>(); outer_view->style()->set("border: 20px solid blue; padding: 15px; margin: 0px; background-color: black; width: 1000px; height: 500px;"); auto column_flex_view = outer_view->add_child<clan::View>(); column_flex_view->style()->set("border: 8px solid yellow; padding: 15px; margin: 0px; display:flex; align-items:flex-start; flex-direction:column; height:400px; background-color: #666666;"); std::string row_flex_style("border: 8px solid red; padding: 15px; margin: 0px; width:100%; box-sizing: border-box; display:flex; align-items:flex-start; background-color: #444444;"); std::string row_view_style("color: white; height:60px; border: 8px solid white; background: black;"); for (int cnt = 0; cnt < 2; cnt++) { auto row_flex_view = column_flex_view->add_child<clan::View>(); row_flex_view->style()->set(row_flex_style); auto row_view1 = row_flex_view->add_child<clan::View>(); row_view1->style()->set(row_view_style); row_view1->style()->set("flex: 0 0 400px;"); auto row_view2 = row_flex_view->add_child<clan::View>(); row_view2->style()->set(row_view_style); row_view2->style()->set("flex: 1 0 auto;"); auto row_view3 = row_flex_view->add_child<clan::View>(); row_view3->style()->set(row_view_style); row_view3->style()->set("flex: 0 0 200px;"); } // Prevent close program when hint or modal windows closes. window_manager.set_exit_on_last_close(false); // Make our window visible window->show(); }
HelloWorld::HelloWorld() { // We support all display targets, in order listed here //clan::D3DTarget::enable(); clan::OpenGLTarget::enable(); // Create a source for our resources FileResourceDocument doc(FileSystem("../../ThemeAero")); ResourceManager resources = FileResourceManager::create(doc); // Mark this thread as the UI thread ui_thread = UIThread(resources); // Create root view and window: DisplayWindowDescription desc; desc.set_title("UICore: Hello World"); desc.set_allow_resize(true); desc.set_size(Sizef(640, 600), false); root = std::make_shared<WindowView>(desc); // Exit run loop when close is clicked. // We have to store the return Slot because if it is destroyed the lambda function is disconnected from the signal. slot_close = root->sig_close().connect([&](CloseEvent &e) { RunLoop::exit(); }); // Style the root view to use rounded corners and a bit of drop shadow root->style()->set("padding: 11px"); root->style()->set("background: #efefef"); root->style()->set("flex-direction: column"); auto body = std::make_shared<View>(); body->style()->set("background: white"); body->style()->set("padding: 11px"); body->style()->set("border-top: 5px solid #DD3B2A"); body->style()->set("border-bottom: 5px solid #DD3B2A"); body->style()->set("flex-direction: column"); body->style()->set("flex: auto"); root->add_subview(body); // Create a label with some text to have some content label = std::make_shared<LabelView>(); label->style()->set("flex: none"); label->style()->set("font: 20px/40px 'Ravie'"); label->style()->set("color: #DD3B2A"); label->set_text("Hello World!"); body->add_subview(label); // React to clicking label->slots.connect(label->sig_pointer_press(), [&](PointerEvent &e) { label->set_text(label->text() + " CLICK!"); }); auto scrollarea = std::make_shared<ScrollView>(); scrollarea->style()->set("margin: 5px 0; border: 1px solid black; padding: 5px 5px;"); scrollarea->scrollbar_x_view()->thumb()->style()->set("background: #c8c8c8"); scrollarea->scrollbar_y_view()->thumb()->style()->set("background: #c8c8c8"); scrollarea->content_view()->style()->set("flex-direction: column"); body->add_subview(scrollarea); // Create a text field for our span layout std::shared_ptr<TextFieldView> edit = std::make_shared<TextFieldView>(); edit->style()->set("font: 11px/20px 'Segoe UI'"); edit->style()->set("margin: 5px"); edit->style()->set("background: #efefef"); edit->style()->set("border: 1px solid black"); edit->style()->set("border-radius: 3px"); edit->style()->set("padding: 2px 5px 2px 5px"); edit->style()->set("width: 128px"); edit->style()->set("box-shadow: 0 0 5px rgba(100,100,200,0.2)"); edit->set_text("amazing!"); // Create some text styles for the text we will write std::shared_ptr<Style> normal = std::make_shared<Style>(); std::shared_ptr<Style> bold = std::make_shared<Style>(); std::shared_ptr<Style> italic = std::make_shared<Style>(); normal->set("font: 13px/25px 'Segoe UI'"); bold->set("font: 13px/25px 'Segoe UI'; font-weight: bold"); italic->set("font: 13px/25px 'Segoe UI'; font-style: italic"); // Create a span layout views with some more complex inline formatting std::shared_ptr<SpanLayoutView> p1 = std::make_shared<SpanLayoutView>(); p1->add_text("This is an example of why Sphair should never ever make fun of my ", normal); p1->add_text("BEAUTIFUL", bold); p1->add_text(" green 13.37deg gradients because he will never know what it is replaced with!", normal); scrollarea->content_view()->add_subview(p1); std::shared_ptr<SpanLayoutView> p2 = std::make_shared<SpanLayoutView>(); p2->style()->set("margin: 15px 0 5px 0"); p2->style()->set("padding: 7px"); p2->style()->set("border-top: 5px solid #CCE4FB"); p2->style()->set("border-bottom: 5px solid #CCE4FB"); p2->style()->set("background: #EDF6FF"); p2->add_text("If you also think Sphair made a ", normal); p2->add_text("BIG MISTAKE", bold); p2->add_text(" please consider typing ", normal); p2->add_text("Yes, yes, yes, yes, yes, yes, yes yes, YES!", italic); p2->add_text(" in the text field: ", normal); p2->add_subview(edit); p2->add_text(" You know you want to!", bold); scrollarea->content_view()->add_subview(p2); std::shared_ptr<SpanLayoutView> p3 = std::make_shared<SpanLayoutView>(); p3->add_text("Since we both know you typed ", normal); p3->add_text("Yes, yes, yes..", italic); p3->add_text(" into the text field (who wouldn't!?), here's the amazing gradient:", normal); scrollarea->content_view()->add_subview(p3); std::shared_ptr<View> gradient_box = std::make_shared<View>(); gradient_box->style()->set("margin: 15px auto; width: 120px; height: 75px;"); gradient_box->style()->set("border: 1px solid #777"); gradient_box->style()->set("background: linear-gradient(13.37deg, #f0f0f0, rgb(120,240,120) 50%, #f0f0f0)"); gradient_box->style()->set("box-shadow: 7px 7px 7px rgba(0,0,0,0.2)"); scrollarea->content_view()->add_subview(gradient_box); auto scrollbar = Theme::create_scrollbar(); //scrollbar->set_disabled(); scrollbar->set_range(0.0, 1.0); scrollbar->set_position(0.5); scrollbar->set_page_step(0.1); scrollbar->set_line_step(0.01); scrollarea->content_view()->add_subview(scrollbar); auto button = Theme::create_button(); button->label()->set_text("This is a button"); scrollarea->content_view()->add_subview(button); std::shared_ptr<clan::SliderView> slider = Theme::create_slider(); //slider->set_disabled(); slider->set_min_position(0); slider->set_max_position(1000); slider->set_tick_count(100); slider->set_lock_to_ticks(false); slider->set_page_step(100); slider->set_position(slider->max_position()/2); scrollarea->content_view()->add_subview(slider); auto checkbox = Theme::create_checkbox(); //checkbox->set_disabled(); scrollarea->content_view()->add_subview(checkbox); for (int cnt = 0; cnt < 3; cnt++) { auto radio = Theme::create_radiobutton(); //radio->set_disabled(true); scrollarea->content_view()->add_subview(radio); } // Make our window visible root->show(); }
App::App() { #if defined(WIN32) && !defined(__MINGW32__) clan::D3DTarget::set_current(); #else clan::OpenGLTarget::set_current(); #endif // Create a window: DisplayWindowDescription desc; desc.set_title("UICore: Hello World"); desc.set_allow_resize(true); window = std::make_shared<TopLevelWindow>(desc); auto pRootView = window->root_view(); pRootView->slots.connect(window->root_view()->sig_close(), [&](CloseEvent &e) { RunLoop::exit(); }); pRootView->slots.connect(pRootView->sig_key_press(), [&](clan::KeyEvent &e) { if (e.key() == clan::Key::escape) RunLoop::exit(); } ); // Need for receive a keyboard events. pRootView->set_focus(); // Create a source for our resources FileResourceDocument doc(FileSystem("../../ThemeAero")); ResourceManager resources = FileResourceManager::create(doc); // Mark this thread as the UI thread ui_thread = UIThread(resources); // Style the root view to use rounded corners and a bit of drop shadow pRootView->style()->set("padding: 11px"); pRootView->style()->set("background: #efefef"); pRootView->style()->set("flex-direction: column"); // First (top) panel with button and text // auto panel1 = std::make_shared<View>(); panel1->style()->set("background: white"); panel1->style()->set("padding: 11px"); panel1->style()->set("flex-direction: row"); panel1->style()->set("flex: auto"); pRootView->add_child(panel1); auto button1 = Theme::create_button(); button1->style()->set("height: 40px"); button1->style()->set("width: 120px"); button1->label()->set_text("Folder browse"); button1->style()->set("flex: none"); button1->image_view()->set_image(clan::Image(pRootView->canvas(), "./document_open.png")); button1->func_clicked() = clan::bind_member(this, &App::on_button1_down); panel1->add_child(button1); label1 = std::make_shared<LabelView>(); label1->style()->set("font: 20px/40px 'Ravie'"); label1->style()->set("padding: 0px 10px"); label1->set_text("Press the button for select a folder"); panel1->add_child(label1); // Second panel with button and text // auto panel2 = std::make_shared<View>(); panel2->style()->set("background: white"); panel2->style()->set("padding: 11px"); panel2->style()->set("flex-direction: row"); panel2->style()->set("flex: auto"); pRootView->add_child(panel2); auto button2 = Theme::create_button(); button2->style()->set("height: 40px"); button2->style()->set("width: 120px"); button2->label()->set_text("Open file"); button2->style()->set("flex: none"); button2->func_clicked() = clan::bind_member(this, &App::on_button2_down); panel2->add_child(button2); label2 = std::make_shared<LabelView>(); label2->style()->set("font: 20px/40px 'Ravie'"); label2->style()->set("padding: 0px 10px"); label2->set_text("Press the button for select only existing file"); panel2->add_child(label2); // Third panel with button and text // auto panel3 = std::make_shared<View>(); panel3->style()->set("background: white"); panel3->style()->set("padding: 11px"); panel3->style()->set("flex-direction: row"); panel3->style()->set("flex: auto"); pRootView->add_child(panel3); auto button3 = Theme::create_button(); button3->style()->set("height: 40px"); button3->style()->set("width: 120px"); button3->label()->set_text("Save file"); button3->style()->set("flex: none"); button3->func_clicked() = clan::bind_member(this, &App::on_button3_down); panel3->add_child(button3); label3 = std::make_shared<LabelView>(); label3->style()->set("font: 20px/40px 'Ravie'"); label3->style()->set("padding: 0px 10px"); label3->set_text("Press the button for select existing or new file"); panel3->add_child(label3); // Fourth panel with button and text // auto panel4 = std::make_shared<View>(); panel4->style()->set("background: white"); panel4->style()->set("padding: 11px"); panel4->style()->set("flex-direction: row"); panel4->style()->set("flex: auto"); pRootView->add_child(panel4); button4 = Theme::create_button(); button4->style()->set("height: 40px"); button4->style()->set("width: 120px"); button4->label()->set_text("Sticky button"); button4->style()->set("flex: none"); button4->func_clicked() = clan::bind_member(this, &App::on_button4_down); button4->set_sticky(true); button4->set_pressed(true); panel4->add_child(button4); label4 = std::make_shared<LabelView>(); label4->style()->set("font: 20px/40px 'Ravie'"); label4->style()->set("padding: 0px 10px"); panel4->add_child(label4); on_button4_down(); // Manual setting button's "pressed" property doesn't call user event handler automatically. }
// The start of the Application int App::start(const std::vector<std::string> &args) { quit = false; DisplayWindowDescription desc; desc.set_title("ClanLib Quaternion's Example"); desc.set_size(Size(900, 700), true); desc.set_multisampling(4); desc.set_allow_resize(true); desc.set_depth_size(16); DisplayWindow window(desc); // Connect the Window close event Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); // Connect a keyboard handler to on_key_up() Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up); // Set up GUI std::string theme; if (FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css")) theme = "../../../Resources/GUIThemeAero"; else if (FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css")) theme = "../../../Resources/GUIThemeBasic"; else throw Exception("No themes found"); GUIWindowManagerTexture wm(window); GUIManager gui(wm, theme); Canvas canvas(window); // Deleted automatically by the GUI Options *options = new Options(gui, Rect(8, 8, Size(canvas.get_width()-16, 170))); options->request_repaint(); // Setup graphic store GraphicStore graphic_store(canvas); scene.gs = &graphic_store; RasterizerStateDescription rasterizer_state_desc; rasterizer_state_desc.set_culled(true); rasterizer_state_desc.set_face_cull_mode(cull_back); rasterizer_state_desc.set_front_face(face_clockwise); RasterizerState raster_state(canvas, rasterizer_state_desc); DepthStencilStateDescription depth_state_desc; depth_state_desc.enable_depth_write(true); depth_state_desc.enable_depth_test(true); depth_state_desc.enable_stencil_test(false); depth_state_desc.set_depth_compare_function(compare_lequal); DepthStencilState depth_write_enabled(canvas, depth_state_desc); create_scene(canvas); clan::Font font(canvas, "tahoma", 24); FramerateCounter framerate_counter; active_lerp = false; ubyte64 time_last = System::get_time(); ubyte64 time_start = time_last; // Run until someone presses escape while (!quit) { framerate_counter.frame_shown(); // Calculate time since last frame ubyte64 time_now = System::get_time(); current_time = time_now - time_start; time_delta = time_now - time_last; time_last = time_now; // Control the target options control_target(options); // Use the euler angle options rotation_euler_a->rotation_y = options->rotation_y; rotation_euler_b->rotation_x = options->rotation_x; rotation_euler_c->rotation_z = options->rotation_z; teapot_euler->rotation_x = options->rotation_x; teapot_euler->rotation_y = options->rotation_y; teapot_euler->rotation_z = options->rotation_z; // Use the target angle options rotation_target_a->rotation_y = options->target_y; rotation_target_b->rotation_x = options->target_x; rotation_target_c->rotation_z = options->target_z; teapot_target->rotation_x = options->target_x; teapot_target->rotation_y = options->target_y; teapot_target->rotation_z = options->target_z; // Render the scene using euler angles calculate_matricies(canvas); update_light(canvas, options); canvas.set_depth_stencil_state(depth_write_enabled); canvas.set_rasterizer_state(raster_state); render(canvas); // Show the quaternion teapot Mat4f modelview_matrix = scene.gs->camera_modelview; modelview_matrix.translate_self(0.0f, 0.0f, 0.0f); modelview_matrix = modelview_matrix * options->quaternion.to_matrix(); modelview_matrix.scale_self(5.0f, 5.0f, 5.0f); model_teapot.Draw(canvas, scene.gs, modelview_matrix); // Draw information boxes canvas.reset_rasterizer_state(); canvas.reset_depth_stencil_state(); std::string fps(string_format("%1 fps", framerate_counter.get_framerate())); font.draw_text(canvas, 16-2, canvas.get_height()-16-2, fps, Colorf(0.0f, 0.0f, 0.0f, 1.0f)); font.draw_text(canvas, 16, canvas.get_height()-16-2, fps, Colorf(1.0f, 1.0f, 1.0f, 1.0f)); font.draw_text(canvas, 60, 250, "Euler Orientation"); font.draw_text(canvas, 330, 250, "Quaternion Orientation"); font.draw_text(canvas, 600, 250, "Target Euler Orientation"); font.draw_text(canvas, 16, 630, "(Using YXZ rotation order)"); wm.process(); wm.draw_windows(canvas); // Use flip(1) to lock the fps window.flip(0); KeepAlive::process(); } return 0; }
HelloWorld::HelloWorld() { clan::Application::use_timeout_timing(std::numeric_limits<int>::max()); // The update() loop is not required for this application //clan::D3DTarget::set_current(); clan::OpenGLTarget::set_current(); // Create a source for our resources FileResourceDocument doc(FileSystem("../../ThemeAero")); ResourceManager resources = FileResourceManager::create(doc); // Mark this thread as the UI thread ui_thread = UIThread(resources); // Create a window: DisplayWindowDescription desc; desc.set_title("UICore: Hello World"); desc.set_allow_resize(true); desc.set_size(Sizef(640, 600), false); window = std::make_shared<TopLevelWindow>(desc); // Exit run loop when close is clicked. // We have to store the return Slot because if it is destroyed the lambda function is disconnected from the signal. slots.connect(window->root_view()->sig_close(), [&](CloseEvent &e) { RunLoop::exit(); }); // Style the root view to use rounded corners and a bit of drop shadow window->root_view()->style()->set("padding: 11px"); window->root_view()->style()->set("background: #efefef"); window->root_view()->style()->set("flex-direction: column"); auto body = std::make_shared<View>(); body->style()->set("background: white"); body->style()->set("padding: 11px"); body->style()->set("border-top: 5px solid #DD3B2A"); body->style()->set("border-bottom: 5px solid #DD3B2A"); body->style()->set("flex-direction: column"); body->style()->set("flex: auto"); window->root_view()->add_subview(body); // Create a label with some text to have some content label = std::make_shared<LabelView>(); label->style()->set("flex: none"); label->style()->set("font: 20px/40px 'Ravie'"); label->style()->set("color: #DD3B2A"); label->set_text("Hello World!"); body->add_subview(label); // React to clicking label->slots.connect(label->sig_pointer_press(), [&](PointerEvent &e) { label->set_text(label->text() + " CLICK!"); }); auto scrollarea = std::make_shared<ScrollView>(); scrollarea->style()->set("margin: 5px 0; border: 1px solid black; padding: 5px 5px;"); scrollarea->scrollbar_x_view()->style()->set("background: rgb(232,232,236); margin-top: 5px"); scrollarea->scrollbar_x_view()->track()->style()->set("padding: 0 4px"); scrollarea->scrollbar_x_view()->thumb()->style()->set("background: rgb(208,209,215)"); scrollarea->scrollbar_y_view()->style()->set("background: rgb(232,232,236); margin-left: 5px"); scrollarea->scrollbar_y_view()->track()->style()->set("padding: 0 4px"); scrollarea->scrollbar_y_view()->thumb()->style()->set("background: rgb(208,209,215)"); scrollarea->content_view()->style()->set("flex-direction: column"); body->add_subview(scrollarea); // Create a text field for our span layout std::shared_ptr<TextFieldView> edit = std::make_shared<TextFieldView>(); edit->style()->set("font: 11px/20px 'Segoe UI'"); edit->style()->set("margin: 5px"); edit->style()->set("background: #efefef"); edit->style()->set("border: 1px solid black"); edit->style()->set("border-radius: 3px"); edit->style()->set("padding: 2px 5px 2px 5px"); edit->style()->set("width: 128px"); edit->style()->set("box-shadow: 0 0 5px rgba(100,100,200,0.2)"); edit->set_text("amazing!"); // Create a span layout views with some more complex inline formatting std::shared_ptr<SpanLayoutView> p1 = std::make_shared<SpanLayoutView>(); p1->style()->set("font: 13px/25px 'Segoe UI'"); p1->text_style("bold")->set("font-weight: bold"); p1->text_style("italic")->set("font-style: italic"); p1->add_text("This is an example of why Sphair should never ever make fun of my "); p1->add_text("BEAUTIFUL", "bold"); p1->add_text(" green 13.37deg gradients because he will never know what it is replaced with!"); scrollarea->content_view()->add_subview(p1); std::shared_ptr<SpanLayoutView> p2 = std::make_shared<SpanLayoutView>(); p2->style()->set("margin: 15px 0 5px 0"); p2->style()->set("padding: 7px"); p2->style()->set("border-top: 5px solid #CCE4FB"); p2->style()->set("border-bottom: 5px solid #CCE4FB"); p2->style()->set("background: #EDF6FF"); p2->style()->set("font: 13px/25px 'Segoe UI'"); p2->text_style("bold")->set("font-weight: bold"); p2->text_style("italic")->set("font-style: italic"); p2->add_text("If you also think Sphair made a "); p2->add_text("BIG MISTAKE", "bold"); p2->add_text(" please consider typing "); p2->add_text("Yes, yes, yes, yes, yes, yes, yes yes, YES!", "italic"); p2->add_text(" in the text field: "); p2->add_subview(edit); p2->add_text(" You know you want to!", "bold"); scrollarea->content_view()->add_subview(p2); std::shared_ptr<SpanLayoutView> p3 = std::make_shared<SpanLayoutView>(); p3->style()->set("font: 13px/25px 'Segoe UI'"); p3->text_style("bold")->set("font-weight: bold"); p3->text_style("italic")->set("font-style: italic"); p3->add_text("Since we both know you typed "); p3->add_text("Yes, yes, yes..", "italic"); p3->add_text(" into the text field (who wouldn't!?), here's the amazing gradient:"); scrollarea->content_view()->add_subview(p3); std::shared_ptr<View> gradient_box = std::make_shared<View>(); gradient_box->style()->set("margin: 15px auto; width: 120px; height: 75px;"); gradient_box->style()->set("border: 1px solid #777"); gradient_box->style()->set("background: linear-gradient(13.37deg, #f0f0f0, rgb(120,240,120) 50%, #f0f0f0)"); gradient_box->style()->set("box-shadow: 7px 7px 7px rgba(0,0,0,0.2)"); scrollarea->content_view()->add_subview(gradient_box); auto listbox = std::make_shared<ListBoxView>(); listbox->style()->set("flex: none; height: 60px; margin: 7px 0; border: 1px solid black; padding: 5px; background: #f0f0f0"); listbox->set_items<std::string>( { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "More items", "Even more items!!", "No more items!!!!!" }, [](const std::string &s) -> std::shared_ptr<View> { auto item = std::make_shared<LabelView>(); item->style()->set("font: 13px/17px 'Segoe UI'; color: black; margin: 1px 0; padding: 0 2px"); item->style("selected")->set("background: #7777f0; color: white"); item->style("hot")->set("background: #ccccf0; color: black"); item->set_text(s); return item; }); scrollarea->content_view()->add_subview(listbox); auto scrollbar = Theme::create_scrollbar(); //scrollbar->set_disabled(); scrollbar->set_range(0.0, 1.0); scrollbar->set_position(0.5); scrollbar->set_page_step(0.1); scrollbar->set_line_step(0.01); scrollarea->content_view()->add_subview(scrollbar); auto button = Theme::create_button(); button->label()->set_text("This is a button"); scrollarea->content_view()->add_subview(button); std::shared_ptr<clan::SliderView> slider = Theme::create_slider(); //slider->set_disabled(); slider->set_min_position(0); slider->set_max_position(1000); slider->set_tick_count(100); slider->set_lock_to_ticks(false); slider->set_page_step(100); slider->set_position(slider->max_position()/2); scrollarea->content_view()->add_subview(slider); auto checkbox = Theme::create_checkbox(); //checkbox->set_disabled(); scrollarea->content_view()->add_subview(checkbox); for (int cnt = 0; cnt < 3; cnt++) { auto radio = Theme::create_radiobutton(); //radio->set_disabled(true); scrollarea->content_view()->add_subview(radio); } // Create a popup window slots.connect(button->sig_pointer_enter(), [=](PointerEvent &e) { auto popup = std::make_shared<WindowController>(); popup->root_view()->style()->set("flex-direction: column"); popup->root_view()->style()->set("background: #FFFFE0"); popup->root_view()->style()->set("margin: 5px"); popup->root_view()->style()->set("border: 1px solid black"); popup->root_view()->style()->set("border-radius: 2px"); popup->root_view()->style()->set("padding: 2px 5px 2px 5px"); popup->root_view()->style()->set("box-shadow: 0 0 3px rgba(0,0,0,0.2)"); auto text = Theme::create_label(true); text->style()->set("font: 12px Tahoma; color: black"); text->set_text("This is an awesome popup"); popup->root_view()->add_subview(text); std::weak_ptr<WindowController> popup_weak = popup; popup->slots.connect(button->sig_pointer_leave(), [=](PointerEvent &e) { auto p = popup_weak.lock(); if (p) p->dismiss(); }); window_manager.present_popup(button.get(), e.pos(button) + Pointf(10.0f, -10.0f), popup); }); // Show a modal dialog button->func_clicked() = [=]() { auto dialog = std::make_shared<WindowController>(); dialog->set_title("Alarm!!"); dialog->root_view()->style()->set("flex-direction: column"); dialog->root_view()->style()->set("background: rgb(240,240,240)"); dialog->root_view()->style()->set("padding: 11px"); dialog->root_view()->style()->set("width: 250px"); auto text = Theme::create_label(true); text->style()->set("margin-bottom: 7px"); text->style()->set("font: 12px Tahoma; color: black"); text->set_text("This a modal dialog"); dialog->root_view()->add_subview(text); auto ok_button = Theme::create_button(); ok_button->label()->set_text("OK"); dialog->root_view()->add_subview(ok_button); std::weak_ptr<WindowController> dialog_weak = dialog; ok_button->func_clicked() = [=]() { auto d = dialog_weak.lock(); if (d) d->dismiss(); }; window_manager.present_modal(window->root_view().get(), dialog); }; // Make our window visible window->show(); }
// The start of the Application int HelloWorld::start(const std::vector<std::string> &args) { // Create a source for our resources ResourceManager resources; DisplayCache::set(resources, std::make_shared<DisplayResources>()); // Mark this thread as the UI thread UIThread ui_thread(resources); // Create root view and window: DisplayWindowDescription desc; desc.set_title("UICore: Hello World"); desc.set_allow_resize(true); desc.set_type(WindowType::custom); desc.set_extend_frame(16, 40, 16, 16); std::shared_ptr<WindowView> root = std::make_shared<WindowView>(desc); // Exit run loop when close is clicked. // We have to store the return Slot because if it is destroyed the lambda function is disconnected from the signal. Slot slot_close = root->sig_close().connect([&](CloseEvent &e) { exit(); }); Canvas canvas = UIThread::get_resource_canvas(); // Style the root view to use rounded corners and a bit of drop shadow root->box_style.set_background(Colorf(240, 240, 240, 255)); root->box_style.set_padding(11.0f); root->box_style.set_border_radius(15.0f); root->box_style.set_border(Colorf(0, 0, 0), 1.0f); root->box_style.set_margin(10.0f, 35.0f, 10.0f, 10.0f); root->box_style.set_box_shadow(Colorf(0, 0, 0, 50), 0.0f, 0.0f, 20.0f); // Create a label with some text to have some content std::shared_ptr<LabelView> label = std::make_shared<LabelView>(); label->text_style().set_font("Ravie", 20.0f, 40.0f); label->set_text("Hello World!"); root->add_subview(label); // React to clicking label->slots.connect(label->sig_pointer_press(), [&](PointerEvent &e) { label->set_text(label->text() + " CLICK!"); }); // Create a text field for our span layout std::shared_ptr<TextFieldView> edit = std::make_shared<TextFieldView>(); edit->text_style().set_font("Ravie", 11.0f, 20.0f); edit->set_text("42"); edit->box_style.set_margin(0.0f, 5.0f); edit->box_style.set_background(Colorf(255, 255, 255)); edit->box_style.set_border(Colorf(0.0f, 0.0f, 0.0f), 1.0f); edit->box_style.set_border_radius(3.0f); edit->box_style.set_padding(5.0f, 2.0f, 5.0f, 3.0f); edit->box_style.set_width(35.0f); // Create a span layout view with some more complex inline formatting std::shared_ptr<SpanLayoutView> span = std::make_shared<SpanLayoutView>(); TextStyle font_desc2; font_desc2.set_font_family("Segoe UI"); font_desc2.set_size(13.0f); font_desc2.set_line_height(40.0f); span->add_text("This is the UI core ", font_desc2); TextStyle font_desc3; font_desc3.set_font_family("Segoe UI"); font_desc3.set_size(18.0f); font_desc3.set_line_height(40.0f); span->add_text("Hello World!", font_desc3); TextStyle font_desc4; font_desc4.set_font_family("Segoe UI"); font_desc4.set_size(13.0f); font_desc4.set_line_height(40.0f); span->add_text(" example! Here's a text field: ", font_desc4); span->add_subview(edit); TextStyle font_desc5; font_desc5.set_font_family("Segoe UI"); font_desc5.set_size(16.0f); font_desc5.set_line_height(40.0f); font_desc5.set_weight(800); span->add_text(" units! sdfjghsdkfj hkjsdfhg jksdhfj gkshdfk gsjdkfghsjkdfh kgjshdfkg sjkdfh gjskhf gskjdfg hkjsdfh kgjsdhfkgjhsdkjfhgksjdfhg kjsdfhgjkshdfkhgskjdf ghkjsdfsg kdfhg skjdfhgjksdh fgsdfhg kjsdhfjkghsdkjfh gkjsdhfjkgsdhfkgjhsdkfj hgksj.", font_desc5); root->add_subview(span); // Create a popup window placed where the edit field is at std::shared_ptr<PopupView> popup = std::make_shared<PopupView>(); popup->box_style.set_background(Colorf::lightyellow); popup->box_style.set_margin(5.0f); popup->box_style.set_box_shadow(Colorf(0, 0, 0, 40), 2.0f, 2.0f, 3.0f); popup->box_style.set_border_radius(2.0f); popup->box_style.set_border(Colorf::black, 1.0f); popup->box_style.set_padding(5.0f, 2.0f); popup->box_style.set_absolute(); popup->box_style.set_bottom(28.0f); popup->box_style.set_left(0.0f); popup->box_style.set_layout_vbox(); edit->add_subview(popup); // Write some text in the popup std::shared_ptr<LabelView> popup_label = std::make_shared<LabelView>(); popup_label->text_style().set_font("Consolas", 12.0f, 14.0f); popup_label->set_text("Hey, this popup looks like a tooltip!"); popup->add_subview(popup_label); // Make our window visible root->show(); popup->show(WindowShowType::show_no_activate); // Process messages until user exits run(); return 0; }
HelloWorld::HelloWorld() { #if defined(WIN32) && !defined(__MINGW32__) clan::D3DTarget::set_current(); #else clan::OpenGLTarget::set_current(); #endif // Create a source for our resources FileResourceDocument doc(FileSystem("../../ThemeAero")); ResourceManager resources = FileResourceManager::create(doc); // Mark this thread as the UI thread ui_thread = UIThread(resources); // Create a window: DisplayWindowDescription desc; desc.set_title("UICore: Hello World"); desc.set_allow_resize(true); desc.set_size(Sizef(640, 600), false); window = std::make_shared<TopLevelWindow>(desc); // Exit run loop when close is clicked or ESC pressed. auto pRootView = window->root_view(); pRootView->slots.connect(pRootView->sig_close(), [&](CloseEvent &e) { RunLoop::exit(); }); pRootView->slots.connect(pRootView->sig_key_press(), [&](clan::KeyEvent &e) { if (e.key() == clan::Key::escape) RunLoop::exit(); } ); // Need for receive a keyboard events. pRootView->set_focus(); // Style the root view to use rounded corners and a bit of drop shadow window->root_view()->style()->set("padding: 11px"); window->root_view()->style()->set("background: #efefef"); window->root_view()->style()->set("flex-direction: column"); // Main window icons window->display_window().set_small_icon(clan::PixelBuffer("Resources/app_icon_16x16.png", doc.get_file_system())); window->display_window().set_large_icon(clan::PixelBuffer("Resources/app_icon_32x32.png", doc.get_file_system())); auto body = std::make_shared<View>(); body->style()->set("background: white"); body->style()->set("padding: 11px"); body->style()->set("border-top: 5px solid #DD3B2A"); body->style()->set("border-bottom: 5px solid #DD3B2A"); body->style()->set("flex-direction: column"); body->style()->set("flex: auto"); window->root_view()->add_child(body); // Create a label with some text to have some content label = std::make_shared<LabelView>(); label->style()->set("flex: none"); label->style()->set("font: 20px/40px 'Ravie'"); label->style()->set("color: #DD3B2A"); label->set_text("Hello World!"); body->add_child(label); // React to clicking label->slots.connect(label->sig_pointer_press(), [&](PointerEvent &e) { label->set_text(label->text() + " CLICK!"); }); auto scrollarea = std::make_shared<ScrollView>(); scrollarea->style()->set("margin: 5px 0; border: 1px solid black; padding: 5px 0px 5px 5px;"); scrollarea->content_view()->style()->set("flex-direction: column; background: white;"); Theme::initialize_scrollbar(scrollarea->scrollbar_y_view(), false); scrollarea->scrollbar_y_view()->style()->set("padding: 0 0 0 3px; background: white;"); body->add_child(scrollarea); // Create a text field for our span layout std::shared_ptr<TextFieldView> edit = std::make_shared<TextFieldView>(); edit->style()->set("font: 11px/20px 'Segoe UI'"); edit->style()->set("margin: 5px"); edit->style()->set("background: #efefef"); edit->style()->set("border: 1px solid black"); edit->style()->set("border-radius: 3px"); edit->style()->set("padding: 2px 5px 2px 5px"); edit->style()->set("width: 128px"); edit->style()->set("box-shadow: 0 0 5px rgba(100,100,200,0.2)"); edit->set_text("amazing!"); // Create a span layout views with some more complex inline formatting std::shared_ptr<SpanLayoutView> p1 = std::make_shared<SpanLayoutView>(); p1->style()->set("font: 13px/25px 'Segoe UI'"); p1->text_style("bold")->set("font-weight: bold"); p1->text_style("italic")->set("font-style: italic"); p1->add_text("This is an example of why Sphair should never ever make fun of my "); p1->add_text("BEAUTIFUL", "bold"); p1->add_text(" green 13.37deg gradients because he will never know what it is replaced with!"); scrollarea->content_view()->add_child(p1); std::shared_ptr<SpanLayoutView> p2 = std::make_shared<SpanLayoutView>(); p2->style()->set("margin: 15px 0 5px 0"); p2->style()->set("padding: 7px"); p2->style()->set("border-top: 5px solid #CCE4FB"); p2->style()->set("border-bottom: 5px solid #CCE4FB"); p2->style()->set("background: #EDF6FF"); p2->style()->set("font: 13px/25px 'Segoe UI'"); p2->text_style("bold")->set("font-weight: bold"); p2->text_style("italic")->set("font-style: italic"); p2->add_text("If you also think Sphair made a "); p2->add_text("BIG MISTAKE", "bold"); p2->add_text(" please consider typing "); p2->add_text("Yes, yes, yes, yes, yes, yes, yes yes, YES!", "italic"); p2->add_text(" in the text field: "); p2->add_child(edit); p2->add_text(" You know you want to!", "bold"); scrollarea->content_view()->add_child(p2); std::shared_ptr<SpanLayoutView> p3 = std::make_shared<SpanLayoutView>(); p3->style()->set("font: 13px/25px 'Segoe UI'"); p3->text_style("bold")->set("font-weight: bold"); p3->text_style("italic")->set("font-style: italic"); p3->add_text("Since we both know you typed "); p3->add_text("Yes, yes, yes..", "italic"); p3->add_text(" into the text field (who wouldn't!?), here's the amazing gradient:"); scrollarea->content_view()->add_child(p3); std::shared_ptr<View> gradient_box = std::make_shared<View>(); gradient_box->style()->set("margin: 15px auto; width: 120px; height: 75px;"); gradient_box->style()->set("border: 1px solid #777"); gradient_box->style()->set("background: linear-gradient(13.37deg, #f0f0f0, rgb(120,240,120) 50%, #f0f0f0)"); gradient_box->style()->set("box-shadow: 7px 7px 7px rgba(0,0,0,0.2)"); scrollarea->content_view()->add_child(gradient_box); auto listbox = Theme::create_listbox(); listbox->style()->set("flex: none; height: 60px; margin: 7px 0; border: 1px solid black; padding: 5px; background: #f0f0f0"); listbox->set_items<std::string>( { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "More items", "Even more items!!", "No more items!!!!!" }, [](const std::string &s) -> std::shared_ptr<View> { auto item = Theme::create_listbox_label(s); return item; }); scrollarea->content_view()->add_child(listbox); auto scrollbar = Theme::create_scrollbar(); //scrollbar->set_disabled(); scrollbar->set_range(0.0, 1.0); scrollbar->set_position(0.5); scrollbar->set_page_step(0.1); scrollbar->set_line_step(0.01); scrollarea->content_view()->add_child(scrollbar); auto button = Theme::create_button(); button->label()->set_text("This is a button"); scrollarea->content_view()->add_child(button); std::shared_ptr<clan::SliderView> slider = Theme::create_slider(); //slider->set_disabled(); slider->set_min_position(0); slider->set_max_position(1000); slider->set_tick_count(100); slider->set_lock_to_ticks(false); slider->set_page_step(100); slider->set_position(slider->max_position()/2); scrollarea->content_view()->add_child(slider); auto checkbox = Theme::create_checkbox(); //checkbox->set_disabled(); checkbox->style()->set("margin: 12px"); checkbox->label()->set_text("Checkbox"); scrollarea->content_view()->add_child(checkbox); // Hint - parent of the radiobutton must have an opaque background due to sub-pixel rendering effect. for (int cnt = 0; cnt < 3; cnt++) { auto radio = Theme::create_radiobutton(); //radio->set_disabled(true); scrollarea->content_view()->add_child(radio); } // Create a popup window pRootView->slots.connect(button->sig_pointer_enter(), [=](PointerEvent &e) { auto popup = std::make_shared<WindowController>(); popup->root_view()->style()->set("flex-direction: column"); popup->root_view()->style()->set("background: #FFFFE0"); popup->root_view()->style()->set("margin: 5px"); popup->root_view()->style()->set("border: 1px solid black"); popup->root_view()->style()->set("border-radius: 2px"); popup->root_view()->style()->set("padding: 2px 5px 2px 5px"); popup->root_view()->style()->set("box-shadow: 0 0 3px rgba(0,0,0,0.2)"); auto text = Theme::create_label(true); text->style()->set("font: 12px Tahoma; color: black"); text->set_text("This is an awesome popup"); popup->root_view()->add_child(text); std::weak_ptr<WindowController> popup_weak = popup; popup->slots.connect(button->sig_pointer_leave(), [=](PointerEvent &e) { auto p = popup_weak.lock(); if (p) p->dismiss(); }); window_manager.present_popup(button.get(), e.pos(button) + Pointf(10.0f, -10.0f), popup); }); // Show a modal dialog button->func_clicked() = [=]() { auto dialog = std::make_shared<WindowController>(); dialog->set_title("Alarm!!"); dialog->root_view()->style()->set("flex-direction: column"); dialog->root_view()->style()->set("background: rgb(240,240,240)"); dialog->root_view()->style()->set("padding: 11px"); dialog->root_view()->style()->set("width: 250px"); auto text = Theme::create_label(true); text->style()->set("margin-bottom: 7px"); text->style()->set("font: 12px Tahoma; color: black"); text->set_text("This a modal dialog"); dialog->root_view()->add_child(text); auto ok_button = Theme::create_button(); ok_button->label()->set_text("OK"); dialog->root_view()->add_child(ok_button); std::weak_ptr<WindowController> dialog_weak = dialog; ok_button->func_clicked() = [=]() { auto d = dialog_weak.lock(); if (d) d->dismiss(); }; window_manager.present_modal(window->root_view().get(), dialog); }; // Prevent close program when hint or modal windows closes. window_manager.set_exit_on_last_close(false); // Make our window visible window->show(); }
// The start of the Application int Collision::start(const std::vector<std::string> &args) { //Remove the need to send physic world to every object. Instead send just the description. //Fix having two fixtures working weirdly. quit = false; // Set the window DisplayWindowDescription desc; desc.set_title("ClanLib Collision Example"); desc.set_size(Size(window_x_size, window_y_size), true); desc.set_allow_resize(false); DisplayWindow window(desc); // Connect the Window close event window.sig_window_close().connect(this, &Collision::on_window_close); // Connect a keyboard handler to on_key_up() window.get_ic().get_keyboard().sig_key_up().connect(this, &Collision::on_input_up); // Create the canvas Canvas canvas(window); //Setup physic world PhysicsWorldDescription phys_desc; phys_desc.set_gravity(0.0f,10.0f); phys_desc.set_sleep(true); phys_desc.set_physic_scale(100); phys_desc.set_timestep(1.0f/60.0f); phys_desc.set_velocity_iterations(8); phys_desc.set_position_iterations(3); PhysicsWorld phys_world(phys_desc); //Setup ground body Body ground = create_ground_body(phys_world); unsigned int last_time = System::get_time(); //Setup outline body Body outline_body = create_outline_body(phys_world); outline_body.set_position(Vec2f(200.0f,200.0f)); //Setup debug draw. PhysicsDebugDraw debug_draw(phys_world); debug_draw.set_flags(f_shape); GraphicContext gc = canvas.get_gc(); // Run until someone presses escape while (!quit) { unsigned int current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; canvas.clear(); phys_world.step(); debug_draw.draw(canvas); canvas.flush(); window.flip(1); // This call processes user input and other events KeepAlive::process(0); System::sleep(10); } return 0; }
// The start of the Application int Joints::start(const std::vector<std::string> &args) { //Remove the need to send physic world to every object. Instead send just the description. //Fix having two fixtures working weirdly. quit = false; // Set the window DisplayWindowDescription desc; desc.set_title("ClanLib Joints Example"); desc.set_size(Size(window_x_size, window_y_size), true); desc.set_allow_resize(false); DisplayWindow window(desc); // Connect the Window close event Slot slot_quit = window.sig_window_close().connect(this, &Joints::on_window_close); // Connect a keyboard handler to on_key_up() Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Joints::on_input_up); // Create the canvas Canvas canvas(window); //Setup physic world PhysicsWorldDescription phys_desc; phys_desc.set_gravity(0.0f,10.0f); phys_desc.set_sleep(true); phys_desc.set_physic_scale(100); PhysicsWorld phys_world(phys_desc); //Setup ground body Body ground = create_ground_body(phys_world); unsigned int last_time = System::get_time(); //Setup debug draw. PhysicsDebugDraw debug_draw(phys_world); debug_draw.set_flags(f_shape|f_aabb|f_joint); GraphicContext gc = canvas.get_gc(); //Setup joints const int number_of_joints = 3; std::vector<Body> bodies_A(number_of_joints); std::vector<Body> bodies_B(number_of_joints); std::vector<std::shared_ptr<Joint>> Joints(number_of_joints); for(int i=0; i<number_of_joints; i++) { bodies_A[i] = create_box_body(phys_world); bodies_A[i].set_position(Vec2f(80.0f+80.0f*i,280.0f)); bodies_B[i] = create_box_body(phys_world); bodies_B[i].set_position(Vec2f(80.0f+80.0f*i,440.0f)); Joints[i] = create_joint(phys_world, bodies_A[i], bodies_B[i], i); } // Run until someone presses escape while (!quit) { unsigned int current_time = System::get_time(); float time_delta_ms = static_cast<float> (current_time - last_time); last_time = current_time; canvas.clear(); phys_world.step(); debug_draw.draw(canvas); canvas.flush(); window.flip(1); // This call processes user input and other events KeepAlive::process(0); System::sleep(10); } return 0; }