Control* NarrowTool::CreateViewEntry (Selection* s, Editor* ed) { Control* ctrl = nil; Iterator i; if (s->Number() >= 1) { H_PopupMenu* popup = new H_PopupMenu; ctrl = popup; s->First(i); GraphicComp* kid = s->GetView(i)->GetGraphicComp(); RecurPopupInclude(ed, popup, kid); popup->LockPosition(); for (;!s->Done(i); s->Next(i)) { GraphicView* gv = s->GetView(i); GraphicComp* parent = gv->GetGraphicComp(); if (parent->IsA(SCENE_COMP) || parent->IsA(IGRAPHIC_COMPS)){ GraphicComp* mykid = nil; Iterator j(i); s->Next(j); if (!s->Done(j)) { mykid = (GraphicComp*) s->GetView(j)->GetGraphicComp(); } NavigateCmd* cmd = new NavigateCmd(ed, false, parent, mykid); popup->Include(new CommandItem(GetName(parent), Center, cmd)); } } } return ctrl; }
Manipulator* ScaleTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; GraphicView* gv; Manipulator* m = nil; Iterator i; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (newSel->IsEmpty()) { s->Clear(); } else { newSel->First(i); gv = newSel->GetView(i); if (s->Includes(gv)) { s->Remove(gv); s->Prepend(gv); } else { s->Clear(); s->Append(gv); s->Update(); } m = gv->CreateManipulator(v, e, rel, this); } delete newSel; return m; }
void Viewer::Update () { Selection* s = GetSelection(); GraphicView* view = GetGraphicView(); Component* viewComp = view->GetGraphicComp(); Component* edComp = _editor->GetComponent(); if (viewComp != edComp) { ComponentView* newView = edComp->Create(ViewCategory()); if (newView->IsA(GRAPHIC_VIEW)) { edComp->Attach(newView); newView->Update(); SetGraphicView((GraphicView*) newView); } else { delete newView; } } else { s->Hide(this); _viewerView->Update(); GraphicBlock::UpdatePerspective(); _damage->Repair(); s->Show(this); } }
Manipulator* AttributeTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { Manipulator* m = nil; GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (e.shift) { Localize(s, v); } else { s->Clear(); } if (newSel->IsEmpty()) { // do nothing } else { // else user selected object directly s->Exclusive(newSel); } delete newSel; if (s->Number() == 1) { Iterator i; s->First(i); GraphicView* view = s->GetView(i); if (view->IsA(OVERLAY_VIEW)) { ((OverlayEditor*)v->GetEditor())->MouseDocObservable()->textvalue(""); ((OverlayEditor*)v->GetEditor())->AttrEdit(((OverlayView*)view)->GetOverlayComp()); ((OverlayEditor*)v->GetEditor())->MouseDocObservable()->textvalue(OverlayKit::mouse_attr); } } return m; }
Manipulator* LinkView::CreateLinkCompManip ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); RubberGroup* rg = new RubberGroup(nil, nil); float x, y, tx, ty; Coord cx = 0, rad = PIN_RAD, dum1 = 0, dum2 = 0; ConnectorView* target = views->ConnectorIntersecting( e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP ); s->Clear(); if (target != nil) { target->GetConnector()->GetCenter(x, y); rel->Transform(x, y, tx, ty); e.x = Math::round(tx); e.y = Math::round(ty); } if (rel != nil) { rel->Transform(cx, dum1); rel->Transform(rad, dum2); rad = abs(rad - cx); } rg->Append( new RubberLine(nil, nil, e.x, e.y, e.x, e.y), new FixedPin(nil, nil, e.x, e.y, rad), new SlidingPin(nil, nil, e.x, e.y, rad, e.x, e.y) ); return new ConnectManip(v, rg, rel, tool); }
boolean ConnectManip::Manipulating (Event& e) { GraphicView* views = GetViewer()->GetGraphicView(); Rubberband* r = GetRubberband(); float cx, cy; if (r == nil) { return false; } if (e.eventType == MotionEvent) { _target = views->ConnectorIntersecting( e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP ); if (_target == nil) { r->Track(e.x, e.y); } else { _target->GetGraphic()->GetCenter(cx, cy); r->Track(Math::round(cx), Math::round(cy)); } } else if (e.eventType == UpEvent) { r->Erase(); return false; } return true; }
Manipulator* ExamineTool::CreateManipulator ( Viewer* v, Event& e, Transformer* t ){ GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); _selPath = new Selection; Manipulator* m = nil; s->Clear(); ComputeViewPath(e, views, _selPath); _shift = e.shift_is_down(); if (!_selPath->IsEmpty()) { Iterator i; _selPath->First(i); GraphicView* gv = _selPath->GetView(i); s->Append(gv); s->Update(); _selPath->Last(i); gv = _selPath->GetView(i); m = gv->CreateManipulator(v, e, t, this); } delete _selPath; return m; }
Manipulator* TabTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { Iterator i; Selection* s = v->GetSelection(); s->First(i); GraphicView* gv = s->GetView(i); return gv->CreateManipulator(v, e, rel, this); }
void Selection::Hide (Viewer* viewer) { Iterator i; for (First(i); !Done(i); Next(i)) { GraphicView* view = GetView(i); if (viewer == nil || view->GetViewer() == viewer) { view->EraseHandles(); } } }
void OverlaysComp::SelectViewsOf (OverlayComp* comp, Editor* ed) { Selection* s = ed->GetSelection(); s->Clear(); Viewer* viewer; for (int i = 0; (viewer = ed->GetViewer(i)) != nil; ++i) { GraphicView* views = viewer->GetGraphicView(); GraphicView* view = views->GetGraphicView(comp); if (view != nil) s->Append(view); } }
void Selection::Clear (Viewer* viewer) { Iterator i; First(i); while (!Done(i)) { GraphicView* view = GetView(i); if (viewer == nil || view->GetViewer() == viewer) { view->EraseHandles(); } Remove(i); } }
void SelectTool::Localize (Selection* s, Viewer* v) { Iterator i; for (s->First(i); !s->Done(i);) { GraphicView* view = s->GetView(i); if (view->GetViewer() != v) { s->Remove(i); view->EraseHandles(); } else { s->Next(i); } } }
void ViewerGraphic::Update () { GraphicComp* parent = (GraphicComp*) _view->GetGraphicComp()->GetParent(); if (parent != nil) { FullGraphic gs; totalGSGraphic(parent->GetGraphic(), gs); if (Different(this, &gs)) { Damage* damage = _view->GetViewer()->GetDamage(); damage->Incur(this); *(Graphic*)this = *(Graphic*)(&gs); damage->Incur(this); } } }
void OverlaysComp::SelectClipboard (Clipboard* cb, Editor* ed) { Selection* s = ed->GetSelection(); s->Clear(); Viewer* viewer; Iterator i; for (int j = 0; (viewer = ed->GetViewer(j)) != nil; ++j) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicView* views = viewer->GetGraphicView(); GraphicView* view = views->GetGraphicView(cb->GetComp(i)); if (view != nil) s->Append(view); } } ((OverlaySelection*)s)->Reserve(); }
Command* SelectTool::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Viewer* viewer = dm->GetViewer(); GraphicView* views = viewer->GetGraphicView(); Selection* s = viewer->GetSelection(); RubberRect* rr = (RubberRect*) dm->GetRubberband(); Selection* newSel; Coord l, b, r, t; rr->GetCurrent(l, b, r, t); newSel = views->ViewsWithin(l, b, r, t); s->Exclusive(newSel); delete newSel; return nil; }
void Selection::Exclusive (Selection* s) { Iterator i; GraphicView* gv; for (s->First(i); !s->Done(i); s->Next(i)) { gv = GetView(i); if (Includes(gv)) { Remove(gv); gv->EraseHandles(); } else { Append(gv); } } Update(); }
TEST_FIXTURE(InteractorTestFixture, TaskSelection_MouseRightMove) { MyDoorway platform; LibraryScope libraryScope(cout, &platform); libraryScope.set_default_fonts_path(TESTLIB_FONTS_PATH); SpDocument spDoc( new Document(libraryScope) ); spDoc->create_empty(); GraphicView* pView = Injector::inject_SimpleView(libraryScope, spDoc.get()); SpInteractor pIntor(Injector::inject_Interactor(libraryScope, WpDocument(spDoc), pView, NULL)); pView->set_interactor(pIntor.get()); MyTaskSelection task(pIntor.get()); task.init_task(); task.process_event( Event(Event::k_mouse_right_down, 10, 33, k_mouse_right) ); task.process_event( Event(Event::k_mouse_move, 11, 35, k_mouse_right) ); CHECK( task.is_waiting_for_point_2_right() == true ); }
TEST_FIXTURE(InteractorTestFixture, TaskSelection_Creation) { MyDoorway platform; LibraryScope libraryScope(cout, &platform); libraryScope.set_default_fonts_path(TESTLIB_FONTS_PATH); SpDocument spDoc( new Document(libraryScope) ); spDoc->create_empty(); GraphicView* pView = Injector::inject_SimpleView(libraryScope, spDoc.get()); SpInteractor pIntor(Injector::inject_Interactor(libraryScope, WpDocument(spDoc), pView, NULL)); pView->set_interactor(pIntor.get()); MyTaskSelection task(pIntor.get()); task.init_task(); CHECK( task.is_waiting_for_first_point() == true ); CHECK( task.first_point_x() == 0 ); CHECK( task.first_point_y() == 0 ); }
Manipulator* ConnectTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); Manipulator* m = nil; _source = views->ConnectorIntersecting( e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP ); if (_source == nil) { s->Clear(); } else { m = _source->CreateManipulator(v, e, rel, this); } return m; }
Command* MoveTool::InterpretManipulator (Manipulator* m) { Selection* s; Command* cmd = nil; Iterator i; GraphicView* gv; if (m != nil) { s = m->GetViewer()->GetSelection(); s->First(i); gv = s->GetView(i); if (s->Number() > 1) { cmd = gv->GraphicView::InterpretManipulator(m); } else { cmd = gv->InterpretManipulator(m); } } return cmd; }
Command* LinkView::InterpLinkCompManip (Manipulator* m) { Viewer* v = m->GetViewer(); Editor* ed = v->GetEditor(); GraphicView* views = v->GetGraphicView(); BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); ConnectManip* cm = (ConnectManip*) m; Transformer* rel = cm->GetTransformer(); RubberGroup* rg = (RubberGroup*) cm->GetRubberband(); RubberLine* rl = (RubberLine*) rg->First(); Coord x0, y0, x1, y1; Connector* c1, *c2; ConnectorView* target1, *target2; MacroCmd* macro = new MacroCmd(ed); rl->GetCurrent(x0, y0, x1, y1); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); Line* line = new Line(x0, y0, x1, y1, pg); if (brVar != nil) line->SetBrush(brVar->GetBrush()); line->SetTransformer(rel); Unref(rel); LinkComp* linkComp = NewSubject(line); linkComp->GetConnectors(c1, c2); macro->Append(new PasteCmd(ed, new Clipboard(linkComp))); target1 = views->ConnectorIntersecting(x0-SLOP, y0-SLOP, x0+SLOP, y0+SLOP); target2 = views->ConnectorIntersecting(x1-SLOP, y1-SLOP, x1+SLOP, y1+SLOP); if (target1 != nil) { macro->Append(new ConnectCmd(ed, c1, target1->GetConnector())); } if (target2 != nil) { macro->Append(new ConnectCmd(ed, c2, target2->GetConnector())); } return macro; }
Manipulator* SelectTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { Manipulator* m = nil; GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (e.shift) { Localize(s, v); } else { s->Clear(); } if (newSel->IsEmpty()) { // select w/RubberRect if nothing hit m = new DragManip(v, new RubberRect(nil,nil, e.x,e.y,e.x,e.y), rel); } else { // else user selected object directly s->Exclusive(newSel); } delete newSel; return m; }
TEST_FIXTURE(InteractorTestFixture, TaskSelection_MouseRightUp) { MyDoorway platform; LibraryScope libraryScope(cout, &platform); libraryScope.set_default_fonts_path(TESTLIB_FONTS_PATH); SpDocument spDoc( new Document(libraryScope) ); spDoc->create_empty(); GraphicView* pView = Injector::inject_SimpleView(libraryScope, spDoc.get()); MyInteractor* pIntor = LOMSE_NEW MyInteractor(libraryScope, WpDocument(spDoc), pView); SpInteractor sp(pIntor); pView->set_interactor(pIntor); MyTaskSelection task(pIntor); task.init_task(); task.process_event( Event(Event::k_mouse_right_down, 10, 33, k_mouse_right) ); task.process_event( Event(Event::k_mouse_move, 11, 35, k_mouse_right) ); CHECK( pIntor->select_object_invoked() == false ); task.process_event( Event(Event::k_mouse_right_up, 12, 34, k_mouse_right) ); CHECK( task.is_waiting_for_first_point() == true ); CHECK( pIntor->select_object_invoked() == true ); CHECK( pIntor->sel_point_is(10, 33) == true ); }
Control* ExamineTool::CreateInfoEntry (Selection* s, Editor* ed) { Control* ctrl = nil; Iterator i; if (s->Number() > 1) { Menu* m = new H_PullrightMenu(new Message("Info...", Center, 2, hfil)); ctrl = m; for (s->First(i); !s->Done(i); s->Next(i)) { GraphicView* view = (GraphicView*) s->GetView(i); GraphicComp* comp = view->GetGraphicComp(); InfoCmd* cmd = new InfoCmd(ed, view); m->Include( new CommandItem(GetName(comp, _shift, true), Center, cmd) ); } } else { s->First(i); GraphicView* view = (GraphicView*) s->GetView(i); ctrl = new CommandItem("Info...", Center, new InfoCmd(ed, view)); } return ctrl; }
void FrameKit::InitViewer () { Catalog* catalog = unidraw->GetCatalog(); const char* page_w = catalog->GetAttribute(page_width_attrib); const char* page_h = catalog->GetAttribute(page_height_attrib); const char* page_cols = catalog->GetAttribute(page_cols_attrib); const char* page_rows = catalog->GetAttribute(page_rows_attrib); const char* x_incr = catalog->GetAttribute(grid_x_incr); const char* y_incr = catalog->GetAttribute(grid_y_incr); GraphicView* view = (GraphicView*)((FrameEditor*)_ed)->_comp->Create(COMPONENT_VIEW); ((FrameEditor*)_ed)->_comp->Attach(view); view->Update(); Style* style = Session::instance()->style(); boolean bookgeom = style->value_is_on("bookgeom"); float w = bookgeom ? 700 : Math::round(atof(page_w) * ivinches); float h = bookgeom ? 906 : Math::round(atof(page_h) * ivinches); if (page_cols && page_rows) { int ncols = atoi(page_cols); int nrows = atoi(page_rows); if (ncols>0 && nrows>0) { w = ncols; h = nrows; } } OverlayPage* page = new OverlayPage(w, h); Grid* grid = new Grid(w, h, atof(x_incr), atof(y_incr)); grid->Visibility(false); if (!bookgeom) ((FrameEditor*)_ed)->_viewer = new FrameViewer(_ed, view, page, grid); else ((FrameEditor*)_ed)->_viewer = new FrameViewer(_ed, view, page, grid, (int) h+1, (int) w+1, Rotated); }
void SelectFunc::execute() { static int all_symid = symbol_add("all"); ComValue all_flagv(stack_key(all_symid)); boolean all_flag = all_flagv.is_true(); static int clear_symid = symbol_add("clear"); ComValue clear_flagv(stack_key(clear_symid)); boolean clear_flag = clear_flagv.is_true(); Selection* sel = _ed->GetViewer()->GetSelection(); if (clear_flag) { sel->Clear(); unidraw->Update(); reset_stack(); return; } OverlaySelection* newSel = ((OverlayEditor*)_ed)->overlay_kit()->MakeSelection(); Viewer* viewer = _ed->GetViewer(); AttributeValueList* avl = new AttributeValueList(); if (all_flag) { GraphicView* gv = ((OverlayEditor*)_ed)->GetFrame(); Iterator i; int count=0; for (gv->First(i); !gv->Done(i); gv->Next(i)) { GraphicView* subgv = gv->GetView(i); newSel->Append(subgv); OverlayComp* comp = (OverlayComp*)subgv->GetGraphicComp(); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } else if (nargs()==0) { Iterator i; int count=0; for (sel->First(i); !sel->Done(i); sel->Next(i)) { GraphicView* grview = sel->GetView(i); OverlayComp* comp = grview ? (OverlayComp*)grview->GetSubject() : nil; ComValue* compval = comp ? new ComValue(new OverlayViewRef(comp), comp->classid()) : nil; if (compval) { avl->Append(compval); } delete newSel; newSel = nil; } } else { for (int i=0; i<nargsfixed(); i++) { ComValue& obj = stack_arg(i); if (obj.object_compview()) { ComponentView* comview = (ComponentView*)obj.obj_val(); OverlayComp* comp = (OverlayComp*)comview->GetSubject(); if (comp) { GraphicView* view = comp->FindView(viewer); if (view) { newSel->Append(view); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } } else if (obj.is_array()) { Iterator it; AttributeValueList* al = obj.array_val(); al->First(it); while (!al->Done(it)) { if (al->GetAttrVal(it)->object_compview()) { ComponentView* comview = (ComponentView*)al->GetAttrVal(it)->obj_val(); OverlayComp* comp = (OverlayComp*)comview->GetSubject(); if (comp) { GraphicView* view = comp->FindView(viewer); if (view) { newSel->Append(view); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } } al->Next(it); } } } } if (newSel){ sel->Clear(); delete sel; _ed->SetSelection(newSel); newSel->Update(viewer); unidraw->Update(); } reset_stack(); ComValue retval(avl); push_stack(retval); }