X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdesigner%2Fselectionwrap.cpp;h=53750758c7b14b54cf072c64bd237e631ab26b45;hb=d84f187ca34a6ab2f8c37d85fa13d5c113714344;hp=fcc4df6b2a7fc561915a22e008782be322773b27;hpb=bde934f7d5ba07a9442a305192e10024820d13ed;p=r2c2.git diff --git a/source/designer/selectionwrap.cpp b/source/designer/selectionwrap.cpp index fcc4df6..5375075 100644 --- a/source/designer/selectionwrap.cpp +++ b/source/designer/selectionwrap.cpp @@ -18,6 +18,8 @@ SelectionWrap::~SelectionWrap() { for(map::iterator i=meshes.begin(); i!=meshes.end(); ++i) delete i->second; + for(map::iterator i=transient_meshes.begin(); i!=transient_meshes.end(); ++i) + delete i->second; } void SelectionWrap::render(GL::Renderer &renderer, const GL::Tag &) const @@ -26,7 +28,7 @@ void SelectionWrap::render(GL::Renderer &renderer, const GL::Tag &) const { GL::MatrixStack::Push push(renderer.matrix_stack()); const Vector &pos = i->object->get_position(); - renderer.matrix_stack() *= GL::Matrix::translation(pos); + renderer.matrix_stack() *= GL::Matrix::translation(pos+GL::Vector3(0, 0, 0.001)); renderer.matrix_stack() *= GL::Matrix::rotation(i->object->get_rotation(), 0, 0, 1); i->mesh->draw(renderer); } @@ -40,13 +42,30 @@ void SelectionWrap::selection_changed() { Wrap wrap; wrap.object = *i; - wrap.mesh = &get_mesh((*i)->get_type()); + wrap.mesh = &get_mesh(**i); wraps.push_back(wrap); } + + set cobjects(objects.begin(), objects.end()); + for(map::iterator i=transient_meshes.begin(); i!=transient_meshes.end(); ) + { + if(!cobjects.count(i->first)) + { + delete i->second; + transient_meshes.erase(i++); + } + else + ++i; + } } -GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type) +const GL::Mesh &SelectionWrap::get_mesh(const Object &obj) { + map::iterator i = transient_meshes.find(&obj); + if(i!=transient_meshes.end()) + return *i->second; + + const ObjectType &type = obj.get_type(); map::iterator j = meshes.find(&type); if(j!=meshes.end()) return *j->second; @@ -55,7 +74,7 @@ GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type) GL::MeshBuilder bld(*mesh); bld.color(0.0f, 1.0f, 0.0f, 1.0f); - const Shape *shape = type.get_shape(); + const Shape *shape = obj.get_shape(); if(!shape) throw logic_error("No shape"); @@ -70,7 +89,10 @@ GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type) bld.vertex(min_pt.x-0.005, max_pt.y+0.005); bld.end(); - meshes[&type] = mesh; + if(shape!=type.get_shape()) + transient_meshes[&obj] = mesh; + else + meshes[&type] = mesh; return *mesh; }