fix mutability of DrawArea
parent
9542592027
commit
742f0c1c8e
|
@ -25,22 +25,22 @@ pub trait DrawArea
|
|||
fn h(&self) -> Coord;
|
||||
|
||||
/// Fills the entire screen with `cr`. Will also default all settings.
|
||||
fn clear(&self, cr: impl Color);
|
||||
fn clear(&mut self, cr: impl Color);
|
||||
|
||||
/// Changes the width for lines. The default is `1`.
|
||||
fn line_width(&self, width: u8);
|
||||
fn line_width(&mut self, width: u8);
|
||||
|
||||
/// Draws a line from `p1` to `p2` with color `cr`.
|
||||
fn line(&self, p1: Point, p2: Point, cr: impl Color);
|
||||
fn line(&mut self, p1: Point, p2: Point, cr: impl Color);
|
||||
|
||||
/// Draws a rectangle `rect` of color `cr`.
|
||||
fn rect(&self, rect: Rect, cr: impl Color);
|
||||
fn rect(&mut self, rect: Rect, cr: impl Color);
|
||||
|
||||
/// Draws the Unicode `text` at `pos` stroked with color `cr`.
|
||||
fn text(&self, pos: Point, text: &str, cr: impl Color);
|
||||
fn text(&mut self, pos: Point, text: &str, cr: impl Color);
|
||||
|
||||
/// Draws `im` at `pos`, starting from the top left column.
|
||||
fn image(&self, pos: Point, im: &Self::NativeImage);
|
||||
fn image(&mut self, pos: Point, im: &Self::NativeImage);
|
||||
}
|
||||
|
||||
/// A type capable of representing any coordinate on any axis.
|
||||
|
|
|
@ -34,7 +34,7 @@ impl DrawArea for CrDrawArea
|
|||
fn w(&self) -> Coord {self.w}
|
||||
fn h(&self) -> Coord {self.h}
|
||||
|
||||
fn clear(&self, cr: impl Color)
|
||||
fn clear(&mut self, cr: impl Color)
|
||||
{
|
||||
self.rect(Rect{x: 0, y: 0, w: self.w(), h: self.h()}, cr);
|
||||
|
||||
|
@ -48,7 +48,7 @@ impl DrawArea for CrDrawArea
|
|||
}
|
||||
}
|
||||
|
||||
fn line_width(&self, width: u8)
|
||||
fn line_width(&mut self, width: u8)
|
||||
{
|
||||
let width = f64::from(width);
|
||||
|
||||
|
@ -57,7 +57,7 @@ impl DrawArea for CrDrawArea
|
|||
}
|
||||
}
|
||||
|
||||
fn line(&self, p1: Point, p2: Point, cr: impl Color)
|
||||
fn line(&mut self, p1: Point, p2: Point, cr: impl Color)
|
||||
{
|
||||
let (r, g, b) = flt_color(cr);
|
||||
|
||||
|
@ -75,7 +75,7 @@ impl DrawArea for CrDrawArea
|
|||
}
|
||||
}
|
||||
|
||||
fn rect(&self, rect: Rect, cr: impl Color)
|
||||
fn rect(&mut self, rect: Rect, cr: impl Color)
|
||||
{
|
||||
let px = f64::from(rect.x);
|
||||
let py = f64::from(rect.y);
|
||||
|
@ -91,7 +91,7 @@ impl DrawArea for CrDrawArea
|
|||
}
|
||||
}
|
||||
|
||||
fn text(&self, pos: Point, text: &str, cr: impl Color)
|
||||
fn text(&mut self, pos: Point, text: &str, cr: impl Color)
|
||||
{
|
||||
let (r, g, b) = flt_color(cr);
|
||||
|
||||
|
@ -107,7 +107,7 @@ impl DrawArea for CrDrawArea
|
|||
}
|
||||
}
|
||||
|
||||
fn image(&self, pos: Point, im: &Self::NativeImage)
|
||||
fn image(&mut self, pos: Point, im: &Self::NativeImage)
|
||||
{
|
||||
let x = f64::from(pos.0);
|
||||
let y = f64::from(pos.1);
|
||||
|
|
|
@ -75,9 +75,9 @@ unsafe fn setup_draw_area(b: *mut GtkBuilder, edit: Rc<MapEditorRef>)
|
|||
gtk_adjustment_set_upper(rend.ay, h);
|
||||
|
||||
let im = CrImage(rend.im_nomap);
|
||||
let dr = CrDrawArea::new(ctx, w, h);
|
||||
let mut dr = CrDrawArea::new(ctx, w, h);
|
||||
|
||||
rend.edit.borrow().draw(&dr, &im);
|
||||
rend.edit.borrow().draw(&mut dr, &im);
|
||||
|
||||
1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue