tattersail

Window.cpp

Apr 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include "Window.h"
  2. #include "Graph.h"
  3. #include "GUI.h"
  4.  
  5. namespace Graph_lib {
  6.  
  7. Window::Window(int ww, int hh, const string& title)
  8. :Fl_Window(ww, hh, title.c_str()), w(ww), h(hh)
  9. {
  10. init();
  11. }
  12.  
  13. Window::Window(Point xy, int ww, int hh, const string& title)
  14. : Fl_Window(xy.x, xy.y, ww, hh, title.c_str()), w(ww), h(hh)
  15. {
  16. init();
  17. }
  18.  
  19. void Window::init()
  20. {
  21. resizable(this);
  22. show();
  23. }
  24.  
  25. //----------------------------------------------------
  26.  
  27. void Window::draw()
  28. {
  29. Fl_Window::draw();
  30. for (unsigned int i = 0; i<shapes.size(); ++i) shapes[i]->draw();
  31. }
  32.  
  33. void Window::attach(Widget& w)
  34. {
  35. begin(); // FTLK: begin attaching new Fl_Wigets to this window
  36. w.attach(*this); // let the Widget create its Fl_Wigits
  37. end(); // FTLK: stop attaching new Fl_Wigets to this window
  38. }
  39.  
  40. void Window::detach(Widget& b)
  41. {
  42. b.hide();
  43. }
  44.  
  45. void Window::attach(Shape& s)
  46. {
  47. shapes.push_back(&s);
  48. // s.attached = this;
  49. }
  50. void Window::detach(Shape& s)
  51. {
  52. for (unsigned int i = shapes.size(); 0<i; --i) // guess last attached will be first released
  53. if (shapes[i - 1] == &s)
  54. shapes.erase(shapes.begin() + (i - 1));//&shapes[i-1]);
  55. }
  56.  
  57.  
  58. void Window::put_on_top(Shape& p) {
  59. for (int i = 0; i<shapes.size(); ++i) {
  60. if (&p == shapes[i]) {
  61. for (++i; i<shapes.size(); ++i)
  62. shapes[i - 1] = shapes[i];
  63. shapes[shapes.size() - 1] = &p;
  64. return;
  65. }
  66. }
  67. }
  68.  
  69. int gui_main() { return Fl::run(); }
  70.  
  71. } // Graph
Add Comment
Please, Sign In to add comment