void DragClientImpl::startDrag(DragImage* dragImage,
                               const IntPoint& dragImageOrigin,
                               const IntPoint& eventPos,
                               Clipboard* clipboard,
                               Frame* frame,
                               bool isLinkDrag)
{
    // Add a ref to the frame just in case a load occurs mid-drag.
    RefPtr<Frame> frameProtector = frame;

    WebDragData dragData = static_cast<ClipboardChromium*>(clipboard)->dataObject();
    WebDragOperationsMask dragOperationMask = static_cast<WebDragOperationsMask>(clipboard->sourceOperation());
    WebImage image;
    IntSize offsetSize(eventPos - dragImageOrigin);
    WebPoint offsetPoint(offsetSize.width(), offsetSize.height());

    if (dragImage) {
        float resolutionScale = dragImage->resolutionScale();
        if (m_webView->deviceScaleFactor() != resolutionScale) {
            ASSERT(resolutionScale > 0);
            float scale = m_webView->deviceScaleFactor() / resolutionScale;
            dragImage->scale(scale, scale);
        }
        image = dragImage->bitmap();
    }

    m_webView->startDragging(frame, dragData, dragOperationMask, image, offsetPoint);
}
Ejemplo n.º 2
0
void DragClientImpl::startDrag(DragImageRef dragImage,
                               const IntPoint& dragImageOrigin,
                               const IntPoint& eventPos,
                               Clipboard* clipboard,
                               Frame* frame,
                               bool isLinkDrag)
{
    // Add a ref to the frame just in case a load occurs mid-drag.
    RefPtr<Frame> frameProtector = frame;

    WebDragData dragData = static_cast<ClipboardChromium*>(clipboard)->dataObject();

    DragOperation dragOperationMask = clipboard->sourceOperation();

    IntSize offsetSize(eventPos - dragImageOrigin);
    WebPoint offsetPoint(offsetSize.width(), offsetSize.height());
    m_webView->startDragging(
        dragData, static_cast<WebDragOperationsMask>(dragOperationMask),
#if WEBKIT_USING_SKIA
        dragImage ? WebImage(*dragImage) : WebImage(),
#else
        dragImage ? WebImage(dragImage) : WebImage(),
#endif
        offsetPoint);
}
/*!
    \class HsAnchorPointInBottomRight
    \brief Diagonal widget positioning algorithm.
    
    Sets widget's lower right corner to follow content area's diagonal.
    Widgets are positioned to certain offset to each other.
*/
HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInBottomRight::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint)
{
    Q_UNUSED(existingRects);

    HsWidgetPositioningOnWidgetAdd::Result result;
    QList<QRectF> toGeometries;

    //Offset for widgets' bottom right position to each other
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
    qreal offset_x = offset/(sqrt(k + 1));
    qreal offset_y = k*offset_x;
    QPointF offsetPoint(offset_x, offset_y);
    
    QPointF anchorPoint;
   
    if(startPoint.isNull()){

        QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
        QLineF widgetRightSide(contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.top(),
                           contentArea.center().x()+ newRects.at(0).width()/2,
                           contentArea.bottom());

        // right side line intersection with diagonal will be bottom right position
        // for the first rect
        if(QLineF::BoundedIntersection != 
            diagonal.intersect(widgetRightSide, &anchorPoint)) {
            result.calculatedRects = newRects;
            return result; //Return original since undefined error.
                            //In this case widget's must be wider than the content area.
        }
    } else {
        anchorPoint = startPoint - offsetPoint;
    }

    QRectF widgetRect;
    for(int i=0;i<newRects.count();++i) {
        widgetRect = newRects.at(i);
        widgetRect.moveBottomRight(anchorPoint);
        //if widget rect doesn't fit, try to move it
        if(!contentArea.contains(widgetRect)) {
            /*! precondition is that
             widget's max height < content area height
             widget's max widht < content area width
            */
            widgetRect.moveBottomRight(contentArea.bottomRight());
            // anchorPoin is always previous bottom right
            anchorPoint = widgetRect.bottomRight();
        }
        toGeometries << widgetRect;
        anchorPoint -= offsetPoint;
        
    }
    result.calculatedRects = toGeometries;
    return result;
}
HsWidgetPositioningOnWidgetAdd::Result HsAnchorPointInCenter::convert(
    const QRectF &contentArea,
    const QList<QRectF> &existingRects,
    const QList<QRectF> &newRects,
    const QPointF &startPoint )
{
    Q_UNUSED(existingRects);
    Q_UNUSED(startPoint)

    HsWidgetPositioningOnWidgetAdd::Result result;
    QList<QRectF> toGeometries;

    //Offset for widgets' centers position to each other
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
    qreal offset_x = offset/(sqrt(k + 1));
    qreal offset_y = k*offset_x;
    QPointF offsetPoint(offset_x, offset_y);

    //First widget to the center of the content area
    QPointF anchorPoint = contentArea.center();
    foreach (QRectF g, newRects) {
        g.moveCenter(anchorPoint);
        toGeometries << g;
        anchorPoint -= offsetPoint;
        if(!contentArea.contains(anchorPoint)) {
            anchorPoint = contentArea.bottomRight();
        }
    }
Ejemplo n.º 5
0
XBOOL XXObjectRectangle::SysCallMethod(int id,XSWFCONTEXT*pCnt,XXVARLIST&list)
{
	switch(id)
	{
	case _SYSID(clone):
		 pCnt->pStack->Push(Clone());
		 return XTRUE;
	case _SYSID(contains):
		 contains(*pCnt,list);
		 return XTRUE;
	case _SYSID(containsPoint):
		 containsPoint(*pCnt,list);
		 return XTRUE;
	case _SYSID(containsRectangle):
		 containsRectangle(*pCnt,list);
		 return XTRUE;
	case _SYSID(equals):
		 equalsRect(*pCnt,list);
		 return XTRUE;
	case _SYSID(inflate):
		 inflate(*pCnt,list);
		 return XTRUE;
	case _SYSID(inflatePoint):
		 inflatePoint(*pCnt,list);
		 return XTRUE;
	case _SYSID(intersection):
		 intersection(*pCnt,list);
		 return XTRUE;
	case _SYSID(intersects):
		 intersects(*pCnt,list);return XTRUE;
	case _SYSID(isEmpty):
		 pCnt->pStack->PushBool((width==0&&height==0));
		 return XTRUE;
	case _SYSID(offset):
		 offsetRect(*pCnt,list);
		 return XTRUE;
	case _SYSID(offsetPoint):
		 offsetPoint(*pCnt,list);
		 return XTRUE;
	case _SYSID(setEmpty):
		 left=top=0;
		 width=height=0;
		 pCnt->pStack->PushConst(XOCT_UNDEFINE);
		 return XTRUE;
	case _SYSID(toString):
		{
			XXVar var;
			GetString(var);
			pCnt->pStack->Push(var);
		}return XTRUE;
	case _SYSID(union):
		unionRect(*pCnt,list);
		return XTRUE;
	}
	return XXObject::SysCallMethod(id,pCnt,list);
}
Ejemplo n.º 6
0
bool CRegion::containsPoint(QPoint point)
{
    // Offset point
    QPoint offsetPoint(point.x() - OFFSET_X, point.y() - OFFSET_Y);

    // Check point
    if( offsetPoint.x() < m_topRight.x() &&
        offsetPoint.x() > m_topLeft.x() &&
        offsetPoint.y() < m_botLeft.y() &&
        offsetPoint.y() > m_topLeft.y())
        return true;

    return false;
}
Ejemplo n.º 7
0
bool SpatialAverageSpotter::train(string dirPath)
{
    
    int count=0;
    vector<vector<tuple<int,Point2f> > > features;
    featureAverages.resize(codebook->size());
    for (int i =0; i<codebook->size(); i++)
        featureAverages[i]=Mat(BASE_SIZE,BASE_SIZE,CV_32F,Scalar(0));
    
    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir (dirPath.c_str())) != NULL) {
      /* print all the files and directories within directory */
//      Mat img;
      while ((ent = readdir (dir)) != NULL) {
          
          string fileName(ent->d_name);
//          cout << "examining " << fileName << endl;
          if (fileName[0] == '.' || fileName[fileName.size()-1]!='G')
              continue;
          
          Mat img = imread(dirPath+fileName, CV_LOAD_IMAGE_GRAYSCALE);
//          resize(img,img,Size(0,0),2,2);
          threshold(img,img,120.0,255,THRESH_BINARY);
//          windowWidth += img.cols;
//          windowHeight += img.rows;
//          int avg=0;
//          for (int x=0; x<img.cols; x++)
//              for (int  y=0; y<img.rows; y++)
//                  avg += (int)img.at<unsigned char>(y,x);
////          cout << "avg="<<avg<<"/"<<img.cols*img.rows<<" = "<<avg/(img.cols*img.rows)<<endl;
//          avg /= img.cols*img.rows;
          
          resize(img,img,Size(PRE_BASE_SIZE,PRE_BASE_SIZE*((0.0+img.rows)/img.cols)));
          
          
          copyMakeBorder( img, img, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_CONSTANT, 255 );
          assert(img.cols > 1 && img.rows > 1);
          adjustedTrainingImages.push_back(img.clone());
          
          Point2f centerOfMass = findCenterOfMass(img);
          int offsetx=(img.cols/2)-centerOfMass.x;
          int offsety=(img.rows/2)-centerOfMass.y;
          translateImg(img,offsetx,offsety);
          
        
          vector<KeyPoint> keypoints;
          Mat desc;
          detectKeypoints( img,keypoints, desc);
          Mat out;
          cvtColor(img,out,CV_GRAY2RGB);
          circle(out,centerOfMass,1,Scalar(0,0,255));
          
          features.resize(count+1);
          //double scaling = BASE_SIZE/img
          for (int r=0; r<desc.rows; r++)
          {
              int f = codebook->quantize(desc.row(r));
              Point2f offsetPoint(keypoints[r].pt.x - centerOfMass.x, keypoints[r].pt.y - centerOfMass.y);
              features[count].push_back(make_tuple(f,offsetPoint));//we're ignoring the keypoint scale.. 
              
              
//              circle(out,keypoints[r].pt,keypoints[r].size,Scalar(colorTable[f]));
              Rect rec(keypoints[r].pt.x-(keypoints[r].size/2),keypoints[r].pt.y-(keypoints[r].size/2),keypoints[r].size,keypoints[r].size);
              rectangle(out,rec,Scalar(colorTable[f]));
              
          }
          guassColorIn(features[count]);
          
          
          imshow("learning keypoints",out);
          cout << "image "<<count<<endl;
          waitKey(5);
          
          count++;
//          img.release();
      }
      closedir (dir);
    } else {
      /* could not open directory */
      perror ("");
      return false;
    }
    
    //We now step through adjusting the scales of the various images so the guass coloring is maximized
    //But we may still want to look at tfidf to see which ones should be weighted more, etc.
    maximizeAlignment(features);
    
    float max=0;
    float min =99999;
    float avg_max=0;
    
    int firstx=9999;
    int lastx=0;
    int firsty=9999;
    int lasty=0;
    
    for (int f=0; f<codebook->size(); f++)
    {
        float local_max=0;
        
        bool hitFirst=false;
        
        for (int x=0; x<featureAverages[f].cols; x++)
            for (int y=0; y<featureAverages[f].rows; y++)
            {
                float val = featureAverages[f].at<float>(y,x);
                if (val > 300 || val < -300)
                    cout << "val (" << x <<","<<y<<") " << val << endl;
                if (val>max) max=val;
                if (val<min) min=val;
                if (val>local_max) local_max=val;
                
                if (val>WINDOW_THRESH)
                {
                    if (!hitFirst)
                    {
                        hitFirst=true;
                        if (x<firstx) firstx=x;
                        if (y<firsty) firsty=y;
                    }
                    if (x>lastx) lastx=x;
                    if (y>lasty) lasty=y;
                }
            }
        avg_max+=local_max;
    }
//    penalty=min+(max-min)*.2;
    avg_max /= codebook->size();
    penalty=avg_max*.15;//.2
    
//    windowWidth/=count;
//    windowHeight/=count;
    windowWidth = lastx-firstx;
    windowHeight = lasty-firsty;
    cout << "window size is "<<windowWidth<<"x"<<windowHeight<<endl;
    
    //show averages
    showAverages();
    
    return true;
}