Просмотр исходного кода

Deep clone for screen entities, copy/paste in 2d editor

Ivan Safrin 13 лет назад
Родитель
Сommit
391fc8afbf
29 измененных файлов с 507 добавлено и 20 удалено
  1. 14 0
      Core/Contents/Include/PolyEntity.h
  2. 3 0
      Core/Contents/Include/PolyParticleEmitter.h
  3. 4 2
      Core/Contents/Include/PolyScreenEntity.h
  4. 11 4
      Core/Contents/Include/PolyScreenEntityInstance.h
  5. 4 0
      Core/Contents/Include/PolyScreenImage.h
  6. 3 0
      Core/Contents/Include/PolyScreenLabel.h
  7. 4 1
      Core/Contents/Include/PolyScreenShape.h
  8. 4 0
      Core/Contents/Include/PolyScreenSound.h
  9. 3 0
      Core/Contents/Include/PolyScreenSprite.h
  10. 48 0
      Core/Contents/Source/PolyEntity.cpp
  11. 43 0
      Core/Contents/Source/PolyParticleEmitter.cpp
  12. 21 0
      Core/Contents/Source/PolyScreenEntity.cpp
  13. 30 1
      Core/Contents/Source/PolyScreenEntityInstance.cpp
  14. 10 0
      Core/Contents/Source/PolyScreenImage.cpp
  15. 12 0
      Core/Contents/Source/PolyScreenLabel.cpp
  16. 13 0
      Core/Contents/Source/PolyScreenShape.cpp
  17. 9 0
      Core/Contents/Source/PolyScreenSound.cpp
  18. 17 0
      Core/Contents/Source/PolyScreenSprite.cpp
  19. 1 1
      IDE/Build/Linux/Makefile
  20. 50 0
      IDE/Contents/Include/PolycodeClipboard.h
  21. 11 2
      IDE/Contents/Include/PolycodeEditor.h
  22. 1 0
      IDE/Contents/Include/PolycodeIDEApp.h
  23. 19 2
      IDE/Contents/Include/PolycodeScreenEditor.h
  24. 51 0
      IDE/Contents/Source/PolycodeClipboard.cpp
  25. 31 1
      IDE/Contents/Source/PolycodeEditor.cpp
  26. 6 1
      IDE/Contents/Source/PolycodeIDEApp.cpp
  27. 80 1
      IDE/Contents/Source/PolycodeScreenEditor.cpp
  28. 2 2
      Modules/Contents/UI/Include/PolyUITree.h
  29. 2 2
      Modules/Contents/UI/Source/PolyUITree.cpp

+ 14 - 0
Core/Contents/Include/PolyEntity.h

@@ -79,6 +79,20 @@ namespace Polycode {
 
 			void renderChildren();					
 		
+			
+			/**
+ 			* Clones the entity, return an exact copy. This method must be implemented in an Entity subclass for you to be able to clone it.
+ 			* @param deepClone If true, perform a deep clone, cloning all the children.
+ 			* @param ignoreEditorOnly If true, ignore all child entities where editorOnly is set to true (will still clone the entity you call Clone() on even if its editorOnly flag is set to true.
+ 			* @return The clone of the entity.
+ 			*/
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+
+			/**
+ 			* This method must be implemented by all subvlasses implementing Clone.
+ 			*/
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		
 		
 			// ----------------------------------------------------------------------------------------------------------------
 			/** @name Matrix operations.

+ 3 - 0
Core/Contents/Include/PolyParticleEmitter.h

@@ -326,6 +326,9 @@ namespace Polycode {
 		ScreenParticleEmitter(const String& imageFile, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, ScreenMesh *emitter = NULL);
 		virtual ~ScreenParticleEmitter();		
 		
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		
 		/**
 		* Returns the emitter (helper method for LUA).
 		*/ 		

+ 4 - 2
Core/Contents/Include/PolyScreenEntity.h

@@ -51,7 +51,9 @@ class _PolyExport ScreenEntity : public Entity {
 		ScreenEntity();
 		virtual ~ScreenEntity();
 		
-		
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+
 		void addEntity(Entity *newChild);
 		
 		/**
@@ -230,4 +232,4 @@ class _PolyExport ScreenEntity : public Entity {
 
 };
 
-}
+}

+ 11 - 4
Core/Contents/Include/PolyScreenEntityInstance.h

@@ -39,8 +39,13 @@ namespace Polycode {
 class ScreenEntityInstance : public ScreenEntity {
 	public:
 		ScreenEntityInstance(const String& fileName);
+		ScreenEntityInstance();
+
 		~ScreenEntityInstance();
-		
+	
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+
 		void parseObjectIntoCurve(ObjectEntry *entry, BezierCurve *curve);
 		void applyScreenShape(ObjectEntry *entry, ScreenShape *shape);
 		ScreenEntity *loadObjectEntryIntoEntity(ObjectEntry *entry);
@@ -50,9 +55,11 @@ class ScreenEntityInstance : public ScreenEntity {
 		
 		String getFileName() const;
 		
-	protected:
-		ScreenEntity *rootEntity;		
+		bool cloneUsingReload;
+
 		String fileName;
+
+		ScreenEntity *rootEntity;		
 };
 
-}
+}

+ 4 - 0
Core/Contents/Include/PolyScreenImage.h

@@ -49,8 +49,12 @@ namespace Polycode {
 		 */		
 		ScreenImage(Texture *texture);		
 		
+
 		virtual ~ScreenImage();
 		
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+
 		/**
 		* Changes which part of the image is displayed.
 		* @param x X position of the display rectangle.

+ 3 - 0
Core/Contents/Include/PolyScreenLabel.h

@@ -45,6 +45,9 @@ namespace Polycode {
 			ScreenLabel(const String& text, int size, const String& fontName = "sans", int amode = 0, bool premultiplyAlpha = false);
 			virtual ~ScreenLabel();		
 		
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+		
 			/**
 			* Adds a drop shadow to the label.
 			* @param color Color of the drop shadow.

+ 4 - 1
Core/Contents/Include/PolyScreenShape.h

@@ -43,7 +43,10 @@ namespace Polycode {
 			* @param option4 Reserved.
 			*/
 			ScreenShape(int shapeType, Number option1=0, Number option2=0, Number option3=0, Number option4=0);
-						
+		
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+				
 			virtual ~ScreenShape();
 			void Render();
 

+ 4 - 0
Core/Contents/Include/PolyScreenSound.h

@@ -46,6 +46,10 @@ namespace Polycode {
 		public:
 			ScreenSound(const String& fileName, Number referenceDistance, Number maxDistance);
 			virtual ~ScreenSound();			
+
+			virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+			virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+
 			void Update();			
 			
 			/**

+ 3 - 0
Core/Contents/Include/PolyScreenSprite.h

@@ -66,6 +66,9 @@ class _PolyExport ScreenSprite : public ScreenShape
 		ScreenSprite(const String& fileName, Number spriteWidth, Number spriteHeight);
 		virtual ~ScreenSprite();
 		
+		virtual Entity *Clone(bool deepClone, bool ignoreEditorOnly);
+		virtual void applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly);
+
 		/**
 		* Adds a new animation to the sprite. Animations are added by specifying a list of frame indexes and then can be played back by the specified name.
 		* @param name Name of the new animation.

+ 48 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -77,6 +77,54 @@ Entity *Entity::getEntityById(String id, bool recursive) {
 	return NULL;
 }
 
+Entity *Entity::Clone(bool deepClone, bool ignoreEditorOnly) {
+	Entity *newEntity = new Entity();
+	applyClone(newEntity, deepClone, ignoreEditorOnly);
+	return newEntity;
+}
+
+void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	clone->ownsChildren = ownsChildren;
+	clone->position = position;
+	clone->rotation = rotation;
+	clone->scale = scale;
+	clone->color = color;
+	clone->custEntityType = custEntityType;
+	clone->billboardMode = billboardMode;	
+	clone->billboardRoll = billboardRoll;
+	clone->alphaTest = alphaTest;
+	clone->backfaceCulled = backfaceCulled;
+	clone->renderWireframe = renderWireframe;
+	clone->depthWrite = depthWrite;
+	clone->depthTest = depthTest;
+	clone->blendingMode = blendingMode;
+	clone->colorAffectsChildren;
+	clone->visibilityAffectsChildren = visibilityAffectsChildren;
+	clone->depthOnly = depthOnly;
+	clone->setUserData(getUserData());
+	clone->entityProps = entityProps;
+	clone->bBox = bBox;
+	clone->ignoreParentMatrix = ignoreParentMatrix;
+	clone->enableScissor = enableScissor;
+	clone->scissorBox = scissorBox;
+	clone->editorOnly = editorOnly;	
+	clone->id = id;
+	for(int i=0; i < tags.size(); i++) {	
+		clone->addTag(tags[i]);
+	}
+	clone->setRenderer(renderer);
+
+	if(deepClone) {
+		for(int i=0; i < children.size(); i++) {
+			if(children[i]->editorOnly && ignoreEditorOnly) {
+			} else {
+				Entity *childClone = children[i]->Clone(deepClone, ignoreEditorOnly);
+				clone->addChild(childClone);
+			}
+		}
+	}
+}
+
 std::vector<Entity*> Entity::getEntitiesByTag(String tag, bool recursive) {
 
 	std::vector<Entity*> retVector;

+ 43 - 0
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -96,6 +96,49 @@ ScreenParticleEmitter::~ScreenParticleEmitter(){
 	}
 }
 
+Entity *ScreenParticleEmitter::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenParticleEmitter *newEmitter = new ScreenParticleEmitter("default.png", Particle::BILLBOARD_PARTICLE, ParticleEmitter::CONTINUOUS_EMITTER, 2.0, 0, Vector3(0.0, -40.0, 0.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0), Vector3(10.0, 10.0, 0.0));
+	applyClone(newEmitter, deepClone, ignoreEditorOnly);
+	return newEmitter;
+}
+
+void ScreenParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenParticleEmitter *_clone = (ScreenParticleEmitter*) clone;
+
+	_clone->emitterRadius = this->emitterRadius;
+	_clone->dirVector = this->dirVector;
+	_clone->gravVector = this->gravVector;
+	_clone->deviation = this->deviation;
+				
+	_clone->brightnessDeviation = this->brightnessDeviation;
+	_clone->particleSize = this->particleSize;
+	_clone->perlinModSize = this->perlinModSize;
+	_clone->perlinEnabled = this->perlinEnabled;
+	_clone->particleSpeedMod = this->particleSpeedMod;
+				
+	_clone->rotationSpeed = this->rotationSpeed;
+	_clone->lifespan = this->lifespan;
+	_clone->particleSpeedMod = this->particleSpeedMod;
+	_clone->setParticleCount(this->getNumParticles());						
+
+	_clone->rotationFollowsPath = this->rotationFollowsPath;
+	_clone->useScaleCurves = this->useScaleCurves;
+	_clone->scaleCurve = this->scaleCurve;
+
+	_clone->useColorCurves = this->useColorCurves;
+				
+	_clone->colorCurveR = this->colorCurveR;
+	_clone->colorCurveG = this->colorCurveG;
+	_clone->colorCurveB = this->colorCurveB;
+	_clone->colorCurveA = this->colorCurveA;																
+	_clone->setParticleBlendingMode(this->getParticleBlendingMode());
+	_clone->setParticleTexture(this->getParticleTexture());
+	_clone->setWidth(_clone->emitterRadius.x);
+	_clone->setHeight(_clone->emitterRadius.y);			
+	
+	ScreenEntity::applyClone(clone, false, ignoreEditorOnly);
+}
+
 void ScreenParticleEmitter::Update() {
 	updateEmitter();
 }

+ 21 - 0
Core/Contents/Source/PolyScreenEntity.cpp

@@ -67,6 +67,27 @@ ScreenEntity::ScreenEntity() : Entity() {
 	
 }
 
+Entity *ScreenEntity::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenEntity *newEntity = new ScreenEntity();
+	applyClone(newEntity, deepClone, ignoreEditorOnly);
+	return newEntity;
+}
+
+void ScreenEntity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	Entity::applyClone(clone, deepClone, ignoreEditorOnly);
+
+	ScreenEntity *_clone = (ScreenEntity*) clone;
+	_clone->width = width;
+	_clone->height = height;
+	_clone->setHitbox(hit.x, hit.y, hit.w, hit.h);
+	_clone->positionMode = positionMode;
+	_clone->focusable = focusable;
+	_clone->blockMouseInput = blockMouseInput;
+	_clone->snapToPixels = snapToPixels;
+	_clone->processInputEvents = processInputEvents;
+	
+}
+
 void ScreenEntity::addEntity(Entity *newChild) {
 	((ScreenEntity*)newChild)->setDefaultScreenOptions(snapToPixels);
 	Entity::addEntity(newChild);

+ 30 - 1
Core/Contents/Source/PolyScreenEntityInstance.cpp

@@ -29,10 +29,39 @@ ScreenEntityInstance::ScreenEntityInstance(const String& fileName) : ScreenEntit
 	rootEntity = NULL;
 	setPositionMode(ScreenEntity::POSITION_CENTER);
 	loadFromFile(fileName);
+	cloneUsingReload = false;
+}
+
+ScreenEntityInstance::ScreenEntityInstance() {
+	rootEntity = NULL;
+	cloneUsingReload = true;
 }
 
 ScreenEntityInstance::~ScreenEntityInstance() {
+}
+
+Entity *ScreenEntityInstance::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenEntityInstance *newEntity;
+	if(cloneUsingReload) {
+		newEntity = new ScreenEntityInstance(fileName);
+	} else {
+		newEntity = new ScreenEntityInstance();
+	}
+	applyClone(newEntity, deepClone, ignoreEditorOnly);
+	return newEntity;
+}
 
+void ScreenEntityInstance::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	if(cloneUsingReload) {
+		ScreenEntity::applyClone(clone, false, ignoreEditorOnly);
+	} else {
+		ScreenEntity::applyClone(clone, deepClone, ignoreEditorOnly);
+		ScreenEntityInstance *_clone = (ScreenEntityInstance*) clone;
+		_clone->fileName = fileName;
+		if(_clone->getNumChildren() > 0) {
+			_clone->rootEntity = (ScreenEntity*)_clone->getChildAtIndex(0);
+		}
+	}
 }
 
 void ScreenEntityInstance::applyScreenShape(ObjectEntry *entry, ScreenShape *shape) {
@@ -302,4 +331,4 @@ bool ScreenEntityInstance::loadFromFile(const String& fileName) {
 		addChild(rootEntity);		
 	}
 	return true;
-}
+}

+ 10 - 0
Core/Contents/Source/PolyScreenImage.cpp

@@ -71,6 +71,16 @@ ScreenImage::~ScreenImage() {
 
 }
 
+Entity *ScreenImage::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenImage *newImage = new ScreenImage(getTexture()->getResourcePath());
+	applyClone(newImage, deepClone, ignoreEditorOnly);
+	return newImage;
+}
+
+void ScreenImage::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
+}
+
 void ScreenImage::setImageCoordinates(Number x, Number y, Number width, Number height) {
 	Vertex *vertex;
 	Number pixelSizeX = 1/imageWidth;

+ 12 - 0
Core/Contents/Source/PolyScreenLabel.cpp

@@ -53,6 +53,18 @@ Label *ScreenLabel::getLabel() const {
 	return label;
 }
 
+Entity *ScreenLabel::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenLabel *newLabel = new ScreenLabel(getText(), label->getSize(), label->getFont()->getFontName(), label->getAntialiasMode());
+	applyClone(newLabel, deepClone, ignoreEditorOnly);
+	return newLabel;
+}
+
+void ScreenLabel::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
+	ScreenLabel *_clone = (ScreenLabel*) clone;
+	_clone->positionAtBaseline = positionAtBaseline;
+}
+
 void ScreenLabel::addDropShadow(Color color, Number size, Number offsetX, Number offsetY) {
 	delete dropShadowImage;
 	Image *labelImage = new Image(label);

+ 13 - 0
Core/Contents/Source/PolyScreenShape.cpp

@@ -71,6 +71,19 @@ void ScreenShape::operator=(const ScreenShape& copy) {
 
 }
 
+Entity *ScreenShape::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenShape *newEntity = new ScreenShape(ScreenShape::SHAPE_RECT, 1,1);
+	applyClone(newEntity, deepClone, ignoreEditorOnly);
+	return newEntity;
+
+}
+
+void ScreenShape::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenEntity::applyClone(clone, deepClone, ignoreEditorOnly);
+	ScreenShape *_clone = (ScreenShape*) clone;
+	*_clone = *this;
+}
+
 void ScreenShape::buildShapeMesh() {
 
 	mesh->clearMesh();

+ 9 - 0
Core/Contents/Source/PolyScreenSound.cpp

@@ -50,6 +50,15 @@ void ScreenSoundListener::Update() {
 
 }
 
+Entity *ScreenSound::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenSound *newSound = new ScreenSound(sound->getFileName(), sound->getReferenceDistance(), sound->getMaxDistance());
+	applyClone(newSound, deepClone, ignoreEditorOnly);
+	return newSound;
+}
+
+void ScreenSound::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenEntity::applyClone(clone, deepClone, ignoreEditorOnly);
+}
 
 ScreenSound::ScreenSound(const String& fileName, Number referenceDistance, Number maxDistance) : ScreenEntity() {
 	sound = new Sound(fileName);

+ 17 - 0
Core/Contents/Source/PolyScreenSprite.cpp

@@ -39,6 +39,23 @@ ScreenSprite::ScreenSprite(const String& fileName) : ScreenShape(ScreenShape::SH
 	loadFromFile(fileName);
 }
 
+Entity *ScreenSprite::Clone(bool deepClone, bool ignoreEditorOnly) {
+	ScreenSprite *newSprite = new ScreenSprite(getTexture()->getResourcePath(), spriteWidth, spriteHeight);
+	for(int i=0; i < animations.size(); i++) {
+		newSprite->addAnimation(animations[i]->name, animations[i]->frames, animations[i]->speed);
+	}
+	if(currentAnimation) {
+		newSprite->playAnimation(currentAnimation->name, currentFrame, playingOnce);
+	}
+	applyClone(newSprite, deepClone, ignoreEditorOnly);
+	return newSprite;
+}
+
+void ScreenSprite::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) {
+	ScreenShape::applyClone(clone, deepClone, ignoreEditorOnly);
+	
+}
+
 bool ScreenSprite::loadFromFile(const String& fileName) {
 	Object loadObject;
 	

+ 1 - 1
IDE/Build/Linux/Makefile

@@ -2,7 +2,7 @@ CC=g++
 CFLAGS=-I../../Contents/Include -I../../../Release/Linux/Framework/Core/Dependencies/include -I../../../Release/Linux/Framework/Core/Dependencies/include/AL -I../../../Release/Linux/Framework/Core/include -I../../../Release/Linux/Framework/Modules/include -I../../../Release/Linux/Framework/Modules/Dependencies/include -I../../../Release/Linux/Framework/Modules/Dependencies/include/bullet -DUSE_POLYCODEUI_FILE_DIALOGS -DUSE_POLYCODEUI_MENUBAR
 LDFLAGS=-lrt -ldl -lpthread ../../../Release/Linux/Framework/Core/lib/libPolycore.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libfreetype.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbisfile.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbis.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibogg.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libopenal.so ../../../Release/Linux/Framework/Core/Dependencies/lib/libphysfs.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libpng15.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libz.a -lGL -lGLU -lSDL ../../../Release/Linux/Framework/Modules/lib/libPolycode2DPhysics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBox2D.a ../../../Release/Linux/Framework/Modules/lib/libPolycode3DPhysics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletDynamics.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletCollision.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libLinearMath.a ../../../Release/Linux/Framework/Modules/lib/libPolycodeUI.a
 LDFLAGS_DEBUG=-lrt -ldl -lpthread ../../../Release/Linux/Framework/Core/lib/libPolycore_d.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libfreetype_d.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbisfiled.a ../../../Release/Linux/Framework/Core/Dependencies/lib/liblibvorbisd.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libliboggd.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libopenal.so ../../../Release/Linux/Framework/Core/Dependencies/lib/libphysfsd.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libpng15d.a ../../../Release/Linux/Framework/Core/Dependencies/lib/libz.a -lGL -lGLU -lSDL ../../../Release/Linux/Framework/Modules/lib/libPolycode2DPhysics_d.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBox2D_d.a ../../../Release/Linux/Framework/Modules/lib/libPolycode3DPhysics_d.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletDynamics_d.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libBulletCollision_d.a ../../../Release/Linux/Framework/Modules/Dependencies/lib/libLinearMath_d.a ../../../Release/Linux/Framework/Modules/lib/libPolycodeUI_d.a
-SRCS=../../Contents/Source/ExampleBrowserWindow.cpp ../../Contents/Source/PolycodeEditorManager.cpp  ../../Contents/Source/PolycodeProject.cpp        ../../Contents/Source/PolycodeScreenEditor.cpp ../../Contents/Source/ExportProjectWindow.cpp  ../../Contents/Source/PolycodeFontEditor.cpp     ../../Contents/Source/PolycodeProjectBrowser.cpp ../../Contents/Source/PolycodeSpriteEditor.cpp ../../Contents/Source/NewFileWindow.cpp        ../../Contents/Source/PolycodeFrame.cpp          ../../Contents/Source/PolycodeProjectEditor.cpp  ../../Contents/Source/PolycodeTextEditor.cpp ../../Contents/Source/NewProjectWindow.cpp     ../../Contents/Source/PolycodeIDEApp.cpp         ../../Contents/Source/PolycodeProjectManager.cpp ../../Contents/Source/PolycodeToolLauncher.cpp ../../Contents/Source/PolycodeConsole.cpp      ../../Contents/Source/PolycodeImageEditor.cpp    ../../Contents/Source/PolycodeProps.cpp          ../../Contents/Source/TextureBrowser.cpp ../../Contents/Source/PolycodeEditor.cpp       ../../Contents/Source/PolycodeMaterialEditor.cpp ../../Contents/Source/PolycodeRemoteDebugger.cpp ../../Contents/Source/ToolWindows.cpp
+SRCS=../../Contents/Source/ExampleBrowserWindow.cpp ../../Contents/Source/PolycodeEditorManager.cpp  ../../Contents/Source/PolycodeProject.cpp        ../../Contents/Source/PolycodeScreenEditor.cpp ../../Contents/Source/ExportProjectWindow.cpp  ../../Contents/Source/PolycodeFontEditor.cpp     ../../Contents/Source/PolycodeProjectBrowser.cpp ../../Contents/Source/PolycodeSpriteEditor.cpp ../../Contents/Source/NewFileWindow.cpp        ../../Contents/Source/PolycodeFrame.cpp          ../../Contents/Source/PolycodeProjectEditor.cpp  ../../Contents/Source/PolycodeTextEditor.cpp ../../Contents/Source/NewProjectWindow.cpp     ../../Contents/Source/PolycodeIDEApp.cpp         ../../Contents/Source/PolycodeProjectManager.cpp ../../Contents/Source/PolycodeToolLauncher.cpp ../../Contents/Source/PolycodeConsole.cpp      ../../Contents/Source/PolycodeImageEditor.cpp    ../../Contents/Source/PolycodeProps.cpp          ../../Contents/Source/TextureBrowser.cpp ../../Contents/Source/PolycodeEditor.cpp       ../../Contents/Source/PolycodeMaterialEditor.cpp ../../Contents/Source/PolycodeRemoteDebugger.cpp ../../Contents/Source/ToolWindows.cpp ../../Contents/Source/PolycodeClipboard.cpp
 
 default:
 	$(CC) $(CFLAGS) -O2 main.cpp $(SRCS) -o ./Build/Polycode $(LDFLAGS)

+ 50 - 0
IDE/Contents/Include/PolycodeClipboard.h

@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#pragma once 
+
+#include <Polycode.h>
+
+using namespace Polycode;
+
+class ClipboardProvider {
+	public:
+		ClipboardProvider(){}
+
+		virtual void destroyClipboardData(void *data, String type) {}
+};
+
+class PolycodeClipboard {
+	public:
+		PolycodeClipboard();
+
+		void setData(void *data, String type, ClipboardProvider *provider);
+		void *getData();
+		String getType();
+
+	protected:
+
+		ClipboardProvider *currentProvider;
+		String type;
+		void *data;
+};
+

+ 11 - 2
IDE/Contents/Include/PolycodeEditor.h

@@ -25,11 +25,12 @@
 #include "Polycode.h"
 #include "OSBasics.h"
 #include "PolycodeProject.h"
+#include "PolycodeClipboard.h"
 
 using namespace Polycode;
 
 
-class PolycodeEditor : public ScreenEntity { 
+class PolycodeEditor : public ScreenEntity, public ClipboardProvider { 
 public:
 	PolycodeEditor(bool _isReadOnly);
 	virtual ~PolycodeEditor();
@@ -37,10 +38,15 @@ public:
 	virtual bool openFile(OSFileEntry filePath){ this->filePath = filePath.fullPath; return true;}
 	virtual void Resize(int x, int y);
 	
+	virtual void handleEvent(Event *event);
+
 	virtual void Activate() {};
 	
 	virtual void saveFile(){};
 	
+	virtual String Copy(void **data) {}
+	virtual void Paste(void *data, String clipboardType) {}
+
 	virtual void handleDroppedFile(OSFileEntry file, Number x, Number y) {};
 	
 	void setFilePath(String newPath);
@@ -53,6 +59,9 @@ public:
 	PolycodeProject *parentProject;
 		
 protected:
+
+	
+
 	String filePath;
 	bool _isReadOnly;
 	
@@ -75,4 +84,4 @@ public:
 protected:
 	std::vector<std::string> extensions;
 	
-};
+};

+ 1 - 0
IDE/Contents/Include/PolycodeIDEApp.h

@@ -45,6 +45,7 @@
 #include "PolycodeToolLauncher.h"
 
 #include "PolycodeRemoteDebugger.h"
+#include "PolycodeClipboard.h"
 
 using namespace Polycode;
 

+ 19 - 2
IDE/Contents/Include/PolycodeScreenEditor.h

@@ -126,7 +126,11 @@ class PolycodeScreenEditorMain : public UIElement {
 		void handleMouseUp(Vector2 position);
 		
 		void setGrid(int gridSize);
-				
+		
+		String Copy(void **data);
+		void Paste(void *data, String clipboardType);
+		void destroyClipboardData(void *data, String type);
+		
 		static const int MODE_SELECT = 0;
 		static const int MODE_SHAPE = 1;
 		static const int MODE_ZOOM = 2;
@@ -165,9 +169,9 @@ class PolycodeScreenEditorMain : public UIElement {
 		
 		ScreenEntity *objectBaseEntity;		
 		ScreenEntity *placingPreviewEntity;												
+		bool multiSelect;
 	protected:
 	
-		bool multiSelect;
 	
 		int gridSize;
 		bool gridSnap;
@@ -186,6 +190,8 @@ class PolycodeScreenEditorMain : public UIElement {
 
 		bool firstResize;
 		
+		bool firstMove;
+
 		int placementCount;
 	
 		
@@ -298,6 +304,13 @@ class PolycodeScreenEditorMain : public UIElement {
 		int mode;	
 };
 
+class ScreenEntityClipboardData {
+	public:
+		ScreenEntityClipboardData(){}
+		
+		std::vector<ScreenEntity*> entities;
+};
+
 class PolycodeScreenEditor : public PolycodeEditor {
 	public:
 		PolycodeScreenEditor();
@@ -306,6 +319,10 @@ class PolycodeScreenEditor : public PolycodeEditor {
 		bool openFile(OSFileEntry filePath);
 		void Resize(int x, int y);
 		
+		String Copy(void **data);
+		void Paste(void *data, String clipboardType);
+		void destroyClipboardData(void *data, String type);
+
 		void Activate();		
 		
 		void saveCurveToObject(ObjectEntry *entry, BezierCurve *curve);

+ 51 - 0
IDE/Contents/Source/PolycodeClipboard.cpp

@@ -0,0 +1,51 @@
+
+/*
+ Copyright (C) 2012 by Ivan Safrin
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ */
+
+#include "PolycodeClipboard.h"
+
+PolycodeClipboard::PolycodeClipboard() {
+	data = NULL;
+}
+
+void PolycodeClipboard::setData(void *data, String type, ClipboardProvider *provider) {
+	if(!data)
+		return;
+
+	if(this->data) {
+		currentProvider->destroyClipboardData(this->data, this->type);
+		this->data = NULL;
+		currentProvider = NULL;
+	}
+	
+	this->data = data;
+	this->type = type;
+	currentProvider = provider;
+}
+
+void *PolycodeClipboard::getData() {
+	return data;
+}
+
+String PolycodeClipboard::getType() {
+	return type;
+}

+ 31 - 1
IDE/Contents/Source/PolycodeEditor.cpp

@@ -22,6 +22,8 @@
 
 #include "PolycodeEditor.h"
 
+extern PolycodeClipboard *globalClipboard;
+
 PolycodeEditorFactory::PolycodeEditorFactory() {
 	
 }
@@ -42,10 +44,38 @@ void PolycodeEditor::setFilePath(String newPath) {
 	filePath = newPath;
 }
 
-PolycodeEditor::PolycodeEditor(bool _isReadOnly) : ScreenEntity() {
+PolycodeEditor::PolycodeEditor(bool _isReadOnly) : ScreenEntity(), ClipboardProvider() {
 	this->_isReadOnly = _isReadOnly;
 	enableScissor = true;	
 	processInputEvents = true;
+
+	Core *core = CoreServices::getInstance()->getCore();
+	
+	core->addEventListener(this, Core::EVENT_COPY);
+	core->addEventListener(this, Core::EVENT_PASTE);
+}
+
+void PolycodeEditor::handleEvent(Event *event) {
+	if(event->getDispatcher() == CoreServices::getInstance()->getCore()) {
+		switch(event->getEventCode()) {
+			case Core::EVENT_COPY:
+			{
+				void *data = NULL;
+				String dataType = Copy(&data);
+				if(data) {
+					globalClipboard->setData(data, dataType, this);
+				}
+			}
+			break;
+			case Core::EVENT_PASTE:
+			{
+				if(globalClipboard->getData()) {
+					Paste(globalClipboard->getData(), globalClipboard->getType());
+				}
+			}
+			break;
+		}
+	}
 }
 
 void PolycodeEditor::Resize(int x, int y) {

+ 6 - 1
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -27,11 +27,14 @@ using namespace Polycode;
 
 UIGlobalMenu *globalMenu;
 SyntaxHighlightTheme *globalSyntaxTheme;
+PolycodeClipboard *globalClipboard;
+
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	
+	globalClipboard = new PolycodeClipboard();
 	
 	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
 				
@@ -446,9 +449,11 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 	if(event->getDispatcher() == core) {
 		switch(event->getEventCode()) {
 			case Core::EVENT_CORE_RESIZE:
-				frame->Resize(core->getXRes(), core->getYRes());
 				if(menuBar) {
+					frame->Resize(core->getXRes(), core->getYRes()-25);
 					menuBar->Resize(core->getXRes(), 25);
+				} else {
+					frame->Resize(core->getXRes(), core->getYRes());
 				}
 			break;
 		}

+ 80 - 1
IDE/Contents/Source/PolycodeScreenEditor.cpp

@@ -257,6 +257,8 @@ void EntityTreeView::Resize(Number width, Number height) {
 
 PolycodeScreenEditorMain::PolycodeScreenEditorMain() {
 
+	firstMove = false;
+
 	multiSelect = false;
 	currentLayer = NULL;
 	treeView = NULL;
@@ -1893,11 +1895,13 @@ void PolycodeScreenEditorMain::handleEvent(Event *event) {
 	if(event->getDispatcher() == baseEntity) {
 		switch (event->getEventCode()) {
 			case InputEvent::EVENT_MOUSEDOWN:
+				firstMove = true;
 				handleMouseDown(inputEvent->mousePosition);
 				focusChild(baseEntity);
 			break;		
 			case InputEvent::EVENT_MOUSEUP:
 			case InputEvent::EVENT_MOUSEUP_OUTSIDE:			
+				firstMove = false;
 				handleMouseUp(inputEvent->mousePosition);
 			break;
 			case InputEvent::EVENT_MOUSEOUT:
@@ -1905,6 +1909,18 @@ void PolycodeScreenEditorMain::handleEvent(Event *event) {
 			break;
 			case InputEvent::EVENT_MOUSEMOVE:
 			{
+				if(firstMove) {
+					Core *core = CoreServices::getInstance()->getCore();
+					if(core->getInput()->getKeyState(KEY_RCTRL) || core->getInput()->getKeyState(KEY_LCTRL)) {
+						void *data;
+						String type = Copy(&data);
+						if(data) {
+							Paste(data, type);
+							destroyClipboardData(data, type);
+						}
+					}
+					firstMove = false;
+				}
 				updateCursor();
 				handleMouseMove(inputEvent->mousePosition);
 			}
@@ -2110,6 +2126,68 @@ PolycodeScreenEditor::PolycodeScreenEditor() : PolycodeEditor(true){
 	treeView->Refresh();
 }
 
+String PolycodeScreenEditor::Copy(void **data) {
+	return editorMain->Copy(data);
+}
+
+void PolycodeScreenEditor::Paste(void *data, String clipboardType) {
+	editorMain->Paste(data, clipboardType);
+}
+
+void PolycodeScreenEditor::destroyClipboardData(void *data, String type) {
+	editorMain->destroyClipboardData(data, type);
+}
+
+String PolycodeScreenEditorMain::Copy(void **data) {
+	if(selectedEntities.size() > 0) {
+		ScreenEntityClipboardData *newData = new ScreenEntityClipboardData();
+		for(int i=0; i < selectedEntities.size(); i++) {
+			ScreenEntity *clone = (ScreenEntity*)selectedEntities[i]->Clone(true, true);
+			newData->entities.push_back(clone);
+		}
+		*data = (void*) newData;
+	}
+	return "ScreenEntity";
+}
+
+void PolycodeScreenEditorMain::Paste(void *data, String clipboardType) {
+	if(!data)
+		return;
+	if(clipboardType == "ScreenEntity") {
+		selectEntity(NULL);
+		multiSelect = true;
+		ScreenEntityClipboardData *newData = (ScreenEntityClipboardData*) data;
+		if(currentLayer) {
+			for(int i=0; i < newData->entities.size(); i++) {
+				ScreenEntity *entity = (ScreenEntity*) newData->entities[i]->Clone(true, true);
+				entity->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
+				entity->addEventListener(this, InputEvent::EVENT_MOUSEUP);
+				if(selectedEntity && selectedEntity != currentLayer) {
+					selectedEntity->getParentEntity()->addChild(entity);
+				} else {
+					currentLayer->addChild(entity);
+				}
+				applyEditorProperties(entity);
+				selectEntity(entity);
+			}
+		}
+		multiSelect = false;
+	}
+	if(treeView) {
+		treeView->Refresh();		
+	}											
+}
+
+void PolycodeScreenEditorMain::destroyClipboardData(void *data, String type) {
+	if(type == "ScreenEntity") {
+		ScreenEntityClipboardData *oldData = (ScreenEntityClipboardData*) data;
+		for(int i=0; i < oldData->entities.size(); i++) {
+			delete oldData->entities[i];
+		}
+		delete oldData;
+	}
+}
+
 void PolycodeScreenEditor::Activate() {
 	editorMain->labelSheet->refreshFonts();
 }
@@ -2361,7 +2439,7 @@ void PolycodeScreenEditor::handleEvent(Event *event) {
 		}
 
 	}
-
+	PolycodeEditor::handleEvent(event);
 }
 
 PolycodeScreenEditor::~PolycodeScreenEditor() {
@@ -2375,6 +2453,7 @@ void PolycodeScreenEditorMain::applyEditorProperties(ScreenEntity *entity) {
 	}
 
 	if(dynamic_cast<ScreenEntityInstance*>(entity)) {
+		(((ScreenEntityInstance*)entity))->cloneUsingReload = true;
 		applyEditorOnly(((ScreenEntityInstance*)entity)->getRootEntity());
 		entity->setWidth(50);
 		entity->setHeight(50);		

+ 2 - 2
Modules/Contents/UI/Include/PolyUITree.h

@@ -70,7 +70,7 @@ namespace Polycode {
 			Number handleRotation;
 		
 		private:
-		
+
 			bool willDrag;
 			bool isDragging;
 		
@@ -99,4 +99,4 @@ namespace Polycode {
 			Number cellHeight;
 			Number cellPadding;
 	};
-}
+}

+ 2 - 2
Modules/Contents/UI/Source/PolyUITree.cpp

@@ -248,14 +248,14 @@ void UITree::clearSelection(UITree *selectedNode) {
 
 void UITree::refreshTree() {
 	if(collapsed) {
-		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 0, 0.2f, false, true);
+		handleRotation = 0;
 		for(int i=0; i < treeChildren.size(); i++) {
 			treeChildren[i]->visible = false;
 			treeChildren[i]->enabled = false;			
 		}
 		treeHeight = 0;
 	} else {
-		new Tween(&handleRotation, Tween::EASE_IN_QUAD, handleRotation, 90, 0.2f, false, true);
+		handleRotation = 90;
 		int offset = cellHeight;
 		for(int i=0; i < treeChildren.size(); i++) {
 			treeChildren[i]->visible = true;