Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bartosz Pokorski
- //281814
- #include <graph.h>
- #include <GUI.h>
- #include <string>
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <vector>
- using namespace Graph_lib;
- void cb_close (Address addr1, Address pWnd);
- class myWindow;
- struct myButton : Button
- {
- myWindow* pMyWindow;
- myButton(Point xy, int w, int h, const string& label, Callback cb, myWindow* pMyWin) : Button(xy, w,h, label, cb),
- pMyWindow(pMyWin)
- {}
- void attach(Graph_lib::Window& wnd)
- {
- Button::attach(wnd);
- pw -> callback(reinterpret_cast<Fl_Callback*>(do_it),pMyWindow);
- }
- Address getWigdetAddress() const { return pw; }
- };
- //class Spinner
- //{
- //private:
- //
- // myButton btn_down;
- // myButton btn_left;
- // myButton btn_right;
- // myButton btn_up;
- //
- // Graph_lib::Out_box positionBox;
- // Point position;
- // static const int crs_size = 5;
- //
- // Lines crosshair;
- // Graph_lib::Window *pWnd = nullptr;
- //
- //
- // static void cb_down (Address pWidget, Address pSpin)
- // {
- // ((Spinner*)pSpin)->changePositionY(crs_size);
- // }
- //
- //
- //
- // static void cb_right (Address pWidget, Address pSpin)
- // {
- // ((Spinner*)pSpin)->changePositionX(crs_size);
- // }
- //
- // static void cb_up (Address pWidget, Address pSpin)
- // {
- // ((Spinner*)pSpin)->changePositionY(-crs_size);
- // }
- //
- //
- // void changePositionX(int Step)
- // {
- // if ((position.x > 5 && position.x < 595))
- // {
- // position.x += Step;
- // }
- //
- // positionBox.put(position.x);
- // pWnd->detach(crosshair);
- // crosshair.move(position.x, position.y);
- //
- // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
- // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
- // pWnd->attach(crosshair);
- // pWnd->redraw();
- //
- // }
- //
- // void changePositionY(int Step)
- // {
- // if ((position.y > 5 && position.y < 395))
- // {
- // position.y += Step;
- // }
- //
- // positionBox.put(position.y);
- // pWnd->detach(crosshair);
- // crosshair.move(position.x, position.y);
- //
- // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
- // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
- //
- //
- // pWnd->attach(crosshair);
- // pWnd->redraw();
- //
- // }
- //
- //
- //public:
- // Spinner(Point loc, Point startPoint, Color spinColor)
- // : btn_down(loc, 20, 20, "\\/", Spinner::cb_down, this),
- // btn_left(Point(loc.x + 25, loc.y), 20, 20, "<", Spinner::cb_left,this),
- // btn_right(Point(loc.x + 125, loc.y), 20, 20, ">", Spinner::cb_right, this),
- // btn_up(Point(loc.x + 150, loc.y), 20, 20, "/\\", Spinner::cb_up, this),
- // positionBox(Point(loc.x + 50, loc.y), 70, 20, ""),
- // position(startPoint),
- // crosshair()
- // {
- // crosshair.add(Point(position.x - crs_size, position.y), Point(position.x + crs_size, position.y));
- // crosshair.add(Point(position.x, position.y - crs_size), Point(position.x, position.y + crs_size));
- // crosshair.set_color(spinColor);
- // }
- //
- //
- //
- // void attachTo(Graph_lib::Window& wnd)
- // {
- // wnd.attach(btn_down);
- // wnd.attach(btn_left);
- // wnd.attach(btn_right);
- // wnd.attach(btn_up);
- // wnd.attach(positionBox);
- // positionBox.put(position.x);
- // positionBox.put(position.y);
- //
- // wnd.attach(crosshair);
- // pWnd = &wnd;
- // }
- //};
- ostream& operator<<(ostream& os, const Point& pt)
- {
- return os << '(' << pt.x << ',' << pt.y << ')';
- }
- class DrawingArea
- {
- // Point one;
- // Point two;
- Shape *pArea = nullptr;
- Graph_lib::Window *pWnd = nullptr;
- // Graph_lib::Point one;
- // Graph_lib::Point second;
- public:
- DrawingArea(Graph_lib::Point uno, Graph_lib::Point secondo)
- {
- pWnd = nullptr;
- pArea = new Graph_lib::Rectangle(Point(200,200), Point(300,300));
- }
- ~DrawingArea()
- {
- delete pArea;
- }
- };
- //static void cb_left (Address pWidget, Address pSpin)
- // {
- // ((Spinner*)pSpin)->changePositionX(-crs_size);
- // }
- class myWindow : public Graph_lib::Window
- {
- Button btn_close, btn_save;
- bool drawingNow;
- DrawingArea canvas;
- Point start, stop;
- Graph_lib::Rectangle *pRect;
- std::vector<Shape *> shapes;
- fstream myFile;
- int start_x, start_y, stop_x, stop_y;
- Graph_lib::Window *pWnd = nullptr;
- static void cb_close(Address pWidget, Address pMyWin)
- {
- ((Graph_lib::Window *)pMyWin) -> hide();
- }
- static void cb_save(Address pWidget, Address pMyWin)
- {
- ((myWindow*)pMyWin)->saving();
- }
- void saving()
- {
- // myFile ("Plik.txt", ios::out);
- // myFile.close();
- }
- public:
- myWindow(Point loc, int w, int h, std::string title) :
- Graph_lib::Window(loc, w, h, title),
- btn_close(Point(x_max() - 80, y_max() - 20), 80, 20,
- "Close", myWindow::cb_close),
- btn_save(Point(x_max() - 80, y_max() - 50), 80, 20,
- "Save", myWindow::cb_save),
- drawingNow(false),
- canvas(Point(10,10), Point(x_max() - 100, y_max() - 10)),
- start(0, 0), stop(0, 0), pRect(nullptr)
- {
- attach(btn_close);
- attach(btn_save);
- }
- Point event_xy() const
- {
- return Point(Fl::event_x(), Fl::event_y());
- }
- int handle(int event)
- {
- switch (event)
- {
- case FL_PUSH: // nacisniecie lewego przycisku myszy
- std::cout << "push @" << event_xy() << std::endl;
- drawingNow = true;
- start = event_xy();
- break;
- case FL_DRAG: // "wleczenie" myszy
- if(drawingNow)
- {
- std::cout << "drag @" << event_xy() << std::endl;
- //int start_x, start_y;
- if (start.y < event_xy().y)
- {
- start_y = std::min(start.y, event_xy().y);
- start_x = std::min(start.x, event_xy().x);
- pRect = new Graph_lib::Rectangle (Point(start_x, start_y), event_xy());
- this -> attach(*pRect);
- }
- }
- break;
- case FL_RELEASE: // zwolnienie lewego przycisku myszy
- std::cout << "release @" << event_xy() << std::endl;
- drawingNow = false;
- stop = event_xy();
- // int stop_x, stop_y;
- if (start.y < stop.y)
- {
- stop_y = std::max(start_y, stop.y);
- stop_x = std::max(start_x, stop.x);
- pRect = new Graph_lib::Rectangle(Point(start_x, start_y), Point(stop_x, stop_y));
- shapes.push_back(pRect);
- //this -> attach(*pRect);
- }
- break;
- }
- (myWindow()*) ->attach(*pRect);
- return Fl_Window::handle(event);
- }
- };
- main()
- {
- myWindow wnd(Point(100, 100), 600, 400, "Bartosz Pokorski (281814)");
- // Graph_lib::Window wnd(Point(100, 100), 600, 400, "Bartosz Pokorski (281814)");
- // Button btn(Point(wnd.x_max() - 80, wnd.y_max() - 20), 80, 20, "Close", cb_close);
- // wnd.attach(btn);
- // Spinner crsRed(Point(wnd.x_max() - 170, 10), Point(200, 200), Color::red);
- // crsRed.attachTo(wnd);
- // Spinner crsBlue(Point(wnd.x_max() - 170, 40),Point(220, 200), Color::blue);
- // crsBlue.attachTo(wnd);
- gui_main();
- return 0;
- }
- //void cb_close (Address addr1, Address addr2)
- //{
- // cout << "addr1: "<< addr1 << endl;
- // cout << "addr2: " <<addr2 << endl;
- // cout << "close pressed\n";
- //// btn_close.move(100, -100);
- // ((Graph_lib::Window *)addr2) -> hide();
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement