Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <fl/fl.h>
  4. #include <fl/fl_window.h>
  5. #include <fl/fl_jpeg_image.h>
  6. #include <fl/fl_box.h>
  7.  
  8.  
  9. struct Area{
  10. int x;
  11. int y;
  12. int height;
  13. int width;
  14. string name;
  15. };
  16.  
  17. Area area1 = {0,310,130,40,"area1"};
  18. Area area2 = {120,425,130,125,"area2"};
  19. Area area3 = {720,460,60,110,"area3"};
  20. Area area4 = {630,60,50,90,"area4"};
  21. Area areas[4] = {area1,area2,area3,area4};
  22. bool contains_area(int x, int y, Area image);
  23. class CatBox : public Fl_Box
  24. {
  25. public:
  26. CatBox(int x, int y,int w, int h, const char* title) : Fl_Box(x,y,w,h,title){}
  27.  
  28. int handle(int e)
  29. {
  30. if(e == FL_PUSH)
  31. {
  32. for (int i = 0; i < 4; ++i)
  33. {
  34. if(contains_area(Fl::event_x(),Fl::event_y(),areas[i]))
  35. {
  36. cout << areas[i].name << "(" << Fl::event_x() << "," << Fl::event_y() << ")" << endl ;
  37. }
  38. }
  39. // cout << " ouch! " << "(" << Fl::event_x() << "," << Fl::event_y() << ")";
  40. }
  41. }
  42. };
  43.  
  44. class CatWindow : public Fl_Window
  45. {
  46. private:
  47. Fl_JPEG_Image catPicture;
  48. CatBox catBox;
  49.  
  50. public:
  51. CatWindow(int w, int h,const char* t)
  52. : Fl_Window(w,h,t) , catBox( 0, 0,750,600,"Testing"),
  53. catPicture("cluttercity1.jpg")
  54. {
  55. catBox.image(catPicture);
  56. }
  57.  
  58. };
  59.  
  60. int main()
  61. {
  62.  
  63. // sound->play();
  64. CatWindow w(750,600, "I spy");
  65. w.show();
  66. Fl::run();
  67.  
  68. }
  69.  
  70.  
  71. bool contains_area(int x, int y, Area image) // checks to see if the x and y coordinates falls into the Area image
  72. {
  73. bool contains = false;
  74. if ( (x > image.x) && (x < (image.x + image.width)) )
  75. {
  76. if ( (y < image.y + image.height) && (y > (image.y)))
  77. {
  78. contains = true;
  79. }
  80. }
  81. return contains;
  82. }
Add Comment
Please, Sign In to add comment