use crate::canvas::canvas_frame::Drawable; use crate::util::vertex::{VertexTypeContainer, ColorVertex3D}; use crate::util::tr_event::{TrUIEvent, TrEvent}; /// #[derive(Debug, Clone)] pub struct Text { pub verts: VertexTypeContainer, position: (f32, f32), size: (f32, f32), } /// Container class which implements drawable. impl Text { fn accumulator(depth: f32, accumulator: &mut f32, constant: f32) -> f32{ let accum = *accumulator; *accumulator += constant; return depth + accum + constant; } /// pub fn new(position: (f32, f32), size: (f32, f32), depth: u32) -> Text { let normalized_depth = (depth as f32 / 255.0); let mut depth_accumulator = 1.0; let depth_accum_constant = -0.01 as f32; let verts = { vec![ ColorVertex3D { v_position: [-0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1], color: [1.0, 0.0, 0.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1], color: [1.0, 0.8, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)+0.1], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [0.8, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.0, 0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 0.8, 1.0/255.0], }, ColorVertex3D { v_position: [0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 0.8, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.0, 0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.25, 0.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.0, -0.1, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [0.0, -0.1, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-0.5, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-1.0, 1.0, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }, ColorVertex3D { v_position: [-0.25, -0.5, Text::accumulator(normalized_depth, &mut depth_accumulator, depth_accum_constant)], color: [1.0, 1.0, 1.0, 1.0/255.0], }] }; Text { verts: VertexTypeContainer::TextType(verts), position: position, size: size, } } } impl Drawable for Text { fn render(&self, window_size: (u32, u32), position: (f32, f32), rotation: f32, size: (f32, f32), depth: f32, ) -> Vec { vec![self.verts.clone()] } // fn update(&self, delta_time: f32) -> Vec> { // Vec::new() // } // // fn notify(&self, tr_event: Vec>, ui_events: Vec>) -> Vec> { // Vec::new() // } }