123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // Flexlay - A Generic 2D Game Editor
- // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- #include "object_layer.hpp"
- #include "object_move_command.hpp"
- class ObjectMoveCommandImpl : public CommandImpl
- {
- public:
- ObjectMoveCommandImpl() {}
- virtual ~ObjectMoveCommandImpl() {}
- ObjectLayer objmap;
- struct Obj {
- CL_Pointf old_pos;
- CL_Pointf new_pos;
- ObjMapObject obj;
- };
- typedef std::vector<Obj> Objects;
- Objects objects;
- void execute();
- void redo();
- void undo();
- std::string serialize();
- };
- ObjectMoveCommand::ObjectMoveCommand(const ObjectLayer& o)
- : impl(new ObjectMoveCommandImpl())
- {
- impl->objmap = o;
- }
- ObjectMoveCommand::~ObjectMoveCommand()
- {
- }
- void
- ObjectMoveCommandImpl::execute()
- {
- }
- void
- ObjectMoveCommand::add_obj(const ObjMapObject& obj)
- {
- ObjectMoveCommandImpl::Obj o;
- o.obj = obj;
- o.old_pos = obj.get_pos();
- impl->objects.push_back(o);
- }
- void
- ObjectMoveCommand::move_by(const CL_Pointf& delta)
- {
- for(ObjectMoveCommandImpl::Objects::iterator i = impl->objects.begin();
- i != impl->objects.end();
- ++i)
- {
- i->new_pos = i->old_pos + delta;
- i->obj.set_pos(i->new_pos);
- i->obj.sig_move()(i->obj);
- }
- }
- void
- ObjectMoveCommandImpl::redo()
- {
- for(ObjectMoveCommandImpl::Objects::iterator i = objects.begin();
- i != objects.end();
- ++i)
- {
- i->obj.set_pos(i->new_pos);
- }
- }
- void
- ObjectMoveCommandImpl::undo()
- {
- for(ObjectMoveCommandImpl::Objects::iterator i = objects.begin();
- i != objects.end();
- ++i)
- {
- i->obj.set_pos(i->old_pos);
- }
- }
- std::string
- ObjectMoveCommandImpl::serialize()
- {
- return "";
- }
- Command
- ObjectMoveCommand::to_command()
- {
- return Command(impl);
- }
- /* EOF */
|