mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-17 17:42:51 +00:00
- Renamed Editor::offset() with padding() - Changed padding size (and added Editor::calcExtraPadding() function) - Added Zoom::linearScale() and Zoom::fromLinearScale()
109 lines
2.2 KiB
C++
109 lines
2.2 KiB
C++
// Aseprite
|
|
// Copyright (C) 2001-2015 David Capello
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
// published by the Free Software Foundation.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include "app/ui/editor/zooming_state.h"
|
|
|
|
#include "app/app.h"
|
|
#include "app/ui/editor/editor.h"
|
|
#include "app/ui/status_bar.h"
|
|
#include "doc/sprite.h"
|
|
#include "gfx/rect.h"
|
|
#include "she/display.h"
|
|
#include "ui/manager.h"
|
|
#include "ui/message.h"
|
|
#include "ui/system.h"
|
|
#include "ui/theme.h"
|
|
#include "ui/view.h"
|
|
|
|
#include <cmath>
|
|
|
|
namespace app {
|
|
|
|
using namespace ui;
|
|
|
|
ZoomingState::ZoomingState()
|
|
: m_startZoom(1, 1)
|
|
, m_moved(false)
|
|
{
|
|
}
|
|
|
|
ZoomingState::~ZoomingState()
|
|
{
|
|
}
|
|
|
|
bool ZoomingState::onMouseDown(Editor* editor, MouseMessage* msg)
|
|
{
|
|
m_startPos = msg->position();
|
|
m_startZoom = editor->zoom();
|
|
|
|
editor->captureMouse();
|
|
return true;
|
|
}
|
|
|
|
bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg)
|
|
{
|
|
if (!m_moved) {
|
|
render::Zoom zoom = editor->zoom();
|
|
|
|
if (msg->left())
|
|
zoom.in();
|
|
else if (msg->right())
|
|
zoom.out();
|
|
|
|
editor->setZoomAndCenterInMouse(
|
|
zoom, msg->position(), Editor::ZoomBehavior::MOUSE);
|
|
}
|
|
|
|
editor->backToPreviousState();
|
|
editor->releaseMouse();
|
|
return true;
|
|
}
|
|
|
|
bool ZoomingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
|
{
|
|
gfx::Point pt = (msg->position() - m_startPos);
|
|
int threshold = 8 * guiscale() * editor->getManager()->getDisplay()->scale();
|
|
|
|
if (m_moved || std::sqrt(pt.x*pt.x + pt.y*pt.y) > threshold) {
|
|
m_moved = true;
|
|
|
|
int newScale = m_startZoom.linearScale() + pt.x / threshold;
|
|
render::Zoom newZoom = render::Zoom::fromLinearScale(newScale);
|
|
|
|
editor->setZoomAndCenterInMouse(
|
|
newZoom, m_startPos, Editor::ZoomBehavior::MOUSE);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool ZoomingState::onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos)
|
|
{
|
|
editor->showMouseCursor(kMagnifierCursor);
|
|
return true;
|
|
}
|
|
|
|
bool ZoomingState::onKeyDown(Editor* editor, KeyMessage* msg)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool ZoomingState::onKeyUp(Editor* editor, KeyMessage* msg)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool ZoomingState::onUpdateStatusBar(Editor* editor)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
} // namespace app
|