line_imp.rs - icy_draw - icy_draw is the successor to mystic draw. fork / mirror
(HTM) git clone https://git.drkhsh.at/icy_draw.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
line_imp.rs (2986B)
---
1 use eframe::egui;
2 use i18n_embed_fl::fl;
3 use icy_engine_egui::TerminalCalc;
4
5 use crate::{
6 paint::{draw_line, BrushMode, ColorMode},
7 AnsiEditor, Event, Message,
8 };
9
10 use super::{Position, Tool};
11
12 pub struct LineTool {
13 draw_mode: BrushMode,
14 color_mode: ColorMode,
15
16 pub char_code: std::rc::Rc<std::cell::RefCell<char>>,
17
18 pub old_pos: Position,
19 }
20
21 impl Default for LineTool {
22 fn default() -> Self {
23 Self {
24 draw_mode: BrushMode::HalfBlock,
25 color_mode: crate::paint::ColorMode::Both,
26 char_code: std::rc::Rc::new(std::cell::RefCell::new('\u{00B0}')),
27 old_pos: Position::default(),
28 }
29 }
30 }
31
32 // block tools:
33 // copy/moxe
34 // fill, delete
35 impl Tool for LineTool {
36 fn get_icon(&self) -> &egui::Image<'static> {
37 &super::icons::LINE_SVG
38 }
39
40 fn tool_name(&self) -> String {
41 fl!(crate::LANGUAGE_LOADER, "tool-line_name")
42 }
43
44 fn tooltip(&self) -> String {
45 fl!(crate::LANGUAGE_LOADER, "tool-line_tooltip")
46 }
47
48 fn use_caret(&self, _editor: &AnsiEditor) -> bool {
49 false
50 }
51
52 fn use_selection(&self) -> bool {
53 false
54 }
55
56 fn show_ui(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui, editor_opt: Option<&mut AnsiEditor>) -> Option<Message> {
57 self.color_mode.show_ui(ui);
58 self.draw_mode
59 .show_ui(ui, editor_opt, self.char_code.clone(), crate::paint::BrushUi::HideOutline)
60 }
61
62 fn handle_click(&mut self, editor: &mut AnsiEditor, button: i32, pos: Position, _pos_abs: Position, _response: &egui::Response) -> Option<Message> {
63 if button == 1 {
64 editor.set_caret_position(pos);
65 }
66 None
67 }
68
69 fn handle_hover(&mut self, _ui: &egui::Ui, response: egui::Response, _editor: &mut AnsiEditor, _cur: Position, _cur_abs: Position) -> egui::Response {
70 response.on_hover_cursor(egui::CursorIcon::Crosshair)
71 }
72
73 fn handle_drag_begin(&mut self, _editor: &mut AnsiEditor, _response: &egui::Response) -> Event {
74 self.old_pos = Position::new(-1, -1);
75 Event::None
76 }
77
78 fn handle_drag(&mut self, _ui: &egui::Ui, response: egui::Response, editor: &mut AnsiEditor, _calc: &TerminalCalc) -> egui::Response {
79 let p2 = editor.half_block_click_pos;
80 if self.old_pos == p2 {
81 return response;
82 }
83 self.old_pos = p2;
84
85 editor.clear_overlay_layer();
86 draw_line(
87 &mut editor.buffer_view.lock(),
88 editor.drag_pos.start_half_block,
89 p2,
90 self.draw_mode.clone(),
91 self.color_mode,
92 );
93 response
94 }
95
96 fn handle_drag_end(&mut self, editor: &mut AnsiEditor) -> Option<Message> {
97 if editor.drag_pos.start == editor.drag_pos.cur {
98 editor.buffer_view.lock().get_buffer_mut().remove_overlay();
99 } else {
100 editor.join_overlay(fl!(crate::LANGUAGE_LOADER, "undo-line"));
101 }
102 None
103 }
104 }