Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <fl/fl.h>
- #include <fl/fl_window.h>
- #include <fl/fl_jpeg_image.h>
- #include <fl/fl_box.h>
- struct Area{
- int x;
- int y;
- int height;
- int width;
- string name;
- };
- Area area1 = {0,310,130,40,"area1"};
- Area area2 = {120,425,130,125,"area2"};
- Area area3 = {720,460,60,110,"area3"};
- Area area4 = {630,60,50,90,"area4"};
- Area areas[4] = {area1,area2,area3,area4};
- bool contains_area(int x, int y, Area image);
- class CatBox : public Fl_Box
- {
- public:
- CatBox(int x, int y,int w, int h, const char* title) : Fl_Box(x,y,w,h,title){}
- int handle(int e)
- {
- if(e == FL_PUSH)
- {
- for (int i = 0; i < 4; ++i)
- {
- if(contains_area(Fl::event_x(),Fl::event_y(),areas[i]))
- {
- cout << areas[i].name << "(" << Fl::event_x() << "," << Fl::event_y() << ")" << endl ;
- }
- }
- // cout << " ouch! " << "(" << Fl::event_x() << "," << Fl::event_y() << ")";
- }
- }
- };
- class CatWindow : public Fl_Window
- {
- private:
- Fl_JPEG_Image catPicture;
- CatBox catBox;
- public:
- CatWindow(int w, int h,const char* t)
- : Fl_Window(w,h,t) , catBox( 0, 0,750,600,"Testing"),
- catPicture("cluttercity1.jpg")
- {
- catBox.image(catPicture);
- }
- };
- int main()
- {
- // sound->play();
- CatWindow w(750,600, "I spy");
- w.show();
- Fl::run();
- }
- bool contains_area(int x, int y, Area image) // checks to see if the x and y coordinates falls into the Area image
- {
- bool contains = false;
- if ( (x > image.x) && (x < (image.x + image.width)) )
- {
- if ( (y < image.y + image.height) && (y > (image.y)))
- {
- contains = true;
- }
- }
- return contains;
- }
Add Comment
Please, Sign In to add comment