2020-01-18 03:38:21 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-11-10 15:45:32 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Tool.h"
|
2019-11-10 16:31:10 -05:00
|
|
|
#include <AK/HashMap.h>
|
2020-02-16 03:17:49 -05:00
|
|
|
#include <LibGUI/Forward.h>
|
2020-02-06 06:04:00 -05:00
|
|
|
#include <LibGfx/Point.h>
|
2019-11-10 16:31:10 -05:00
|
|
|
|
2020-08-17 09:22:30 -04:00
|
|
|
namespace HackStudio {
|
|
|
|
|
2019-11-10 15:45:32 -05:00
|
|
|
class CursorTool final : public Tool {
|
|
|
|
public:
|
|
|
|
explicit CursorTool(FormEditorWidget& editor)
|
|
|
|
: Tool(editor)
|
|
|
|
{
|
|
|
|
}
|
2020-08-17 09:22:30 -04:00
|
|
|
virtual ~CursorTool() override { }
|
2019-11-10 15:45:32 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual const char* class_name() const override { return "CursorTool"; }
|
2020-02-02 09:07:41 -05:00
|
|
|
virtual void on_mousedown(GUI::MouseEvent&) override;
|
|
|
|
virtual void on_mouseup(GUI::MouseEvent&) override;
|
|
|
|
virtual void on_mousemove(GUI::MouseEvent&) override;
|
|
|
|
virtual void on_keydown(GUI::KeyEvent&) override;
|
|
|
|
virtual void on_second_paint(GUI::Painter&, GUI::PaintEvent&) override;
|
2019-11-16 16:26:46 -05:00
|
|
|
|
2020-06-10 04:57:59 -04:00
|
|
|
void set_rubber_band_position(const Gfx::IntPoint&);
|
|
|
|
Gfx::IntRect rubber_band_rect() const;
|
2019-11-10 16:31:10 -05:00
|
|
|
|
2020-06-10 04:57:59 -04:00
|
|
|
Gfx::IntPoint m_drag_origin;
|
|
|
|
HashMap<GUI::Widget*, Gfx::IntPoint> m_positions_before_drag;
|
2019-11-10 16:31:10 -05:00
|
|
|
bool m_dragging { false };
|
2019-11-16 16:26:46 -05:00
|
|
|
|
|
|
|
bool m_rubber_banding { false };
|
2020-06-10 04:57:59 -04:00
|
|
|
Gfx::IntPoint m_rubber_band_origin;
|
|
|
|
Gfx::IntPoint m_rubber_band_position;
|
2019-11-10 15:45:32 -05:00
|
|
|
};
|
2020-08-17 09:22:30 -04:00
|
|
|
|
|
|
|
}
|