189 lines
5.8 KiB
Rust
189 lines
5.8 KiB
Rust
mod patch;
|
|
mod titlebar;
|
|
mod boxes;
|
|
|
|
use titlebar::CustomTitleBar;
|
|
use boxes::*;
|
|
|
|
use std::path::PathBuf;
|
|
use std::rc::Rc;
|
|
|
|
use gtk4::prelude::*;
|
|
use gtk4::{
|
|
gdk::{
|
|
Display
|
|
},
|
|
Application,
|
|
ApplicationWindow,
|
|
StyleContext,
|
|
};
|
|
|
|
fn main() {
|
|
let app = Application::new(Some("com.wyattjmiller.snespatcher"), Default::default());
|
|
app.connect_activate(build_ui);
|
|
app.run();
|
|
}
|
|
|
|
// fn build_ui(app: &Application) {
|
|
// let resources_bytes = include_bytes!("../resources/resources.gresource");
|
|
// let resource_data = glib::Bytes::from(&resources_bytes[..]);
|
|
// let res = gio::Resource::from_data(&resource_data).unwrap();
|
|
// gio::resources_register(&res);
|
|
|
|
// let provider = gtk4::CssProvider::new();
|
|
// provider.load_from_resource("/com/wyattjmiller/snespatcher/style.css");
|
|
// StyleContext::add_provider_for_display(
|
|
// &Display::default().expect("Error initializing CSS provider!"),
|
|
// &provider,
|
|
// gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
// );
|
|
|
|
// let builder = Builder::from_resource("/com/wyattjmiller/snespatcher/snespatcher.ui");
|
|
|
|
// let window: ApplicationWindow = builder.object("app_window").expect("Failure to load window!");
|
|
// let run_btn: Button = builder.object("run_btn").unwrap();
|
|
// window.set_application(Some(app));
|
|
// window.set_show_menubar(false);
|
|
// println!("{:?}", window.shows_menubar());
|
|
|
|
// run_btn.connect_clicked( move |_| {
|
|
// patch::apply_ips(PathBuf::from("/home/wyatt/Downloads/smw-widescreen.bps"), PathBuf::from("/home/wyatt/Downloads/smw-widescreen.bps"));
|
|
// });
|
|
|
|
// window.show();
|
|
// }
|
|
|
|
// fn build_ui(app: &Application) {
|
|
// let resources_bytes = include_bytes!("../resources/resources.gresource");
|
|
// let resource_data = glib::Bytes::from(&resources_bytes[..]);
|
|
// let res = gio::Resource::from_data(&resource_data).unwrap();
|
|
// gio::resources_register(&res);
|
|
|
|
// let provider = gtk4::CssProvider::new();
|
|
// provider.load_from_resource("/com/wyattjmiller/snespatcher/style.css");
|
|
// StyleContext::add_provider_for_display(
|
|
// &Display::default().expect("Error initializing CSS provider!"),
|
|
// &provider,
|
|
// gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
// );
|
|
|
|
// let run_btn = Button::builder()
|
|
// .label("Apply Patch")
|
|
// .css_name("run_btn")
|
|
// .build();
|
|
|
|
// let headerbar_ctr: HeaderBar = HeaderBar::builder()
|
|
// .visible(true)
|
|
// .can_focus(false)
|
|
// .title_widget(&run_btn)
|
|
// .build();
|
|
|
|
// let patch_btn: Button = Button::builder()
|
|
// .label("Open Patch")
|
|
// .build();
|
|
|
|
// let patch_lbl: Label = Label::builder()
|
|
// .label("Patch")
|
|
// .visible(true)
|
|
// .can_focus(false)
|
|
// .build();
|
|
|
|
// let patch_box: Box = Box::builder()
|
|
// .visible(true)
|
|
// .can_focus(false)
|
|
// .margin_start(20)
|
|
// .margin_end(20)
|
|
// .margin_top(20)
|
|
// .homogeneous(true)
|
|
// .child::<Label>(&patch_lbl)
|
|
// .child::<Button>(&patch_btn)
|
|
// .build();
|
|
|
|
// let app_box: Box = Box::builder()
|
|
// .visible(false)
|
|
// .can_focus(false)
|
|
// .orientation(Orientation::Vertical)
|
|
// .build();
|
|
|
|
// let app_window: ApplicationWindow = ApplicationWindow::builder()
|
|
// .can_focus(false)
|
|
// .title("SNES Patcher")
|
|
// .show_menubar(true)
|
|
// .child::<Box>(&app_box)
|
|
// .child::<HeaderBar>(&headerbar_ctr)
|
|
// .build();
|
|
|
|
// app_window.show();
|
|
// }
|
|
|
|
fn build_ui(app: &Application) {
|
|
let resources_bytes = include_bytes!("../resources/resources.gresource");
|
|
let resource_data = glib::Bytes::from(&resources_bytes[..]);
|
|
let res = gio::Resource::from_data(&resource_data).unwrap();
|
|
gio::resources_register(&res);
|
|
|
|
let provider = gtk4::CssProvider::new();
|
|
provider.load_from_resource("/com/wyattjmiller/snespatcher/style.css");
|
|
StyleContext::add_provider_for_display(
|
|
&Display::default().expect("Error initializing CSS provider!"),
|
|
&provider,
|
|
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
);
|
|
|
|
let app_window: Rc<ApplicationWindow> = Rc::new(ApplicationWindow::new(app));
|
|
let header_bar: CustomTitleBar = CustomTitleBar::new();
|
|
let app_box: AppBox = AppBox::new();
|
|
let patch_box: PatchBox = PatchBox::new(&app_window);
|
|
let rom_box: RomBox = RomBox::new(&app_window);
|
|
|
|
// set header bar methods
|
|
header_bar.set_buttons();
|
|
header_bar.set_titlebar();
|
|
header_bar.set_window(&app_window);
|
|
header_bar.click_run_button();
|
|
|
|
// set patch box methods
|
|
patch_box.set_label();
|
|
patch_box.set_button();
|
|
patch_box.set_box();
|
|
patch_box.click_button();
|
|
|
|
// set rom box methods
|
|
rom_box.set_label();
|
|
rom_box.set_button();
|
|
rom_box.set_box();
|
|
rom_box.click_button();
|
|
|
|
// set app box methods
|
|
app_box.set_box(&rom_box, &patch_box);
|
|
|
|
// set apps default methods
|
|
app_window.set_title(Some("SNES Patcher"));
|
|
app_window.set_resizable(false);
|
|
app_window.set_child(Some(&app_box.app_box));
|
|
app_window.show();
|
|
}
|
|
|
|
async fn dialog<W: IsA<gtk4::Window>>(window: Rc<W>) {
|
|
let question_dialog = gtk4::MessageDialog::builder()
|
|
.transient_for(&*window)
|
|
.modal(true)
|
|
.buttons(gtk4::ButtonsType::OkCancel)
|
|
.text("What is your answer?")
|
|
.build();
|
|
|
|
let answer = question_dialog.run_future().await;
|
|
question_dialog.close();
|
|
|
|
let info_dialog = gtk4::MessageDialog::builder()
|
|
.transient_for(&*window)
|
|
.modal(true)
|
|
.buttons(gtk4::ButtonsType::Close)
|
|
.text("You answered")
|
|
.secondary_text(&format!("Your answer: {:?}", answer))
|
|
.build();
|
|
|
|
info_dialog.run_future().await;
|
|
info_dialog.close();
|
|
}
|