Advertisement
Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 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. using namespace Graph_lib;
  11.  
  12. void cb_close (Address addr1, Address pWnd);
  13. class myWindow;
  14. struct myButton : Button
  15. {
  16. myWindow* pMyWindow;
  17. myButton(Point xy, int w, int h, const string& label, Callback cb, myWindow* pMyWin) : Button(xy, w,h, label, cb),
  18. pMyWindow(pMyWin)
  19. {}
  20.  
  21.  
  22. void attach(Graph_lib::Window& wnd)
  23. {
  24. Button::attach(wnd);
  25. pw -> callback(reinterpret_cast<Fl_Callback*>(do_it),pMyWindow);
  26.  
  27. }
  28. Address getWigdetAddress() const { return pw; }
  29. };
  30.  
  31.  
  32.  
  33. //class Spinner
  34. //{
  35. //private:
  36. //
  37. // myButton btn_down;
  38. // myButton btn_left;
  39. // myButton btn_right;
  40. // myButton btn_up;
  41. //
  42. // Graph_lib::Out_box positionBox;
  43. // Point position;
  44. // static const int crs_size = 5;
  45. //
  46. // Lines crosshair;
  47. // Graph_lib::Window *pWnd = nullptr;
  48. //
  49. //
  50. // static void cb_down (Address pWidget, Address pSpin)
  51. // {
  52. // ((Spinner*)pSpin)->changePositionY(crs_size);
  53. // }
  54. //
  55. //
  56. //
  57. // static void cb_right (Address pWidget, Address pSpin)
  58. // {
  59. // ((Spinner*)pSpin)->changePositionX(crs_size);
  60. // }
  61. //
  62. // static void cb_up (Address pWidget, Address pSpin)
  63. // {
  64. // ((Spinner*)pSpin)->changePositionY(-crs_size);
  65. // }
  66. //
  67. //
  68. // void changePositionX(int Step)
  69. // {
  70. // if ((position.x > 5 && position.x < 595))
  71. // {
  72. // position.x += Step;
  73. // }
  74. //
  75. // positionBox.put(position.x);
  76. // pWnd->detach(crosshair);
  77. // crosshair.move(position.x, position.y);
  78. //
  79. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  80. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  81. // pWnd->attach(crosshair);
  82. // pWnd->redraw();
  83. //
  84. // }
  85. //
  86. // void changePositionY(int Step)
  87. // {
  88. // if ((position.y > 5 && position.y < 395))
  89. // {
  90. // position.y += Step;
  91. // }
  92. //
  93. // positionBox.put(position.y);
  94. // pWnd->detach(crosshair);
  95. // crosshair.move(position.x, position.y);
  96. //
  97. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  98. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  99. //
  100. //
  101. // pWnd->attach(crosshair);
  102. // pWnd->redraw();
  103. //
  104. // }
  105. //
  106. //
  107. //public:
  108. // Spinner(Point loc, Point startPoint, Color spinColor)
  109. // : btn_down(loc, 20, 20, "\\/", Spinner::cb_down, this),
  110. // btn_left(Point(loc.x + 25, loc.y), 20, 20, "<", Spinner::cb_left,this),
  111. // btn_right(Point(loc.x + 125, loc.y), 20, 20, ">", Spinner::cb_right, this),
  112. // btn_up(Point(loc.x + 150, loc.y), 20, 20, "/\\", Spinner::cb_up, this),
  113. // positionBox(Point(loc.x + 50, loc.y), 70, 20, ""),
  114. // position(startPoint),
  115. // crosshair()
  116. // {
  117. // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
  118. // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
  119. // crosshair.set_color(spinColor);
  120. // }
  121. //
  122. //
  123. //
  124. // void attachTo(Graph_lib::Window& wnd)
  125. // {
  126. // wnd.attach(btn_down);
  127. // wnd.attach(btn_left);
  128. // wnd.attach(btn_right);
  129. // wnd.attach(btn_up);
  130. // wnd.attach(positionBox);
  131. // positionBox.put(position.x);
  132. // positionBox.put(position.y);
  133. //
  134. // wnd.attach(crosshair);
  135. // pWnd = &wnd;
  136. // }
  137. //};
  138.  
  139. class DrawingArea
  140. {
  141. Graph_lib::Point AnotherPoint;
  142. public:
  143. DrawingArea(Point loc, Point AnotherPoint): {}
  144.  
  145. };
  146.  
  147. //static void cb_left (Address pWidget, Address pSpin)
  148. // {
  149. // ((Spinner*)pSpin)->changePositionX(-crs_size);
  150. // }
  151.  
  152. class myWindow : public Graph_lib::Window
  153. {
  154. Graph_lib::Button btn_close, Graph_lib::Button btn_save;
  155. bool drawingNow;
  156. DrawingArea canvas;
  157. Point start, stop;
  158. Graph_lib::Rectangle *pRect;
  159. std::vector<shape *> shapes;
  160. ofstream myFile;
  161. Graph_lib::Window *pWnd = nullptr;
  162.  
  163. static void cb_close(Address pWidget, Address pMyWin)
  164. {
  165. ((Graph_lib::Window *)pMyWin) -> hide();
  166. }
  167. static void cb_save(Address pWidget, Address pMyWin)
  168. {
  169. ((myWindow*)pMyWin->saving());
  170. }
  171.  
  172. void saving(ofstream SavingFiles)
  173. {
  174. myFile.open ("Plik.txt");
  175. myFile.close();
  176. return myFile;
  177. }
  178.  
  179. public:
  180. myWindow(Point loc, int w, int h, std::string title) :
  181. Graph_lib::Window(loc, w, h, title),
  182. btn_close(Point(x_max() - 80, y_max() - 20), 80, 20,
  183. "Close", myWindow::cb_close),
  184. btn_save(Point(x_max() - 80, y_max() - 50), 80, 20,
  185. "Save", myWindow::cb_save),
  186. drawingNow(false),
  187. canvas(Point(10,10), Point(x_max() - 100, y_max() - 10)),
  188. start(0, 0), stop(0, 0), pRect(nullptr)
  189. {
  190. attach(btn_close);
  191. attach(btn_save);
  192. }
  193. };
  194.  
  195. main()
  196. {
  197. Graph_lib::Window wnd(Point(100, 100), 600, 400, "Bartosz Pokorski (281814)");
  198. Button btn(Point(wnd.x_max() - 80, wnd.y_max() - 20), 80, 20, "Close", cb_close);
  199. wnd.attach(btn);
  200. Spinner crsRed(Point(wnd.x_max() - 170, 10), Point(200, 200), Color::red);
  201. crsRed.attachTo(wnd);
  202. Spinner crsBlue(Point(wnd.x_max() - 170, 40),Point(220, 200), Color::blue);
  203. crsBlue.attachTo(wnd);
  204. gui_main();
  205. return 0;
  206. }
  207.  
  208. //void cb_close (Address addr1, Address addr2)
  209. //{
  210. // cout << "addr1: "<< addr1 << endl;
  211. // cout << "addr2: " <<addr2 << endl;
  212. // cout << "close pressed\n";
  213. //// btn_close.move(100, -100);
  214. // ((Graph_lib::Window *)addr2) -> hide();
  215. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement