fork(1) download
  1. #include <FL/Fl.H>
  2. #include <FL/Fl_Box.H>
  3. #include <FL/Fl_Window.H>
  4. #include "../../../std_lib_facilities.h"
  5. #include "../../../Point.h"
  6. #include "../../../Graph.h"
  7. #include "../../../GUI.h"
  8. #include "../../../Simple_window.h"
  9. #include "../../../Window.h"
  10.  
  11. using namespace Graph_lib;
  12.  
  13. struct Coulomb_window :Window{
  14. Coulomb_window(Point xy, int w, int h, const string& title );
  15.  
  16. private:
  17. Circle circle;
  18. Button start_button;
  19. static void cb_start(Address,Address);
  20. void start();
  21. int handle(int);
  22. friend void timeout_callback(void*);
  23. };
  24.  
  25.  
  26.  
  27.  
  28. Coulomb_window::Coulomb_window(Point xy, int w, int h, const string& title )
  29. :Window(xy,w,h,title),
  30. circle(Point(100,100),50),
  31. start_button(Point(x_max()-150,5),40,20,"start",cb_start)
  32.  
  33. {
  34. circle.set_fill_color(Color::red);
  35. circle.set_color(Color::invisible);
  36. attach(circle);
  37. attach(start_button);
  38. };
  39.  
  40.  
  41.  
  42. void Coulomb_window::cb_start(Address,Address pw)
  43. {
  44. reference_to<Coulomb_window>(pw).start();
  45. };
  46.  
  47. void timeout_callback(void* ptr)
  48. {
  49. Coulomb_window* this_ = static_cast<Coulomb_window*>(ptr);
  50. this_->circle.move(10,0); this_->redraw();
  51. Fl::repeat_timeout(0.1, timeout_callback, static_cast<void*>(this_));
  52. }
  53.  
  54. //円を動かす
  55. void Coulomb_window::start()
  56. {
  57. Fl::add_timeout(0.1, timeout_callback, static_cast<void*>(this));
  58. }
  59.  
  60. int Coulomb_window::handle(int e)
  61. {
  62. int ret = 0;
  63. switch (e) {
  64. case FL_FOCUS:
  65. case FL_UNFOCUS:
  66. ret = 1;
  67. break;
  68. case FL_KEYDOWN:
  69. if ( Fl::event_key('A') ) { ret = 1; circle.move(10,0); redraw(); }
  70. break;
  71. }
  72. return ret || Fl_Window::handle(e);
  73. }
  74.  
  75. int main()
  76. try{
  77. Coulomb_window win(Point(100,100),600,400,"Coulomb's_law");
  78. return gui_main();
  79. }
  80.  
  81. catch(exception& e) {
  82. cerr << "exception: " << e.what() << '\n';
  83. return 1;
  84. }
  85. catch (...) {
  86. cerr << "some exception\n";
  87. return 2;
  88. }
  89.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty