1 // This example displays an image with a menu bar.
2 
3 #include <iostream>
4 #ifdef _MSC_VER
5 #  include "vcl_msvc_warnings.h"
6 #endif
7 #include "vgui/vgui.h"
8 #include "vgui/vgui_menu.h"
9 #include "vgui/vgui_image_tableau.h"
10 #include "vgui/vgui_viewer2D_tableau.h"
11 #include "vgui/vgui_shell_tableau.h"
12 
13 // Set up a dummy callback function for the menu to call (for
14 // simplicity all menu items will call this function):
15 static void
dummy()16 dummy()
17 {
18   std::cerr << "Dummy function called\n";
19 }
20 
21 // Create a vgui menu:
22 vgui_menu
create_menus()23 create_menus()
24 {
25   vgui_menu file;
26   file.add("Open", dummy, (vgui_key)'O', vgui_CTRL);
27   file.add("Quit", dummy, (vgui_key)'R', vgui_SHIFT);
28 
29   vgui_menu image;
30   image.add("Center image", dummy);
31   image.add("Show histogram", dummy);
32 
33   vgui_menu bar;
34   bar.add("File", file);
35   bar.add("Image", image);
36 
37   return bar;
38 }
39 
40 int
main(int argc,char ** argv)41 main(int argc, char ** argv)
42 {
43   vgui::init(argc, argv);
44   if (argc <= 1)
45   {
46     std::cerr << "Please give an image filename on the command line\n";
47     return 0;
48   }
49 
50   // Make our tableau hierarchy.
51   vgui_image_tableau_new image(argv[1]);
52   vgui_viewer2D_tableau_new viewer(image);
53   vgui_shell_tableau_new shell(viewer);
54 
55   // Create a window, but this time we also pass in a vgui_menu.
56   return vgui::run(shell, 512, 512, create_menus());
57 }
58