4 Commits

Author SHA1 Message Date
b24d6a934c feat(GUI): (WIP) first gui attempt, render single converted image 2022-01-23 06:17:37 +03:00
2507c010c0 build(cli): remove unused deps 2022-01-23 04:06:07 +03:00
5c69f3ad5d docs: update download link 2022-01-23 04:02:19 +03:00
cd04c5d78b Merge pull request #1 from xzeldon/refactoring
refactor: refactoring code, separate crates
2022-01-23 03:51:24 +03:00
6 changed files with 1860 additions and 15 deletions

1751
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ Convert and save photomode screenshots from Red Dead Redemption 2 to JPEG format
![Imgur](https://i.imgur.com/ZGbmHYd.png)
## QuickStart
Just [download](https://github.com/xzeldon/rdr2_screenshot_converter/releases/download/1.0.0/rdr2_screenshot_converter.exe) the executable file from releases and run it. It will automatically find your screenshots and save them.
Just [download](https://github.com/xzeldon/rdr2_screenshot_converter/releases) the executable file from releases and run it. It will automatically find your screenshots and save them.
## Arguments
You can define a path for saving screenshots. To do this, open a command prompt, specify the path to the executable file and the path to save the screenshots.

View File

@ -12,14 +12,8 @@ version = "1.1.0"
[dependencies]
colored = "2.0.0"
core = {path = "../core"}
ctrlc = {version = "3.0", features = ["termination"]}
dirs = "4.0.0"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
[target.'cfg(target_os="windows")'.dependencies.winapi]
features = ["consoleapi", "errhandlingapi", "fileapi", "handleapi", "processenv"]
version = "0.3"
[build-dependencies]
embed-resource = "1.6"

View File

@ -1,8 +1,13 @@
[package]
edition = "2021"
name = "gui"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cli = {path = "../cli"}
core = {path = "../core"}
eframe = "0.16.0"
image = "0.23.14"
rfd = "0.6.4"

59
gui/src/lib.rs Normal file
View File

@ -0,0 +1,59 @@
use eframe::egui::{Separator, Ui};
use eframe::epi::Image;
use eframe::{egui, epi};
const PADDING: f32 = 5.0;
pub fn render_header(ui: &mut Ui) {
ui.vertical_centered(|ui| {
ui.heading("RDR2Converter");
});
ui.add_space(PADDING);
let sep = Separator::default().spacing(20.);
ui.add(sep);
}
pub fn decode_image(buffer: &[u8]) -> Option<epi::Image> {
use image::GenericImageView;
let image = image::load_from_memory(buffer).ok()?;
let image_buffer = image.to_rgba8();
let size = [image.width() as usize, image.height() as usize];
let pixels = image_buffer.into_vec();
Some(epi::Image::from_rgba_unmultiplied(size, &pixels))
}
pub fn render_image(
ui: &mut egui::Ui,
frame: &epi::Frame,
tex_mngr: &mut TextureManager,
image: Option<epi::Image>,
) {
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.show(ui, |ui| {
if let Some(image) = image {
if let Some(texture_id) = tex_mngr.texture(frame, &image) {
let mut size = egui::Vec2::new(image.size[0] as f32, image.size[1] as f32);
size *= (ui.available_width() / size.x).min(1.0);
ui.image(texture_id, size);
} else {
ui.monospace("ERROR");
}
}
})
}
#[derive(Default)]
pub struct TextureManager {
texture_id: Option<egui::TextureId>,
}
impl TextureManager {
pub fn texture(&mut self, frame: &epi::Frame, image: &Image) -> Option<egui::TextureId> {
if let Some(texture_id) = self.texture_id.take() {
frame.free_texture(texture_id);
}
self.texture_id = Some(frame.alloc_texture(image.clone()));
self.texture_id
}
}

View File

@ -1,3 +1,49 @@
fn main() {
println!("Hello, world!");
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use core::buffer;
use eframe::{
egui::{CentralPanel, Vec2},
epi::App,
run_native, NativeOptions,
};
use gui::TextureManager;
use std::path::PathBuf;
#[derive(Default)]
struct RDR2Converter {
pub tex_mngr: TextureManager,
picked_path: Option<PathBuf>,
}
impl App for RDR2Converter {
fn update(&mut self, ctx: &eframe::egui::CtxRef, frame: &eframe::epi::Frame) {
CentralPanel::default().show(ctx, |ui| {
gui::render_header(ui);
if ui.button("Open file...").clicked() {
if let Some(path) = rfd::FileDialog::new().pick_file() {
self.picked_path = Some(path);
}
}
// TODO: use threads and channels
if let Some(picked_path) = &self.picked_path {
let buf = buffer::read_file(&picked_path).unwrap();
let pic = buffer::parse_buf(&buf, b"JPEG", b"JSON", 12);
let image = gui::decode_image(&pic);
gui::render_image(ui, frame, &mut self.tex_mngr, image);
}
});
}
fn name(&self) -> &str {
"RDR2Converter"
}
}
fn main() {
let app = RDR2Converter::default();
let mut win_option = NativeOptions::default();
win_option.initial_window_size = Some(Vec2::new(540., 960.));
run_native(Box::new(app), win_option);
}