Esempio n. 1
0
	void draw(void){
		int minx=scroll->x()-x(),miny=scroll->y()-y();
		int maxx=minx+scroll->w(),maxy=miny+scroll->h();
		Fl_Box::draw();
		//Now draw the rectangles
		for(unsigned i=0;i<rects->size();i+=4){
			if(((*rects)[i]>=minx)||((*rects)[i]<=maxx)){
				if(((*rects)[i+2]>=miny)||((*rects)[i+2]<=maxy)){
					if(!(*deleted)[i/4])
						fl_draw_box(FL_EMBOSSED_FRAME,(*rects)[i]+x(),(*rects)[i+2]+y(),(*rects)[i+1]-(*rects)[i]+1,(*rects)[i+3]-(*rects)[i+2]+1,0);
				}
			}
		}
	}
int Fl_Canvas::handle (int event) {
    if (Fl_Group::handle (event)) return 1;
    if (event==FL_PUSH) {
       ClearIncompleteWire();
       redraw();
       m_DragX=Fl::event_x();
       m_DragY=Fl::event_y();
    }
    if ((Fl::event_button() == 1) && ((Fl::event_state() & FL_SHIFT) == 0) && ((Fl::event_state() & FL_CTRL) == 0)) {
       // Left-Click  (or plain click for those who are mouse-button challenged)
       // Select / Multi-select / move devices
       // Handled below - If on a non-selected plugin, deselect and move
       // Handled below - If on a selected plugin, move selection
       // Handled Here - If on canvas - multi select
       if (event==FL_PUSH) {
          if (m_HaveSelection) {
             m_Selection.Clear();
             m_HaveSelection = false;
          }
          m_Selecting = true;
          m_StartSelectX=Fl::event_x();
          m_StartSelectY=Fl::event_y();
          m_EndSelectX=Fl::event_x();
          m_EndSelectY=Fl::event_y();
          ClearIncompleteWire();
          redraw();
          m_DragX=Fl::event_x();
          m_DragY=Fl::event_y();
       }
       if ((event==FL_DRAG) && m_Selecting) {
          m_EndSelectX = Fl::event_x();
          m_EndSelectY = Fl::event_y();
          Fl_Scroll* scroll = (Fl_Scroll *)parent();
          int newx = 0, xp = scroll->xposition();
          int newy = 0, yp = scroll->yposition();
          if ((m_EndSelectX < m_StartSelectX) && ((m_EndSelectX - x() - xp) <= 15))
             newx = 10;
          if ((m_EndSelectY < m_StartSelectY) && ((m_EndSelectY - y() - yp) <= 15))
             newy = 10;
          if ((m_EndSelectX > m_StartSelectX) && ((scroll->x() + scroll->w() - m_EndSelectX - 15) <= 15))
             newx = -10;
          if ((m_EndSelectY > m_StartSelectY) && ((scroll->y() + scroll->h() - m_EndSelectY - 15) <= 5))
             newy = -10;
          if ((newx!=0) || (newy!=0)) {
             position(x()+newx,y()+newy);
             m_StartSelectX += newx;
             m_StartSelectY += newy;
          }
          m_DragX=Fl::event_x();
          m_DragY=Fl::event_y();
          redraw();
       }
       if ((event==FL_RELEASE) && m_Selecting) {
          m_Selecting = false;
          if ((m_EndSelectX != m_StartSelectX) && (m_EndSelectY != m_StartSelectY))
             CalculateSelection();
          redraw();
       }
    }
    if ((Fl::event_button() == 2) || ((Fl::event_button() == 1) && ((Fl::event_state() & FL_SHIFT) != 0))) {
       // Middle-Click  (or shift-click for the mouse button challenged) - old left click
       // Handled Below - If on items allows selecting of individual items
       // Handled Here - If on canvas, drags canvas
       if (event==FL_PUSH) {
          ClearIncompleteWire();
          redraw();
          m_DragX=Fl::event_x();
          m_DragY=Fl::event_y();
       }
       if (event==FL_DRAG) {
          position (x() + (Fl::event_x() - m_DragX), y() + (Fl::event_y() - m_DragY));
          m_DragX=Fl::event_x();
          m_DragY=Fl::event_y();
          redraw();
       }
    }
    if ((Fl::event_button() == 3) || ((Fl::event_button() == 1) && ((Fl::event_state() & FL_CTRL) != 0))) {
       // Right-Click (or Ctrl-click for the M.B.C.)
       // Pop-up Edit/Plugins menu
       if (event==FL_PUSH) {
          m_x=Fl::event_x();
          m_y=Fl::event_y();
          PopupEditMenu (this);
       }
    }
    return 1;
}