pub struct PaintCtx<'a> { /* private fields */ }Expand description
Context for painting by app into window.
Implementations§
Source§impl<'a> PaintCtx<'a>
impl<'a> PaintCtx<'a>
Sourcepub fn d2d_factory(&self) -> &Factory
pub fn d2d_factory(&self) -> &Factory
Return the raw Direct2D factory for this painting context. Note: it’s possible this will be wrapped to make it easier to port.
Sourcepub fn render_target(&mut self) -> &mut GenericRenderTarget
pub fn render_target(&mut self) -> &mut GenericRenderTarget
Return the raw Direct2D RenderTarget for this painting context. Note: it’s possible this will be wrapped to make it easier to port.
Examples found in repository?
More examples
examples/perftest.rs (line 50)
48 fn paint(&self, paint_ctx: &mut PaintCtx) -> bool {
49 let mut state = self.0.borrow_mut();
50 let rt = paint_ctx.render_target();
51 let size = rt.get_size();
52 let rect = RectF::from((0.0, 0.0, size.width, size.height));
53 let bg = SolidColorBrush::create(rt).with_color(0x272822).build().unwrap();
54 let fg = SolidColorBrush::create(rt).with_color(0xf0f0ea).build().unwrap();
55 rt.fill_rectangle(rect, &bg);
56
57 rt.draw_line((0.0, size.height), (size.width, 0.0), &fg, 1.0, None);
58
59 let th = ::std::f32::consts::PI * (get_time().nsec as f32) * 2e-9;
60 let dx = 100.0 * th.sin();
61 let dy = 100.0 * th.cos();
62 rt.draw_line((100.0, 100.0), (100.0 + dx, 100.0 - dy),
63 &fg, 1.0, None);
64
65 let text_format = TextFormat::create(&state.dwrite_factory)
66 .with_family("Consolas")
67 .with_size(15.0)
68 .build()
69 .unwrap();
70
71 let now = get_time();
72 let now = now.sec as f64 + 1e-9 * now.nsec as f64;
73 let msg = format!("{:3.1}ms", 1e3 * (now - state.last_time));
74 state.last_time = now;
75 rt.draw_text(
76 &msg,
77 &text_format,
78 (10.0, 210.0, 100.0, 300.0),
79 &fg,
80 default_text_options()
81 );
82
83 let msg = "Hello DWrite! This is a somewhat longer string of text intended to provoke slightly longer draw times.";
84 let dy = 15.0;
85 let x0 = 210.0;
86 let y0 = 10.0;
87 for i in 0..60 {
88 let y = y0 + (i as f32) * dy;
89 rt.draw_text(
90 msg,
91 &text_format,
92 (x0, y, x0 + 900.0, y + 80.0),
93 &fg,
94 default_text_options()
95 );
96 }
97
98 true
99 }Auto Trait Implementations§
impl<'a> Freeze for PaintCtx<'a>
impl<'a> RefUnwindSafe for PaintCtx<'a>
impl<'a> Send for PaintCtx<'a>
impl<'a> Sync for PaintCtx<'a>
impl<'a> Unpin for PaintCtx<'a>
impl<'a> !UnwindSafe for PaintCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more