<commit_before>#ifndef D2D_ARRANGE_SPRITE_OP_CPP_
#define D2D_ARRANGE_SPRITE_OP_CPP_

#include "ArrangeSpriteOP.h"

#include "dataset/ISprite.h"
#include "dataset/ISymbol.h"
#include "dataset/AbstractBV.h"
#include "common/Math.h"
#include "common/visitors.h"
#include "common/Matrix.h"
#include "view/EditPanel.h"
#include "view/MultiSpritesImpl.h"
#include "view/PropertySettingPanel.h"
#include "history/ArrangeSpriteAtomicOP.h"
#include "render/PrimitiveDraw.h"

namespace d2d
{
	template <typename TBase>
	const float ArrangeSpriteOP<TBase>::SCALE_NODE_RADIUS = 2.0f;

	template <typename TBase>
	ArrangeSpriteOP<TBase>::ArrangeSpriteOP(EditPanel* editPanel, MultiSpritesImpl* spritesImpl, 
		PropertySettingPanel* propertyPanel/* = NULL*/, AbstractEditCMPT* callback/* = NULL*/, bool isDeformOpen/* = true*/)
		: TBase(editPanel, spritesImpl, propertyPanel, callback)
		, m_isDeformOpen(isDeformOpen)
		, m_spritesImpl(spritesImpl)
		, m_propertyPanel(propertyPanel)
		, m_bRightPress(false)
		, m_selected(NULL)
		, m_bDirty(false)
		, m_autoAlignOpen(false)
	{
		m_selection = spritesImpl->getSpriteSelection();
		m_selection->retain();

		m_firstPos.setInvalid();

		m_ctrlNodeSelected.setInvalid();

		m_shearNodeStyle.color.set(0.2f, 0.8f, 0.2f);
		m_shearNodeStyle.fill = false;
		m_shearNodeStyle.size = 2;
	}

	template <typename TBase>
	ArrangeSpriteOP<TBase>::~ArrangeSpriteOP()
	{
		m_selection->release();
	}

