Posted by mrmuscolo on Mon 8th Feb 20:37
download | new post | report as spam

  1. #include <fltk/Button.h>
  2. #include <fltk/Divider.h>
  3. #include <fltk/Item.h>
  4. #include <fltk/ItemGroup.h>
  5. #include <fltk/MenuBar.h>
  6. #include <fltk/TabGroup.h>
  7. #include <fltk/Widget.h>
  8. #include <fltk/Window.h>
  9. #include <fltk/events.h>
  10. #include <fltk/run.h>
  11.  
  12. #include <stdlib.h>
  13.  
  14.  
  15. using namespace fltk;
  16.  
  17.  
  18. static bool menuBarState = true;
  19. static bool fullscrState = false;
  20. static int windowX      = 0;
  21. static int windowY      = 0;
  22. static int windowW      = 800;
  23. static int windowH      = 500;
  24.  
  25. void buildMenuBar(void *window);
  26. void cbMenuBarToggle(Widget *, void *menu);
  27. void cbFullscr(Widget *, void *windowMain);
  28. void cbQuit(Widget *, void *);
  29.  
  30.  
  31. int main(int argc, char **argv)
  32. {
  33.         Window *windowMain      = new Window(windowW, windowH);
  34.  
  35.         windowMain->begin();
  36.                 buildMenuBar(windowMain);
  37.  
  38.                 TabGroup *tabs  = new TabGroup(0, 26, windowMain->w(), (windowMain->h() - 26));
  39.  
  40.                 tabs->begin();
  41.                         tabs->textsize(18);
  42.  
  43.                         Group *tab1     = new Group(0, 29, tabs->w(), ((tabs->h()) - 30), "Tab 1               ");
  44.  
  45.                         tab1->begin();
  46.                                 tab1->textsize(18);
  47.                         tab1->end();
  48.  
  49.                         Group *tab2     = new Group(0, 29, tabs->w(), ((tabs->h()) - 30), "Tab 2               ");
  50.  
  51.                         tab2->begin();
  52.                                 tab2->textsize(18);
  53.                         tab2->end();
  54.                 tabs->end();
  55.         windowMain->resizable(tabs);
  56.         windowMain->size_range(700, 400, 0, 0);
  57.         windowMain->callback(cbQuit);
  58.         windowMain->end();
  59.         windowMain->show(argc, argv);
  60.  
  61.         return run();
  62. }
  63.  
  64. void buildMenuBar(void *window)
  65. {
  66.         Window *windowMain = (Window *) window;
  67.  
  68.         MenuBar *menuBar        = new MenuBar(0, 0, windowMain->w(), 26);
  69.  
  70.         menuBar->begin();
  71.                 menuBar->box(UP_BOX);
  72.  
  73.                 ItemGroup *file = new ItemGroup("&File");
  74.  
  75.                 file->begin();
  76.                         file->textsize(18);
  77.                         file->add("New &Window     ", CTRL|'n', 0, 0, 0)->textsize(18);
  78.                         file->add("New &Tab        ", CTRL|'t', 0, 0, 0)->textsize(18);
  79.                         file->add("&Open           ", CTRL|'o', 0, 0, 0)->textsize(18);
  80.                         file->add("Close &Window   ", CTRL|SHIFT|'w', 0, 0, 0)->textsize(18);
  81.                         file->add("Close &Tab      ", CTRL|'t', 0, 0, 0)->textsize(18);
  82.  
  83.                         new Divider();
  84.  
  85.                         file->add("&Save           ", CTRL|'s', 0, 0, 0)->textsize(18);
  86.                         file->add("Save &As...     ", CTRL|SHIFT|'s', 0, 0, 0)->textsize(18);
  87.  
  88.                         new Divider();
  89.  
  90.                         file->add("Print Pre&view  ", CTRL|SHIFT|'p', 0, 0, 0)->textsize(18);
  91.                         file->add("&Print          ", CTRL|'p', 0, 0, 0)->textsize(18);
  92.  
  93.                         new Divider();
  94.  
  95.                         file->add("&Quit           ", CTRL|'q', cbQuit, 0, 0)->textsize(18);
  96.  
  97.                 file->end();
  98.  
  99.                 ItemGroup *edit = new ItemGroup("&Edit");
  100.  
  101.                 edit->begin();
  102.                         edit->textsize(18);
  103.                         edit->add("&Undo           ", CTRL|'z', 0, 0, 0)->textsize(18);
  104.                         edit->add("&Redo           ", CTRL|'y', 0, 0, 0)->textsize(18);
  105.  
  106.                         new Divider();
  107.  
  108.                         edit->add("Cu&t            ", CTRL|'x', 0, 0, 0)->textsize(18);
  109.                         edit->add("&Copy           ", CTRL|'c', 0, 0, 0)->textsize(18);
  110.                         edit->add("&Paste          ", CTRL|'v', 0, 0, 0)->textsize(18);
  111.                         edit->add("&Delete         ", DeleteKey, 0, 0, 0)->textsize(18);
  112.  
  113.                         new Divider();
  114.  
  115.                         edit->add("&Find           ", CTRL|'f', 0, 0, 0)->textsize(18);
  116.                         edit->add("Find A&gain     ", CTRL|'g', 0, 0, 0)->textsize(18);
  117.  
  118.                         new Divider();
  119.  
  120.                         edit->add("Prefere&nces    ", 0, 0, 0, 0)->textsize(18);
  121.                 edit->end();
  122.  
  123.                 ItemGroup *view = new ItemGroup("&View");
  124.  
  125.                 view->begin();
  126.                         view->textsize(18);
  127.  
  128.                         ItemGroup *toolbars     = new ItemGroup("&Toolbars            ");
  129.  
  130.                         toolbars->begin();
  131.                         toolbars->textsize(18);
  132.  
  133.                         Item *menu      = new Item("&Menu Bar       ");
  134.  
  135.                                 menu->type(Item::TOGGLE);
  136.                                 menu->shortcut(F10Key);
  137.                                 menu->callback(cbMenuBarToggle, menuBar);
  138.                                 menu->textsize(18);
  139.  
  140.                         Item *tools     = new Item("&Tools Bar      ");
  141.  
  142.                                 tools->type(Item::TOGGLE);
  143.                                 tools->textsize(18);
  144.  
  145.                         Item *status    = new Item("&Status Bar     ");
  146.  
  147.                                 status->type(Item::TOGGLE);
  148.                                 status->textsize(18);
  149.  
  150.                         toolbars->end();
  151.  
  152.                         new Divider();
  153.  
  154.                         ItemGroup *zoom = new ItemGroup("&Zoom                ");
  155.  
  156.                         zoom->begin();
  157.                                 zoom->textsize(18);
  158.                                 zoom->add("Zoom &In        ", CTRL|'+', 0, 0, 0)->textsize(18);
  159.                                 zoom->add("Zoom &Out       ", CTRL|'-', 0, 0, 0)->textsize(18);
  160.                                 zoom->add("&Reset          ", CTRL|'0', 0, 0, 0)->textsize(18);
  161.  
  162.                                 new Divider();
  163.  
  164.                                 Item *zoomText  = new Item("Zoom &Text Only ");
  165.  
  166.                                 zoomText->type(Item::TOGGLE);
  167.                                 zoomText->textsize(18);
  168.                         zoom->end();
  169.  
  170.                         Item *fullscreen        = new Item("&Fullscreen     ");
  171.  
  172.                         fullscreen->type(Item::TOGGLE);
  173.                         fullscreen->shortcut(F11Key);
  174.                         fullscreen->callback(cbFullscr, windowMain);
  175.                         fullscreen->textsize(18);
  176.                 view->end();
  177.  
  178.                 ItemGroup *help = new ItemGroup("&Help");
  179.  
  180.                 help->begin();
  181.                         help->textsize(18);
  182.                         help->add("&Help Contents  ", F1Key, 0, 0, 0)->textsize(18);
  183.  
  184.                         new Divider();
  185.  
  186.                         help->add("&Updates Check  ", 0, 0, 0)->textsize(18);
  187.  
  188.                         new Divider();
  189.  
  190.                         help->add("&About          ", 0, 0, 0)->textsize(18);
  191.                 help->end();
  192.         menuBar->end();
  193. }
  194.  
  195. void cbMenuBarToggle(Widget *, void *menu)
  196. {
  197.         MenuBar *menuBar = (MenuBar *) menu;
  198.  
  199.         if(menuBar) {
  200.                 menuBar->hide();
  201.  
  202.                 menuBarState = false;
  203.         } else {
  204.                 menuBar->show();
  205.  
  206.                 menuBarState = true;
  207.         }
  208. }
  209.  
  210. void cbFullscr(Widget *, void *window)
  211. {
  212.         Window *windowMain = (Window *) window;
  213.  
  214.  
  215.         if(fullscrState) {
  216.                 windowMain->fullscreen_off(windowX, windowY, windowW, windowH);
  217.                 windowMain->hide();
  218.                 windowMain->border(true);
  219.                 windowMain->show();
  220.  
  221.                 fullscrState = false;
  222.         } else {
  223.                 windowX = windowMain->x();
  224.                 windowY = windowMain->y();
  225.                 windowW = windowMain->w();
  226.                 windowH = windowMain->h();
  227.  
  228.                 windowMain->fullscreen();
  229.  
  230.                 fullscrState = true;
  231.         }
  232. }
  233.  
  234. void cbQuit(Widget *, void *)
  235. {
  236.         if(event_key_state(EscapeKey)) {
  237.                 return;
  238.         }
  239.  
  240.         exit(0);
  241. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily
.
Syntax highlighting:

To highlight particular lines, prefix each line with @@
   Remember me