当前位置: 首页>>代码示例>>C++>>正文


C++ Drawing::addPoint方法代码示例

本文整理汇总了C++中Drawing::addPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Drawing::addPoint方法的具体用法?C++ Drawing::addPoint怎么用?C++ Drawing::addPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drawing的用法示例。


在下文中一共展示了Drawing::addPoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onMessage

//--------------------------------------------------------------
void ofApp::onMessage( ofxLibwebsockets::Event& args ){
    cout<<"got message "<<args.message<<endl;
    
  try{
    // trace out string messages or JSON messages!
    if ( !args.json.isNull() ){
        ofPoint point = ofPoint( args.json["point"]["x"].asFloat(), args.json["point"]["y"].asFloat() );
        
        // for some reason these come across as strings via JSON.stringify!
        int r = ofToInt(args.json["color"]["r"].asString());
        int g = ofToInt(args.json["color"]["g"].asString());
        int b = ofToInt(args.json["color"]["b"].asString());
        ofColor color = ofColor( r, g, b );
        
        int _id = ofToInt(args.json["id"].asString());
        
        map<int, Drawing*>::const_iterator it = drawings.find(_id);
        Drawing * d = it->second;
        d->addPoint(point);
    } else {
    }
    // send all that drawing back to everybody except this one
    vector<ofxLibwebsockets::Connection *> connections = server.getConnections();
    for ( int i=0; i<connections.size(); i++){
        if ( (*connections[i]) != args.conn ){
            connections[i]->send( args.message );
        }
    }
  }
  catch(exception& e){
    ofLogError() << e.what();
  }
}
开发者ID:PTS93,项目名称:ofxLibwebsockets,代码行数:34,代码来源:ofApp.cpp

示例2: mouseDragged

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
    ofPoint p(x,y);
    
    map<int, Drawing*>::iterator it = drawings.find(0);
    Drawing * d = it->second;
    d->addPoint(p);
    server.send( "{\"id\":-1,\"point\":{\"x\":\""+ ofToString(x)+"\",\"y\":\""+ofToString(y)+"\"}," + d->getColorJSON() +"}");
}
开发者ID:PTS93,项目名称:ofxLibwebsockets,代码行数:9,代码来源:ofApp.cpp

示例3: mousePressed

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

    ofPoint p(x,y);
    map<int, Drawing*>::iterator it = drawings.find(id);
    if ( it == drawings.end() ) return;
    Drawing * d = it->second;
    d->addPoint(p);
    client.send( "{\"id\":"+ ofToString(id) + ",\"point\":{\"x\":\""+ ofToString(x)+"\",\"y\":\""+ofToString(y)+"\"}," + d->getColorJSON() +"}");
}
开发者ID:PTS93,项目名称:ofxLibwebsockets,代码行数:10,代码来源:ofApp.cpp

示例4: onMessage

//--------------------------------------------------------------
void ofApp::onMessage( ofxLibwebsockets::Event& args ){
  try{
    cout<<"got message "<<args.message<<endl;
    // trace out string messages or JSON messages!
    if ( !args.json.isNull() ){
        if (!args.json["setup"].isNull()){
            Drawing * d = new Drawing();
            d->_id = args.json["setup"]["id"].asInt();
            // for some reason these come across as strings via JSON.stringify!
            int r = ofToInt(args.json["setup"]["color"]["r"].asString());
            int g = ofToInt(args.json["setup"]["color"]["g"].asString());
            int b = ofToInt(args.json["setup"]["color"]["b"].asString());
            d->color.set(r, g, b);
            drawings.insert( make_pair( d->_id, d ));
            id = d->_id;
            color.set(r, g, b);
            cout << "setup with id:" << id << endl;
        }
        else if (args.json["id"].asInt() != id){
          cout << "received point" << endl;
            ofPoint point = ofPoint( args.json["point"]["x"].asFloat(), args.json["point"]["y"].asFloat() );
            
            // for some reason these come across as strings via JSON.stringify!
            int r = ofToInt(args.json["color"]["r"].asString());
            int g = ofToInt(args.json["color"]["g"].asString());
            int b = ofToInt(args.json["color"]["b"].asString());
            ofColor color = ofColor( r, g, b );
            
            int _id = args.json["id"].asInt();
            
            map<int, Drawing*>::const_iterator it = drawings.find(_id);
            Drawing * d;
            if (it!=drawings.end()){
                d = it->second;
            }
            else {
              d = new Drawing();
              d->_id = _id;
              // for some reason these come across as strings via JSON.stringify!
              int r = ofToInt(args.json["color"]["r"].asString());
              int g = ofToInt(args.json["color"]["g"].asString());
              int b = ofToInt(args.json["color"]["b"].asString());
              d->color.set(r, g, b);
              drawings.insert( make_pair( d->_id, d ));
              cout << "new drawing with id:" << _id << endl;
            }

            d->addPoint(point);
        }
    } else {
    }
  }
  catch(exception& e){
    ofLogError() << e.what();
  }
}
开发者ID:PTS93,项目名称:ofxLibwebsockets,代码行数:57,代码来源:ofApp.cpp


注:本文中的Drawing::addPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。