summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint/Tools/TextTool.h
blob: 1396290d3040e9554e2f018d495d3cce808a72e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (c) 2022, Timothy Slater <tslater2006@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "Tool.h"
#include <LibCore/Timer.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Label.h>
#include <LibGUI/Painter.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/TextPosition.h>

namespace PixelPaint {
class TextTool;

class TextToolEditor : public GUI::TextEditor {
    C_OBJECT(TextToolEditor)
public:
    virtual ~TextToolEditor() override = default;
    virtual void handle_keyevent(Badge<TextTool>, GUI::KeyEvent&);
    NonnullRefPtrVector<GUI::Action> actions();

protected:
    TextToolEditor();
};

class TextTool final : public Tool {
public:
    TextTool();
    virtual ~TextTool() override = default;

    virtual void on_mousemove(Layer*, MouseEvent&) override;
    virtual void on_mouseup(Layer*, MouseEvent&) override;
    virtual void on_mousedown(Layer*, MouseEvent&) override;
    virtual bool on_keydown(GUI::KeyEvent&) override;
    virtual void on_second_paint(Layer const*, GUI::PaintEvent&) override;
    virtual void on_primary_color_change(Color) override;
    virtual void on_tool_deactivation() override;
    virtual Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> cursor() override;
    virtual ErrorOr<GUI::Widget*> get_properties_widget() override;

private:
    virtual StringView tool_name() const override { return "Text Tool"sv; }
    void apply_text_to_layer();
    void reset_tool();

    RefPtr<GUI::Widget> m_properties_widget;
    RefPtr<GUI::Label> m_font_label;
    RefPtr<Core::Timer> m_cursor_blink_timer;
    RefPtr<PixelPaint::TextToolEditor> m_text_editor;
    Gfx::IntPoint m_add_text_position { 0, 0 };
    RefPtr<Gfx::Font> m_selected_font;
    bool m_text_input_is_active { false };
    bool m_cursor_blink_state { false };
    bool m_mouse_is_over_text { false };
    bool m_is_dragging { false };
    Gfx::IntPoint m_drag_start_point;
    Gfx::IntRect m_ants_rect;
    Color m_text_color;
};

}