Added menu commands for setting 9px & lga modes. - 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
       ---
 (DIR) commit ab2dc039a57507a0e1c45b664b1a1979f349f76e
 (DIR) parent 3a706d6ec6e64a2eabc8bc2fc2894162c4dba487
 (HTM) Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Wed, 20 Sep 2023 13:09:46 +0200
       
       Added menu commands for setting 9px & lga modes.
       
       Diffstat:
         M i18n/de/icy_draw.ftl                |       6 ++++--
         M i18n/en/icy_draw.ftl                |       6 ++++--
         M src/ui/commands.rs                  |      54 +++++++++++++++++++++++++++++++
         M src/ui/document_docking.rs          |       4 ++--
         M src/ui/main_window.rs               |       4 +++-
         M src/ui/messages.rs                  |      57 ++++++++++++++++++++++++++++++-
         M src/ui/top_bar.rs                   |       3 +++
       
       7 files changed, 126 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/i18n/de/icy_draw.ftl b/i18n/de/icy_draw.ftl
       @@ -9,6 +9,8 @@ menu-open_recent=Zuletzt geöffnet
        menu-open_recent_clear=Liste leeren
        menu-save=Speichern
        menu-edit-sauce=SAUCE Info bearbeiten…
       +menu-9px-font=9px Font
       +menu-aspect-ratio=Klassisches Seitenverhältnis
        menu-set-canvas-size=Leinwandgröße ändern…
        menu-close=Schließen
        menu-save-as=Speichern unter…
       @@ -150,8 +152,8 @@ edit-sauce-author-label-length=(20 Zeichen)
        edit-sauce-group-label=Grupe:
        edit-sauce-group-label-length=(20 Zeichen)
        edit-sauce-comments-label=Kommentare:
       -edit-sauce-letter-spacing=Zeichenabstand:
       -edit-sauce-aspect-ratio=Seitenverhältnis:
       +edit-sauce-letter-spacing=9 Pixel Modus:
       +edit-sauce-aspect-ratio=Klassisches Seitenverhältnis:
        
        edit-canvas-size-title=Leinwandgröße
        edit-canvas-size-width-label=Breite:
 (DIR) diff --git a/i18n/en/icy_draw.ftl b/i18n/en/icy_draw.ftl
       @@ -9,6 +9,8 @@ menu-open_recent=Open Recent
        menu-open_recent_clear=Clear
        menu-save=Save
        menu-edit-sauce=Edit Sauce Info…
       +menu-9px-font=9px Font
       +menu-aspect-ratio=Legacey Aspect Ratio
        menu-set-canvas-size=Set Canvas Size…
        menu-close=Close
        menu-save-as=Save As…
       @@ -145,8 +147,8 @@ edit-sauce-author-label-length=(20 chars)
        edit-sauce-group-label=Group:
        edit-sauce-group-label-length=(20 chars)
        edit-sauce-comments-label=Comments
       -edit-sauce-letter-spacing=Letter spacing:
       -edit-sauce-aspect-ratio=Aspect ratio:
       +edit-sauce-letter-spacing=Use 9px mode:
       +edit-sauce-aspect-ratio=Simulate classic aspect ratio:
        
        edit-canvas-size-title=Set Canvas Size
        edit-canvas-size-width-label=Width:
 (DIR) diff --git a/src/ui/commands.rs b/src/ui/commands.rs
       @@ -159,6 +159,53 @@ impl CommandState for CanPasteState {
            }
        }
        
       +#[derive(Default)]
       +pub struct LGAFontState {}
       +
       +impl CommandState for LGAFontState {
       +    fn is_enabled(&self, open_tab_opt: Option<&DocumentTab>) -> bool {
       +        if let Some(pane) = open_tab_opt {
       +            if let Ok(doc) = pane.doc.lock() {
       +                return doc.get_ansi_editor().is_some();
       +            }
       +        }
       +        false
       +    }
       +    fn is_checked(&self, open_tab_opt: Option<&DocumentTab>) -> Option<bool> {
       +        if let Some(pane) = open_tab_opt {
       +            if let Ok(doc) = pane.doc.lock() {
       +                if let Some(editor) = doc.get_ansi_editor() {
       +                    return Some(editor.buffer_view.lock().get_buffer().use_letter_spacing());
       +                }
       +            }
       +        }
       +        Some(false)
       +    }
       +}
       +#[derive(Default)]
       +pub struct AspectRatioState {}
       +
       +impl CommandState for AspectRatioState {
       +    fn is_enabled(&self, open_tab_opt: Option<&DocumentTab>) -> bool {
       +        if let Some(pane) = open_tab_opt {
       +            if let Ok(doc) = pane.doc.lock() {
       +                return doc.get_ansi_editor().is_some();
       +            }
       +        }
       +        false
       +    }
       +    fn is_checked(&self, open_tab_opt: Option<&DocumentTab>) -> Option<bool> {
       +        if let Some(pane) = open_tab_opt {
       +            if let Ok(doc) = pane.doc.lock() {
       +                if let Some(editor) = doc.get_ansi_editor() {
       +                    return Some(editor.buffer_view.lock().get_buffer().use_aspect_ratio());
       +                }
       +            }
       +        }
       +        Some(false)
       +    }
       +}
       +
        pub struct CommandWrapper {
            key: Option<(KeyOrPointer, Modifiers)>,
            message: Message,
       @@ -838,4 +885,11 @@ keys![
                ArrowLeft,
                CTRL
            ),
       +    (lga_font, "menu-9px-font", ToggleLGAFont, LGAFontState),
       +    (
       +        aspect_ratio,
       +        "menu-aspect-ratio",
       +        ToggleAspectRatio,
       +        AspectRatioState
       +    ),
        ];
 (DIR) diff --git a/src/ui/document_docking.rs b/src/ui/document_docking.rs
       @@ -29,7 +29,7 @@ pub struct DocumentTab {
            auto_save_status: usize,
            instant: Instant,
            last_change_autosave_timer: usize,
       -    destroyed: bool
       +    destroyed: bool,
        }
        impl DocumentTab {
            pub fn is_dirty(&self) -> bool {
       @@ -451,7 +451,7 @@ pub fn add_child(
                last_save: 0,
                instant: Instant::now(),
                last_change_autosave_timer: 0,
       -        destroyed: false
       +        destroyed: false,
            };
            let new_child = tree.tiles.insert_pane(tile);
        
 (DIR) diff --git a/src/ui/main_window.rs b/src/ui/main_window.rs
       @@ -528,7 +528,9 @@ impl MainWindow {
                let mut msg = None;
                if let Some(egui_tiles::Tile::Pane(pane)) = self.document_tree.tiles.get(close_id) {
                    if !pane.is_dirty() {
       -                if let Some(egui_tiles::Tile::Pane(pane)) = self.document_tree.tiles.get_mut(close_id) {
       +                if let Some(egui_tiles::Tile::Pane(pane)) =
       +                    self.document_tree.tiles.get_mut(close_id)
       +                {
                            msg = pane.destroy(&self.gl);
                        }
                        self.document_tree.tiles.remove(close_id);
 (DIR) diff --git a/src/ui/messages.rs b/src/ui/messages.rs
       @@ -11,7 +11,8 @@ use eframe::{
            epaint::Vec2,
        };
        use icy_engine::{
       -    util::pop_data, BitFont, EngineResult, Layer, Size, TextAttribute, TextPane, TheDrawFont,
       +    util::pop_data, BitFont, EngineResult, Layer, SauceData, Size, TextAttribute, TextPane,
       +    TheDrawFont,
        };
        
        use crate::{
       @@ -146,6 +147,8 @@ pub enum Message {
            NextBgColor,
            PreviousBgColor,
            ShowSettings,
       +    ToggleLGAFont,
       +    ToggleAspectRatio,
        }
        
        pub const CTRL_SHIFT: egui::Modifiers = egui::Modifiers {
       @@ -1135,6 +1138,58 @@ impl MainWindow {
                        self.show_settings = true;
                        self.settings_dialog.init();
                    }
       +
       +            Message::ToggleLGAFont => {
       +                self.run_editor_command(0, |_, editor, _| {
       +                    let use_lga = editor
       +                        .buffer_view
       +                        .lock()
       +                        .get_buffer_mut()
       +                        .use_letter_spacing();
       +                    let mut sauce_data = if let Some(data) =
       +                        &editor.buffer_view.lock().get_buffer_mut().sauce_data
       +                    {
       +                        data.clone()
       +                    } else {
       +                        SauceData::default()
       +                    };
       +                    sauce_data.use_letter_spacing = !use_lga;
       +
       +                    to_message(
       +                        editor
       +                            .buffer_view
       +                            .lock()
       +                            .get_edit_state_mut()
       +                            .update_sauce_data(Some(sauce_data)),
       +                    )
       +                });
       +            }
       +
       +            Message::ToggleAspectRatio => {
       +                self.run_editor_command(0, |_, editor, _| {
       +                    let use_ar = editor
       +                        .buffer_view
       +                        .lock()
       +                        .get_buffer_mut()
       +                        .use_aspect_ratio();
       +                    let mut sauce_data = if let Some(data) =
       +                        &editor.buffer_view.lock().get_buffer_mut().sauce_data
       +                    {
       +                        data.clone()
       +                    } else {
       +                        SauceData::default()
       +                    };
       +                    sauce_data.use_aspect_ratio = !use_ar;
       +
       +                    to_message(
       +                        editor
       +                            .buffer_view
       +                            .lock()
       +                            .get_edit_state_mut()
       +                            .update_sauce_data(Some(sauce_data)),
       +                    )
       +                });
       +            }
                }
            }
        }
 (DIR) diff --git a/src/ui/top_bar.rs b/src/ui/top_bar.rs
       @@ -216,6 +216,9 @@ impl MainWindow {
                            result = Some(Message::EditSauce);
                            ui.close_menu();
                        }
       +                self.commands[0].lga_font.ui(ui, &mut result);
       +                self.commands[0].aspect_ratio.ui(ui, &mut result);
       +                ui.separator();
        
                        if ui
                            .add_enabled(