Exemple #1
0
//! Draw a straight line cross-ways to an existing
//! straight Bcurve to create a rectangle:
bool 
SWEEP_LINE::create_rect(CGESTUREptr& gest)
{

   static bool debug =
      Config::get_var_bool("DEBUG_CREATE_RECT",false) || debug_all;
   err_adv(debug, "SWEEP_LINE::create_rect");

   if (!(gest && gest->is_line())) {
      err_adv(debug, "SWEEP_LINE::create_rect: gesture is not a line");
      return false;
   }

   // central axis must be on-screen
   if (!sweep_origin().in_frustum()) {
      err_adv(debug_all, "SWEEP_LINE::stroke_cb: error: sweep origin off-screen");
      return false;
   }

   if (!from_center(gest)) {
      WORLD::message("Stroke must begin on curve at guideline");
      return false;
   }
   if (!hits_line(gest->end())) {
      WORLD::message("Line must follow axis");
      return false;
   }

   // compute vector along guideline, based on input stroke:
   Wvec v = project_to_guideline(gest->end()) - sweep_origin();

   return create_rect(v);
}
Exemple #2
0
int
CIRCLE_WIDGET::stroke_cb(CGESTUREptr& g, DrawState*&)
{
   err_adv(debug_all, "CIRCLE_WIDGET::stroke_cb()");

   // Activity occurred to extend the deadline for fading away:
   reset_timeout();

   // sanity check
   assert(g);

   if( !g->is_line() )
      return 1;
   _preview.update_length();
   if (PIXEL_list(_preview).dist(g->start()) < PIXEL_DIST_THRESH  ||
       g->start().dist(_center) < PIXEL_DIST_THRESH  ) {
      if ( _circle ) {
         Bcurve *border = Bcurve::lookup(_circle->bfaces().get_boundary().edges());
         if ( border != 0 ) {
            Wplane plane = border->plane();
            _radius = _center.dist(Wpt(plane, Wline(XYpt(g->end()))));
         }
      } else {
         Wplane P = get_draw_plane(g->end());
         if (!P.is_valid())
            return 1;
         _radius = _center.dist(Wpt(P, Wline(XYpt(g->end()))));
      }
      make_preview();
   }

   return 1;
}