Add the clock and some extra lines

This commit is contained in:
Savanni D'Gerinel 2023-04-09 20:07:12 -04:00 committed by Gitea
parent d1b257e631
commit ea5c8cdb78
1 changed files with 98 additions and 101 deletions

View File

@ -5,8 +5,8 @@ use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
const WIDTH: i32 = 800; const WIDTH: i32 = 1920;
const HEIGHT: i32 = 800; const HEIGHT: i32 = 1280;
pub struct SplashPrivate { pub struct SplashPrivate {
text: Rc<RefCell<String>>, text: Rc<RefCell<String>>,
@ -31,40 +31,19 @@ impl SplashPrivate {
let _ = context.paint(); let _ = context.paint();
context.select_font_face("Alegreya Sans SC", FontSlant::Normal, FontWeight::Bold); context.select_font_face("Alegreya Sans SC", FontSlant::Normal, FontWeight::Bold);
context.set_font_size(64.); context.set_font_size(128.);
let center_x = WIDTH as f64 / 2.; let center_x = WIDTH as f64 / 2.;
let center_y = HEIGHT as f64 / 2.; let center_y = HEIGHT as f64 / 2.;
let (title_width, title_height) = {
let title_extents = context.text_extents(&self.text.borrow()).unwrap(); let title_extents = context.text_extents(&self.text.borrow()).unwrap();
let title_width = title_extents.width();
let title_baseline_x = center_x - title_extents.width() / 2.; let title_height = title_extents.height();
let title_baseline_y = center_y - 20.;
let gradient = LinearGradient::new(
title_baseline_x,
title_baseline_y - title_extents.height(),
title_baseline_x,
title_baseline_y,
);
gradient.add_color_stop_rgb(0.2, 0.7, 0.0, 1.0);
gradient.add_color_stop_rgb(0.8, 0.2, 0.0, 1.0);
context.move_to(title_baseline_x, title_baseline_y);
let _ = context.set_source(gradient);
let _ = context.show_text(&self.text.borrow());
(title_extents.width(), title_extents.height())
};
{ {
context.set_source_rgb(0.7, 0., 1.);
context.set_line_width(5.);
context.set_line_cap(LineCap::Round);
let start_length = center_x - title_width / 2. - title_height - 20.; let start_length = center_x - title_width / 2. - title_height - 20.;
AsymLineCutout { let title_cutout = AsymLineCutout {
orientation: gtk::Orientation::Horizontal, orientation: gtk::Orientation::Horizontal,
start_x: 20., start_x: 20.,
start_y: center_y - 20. - title_height / 2., start_y: center_y - 20. - title_height / 2.,
@ -73,11 +52,81 @@ impl SplashPrivate {
cutout_length: title_width, cutout_length: title_width,
height: title_height, height: title_height,
invert: false, invert: false,
};
context.set_line_cap(LineCap::Round);
context.set_source_rgb(0.7, 0., 1.);
context.set_line_width(2.);
title_cutout.draw(&context);
let _ = context.stroke();
}
{
let title_baseline_x = center_x - title_width / 2.;
let title_baseline_y = center_y - 20.;
let gradient = LinearGradient::new(
title_baseline_x,
title_baseline_y - title_height,
title_baseline_x,
title_baseline_y,
);
gradient.add_color_stop_rgb(0.2, 0.7, 0.0, 1.0);
gradient.add_color_stop_rgb(0.8, 0.2, 0.0, 1.0);
context.move_to(title_baseline_x, title_baseline_y);
let _ = context.set_source(gradient);
let _ = context.show_text(&self.text.borrow());
}
{
context.set_source_rgb(0.7, 0., 1.);
AsymLine {
orientation: gtk::Orientation::Horizontal,
start_x: 100.,
start_y: HEIGHT as f64 / 2. + 100.,
start_length: 400.,
height: 50.,
total_length: 650.,
invert: true,
} }
.draw(&context); .draw(&context);
let _ = context.stroke(); let _ = context.stroke();
} }
{
context.set_source_rgb(0.7, 0., 1.);
AsymLine {
orientation: gtk::Orientation::Horizontal,
start_x: WIDTH as f64 / 2. + 100.,
start_y: HEIGHT as f64 / 2. + 200.,
start_length: 600.,
height: 50.,
total_length: 650.,
invert: false,
}
.draw(&context);
let _ = context.stroke();
}
{
context.set_font_size(128.);
let time_extents = context.text_extents(&self.time.borrow()).unwrap();
let time_baseline_x = center_x - time_extents.width() / 2.;
let time_baseline_y = center_y + 100.;
let gradient = LinearGradient::new(
time_baseline_x,
time_baseline_y - time_extents.height(),
time_baseline_x,
time_baseline_y,
);
gradient.add_color_stop_rgb(0.2, 0.2, 0.0, 1.0);
gradient.add_color_stop_rgb(0.8, 0.7, 0.0, 1.0);
context.move_to(time_baseline_x, time_baseline_y);
let _ = context.set_source(gradient);
let _ = context.show_text(&self.time.borrow());
}
let background = context.pop_group().unwrap(); let background = context.pop_group().unwrap();
*self.background.borrow_mut() = background; *self.background.borrow_mut() = background;
@ -178,111 +227,59 @@ impl AsymLineCutout {
context.line_to(self.total_length, self.start_y + dodge / 2.); context.line_to(self.total_length, self.start_y + dodge / 2.);
} }
gtk::Orientation::Vertical => { gtk::Orientation::Vertical => {
/*
context.move_to(self.start_x, self.start_y); context.move_to(self.start_x, self.start_y);
context.line_to(self.start_x, self.start_y + self.start_length); context.line_to(self.start_x, self.start_y + self.start_length);
context.line_to( context.line_to(
self.start_x + self.height, self.start_x + dodge,
self.start_y + self.start_length + self.height, self.start_y + self.start_length + self.height,
); );
context.line_to( context.line_to(
self.start_x + self.height, self.start_x + dodge,
self.start_y + self.start_length + self.height + self.center_length, self.start_y + self.start_length + self.height + self.cutout_length,
); );
context.line_to( context.line_to(
self.start_x + self.height / 2., self.start_x + dodge / 2.,
self.start_y self.start_y
+ self.start_length + self.start_length
+ self.height + self.height
+ self.center_length + self.cutout_length
+ (self.height / 2.), + (self.height / 2.),
); );
context.line_to( context.line_to(self.start_x + dodge / 2., self.total_length);
self.start_x + self.height / 2.,
self.start_y
+ self.start_length
+ self.height
+ self.center_length
+ (self.height / 2.)
+ self.end_length,
);
*/
} }
_ => panic!("unknown orientation"), _ => panic!("unknown orientation"),
} }
} }
} }
struct AsymLineReturn {
struct AsymLine {
orientation: gtk::Orientation, orientation: gtk::Orientation,
start_x: f64, start_x: f64,
start_y: f64, start_y: f64,
start_length: f64, start_length: f64,
center_length: f64, height: f64,
end_length: f64, total_length: f64,
width: f64, invert: bool,
} }
impl AsymLineReturn { impl AsymLine {
fn draw(&self, context: &Context) { fn draw(&self, context: &Context) {
let dodge = if self.invert {
self.height
} else {
-self.height
};
match self.orientation { match self.orientation {
gtk::Orientation::Horizontal => { gtk::Orientation::Horizontal => {
context.move_to(self.start_x, self.start_y); context.move_to(self.start_x, self.start_y);
context.line_to(self.start_x + self.start_length, self.start_y); context.line_to(self.start_x + self.start_length, self.start_y);
context.line_to( context.line_to(
self.start_x + self.start_length + self.width.abs(), self.start_x + self.start_length + self.height,
self.start_y + self.width, self.start_y + dodge,
);
context.line_to(
self.start_x + self.start_length + self.width.abs() + self.center_length,
self.start_y + self.width,
);
context.line_to(
self.start_x
+ self.start_length
+ self.width.abs()
+ self.center_length
+ (self.width.abs() / 2.),
self.start_y + self.width / 2.,
);
context.line_to(
self.start_x
+ self.start_length
+ self.width.abs()
+ self.center_length
+ (self.width.abs() / 2.)
+ self.end_length,
self.start_y + self.width / 2.,
);
}
gtk::Orientation::Vertical => {
context.move_to(self.start_x, self.start_y);
context.line_to(self.start_x, self.start_y + self.start_length);
context.line_to(
self.start_x + self.width,
self.start_y + self.start_length + self.width.abs(),
);
context.line_to(
self.start_x + self.width,
self.start_y + self.start_length + self.width.abs() + self.center_length,
);
context.line_to(
self.start_x + self.width / 2.,
self.start_y
+ self.start_length
+ self.width.abs()
+ self.center_length
+ (self.width.abs() / 2.),
);
context.line_to(
self.start_x + self.width / 2.,
self.start_y
+ self.start_length
+ self.width.abs()
+ self.center_length
+ (self.width.abs() / 2.)
+ self.end_length,
); );
context.line_to(self.start_x + self.total_length, self.start_y + dodge);
} }
gtk::Orientation::Vertical => {}
_ => panic!("unknown orientation"), _ => panic!("unknown orientation"),
} }
} }