Advertisement
Guest User

Untitled

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.40 KB | None | 0 0
  1. //Bartosz Pokorski
  2. //281814
  3.  
  4. #include <graph.h>
  5. #include <GUI.h>
  6. #include <string>
  7. #include <iostream>
  8. #include <sstream>
  9. #include <fstream>
  10. #include <vector>
  11. using namespace Graph_lib;
  12.  
  13. void cb_close (Address addr1, Address pWnd);
  14. class myWindow;
  15. struct myButton : Button
  16. {
  17. myWindow* pMyWindow;
  18. myButton(Point xy, int w, int h, const string& label, Callback cb, myWindow* pMyWin) : Button(xy, w,h, label, cb),
  19. pMyWindow(pMyWin)
  20. {}
  21.  
  22.  
  23. void attach(Graph_lib::Window& wnd)
  24. {
  25. Button::attach(wnd);
  26. pw -> callback(reinterpret_cast<Fl_Callback*>(do_it),pMyWindow);
  27.  
  28. }
  29. Address getWigdetAddress() const { return pw; }
  30. };
  31.  
  32.  
  33.  
  34. //class Spinner
  35. //{
  36. //private:
  37. //
  38. // myButton btn_down;
  39. // myButton btn_left;
  40. // myButton btn_right;
  41. // myButton btn_up;
  42. //
  43. // Graph_lib::Out_box positionBox;
  44. // Point position;
  45. // static const int crs_size = 5;
  46. //
  47. // Lines crosshair;
  48. // Graph_lib::Window *pWnd = nullptr;
  49. //
  50. //
  51. // static void cb_down (Address pWidget, Address pSpin)
  52. // {
  53. // ((Spinner*)pSpin)->changePositionY(crs_size);
  54. // }
  55. //
  56. //
  57. //
  58. // static void cb_right (Address pWidget, Address pSpin)
  59. // {
  60. // ((Spinner*)pSpin)->changePositionX(crs_size);
  61. // }
  62. //
  63. // static void cb_up (Address pWidget, Address pSpin)
  64. // {
  65. // ((Spinner*)pSpin)->changePositionY(-crs_size);
  66. // }
  67. //
  68. //
  69. // void changePositionX(int Step)
  70. // {
  71. // if ((position.x > 5 && position.x < 595))
  72. // {
  73. // position.x += Step;
  74. // }
  75. //
  76. // positionBox.put(position.x);
  77. // pWnd->detach(crosshair);
  78. // crosshair.move(position.x, position.y);
  79. //
  80. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  81. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  82. // pWnd->attach(crosshair);
  83. // pWnd->redraw();
  84. //
  85. // }
  86. //
  87. // void changePositionY(int Step)
  88. // {
  89. // if ((position.y > 5 && position.y < 395))
  90. // {
  91. // position.y += Step;
  92. // }
  93. //
  94. // positionBox.put(position.y);
  95. // pWnd->detach(crosshair);
  96. // crosshair.move(position.x, position.y);
  97. //
  98. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  99. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  100. //
  101. //
  102. // pWnd->attach(crosshair);
  103. // pWnd->redraw();
  104. //
  105. // }
  106. //
  107. //
  108. //public:
  109. // Spinner(Point loc, Point startPoint, Color spinColor)
  110. // : btn_down(loc, 20, 20, "\\/", Spinner::cb_down, this),
  111. // btn_left(Point(loc.x + 25, loc.y), 20, 20, "<", Spinner::cb_left,this),
  112. // btn_right(Point(loc.x + 125, loc.y), 20, 20, ">", Spinner::cb_right, this),
  113. // btn_up(Point(loc.x + 150, loc.y), 20, 20, "/\\", Spinner::cb_up, this),
  114. // positionBox(Point(loc.x + 50, loc.y), 70, 20, ""),
  115. // position(startPoint),
  116. // crosshair()
  117. // {
  118. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  119. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  120. // crosshair.set_color(spinColor);
  121. // }
  122. //
  123. //
  124. //
  125. // void attachTo(Graph_lib::Window& wnd)
  126. // {
  127. // wnd.attach(btn_down);
  128. // wnd.attach(btn_left);
  129. // wnd.attach(btn_right);
  130. // wnd.attach(btn_up);
  131. // wnd.attach(positionBox);
  132. // positionBox.put(position.x);
  133. // positionBox.put(position.y);
  134. //
  135. // wnd.attach(crosshair);
  136. // pWnd = &wnd;
  137. // }
  138. //};
  139. ostream& operator<<(ostream& os, const Point& pt)
  140. {
  141. return os << '(' << pt.x << ',' << pt.y << ')';
  142. }
  143.  
  144. class DrawingArea
  145. {
  146. // Point one;
  147. // Point two;
  148. Shape *pArea = nullptr;
  149. Graph_lib::Window *pWnd = nullptr;
  150. // Graph_lib::Point one;
  151. // Graph_lib::Point second;
  152. public:
  153. DrawingArea(Graph_lib::Point uno, Graph_lib::Point secondo)
  154. {
  155. pWnd = nullptr;
  156. pArea = new Graph_lib::Rectangle(Point(200,200), Point(300,300));
  157. }
  158. ~DrawingArea()
  159. {
  160. delete pArea;
  161. }
  162. };
  163.  
  164. //static void cb_left (Address pWidget, Address pSpin)
  165. // {
  166. // ((Spinner*)pSpin)->changePositionX(-crs_size);
  167. // }
  168.  
  169. class myWindow : public Graph_lib::Window
  170. {
  171. Button btn_close, btn_save;
  172. bool drawingNow;
  173. DrawingArea canvas;
  174. Point start, stop;
  175. Graph_lib::Rectangle *pRect;
  176. std::vector<Shape *> shapes;
  177. fstream myFile;
  178. int start_x, start_y, stop_x, stop_y;
  179. Graph_lib::Window *pWnd = nullptr;
  180.  
  181. static void cb_close(Address pWidget, Address pMyWin)
  182. {
  183. ((Graph_lib::Window *)pMyWin) -> hide();
  184. }
  185. static void cb_save(Address pWidget, Address pMyWin)
  186. {
  187. ((myWindow*)pMyWin)->saving();
  188. }
  189.  
  190. void saving()
  191. {
  192. // myFile ("Plik.txt", ios::out);
  193. // myFile.close();
  194. }
  195.  
  196. public:
  197. myWindow(Point loc, int w, int h, std::string title) :
  198. Graph_lib::Window(loc, w, h, title),
  199. btn_close(Point(x_max() - 80, y_max() - 20), 80, 20,
  200. "Close", myWindow::cb_close),
  201. btn_save(Point(x_max() - 80, y_max() - 50), 80, 20,
  202. "Save", myWindow::cb_save),
  203. drawingNow(false),
  204. canvas(Point(10,10), Point(x_max() - 100, y_max() - 10)),
  205. start(0, 0), stop(0, 0), pRect(nullptr)
  206. {
  207. attach(btn_close);
  208. attach(btn_save);
  209. }
  210. Point event_xy() const
  211. {
  212. return Point(Fl::event_x(), Fl::event_y());
  213. }
  214. int handle(int event)
  215. {
  216.  
  217. switch (event)
  218. {
  219.  
  220. case FL_PUSH: // nacisniecie lewego przycisku myszy
  221. std::cout << "push @" << event_xy() << std::endl;
  222. drawingNow = true;
  223. start = event_xy();
  224. break;
  225.  
  226.  
  227. case FL_DRAG: // "wleczenie" myszy
  228. if(drawingNow)
  229. {
  230. std::cout << "drag @" << event_xy() << std::endl;
  231. //int start_x, start_y;
  232. if (start.y < event_xy().y)
  233. {
  234. start_y = std::min(start.y, event_xy().y);
  235. start_x = std::min(start.x, event_xy().x);
  236. pRect = new Graph_lib::Rectangle (Point(start_x, start_y), event_xy());
  237. this -> attach(*pRect);
  238. }
  239.  
  240. }
  241. break;
  242.  
  243.  
  244. case FL_RELEASE: // zwolnienie lewego przycisku myszy
  245. std::cout << "release @" << event_xy() << std::endl;
  246. drawingNow = false;
  247. stop = event_xy();
  248. // int stop_x, stop_y;
  249. if (start.y < stop.y)
  250. {
  251. stop_y = std::max(start_y, stop.y);
  252. stop_x = std::max(start_x, stop.x);
  253. pRect = new Graph_lib::Rectangle(Point(start_x, start_y), Point(stop_x, stop_y));
  254. shapes.push_back(pRect);
  255. //this -> attach(*pRect);
  256.  
  257. }
  258. break;
  259.  
  260. }
  261. (myWindow()*) ->attach(*pRect);
  262.  
  263. return Fl_Window::handle(event);
  264. }
  265.  
  266. };
  267.  
  268. main()
  269. {
  270. myWindow wnd(Point(100, 100), 600, 400, "Bartosz Pokorski (281814)");
  271. // Graph_lib::Window wnd(Point(100, 100), 600, 400, "Bartosz Pokorski (281814)");
  272. // Button btn(Point(wnd.x_max() - 80, wnd.y_max() - 20), 80, 20, "Close", cb_close);
  273. // wnd.attach(btn);
  274. // Spinner crsRed(Point(wnd.x_max() - 170, 10), Point(200, 200), Color::red);
  275. // crsRed.attachTo(wnd);
  276. // Spinner crsBlue(Point(wnd.x_max() - 170, 40),Point(220, 200), Color::blue);
  277. // crsBlue.attachTo(wnd);
  278. gui_main();
  279. return 0;
  280. }
  281.  
  282. //void cb_close (Address addr1, Address addr2)
  283. //{
  284. // cout << "addr1: "<< addr1 << endl;
  285. // cout << "addr2: " <<addr2 << endl;
  286. // cout << "close pressed\n";
  287. //// btn_close.move(100, -100);
  288. // ((Graph_lib::Window *)addr2) -> hide();
  289. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement