1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use super::prelude::*;
use super::{FractalViewManager, MandelbrotViewManager, DoubleViewManager};
use wgpu::{Device, SwapChainOutput, CommandBuffer};
use winit::event::{MouseButton, ElementState};
use winit::dpi::{PhysicalSize, LogicalSize};
use crate::utils::CurrentView;
pub struct SwitchableViewManager {
single: Arc<Mutex<MandelbrotViewManager>>,
double: Arc<Mutex<DoubleViewManager>>,
pub current: CurrentView
}
impl SwitchableViewManager {
pub fn init(single: Arc<Mutex<MandelbrotViewManager>>, double: Arc<Mutex<DoubleViewManager>>, current: CurrentView) -> Self {
Self {
single,
double,
current
}
}
}
impl FractalViewManager for SwitchableViewManager where {
fn new(_device: &Device, _size: LogicalSize) -> Self {
unimplemented!()
}
fn render(&mut self, device: &Arc<Mutex<Device>>, frame: &SwapChainOutput) -> Vec<CommandBuffer> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().render(device, frame)
} else {
self.single.lock().unwrap().render(device, frame)
}
}
fn resized(&mut self, device: &Arc<Mutex<Device>>, window_size: &WindowSize) -> Vec<CommandBuffer> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().resized(device, window_size)
} else {
self.single.lock().unwrap().resized(device, window_size)
}
}
fn mouse_input(&mut self, button: MouseButton, state: ElementState) {
if self.current == CurrentView::Double {
self.double.lock().unwrap().mouse_input(button, state)
} else {
self.single.lock().unwrap().mouse_input(button, state)
}
}
fn iterations(&mut self, device: &Arc<Mutex<Device>>, y_delta: f32) -> Vec<CommandBuffer> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().iterations(device, y_delta)
} else {
self.single.lock().unwrap().iterations(device, y_delta)
}
}
fn set_julia(&mut self, device: &Arc<Mutex<Device>>, state: bool) -> Option<Vec<CommandBuffer>> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().set_julia(device, state)
} else {
self.single.lock().unwrap().set_julia(device, state)
}
}
fn zoom(&mut self, device: &Arc<Mutex<Device>>, y_delta: f32) -> Vec<CommandBuffer> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().zoom(device, y_delta)
} else {
self.single.lock().unwrap().zoom(device, y_delta)
}
}
fn new_position(&mut self, device: &Arc<Mutex<Device>>, x: f32, y: f32, active: bool) -> Option<Vec<CommandBuffer>> {
if self.current == CurrentView::Double {
self.double.lock().unwrap().new_position(device, x, y, active)
} else {
self.single.lock().unwrap().new_position(device, x, y, active)
}
}
fn create_render_pipeline(&mut self, device: &Device) {
if self.current == CurrentView::Double {
self.double.lock().unwrap().create_render_pipeline(device)
} else {
self.single.lock().unwrap().create_render_pipeline(device)
}
}
fn reload_fs(&mut self, device: &Arc<Mutex<Device>>) {
if self.current == CurrentView::Double {
self.double.lock().unwrap().reload_fs(device)
} else {
self.single.lock().unwrap().reload_fs(device)
}
}
}