Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff4fda55b | ||
|
|
76b7e9d6ec | ||
|
|
e15659f6d2 | ||
|
|
a926f19f79 | ||
|
|
8ed1019b44 |
Generated
+1
-1
@@ -2034,7 +2034,7 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lemur"
|
||||
version = "0.13.1"
|
||||
version = "0.14.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"atoi",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ description = "An emulator for the Virtual Boy."
|
||||
repository = "https://git.virtual-boy.com/PVB/lemur"
|
||||
publish = false
|
||||
license = "MIT"
|
||||
version = "0.13.1"
|
||||
version = "0.14.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
|
||||
use winit::window::Window;
|
||||
|
||||
pub struct FilePicker {
|
||||
window: Option<Weak<Window>>,
|
||||
}
|
||||
|
||||
impl FilePicker {
|
||||
pub fn new() -> Self {
|
||||
Self { window: None }
|
||||
}
|
||||
|
||||
pub fn set_window(&mut self, window: &Arc<Window>) {
|
||||
self.window = Some(Arc::downgrade(window));
|
||||
}
|
||||
|
||||
pub fn pick_file_dialog(&self) -> FileDialogBuilder {
|
||||
self.new_dialog(FileDialogAction::PickFile, false)
|
||||
}
|
||||
|
||||
pub fn save_file_dialog(&self) -> FileDialogBuilder {
|
||||
self.new_dialog(FileDialogAction::SaveFile, cfg!(not(target_os = "windows")))
|
||||
}
|
||||
|
||||
fn new_dialog(&self, action: FileDialogAction, attach_window: bool) -> FileDialogBuilder {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let mut dialog = rfd::AsyncFileDialog::new();
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut dialog = rfd::FileDialog::new();
|
||||
|
||||
if attach_window && let Some(window) = self.window.as_ref().and_then(|w| w.upgrade()) {
|
||||
dialog = dialog.set_parent(&window);
|
||||
}
|
||||
FileDialogBuilder { dialog, action }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FileDialogBuilder {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
dialog: rfd::AsyncFileDialog,
|
||||
#[cfg(target_os = "macos")]
|
||||
dialog: rfd::FileDialog,
|
||||
action: FileDialogAction,
|
||||
}
|
||||
|
||||
impl FileDialogBuilder {
|
||||
pub fn add_filter(self, name: impl Into<String>, extensions: &[impl ToString]) -> Self {
|
||||
Self {
|
||||
dialog: self.dialog.add_filter(name, extensions),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_file_name(self, file_name: impl Into<String>) -> Self {
|
||||
Self {
|
||||
dialog: self.dialog.set_file_name(file_name),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open(self) -> Option<PathBuf> {
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn resolve(action: impl Future<Output = Option<rfd::FileHandle>>) -> Option<PathBuf> {
|
||||
pollster::block_on(action).map(Into::into)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
fn resolve(action: Option<PathBuf>) -> Option<PathBuf> {
|
||||
action
|
||||
}
|
||||
match self.action {
|
||||
FileDialogAction::PickFile => resolve(self.dialog.pick_file()),
|
||||
FileDialogAction::SaveFile => resolve(self.dialog.save_file()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum FileDialogAction {
|
||||
PickFile,
|
||||
SaveFile,
|
||||
}
|
||||
@@ -23,6 +23,7 @@ mod audio;
|
||||
mod config;
|
||||
mod controller;
|
||||
mod emulator;
|
||||
mod filepicker;
|
||||
mod gdbserver;
|
||||
mod graphics;
|
||||
mod images;
|
||||
|
||||
+17
-13
@@ -8,6 +8,7 @@ use crate::{
|
||||
app::UserEvent,
|
||||
config::{COLOR_PRESETS, SimConfig},
|
||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
|
||||
filepicker::FilePicker,
|
||||
images::ImageTextureLoader,
|
||||
input::{Command, MappingProvider, ShortcutProvider},
|
||||
memory::MemoryClient,
|
||||
@@ -46,7 +47,7 @@ pub struct GameWindow {
|
||||
messages: mpsc::Receiver<Toast>,
|
||||
message_sink: mpsc::Sender<Toast>,
|
||||
color_picker: Option<ColorPickerState>,
|
||||
window: Option<Arc<winit::window::Window>>,
|
||||
file_picker: FilePicker,
|
||||
memory: Arc<MemoryClient>,
|
||||
images: Arc<ImageTextureLoader>,
|
||||
mappings: MappingProvider,
|
||||
@@ -88,7 +89,7 @@ impl GameWindow {
|
||||
messages,
|
||||
message_sink,
|
||||
color_picker: None,
|
||||
window: None,
|
||||
file_picker: FilePicker::new(),
|
||||
memory: memory.clone(),
|
||||
images: images.clone(),
|
||||
mappings: mappings.clone(),
|
||||
@@ -249,9 +250,11 @@ impl GameWindow {
|
||||
for command in ui.input_mut(|input| self.shortcuts.consume_all(input)) {
|
||||
match command {
|
||||
Command::OpenRom => {
|
||||
let rom = rfd::FileDialog::new()
|
||||
let rom = self
|
||||
.file_picker
|
||||
.pick_file_dialog()
|
||||
.add_filter("Virtual Boy ROMs", &["vb", "vbrom", "elf", "isx"])
|
||||
.pick_file();
|
||||
.open();
|
||||
if let Some(path) = rom {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::LoadGame(self.sim_id, path));
|
||||
@@ -305,9 +308,11 @@ impl GameWindow {
|
||||
.add(self.button_for(ui.ctx(), "Open ROM", Command::OpenRom))
|
||||
.clicked()
|
||||
{
|
||||
let rom = rfd::FileDialog::new()
|
||||
let rom = self
|
||||
.file_picker
|
||||
.pick_file_dialog()
|
||||
.add_filter("Virtual Boy ROMs", &["vb", "vbrom", "elf", "isx"])
|
||||
.pick_file();
|
||||
.open();
|
||||
if let Some(path) = rom {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::LoadGame(self.sim_id, path));
|
||||
@@ -459,13 +464,12 @@ impl GameWindow {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::Screenshot(self.sim_id, tx));
|
||||
let bytes = rx.await.context("Could not take screenshot")?;
|
||||
let mut file_dialog = rfd::FileDialog::new()
|
||||
let file = self
|
||||
.file_picker
|
||||
.save_file_dialog()
|
||||
.add_filter("PNG images", &["png"])
|
||||
.set_file_name("screenshot.png");
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
file_dialog = file_dialog.set_parent(window);
|
||||
}
|
||||
let file = file_dialog.save_file();
|
||||
.set_file_name("screenshot.png")
|
||||
.open();
|
||||
let Some(path) = file else {
|
||||
return Ok(None);
|
||||
};
|
||||
@@ -759,7 +763,7 @@ impl AppWindow for GameWindow {
|
||||
));
|
||||
self.screen = Some(screen);
|
||||
}
|
||||
self.window = Some(args.window.clone());
|
||||
self.file_picker.set_window(args.window);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-11
@@ -1,12 +1,12 @@
|
||||
use std::{fs, sync::Arc, time::Duration};
|
||||
use std::{fs, time::Duration};
|
||||
|
||||
use anyhow::Result;
|
||||
use egui::{Button, CentralPanel, Checkbox, Label, ViewportBuilder};
|
||||
use egui_notify::{Anchor, Toast, Toasts};
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId},
|
||||
filepicker::FilePicker,
|
||||
profiler::{Profiler, ProfilerStatus},
|
||||
window::{AppWindow, InitArgs},
|
||||
};
|
||||
@@ -16,7 +16,7 @@ pub struct ProfileWindow {
|
||||
client: EmulatorClient,
|
||||
profiler: Profiler,
|
||||
toasts: Toasts,
|
||||
window: Option<Arc<Window>>,
|
||||
file_picker: FilePicker,
|
||||
}
|
||||
|
||||
impl ProfileWindow {
|
||||
@@ -29,7 +29,7 @@ impl ProfileWindow {
|
||||
.with_anchor(Anchor::BottomLeft)
|
||||
.with_margin((10.0, 10.0).into())
|
||||
.reverse(true),
|
||||
window: None,
|
||||
file_picker: FilePicker::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,12 @@ impl ProfileWindow {
|
||||
|
||||
fn try_finish_recording(&mut self) -> Result<Option<String>> {
|
||||
let bytes_receiver = self.profiler.finish_recording();
|
||||
let mut file_dialog = rfd::FileDialog::new()
|
||||
let file = self
|
||||
.file_picker
|
||||
.save_file_dialog()
|
||||
.add_filter("Profiler files", &["json"])
|
||||
.set_file_name("profile.json");
|
||||
if let Some(window) = self.window.as_ref() {
|
||||
file_dialog = file_dialog.set_parent(window);
|
||||
}
|
||||
let file = file_dialog.save_file();
|
||||
.set_file_name("profile.json")
|
||||
.open();
|
||||
if let Some(path) = file {
|
||||
let bytes = pollster::block_on(bytes_receiver)?;
|
||||
let _ = fs::remove_file(&path);
|
||||
@@ -164,6 +163,6 @@ impl AppWindow for ProfileWindow {
|
||||
}
|
||||
|
||||
fn on_init(&mut self, args: InitArgs) {
|
||||
self.window = Some(args.window.clone());
|
||||
self.file_picker.set_window(args.window);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user