Targets
- Add button
- Print some texts when click Button
Modules
Add UI panel
const int UI_WIDTH = 180;
// Add named OpenGL viewport to window and provide 3D Handler
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -float(w) / float(h))
.SetHandler(new pangolin::Handler3D(s_cam));
// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
pangolin::CreatePanel("ui") .SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
Add button
pangolin::CreatePanel("ui").SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));
pangolin::Var<bool> a_button("ui.Button", false, false);
if (pangolin::Pushed(a_button))
std::cout << "You Pushed a button!" << std::endl;
Result:
Clic the button:
You Pushed a button!
Add callback function to deal with keyboard event and mouse click event
pangolin::Var<std::function<void(void)>> reset("ui.Reset", SampleMethod);
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);
void SampleMethod()
{
std::cout << "You typed ctrl-r or pushed reset" << std::endl;
}
Result:
Click "Reset" or press "C-r" to reset sth.
Save window and cube
pangolin::Var<bool> save_window("ui.Save_Window", false, false);
pangolin::Var<bool> save_cube("ui.Save_Cube", false, false);
if (pangolin::Pushed(save_window))
{
std::cout<<"Save window"<<std::endl; pangolin::savewindowonrender("window");}="" if="" (pangolin::pushed(save_cube))="" {="" std::cout<<"save="" cube"<<std::endl;="" d_cam.saveonrender("cube");="" }="" ```="" ##="" record="" cube="" ```cpp="" pangolin::var<bool=""> record_cube("ui.Record_Cube",false,false);
if (pangolin::Pushed(record_cube))
pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");