Added half block transparency colors. - 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 41a73b3cfa8464570a90cb154110473e4ac3781f
 (DIR) parent 84b3277c74cfa4ae7c792c319868edde17173e65
 (HTM) Author: Mike Krüger <mkrueger@posteo.de>
       Date:   Mon,  9 Oct 2023 23:24:47 +0200
       
       Added half block transparency colors.
       
       Fixes #31
       
       Diffstat:
         D src/paint/half_block.rs             |     143 -------------------------------
         M src/paint/mod.rs                    |       5 +----
         M src/plugins/mod.rs                  |       2 +-
       
       3 files changed, 2 insertions(+), 148 deletions(-)
       ---
 (DIR) diff --git a/src/paint/half_block.rs b/src/paint/half_block.rs
       @@ -1,143 +0,0 @@
       -use icy_engine::{AttributedChar, Position, TextAttribute};
       -
       -const FULL_BLOCK: char = 219 as char;
       -const HALF_BLOCK_TOP: char = 223 as char;
       -const HALF_BLOCK_BOTTOM: char = 220 as char;
       -const HALF_BLOCK_LEFT: char = 221 as char;
       -const HALF_BLOCK_RIGHT: char = 222 as char;
       -
       -const SPACE: char = 32 as char;
       -const ZERO: char = 0 as char;
       -const XFF: char = 255 as char;
       -
       -struct HalfBlock {
       -    pub block: AttributedChar,
       -    pub is_blocky: bool,
       -    pub is_vertically_blocky: bool,
       -
       -    pub upper_block_color: u32,
       -    pub lower_block_color: u32,
       -    pub is_top: bool,
       -}
       -
       -impl HalfBlock {
       -    pub fn from(block: AttributedChar, pos: Position) -> Self {
       -        let is_top = pos.y % 2 == 0;
       -
       -        let mut upper_block_color = 0;
       -        let mut lower_block_color = 0;
       -        let mut is_blocky = false;
       -        let mut is_vertically_blocky = false;
       -        match block.ch {
       -            ZERO | SPACE | XFF => {
       -                // all blank characters
       -                upper_block_color = block.attribute.get_background();
       -                lower_block_color = block.attribute.get_background();
       -                is_blocky = true;
       -            }
       -            HALF_BLOCK_BOTTOM => {
       -                upper_block_color = block.attribute.get_background();
       -                lower_block_color = block.attribute.get_foreground();
       -                is_blocky = true;
       -            }
       -            HALF_BLOCK_TOP => {
       -                upper_block_color = block.attribute.get_foreground();
       -                lower_block_color = block.attribute.get_background();
       -                is_blocky = true;
       -            }
       -            FULL_BLOCK => {
       -                upper_block_color = block.attribute.get_foreground();
       -                lower_block_color = block.attribute.get_foreground();
       -                is_blocky = true;
       -            }
       -            HALF_BLOCK_LEFT | HALF_BLOCK_RIGHT => {
       -                is_vertically_blocky = true;
       -            }
       -            _ => {
       -                if block.attribute.get_foreground() == block.attribute.get_background() {
       -                    is_blocky = true;
       -                    upper_block_color = block.attribute.get_foreground();
       -                    lower_block_color = block.attribute.get_foreground();
       -                } else {
       -                    is_blocky = false;
       -                }
       -            }
       -        }
       -
       -        Self {
       -            block,
       -            is_top,
       -            is_blocky,
       -            is_vertically_blocky,
       -            upper_block_color,
       -            lower_block_color,
       -        }
       -    }
       -}
       -
       -pub fn get_half_block(cur_char: AttributedChar, pos: Position, color: u32) -> AttributedChar {
       -    let half_block = HalfBlock::from(cur_char, pos);
       -
       -    let ch = if half_block.is_blocky {
       -        if (half_block.is_top && half_block.lower_block_color == color) || (!half_block.is_top && half_block.upper_block_color == color) {
       -            AttributedChar::new(FULL_BLOCK, TextAttribute::new(color, 0))
       -        } else if half_block.is_top {
       -            AttributedChar::new(HALF_BLOCK_TOP, TextAttribute::new(color, half_block.lower_block_color))
       -        } else {
       -            AttributedChar::new(HALF_BLOCK_BOTTOM, TextAttribute::new(color, half_block.upper_block_color))
       -        }
       -    } else if half_block.is_top {
       -        AttributedChar::new(HALF_BLOCK_TOP, TextAttribute::new(color, half_block.block.attribute.get_background()))
       -    } else {
       -        AttributedChar::new(HALF_BLOCK_BOTTOM, TextAttribute::new(color, half_block.block.attribute.get_background()))
       -    };
       -    optimize_block(ch, &half_block)
       -}
       -
       -fn flip_colors(attribute: icy_engine::TextAttribute) -> icy_engine::TextAttribute {
       -    let mut result = attribute;
       -    result.set_foreground(attribute.get_background());
       -    result.set_background(attribute.get_foreground());
       -    result
       -}
       -
       -fn optimize_block(mut block: AttributedChar, half_block: &HalfBlock) -> AttributedChar {
       -    if block.attribute.get_foreground() == 0 {
       -        if block.attribute.get_background() == 0 || block.ch == FULL_BLOCK {
       -            block.ch = ' ';
       -            return block;
       -        }
       -        match block.ch {
       -            HALF_BLOCK_BOTTOM => {
       -                return AttributedChar::new(HALF_BLOCK_TOP, flip_colors(block.attribute));
       -            }
       -            HALF_BLOCK_TOP => {
       -                return AttributedChar::new(HALF_BLOCK_BOTTOM, flip_colors(block.attribute));
       -            }
       -            _ => {}
       -        }
       -    } else if block.attribute.get_foreground() < 8 && block.attribute.get_background() >= 8 {
       -        if half_block.is_blocky {
       -            match block.ch {
       -                HALF_BLOCK_BOTTOM => {
       -                    return AttributedChar::new(HALF_BLOCK_TOP, flip_colors(block.attribute));
       -                }
       -                HALF_BLOCK_TOP => {
       -                    return AttributedChar::new(HALF_BLOCK_BOTTOM, flip_colors(block.attribute));
       -                }
       -                _ => {}
       -            }
       -        } else if half_block.is_vertically_blocky {
       -            match block.ch {
       -                HALF_BLOCK_LEFT => {
       -                    return AttributedChar::new(HALF_BLOCK_RIGHT, flip_colors(block.attribute));
       -                }
       -                HALF_BLOCK_RIGHT => {
       -                    return AttributedChar::new(HALF_BLOCK_LEFT, flip_colors(block.attribute));
       -                }
       -                _ => {}
       -            }
       -        }
       -    }
       -    block
       -}
 (DIR) diff --git a/src/paint/mod.rs b/src/paint/mod.rs
       @@ -6,9 +6,6 @@ use icy_engine_egui::BufferView;
        
        use crate::{create_font_image, create_hover_image, AnsiEditor, Message};
        
       -use self::half_block::get_half_block;
       -
       -mod half_block;
        mod rectangle;
        pub use rectangle::*;
        mod line;
       @@ -308,7 +305,7 @@ pub fn plot_point(buffer_view: &mut BufferView, pos: impl Into<Position>, mut mo
            }
            match mode {
                BrushMode::HalfBlock => {
       -            layer.set_char(text_pos, get_half_block(ch, pos, attribute.get_foreground()));
       +            layer.set_char(text_pos, icy_engine::paint::get_halfblock(ch, pos, attribute.get_foreground(), true));
                }
                BrushMode::Block => {
                    layer.set_char(text_pos, AttributedChar::new(219 as char, attribute));
 (DIR) diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs
       @@ -79,7 +79,7 @@ impl Plugin {
            pub fn read_plugin_directory() {
                let Ok(root) = Settings::get_plugin_directory() else {
                    log::error!("Can't read plugin directory.");
       -            return
       +            return;
                };
                let walker = WalkDir::new(root).into_iter();
                for entry in walker.filter_entry(|e| !FontTool::is_hidden(e)) {