本文整理汇总了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();
}
}
示例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() +"}");
}
示例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() +"}");
}
示例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();
}
}