Commit 933c1c30 authored by René Rössler's avatar René Rössler 😍
Browse files

only call by reference

parent 07278356
Pipeline #104672274 passed with stage
in 10 minutes and 19 seconds
......@@ -48,39 +48,29 @@ fn create_window(renderer: &Arc<RwLock<Renderer>>, application: &Application) {
palettes: AtomicBool::new(true),
});
let builder = Builder::new_from_string(include_str!("ui/gled.glade"));
let update_ui = update_ui::init(
&builder,
renderer.clone(),
ignore_signals.clone(),
dirty.clone(),
);
let update_ui = update_ui::init(&builder, renderer, &ignore_signals, &dirty);
about_dialog::init(&builder);
blackout::init(&builder);
bpm::init(&builder, ignore_signals.clone());
colors::init(
&builder,
renderer.clone(),
update_ui.clone(),
ignore_signals.clone(),
);
drawing_area::init(&builder, &renderer, true);
drawing_area::init(&builder, &renderer, false);
file_menu::init(&builder, renderer.clone(), application);
frozen::init(&builder, renderer.clone());
bpm::init(&builder, &ignore_signals);
colors::init(&builder, renderer, &update_ui, &ignore_signals);
drawing_area::init(&builder, renderer, true);
drawing_area::init(&builder, renderer, false);
file_menu::init(&builder, renderer, application);
frozen::init(&builder, renderer);
icon::init(&builder);
master_dimmer::init(&builder, ignore_signals.clone());
palettes::init(&builder, &renderer, &update_ui, &ignore_signals, &dirty);
preferences::init(&builder, renderer.clone(), &ignore_signals);
presets::init(&builder, &renderer, &update_ui, &ignore_signals, &dirty);
preview_to_live::init(&builder, renderer.clone(), update_ui.clone(), dirty);
render_groups::init(&builder, &renderer, &update_ui, &ignore_signals);
master_dimmer::init(&builder, &ignore_signals);
palettes::init(&builder, renderer, &update_ui, &ignore_signals, &dirty);
preferences::init(&builder, renderer, &ignore_signals);
presets::init(&builder, renderer, &update_ui, &ignore_signals, &dirty);
preview_to_live::init(&builder, renderer, &update_ui, &dirty);
render_groups::init(&builder, renderer, &update_ui, &ignore_signals);
tap::init(&builder);
update_fps::init(&builder, renderer.clone());
window::init(&builder, renderer.clone(), application);
update_fps::init(&builder, renderer);
window::init(&builder, renderer, application);
let _ = update_ui.send(UpdateUiConfig::default());
show(&builder, &renderer);
show(&builder, renderer);
ignore_signals.store(false, Ordering::Relaxed);
}
......@@ -122,7 +112,7 @@ pub fn open_windows(application: &Application) {
};
renderers
.iter()
.for_each(|renderer| create_window(&renderer, application));
.for_each(|renderer| create_window(renderer, application));
}
pub fn add_recent(path: &Path) {
......
use gled::STATE;
use gled::{clone, STATE};
use gtk::{prelude::*, Builder, Scale};
use std::sync::{
atomic::{AtomicBool, Ordering},
atomic::{AtomicBool, Ordering::Relaxed},
Arc,
};
pub fn init(builder: &Builder, ignore_signals: Arc<AtomicBool>) {
pub fn init(builder: &Builder, ignore_signals: &Arc<AtomicBool>) {
let bpm: Scale = builder.get_object("bpm").unwrap();
bpm.connect_value_changed(move |bpm| {
if ignore_signals.load(Ordering::Relaxed) {
bpm.connect_value_changed(clone!(ignore_signals => move |bpm| {
if ignore_signals.load(Relaxed) {
return;
}
let mut state = STATE.write().unwrap();
state.duration_milliseconds = 60_000.0 / bpm.get_value();
});
}));
bpm.connect_format_value(|_, value| format!("{:.0} bpm", value));
}
......
......@@ -11,9 +11,9 @@ use std::sync::{
pub fn init(
builder: &Builder,
renderer: Arc<RwLock<Renderer>>,
update_ui: Sender<UpdateUiConfig>,
ignore_signals: Arc<AtomicBool>,
renderer: &Arc<RwLock<Renderer>>,
update_ui: &Sender<UpdateUiConfig>,
ignore_signals: &Arc<AtomicBool>,
) {
let window = builder.get_object::<Window>("window").unwrap();
let colors = builder.get_object::<TreeView>("colors").unwrap();
......@@ -69,7 +69,7 @@ pub fn init(
let _ = update_ui.send(UpdateUiConfig::default());
}));
del_color.connect_clicked(move |_| {
del_color.connect_clicked(clone!(ignore_signals, renderer, update_ui => move |_| {
if ignore_signals.load(Ordering::Relaxed) {
return;
}
......@@ -79,7 +79,7 @@ pub fn init(
let preview_palette = config.preview_palette;
config.palettes[preview_palette].colors.pop();
let _ = update_ui.send(UpdateUiConfig::default());
});
}));
}
pub fn update_ui(builder: &Builder, renderer: &Renderer) {
......
......@@ -2,7 +2,7 @@ use gled::{clone, Renderer};
use gtk::{prelude::*, Application, Builder, FileFilter, MenuItem, Window};
use std::sync::{Arc, RwLock};
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, application: &Application) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>, application: &Application) {
let window = builder.get_object::<Window>("window").unwrap();
let create = builder.get_object::<MenuItem>("create").unwrap();
let open = builder.get_object::<MenuItem>("open").unwrap();
......@@ -88,7 +88,7 @@ pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, application: &Ap
file_chooser.destroy();
}));
open_svg.connect_activate(move |_| {
open_svg.connect_activate(clone!(renderer => move |_| {
let file_chooser = gtk::FileChooserDialog::new(
Some("Open SVG file"),
Some(&window),
......@@ -112,5 +112,5 @@ pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, application: &Ap
}
file_chooser.destroy();
});
}));
}
use gled::Renderer;
use gled::{clone, Renderer};
use gtk::{prelude::*, Builder, ToggleButton};
use std::sync::{atomic::Ordering, Arc, RwLock};
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>) {
let frozen: ToggleButton = builder.get_object("frozen").unwrap();
frozen.connect_property_active_notify(move |frozen| {
frozen.connect_property_active_notify(clone!(renderer => move |frozen| {
let active = frozen.get_active();
let renderer = renderer.read().unwrap();
renderer.frozen.store(active, Ordering::Relaxed);
});
}));
}
use gled::STATE;
use gled::{clone, STATE};
use gtk::{prelude::*, Builder, Scale};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
pub fn init(builder: &Builder, ignore_signals: Arc<AtomicBool>) {
pub fn init(builder: &Builder, ignore_signals: &Arc<AtomicBool>) {
let master_dimmer: Scale = builder.get_object("master_dimmer").unwrap();
master_dimmer.connect_value_changed(move |master_dimmer| {
master_dimmer.connect_value_changed(clone!(ignore_signals => move |master_dimmer| {
if ignore_signals.load(Ordering::Relaxed) {
return;
}
let mut state = STATE.write().unwrap();
state.master_dimmer = master_dimmer.get_value() / 100.0;
});
}));
master_dimmer.connect_format_value(|_, value| format!("{:.1} %", value));
}
......
......@@ -5,7 +5,7 @@ use std::sync::{
Arc, RwLock,
};
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, ignore_signals: &Arc<AtomicBool>) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>, ignore_signals: &Arc<AtomicBool>) {
let framerate_limiter = builder.get_object::<Scale>("framerate_limiter").unwrap();
let artnet_broadcast_address = builder
.get_object::<Entry>("artnet_broadcast_address")
......@@ -38,7 +38,7 @@ pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, ignore_signals:
);
hide_sidepanels.connect_property_active_notify(
clone!(builder, ignore_signals => move |hide_sidepanels| {
clone!(builder, ignore_signals, renderer => move |hide_sidepanels| {
if ignore_signals.load(Ordering::Relaxed) {
return;
}
......
use super::{update_ui::UpdateUiConfig, Dirty};
use gled::Renderer;
use gled::{clone, Renderer};
use glib::Sender;
use gtk::{prelude::*, Builder, Button};
use std::sync::{atomic::Ordering, Arc, RwLock};
pub fn init(
builder: &Builder,
renderer: Arc<RwLock<Renderer>>,
update_ui: Sender<UpdateUiConfig>,
dirty: Arc<Dirty>,
renderer: &Arc<RwLock<Renderer>>,
update_ui: &Sender<UpdateUiConfig>,
dirty: &Arc<Dirty>,
) {
let preview_to_live: Button = builder.get_object("preview_to_live").unwrap();
preview_to_live.connect_clicked(move |_| {
preview_to_live.connect_clicked(clone!(update_ui, dirty, renderer => move |_| {
let renderer = renderer.read().unwrap();
let mut config = renderer.config.write().unwrap();
config.live_preset = config.preview_preset;
......@@ -21,5 +21,5 @@ pub fn init(
dirty.presets.store(true, Ordering::Relaxed);
dirty.palettes.store(true, Ordering::Relaxed);
let _ = update_ui.send(UpdateUiConfig::default());
});
}));
}
......@@ -3,10 +3,12 @@ use gtk::{prelude::*, Builder, Button, Window};
use std::sync::{Arc, RwLock};
use std::thread;
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>) {
let tap = builder.get_object::<Button>("tap").unwrap();
let window = builder.get_object::<Window>("window").unwrap();
let (update_fps_tx, update_fps_rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
let renderer = renderer.clone();
update_fps_rx.attach(None, move |(fps, progress): (u16, f64)| {
let style = tap.get_style_context();
if progress % 1. < 0.3 {
......
......@@ -45,15 +45,15 @@ impl UpdateUiConfig {
pub fn init(
builder: &Builder,
renderer: Arc<RwLock<Renderer>>,
ignore_signals: Arc<AtomicBool>,
dirty: Arc<Dirty>,
renderer: &Arc<RwLock<Renderer>>,
ignore_signals: &Arc<AtomicBool>,
dirty: &Arc<Dirty>,
) -> Sender<UpdateUiConfig> {
let (update_ui_tx, update_ui_rx) =
glib::MainContext::channel::<UpdateUiConfig>(glib::PRIORITY_DEFAULT);
update_ui_rx.attach(
None,
clone!(builder, update_ui_tx => move |update_ui_config| {
clone!(builder, update_ui_tx, renderer, dirty , ignore_signals => move |update_ui_config| {
if !gled::has_ui_changes() {
return glib::Continue(true);
}
......
use gled::Renderer;
use gled::{clone, Renderer};
use gtk::{prelude::*, Application, Builder, Window};
use std::sync::{
atomic::{AtomicU32, Ordering},
......@@ -7,16 +7,16 @@ use std::sync::{
static OPEN_WINDOWS: AtomicU32 = AtomicU32::new(0);
pub fn init(builder: &Builder, renderer: Arc<RwLock<Renderer>>, application: &Application) {
pub fn init(builder: &Builder, renderer: &Arc<RwLock<Renderer>>, application: &Application) {
OPEN_WINDOWS.fetch_add(1, Ordering::SeqCst);
let window = builder.get_object::<Window>("window").unwrap();
window.connect_destroy(move |_| {
window.connect_destroy(clone!(renderer => move |_| {
if OPEN_WINDOWS.fetch_sub(1, Ordering::SeqCst) == 1 {
std::process::exit(0);
}
renderer.read().unwrap().stop();
});
}));
application.add_window(&window);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment