Advertisement
DragonOsman

GUI.cpp

Mar 17th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include "GUI.h"
  2. #include "std_lib_facilities.h"
  3. #include <sstream>
  4.  
  5. using namespace Graph_lib;
  6.  
  7.  
  8. void Button::attach(Window& win)
  9. {
  10.     pw = new Fl_Button(loc.x, loc.y, width, height, label.c_str());
  11.     pw->callback(reinterpret_cast<Fl_Callback*>(do_it), &win); // pass the window
  12.     own = &win;
  13. }
  14.  
  15. int In_box::get_int()
  16. {
  17.     Fl_Input& pi = reference_to<Fl_Input>(pw);
  18.     //  return atoi(pi.value());
  19.     const char* p = pi.value();
  20.     if (!isdigit(p[0])) return -999999;
  21.     return atoi(p);
  22. }
  23.  
  24. string In_box::get_string()
  25. {
  26.     Fl_Input& pi = reference_to<Fl_Input>(pw);
  27.     return string(pi.value());
  28. }
  29.  
  30. void In_box::attach(Window& win)
  31. {
  32.     pw = new Fl_Input(loc.x, loc.y, width, height, label.c_str());
  33.     own = &win;
  34. }
  35.  
  36. void Out_box::put(int i)
  37. {
  38.     Fl_Output& po = reference_to<Fl_Output>(pw);
  39.     std::stringstream ss;
  40.     ss << i;
  41.     po.value(ss.str().c_str());
  42. }
  43.  
  44. void Out_box::put(const string& s)
  45. {
  46.     reference_to<Fl_Output>(pw).value(s.c_str());
  47. }
  48.  
  49. void Out_box::attach(Window& win)
  50. {
  51.     pw = new Fl_Output(loc.x, loc.y, width, height, label.c_str());
  52.     own = &win;
  53. }
  54.  
  55. Menu::Menu(Point xy, int w, int h, Kind kk, const string& s)
  56.     :Widget(xy, w, h, s, 0), k(kk), offset(0)
  57. {
  58. }
  59.  
  60. int Menu::attach(Button& b)
  61. {
  62.     b.width = width;
  63.     b.height = height;
  64.  
  65.     switch (k) {
  66.     case horizontal:
  67.         b.loc = Point(loc.x + offset, loc.y);
  68.         offset += b.width;
  69.         break;
  70.     case vertical:
  71.         b.loc = Point(loc.x, loc.y + offset);
  72.         offset += b.height;
  73.         break;
  74.     }
  75.     selection.push_back(&b);
  76.     return int(selection.size() - 1);
  77. }
  78.  
  79. int Menu::attach(Button* p)
  80. {
  81.     //  owned.push_back(p);
  82.     return attach(*p);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement