bool Orbit::touchDown(float x, float y, int touchId){
	switch (mode) {
		case 0:
			shapeOnScreen = !shapeOnScreen;
			if(!shapeOnScreen){
				nextShape();
			}

			timeOfLastInteraction = ofGetElapsedTimef();
			break;
		case 1:
			numberOfShapes++;

			if(numberOfShapes > maxNumberOfShapes){
				numberOfShapes = 0;
				bigShapeColour = ofColor(ofRandom(0,255), ofRandom(0,255), ofRandom(0,255));
				shapesColour = bigShapeColour;
				nextShape();
			}

			timeOfLastInteraction = ofGetElapsedTimef();
			break;
		case 2:
			if (numberOfShapes < maxNumberOfShapes) {
				numberOfShapes++;
			}else if (numberOfMiddleShapes < maxNumberOfMiddleShapes){
				numberOfMiddleShapes++;
			}else if (numberOfInnerShapes <= maxNumberOfInnerShapes){
				numberOfInnerShapes++;
			}

			if((numberOfShapes >= maxNumberOfShapes) && (numberOfMiddleShapes >= maxNumberOfMiddleShapes) && (numberOfInnerShapes > maxNumberOfInnerShapes)){
				numberOfShapes = 0;
				numberOfMiddleShapes = 0;
				numberOfInnerShapes = 0;

				bigShapeColour = ofColor(ofRandom(0,255), ofRandom(0,255), ofRandom(0,255));
				shapesColour = bigShapeColour;
				nextShape();
			}

			timeOfLastInteraction = ofGetElapsedTimef();

			break;
		default:
			break;
	}

	return true;
}
bool wxJigsawEditorDocument::InsertGroup(wxJigsawShapeGroup * target, 
		wxJigsawShapeGroup * source, int insertIndex)
{
	do
	{
		if(!target || !source || ((insertIndex < 0) || (insertIndex > target->GetShapes().GetCount()))) break;
		wxJigsawShape * prevShape(NULL);
		wxJigsawShape * nextShape(NULL);
		wxJigsawShape * sourceFirstShape(NULL);
		wxJigsawShape * sourceLastShape(NULL);
		wxJigsawShapeList::Node * node(NULL);

		// Check if group is insertable
		node = source->GetShapes().GetFirst();
		sourceFirstShape = node->GetData();
		if(insertIndex > 0)
		{
			node = target->GetShapes().Item(insertIndex-1);
			if(!node) break;
			prevShape = node->GetData();
		}

		node = source->GetShapes().GetLast();
		sourceLastShape = node->GetData();
		if(insertIndex < (target->GetShapes().GetCount()-1))
		{
			node = target->GetShapes().Item(insertIndex);
			nextShape = node->GetData();
		}

		// If "previous" shape exists but we can't insert the shape then exit
		if(prevShape && (!prevShape->GetHasBump()  || !sourceFirstShape->GetHasNotch())) break;
		// If "next" shape exists but we can't insert the shape then exit
		if(nextShape && (!nextShape->GetHasNotch() || !sourceLastShape->GetHasBump())) break;

		for(node = source->GetShapes().GetLast(); node; node = node->GetPrevious())
		{
			wxJigsawShape * shape = node->GetData();
			if(!shape) continue;
			target->GetShapes().Insert(insertIndex, shape);
		}
		bool oldDeleteContents = source->GetShapes().GetDeleteContents();
		source->GetShapes().DeleteContents(false);
		source->GetShapes().Clear();
		source->GetShapes().DeleteContents(oldDeleteContents);
		return true;
	}
	while(false);
	return false;
}