Skip to content

Commit

Permalink
Implemented object selection, deleting, undo and redo
Browse files Browse the repository at this point in the history
  • Loading branch information
T4r4sB committed Oct 11, 2022
1 parent 856a634 commit c1305f6
Show file tree
Hide file tree
Showing 25 changed files with 2,067 additions and 549 deletions.
6 changes: 3 additions & 3 deletions application/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Font {
for c in text.chars() {
match self.get_char(c, line) {
Some(Glyph::NoAA(img)) => {
dst.draw(img.as_view(), position, |dst, src| {
dst.draw(&img.as_view(), position, |dst, src| {
if *src {
*dst = color;
}
Expand All @@ -213,7 +213,7 @@ impl Font {
}
Some(Glyph::AA(img_black, img_white)) => {
let img = if self.light { &img_white } else { &img_black };
dst.draw(img.as_view(), position, |dst, src| {
dst.draw(&img.as_view(), position, |dst, src| {
let dst_r = (*dst & 0xFF) as i32;
let dst_g = ((*dst >> 8) & 0xFF) as i32;
let dst_b = ((*dst >> 16) & 0xFF) as i32;
Expand All @@ -238,7 +238,7 @@ impl Font {
}
Some(Glyph::TT(img_black, img_white)) => {
let img = if self.light { &img_white } else { &img_black };
dst.draw(img.as_view(), position, |dst, src| {
dst.draw(&img.as_view(), position, |dst, src| {
let dst_r = (*dst & 0xFF) as i32;
let dst_g = ((*dst >> 8) & 0xFF) as i32;
let dst_b = ((*dst >> 16) & 0xFF) as i32;
Expand Down
181 changes: 102 additions & 79 deletions application/src/gui/gui_components.rs

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions application/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ impl std::fmt::Debug for HotkeyCallback {
}
}

impl HotkeyCallback {
pub fn new(f: Rc<dyn Fn() + 'static>) -> Self {
Self(f)
}
}

#[derive(Debug)]
pub struct GuiControlBase {
pub(crate) size_constraints: SizeConstraints,
Expand Down Expand Up @@ -107,6 +113,17 @@ impl GuiControlBase {
self.current_size_constraints = constraints;
self.minimal_size = (constraints.0.absolute, constraints.1.absolute);
}

pub fn get_rect(&self) -> Rect {
self.rect
}

pub fn get_size(&self) -> Position {
(
self.rect.right_bottom.0 - self.rect.left_top.0,
self.rect.right_bottom.1 - self.rect.left_top.1,
)
}
}

pub enum GuiMessage<'i, 'j> {
Expand Down Expand Up @@ -155,10 +172,10 @@ pub static DARK_THEME: GuiColorTheme = GuiColorTheme {
background: 0x000000,
font: 0xCCCCCC,
splitter: 0xAACCAA,
highlight: 0x9999CC,
highlight: 0xCCAA88,
pressed: 0xFFFFFF,
selected: 0x66CC66,
inactive: 0x555555,
inactive: 0x666666,
edit_focused: 0x999999,
};

Expand All @@ -169,7 +186,7 @@ pub static LIGHT_THEME: GuiColorTheme = GuiColorTheme {
highlight: 0x779966,
pressed: 0x222222,
selected: 0xCC8844,
inactive: 0xAAAAAA,
inactive: 0xBBBBBB,
edit_focused: 0xEEEEEE,
};

Expand Down
24 changes: 23 additions & 1 deletion application/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ macro_rules! lines {

macro_rules! window {
($self: expr, $left_top: ident, $right_bottom: ident, $result: ident) => {
assert!($left_top.0 <= $right_bottom.0);
assert!($right_bottom.0 <= $self.size.0);
assert!($left_top.1 <= $right_bottom.1);
assert!($right_bottom.1 <= $self.size.1);
unsafe {
return $result::from_raw(
Expand Down Expand Up @@ -120,7 +122,7 @@ impl<'i, Pixel> ImageViewMut<'i, Pixel> {

pub fn draw<SrcPixel>(
&mut self,
src: ImageView<SrcPixel>,
src: &ImageView<SrcPixel>,
position: Position,
apply: impl Fn(&mut Pixel, &SrcPixel),
) {
Expand Down Expand Up @@ -197,6 +199,26 @@ impl<'i, Pixel> ImageViewMut<'i, Pixel> {
}
}
}

pub fn fill_with_coord(&mut self, apply: impl Fn(&mut Pixel, (usize, usize))) {
unsafe {
let mut y = 0;
let mut dsty = self.memory;
let dsty_end = self.memory.add(self.stride * self.size.1);
while dsty < dsty_end {
let mut x = 0;
let mut dstx = dsty;
let dstx_end = dstx.add(self.size.0);
while dstx < dstx_end {
apply(&mut *dstx, (x, y));
x += 1;
dstx = dstx.add(1);
}
y += 1;
dsty = dsty.add(self.stride);
}
}
}
}

pub struct ImageView<'i, Pixel> {
Expand Down
8 changes: 4 additions & 4 deletions application/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl std::fmt::Debug for Key {
Self::Right => f.pad("Right"),
Self::Up => f.pad("Up"),
Self::Down => f.pad("Down"),
Self::Backspace => f.pad("Backspace"),
Self::Delete => f.pad("Delete"),
Self::Insert => f.pad("Insert"),
Self::Backspace => f.pad("Back"),
Self::Delete => f.pad("Del"),
Self::Insert => f.pad("Ins"),
Self::Numpad0 => f.pad("Numpad 0"),
Self::Numpad1 => f.pad("Numpad 1"),
Self::Numpad2 => f.pad("Numpad 2"),
Expand All @@ -140,7 +140,7 @@ impl std::fmt::Debug for Key {
Self::Numpad7 => f.pad("Numpad 7"),
Self::Numpad8 => f.pad("Numpad 8"),
Self::Numpad9 => f.pad("Numpad 9"),
Self::Escape => f.pad("Escape"),
Self::Escape => f.pad("Esc"),
Self::Enter => f.pad("Enter"),
Self::F1 => f.pad("F1"),
Self::F2 => f.pad("F2"),
Expand Down
185 changes: 0 additions & 185 deletions curves/src/curves.rs

This file was deleted.

Loading

0 comments on commit c1305f6

Please sign in to comment.