<commit_before>#include "EditPanelImpl.h"
#include "EditPanel.h"
#include "Frame.h"
#include "StageCanvas.h"
#include "panel_msg.h"
#include "subject_id.h"
#include "EditOP.h"
#include "sprite_msg.h"
#include "StringHelper.h"
#include "SpriteRenderer.h"
#include "CameraMgr.h"
#include "OrthoCamera.h"
#include "Pseudo3DCamera.h"

#include <fstream>

namespace ee
{

EditPanelImpl::EditPanelImpl(wxTopLevelWindow* frame,
							 EditPanel* stage)
	: m_frame(frame)
	, m_stage(stage)
{
	m_edit_op = NULL;
	m_canvas = NULL;
	InitSubjects();
}

EditPanelImpl::~EditPanelImpl()
{
	Clear();

	if (m_edit_op) {
		m_edit_op->Release();
	}
	if (m_canvas) {
		m_canvas->Release();
		m_canvas = NULL;
	}
}

void EditPanelImpl::SetEditPanelNull()
{
	m_stage = NULL;
}

bool EditPanelImpl::Update(int version)
{
	if (m_stage) {
		return m_stage->Update(version);
	} else {
		return false;
	}
}

Vector EditPanelImpl::TransPosScrToProj(int x, int y) const
{
	if (!m_stage) {
		return Vector(0, 0);
	}

	int w = m_stage->GetSize().GetWidth(),
		h = m_stage->GetSize().GetHeight();
	return CameraMgr::Instance()->GetCamera()->TransPosScreenToProject(x, y, w, h);
}

Vector EditPanelImpl::TransPosProjToScr(const Vector& proj) const
{
	if (!m_stage) {
		return Vector(0, 0);
	}

	int w = m_stage->GetSize().GetWidth(),
		h = m_stage->GetSize().GetHeight();
	return CameraMgr::Instance()->GetCamera()->TransPosProjectToScreen(proj, w, h);
}

void EditPanelImpl::DrawEditOP() const
{
	if (m_edit_op) {
		m_edit_op->OnDraw();
	}
}

void EditPanelImpl::SetEditOP(EditOP* editOP)
{
	if (m_edit_op == editOP) {
		return;
	}

	if (editOP) {
		editOP->Retain();
	}
	if (m_edit_op)
	{
		m_edit_op->Clear();
		m_edit_op->Release();
	}
	m_edit_op = editOP;
	if (m_edit_op) {
		m_edit_op->OnActive();
	}
	SetCanvasDirtySJ::Instance()->SetDirty();
}

void EditPanelImpl::SetCanvas(StageCanvas* canvas) 
{ 
	obj_assign<StageCanvas>(m_canvas, canvas);
}

void EditPanelImpl::OnMouse(wxMouseEvent& event)
{
#ifdef _DEBUG
	if (wxFrame* frame = dynamic_cast<wxFrame*>(m_frame)) 
	{
		Vector pos = TransPosScrToProj(event.GetX(), event.GetY());
		std::string msg = ee::StringHelper::Format("Mouse: %.1f, %.1f", pos.x, pos.y);
		static_cast<wxFrame*>(m_frame)->SetStatusText(msg);
	}
#endif

	if (!m_edit_op) return;

	if (event.LeftDown())
		m_edit_op->OnMouseLeftDown(event.GetX(), event.GetY());
	else if (event.LeftUp())
		m_edit_op->OnMouseLeftUp(event.GetX(), event.GetY());
	else if (event.RightDown())
		m_edit_op->OnMouseRightDown(event.GetX(), event.GetY());
	else if (event.RightUp())
		m_edit_op->OnMouseRightUp(event.GetX(), event.GetY());
	else if (event.Moving())
		m_edit_op->OnMouseMove(event.GetX(), event.GetY());
	else if (event.Dragging())
		m_edit_op->OnMouseDrag(event.GetX(), event.GetY());
	else if (event.LeftDClick())
		m_edit_op->OnMouseLeftDClick(event.GetX(), event.GetY());
	else if (event.GetWheelRotation())
		m_edit_op->OnMouseWheelRotation(event.GetX(), event.GetY(), event.GetWheelRotation());

	if (m_stage) {
		m_stage->OnMouseHook(event);
	}
}

void EditPanelImpl::OnKeyDown(wxKeyEvent& event)
{
	int key_code = event.GetKeyCode();
	m_keys_state.OnKeyDown(key_code);

	if (GetKeyState(WXK_CONTROL) && (key_code == 'z' || key_code == 'Z')) {
		Undo();
	} else if (GetKeyState(WXK_CONTROL) && (key_code == 'y' || key_code == 'Y')) {
		Redo();
	}

	switch (key_code) {
	case WXK_F5:
		{
			Frame* frame = dynamic_cast<Frame*>(m_frame);
			if (frame) {
				Clear();
				frame->RefreshWithCurrFile();
			}
		}
		break;
	}

	if (m_edit_op) {
		m_edit_op->OnKeyDown(key_code);
	}

	if (m_stage) {
		m_stage->OnKeyHook(key_code);
	}
}

void EditPanelImpl::OnKeyUp(wxKeyEvent& event)
{
	int key_code = event.GetKeyCode();
	m_keys_state.OnKeyUp(key_code);

	if (m_edit_op) {
		m_edit_op->OnKeyUp(key_code);
	}
}

void EditPanelImpl::OnMouseWheelRotation(int x, int y, int direction)
{
	if (CameraMgr::Instance()->IsType(CameraMgr::ORTHO) && m_stage) 
	{
		int w = m_stage->GetSize().GetWidth(),
			h = m_stage->GetSize().GetHeight();
		const float scale = direction > 0 ? 1 / 1.1f : 1.1f;
		const float cx = static_cast<float>(x),
			        cy = static_cast<float>(h - y);
		OrthoCamera* cam = static_cast<OrthoCamera*>(CameraMgr::Instance()->GetCamera());
		cam->Scale(scale, cx, cy, w, h);
	} 
	else if (CameraMgr::Instance()->IsType(CameraMgr::PSEUDO3D))
	{
		Pseudo3DCamera* cam = static_cast<Pseudo3DCamera*>(CameraMgr::Instance()->GetCamera());
		float dz = direction > 0 ? 5 : -5;
		cam->Translate(vec3(0, 0, dz));
	}
}<commit_msg>[ADDED] fine tuning for ortho scale<commit_after>#include "EditPanelImpl.h"
#include "EditPanel.h"
#include "Frame.h"
#include "StageCanvas.h"
#include "panel_msg.h"
#include "subject_id.h"
#include "EditOP.h"
#include "sprite_msg.h"
#include "StringHelper.h"
#include "SpriteRenderer.h"
#include "CameraMgr.h"
#include "OrthoCamera.h"
#include "Pseudo3DCamera.h"

#include <fstream>

namespace ee
{

EditPanelImpl::EditPanelImpl(wxTopLevelWindow* frame,
							 EditPanel* stage)
	: m_frame(frame)
	, m_stage(stage)
{
	m_edit_op = NULL;
	m_canvas = NULL;
	InitSubjects();
}

EditPanelImpl::~EditPanelImpl()
{
	Clear();

	if (m_edit_op) {
		m_edit_op->Release();
	}
	if (m_canvas) {
		m_canvas->Release();
		m_canvas = NULL;
	}
}

void EditPanelImpl::SetEditPanelNull()
{
	m_stage = NULL;
}

bool EditPanelImpl::Update(int version)
{
	if (m_stage) {
		return m_stage->Update(version);
	} else {
		return false;
	}
}

Vector EditPanelImpl::TransPosScrToProj(int x, int y) const
{
	if (!m_stage) {
		return Vector(0, 0);
	}

	int w = m_stage->GetSize().GetWidth(),
		h = m_stage->GetSize().GetHeight();
	return CameraMgr::Instance()->GetCamera()->TransPosScreenToProject(x, y, w, h);
}

Vector EditPanelImpl::TransPosProjToScr(const Vector& proj) const
{
	if (!m_stage) {
		return Vector(0, 0);
	}

	int w = m_stage->GetSize().GetWidth(),
		h = m_stage->GetSize().GetHeight();
	return CameraMgr::Instance()->GetCamera()->TransPosProjectToScreen(proj, w, h);
}

void EditPanelImpl::DrawEditOP() const
{
	if (m_edit_op) {
		m_edit_op->OnDraw();
	}
}

void EditPanelImpl::SetEditOP(EditOP* editOP)
{
	if (m_edit_op == editOP) {
		return;
	}

	if (editOP) {
		editOP->Retain();
	}
	if (m_edit_op)
	{
		m_edit_op->Clear();
		m_edit_op->Release();
	}
	m_edit_op = editOP;
	if (m_edit_op) {
		m_edit_op->OnActive();
	}
	SetCanvasDirtySJ::Instance()->SetDirty();
}

void EditPanelImpl::SetCanvas(StageCanvas* canvas) 
{ 
	obj_assign<StageCanvas>(m_canvas, canvas);
}

void EditPanelImpl::OnMouse(wxMouseEvent& event)
{
#ifdef _DEBUG
	if (wxFrame* frame = dynamic_cast<wxFrame*>(m_frame)) 
	{
		Vector pos = TransPosScrToProj(event.GetX(), event.GetY());
		std::string msg = ee::StringHelper::Format("Mouse: %.1f, %.1f", pos.x, pos.y);
		static_cast<wxFrame*>(m_frame)->SetStatusText(msg);
	}
#endif

	if (!m_edit_op) return;

	if (event.LeftDown())
		m_edit_op->OnMouseLeftDown(event.GetX(), event.GetY());
	else if (event.LeftUp())
		m_edit_op->OnMouseLeftUp(event.GetX(), event.GetY());
	else if (event.RightDown())
		m_edit_op->OnMouseRightDown(event.GetX(), event.GetY());
	else if (event.RightUp())
		m_edit_op->OnMouseRightUp(event.GetX(), event.GetY());
	else if (event.Moving())
		m_edit_op->OnMouseMove(event.GetX(), event.GetY());
	else if (event.Dragging())
		m_edit_op->OnMouseDrag(event.GetX(), event.GetY());
	else if (event.LeftDClick())
		m_edit_op->OnMouseLeftDClick(event.GetX(), event.GetY());
	else if (event.GetWheelRotation())
		m_edit_op->OnMouseWheelRotation(event.GetX(), event.GetY(), event.GetWheelRotation());

	if (m_stage) {
		m_stage->OnMouseHook(event);
	}
}

void EditPanelImpl::OnKeyDown(wxKeyEvent& event)
{
	int key_code = event.GetKeyCode();
	m_keys_state.OnKeyDown(key_code);

	if (GetKeyState(WXK_CONTROL) && (key_code == 'z' || key_code == 'Z')) {
		Undo();
	} else if (GetKeyState(WXK_CONTROL) && (key_code == 'y' || key_code == 'Y')) {
		Redo();
	}

	switch (key_code) {
	case WXK_F5:
		{
			Frame* frame = dynamic_cast<Frame*>(m_frame);
			if (frame) {
				Clear();
				frame->RefreshWithCurrFile();
			}
		}
		break;
	}

	if (m_edit_op) {
		m_edit_op->OnKeyDown(key_code);
	}

	if (m_stage) {
		m_stage->OnKeyHook(key_code);
	}
}

void EditPanelImpl::OnKeyUp(wxKeyEvent& event)
{
	int key_code = event.GetKeyCode();
	m_keys_state.OnKeyUp(key_code);

	if (m_edit_op) {
		m_edit_op->OnKeyUp(key_code);
	}
}

void EditPanelImpl::OnMouseWheelRotation(int x, int y, int direction)
{
	if (CameraMgr::Instance()->IsType(CameraMgr::ORTHO) && m_stage) 
	{
		int w = m_stage->GetSize().GetWidth(),
			h = m_stage->GetSize().GetHeight();
		float scale = 1;
		if (GetKeyState(WXK_CONTROL)) {
			scale = direction > 0 ? 1 / 1.01f : 1.01f;
		} else {
			scale = direction > 0 ? 1 / 1.1f : 1.1f;
		}
		const float cx = static_cast<float>(x),
			        cy = static_cast<float>(h - y);
		OrthoCamera* cam = static_cast<OrthoCamera*>(CameraMgr::Instance()->GetCamera());
		cam->Scale(scale, cx, cy, w, h);
	} 
	else if (CameraMgr::Instance()->IsType(CameraMgr::PSEUDO3D))
	{
		Pseudo3DCamera* cam = static_cast<Pseudo3DCamera*>(CameraMgr::Instance()->GetCamera());
		float dz = direction > 0 ? 5 : -5;
		cam->Translate(vec3(0, 0, dz));
	}
}
{'fraction_non_alphanumeric': 0.17695070192621612, 'fraction_numerical': 0.005985417346827729, 'mean_word_length': 4.971410006497726, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 104, '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': '4731260', 'n_tokens_mistral': 3909, 'n_tokens_neox': 3727, 'n_words': 629}