Пример #1
0
    GraphObjectChange *Ellipse::moveHandle(Handle *handle,
                                           Point *to,
                                           HandleMoveReason reason)
    {
        Element *elem = this;
        Point nw_to;
        Point se_to;

        if (handle == NULL)
            return NULL;
        if (to == NULL)
            return NULL;

        if (handle->id() >= 8 && handle->id() != HANDLE_CUSTOM1)
            return NULL;

        if (handle->id() == HANDLE_CUSTOM1) {
            Point delta;
            Point corner_to;
            delta.setX( to->x() - (elem->corner().x() + elem->width() / 2) );
            delta.setY( to->y() - (elem->corner().y() + elem->height() / 2) );
            corner_to.setX( elem->corner().x() + delta.x() );
            corner_to.setY( elem->corner().y() + delta.y() );
            return move(&corner_to);
        } else {
            if (m_data->aspectType != FREE_ASPECT){
                double width;
                double height;
                double new_width;
                double new_height;
                double to_width;
                double aspect_width;
                Point center;

                width = elem->width();
                height = elem->height();
                center.setX( elem->corner().x() + width / 2 );
                center.setY( elem->corner().y() + height / 2 );
                switch (handle->id()) {
                      case HANDLE_RESIZE_E:
                      case HANDLE_RESIZE_W:
                          new_width = 2 * fabs(to->x() - center.x());
                          new_height = new_width / width * height;
                          break;
                      case HANDLE_RESIZE_N:
                      case HANDLE_RESIZE_S:
                          new_height = 2 * fabs(to->y() - center.y());
                          new_width = new_height / height * width;
                          break;
                      case HANDLE_RESIZE_NW:
                      case HANDLE_RESIZE_NE:
                      case HANDLE_RESIZE_SW:
                      case HANDLE_RESIZE_SE:
                          to_width = 2 * fabs(to->x() - center.x());
                          aspect_width = 2 * fabs(to->y() - center.y()) / height * width;
                          new_width = to_width < aspect_width ? to_width : aspect_width;
                          new_height = new_width / width * height;
                          break;
                      default:
                          new_width = width;
                          new_height = height;
                          break;
                }

                nw_to.setX( center.x() - new_width / 2 );
                nw_to.setY( center.y() - new_height / 2 );
                se_to.setX( center.x() + new_width / 2 );
                se_to.setY( center.y() + new_height / 2 );

                elem->moveHandle(HANDLE_RESIZE_NW, &nw_to, reason);
                elem->moveHandle(HANDLE_RESIZE_SE, &se_to, reason);
            } else {
                Point center;
                Point opposite_to;
                center.setX( elem->corner().x() + elem->width() / 2 );
                center.setY( elem->corner().y() + elem->height() / 2 );
                opposite_to.setX( center.x() - (to->x() - center.x()) );
                opposite_to.setY( center.y() - (to->y() - center.y()) );

                elem->moveHandle(handle->id(), to, reason);
                elem->moveHandle(HandleId(7 - handle->id()), &opposite_to, reason);
            }

          updateData();
          return NULL;
        }
    }
Пример #2
0
bool ppCond::Check(int token, const std::string &line, int lineno)
{
    std::string line1 = line;
    switch(token)
    {
        case ELSE:
            HandleElse(line1);
            break;
        case ENDIF:
            HandleEndIf(line1);
            break;
        case IF:
            define->replaceDefined(line1);
            define->Process(line1);
            HandleIf(expr.Eval(line1), line1, lineno);
            break;
        case ELIF:
            define->replaceDefined(line1);
            define->Process(line1);
            HandleElif(expr.Eval(line1), line1);
            break;
        case IFDEF:
            HandleDef(line1, false, false, lineno);
            break;
        case IFNDEF:
            HandleDef(line1, false, true, lineno);
            break;
        case ELIFDEF:
            HandleDef(line1, true, false, lineno);
            break;
        case ELIFNDEF:
            HandleDef(line1, true, true, lineno);
            break;
        case IFIDN:
            HandleIdn(line1, false, false, true, lineno);
            break;
        case ELIFIDN:
            HandleIdn(line1, true, false, true, lineno);
            break;
        case IFNIDN:
            HandleIdn(line1, false, true, true, lineno);
            break;
        case ELIFNIDN:
            HandleIdn(line1, true, true, true, lineno);
            break;
        case IFIDNI:
            HandleIdn(line1, false, false, false, lineno);
            break;
        case ELIFIDNI:
            HandleIdn(line1, true, false, false, lineno);
            break;
        case IFNIDNI:
            HandleIdn(line1, false, true, false, lineno);
            break;
        case ELIFNIDNI:
            HandleIdn(line1, true, true, false, lineno);
            break;
        case IFID:
            HandleId(line1, false, false, lineno);
            break;
        case ELIFID:
            HandleId(line1, true, false, lineno);
            break;
        case IFNID:
            HandleId(line1, false, true, lineno);
            break;
        case ELIFNID:
            HandleId(line1, true, true, lineno);
            break;
        case IFNUM:
            HandleNum(line1, false, false, lineno);
            break;
        case ELIFNUM:
            HandleNum(line1, true, false, lineno);
            break;
        case IFNNUM:
            HandleNum(line1, false, true, lineno);
            break;
        case ELIFNNUM:
            HandleNum(line1, true, true, lineno);
            break;
        case IFSTR:
            HandleStr(line1, false, false, lineno);
            break;
        case ELIFSTR:
            HandleStr(line1, true, false, lineno);
            break;
        case IFNSTR:
            HandleStr(line1, false, true, lineno);
            break;
        case ELIFNSTR:
            HandleStr(line1, true, true, lineno);
            break;
        case IFCTX:
            HandleCtx(line1, false, false, lineno);
            break;
        case ELIFCTX:
            HandleCtx(line1, true, false, lineno);
            break;
        case IFNCTX:
            HandleCtx(line1, false, true, lineno);
            break;
        case ELIFNCTX:
            HandleCtx(line1, true, true, lineno);
            break;
        default:
            return current && current->skipping;
    }
    return true;
}