コード例 #1
0
ファイル: pathfind.cpp プロジェクト: Aninimouse/Cataclysm2
Path Pathfinder::get_path(Path_type type, Tripoint start, Tripoint end)
{
  switch (type) {
    case PATH_NULL:
    case PATH_LINE:
      return path_line(start, end);
    case PATH_A_STAR:
      return path_a_star(start, end);
    default:
      return path_line(start, end);
  }
  return path_line(start, end);
}
コード例 #2
0
  void TOPPASEdge::paint(QPainter * painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
  {
    painter->setBrush(Qt::white);

    QPen pen(color_);
    if (isSelected())
    {
      pen.setWidth(3);
    }
    else
    {
      pen.setWidth(2);
    }

    TOPPASToolVertex* ttv_source = qobject_cast<TOPPASToolVertex*>(this->getSourceVertex());
    // when copying parameters (using CTRL); only for incomplete edges drawn from tool nodes
    if (QApplication::keyboardModifiers() && Qt::ControlModifier && !this->to_ && ttv_source)
    {
      pen.setColor(Qt::darkMagenta);
      pen.setWidth(1);
    }

    painter->setPen(pen);

    // angle of line
    qreal angle = -QLineF(endPos(), startPos()).angle() + 180; // negate since angle() reports counter-clockwise; +180 since painter.rotate() is more intuivite then

    // draw the actual line
    QPainterPath path_line(startPos());
    path_line.lineTo(endPos());
    painter->drawPath(path_line);

    // print names
    qreal text_angle = angle;
    bool invert_text_direction = endPos().x() < startPos().x();
    if (invert_text_direction)
    {
      text_angle += 180;
    }
    QPainterPath path_line_short(borderPoint_(false));
    path_line_short.lineTo(endPos());

    // y offset for printing text; we add -1 to make "_" in param names visible (e.g. in "out_annotation")
    //                             otherwise they are too close to the edge itself
    int y_text = -pen.width() - 1;

    // source name
    QString str = getSourceOutParamName();
    if (!str.isEmpty())
    {
      painter->save();     // hard to avoid multiple calls to save() and restore() since we first translate and then rotate
      QPointF point = path_line_short.pointAtPercent(0.05);
      painter->translate(point);
      painter->rotate(text_angle);
      if (invert_text_direction)
      {
        QFontMetrics fm(painter->fontMetrics());
        int text_width=fm.width(str);
        painter->drawText(QPoint(-text_width, y_text), str);
      }
      else
      {
        painter->drawText(QPoint(0, y_text), str);
      }
      painter->restore();
    }
    // target name
    const qreal arrow_width = 10; // required multiple times, so defined here to avoid inconsistencies
    str = getTargetInParamName();
    if (!str.isEmpty())
    {
      painter->save();
      // qreal pc = path_line_short.percentAtLength(10);
      QPointF point = path_line_short.pointAtPercent(0.95);
      painter->translate(point);
      painter->rotate(text_angle);
      QFontMetrics fm(painter->fontMetrics());
      int text_width = fm.width(str);
      int text_height = fm.height();   // shift text below the edge by its own height
      if (invert_text_direction)
      {
        painter->drawText(QPoint(arrow_width, text_height + y_text), str);
      }
      else
      {
        painter->drawText(QPoint(-text_width - arrow_width, text_height + y_text), str);
      }
      painter->restore();
    }

    // draw arrow head
    painter->save();
    painter->translate(endPos());
    painter->rotate(angle);
    QPainterPath path;
    path.moveTo(QPointF(0, 0));
    path.lineTo(QPointF(-arrow_width, 4));
    path.lineTo(QPointF(-arrow_width, -4));
    path.closeSubpath();
    painter->drawPath(path);
    painter->restore();
  }