	template <typename TBase>
	bool ArrangeSpriteOP<TBase>::onKeyDown(int keyCode)
	{
		std::vector<ISprite*> sprites;
		m_selection->traverse(FetchAllVisitor<ISprite>(sprites));
		for (size_t i = 0, n = sprites.size(); i < n; ++i)
			sprites[i]->retain();

		if (TBase::onKeyDown(keyCode)) 
		{
			for (size_t i = 0, n = sprites.size(); i < n; ++i)
				sprites[i]->release();
			return true;
		}

		switch (keyCode)
		{
		case WXK_DELETE:
			{
				std::vector<ISprite*> noPhysicsSprites;
				for (size_t i = 0, n = sprites.size(); i < n; ++i)
					if (!sprites[i]->getBody()) 
						noPhysicsSprites.push_back(sprites[i]);
				m_editPanel->addHistoryOP(new arrange_sprite::DeleteSpritesAOP(noPhysicsSprites, m_spritesImpl));
			}
			m_spritesImpl->removeSpriteSelection();
			m_selected = NULL;
			break;
		case 'a': case 'A':
			translateSprite(Vector(-1, 0));
			break;
		case 'd': case 'D':
			translateSprite(Vector(1, 0));
			break;
		case 's': case 'S':
			translateSprite(Vector(0, -1));
			break;
		case 'w': case 'W':
			translateSprite(Vector(0, 1));
			break;
		case WXK_SPACE:
			{
				std::vector<ISprite*> selected;
				m_selection->traverse(FetchAllVisitor<ISprite>(selected));
				for (size_t i = 0, n = selected.size(); i < n; ++i)
				{
					selected[i]->setTransform(Vector(0, 0), 0);
					selected[i]->setOffset(Vector(0, 0));
				}
				m_editPanel->Refresh();<commit_msg>编辑sprite时，空格不清offset<commit_after>#ifndef D2D_ARRANGE_SPRITE_OP_CPP_
#define D2D_ARRANGE_SPRITE_OP_CPP_

#include "ArrangeSpriteOP.h"

#include "dataset/ISprite.h"
#include "dataset/ISymbol.h"
#include "dataset/AbstractBV.h"
#include "common/Math.h"
#include "common/visitors.h"
#include "common/Matrix.h"
#include "view/EditPanel.h"
#include "view/MultiSpritesImpl.h"
#include "view/PropertySettingPanel.h"
#include "history/ArrangeSpriteAtomicOP.h"
#include "render/PrimitiveDraw.h"

namespace d2d
{
	template <typename TBase>
	const float ArrangeSpriteOP<TBase>::SCALE_NODE_RADIUS = 2.0f;

	template <typename TBase>
	ArrangeSpriteOP<TBase>::ArrangeSpriteOP(EditPanel* editPanel, MultiSpritesImpl* spritesImpl, 
		PropertySettingPanel* propertyPanel/* = NULL*/, AbstractEditCMPT* callback/* = NULL*/, bool isDeformOpen/* = true*/)
		: TBase(editPanel, spritesImpl, propertyPanel, callback)
		, m_isDeformOpen(isDeformOpen)
		, m_spritesImpl(spritesImpl)
		, m_propertyPanel(propertyPanel)
		, m_bRightPress(false)
		, m_selected(NULL)
		, m_bDirty(false)
		, m_autoAlignOpen(false)
	{
		m_selection = spritesImpl->getSpriteSelection();
		m_selection->retain();

		m_firstPos.setInvalid();

		m_ctrlNodeSelected.setInvalid();

		m_shearNodeStyle.color.set(0.2f, 0.8f, 0.2f);
		m_shearNodeStyle.fill = false;
		m_shearNodeStyle.size = 2;
	}

	template <typename TBase>
	ArrangeSpriteOP<TBase>::~ArrangeSpriteOP()
	{
		m_selection->release();
	}

	template <typename TBase>
	bool ArrangeSpriteOP<TBase>::onKeyDown(int keyCode)
	{
		std::vector<ISprite*> sprites;
		m_selection->traverse(FetchAllVisitor<ISprite>(sprites));
		for (size_t i = 0, n = sprites.size(); i < n; ++i)
			sprites[i]->retain();

		if (TBase::onKeyDown(keyCode)) 
		{
			for (size_t i = 0, n = sprites.size(); i < n; ++i)
				sprites[i]->release();
			return true;
		}

		switch (keyCode)
		{
		case WXK_DELETE:
			{
				std::vector<ISprite*> noPhysicsSprites;
				for (size_t i = 0, n = sprites.size(); i < n; ++i)
					if (!sprites[i]->getBody()) 
						noPhysicsSprites.push_back(sprites[i]);
				m_editPanel->addHistoryOP(new arrange_sprite::DeleteSpritesAOP(noPhysicsSprites, m_spritesImpl));
			}
			m_spritesImpl->removeSpriteSelection();
			m_selected = NULL;
			break;
		case 'a': case 'A':
			translateSprite(Vector(-1, 0));
			break;
		case 'd': case 'D':
			translateSprite(Vector(1, 0));
			break;
		case 's': case 'S':
			translateSprite(Vector(0, -1));
			break;
		case 'w': case 'W':
			translateSprite(Vector(0, 1));
			break;
		case WXK_SPACE:
			{
				std::vector<ISprite*> selected;
				m_selection->traverse(FetchAllVisitor<ISprite>(selected));
				for (size_t i = 0, n = selected.size(); i < n; ++i)
				{
					selected[i]->setTransform(Vector(0, 0), 0);
//					selected[i]->setOffset(Vector(0, 0));
				}
				m_editPanel->Refresh();
{'fraction_non_alphanumeric': 0.15217006200177147, 'fraction_numerical': 0.010274579273693534, 'mean_word_length': 4.767109295199183, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12162', 'n_tokens_mistral': 2434, 'n_tokens_neox': 2179, 'n_words': 373}