Exemplo n.º 1
0
void View::transform(
    Transformer& t, const Allocation& a, const Allocation&
) const {
    scene2view(a);
    const Allotment& ax = a.x_allotment();
    const Allotment& ay = a.y_allotment();
    csize(ax.begin(), ax.span(), ay.begin(), ay.span());
    float sx = ax.span()/XYView::width();
    float sy = ay.span()/XYView::height();
//	if (sx > sy) sx = sy;
    t.translate( -x(), -y());
    t.scale(sx, sx);
    View* v = (View*)this;
    v->x_pick_epsilon_ = pick_epsilon/sx;
    v->y_pick_epsilon_ = pick_epsilon/sx;
    t.translate((ax.begin() + ax.end())/2,(ay.begin() + ay.end())/2);
//printf("\nx origin=%g span=%g alignment=%g begin=%g end=%g\n", ax.origin(), ax.span(), ax.alignment(), ax.begin(), ax.end());
//printf("\ny origin=%g span=%g alignment=%g begin=%g end=%g\n", ay.origin(), ay.span(), ay.alignment(), ay.begin(), ay.end());
    Coord x1,y1;
    t.transform(x() - x_span_/2, y() - y_span_/2, x1, y1);
    if (!Math::equal(ax.begin(), x1, 1) || !Math::equal(ay.begin(), y1, 1)) {
        t.inverse_transform(ax.begin(), ay.begin(), x1, y1);
        v->x_span_ = 2*(x() - x1);
        v->y_span_ = 2*(y() - y1);
        v->size(x1,y1,x1+v->x_span_, y1+v->y_span_);
    }

}
Exemplo n.º 2
0
static void invXform_gs (Coord& tx, Coord& ty, Graphic31* g) {
    Transformer* t = g->transformer();
    if (t != nil) {
        t->inverse_transform(tx, ty);
    }
}
Exemplo n.º 3
0
boolean Graphic31::manipulating (const Event& e, Tool31& tool) {
    if (e.type() == Event::up) {
        return false;
    } else if (e.type() == Event::motion) {
        unsigned int tool_type = tool.tool();
        ToolState& ts = tool.toolstate();

        if (tool_type != Tool31::nop) {
            float pi = 3.14159;
            Graphic31 gs;
            Transformer* tx = ts._gs.transformer();
            
            Coord x, y, lx, ly;
            
            x = ts._last.pointer_x();
            y = ts._last.pointer_y();
            lx = e.pointer_x(); 
            ly = e.pointer_y();
            
            switch(tool_type) {
            case Tool31::select:
                break;
            case Tool31::move:
                {
                    if (tx != nil) {
                        tx->inverse_transform(lx, ly);
                        tx->inverse_transform(x, y);
                    }
                    translate(lx-x, ly-y);
                    ts._last = e;
                }
                break;
            case Tool31::scale:
                {
                    Coord cx, cy;
                    cx = (ts._l + ts._r)/2.0;
                    cy = (ts._b + ts._t)/2.0;
                    
                    scale((lx-cx)/(x-cx), (ly-cy)/(y-cy), cx, cy);
                    ts._last = e;
                } 
                break;
            case Tool31::rotate:
                {
                    Coord cx, cy;
                    cx = (ts._l + ts._r)/2.0;
                    cy = (ts._b + ts._t)/2.0;

                    float ldy = ly-cy; float ldx = lx-cx;
                    float dy = y-cy; float dx = x-cx;

		    float cur = degrees(atan2f(ldy, ldx));
		    float last = degrees(atan2f(dy, dx));
                        
                    rotate(cur-last, cx, cy);
                    ts._last = e;
                }
                break;
            }
        }
    } 
    return true;
}