flip_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
---
flip_imp.rs (3875B)
---
1 use eframe::egui;
2 use i18n_embed_fl::fl;
3 use icy_engine::attribute;
4
5 use crate::{paint::ColorMode, AnsiEditor, Message};
6
7 use super::{Position, Tool};
8 pub struct FlipTool {
9 flip_horizontal: bool,
10 cur_pos: Position,
11 color_mode: ColorMode,
12 }
13
14 impl Default for FlipTool {
15 fn default() -> Self {
16 Self {
17 flip_horizontal: false,
18 cur_pos: Position::new(-1, -1),
19 color_mode: ColorMode::None,
20 }
21 }
22 }
23
24 impl Tool for FlipTool {
25 fn get_icon(&self) -> &egui::Image<'static> {
26 &super::icons::FLIP_TOOL_SVG
27 }
28
29 fn tool_name(&self) -> String {
30 fl!(crate::LANGUAGE_LOADER, "tool-flip_name")
31 }
32
33 fn tooltip(&self) -> String {
34 fl!(crate::LANGUAGE_LOADER, "tool-flip_tooltip")
35 }
36
37 fn use_caret(&self, _editor: &AnsiEditor) -> bool {
38 false
39 }
40
41 fn use_selection(&self) -> bool {
42 false
43 }
44
45 fn show_ui(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui, _editor_opt: Option<&mut AnsiEditor>) -> Option<Message> {
46 self.color_mode.show_ui(ui);
47
48 ui.radio_value(&mut self.flip_horizontal, true, fl!(crate::LANGUAGE_LOADER, "tool-flip_horizontal"));
49 ui.radio_value(&mut self.flip_horizontal, false, fl!(crate::LANGUAGE_LOADER, "tool-flip_vertical"));
50
51 None
52 }
53
54 fn handle_no_hover(&mut self, editor: &mut AnsiEditor) {
55 self.cur_pos = Position::new(-1, -1);
56
57 let lock: &mut eframe::epaint::mutex::MutexGuard<'_, icy_engine_egui::BufferView> = &mut editor.buffer_view.lock();
58 let get_edit_state_mut = lock.get_edit_state_mut();
59 if !get_edit_state_mut.get_tool_overlay_mask_mut().is_empty() {
60 get_edit_state_mut.get_tool_overlay_mask_mut().clear();
61 get_edit_state_mut.set_is_buffer_dirty();
62 }
63 }
64
65 fn handle_hover(&mut self, _ui: &egui::Ui, response: egui::Response, editor: &mut AnsiEditor, _cur: Position, cur_abs: Position) -> egui::Response {
66 if self.cur_pos != cur_abs {
67 self.cur_pos = cur_abs;
68 let lock = &mut editor.buffer_view.lock();
69 let get_tool_overlay_mask_mut = lock.get_edit_state_mut().get_tool_overlay_mask_mut();
70 get_tool_overlay_mask_mut.clear();
71 get_tool_overlay_mask_mut.set_is_selected(cur_abs, true);
72 lock.get_edit_state_mut().set_is_buffer_dirty();
73 }
74
75 response.on_hover_cursor(egui::CursorIcon::Crosshair)
76 }
77
78 fn handle_click(&mut self, editor: &mut AnsiEditor, button: i32, pos: Position, _pos_abs: Position, _response: &egui::Response) -> Option<Message> {
79 if button == 1 {
80 let mut ch = editor.get_char_from_cur_layer(pos);
81 ch.attribute.attr &= !attribute::INVISIBLE;
82 if self.color_mode.use_fore() {
83 ch.attribute
84 .set_foreground(editor.buffer_view.lock().get_caret().get_attribute().get_foreground());
85 }
86 if self.color_mode.use_back() {
87 ch.attribute
88 .set_background(editor.buffer_view.lock().get_caret().get_attribute().get_background());
89 }
90 if self.flip_horizontal {
91 if ch.ch as u8 == 223 {
92 ch.ch = '\u{00DC}';
93 } else if ch.ch as u8 == 220 {
94 ch.ch = '\u{00DB}';
95 } else {
96 ch.ch = '\u{00DF}';
97 }
98 } else {
99 // vertical
100 if ch.ch as u8 == 222 {
101 ch.ch = '\u{00DD}';
102 } else if ch.ch as u8 == 221 {
103 ch.ch = '\u{00DB}';
104 } else {
105 ch.ch = '\u{00DE}';
106 }
107 }
108
109 editor.set_char(pos, ch);
110 }
111 None
112 }
113 } // [176, 177, 178, 219, 223, 220, 221, 222, 254, 250 ],