Fixed palette switcher/removed unused code. - 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 1bf77a1f7f34bca0e2a369aee039c65271758bb6
 (DIR) parent 084fc722a761bf1b0e70a518916b30374d126cf8
 (HTM) Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Sun, 17 Sep 2023 11:04:06 +0200
       
       Fixed palette switcher/removed unused code.
       
       Diffstat:
         M src/ui/dialogs/select_palette_dial… |      19 +++++++++----------
         M src/ui/main_window.rs               |       7 +++++--
         M src/ui/palette_editor.rs            |     309 +------------------------------
       
       3 files changed, 17 insertions(+), 318 deletions(-)
       ---
 (DIR) diff --git a/src/ui/dialogs/select_palette_dialog.rs b/src/ui/dialogs/select_palette_dialog.rs
       @@ -8,8 +8,8 @@ use egui_file::FileDialog;
        use egui_modal::Modal;
        use i18n_embed_fl::fl;
        use icy_engine::{
       -    Palette, C64_DEFAULT_PALETTE, DOS_DEFAULT_PALETTE, EGA_PALETTE, VIEWDATA_PALETTE,
       -    XTERM_256_PALETTE, PaletteFormat,
       +    Palette, PaletteFormat, C64_DEFAULT_PALETTE, DOS_DEFAULT_PALETTE, EGA_PALETTE,
       +    VIEWDATA_PALETTE, XTERM_256_PALETTE,
        };
        use walkdir::WalkDir;
        
       @@ -310,11 +310,11 @@ impl crate::ModalDialog for SelectPaletteDialog {
                if let Some(ed) = &mut self.export_dialog {
                    if ed.show(ctx).selected() {
                        if let Some(res) = ed.path() {
       -                    let s  =self.selected_palette as usize;
       +                    let s = self.selected_palette as usize;
                            if s < self.palettes.len() {
                                let res = res.with_extension("gpl");
                                let data = self.palettes[s].0.export_palette(&PaletteFormat::Gpl);
       -                        if let Err(err)= fs::write(res, data) {
       +                        if let Err(err) = fs::write(res, data) {
                                    log::error!("Error exporting palette: {err}");
                                }
                            }
       @@ -325,7 +325,6 @@ impl crate::ModalDialog for SelectPaletteDialog {
                    }
                }
        
       -
                let mut result = false;
                let modal = Modal::new(ctx, "select_font_dialog2");
                let palette_count = self.palettes.len();
       @@ -439,11 +438,11 @@ impl crate::ModalDialog for SelectPaletteDialog {
                            result = true;
                        }
                        if ui
       -                .button(fl!(crate::LANGUAGE_LOADER, "new-file-cancel"))
       -                .clicked()
       -            {
       -                result = true;
       -            }
       +                    .button(fl!(crate::LANGUAGE_LOADER, "new-file-cancel"))
       +                    .clicked()
       +                {
       +                    result = true;
       +                }
        
                        if ui
                            .button(fl!(crate::LANGUAGE_LOADER, "export-button-title"))
 (DIR) diff --git a/src/ui/main_window.rs b/src/ui/main_window.rs
       @@ -587,9 +587,12 @@ impl eframe::App for MainWindow {
                        ui.vertical_centered(|ui| {
                            msg = crate::palette_switcher(ctx, ui, &caret_attr, &palette);
                        });
       -              
       +
                        ui.separator();
       -                crate::palette_editor_16(ui, &caret_attr, &palette, buffer_type);
       +                let msg2 = crate::palette_editor_16(ui, &caret_attr, &palette, buffer_type);
       +                if msg.is_none() {
       +                    msg = msg2;
       +                }
        
                        if buffer_type.has_blink()
                            && ui
 (DIR) diff --git a/src/ui/palette_editor.rs b/src/ui/palette_editor.rs
       @@ -1,8 +1,7 @@
        use crate::{Message, SWAP_SVG};
       -use eframe::egui::{self, Sense,  TextStyle, Ui};
       -use eframe::emath::Align2;
       -use eframe::epaint::{Color32, FontId, Pos2, Rect, Rounding, Stroke, Vec2};
       -use icy_engine::{BufferType, Palette, TextAttribute, XTERM_256_PALETTE};
       +use eframe::egui::{self, Sense};
       +use eframe::epaint::{Color32, Pos2, Rect, Rounding, Stroke, Vec2};
       +use icy_engine::{BufferType, Palette, TextAttribute};
        use std::cmp::min;
        
        pub fn palette_switcher(
       @@ -275,304 +274,3 @@ pub fn palette_editor_16(
        
            result
        }
       -
       -pub fn show_extended_palette(ui: &mut Ui) -> Option<Message> {
       -    let mut result = None;
       -
       -    let row_height = 24.0;
       -    egui::ScrollArea::vertical()
       -        .id_source("bitfont_scroll_area")
       -        .max_height(200.)
       -        .show_rows(ui, row_height, XTERM_256_PALETTE.len(), |ui, range| {
       -            for idx in range {
       -                ui.horizontal(|ui| {
       -                    ui.add_space(4.0);
       -                    let width = ui.available_width();
       -
       -                    let (id, back_rect) = ui.allocate_space(Vec2::new(width, row_height));
       -                    let mut response = ui.interact(back_rect, id, Sense::click());
       -
       -                    let back_painter = ui.painter_at(back_rect);
       -
       -                    if response.hovered() {
       -                        back_painter.rect_filled(
       -                            back_rect,
       -                            Rounding::none(),
       -                            ui.style().visuals.widgets.active.bg_fill,
       -                        );
       -                    }
       -
       -                    let stroke_rect = Rect::from_min_size(
       -                        back_rect.min + Vec2::new(0.0, 1.0),
       -                        Vec2::new(52.0, 22.0),
       -                    );
       -
       -                    let painter = ui.painter_at(stroke_rect);
       -
       -                    let (r, g, b) = XTERM_256_PALETTE[idx].1.clone().get_rgb();
       -                    painter.rect_filled(stroke_rect, Rounding::none(), Color32::BLACK);
       -                    painter.rect_filled(stroke_rect.shrink(1.0), Rounding::none(), Color32::WHITE);
       -                    let color = Color32::from_rgb(r, g, b);
       -                    painter.rect_filled(stroke_rect.shrink(2.0), Rounding::none(), color);
       -
       -                    let text_color =
       -                        if (r as f32 * 0.299 + g as f32 * 0.587 + b as f32 * 0.114) > 186.0 {
       -                            Color32::BLACK
       -                        } else {
       -                            Color32::WHITE
       -                        };
       -
       -                    let text = format!("#{:02x}{:02x}{:02x}", r, g, b);
       -                    let font_id: eframe::epaint::FontId = FontId::monospace(10.0);
       -                    painter.text(
       -                        stroke_rect.left_center() + Vec2::new(4., 0.),
       -                        Align2::LEFT_CENTER,
       -                        text,
       -                        font_id,
       -                        text_color,
       -                    );
       -
       -                    let font_id = TextStyle::Button.resolve(ui.style());
       -
       -                    let color = if response.hovered() {
       -                        ui.style().visuals.strong_text_color()
       -                    } else {
       -                        ui.style().visuals.text_color()
       -                    };
       -
       -                    back_painter.text(
       -                        stroke_rect.right_center() + Vec2::new(4., 0.),
       -                        Align2::LEFT_CENTER,
       -                        XTERM_256_PALETTE[idx].0,
       -                        font_id,
       -                        color,
       -                    );
       -
       -                    if response.clicked() {
       -                        result = Some(Message::SetForegroundRgb(r, g, b));
       -                        response.mark_changed();
       -                    }
       -
       -                    if response.secondary_clicked() {
       -                        result = Some(Message::SetBackgroundRgb(r, g, b));
       -                        response.mark_changed();
       -                    }
       -                    response
       -                });
       -            }
       -        });
       -    result
       -}
       -/* 
       -static mut CUR_COLOR: [u8; 3] = [0xFF, 0xFF, 0xFF];
       -static mut RENAME_INDEX: Option<usize> = None;
       -static mut EDIT_INDEX: Option<usize> = None;
       -
       -pub fn show_custom_palette(ui: &mut egui::Ui) -> Option<Message> {
       -    let mut result = None;
       -
       -    let pal = Settings::get_custom_palette();
       -
       -    let row_height = 24.0;
       -    egui::ScrollArea::vertical()
       -        .id_source("bitfont_scroll_area")
       -        .max_height(200.)
       -        .show_rows(ui, row_height, pal.len() + 1, |ui, range| {
       -            for idx in range {
       -                if idx > pal.len() {
       -                    break;
       -                }
       -                if idx == pal.len() {
       -                    ui.horizontal(|ui| {
       -                        ui.add_space(4.0);
       -                        unsafe {
       -                            color_picker::color_edit_button_srgb(ui, &mut CUR_COLOR);
       -                            if ui.button("+").clicked() {
       -                                Settings::get_custom_palette().push_rgb(
       -                                    CUR_COLOR[0],
       -                                    CUR_COLOR[1],
       -                                    CUR_COLOR[2],
       -                                );
       -                            }
       -                        }
       -                    });
       -                    continue;
       -                }
       -
       -                unsafe {
       -                    if let Some(edit_index) = EDIT_INDEX {
       -                        if edit_index == idx {
       -                            ui.horizontal(|ui| {
       -                                ui.add_space(4.0);
       -                                let (r, g, b) = pal.colors[idx].get_rgb();
       -                                let mut col = [r, g, b];
       -                                color_picker::color_edit_button_srgb(ui, &mut col);
       -                                pal.colors[idx].set_rgb(col[0], col[1], col[2]);
       -
       -                                if ui
       -                                    .button(fl!(crate::LANGUAGE_LOADER, "new-file-ok"))
       -                                    .clicked()
       -                                {
       -                                    EDIT_INDEX = None;
       -                                }
       -                            });
       -                            continue;
       -                        }
       -                    }
       -                }
       -
       -                let mut in_rename = false;
       -                unsafe {
       -                    if let Some(rename_index) = RENAME_INDEX {
       -                        if rename_index == idx {
       -                            in_rename = true;
       -                        }
       -                    }
       -                }
       -
       -                ui.horizontal(|ui| {
       -                    ui.add_space(4.0);
       -                    let width = if in_rename {
       -                        55.0
       -                    } else {
       -                        ui.available_width()
       -                    };
       -                    let (id, back_rect) = ui.allocate_space(Vec2::new(width, row_height));
       -                    let mut response = ui.interact(
       -                        Rect::from_min_size(
       -                            back_rect.min,
       -                            Vec2::new(back_rect.width(), back_rect.height()),
       -                        ),
       -                        id,
       -                        Sense::click(),
       -                    );
       -
       -                    let back_painter = ui.painter_at(back_rect);
       -
       -                    let is_hovered = response.hovered();
       -
       -                    if is_hovered {
       -                        back_painter.rect_filled(
       -                            back_rect,
       -                            Rounding::none(),
       -                            ui.style().visuals.widgets.active.bg_fill,
       -                        );
       -                    }
       -
       -                    let stroke_rect = Rect::from_min_size(
       -                        back_rect.min + Vec2::new(0.0, 1.0),
       -                        Vec2::new(52.0, 22.0),
       -                    );
       -
       -                    let painter = ui.painter_at(stroke_rect);
       -
       -                    let (r, g, b) = pal.colors[idx].get_rgb();
       -                    painter.rect_filled(stroke_rect, Rounding::none(), Color32::BLACK);
       -                    painter.rect_filled(stroke_rect.shrink(1.0), Rounding::none(), Color32::WHITE);
       -                    let color = Color32::from_rgb(r, g, b);
       -                    painter.rect_filled(stroke_rect.shrink(2.0), Rounding::none(), color);
       -
       -                    let text_color =
       -                        if (r as f32 * 0.299 + g as f32 * 0.587 + b as f32 * 0.114) > 186.0 {
       -                            Color32::BLACK
       -                        } else {
       -                            Color32::WHITE
       -                        };
       -
       -                    let text = pal.colors[idx].get_rgb_text();
       -                    let font_id: eframe::epaint::FontId = FontId::monospace(10.0);
       -                    painter.text(
       -                        stroke_rect.left_center() + Vec2::new(4., 0.),
       -                        Align2::LEFT_CENTER,
       -                        text,
       -                        font_id,
       -                        text_color,
       -                    );
       -
       -                    let font_id = TextStyle::Button.resolve(ui.style());
       -
       -                    let color = if response.hovered() {
       -                        ui.style().visuals.strong_text_color()
       -                    } else {
       -                        ui.style().visuals.text_color()
       -                    };
       -
       -                    if in_rename {
       -                        let mut name = pal.colors[idx].get_name();
       -                        ui.add(TextEdit::singleline(&mut name).desired_width(120.0));
       -                        pal.colors[idx].set_name(name);
       -
       -                        if ui
       -                            .button(fl!(crate::LANGUAGE_LOADER, "new-file-ok"))
       -                            .clicked()
       -                        {
       -                            unsafe {
       -                                RENAME_INDEX = None;
       -                            }
       -                        }
       -                    } else {
       -                        back_painter.text(
       -                            stroke_rect.right_center() + Vec2::new(4., 0.),
       -                            Align2::LEFT_CENTER,
       -                            pal.colors[idx].get_name(),
       -                            font_id,
       -                            color,
       -                        );
       -
       -                        let mut add_context_menu = true;
       -                        if let Some(pos) = response.interact_pointer_pos() {
       -                            if stroke_rect.contains(pos) {
       -                                add_context_menu = false;
       -                                if response.clicked() {
       -                                    result = Some(Message::SetForegroundRgb(r, g, b));
       -                                }
       -
       -                                if response.secondary_clicked() {
       -                                    result = Some(Message::SetBackgroundRgb(r, g, b));
       -                                    return response;
       -                                }
       -                            }
       -                        }
       -
       -                        if add_context_menu {
       -                            response = response.context_menu(|ui| {
       -                                if ui
       -                                    .button(fl!(crate::LANGUAGE_LOADER, "menu-rename"))
       -                                    .clicked()
       -                                {
       -                                    unsafe {
       -                                        RENAME_INDEX = Some(idx);
       -                                    }
       -                                    ui.close_menu();
       -                                }
       -
       -                                if ui
       -                                    .button(fl!(crate::LANGUAGE_LOADER, "menu-edit"))
       -                                    .clicked()
       -                                {
       -                                    unsafe {
       -                                        EDIT_INDEX = Some(idx);
       -                                    }
       -                                    ui.close_menu();
       -                                }
       -                                ui.separator();
       -                                if ui
       -                                    .button(fl!(crate::LANGUAGE_LOADER, "menu-delete"))
       -                                    .clicked()
       -                                {
       -                                    if idx < pal.colors.len() {
       -                                        pal.colors.remove(idx);
       -                                    }
       -                                    ui.close_menu();
       -                                }
       -                            });
       -                        }
       -                    }
       -
       -                    response
       -                });
       -            }
       -        });
       -    result
       -}
       -*/
       -\ No newline at end of file