Cleaning and Version upgrade to 0.2.0
This commit is contained in:
parent
0f7d9f060e
commit
9efe1374e9
|
|
@ -602,7 +602,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "post_maker"
|
name = "post_maker"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "post_maker"
|
name = "post_maker"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Post Maker helps you to make post for instagram and other social madia apps easily"
|
description = "Post Maker helps you to make post for instagram and other social madia apps easily"
|
||||||
authors = ["Piyush Raj <piyush.raj.kit@gmail.com>"]
|
authors = ["Piyush Raj <piyush.raj.kit@gmail.com>"]
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///! load, save configuration and parse cli args
|
//! load, save configuration and parse cli args
|
||||||
use crate::{config_picker::ConfigPicker, globals};
|
use crate::{config_picker::ConfigPicker, globals};
|
||||||
use clap::{ArgEnum, Parser};
|
use clap::{ArgEnum, Parser};
|
||||||
use fltk::dialog;
|
use fltk::dialog;
|
||||||
|
|
@ -27,6 +27,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
/// Directory where all Configurations are present
|
||||||
static ref CONFIG_DIR: PathBuf = {
|
static ref CONFIG_DIR: PathBuf = {
|
||||||
let dir = match dirs::config_dir() {
|
let dir = match dirs::config_dir() {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
|
|
@ -45,8 +46,12 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
dir
|
dir
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Configuration File
|
||||||
static ref CONFIG_FILE: PathBuf = CONFIG_DIR.join("post_maker.config");
|
static ref CONFIG_FILE: PathBuf = CONFIG_DIR.join("post_maker.config");
|
||||||
static ref LOG_PATH: PathBuf = CONFIG_DIR.join("post_maker.log");
|
|
||||||
|
/// Log File
|
||||||
|
static ref LOG_FILE: PathBuf = CONFIG_DIR.join("post_maker.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simple program calculate size of stuff in quote image
|
/// Simple program calculate size of stuff in quote image
|
||||||
|
|
@ -103,14 +108,19 @@ impl Into<ThemeType> for Themes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn args() -> Args {
|
||||||
|
let args = Args::parse();
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
/// Configuation file
|
/// Configuation file
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub(crate) struct ConfigFile {
|
pub(crate) struct ConfigFile {
|
||||||
pub(crate) quote_font_ttf: String,
|
pub(crate) quote_font: String,
|
||||||
pub(crate) subquote_font_ttf: String,
|
pub(crate) subquote_font: String,
|
||||||
pub(crate) subquote2_font_ttf: String,
|
pub(crate) subquote2_font: String,
|
||||||
pub(crate) tag_font_ttf: String,
|
pub(crate) tag_font: String,
|
||||||
pub(crate) tag2_font_ttf: String,
|
pub(crate) tag2_font: String,
|
||||||
pub(crate) quote_font_ratio: f64,
|
pub(crate) quote_font_ratio: f64,
|
||||||
pub(crate) subquote_font_ratio: f64,
|
pub(crate) subquote_font_ratio: f64,
|
||||||
pub(crate) subquote2_font_ratio: f64,
|
pub(crate) subquote2_font_ratio: f64,
|
||||||
|
|
@ -128,11 +138,11 @@ pub(crate) struct ConfigFile {
|
||||||
impl Default for ConfigFile {
|
impl Default for ConfigFile {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
quote_font_ttf: String::new(),
|
quote_font: String::new(),
|
||||||
subquote_font_ttf: String::new(),
|
subquote_font: String::new(),
|
||||||
subquote2_font_ttf: String::new(),
|
subquote2_font: String::new(),
|
||||||
tag_font_ttf: String::new(),
|
tag_font: String::new(),
|
||||||
tag2_font_ttf: String::new(),
|
tag2_font: String::new(),
|
||||||
quote_font_ratio: 230.0,
|
quote_font_ratio: 230.0,
|
||||||
subquote_font_ratio: 230.0,
|
subquote_font_ratio: 230.0,
|
||||||
subquote2_font_ratio: 230.0,
|
subquote2_font_ratio: 230.0,
|
||||||
|
|
@ -190,6 +200,7 @@ impl ConfigFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get parsed configs from file
|
||||||
pub(crate) fn get_configs() -> Option<HashMap<String, ConfigFile>> {
|
pub(crate) fn get_configs() -> Option<HashMap<String, ConfigFile>> {
|
||||||
match std::fs::read_to_string(&*CONFIG_FILE) {
|
match std::fs::read_to_string(&*CONFIG_FILE) {
|
||||||
Ok(r) => serde_json::from_str::<HashMap<String, ConfigFile>>(&r).ok(),
|
Ok(r) => serde_json::from_str::<HashMap<String, ConfigFile>>(&r).ok(),
|
||||||
|
|
@ -197,6 +208,7 @@ pub(crate) fn get_configs() -> Option<HashMap<String, ConfigFile>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Save configs
|
||||||
pub(crate) fn save_configs(configs: HashMap<String, ConfigFile>) {
|
pub(crate) fn save_configs(configs: HashMap<String, ConfigFile>) {
|
||||||
if let Err(e) = std::fs::write(&*CONFIG_FILE, serde_json::to_string(&configs).unwrap()) {
|
if let Err(e) = std::fs::write(&*CONFIG_FILE, serde_json::to_string(&configs).unwrap()) {
|
||||||
dialog::alert_default("Can't write config!");
|
dialog::alert_default("Can't write config!");
|
||||||
|
|
@ -205,9 +217,28 @@ pub(crate) fn save_configs(configs: HashMap<String, ConfigFile>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn config() -> Args {
|
pub(crate) fn log_file() -> File {
|
||||||
let args = Args::parse();
|
match File::open(&*LOG_FILE) {
|
||||||
args
|
Ok(mut file) => {
|
||||||
|
if is_file_30_days_old(&file) {
|
||||||
|
match File::create(&*LOG_FILE) {
|
||||||
|
Ok(f) => file = f,
|
||||||
|
Err(e) => {
|
||||||
|
dialog::alert_default("Can't open log file!");
|
||||||
|
panic!("{:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file
|
||||||
|
}
|
||||||
|
Err(_) => match File::create(&*LOG_FILE) {
|
||||||
|
Ok(f) => f,
|
||||||
|
Err(e) => {
|
||||||
|
dialog::alert_default("Can't open log file!");
|
||||||
|
panic!("{:?}", e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_file_30_days_old(file: &File) -> bool {
|
pub(crate) fn is_file_30_days_old(file: &File) -> bool {
|
||||||
|
|
@ -222,27 +253,3 @@ pub(crate) fn is_file_30_days_old(file: &File) -> bool {
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn log_file() -> File {
|
|
||||||
match File::open(&*LOG_PATH) {
|
|
||||||
Ok(mut file) => {
|
|
||||||
if is_file_30_days_old(&file) {
|
|
||||||
match File::create(&*LOG_PATH) {
|
|
||||||
Ok(f) => file = f,
|
|
||||||
Err(e) => {
|
|
||||||
dialog::alert_default("Can't open log file!");
|
|
||||||
panic!("{:?}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file
|
|
||||||
}
|
|
||||||
Err(_) => match File::create(&*LOG_PATH) {
|
|
||||||
Ok(f) => f,
|
|
||||||
Err(e) => {
|
|
||||||
dialog::alert_default("Can't open log file!");
|
|
||||||
panic!("{:?}", e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@
|
||||||
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{cell::RefCell, rc::Rc};
|
//! Picker to pick config if multiple configs are present or defalut config is not present
|
||||||
|
|
||||||
use crate::globals;
|
use crate::globals;
|
||||||
use fltk::{
|
use fltk::{
|
||||||
app,
|
app,
|
||||||
|
|
@ -25,6 +24,7 @@ use fltk::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
window::Window,
|
window::Window,
|
||||||
};
|
};
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
pub(crate) struct ConfigPicker {
|
pub(crate) struct ConfigPicker {
|
||||||
pub(crate) win: Window,
|
pub(crate) win: Window,
|
||||||
|
|
@ -87,17 +87,21 @@ impl ConfigPicker {
|
||||||
config_picker
|
config_picker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set callbacks of elements
|
||||||
fn event(&mut self) {
|
fn event(&mut self) {
|
||||||
|
// Apply Button
|
||||||
let mut win = self.win.clone();
|
let mut win = self.win.clone();
|
||||||
self.apply_btn.set_callback(move |_| {
|
self.apply_btn.set_callback(move |_| {
|
||||||
win.hide();
|
win.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse List
|
||||||
let selected = Rc::clone(&self.selected);
|
let selected = Rc::clone(&self.selected);
|
||||||
self.browse.set_callback(move |f| {
|
self.browse.set_callback(move |f| {
|
||||||
*selected.borrow_mut() = f.selected_text();
|
*selected.borrow_mut() = f.selected_text();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Window Close
|
||||||
let selected = Rc::clone(&self.selected);
|
let selected = Rc::clone(&self.selected);
|
||||||
self.win.set_callback(move |f| {
|
self.win.set_callback(move |f| {
|
||||||
*selected.borrow_mut() = None;
|
*selected.borrow_mut() = None;
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,16 @@ pub(crate) struct ConfigWindow {
|
||||||
pub(crate) selected_browse_line: Rc<RefCell<i32>>,
|
pub(crate) selected_browse_line: Rc<RefCell<i32>>,
|
||||||
pub(crate) add_config_btn: Button,
|
pub(crate) add_config_btn: Button,
|
||||||
pub(crate) del_config_btn: Button,
|
pub(crate) del_config_btn: Button,
|
||||||
pub(crate) quote_font_ttf: Output,
|
pub(crate) quote_font: Output,
|
||||||
pub(crate) quote_font_ttf_browse: Button,
|
pub(crate) quote_font_browse: Button,
|
||||||
pub(crate) subquote_font_ttf: Output,
|
pub(crate) subquote_font: Output,
|
||||||
pub(crate) subquote_font_ttf_browse: Button,
|
pub(crate) subquote_font_browse: Button,
|
||||||
pub(crate) subquote2_font_ttf: Output,
|
pub(crate) subquote2_font: Output,
|
||||||
pub(crate) subquote2_font_ttf_browse: Button,
|
pub(crate) subquote2_font_browse: Button,
|
||||||
pub(crate) tag_font_ttf: Output,
|
pub(crate) tag_font: Output,
|
||||||
pub(crate) tag_font_ttf_browse: Button,
|
pub(crate) tag_font_browse: Button,
|
||||||
pub(crate) tag2_font_ttf: Output,
|
pub(crate) tag2_font: Output,
|
||||||
pub(crate) tag2_font_ttf_browse: Button,
|
pub(crate) tag2_font_browse: Button,
|
||||||
pub(crate) quote_font_ratio: ValueInput,
|
pub(crate) quote_font_ratio: ValueInput,
|
||||||
pub(crate) subquote_font_ratio: ValueInput,
|
pub(crate) subquote_font_ratio: ValueInput,
|
||||||
pub(crate) subquote2_font_ratio: ValueInput,
|
pub(crate) subquote2_font_ratio: ValueInput,
|
||||||
|
|
@ -64,8 +64,10 @@ pub(crate) struct ConfigWindow {
|
||||||
pub(crate) tag2_position_ratio: ValueInput,
|
pub(crate) tag2_position_ratio: ValueInput,
|
||||||
pub(crate) image_ratio_width: ValueInput,
|
pub(crate) image_ratio_width: ValueInput,
|
||||||
pub(crate) image_ratio_height: ValueInput,
|
pub(crate) image_ratio_height: ValueInput,
|
||||||
pub(crate) layer_rgb: Button,
|
/// RGB value of top translucent layer
|
||||||
pub(crate) layer_alpha: ValueInput,
|
pub(crate) translucent_layer_rgb: Button,
|
||||||
|
/// opacity value of top translucent layer
|
||||||
|
pub(crate) translucent_layer_alpha: ValueInput,
|
||||||
pub(crate) defaults_btn: Button,
|
pub(crate) defaults_btn: Button,
|
||||||
pub(crate) save_btn: Button,
|
pub(crate) save_btn: Button,
|
||||||
pub(crate) cancel_btn: Button,
|
pub(crate) cancel_btn: Button,
|
||||||
|
|
@ -112,73 +114,73 @@ impl ConfigWindow {
|
||||||
let row_grp = Flex::default().row();
|
let row_grp = Flex::default().row();
|
||||||
// column 1
|
// column 1
|
||||||
let mut col_grp = Flex::default().column();
|
let mut col_grp = Flex::default().column();
|
||||||
let mut quote_font_ttf_grp = Flex::default().row();
|
let mut quote_font_grp = Flex::default().row();
|
||||||
quote_font_ttf_grp.set_size(
|
quote_font_grp.set_size(
|
||||||
&Frame::default()
|
&Frame::default()
|
||||||
.with_label("Quote")
|
.with_label("Quote")
|
||||||
.with_align(Align::Right | Align::Inside),
|
.with_align(Align::Right | Align::Inside),
|
||||||
130,
|
130,
|
||||||
);
|
);
|
||||||
let quote_font_ttf = Output::default();
|
let quote_font = Output::default();
|
||||||
let quote_font_ttf_browse = Button::default().with_label("Pick");
|
let quote_font_browse = Button::default().with_label("Pick");
|
||||||
quote_font_ttf_grp.set_size("e_font_ttf_browse, 50);
|
quote_font_grp.set_size("e_font_browse, 50);
|
||||||
quote_font_ttf_grp.end();
|
quote_font_grp.end();
|
||||||
col_grp.set_size("e_font_ttf_grp, 30);
|
col_grp.set_size("e_font_grp, 30);
|
||||||
|
|
||||||
let mut subquote_font_ttf_grp = Flex::default().row();
|
let mut subquote_font_grp = Flex::default().row();
|
||||||
subquote_font_ttf_grp.set_size(
|
subquote_font_grp.set_size(
|
||||||
&Frame::default()
|
&Frame::default()
|
||||||
.with_label("Subquote")
|
.with_label("Subquote")
|
||||||
.with_align(Align::Right | Align::Inside),
|
.with_align(Align::Right | Align::Inside),
|
||||||
130,
|
130,
|
||||||
);
|
);
|
||||||
let subquote_font_ttf = Output::default();
|
let subquote_font = Output::default();
|
||||||
let subquote_font_ttf_browse = Button::default().with_label("Pick");
|
let subquote_font_browse = Button::default().with_label("Pick");
|
||||||
subquote_font_ttf_grp.set_size(&subquote_font_ttf_browse, 50);
|
subquote_font_grp.set_size(&subquote_font_browse, 50);
|
||||||
subquote_font_ttf_grp.end();
|
subquote_font_grp.end();
|
||||||
col_grp.set_size(&subquote_font_ttf_grp, 30);
|
col_grp.set_size(&subquote_font_grp, 30);
|
||||||
|
|
||||||
let mut subquote2_font_ttf_grp = Flex::default().row();
|
let mut subquote2_font_grp = Flex::default().row();
|
||||||
subquote2_font_ttf_grp.set_size(
|
subquote2_font_grp.set_size(
|
||||||
&Frame::default()
|
&Frame::default()
|
||||||
.with_label("Subquote 2")
|
.with_label("Subquote 2")
|
||||||
.with_align(Align::Right | Align::Inside),
|
.with_align(Align::Right | Align::Inside),
|
||||||
130,
|
130,
|
||||||
);
|
);
|
||||||
let subquote2_font_ttf = Output::default();
|
let subquote2_font = Output::default();
|
||||||
let subquote2_font_ttf_browse = Button::default().with_label("Pick");
|
let subquote2_font_browse = Button::default().with_label("Pick");
|
||||||
subquote2_font_ttf_grp.set_size(&subquote2_font_ttf_browse, 50);
|
subquote2_font_grp.set_size(&subquote2_font_browse, 50);
|
||||||
subquote2_font_ttf_grp.end();
|
subquote2_font_grp.end();
|
||||||
col_grp.set_size(&subquote2_font_ttf_grp, 30);
|
col_grp.set_size(&subquote2_font_grp, 30);
|
||||||
col_grp.end();
|
col_grp.end();
|
||||||
|
|
||||||
// column 2
|
// column 2
|
||||||
let mut col_grp = Flex::default().column();
|
let mut col_grp = Flex::default().column();
|
||||||
let mut tag_font_ttf_grp = Flex::default().row();
|
let mut tag_font_grp = Flex::default().row();
|
||||||
tag_font_ttf_grp.set_size(
|
tag_font_grp.set_size(
|
||||||
&Frame::default()
|
&Frame::default()
|
||||||
.with_label("Tag")
|
.with_label("Tag")
|
||||||
.with_align(Align::Right | Align::Inside),
|
.with_align(Align::Right | Align::Inside),
|
||||||
130,
|
130,
|
||||||
);
|
);
|
||||||
let tag_font_ttf = Output::default();
|
let tag_font = Output::default();
|
||||||
let tag_font_ttf_browse = Button::default().with_label("Pick");
|
let tag_font_browse = Button::default().with_label("Pick");
|
||||||
tag_font_ttf_grp.set_size(&tag_font_ttf_browse, 50);
|
tag_font_grp.set_size(&tag_font_browse, 50);
|
||||||
tag_font_ttf_grp.end();
|
tag_font_grp.end();
|
||||||
col_grp.set_size(&tag_font_ttf_grp, 30);
|
col_grp.set_size(&tag_font_grp, 30);
|
||||||
|
|
||||||
let mut tag2_font_ttf_grp = Flex::default().row();
|
let mut tag2_font_grp = Flex::default().row();
|
||||||
tag2_font_ttf_grp.set_size(
|
tag2_font_grp.set_size(
|
||||||
&Frame::default()
|
&Frame::default()
|
||||||
.with_label("Tag 2")
|
.with_label("Tag 2")
|
||||||
.with_align(Align::Right | Align::Inside),
|
.with_align(Align::Right | Align::Inside),
|
||||||
130,
|
130,
|
||||||
);
|
);
|
||||||
let tag2_font_ttf = Output::default();
|
let tag2_font = Output::default();
|
||||||
let tag2_font_ttf_browse = Button::default().with_label("Pick");
|
let tag2_font_browse = Button::default().with_label("Pick");
|
||||||
tag2_font_ttf_grp.set_size(&tag2_font_ttf_browse, 50);
|
tag2_font_grp.set_size(&tag2_font_browse, 50);
|
||||||
tag2_font_ttf_grp.end();
|
tag2_font_grp.end();
|
||||||
col_grp.set_size(&tag2_font_ttf_grp, 30);
|
col_grp.set_size(&tag2_font_grp, 30);
|
||||||
col_grp.end();
|
col_grp.end();
|
||||||
row_grp.end();
|
row_grp.end();
|
||||||
col.set_size(&row_grp, 110);
|
col.set_size(&row_grp, 110);
|
||||||
|
|
@ -355,16 +357,16 @@ impl ConfigWindow {
|
||||||
hint.set_label_size(12);
|
hint.set_label_size(12);
|
||||||
col.set_size(&hint, 20);
|
col.set_size(&hint, 20);
|
||||||
|
|
||||||
let mut darklayer_flex = Flex::default().row();
|
let mut translucent_layer_flex = Flex::default().row();
|
||||||
darklayer_flex.set_pad(2);
|
translucent_layer_flex.set_pad(2);
|
||||||
darklayer_flex.set_size(&Frame::default().with_label("Colour"), 50);
|
translucent_layer_flex.set_size(&Frame::default().with_label("Colour"), 50);
|
||||||
let mut layer_rgb = Button::default();
|
let mut translucent_layer_rgb = Button::default();
|
||||||
layer_rgb.set_frame(enums::FrameType::BorderBox);
|
translucent_layer_rgb.set_frame(enums::FrameType::BorderBox);
|
||||||
|
|
||||||
darklayer_flex.set_size(&Frame::default().with_label("Alpha"), 50);
|
translucent_layer_flex.set_size(&Frame::default().with_label("Alpha"), 50);
|
||||||
let layer_alpha = ValueInput::default();
|
let translucent_layer_alpha = ValueInput::default();
|
||||||
darklayer_flex.end();
|
translucent_layer_flex.end();
|
||||||
col.set_size(&darklayer_flex, 30);
|
col.set_size(&translucent_layer_flex, 30);
|
||||||
|
|
||||||
Frame::default();
|
Frame::default();
|
||||||
|
|
||||||
|
|
@ -392,16 +394,16 @@ impl ConfigWindow {
|
||||||
selected_browse_line: Rc::new(RefCell::new(0)),
|
selected_browse_line: Rc::new(RefCell::new(0)),
|
||||||
add_config_btn,
|
add_config_btn,
|
||||||
del_config_btn,
|
del_config_btn,
|
||||||
quote_font_ttf,
|
quote_font,
|
||||||
quote_font_ttf_browse,
|
quote_font_browse,
|
||||||
subquote_font_ttf,
|
subquote_font,
|
||||||
subquote_font_ttf_browse,
|
subquote_font_browse,
|
||||||
subquote2_font_ttf,
|
subquote2_font,
|
||||||
subquote2_font_ttf_browse,
|
subquote2_font_browse,
|
||||||
tag_font_ttf,
|
tag_font,
|
||||||
tag_font_ttf_browse,
|
tag_font_browse,
|
||||||
tag2_font_ttf,
|
tag2_font,
|
||||||
tag2_font_ttf_browse,
|
tag2_font_browse,
|
||||||
quote_font_ratio,
|
quote_font_ratio,
|
||||||
subquote_font_ratio,
|
subquote_font_ratio,
|
||||||
subquote2_font_ratio,
|
subquote2_font_ratio,
|
||||||
|
|
@ -414,8 +416,8 @@ impl ConfigWindow {
|
||||||
tag2_position_ratio,
|
tag2_position_ratio,
|
||||||
image_ratio_width,
|
image_ratio_width,
|
||||||
image_ratio_height,
|
image_ratio_height,
|
||||||
layer_rgb,
|
translucent_layer_rgb,
|
||||||
layer_alpha,
|
translucent_layer_alpha,
|
||||||
defaults_btn,
|
defaults_btn,
|
||||||
save_btn,
|
save_btn,
|
||||||
cancel_btn,
|
cancel_btn,
|
||||||
|
|
@ -427,6 +429,7 @@ impl ConfigWindow {
|
||||||
config_window
|
config_window
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show to edit config
|
||||||
pub(crate) fn show(&mut self) -> bool {
|
pub(crate) fn show(&mut self) -> bool {
|
||||||
let config_name = &*globals::CONFIG_NAME.read().unwrap();
|
let config_name = &*globals::CONFIG_NAME.read().unwrap();
|
||||||
self.browse.clear();
|
self.browse.clear();
|
||||||
|
|
@ -438,14 +441,12 @@ impl ConfigWindow {
|
||||||
}
|
}
|
||||||
*self.selected_browse_line.borrow_mut() = self.browse.value();
|
*self.selected_browse_line.borrow_mut() = self.browse.value();
|
||||||
let config = globals::CONFIG.read().unwrap();
|
let config = globals::CONFIG.read().unwrap();
|
||||||
self.quote_font_ttf
|
self.quote_font.set_value(config.quote_font.as_str());
|
||||||
.set_value(config.quote_font_ttf.as_str());
|
self.subquote_font.set_value(config.subquote_font.as_str());
|
||||||
self.subquote_font_ttf
|
self.subquote2_font
|
||||||
.set_value(config.subquote_font_ttf.as_str());
|
.set_value(config.subquote2_font.as_str());
|
||||||
self.subquote2_font_ttf
|
self.tag_font.set_value(config.tag_font.as_str());
|
||||||
.set_value(config.subquote2_font_ttf.as_str());
|
self.tag2_font.set_value(config.tag2_font.as_str());
|
||||||
self.tag_font_ttf.set_value(config.tag_font_ttf.as_str());
|
|
||||||
self.tag2_font_ttf.set_value(config.tag2_font_ttf.as_str());
|
|
||||||
self.quote_font_ratio.set_value(config.quote_font_ratio);
|
self.quote_font_ratio.set_value(config.quote_font_ratio);
|
||||||
self.subquote_font_ratio
|
self.subquote_font_ratio
|
||||||
.set_value(config.subquote_font_ratio);
|
.set_value(config.subquote_font_ratio);
|
||||||
|
|
@ -464,8 +465,9 @@ impl ConfigWindow {
|
||||||
.set_value(config.tag2_position_ratio);
|
.set_value(config.tag2_position_ratio);
|
||||||
self.image_ratio_width.set_value(config.image_ratio.0);
|
self.image_ratio_width.set_value(config.image_ratio.0);
|
||||||
self.image_ratio_height.set_value(config.image_ratio.1);
|
self.image_ratio_height.set_value(config.image_ratio.1);
|
||||||
utils::set_color_btn_rgba(config.color_layer, &mut self.layer_rgb);
|
utils::set_color_btn_rgba(config.color_layer, &mut self.translucent_layer_rgb);
|
||||||
self.layer_alpha.set_value(config.color_layer[3] as f64);
|
self.translucent_layer_alpha
|
||||||
|
.set_value(config.color_layer[3] as f64);
|
||||||
*self.did_save.borrow_mut() = false;
|
*self.did_save.borrow_mut() = false;
|
||||||
drop(config);
|
drop(config);
|
||||||
self.win.show();
|
self.win.show();
|
||||||
|
|
@ -475,12 +477,14 @@ impl ConfigWindow {
|
||||||
*self.did_save.borrow()
|
*self.did_save.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set callbacks of elements
|
||||||
fn event(&mut self) {
|
fn event(&mut self) {
|
||||||
let mut quote_font_ttf = self.quote_font_ttf.clone();
|
// Add new Config Button
|
||||||
let mut subquote_font_ttf = self.subquote_font_ttf.clone();
|
let mut quote_font = self.quote_font.clone();
|
||||||
let mut subquote2_font_ttf = self.subquote2_font_ttf.clone();
|
let mut subquote_font = self.subquote_font.clone();
|
||||||
let mut tag_font_ttf = self.tag_font_ttf.clone();
|
let mut subquote2_font = self.subquote2_font.clone();
|
||||||
let mut tag2_font_ttf = self.tag2_font_ttf.clone();
|
let mut tag_font = self.tag_font.clone();
|
||||||
|
let mut tag2_font = self.tag2_font.clone();
|
||||||
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
||||||
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
||||||
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
||||||
|
|
@ -493,8 +497,8 @@ impl ConfigWindow {
|
||||||
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
||||||
let mut image_ratio_width = self.image_ratio_width.clone();
|
let mut image_ratio_width = self.image_ratio_width.clone();
|
||||||
let mut image_ratio_height = self.image_ratio_height.clone();
|
let mut image_ratio_height = self.image_ratio_height.clone();
|
||||||
let mut layer_rgb = self.layer_rgb.clone();
|
let mut layer_rgb = self.translucent_layer_rgb.clone();
|
||||||
let mut layer_alpha = self.layer_alpha.clone();
|
let mut layer_alpha = self.translucent_layer_alpha.clone();
|
||||||
let mut browse = self.browse.clone();
|
let mut browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
||||||
|
|
@ -519,11 +523,11 @@ impl ConfigWindow {
|
||||||
};
|
};
|
||||||
|
|
||||||
let conf = ConfigFile::default();
|
let conf = ConfigFile::default();
|
||||||
quote_font_ttf.set_value(&conf.quote_font_ttf);
|
quote_font.set_value(&conf.quote_font);
|
||||||
subquote_font_ttf.set_value(&conf.subquote_font_ttf);
|
subquote_font.set_value(&conf.subquote_font);
|
||||||
subquote2_font_ttf.set_value(&conf.subquote2_font_ttf);
|
subquote2_font.set_value(&conf.subquote2_font);
|
||||||
tag_font_ttf.set_value(&conf.tag_font_ttf);
|
tag_font.set_value(&conf.tag_font);
|
||||||
tag2_font_ttf.set_value(&conf.tag2_font_ttf);
|
tag2_font.set_value(&conf.tag2_font);
|
||||||
quote_font_ratio.set_value(conf.quote_font_ratio);
|
quote_font_ratio.set_value(conf.quote_font_ratio);
|
||||||
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
||||||
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
||||||
|
|
@ -545,11 +549,12 @@ impl ConfigWindow {
|
||||||
layer_rgb.redraw();
|
layer_rgb.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut quote_font_ttf = self.quote_font_ttf.clone();
|
// Delete selected Config Button
|
||||||
let mut subquote_font_ttf = self.subquote_font_ttf.clone();
|
let mut quote_font = self.quote_font.clone();
|
||||||
let mut subquote2_font_ttf = self.subquote2_font_ttf.clone();
|
let mut subquote_font = self.subquote_font.clone();
|
||||||
let mut tag_font_ttf = self.tag_font_ttf.clone();
|
let mut subquote2_font = self.subquote2_font.clone();
|
||||||
let mut tag2_font_ttf = self.tag2_font_ttf.clone();
|
let mut tag_font = self.tag_font.clone();
|
||||||
|
let mut tag2_font = self.tag2_font.clone();
|
||||||
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
||||||
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
||||||
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
||||||
|
|
@ -562,8 +567,8 @@ impl ConfigWindow {
|
||||||
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
||||||
let mut image_ratio_width = self.image_ratio_width.clone();
|
let mut image_ratio_width = self.image_ratio_width.clone();
|
||||||
let mut image_ratio_height = self.image_ratio_height.clone();
|
let mut image_ratio_height = self.image_ratio_height.clone();
|
||||||
let mut layer_rgb = self.layer_rgb.clone();
|
let mut layer_rgb = self.translucent_layer_rgb.clone();
|
||||||
let mut layer_alpha = self.layer_alpha.clone();
|
let mut layer_alpha = self.translucent_layer_alpha.clone();
|
||||||
let mut browse = self.browse.clone();
|
let mut browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
||||||
|
|
@ -587,11 +592,11 @@ impl ConfigWindow {
|
||||||
*selected_browse_line.borrow_mut() = browse.value();
|
*selected_browse_line.borrow_mut() = browse.value();
|
||||||
|
|
||||||
if let Some(conf) = configs.borrow().get(&browse.selected_text().unwrap()) {
|
if let Some(conf) = configs.borrow().get(&browse.selected_text().unwrap()) {
|
||||||
quote_font_ttf.set_value(&conf.quote_font_ttf);
|
quote_font.set_value(&conf.quote_font);
|
||||||
subquote_font_ttf.set_value(&conf.subquote_font_ttf);
|
subquote_font.set_value(&conf.subquote_font);
|
||||||
subquote2_font_ttf.set_value(&conf.subquote2_font_ttf);
|
subquote2_font.set_value(&conf.subquote2_font);
|
||||||
tag_font_ttf.set_value(&conf.tag_font_ttf);
|
tag_font.set_value(&conf.tag_font);
|
||||||
tag2_font_ttf.set_value(&conf.tag2_font_ttf);
|
tag2_font.set_value(&conf.tag2_font);
|
||||||
quote_font_ratio.set_value(conf.quote_font_ratio);
|
quote_font_ratio.set_value(conf.quote_font_ratio);
|
||||||
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
||||||
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
||||||
|
|
@ -610,11 +615,12 @@ impl ConfigWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut quote_font_ttf = self.quote_font_ttf.clone();
|
// Browse Config List
|
||||||
let mut subquote_font_ttf = self.subquote_font_ttf.clone();
|
let mut quote_font = self.quote_font.clone();
|
||||||
let mut subquote2_font_ttf = self.subquote2_font_ttf.clone();
|
let mut subquote_font = self.subquote_font.clone();
|
||||||
let mut tag_font_ttf = self.tag_font_ttf.clone();
|
let mut subquote2_font = self.subquote2_font.clone();
|
||||||
let mut tag2_font_ttf = self.tag2_font_ttf.clone();
|
let mut tag_font = self.tag_font.clone();
|
||||||
|
let mut tag2_font = self.tag2_font.clone();
|
||||||
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
||||||
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
||||||
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
||||||
|
|
@ -627,8 +633,8 @@ impl ConfigWindow {
|
||||||
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
||||||
let mut image_ratio_width = self.image_ratio_width.clone();
|
let mut image_ratio_width = self.image_ratio_width.clone();
|
||||||
let mut image_ratio_height = self.image_ratio_height.clone();
|
let mut image_ratio_height = self.image_ratio_height.clone();
|
||||||
let mut layer_rgb = self.layer_rgb.clone();
|
let mut layer_rgb = self.translucent_layer_rgb.clone();
|
||||||
let mut layer_alpha = self.layer_alpha.clone();
|
let mut layer_alpha = self.translucent_layer_alpha.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
let selected_browse_line = Rc::clone(&self.selected_browse_line);
|
||||||
self.browse.set_callback(move |f| {
|
self.browse.set_callback(move |f| {
|
||||||
|
|
@ -642,11 +648,11 @@ impl ConfigWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(conf) = configs.borrow().get(&f.selected_text().unwrap()) {
|
if let Some(conf) = configs.borrow().get(&f.selected_text().unwrap()) {
|
||||||
quote_font_ttf.set_value(&conf.quote_font_ttf);
|
quote_font.set_value(&conf.quote_font);
|
||||||
subquote_font_ttf.set_value(&conf.subquote_font_ttf);
|
subquote_font.set_value(&conf.subquote_font);
|
||||||
subquote2_font_ttf.set_value(&conf.subquote2_font_ttf);
|
subquote2_font.set_value(&conf.subquote2_font);
|
||||||
tag_font_ttf.set_value(&conf.tag_font_ttf);
|
tag_font.set_value(&conf.tag_font);
|
||||||
tag2_font_ttf.set_value(&conf.tag2_font_ttf);
|
tag2_font.set_value(&conf.tag2_font);
|
||||||
quote_font_ratio.set_value(conf.quote_font_ratio);
|
quote_font_ratio.set_value(conf.quote_font_ratio);
|
||||||
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
||||||
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
||||||
|
|
@ -666,10 +672,11 @@ impl ConfigWindow {
|
||||||
*selected_browse_line.borrow_mut() = f.value();
|
*selected_browse_line.borrow_mut() = f.value();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse for Quote Font
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let mut quote_font_ttf = self.quote_font_ttf.clone();
|
let mut quote_font = self.quote_font.clone();
|
||||||
self.quote_font_ttf_browse.set_callback(move |_| {
|
self.quote_font_browse.set_callback(move |_| {
|
||||||
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
||||||
chooser.set_option(FileDialogOptions::UseFilterExt);
|
chooser.set_option(FileDialogOptions::UseFilterExt);
|
||||||
chooser.set_filter("*.ttf");
|
chooser.set_filter("*.ttf");
|
||||||
|
|
@ -677,19 +684,20 @@ impl ConfigWindow {
|
||||||
let path = chooser.filename();
|
let path = chooser.filename();
|
||||||
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
quote_font_ttf.set_value(path);
|
quote_font.set_value(path);
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
{
|
{
|
||||||
conf.quote_font_ttf = path.to_owned();
|
conf.quote_font = path.to_owned();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse for Subquote Font
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let mut subquote_font_ttf = self.subquote_font_ttf.clone();
|
let mut subquote_font = self.subquote_font.clone();
|
||||||
self.subquote_font_ttf_browse.set_callback(move |_| {
|
self.subquote_font_browse.set_callback(move |_| {
|
||||||
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
||||||
chooser.set_option(FileDialogOptions::UseFilterExt);
|
chooser.set_option(FileDialogOptions::UseFilterExt);
|
||||||
chooser.set_filter("*.ttf");
|
chooser.set_filter("*.ttf");
|
||||||
|
|
@ -697,19 +705,20 @@ impl ConfigWindow {
|
||||||
let path = chooser.filename();
|
let path = chooser.filename();
|
||||||
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
subquote_font_ttf.set_value(path);
|
subquote_font.set_value(path);
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
{
|
{
|
||||||
conf.subquote_font_ttf = path.to_owned();
|
conf.subquote_font = path.to_owned();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse for Subquote2 Font
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let mut subquote2_font_ttf = self.subquote2_font_ttf.clone();
|
let mut subquote2_font = self.subquote2_font.clone();
|
||||||
self.subquote2_font_ttf_browse.set_callback(move |_| {
|
self.subquote2_font_browse.set_callback(move |_| {
|
||||||
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
||||||
chooser.set_option(FileDialogOptions::UseFilterExt);
|
chooser.set_option(FileDialogOptions::UseFilterExt);
|
||||||
chooser.set_filter("*.ttf");
|
chooser.set_filter("*.ttf");
|
||||||
|
|
@ -717,19 +726,20 @@ impl ConfigWindow {
|
||||||
let path = chooser.filename();
|
let path = chooser.filename();
|
||||||
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
subquote2_font_ttf.set_value(path);
|
subquote2_font.set_value(path);
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
{
|
{
|
||||||
conf.subquote2_font_ttf = path.to_owned();
|
conf.subquote2_font = path.to_owned();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse for Tag Font
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let mut tag_font_ttf = self.tag_font_ttf.clone();
|
let mut tag_font = self.tag_font.clone();
|
||||||
self.tag_font_ttf_browse.set_callback(move |_| {
|
self.tag_font_browse.set_callback(move |_| {
|
||||||
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
||||||
chooser.set_option(FileDialogOptions::UseFilterExt);
|
chooser.set_option(FileDialogOptions::UseFilterExt);
|
||||||
chooser.set_filter("*.ttf");
|
chooser.set_filter("*.ttf");
|
||||||
|
|
@ -737,19 +747,20 @@ impl ConfigWindow {
|
||||||
let path = chooser.filename();
|
let path = chooser.filename();
|
||||||
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
tag_font_ttf.set_value(path);
|
tag_font.set_value(path);
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
{
|
{
|
||||||
conf.tag_font_ttf = path.to_owned();
|
conf.tag_font = path.to_owned();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Browse for Tag2 Font
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let mut tag2_font_ttf = self.tag2_font_ttf.clone();
|
let mut tag2_font = self.tag2_font.clone();
|
||||||
self.tag2_font_ttf_browse.set_callback(move |_| {
|
self.tag2_font_browse.set_callback(move |_| {
|
||||||
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
let mut chooser = NativeFileChooser::new(fltk::dialog::FileDialogType::BrowseFile);
|
||||||
chooser.set_option(FileDialogOptions::UseFilterExt);
|
chooser.set_option(FileDialogOptions::UseFilterExt);
|
||||||
chooser.set_filter("*.ttf");
|
chooser.set_filter("*.ttf");
|
||||||
|
|
@ -757,12 +768,12 @@ impl ConfigWindow {
|
||||||
let path = chooser.filename();
|
let path = chooser.filename();
|
||||||
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
let path = std::fs::canonicalize(&path).unwrap_or(path);
|
||||||
let path = path.to_str().unwrap();
|
let path = path.to_str().unwrap();
|
||||||
tag2_font_ttf.set_value(path);
|
tag2_font.set_value(path);
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
{
|
{
|
||||||
conf.tag2_font_ttf = path.to_owned();
|
conf.tag2_font = path.to_owned();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -771,8 +782,7 @@ impl ConfigWindow {
|
||||||
win.hide();
|
win.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Font size ratio
|
// Quote font size ratio
|
||||||
|
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.quote_font_ratio.handle(move |f, ev| {
|
self.quote_font_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -787,6 +797,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote font size ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.subquote_font_ratio.handle(move |f, ev| {
|
self.subquote_font_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -801,6 +812,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote2 font size ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.subquote2_font_ratio.handle(move |f, ev| {
|
self.subquote2_font_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -815,6 +827,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag font size ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.tag_font_ratio.handle(move |f, ev| {
|
self.tag_font_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -829,6 +842,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag2 font size ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.tag2_font_ratio.handle(move |f, ev| {
|
self.tag2_font_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -843,8 +857,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
// text Position
|
// Quote position ratio
|
||||||
|
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.quote_position_ratio.handle(move |f, ev| {
|
self.quote_position_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -859,6 +872,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote position ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.subquote_position_ratio.handle(move |f, ev| {
|
self.subquote_position_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -873,6 +887,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote2 position ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.subquote2_position_ratio.handle(move |f, ev| {
|
self.subquote2_position_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -887,6 +902,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag position ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.tag_position_ratio.handle(move |f, ev| {
|
self.tag_position_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -901,6 +917,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag2 position ratio
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.tag2_position_ratio.handle(move |f, ev| {
|
self.tag2_position_ratio.handle(move |f, ev| {
|
||||||
|
|
@ -915,7 +932,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
// iamge ratio
|
// Image Ratio Width
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.image_ratio_width.handle(move |f, ev| {
|
self.image_ratio_width.handle(move |f, ev| {
|
||||||
|
|
@ -930,6 +947,7 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Image Ratio Height
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.image_ratio_height.handle(move |f, ev| {
|
self.image_ratio_height.handle(move |f, ev| {
|
||||||
|
|
@ -944,11 +962,10 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
// Color
|
// Translucent Layer RGB
|
||||||
|
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.layer_rgb.set_callback(move |mut f| {
|
self.translucent_layer_rgb.set_callback(move |mut f| {
|
||||||
if let Some(conf) = configs
|
if let Some(conf) = configs
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.get_mut(&browse.selected_text().unwrap())
|
.get_mut(&browse.selected_text().unwrap())
|
||||||
|
|
@ -968,9 +985,10 @@ impl ConfigWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Translucent Layer Opacity
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
self.layer_alpha.handle(move |f, ev| {
|
self.translucent_layer_alpha.handle(move |f, ev| {
|
||||||
if ev == Event::KeyUp {
|
if ev == Event::KeyUp {
|
||||||
if f.value() > 255.0 {
|
if f.value() > 255.0 {
|
||||||
f.set_value(255.0);
|
f.set_value(255.0);
|
||||||
|
|
@ -988,11 +1006,12 @@ impl ConfigWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut quote_font_ttf = self.quote_font_ttf.clone();
|
// Reset to default configuation button
|
||||||
let mut subquote_font_ttf = self.subquote_font_ttf.clone();
|
let mut quote_font = self.quote_font.clone();
|
||||||
let mut subquote2_font_ttf = self.subquote2_font_ttf.clone();
|
let mut subquote_font = self.subquote_font.clone();
|
||||||
let mut tag_font_ttf = self.tag_font_ttf.clone();
|
let mut subquote2_font = self.subquote2_font.clone();
|
||||||
let mut tag2_font_ttf = self.tag2_font_ttf.clone();
|
let mut tag_font = self.tag_font.clone();
|
||||||
|
let mut tag2_font = self.tag2_font.clone();
|
||||||
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
let mut quote_font_ratio = self.quote_font_ratio.clone();
|
||||||
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
let mut subquote_font_ratio = self.subquote_font_ratio.clone();
|
||||||
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
let mut subquote2_font_ratio = self.subquote2_font_ratio.clone();
|
||||||
|
|
@ -1005,17 +1024,17 @@ impl ConfigWindow {
|
||||||
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
let mut tag2_position_ratio = self.tag2_position_ratio.clone();
|
||||||
let mut image_ratio_width = self.image_ratio_width.clone();
|
let mut image_ratio_width = self.image_ratio_width.clone();
|
||||||
let mut image_ratio_height = self.image_ratio_height.clone();
|
let mut image_ratio_height = self.image_ratio_height.clone();
|
||||||
let mut layer_rgb = self.layer_rgb.clone();
|
let mut layer_rgb = self.translucent_layer_rgb.clone();
|
||||||
let mut layer_alpha = self.layer_alpha.clone();
|
let mut layer_alpha = self.translucent_layer_alpha.clone();
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let browse = self.browse.clone();
|
let browse = self.browse.clone();
|
||||||
self.defaults_btn.set_callback(move |_| {
|
self.defaults_btn.set_callback(move |_| {
|
||||||
let conf = ConfigFile::default();
|
let conf = ConfigFile::default();
|
||||||
quote_font_ttf.set_value(&conf.quote_font_ttf);
|
quote_font.set_value(&conf.quote_font);
|
||||||
subquote_font_ttf.set_value(&conf.subquote_font_ttf);
|
subquote_font.set_value(&conf.subquote_font);
|
||||||
subquote2_font_ttf.set_value(&conf.subquote2_font_ttf);
|
subquote2_font.set_value(&conf.subquote2_font);
|
||||||
tag_font_ttf.set_value(&conf.tag_font_ttf);
|
tag_font.set_value(&conf.tag_font);
|
||||||
tag2_font_ttf.set_value(&conf.tag2_font_ttf);
|
tag2_font.set_value(&conf.tag2_font);
|
||||||
quote_font_ratio.set_value(conf.quote_font_ratio);
|
quote_font_ratio.set_value(conf.quote_font_ratio);
|
||||||
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
subquote_font_ratio.set_value(conf.subquote_font_ratio);
|
||||||
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
subquote2_font_ratio.set_value(conf.subquote2_font_ratio);
|
||||||
|
|
@ -1036,6 +1055,7 @@ impl ConfigWindow {
|
||||||
.insert(browse.selected_text().unwrap(), conf);
|
.insert(browse.selected_text().unwrap(), conf);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save Button
|
||||||
let configs = Rc::clone(&self.configs);
|
let configs = Rc::clone(&self.configs);
|
||||||
let did_save = Rc::clone(&self.did_save);
|
let did_save = Rc::clone(&self.did_save);
|
||||||
let mut win = self.win.clone();
|
let mut win = self.win.clone();
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//! Window to change Crop properties of image
|
||||||
use crate::{
|
use crate::{
|
||||||
globals,
|
globals,
|
||||||
utils::{self, Coord, ImageContainer, ImageProperties},
|
utils::{self, Coord, ImageContainer, ImageProperties},
|
||||||
|
|
@ -117,7 +118,7 @@ impl CropWindow {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
container.apply_scale();
|
container.apply_resize();
|
||||||
let (image_width, image_height): (f64, f64) =
|
let (image_width, image_height): (f64, f64) =
|
||||||
Coord::from(container.image.dimensions()).into();
|
Coord::from(container.image.dimensions()).into();
|
||||||
self.win.set_size(image_width as i32, 600);
|
self.win.set_size(image_width as i32, 600);
|
||||||
|
|
@ -147,6 +148,7 @@ impl CropWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set drawing in window
|
||||||
fn draw(&mut self) {
|
fn draw(&mut self) {
|
||||||
let container = Rc::clone(&self.container);
|
let container = Rc::clone(&self.container);
|
||||||
self.page.image_view.draw(move |f| {
|
self.page.image_view.draw(move |f| {
|
||||||
|
|
@ -186,7 +188,9 @@ impl CropWindow {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set callbacks of elements
|
||||||
fn event(&mut self) {
|
fn event(&mut self) {
|
||||||
|
// Handle mosue events for crop area in image view
|
||||||
let mut last: Option<(f64, f64)> = None;
|
let mut last: Option<(f64, f64)> = None;
|
||||||
let container = Rc::clone(&self.container);
|
let container = Rc::clone(&self.container);
|
||||||
self.page.image_view.handle(move |f, ev| {
|
self.page.image_view.handle(move |f, ev| {
|
||||||
|
|
@ -246,6 +250,7 @@ impl CropWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Window close
|
||||||
let mut wind = self.win.clone();
|
let mut wind = self.win.clone();
|
||||||
self.apply_btn.set_callback(move |_| {
|
self.apply_btn.set_callback(move |_| {
|
||||||
wind.do_callback();
|
wind.do_callback();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
//! Thread to manage drawing in background
|
//! Thread to manage drawing in background
|
||||||
|
|
||||||
|
use crate::utils::{ImageContainer, ImageProperties};
|
||||||
use crate::{
|
use crate::{
|
||||||
main_window::{MainWindow, Page},
|
main_window::{MainWindow, Page},
|
||||||
utils::{self, ImagePropertiesFile},
|
utils::{self, ImagePropertiesFile},
|
||||||
|
|
@ -30,15 +31,12 @@ use fltk::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
valuator::Slider,
|
valuator::Slider,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{mpsc, Arc, RwLock},
|
sync::{mpsc, Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::{ImageContainer, ImageProperties};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum DrawMessage {
|
pub(crate) enum DrawMessage {
|
||||||
/// Open file or cropped file
|
/// Open file or cropped file
|
||||||
|
|
@ -57,6 +55,7 @@ pub(crate) enum DrawMessage {
|
||||||
Delete,
|
Delete,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Spawn thread to manage all actions related to image, like: edit, save, delete
|
||||||
pub(crate) fn spawn_image_thread(
|
pub(crate) fn spawn_image_thread(
|
||||||
reciver: mpsc::Receiver<DrawMessage>,
|
reciver: mpsc::Receiver<DrawMessage>,
|
||||||
app_sender: app::Sender<crate::AppMessage>,
|
app_sender: app::Sender<crate::AppMessage>,
|
||||||
|
|
@ -70,8 +69,8 @@ pub(crate) fn spawn_image_thread(
|
||||||
let mut subquote2 = main_win.subquote2.clone();
|
let mut subquote2 = main_win.subquote2.clone();
|
||||||
let mut tag = main_win.tag.clone();
|
let mut tag = main_win.tag.clone();
|
||||||
let mut tag2 = main_win.tag2.clone();
|
let mut tag2 = main_win.tag2.clone();
|
||||||
let mut layer_rgb = main_win.layer_rgb.clone();
|
let mut layer_rgb = main_win.translucent_layer_rgb.clone();
|
||||||
let mut layer_alpha = main_win.layer_alpha.clone();
|
let mut layer_alpha = main_win.translucent_layer_alpha.clone();
|
||||||
let mut quote_position = main_win.quote_position.clone();
|
let mut quote_position = main_win.quote_position.clone();
|
||||||
let mut subquote_position = main_win.subquote_position.clone();
|
let mut subquote_position = main_win.subquote_position.clone();
|
||||||
let mut subquote2_position = main_win.subquote2_position.clone();
|
let mut subquote2_position = main_win.subquote2_position.clone();
|
||||||
|
|
@ -217,6 +216,7 @@ pub(crate) fn spawn_image_thread(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads the selected image in file_choice to ImageContainer to edit
|
||||||
fn load_image(
|
fn load_image(
|
||||||
file_choice: &mut menu::Choice,
|
file_choice: &mut menu::Choice,
|
||||||
images_path: Arc<RwLock<Vec<PathBuf>>>,
|
images_path: Arc<RwLock<Vec<PathBuf>>>,
|
||||||
|
|
@ -313,8 +313,8 @@ fn load_image(
|
||||||
tag2_position_slider.set_range(0.0, properties.original_dimension.1);
|
tag2_position_slider.set_range(0.0, properties.original_dimension.1);
|
||||||
tag2_position_slider.set_value(properties.tag2_position);
|
tag2_position_slider.set_value(properties.tag2_position);
|
||||||
|
|
||||||
utils::set_color_btn_rgba(properties.color_layer, layer_rgb);
|
utils::set_color_btn_rgba(properties.translucent_layer_color, layer_rgb);
|
||||||
layer_alpha.set_value(properties.color_layer[3] as f64);
|
layer_alpha.set_value(properties.translucent_layer_color[3] as f64);
|
||||||
|
|
||||||
dimension.set_label(&format!(
|
dimension.set_label(&format!(
|
||||||
"[{}x{}]",
|
"[{}x{}]",
|
||||||
|
|
@ -331,7 +331,7 @@ fn load_image(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cont.apply_scale();
|
cont.apply_resize();
|
||||||
let (width, height) = cont.properties.read().unwrap().dimension;
|
let (width, height) = cont.properties.read().unwrap().dimension;
|
||||||
page.col_flex.set_size(&page.image, height as i32);
|
page.col_flex.set_size(&page.image, height as i32);
|
||||||
page.row_flex.set_size(&page.col_flex, width as i32);
|
page.row_flex.set_size(&page.col_flex, width as i32);
|
||||||
|
|
@ -342,6 +342,8 @@ fn load_image(
|
||||||
flush_buffer(&app_sender, &container);
|
flush_buffer(&app_sender, &container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Flush the Buffer from image container to drawing buffer for fltk
|
||||||
|
// for drawing buffer for fltk (check in main.rs)
|
||||||
fn flush_buffer(app_sender: &app::Sender<crate::AppMessage>, container: &Option<ImageContainer>) {
|
fn flush_buffer(app_sender: &app::Sender<crate::AppMessage>, container: &Option<ImageContainer>) {
|
||||||
match container {
|
match container {
|
||||||
Some(cont) => {
|
Some(cont) => {
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,21 @@ use rusttype::Font;
|
||||||
use std::{ffi::OsString, io::Read, sync::RwLock};
|
use std::{ffi::OsString, io::Read, sync::RwLock};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
/// Theme for the GUI
|
||||||
pub(crate) static ref THEME: config::Themes =
|
pub(crate) static ref THEME: config::Themes =
|
||||||
config::config().theme.unwrap_or(config::Themes::System);
|
config::args().theme.unwrap_or(config::Themes::System);
|
||||||
|
|
||||||
|
/// Name of config to use
|
||||||
pub(crate) static ref CONFIG_NAME: RwLock<String> = RwLock::new("default".to_owned());
|
pub(crate) static ref CONFIG_NAME: RwLock<String> = RwLock::new("default".to_owned());
|
||||||
|
|
||||||
|
/// Loaded configuration
|
||||||
pub(crate) static ref CONFIG: RwLock<config::ConfigFile> =
|
pub(crate) static ref CONFIG: RwLock<config::ConfigFile> =
|
||||||
RwLock::new(config::ConfigFile::load());
|
RwLock::new(config::ConfigFile::load());
|
||||||
|
|
||||||
|
/// TTF Font for Quote
|
||||||
pub(crate) static ref FONT_QUOTE: Font<'static> = {
|
pub(crate) static ref FONT_QUOTE: Font<'static> = {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
if let Ok(mut file) = std::fs::File::open(CONFIG.read().unwrap().quote_font_ttf.as_str()) {
|
if let Ok(mut file) = std::fs::File::open(CONFIG.read().unwrap().quote_font.as_str()) {
|
||||||
if let Ok(_) = file.read_to_end(&mut buffer) {
|
if let Ok(_) = file.read_to_end(&mut buffer) {
|
||||||
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
||||||
return out;
|
return out;
|
||||||
|
|
@ -37,9 +44,11 @@ lazy_static! {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// TTF Font for Subquote
|
||||||
pub(crate) static ref FONT_SUBQUOTE: Font<'static> = {
|
pub(crate) static ref FONT_SUBQUOTE: Font<'static> = {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
if let Ok(mut file) = std::fs::File::open(CONFIG.read().unwrap().subquote_font_ttf.as_str())
|
if let Ok(mut file) = std::fs::File::open(CONFIG.read().unwrap().subquote_font.as_str())
|
||||||
{
|
{
|
||||||
if let Ok(_) = file.read_to_end(&mut buffer) {
|
if let Ok(_) = file.read_to_end(&mut buffer) {
|
||||||
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
||||||
|
|
@ -52,10 +61,12 @@ lazy_static! {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// TTF Font for Subquote 2
|
||||||
pub(crate) static ref FONT_SUBQUOTE2: Font<'static> = {
|
pub(crate) static ref FONT_SUBQUOTE2: Font<'static> = {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
if let Ok(mut file) =
|
if let Ok(mut file) =
|
||||||
std::fs::File::open(CONFIG.read().unwrap().subquote2_font_ttf.as_str())
|
std::fs::File::open(CONFIG.read().unwrap().subquote2_font.as_str())
|
||||||
{
|
{
|
||||||
if let Ok(_) = file.read_to_end(&mut buffer) {
|
if let Ok(_) = file.read_to_end(&mut buffer) {
|
||||||
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
||||||
|
|
@ -68,9 +79,11 @@ lazy_static! {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// TTF Font for Tag
|
||||||
pub(crate) static ref FONT_TAG: Font<'static> = {
|
pub(crate) static ref FONT_TAG: Font<'static> = {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
if let Ok(mut file) = std::fs::File::open(&CONFIG.read().unwrap().tag_font_ttf.as_str()) {
|
if let Ok(mut file) = std::fs::File::open(&CONFIG.read().unwrap().tag_font.as_str()) {
|
||||||
if let Ok(_) = file.read_to_end(&mut buffer) {
|
if let Ok(_) = file.read_to_end(&mut buffer) {
|
||||||
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
||||||
return out;
|
return out;
|
||||||
|
|
@ -80,9 +93,11 @@ lazy_static! {
|
||||||
rusttype::Font::try_from_vec(include_bytes!("../assets/fonts/Kalam-Regular.ttf").to_vec())
|
rusttype::Font::try_from_vec(include_bytes!("../assets/fonts/Kalam-Regular.ttf").to_vec())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// TTF Font for Tag 2
|
||||||
pub(crate) static ref FONT_TAG2: Font<'static> = {
|
pub(crate) static ref FONT_TAG2: Font<'static> = {
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
if let Ok(mut file) = std::fs::File::open(&CONFIG.read().unwrap().tag2_font_ttf.as_str()) {
|
if let Ok(mut file) = std::fs::File::open(&CONFIG.read().unwrap().tag2_font.as_str()) {
|
||||||
if let Ok(_) = file.read_to_end(&mut buffer) {
|
if let Ok(_) = file.read_to_end(&mut buffer) {
|
||||||
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
if let Some(out) = rusttype::Font::try_from_vec(buffer) {
|
||||||
return out;
|
return out;
|
||||||
|
|
@ -94,7 +109,11 @@ lazy_static! {
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Image to use for Window
|
||||||
pub(crate) static ref ICON: OsString = include_str!("../assets/icon.svg").into();
|
pub(crate) static ref ICON: OsString = include_str!("../assets/icon.svg").into();
|
||||||
|
|
||||||
|
/// Image to use for Reload Button
|
||||||
pub(crate) static ref RELOAD_ICON: OsString = {
|
pub(crate) static ref RELOAD_ICON: OsString = {
|
||||||
let img = include_str!("../assets/reload.svg");
|
let img = include_str!("../assets/reload.svg");
|
||||||
if *THEME == config::Themes::Dark || *THEME == config::Themes::HighContrast {
|
if *THEME == config::Themes::Dark || *THEME == config::Themes::HighContrast {
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ use fltk::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use fltk_theme::WidgetTheme;
|
use fltk_theme::WidgetTheme;
|
||||||
use simplelog::*;
|
|
||||||
|
|
||||||
use main_window::MainWindow;
|
use main_window::MainWindow;
|
||||||
|
use simplelog::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) enum AppMessage {
|
pub(crate) enum AppMessage {
|
||||||
|
/// Copy recived image buffer from draw_thread to Buffer for fltk frame
|
||||||
RedrawMainWindowImage(Option<Vec<u8>>),
|
RedrawMainWindowImage(Option<Vec<u8>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,9 @@ fn main() {
|
||||||
|
|
||||||
lazy_static::initialize(&globals::CONFIG);
|
lazy_static::initialize(&globals::CONFIG);
|
||||||
|
|
||||||
|
// Buffer which will br drawin on fltk frame
|
||||||
let draw_buff: Arc<RwLock<Option<Vec<u8>>>> = Arc::new(RwLock::new(None));
|
let draw_buff: Arc<RwLock<Option<Vec<u8>>>> = Arc::new(RwLock::new(None));
|
||||||
|
|
||||||
let (main_sender, main_receiver) = channel::<AppMessage>();
|
let (main_sender, main_receiver) = channel::<AppMessage>();
|
||||||
let mut main_window = MainWindow::new(main_sender, Arc::clone(&draw_buff));
|
let mut main_window = MainWindow::new(main_sender, Arc::clone(&draw_buff));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
along with Post Maker. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//! Main window where you do all editing
|
||||||
use crate::crop_window::CropWindow;
|
use crate::crop_window::CropWindow;
|
||||||
use crate::draw_thread::*;
|
use crate::draw_thread::*;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
@ -44,14 +45,17 @@ pub(crate) struct MainWindow {
|
||||||
pub(crate) back_btn: Button,
|
pub(crate) back_btn: Button,
|
||||||
pub(crate) next_btn: Button,
|
pub(crate) next_btn: Button,
|
||||||
pub(crate) save_btn: Button,
|
pub(crate) save_btn: Button,
|
||||||
|
/// To choose the file which is being edited in directory
|
||||||
pub(crate) file_choice: menu::Choice,
|
pub(crate) file_choice: menu::Choice,
|
||||||
pub(crate) quote: MultilineInput,
|
pub(crate) quote: MultilineInput,
|
||||||
pub(crate) subquote: MultilineInput,
|
pub(crate) subquote: MultilineInput,
|
||||||
pub(crate) subquote2: MultilineInput,
|
pub(crate) subquote2: MultilineInput,
|
||||||
pub(crate) tag: Input,
|
pub(crate) tag: Input,
|
||||||
pub(crate) tag2: Input,
|
pub(crate) tag2: Input,
|
||||||
pub(crate) layer_rgb: Button,
|
/// RGB value of top translucent layer
|
||||||
pub(crate) layer_alpha: Spinner,
|
pub(crate) translucent_layer_rgb: Button,
|
||||||
|
/// opacity value of top translucent layer
|
||||||
|
pub(crate) translucent_layer_alpha: Spinner,
|
||||||
pub(crate) quote_position: Spinner,
|
pub(crate) quote_position: Spinner,
|
||||||
pub(crate) subquote_position: Spinner,
|
pub(crate) subquote_position: Spinner,
|
||||||
pub(crate) subquote2_position: Spinner,
|
pub(crate) subquote2_position: Spinner,
|
||||||
|
|
@ -62,7 +66,7 @@ pub(crate) struct MainWindow {
|
||||||
pub(crate) subquote2_position_slider: Slider,
|
pub(crate) subquote2_position_slider: Slider,
|
||||||
pub(crate) tag_position_slider: Slider,
|
pub(crate) tag_position_slider: Slider,
|
||||||
pub(crate) tag2_position_slider: Slider,
|
pub(crate) tag2_position_slider: Slider,
|
||||||
pub(crate) reset_darklayer_btn: Button,
|
pub(crate) reset_translucent_layer_btn: Button,
|
||||||
pub(crate) reset_quote_position_btn: Button,
|
pub(crate) reset_quote_position_btn: Button,
|
||||||
pub(crate) reset_subquote_position_btn: Button,
|
pub(crate) reset_subquote_position_btn: Button,
|
||||||
pub(crate) reset_subquote2_position_btn: Button,
|
pub(crate) reset_subquote2_position_btn: Button,
|
||||||
|
|
@ -82,6 +86,7 @@ pub(crate) struct MainWindow {
|
||||||
pub(crate) sender: mpsc::Sender<DrawMessage>,
|
pub(crate) sender: mpsc::Sender<DrawMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Contains the elements to draw page in mid of workspace
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct Page {
|
pub(crate) struct Page {
|
||||||
pub(crate) image: Frame,
|
pub(crate) image: Frame,
|
||||||
|
|
@ -206,27 +211,27 @@ impl MainWindow {
|
||||||
|
|
||||||
// Controls right
|
// Controls right
|
||||||
let mut right_controls_flex = Flex::default().column();
|
let mut right_controls_flex = Flex::default().column();
|
||||||
let mut darklayer_head_flex = Flex::default().row();
|
let mut translucent_layer_head_flex = Flex::default().row();
|
||||||
Frame::default()
|
Frame::default()
|
||||||
.with_label("Dark Layer (RGBA):")
|
.with_label("Translucent Layer:")
|
||||||
.with_align(enums::Align::Left | enums::Align::Inside);
|
.with_align(enums::Align::Left | enums::Align::Inside);
|
||||||
let mut reset_darklayer_btn = Button::default();
|
let mut reset_darklayer_btn = Button::default();
|
||||||
reset_darklayer_btn.set_image(Some(reload_image.clone()));
|
reset_darklayer_btn.set_image(Some(reload_image.clone()));
|
||||||
darklayer_head_flex.set_size(&reset_darklayer_btn, 30);
|
translucent_layer_head_flex.set_size(&reset_darklayer_btn, 30);
|
||||||
darklayer_head_flex.end();
|
translucent_layer_head_flex.end();
|
||||||
right_controls_flex.set_size(&darklayer_head_flex, 30);
|
right_controls_flex.set_size(&translucent_layer_head_flex, 30);
|
||||||
|
|
||||||
let mut darklayer_flex = Flex::default().row();
|
let mut translucent_layer_flex = Flex::default().row();
|
||||||
darklayer_flex.set_pad(2);
|
translucent_layer_flex.set_pad(2);
|
||||||
darklayer_flex.set_size(&Frame::default().with_label("Colour"), 50);
|
translucent_layer_flex.set_size(&Frame::default().with_label("Colour"), 50);
|
||||||
let mut layer_rgb = Button::default();
|
let mut translucent_layer_rgb = Button::default();
|
||||||
layer_rgb.set_frame(enums::FrameType::BorderBox);
|
translucent_layer_rgb.set_frame(enums::FrameType::BorderBox);
|
||||||
|
|
||||||
darklayer_flex.set_size(&Frame::default().with_label("Alpha"), 50);
|
translucent_layer_flex.set_size(&Frame::default().with_label("Alpha"), 50);
|
||||||
let mut layer_alpha = Spinner::default();
|
let mut translucent_layer_alpha = Spinner::default();
|
||||||
layer_alpha.set_range(0.0, 255.0);
|
translucent_layer_alpha.set_range(0.0, 255.0);
|
||||||
darklayer_flex.end();
|
translucent_layer_flex.end();
|
||||||
right_controls_flex.set_size(&darklayer_flex, 30);
|
right_controls_flex.set_size(&translucent_layer_flex, 30);
|
||||||
|
|
||||||
let mut quote_position_flex = Flex::default().row();
|
let mut quote_position_flex = Flex::default().row();
|
||||||
quote_position_flex.set_size(
|
quote_position_flex.set_size(
|
||||||
|
|
@ -349,8 +354,8 @@ impl MainWindow {
|
||||||
subquote2,
|
subquote2,
|
||||||
tag,
|
tag,
|
||||||
tag2,
|
tag2,
|
||||||
layer_rgb,
|
translucent_layer_rgb,
|
||||||
layer_alpha,
|
translucent_layer_alpha,
|
||||||
quote_position,
|
quote_position,
|
||||||
subquote_position,
|
subquote_position,
|
||||||
subquote2_position,
|
subquote2_position,
|
||||||
|
|
@ -361,7 +366,7 @@ impl MainWindow {
|
||||||
subquote2_position_slider,
|
subquote2_position_slider,
|
||||||
tag_position_slider,
|
tag_position_slider,
|
||||||
tag2_position_slider,
|
tag2_position_slider,
|
||||||
reset_darklayer_btn,
|
reset_translucent_layer_btn: reset_darklayer_btn,
|
||||||
reset_quote_position_btn,
|
reset_quote_position_btn,
|
||||||
reset_subquote_position_btn,
|
reset_subquote_position_btn,
|
||||||
reset_subquote2_position_btn,
|
reset_subquote2_position_btn,
|
||||||
|
|
@ -391,6 +396,7 @@ impl MainWindow {
|
||||||
main_win
|
main_win
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set menubar in window
|
||||||
fn menu(&mut self) {
|
fn menu(&mut self) {
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -461,6 +467,7 @@ impl MainWindow {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set drawing in window
|
||||||
fn draw(&mut self) {
|
fn draw(&mut self) {
|
||||||
let buff = Arc::clone(&self.draw_buff);
|
let buff = Arc::clone(&self.draw_buff);
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
|
|
@ -480,7 +487,9 @@ impl MainWindow {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set callbacks of elements
|
||||||
fn events(&mut self) {
|
fn events(&mut self) {
|
||||||
|
// Resest Button for FileChoice
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let imgs = Arc::clone(&self.images_path);
|
let imgs = Arc::clone(&self.images_path);
|
||||||
|
|
@ -492,15 +501,16 @@ impl MainWindow {
|
||||||
load_dir(&path, Arc::clone(&imgs), &mut file_choice, &sender);
|
load_dir(&path, Arc::clone(&imgs), &mut file_choice, &sender);
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut layer_rgb = self.layer_rgb.clone();
|
// Reset Button for Translucent Layer
|
||||||
let mut layer_alpha = self.layer_alpha.clone();
|
let mut layer_rgb = self.translucent_layer_rgb.clone();
|
||||||
|
let mut layer_alpha = self.translucent_layer_alpha.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
self.reset_darklayer_btn.set_callback(move |_| {
|
self.reset_translucent_layer_btn.set_callback(move |_| {
|
||||||
let mut prop = properties.write().unwrap();
|
let mut prop = properties.write().unwrap();
|
||||||
let color = globals::CONFIG.read().unwrap().color_layer;
|
let color = globals::CONFIG.read().unwrap().color_layer;
|
||||||
prop.color_layer = color;
|
prop.translucent_layer_color = color;
|
||||||
prop.is_saved = false;
|
prop.is_saved = false;
|
||||||
utils::set_color_btn_rgba(color, &mut layer_rgb);
|
utils::set_color_btn_rgba(color, &mut layer_rgb);
|
||||||
layer_alpha.set_value(color[3] as f64);
|
layer_alpha.set_value(color[3] as f64);
|
||||||
|
|
@ -509,6 +519,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset Button for Quote Input
|
||||||
let mut quote_position = self.quote_position.clone();
|
let mut quote_position = self.quote_position.clone();
|
||||||
let mut quote_position_slider = self.quote_position_slider.clone();
|
let mut quote_position_slider = self.quote_position_slider.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
|
|
@ -528,6 +539,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset Button for Subquote Input
|
||||||
let mut subquote_position = self.subquote_position.clone();
|
let mut subquote_position = self.subquote_position.clone();
|
||||||
let mut subquote_position_slider = self.subquote_position_slider.clone();
|
let mut subquote_position_slider = self.subquote_position_slider.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
|
|
@ -547,6 +559,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset Button for Subquotes2 Input
|
||||||
let mut subquote2_position = self.subquote2_position.clone();
|
let mut subquote2_position = self.subquote2_position.clone();
|
||||||
let mut subquote2_position_slider = self.subquote2_position_slider.clone();
|
let mut subquote2_position_slider = self.subquote2_position_slider.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
|
|
@ -566,6 +579,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset Button for Tag Input
|
||||||
let mut tag_position = self.tag_position.clone();
|
let mut tag_position = self.tag_position.clone();
|
||||||
let mut tag_position_slider = self.tag_position_slider.clone();
|
let mut tag_position_slider = self.tag_position_slider.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
|
|
@ -585,6 +599,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset Button for Tag2 Input
|
||||||
let mut tag2_position = self.tag2_position.clone();
|
let mut tag2_position = self.tag2_position.clone();
|
||||||
let mut tag2_position_slider = self.tag2_position_slider.clone();
|
let mut tag2_position_slider = self.tag2_position_slider.clone();
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
|
|
@ -604,6 +619,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save Button
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
self.save_btn.set_callback(move |_| {
|
self.save_btn.set_callback(move |_| {
|
||||||
|
|
@ -612,6 +628,7 @@ impl MainWindow {
|
||||||
sender.send(DrawMessage::Save).unwrap()
|
sender.send(DrawMessage::Save).unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clone Button
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -625,6 +642,7 @@ impl MainWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Delete Button
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -638,6 +656,7 @@ impl MainWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Crop Button
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let mut crop_win = CropWindow::new();
|
let mut crop_win = CropWindow::new();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -651,6 +670,7 @@ impl MainWindow {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Next Image Button
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
|
|
@ -673,6 +693,7 @@ impl MainWindow {
|
||||||
sender.send(DrawMessage::Open).unwrap();
|
sender.send(DrawMessage::Open).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Back Image Button
|
||||||
let mut file_choice = self.file_choice.clone();
|
let mut file_choice = self.file_choice.clone();
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
|
|
@ -695,6 +716,7 @@ impl MainWindow {
|
||||||
sender.send(DrawMessage::Open).unwrap();
|
sender.send(DrawMessage::Open).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// File Choice
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
self.file_choice.set_callback(move |_| {
|
self.file_choice.set_callback(move |_| {
|
||||||
|
|
@ -710,6 +732,7 @@ impl MainWindow {
|
||||||
sender.send(DrawMessage::Open).unwrap();
|
sender.send(DrawMessage::Open).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Quote Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -725,6 +748,7 @@ impl MainWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -740,6 +764,7 @@ impl MainWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote2 Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -755,6 +780,7 @@ impl MainWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -770,6 +796,7 @@ impl MainWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag2 Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -785,6 +812,7 @@ impl MainWindow {
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Quote Position Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -799,6 +827,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Quote Position Slider
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -813,6 +842,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote Position Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -827,6 +857,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote Position Slider
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -841,6 +872,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote2 Position Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -855,6 +887,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Subquote2 Position Slider
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -869,6 +902,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag Position Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -883,6 +917,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag Position Slider
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -897,6 +932,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag2 Position Input
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -911,6 +947,7 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tag2 Position Slider
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
|
|
@ -924,22 +961,24 @@ impl MainWindow {
|
||||||
sender.send(DrawMessage::Flush).unwrap();
|
sender.send(DrawMessage::Flush).unwrap();
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Translucent Layer RGB
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
self.layer_rgb.set_callback(move |mut f| {
|
self.translucent_layer_rgb.set_callback(move |mut f| {
|
||||||
let mut prop = properties.write().unwrap();
|
let mut prop = properties.write().unwrap();
|
||||||
let (r, g, b) = dialog::color_chooser_with_default(
|
let (r, g, b) = dialog::color_chooser_with_default(
|
||||||
"Pick a colour",
|
"Pick a colour",
|
||||||
dialog::ColorMode::Byte,
|
dialog::ColorMode::Byte,
|
||||||
(
|
(
|
||||||
prop.color_layer[0],
|
prop.translucent_layer_color[0],
|
||||||
prop.color_layer[1],
|
prop.translucent_layer_color[1],
|
||||||
prop.color_layer[2],
|
prop.translucent_layer_color[2],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
prop.color_layer = [r, g, b, prop.color_layer[3]];
|
prop.translucent_layer_color = [r, g, b, prop.translucent_layer_color[3]];
|
||||||
utils::set_color_btn_rgba(prop.color_layer, &mut f);
|
utils::set_color_btn_rgba(prop.translucent_layer_color, &mut f);
|
||||||
f.redraw();
|
f.redraw();
|
||||||
prop.is_saved = false;
|
prop.is_saved = false;
|
||||||
sender.send(DrawMessage::RedrawToBuffer).unwrap();
|
sender.send(DrawMessage::RedrawToBuffer).unwrap();
|
||||||
|
|
@ -947,12 +986,13 @@ impl MainWindow {
|
||||||
image.redraw();
|
image.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Translucent Layer Opacity
|
||||||
let mut image = self.page.image.clone();
|
let mut image = self.page.image.clone();
|
||||||
let properties = Arc::clone(&self.properties);
|
let properties = Arc::clone(&self.properties);
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
self.layer_alpha.set_callback(move |f| {
|
self.translucent_layer_alpha.set_callback(move |f| {
|
||||||
let mut prop = properties.write().unwrap();
|
let mut prop = properties.write().unwrap();
|
||||||
prop.color_layer[3] = f.value() as u8;
|
prop.translucent_layer_color[3] = f.value() as u8;
|
||||||
prop.is_saved = false;
|
prop.is_saved = false;
|
||||||
sender.send(DrawMessage::RedrawToBuffer).unwrap();
|
sender.send(DrawMessage::RedrawToBuffer).unwrap();
|
||||||
sender.send(DrawMessage::Flush).unwrap();
|
sender.send(DrawMessage::Flush).unwrap();
|
||||||
|
|
@ -961,6 +1001,7 @@ impl MainWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Load all iamges in a directory
|
||||||
fn load_dir(
|
fn load_dir(
|
||||||
path: &PathBuf,
|
path: &PathBuf,
|
||||||
imgs: Arc<RwLock<Vec<PathBuf>>>,
|
imgs: Arc<RwLock<Vec<PathBuf>>>,
|
||||||
|
|
|
||||||
163
src/utils.rs
163
src/utils.rs
|
|
@ -102,7 +102,8 @@ impl ImageContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn apply_scale(&mut self) {
|
/// Resize image
|
||||||
|
pub(crate) fn apply_resize(&mut self) {
|
||||||
let mut prop = self.properties.write().unwrap();
|
let mut prop = self.properties.write().unwrap();
|
||||||
let (width, height) = prop.dimension;
|
let (width, height) = prop.dimension;
|
||||||
let (s_width, s_height) = ((width * 500.0) / height, 500.0);
|
let (s_width, s_height) = ((width * 500.0) / height, 500.0);
|
||||||
|
|
@ -113,6 +114,7 @@ impl ImageContainer {
|
||||||
prop.dimension = (s_width, s_height);
|
prop.dimension = (s_width, s_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Crop Image
|
||||||
pub(crate) fn apply_crop(&mut self) {
|
pub(crate) fn apply_crop(&mut self) {
|
||||||
let mut prop = self.properties.write().unwrap();
|
let mut prop = self.properties.write().unwrap();
|
||||||
let (original_width, original_height) = prop.original_dimension;
|
let (original_width, original_height) = prop.original_dimension;
|
||||||
|
|
@ -155,13 +157,14 @@ impl ImageContainer {
|
||||||
self.buffer = self.image.clone();
|
self.buffer = self.image.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Redraw: Copy image from main image to buffer and draw text and all on it
|
||||||
pub(crate) fn redraw_to_buffer(&mut self) {
|
pub(crate) fn redraw_to_buffer(&mut self) {
|
||||||
let prop = self.properties.read().unwrap();
|
let prop = self.properties.read().unwrap();
|
||||||
let mut tmp = self.image.clone();
|
let mut tmp = self.image.clone();
|
||||||
|
|
||||||
draw_layer_and_text(
|
draw_layer_and_text(
|
||||||
&mut tmp,
|
&mut tmp,
|
||||||
&prop.color_layer,
|
&prop.translucent_layer_color,
|
||||||
&prop.quote,
|
&prop.quote,
|
||||||
&prop.subquote,
|
&prop.subquote,
|
||||||
&prop.subquote2,
|
&prop.subquote2,
|
||||||
|
|
@ -178,6 +181,7 @@ impl ImageContainer {
|
||||||
self.buffer = tmp;
|
self.buffer = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Save image anf properities
|
||||||
pub(crate) fn save(&self) {
|
pub(crate) fn save(&self) {
|
||||||
let prop = self.properties.read().unwrap();
|
let prop = self.properties.read().unwrap();
|
||||||
|
|
||||||
|
|
@ -185,7 +189,7 @@ impl ImageContainer {
|
||||||
Some(p) => Path::new(p),
|
Some(p) => Path::new(p),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let path_conf = path_original.with_extension("conf");
|
let path_properties = path_original.with_extension("prop");
|
||||||
let export = path_original.parent().unwrap().join("export").join(
|
let export = path_original.parent().unwrap().join("export").join(
|
||||||
path_original
|
path_original
|
||||||
.with_extension("png")
|
.with_extension("png")
|
||||||
|
|
@ -198,11 +202,11 @@ impl ImageContainer {
|
||||||
let mut prop = prop.clone();
|
let mut prop = prop.clone();
|
||||||
prop.path = None;
|
prop.path = None;
|
||||||
if let Err(e) = fs::write(
|
if let Err(e) = fs::write(
|
||||||
&path_conf,
|
&path_properties,
|
||||||
serde_json::to_string(&ImagePropertiesFile::from(&prop)).unwrap(),
|
serde_json::to_string(&ImagePropertiesFile::from(&prop)).unwrap(),
|
||||||
) {
|
) {
|
||||||
dialog::alert_default("Failed to save conf!");
|
dialog::alert_default("Failed to save properties!");
|
||||||
warn!("Failed to save conf!\n{:?}", e);
|
warn!("Failed to save properties!\n{:?}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut img = image::open(&path_original).unwrap();
|
let mut img = image::open(&path_original).unwrap();
|
||||||
|
|
@ -218,7 +222,7 @@ impl ImageContainer {
|
||||||
|
|
||||||
draw_layer_and_text(
|
draw_layer_and_text(
|
||||||
&mut img,
|
&mut img,
|
||||||
&prop.color_layer,
|
&prop.translucent_layer_color,
|
||||||
&prop.quote,
|
&prop.quote,
|
||||||
&prop.subquote,
|
&prop.subquote,
|
||||||
&prop.subquote2,
|
&prop.subquote2,
|
||||||
|
|
@ -253,8 +257,8 @@ impl ImageContainer {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_conf = path.with_extension("conf");
|
let path_properties = path.with_extension("prop");
|
||||||
let path_conf_new = new_path.with_extension("conf");
|
let path_properties_new = new_path.with_extension("prop");
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
if let Err(e) = fs::copy(path, &new_path) {
|
if let Err(e) = fs::copy(path, &new_path) {
|
||||||
|
|
@ -264,10 +268,10 @@ impl ImageContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if path_conf.exists() {
|
if path_properties.exists() {
|
||||||
if let Err(e) = fs::copy(path_conf, &path_conf_new) {
|
if let Err(e) = fs::copy(path_properties, &path_properties_new) {
|
||||||
dialog::alert_default("Failed to clone image!");
|
dialog::alert_default("Failed to clone image properties!");
|
||||||
warn!("Failed to clone image!\n{:?}", e);
|
warn!("Failed to clone image properties!\n{:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(new_path)
|
Some(new_path)
|
||||||
|
|
@ -283,7 +287,7 @@ impl ImageContainer {
|
||||||
Some(p) => Path::new(p),
|
Some(p) => Path::new(p),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let path_properties = path_original.with_extension("conf");
|
let path_properties = path_original.with_extension("prop");
|
||||||
let export = path_original.parent().unwrap().join("export").join(
|
let export = path_original.parent().unwrap().join("export").join(
|
||||||
path_original
|
path_original
|
||||||
.with_extension("png")
|
.with_extension("png")
|
||||||
|
|
@ -302,8 +306,8 @@ impl ImageContainer {
|
||||||
|
|
||||||
if path_properties.exists() {
|
if path_properties.exists() {
|
||||||
if let Err(e) = fs::remove_file(path_properties) {
|
if let Err(e) = fs::remove_file(path_properties) {
|
||||||
dialog::alert_default("Failed to delete image properties file!");
|
dialog::alert_default("Failed to delete image properties!");
|
||||||
warn!("Failed to delete image properties file!\n{:?}", e);
|
warn!("Failed to delete image properties!\n{:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,10 +320,9 @@ impl ImageContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Structure of Properties file of image to save and read
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub(crate) struct ImagePropertiesFile {
|
pub(crate) struct ImagePropertiesFile {
|
||||||
// pub(crate) dimension: Option<(f64, f64)>,
|
|
||||||
// pub(crate) original_dimension: Option<(f64, f64)>,
|
|
||||||
pub(crate) crop_position: Option<(f64, f64)>,
|
pub(crate) crop_position: Option<(f64, f64)>,
|
||||||
pub(crate) quote: Option<String>,
|
pub(crate) quote: Option<String>,
|
||||||
pub(crate) subquote: Option<String>,
|
pub(crate) subquote: Option<String>,
|
||||||
|
|
@ -331,14 +334,12 @@ pub(crate) struct ImagePropertiesFile {
|
||||||
pub(crate) subquote2_position: Option<f64>, // as per original
|
pub(crate) subquote2_position: Option<f64>, // as per original
|
||||||
pub(crate) tag_position: Option<f64>, // as per original
|
pub(crate) tag_position: Option<f64>, // as per original
|
||||||
pub(crate) tag2_position: Option<f64>, // as per original
|
pub(crate) tag2_position: Option<f64>, // as per original
|
||||||
pub(crate) color_layer: Option<[u8; 4]>,
|
pub(crate) translucent_layer_color: Option<[u8; 4]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ImagePropertiesFile {
|
impl Default for ImagePropertiesFile {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// dimension: None,
|
|
||||||
// original_dimension: None,
|
|
||||||
crop_position: None,
|
crop_position: None,
|
||||||
quote: None,
|
quote: None,
|
||||||
subquote: None,
|
subquote: None,
|
||||||
|
|
@ -350,7 +351,7 @@ impl Default for ImagePropertiesFile {
|
||||||
subquote2_position: None,
|
subquote2_position: None,
|
||||||
tag_position: None,
|
tag_position: None,
|
||||||
tag2_position: None,
|
tag2_position: None,
|
||||||
color_layer: None,
|
translucent_layer_color: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -358,8 +359,6 @@ impl Default for ImagePropertiesFile {
|
||||||
impl From<&ImageProperties> for ImagePropertiesFile {
|
impl From<&ImageProperties> for ImagePropertiesFile {
|
||||||
fn from(props: &ImageProperties) -> Self {
|
fn from(props: &ImageProperties) -> Self {
|
||||||
Self {
|
Self {
|
||||||
// dimension: Some(props.dimension),
|
|
||||||
// original_dimension: Some(props.original_dimension),
|
|
||||||
crop_position: props.crop_position,
|
crop_position: props.crop_position,
|
||||||
quote: Some(props.quote.clone()),
|
quote: Some(props.quote.clone()),
|
||||||
subquote: Some(props.subquote.clone()),
|
subquote: Some(props.subquote.clone()),
|
||||||
|
|
@ -371,11 +370,12 @@ impl From<&ImageProperties> for ImagePropertiesFile {
|
||||||
subquote2_position: Some(props.subquote2_position),
|
subquote2_position: Some(props.subquote2_position),
|
||||||
tag_position: Some(props.tag_position),
|
tag_position: Some(props.tag_position),
|
||||||
tag2_position: Some(props.tag2_position),
|
tag2_position: Some(props.tag2_position),
|
||||||
color_layer: Some(props.color_layer),
|
translucent_layer_color: Some(props.translucent_layer_color),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Properties of loaded image
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub(crate) struct ImageProperties {
|
pub(crate) struct ImageProperties {
|
||||||
pub(crate) path: Option<PathBuf>,
|
pub(crate) path: Option<PathBuf>,
|
||||||
|
|
@ -392,7 +392,7 @@ pub(crate) struct ImageProperties {
|
||||||
pub(crate) subquote2_position: f64, // as per original
|
pub(crate) subquote2_position: f64, // as per original
|
||||||
pub(crate) tag_position: f64, // as per original
|
pub(crate) tag_position: f64, // as per original
|
||||||
pub(crate) tag2_position: f64, // as per original
|
pub(crate) tag2_position: f64, // as per original
|
||||||
pub(crate) color_layer: [u8; 4],
|
pub(crate) translucent_layer_color: [u8; 4],
|
||||||
pub(crate) is_saved: bool,
|
pub(crate) is_saved: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -413,7 +413,7 @@ impl Default for ImageProperties {
|
||||||
subquote2_position: 0.0,
|
subquote2_position: 0.0,
|
||||||
tag_position: 0.0,
|
tag_position: 0.0,
|
||||||
tag2_position: 0.0,
|
tag2_position: 0.0,
|
||||||
color_layer: [0; 4],
|
translucent_layer_color: [0; 4],
|
||||||
is_saved: true,
|
is_saved: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -440,12 +440,13 @@ impl ImageProperties {
|
||||||
self.subquote2_position = props.subquote2_position.unwrap_or(self.subquote2_position);
|
self.subquote2_position = props.subquote2_position.unwrap_or(self.subquote2_position);
|
||||||
self.tag_position = props.tag_position.unwrap_or(self.tag_position);
|
self.tag_position = props.tag_position.unwrap_or(self.tag_position);
|
||||||
self.tag2_position = props.tag2_position.unwrap_or(self.tag2_position);
|
self.tag2_position = props.tag2_position.unwrap_or(self.tag2_position);
|
||||||
self.color_layer = props
|
self.translucent_layer_color = props
|
||||||
.color_layer
|
.translucent_layer_color
|
||||||
.unwrap_or(globals::CONFIG.read().unwrap().color_layer);
|
.unwrap_or(globals::CONFIG.read().unwrap().color_layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw text and stuffs on image
|
||||||
fn draw_layer_and_text(
|
fn draw_layer_and_text(
|
||||||
tmp: &mut DynamicImage,
|
tmp: &mut DynamicImage,
|
||||||
rgba: &[u8; 4],
|
rgba: &[u8; 4],
|
||||||
|
|
@ -526,6 +527,7 @@ fn draw_layer_and_text(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw multiline string on image
|
||||||
pub(crate) fn draw_multiline_mid_string(
|
pub(crate) fn draw_multiline_mid_string(
|
||||||
tmp: &mut DynamicImage,
|
tmp: &mut DynamicImage,
|
||||||
font: &rusttype::Font,
|
font: &rusttype::Font,
|
||||||
|
|
@ -551,53 +553,7 @@ pub(crate) fn draw_multiline_mid_string(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// small hack because 0,0,0 rgb can't be set on theme
|
/// Get size of text to draw on image
|
||||||
pub(crate) fn set_color_btn_rgba(rgba: [u8; 4], btn: &mut Button) {
|
|
||||||
let [mut r, g, b, _] = rgba;
|
|
||||||
if r == 0 && g == 0 && b == 0 {
|
|
||||||
r = 1;
|
|
||||||
}
|
|
||||||
btn.set_color(enums::Color::from_rgb(r, g, b));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn croped_ratio(width: f64, height: f64) -> (f64, f64) {
|
|
||||||
if width > width_from_height(height) {
|
|
||||||
(width_from_height(height), height)
|
|
||||||
} else {
|
|
||||||
(width, height_from_width(width))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn width_from_height(height: f64) -> f64 {
|
|
||||||
let (w, h) = globals::CONFIG.read().unwrap().image_ratio;
|
|
||||||
(w * height) / h
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn height_from_width(width: f64) -> f64 {
|
|
||||||
let (w, h) = globals::CONFIG.read().unwrap().image_ratio;
|
|
||||||
(h * width) / w
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn quote_from_height(height: f64) -> f64 {
|
|
||||||
(height * globals::CONFIG.read().unwrap().quote_font_ratio) / 5000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn subquote_from_height(height: f64) -> f64 {
|
|
||||||
(height * globals::CONFIG.read().unwrap().subquote_font_ratio) / 5000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn subquote2_from_height(height: f64) -> f64 {
|
|
||||||
(height * globals::CONFIG.read().unwrap().subquote2_font_ratio) / 5000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn tag_from_height(height: f64) -> f64 {
|
|
||||||
(height * globals::CONFIG.read().unwrap().tag_font_ratio) / 5000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn tag2_from_height(height: f64) -> f64 {
|
|
||||||
(height * globals::CONFIG.read().unwrap().tag2_font_ratio) / 5000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn measure_line(
|
pub(crate) fn measure_line(
|
||||||
font: &rusttype::Font,
|
font: &rusttype::Font,
|
||||||
text: &str,
|
text: &str,
|
||||||
|
|
@ -614,3 +570,58 @@ pub(crate) fn measure_line(
|
||||||
|
|
||||||
Coord::from((width, height)).into()
|
Coord::from((width, height)).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// small hack because 0,0,0 rgb, because can't be set on fltk theme
|
||||||
|
pub(crate) fn set_color_btn_rgba(rgba: [u8; 4], btn: &mut Button) {
|
||||||
|
let [mut r, g, b, _] = rgba;
|
||||||
|
if r == 0 && g == 0 && b == 0 {
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
|
btn.set_color(enums::Color::from_rgb(r, g, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required size to crop image as per image ratio
|
||||||
|
pub(crate) fn croped_ratio(width: f64, height: f64) -> (f64, f64) {
|
||||||
|
if width > width_from_height(height) {
|
||||||
|
(width_from_height(height), height)
|
||||||
|
} else {
|
||||||
|
(width, height_from_width(width))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required witdh to crop image from height as per image ratio
|
||||||
|
pub(crate) fn width_from_height(height: f64) -> f64 {
|
||||||
|
let (w, h) = globals::CONFIG.read().unwrap().image_ratio;
|
||||||
|
(w * height) / h
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required height to crop image from width as per image ratio
|
||||||
|
pub(crate) fn height_from_width(width: f64) -> f64 {
|
||||||
|
let (w, h) = globals::CONFIG.read().unwrap().image_ratio;
|
||||||
|
(h * width) / w
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required quote size for crop image from height as per image ratio
|
||||||
|
pub(crate) fn quote_from_height(height: f64) -> f64 {
|
||||||
|
(height * globals::CONFIG.read().unwrap().quote_font_ratio) / 5000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required subquote size for crop image from height as per image ratio
|
||||||
|
pub(crate) fn subquote_from_height(height: f64) -> f64 {
|
||||||
|
(height * globals::CONFIG.read().unwrap().subquote_font_ratio) / 5000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required subquote2 size for crop image from height as per image ratio
|
||||||
|
pub(crate) fn subquote2_from_height(height: f64) -> f64 {
|
||||||
|
(height * globals::CONFIG.read().unwrap().subquote2_font_ratio) / 5000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required tag size for crop image from height as per image ratio
|
||||||
|
pub(crate) fn tag_from_height(height: f64) -> f64 {
|
||||||
|
(height * globals::CONFIG.read().unwrap().tag_font_ratio) / 5000.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get required tag2 size for crop image from height as per image ratio
|
||||||
|
pub(crate) fn tag2_from_height(height: f64) -> f64 {
|
||||||
|
(height * globals::CONFIG.read().unwrap().tag2_font_ratio) / 5000.0
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue