/** * @param from point from which the line begins * @param to point at which the line ends * @param brush brush to draw the line with */ void Preview::preview(const dpcore::Point& from, const dpcore::Point& to, const dpcore::Brush& brush) { brush_ = brush; from_ = from; to_ = to; const int rad = brush.radius(to.pressure()); QColor color = brush.color(to.pressure()); QPen pen; if(rad==0) { pen.setWidth(1); color.setAlphaF(brush.opacity(to.pressure())); } else { pen.setWidth(rad*2); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); // Approximate brush transparency const qreal a = brush.opacity(to.pressure()) * rad * (1-brush.spacing()/100.0); color.setAlphaF(qMin(a, 1.0)); } pen.setColor(color); initAppearance(pen); }
/** * @param brush brush info to send */ void SessionState::sendToolSelect(const dpcore::Brush& brush) { host_->sendPacket( protocol::ToolSelect( host_->localuser_, brush.subpixel()?SUBPIXEL:0, brush.blendingMode(), encodeColor(brush.color(1), brush.opacity(1)), encodeColor(brush.color(0), brush.opacity(0)), brush.radius(1), brush.radius(0), qRound(brush.hardness(1)*255), qRound(brush.hardness(0)*255), brush.spacing() ) ); }
protocol::MessagePtr brushToToolChange(int userid, int layer, const dpcore::Brush &brush) { uint8_t mode = brush.subpixel() ? protocol::TOOL_MODE_SUBPIXEL : 0; mode |= brush.incremental() ? protocol::TOOL_MODE_INCREMENTAL : 0; return protocol::MessagePtr(new protocol::ToolChange( userid, layer, brush.blendingMode(), mode, brush.spacing(), brush.color(1.0).rgba(), brush.color(0.0).rgba(), brush.hardness(1.0) * 255, brush.hardness(0.0) * 255, brush.radius(1.0), brush.radius(0.0), brush.opacity(1.0) * 255, brush.opacity(0.0) * 255 )); }