From fff5d522cf46d5917f58ac589888aebb244b7b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Tue, 7 May 2024 12:12:26 +0200 Subject: [PATCH] Store window coordinates & corrected 80x50 font. --- crates/icy_engine/src/buffers.rs | 5 ++++ crates/icy_term/src/data/options.rs | 21 +++++++++++++++- crates/icy_term/src/main.rs | 20 +++++++++++++-- crates/icy_term/src/ui/app.rs | 28 +++++++++++++-------- crates/icy_term/src/ui/util/screen_modes.rs | 16 ++++++++++-- 5 files changed, 74 insertions(+), 16 deletions(-) diff --git a/crates/icy_engine/src/buffers.rs b/crates/icy_engine/src/buffers.rs index 48e41e7..03894c4 100644 --- a/crates/icy_engine/src/buffers.rs +++ b/crates/icy_engine/src/buffers.rs @@ -611,6 +611,11 @@ impl Buffer { let size = size.into(); self.size = size; } + + pub fn set_default_size(&mut self, size: impl Into) { + let size = size.into(); + self.original_size = size; + } pub fn set_width(&mut self, width: i32) { self.size.width = width; diff --git a/crates/icy_term/src/data/options.rs b/crates/icy_term/src/data/options.rs index 1d0b1e0..88424c8 100644 --- a/crates/icy_term/src/data/options.rs +++ b/crates/icy_term/src/data/options.rs @@ -4,7 +4,7 @@ use std::{ time::Duration, }; -use egui::Modifiers; +use egui::{Modifiers, Rect}; use egui_bind::KeyOrPointer; use i18n_embed_fl::fl; use icy_engine::Color; @@ -284,6 +284,8 @@ pub struct Options { pub bind: KeyBindings, pub iemsi: IEMSISettings, + pub window_rect: Option, + pub modem: Modem, } @@ -297,6 +299,7 @@ impl Default for Options { console_beep: true, bind: KeyBindings::default(), is_dark_mode: None, + window_rect: None, modem: Modem::default(), } } @@ -341,6 +344,10 @@ impl Options { let mut file = File::create(&write_name)?; file.write_all(b"version = \"1.1\"\n")?; + if let Some(rect) = self.window_rect { + file.write_all(format!("window_coord = \"{}/{}-{}/{}\"\n", rect.min.x, rect.min.y, rect.max.x, rect.max.y).as_bytes())?; + } + file.write_all(format!("scaling = \"{:?}\"\n", self.scaling).as_bytes())?; if let Some(dark_mode) = self.is_dark_mode { file.write_all(format!("is_dark_mode = {dark_mode}\n").as_bytes())?; @@ -436,6 +443,18 @@ fn parse_value(options: &mut Options, value: &Value) { Value::Table(table) => { for (k, v) in table { match k.as_str() { + "window_coord" => { + if let Value::String(str) = v { + let mut minmax = str.split('-'); + let min = minmax.next().unwrap().split('/').collect::>(); + let max = minmax.next().unwrap().split('/').collect::>(); + + options.window_rect = Some(Rect::from_min_max( + egui::Pos2::new(min[0].parse::().unwrap(), min[1].parse::().unwrap()), + egui::Pos2::new(max[0].parse::().unwrap(), max[1].parse::().unwrap()), + )); + } + } "scaling" => { if let Value::String(str) = v { match str.as_str() { diff --git a/crates/icy_term/src/main.rs b/crates/icy_term/src/main.rs index 48e6a94..84bd048 100644 --- a/crates/icy_term/src/main.rs +++ b/crates/icy_term/src/main.rs @@ -109,13 +109,29 @@ fn main() { use eframe::icon_data::from_png_bytes; + let options = match Options::load_options() { + Ok(options) => options, + Err(e) => { + log::error!("Error reading dialing_directory: {e}"); + Options::default() + } + }; + let mut native_options = eframe::NativeOptions { multisampling: 0, renderer: eframe::Renderer::Glow, ..Default::default() }; let icon_data = from_png_bytes(include_bytes!("../build/linux/256x256.png")).unwrap(); - native_options.viewport = native_options.viewport.with_inner_size(egui::vec2(1284. + 8., 839.)).with_icon(icon_data); + if let Some(rect) = options.window_rect { + native_options.viewport = native_options + .viewport + .with_inner_size(rect.max.to_vec2()) + .with_icon(icon_data) + .with_position(rect.min); + } else { + native_options.viewport = native_options.viewport.with_inner_size(egui::vec2(1284. + 8., 839.)).with_icon(icon_data); + } if let Ok(log_file) = get_log_file() { // delete log file when it is too big @@ -158,7 +174,7 @@ fn main() { log::info!("Starting iCY TERM {}", *VERSION); - if let Err(err) = eframe::run_native(&DEFAULT_TITLE, native_options, Box::new(|cc| Box::new(MainWindow::new(cc)))) { + if let Err(err) = eframe::run_native(&DEFAULT_TITLE, native_options, Box::new(|cc| Box::new(MainWindow::new(cc, options)))) { log::error!("Error returned by run_native: {}", err); } log::info!("shutting down."); diff --git a/crates/icy_term/src/ui/app.rs b/crates/icy_term/src/ui/app.rs index 98ea304..79fa6fe 100644 --- a/crates/icy_term/src/ui/app.rs +++ b/crates/icy_term/src/ui/app.rs @@ -4,7 +4,7 @@ use std::{path::PathBuf, sync::Arc, time::Duration}; use directories::UserDirs; use eframe::egui::{self}; -use egui::{mutex::Mutex, FontId}; +use egui::{mutex::Mutex, FontId, Rect}; use icy_engine::Position; use icy_net::{ protocol::TransferState, @@ -24,20 +24,12 @@ use crate::{ use super::{MainWindow, MainWindowMode}; impl MainWindow { - pub fn new(cc: &eframe::CreationContext<'_>) -> Self { + pub fn new(cc: &eframe::CreationContext<'_>, options: Options) -> Self { use egui::FontFamily::Proportional; use egui::TextStyle::{Body, Button, Heading, Monospace, Small}; egui_extras::install_image_loaders(&cc.egui_ctx); let gl = cc.gl.as_ref().expect("You need to run eframe with the glow backend"); - let options = match Options::load_options() { - Ok(options) => options, - Err(e) => { - log::error!("Error reading dialing_directory: {e}"); - Options::default() - } - }; - let mut view = BufferView::new(gl); view.interactive = true; view.get_edit_state_mut().set_unicode_converter(get_unicode_converter(&TerminalEmulation::Ansi)); @@ -148,7 +140,6 @@ impl MainWindow { ] .into(); ctx.set_style(style); - view } } @@ -167,6 +158,21 @@ impl eframe::App for MainWindow { #[cfg(not(target_arch = "wasm32"))] self.update_title(ctx); + ctx.input(|i| { + if let Some(or) = i.viewport().outer_rect { + if let Some(ir) = i.viewport().inner_rect { + let rect = Rect { + min: or.min, + max: (ir.max - ir.min).to_pos2(), + }; + if self.state.options.window_rect != Some(rect) { + self.state.options.window_rect = Some(rect); + self.state.store_options(); + } + } + } + }); + match self.get_mode() { MainWindowMode::ShowTerminal => { self.handle_terminal_key_binds(ctx); diff --git a/crates/icy_term/src/ui/util/screen_modes.rs b/crates/icy_term/src/ui/util/screen_modes.rs index 497280d..67f3652 100644 --- a/crates/icy_term/src/ui/util/screen_modes.rs +++ b/crates/icy_term/src/ui/util/screen_modes.rs @@ -1,6 +1,8 @@ use std::fmt::Display; -use icy_engine::{BitFont, Color, Palette, Size, ATARI, ATARI_DEFAULT_PALETTE, C64_DEFAULT_PALETTE, C64_LOWER, C64_UPPER, CP437, VIEWDATA, VIEWDATA_PALETTE}; +use icy_engine::{ + BitFont, Color, Palette, Size, ATARI, ATARI_DEFAULT_PALETTE, C64_DEFAULT_PALETTE, C64_LOWER, C64_UPPER, CP437, IBM_VGA50_SAUCE, VIEWDATA, VIEWDATA_PALETTE, +}; use icy_engine_gui::BufferInputMode; use crate::ui::MainWindow; @@ -100,11 +102,21 @@ impl ScreenMode { } pub fn set_mode(&self, main_window: &MainWindow) { + main_window.buffer_view.lock().get_buffer_mut().set_default_size(self.get_window_size()); main_window.buffer_view.lock().get_buffer_mut().set_size(self.get_window_size()); main_window.buffer_view.lock().get_buffer_mut().terminal_state.set_size(self.get_window_size()); match self { // ScreenMode::Cga(_, h) | ScreenMode::Ega(_, h) | - ScreenMode::Vga(_, _) | ScreenMode::Default => { + ScreenMode::Vga(_x, y) => { + main_window.buffer_view.lock().get_buffer_mut().clear_font_table(); + main_window + .buffer_view + .lock() + .get_buffer_mut() + .set_font(0, BitFont::from_bytes("", if *y >= 50 { IBM_VGA50_SAUCE } else { CP437 }).unwrap()); + main_window.buffer_view.lock().get_buffer_mut().palette = Palette::dos_default(); + } + ScreenMode::Default => { main_window.buffer_view.lock().get_buffer_mut().clear_font_table(); main_window .buffer_view