mod.rs - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
HTML git clone https://git.drkhsh.at/icy_draw.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
mod.rs (3671B)
---
1 pub mod brush_imp;
2 pub mod click_imp;
3 pub mod draw_ellipse_filled_imp;
4 pub mod draw_ellipse_imp;
5 pub mod draw_rectangle_filled_imp;
6 pub mod draw_rectangle_imp;
7 pub mod erase_imp;
8 pub mod fill_imp;
9 pub mod flip_imp;
10 pub mod font_imp;
11 pub mod line_imp;
12 pub mod move_layer_imp;
13 pub mod paste_tool;
14 pub mod pencil_imp;
15 pub mod pipette_imp;
16 pub mod select_imp;
17
18 mod icons;
19
20 use std::sync::Arc;
21
22 use eframe::egui::{self, Response};
23 use egui::mutex::Mutex;
24 use i18n_embed_fl::fl;
25 use icy_engine::Position;
26 use icy_engine_egui::TerminalCalc;
27
28 use crate::{AnsiEditor, Document, Event, Message};
29
30 #[derive(Copy, Clone, Debug)]
31 pub enum MKey {
32 Character(u16),
33 Down,
34 Up,
35 Left,
36 Right,
37 PageDown,
38 PageUp,
39 Home,
40 End,
41 Return,
42 Delete,
43 Insert,
44 Backspace,
45 Tab,
46 Escape,
47 F1,
48 F2,
49 F3,
50 F4,
51 F5,
52 F6,
53 F7,
54 F8,
55 F9,
56 F10,
57 F11,
58 F12,
59 }
60
61 #[derive(Copy, Clone, Debug)]
62 pub enum MModifiers {
63 None,
64 Shift,
65 Alt,
66 Control,
67 }
68
69 impl MModifiers {
70 pub fn is_shift(self) -> bool {
71 matches!(self, MModifiers::Shift)
72 }
73
74 pub fn is_alt(self) -> bool {
75 matches!(self, MModifiers::Alt)
76 }
77
78 pub fn is_control(self) -> bool {
79 matches!(self, MModifiers::Control)
80 }
81 }
82
83 #[derive(Default, Clone, Copy)]
84 pub struct DragPos {
85 pub start_abs: Position,
86 pub cur_abs: Position,
87 pub start: Position,
88 pub cur: Position,
89
90 pub start_half_block: Position,
91 }
92
93 pub trait Tool {
94 fn get_icon(&self) -> &egui::Image<'static>;
95
96 fn tool_name(&self) -> String;
97
98 fn tooltip(&self) -> String;
99
100 fn use_caret(&self, _editor: &AnsiEditor) -> bool {
101 true
102 }
103
104 fn is_visible(&self) -> bool {
105 true
106 }
107
108 fn is_exclusive(&self) -> bool {
109 false
110 }
111
112 fn use_selection(&self) -> bool {
113 true
114 }
115
116 fn show_ui(&mut self, ctx: &egui::Context, ui: &mut egui::Ui, editor_opt: Option<&mut AnsiEditor>) -> Option<Message>;
117
118 fn show_doc_ui(&mut self, _ctx: &egui::Context, _ui: &mut egui::Ui, _doc: Arc<Mutex<Box<dyn Document>>>) -> Option<Message> {
119 None
120 }
121
122 fn handle_key(&mut self, _editor: &mut AnsiEditor, _key: MKey, _modifier: MModifiers) -> Event {
123 Event::None
124 }
125
126 fn handle_click(&mut self, _editor: &mut AnsiEditor, _button: i32, _pos: Position, _pos_abs: Position, _response: &Response) -> Option<Message> {
127 None
128 }
129
130 fn handle_drag_begin(&mut self, _editor: &mut AnsiEditor, _response: &egui::Response) -> Event {
131 Event::None
132 }
133
134 fn handle_drag(&mut self, _ui: &egui::Ui, response: Response, _editor: &mut AnsiEditor, _calc: &TerminalCalc) -> Response {
135 response
136 }
137
138 fn handle_hover(&mut self, _ui: &egui::Ui, response: Response, _editor: &mut AnsiEditor, _cur: Position, _cur_abs: Position) -> Response {
139 response
140 }
141
142 fn handle_no_hover(&mut self, _editor: &mut AnsiEditor) {}
143
144 fn handle_drag_end(&mut self, _editor: &mut AnsiEditor) -> Option<Message> {
145 None
146 }
147
148 fn get_toolbar_location_text(&self, editor: &AnsiEditor) -> String {
149 toolbar_pos_sel_text(editor, true)
150 }
151 }
152
153 fn toolbar_pos_sel_text(editor: &AnsiEditor, show_selection: bool) -> String {
154 let pos = editor.get_caret_position();
155 let sel = if show_selection { editor.buffer_view.lock().get_selection() } else { None };
156
157 if let Some(sel) = sel {
158 let r = sel.as_rectangle();
159 fl!(crate::LANGUAGE_LOADER, "toolbar-size", colums = r.size.width, rows = r.size.height)
160 } else {
161 fl!(crate::LANGUAGE_LOADER, "toolbar-position", line = (pos.y + 1), column = (pos.x + 1))
162 }
163 }