mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-30 18:14:00 +01:00
Keep the right-click popup's brush pictures apart from the docked panel's
The popup and the docked panel draw the brush preview, stamp dial and jitter strip at their own widths through one cache entry per picture, so each frame one replaced the other's texture: the popup's pictures came out blank and both were rendered again every frame. The cache now keeps one entry per drawing layer.
This commit is contained in:
1 parent
bec8934c80
commit
a82b9312fd
2 files changed
+23
-1
No files matched your search
@@ -53,7 +53,8 @@ impl BrushStrokePreview {
|
||||
let pixels_per_point = ctx.pixels_per_point();
|
||||
let size = [(rect.width() * pixels_per_point).round().max(1.0) as usize, (rect.height() * pixels_per_point).round().max(1.0) as usize];
|
||||
let tints: Vec<[u8; 3]> = (0..size[0]).map(|x| tint((x as f32 + 0.5) / size[0] as f32)).collect();
|
||||
let id = Id::unique(key);
|
||||
// The docked panel and the right-click popup draw the same picture at their own widths: one cache each
|
||||
let id = Id::unique(key).with(painter.layer_id());
|
||||
let cached = ctx.data(|data| data.get_temp::<BrushStrokePreview>(id)).filter(|preview| {
|
||||
preview.brush == *brush && preview.size == size && preview.tints == tints && preview.image.as_ref().map(Arc::as_ptr) == image.map(Arc::as_ptr)
|
||||
});
|
||||
|
||||
@@ -201,6 +201,27 @@ fn it_shows_what_the_properties_panel_shows() {
|
||||
assert!(!in_popup("Minimum Size (%)"), "not the brush's");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn its_brush_pictures_and_the_docked_panels_keep_their_own_textures() {
|
||||
let mut harness = harness();
|
||||
let center = view_center(&harness);
|
||||
click(&mut harness, PointerButton::Secondary, center);
|
||||
|
||||
assert!(is_open(&harness));
|
||||
|
||||
let previews = |harness: &Harness<'_, TextureCraftApp>| {
|
||||
let mut ids: Vec<_> =
|
||||
harness.ctx.tex_manager().read().allocated().filter(|(_, texture)| texture.name == "brush_stroke_preview").map(|(id, _)| *id).collect();
|
||||
ids.sort_unstable_by_key(|id| format!("{id:?}"));
|
||||
ids
|
||||
};
|
||||
let before = previews(&harness);
|
||||
harness.run_steps(SETTLE_FRAMES);
|
||||
|
||||
assert_eq!(before.len(), 2, "one stroke preview for the docked panel and one for the popup");
|
||||
assert_eq!(previews(&harness), before, "neither is drawn again while the brush stays the same");
|
||||
}
|
||||
|
||||
/// Whether the jump tab `name` inside `area` is the lit one
|
||||
fn tab_lit(harness: &Harness<'_, TextureCraftApp>, area: egui::Rect, name: &str) -> bool {
|
||||
let tab = harness.get_all_by_role_and_label(Role::Tab, name).find(|tab| area.contains_rect(tab.rect()));
|
||||
|
||||
Reference in new issue
Block a user