#![allow(unused_imports)]
use super::*;
use crate::gles::enums::*;
use crate::Color;
use cgmath::prelude::*;
use cgmath::{Matrix3, Matrix4, Vector2, Vector3};
use primitives::color;
use std::{cell::RefCell, rc::Rc};
use winit::dpi::PhysicalSize;
mod coloredpainter;
pub use self::coloredpainter::*;
mod gles_extensions;
pub use self::gles_extensions::*;
mod imagepainter;
pub use self::imagepainter::*;
mod image;
pub use self::image::*;
mod pipeline;
pub use self::pipeline::*;
mod textpainter;
pub use self::textpainter::*;
mod webgl_extensions;
pub use self::webgl_extensions::*;
#[derive(Default)]
pub struct Font;
impl Font {
pub fn height(&self, val: i32) -> f32 {
0.0
}
}
pub struct ImageScaleQuality;
pub struct KeyCode;
pub struct Video;
pub struct Canvas;
pub struct IndexBuffer;
pub struct VertexBuffer;
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct TextureUnit;
pub struct TextureAddressing;
pub struct CubeMap;
pub struct MipMapFilter;
pub struct TextureFilter;
pub struct DepthStencilFormat;
struct PainterProps {
color: Color,
my_font: Font,
projectionMatrix: Matrix4<f32>,
imagePainter: ImageShaderPainter,
coloredPainter: ColoredShaderPainter,
textPainter: TextShaderPainter,
canvas: PhysicalSize<u32>,
transformations: Vec<cgmath::Matrix3<f32>>,
transformationIndex: usize,
opacities: Vec<f32>,
fontsize: f32,
}
impl PainterProps {
pub fn new() -> Self {
let fontsize = 18.0;
let mut textPainter = TextShaderPainter::new();
textPainter.fontsize = fontsize;
let instance = Self {
color: color::WHITE,
my_font: Font {},
projectionMatrix: Matrix4::identity(),
transformations: vec![Matrix3::identity()],
transformationIndex: 0,
imagePainter: ImageShaderPainter::new(),
coloredPainter: ColoredShaderPainter::new(),
textPainter,
opacities: vec![1.0],
fontsize,
canvas: PhysicalSize::new(900, 700),
};
instance
}
}
pub struct Painter {
props: RefCell<PainterProps>,
}
impl Default for Painter {
fn default() -> Self {
Painter::new()
}
}
impl Painter {
pub fn new() -> Self {
let instance = Self {
props: RefCell::new(PainterProps::new()),
};
instance.set_projection();
instance
}
pub fn begin(&self, clear: bool , clear_color: Option<Color> ) {
if clear {
self.clear(clear_color);
}
self.set_projection();
}
pub fn end(&self) {
self.flush();
}
pub fn flush(&self) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.textPainter.end();
props.coloredPainter.end();
}
pub fn clear(&self, color: Option<Color> ) {
self.flush();
}
pub fn draw_image(&self, img: &Image, x: f32, y: f32) {
self.draw_subimage(img, x, y, 0.0, 0.0, img.width as f32, img.height as f32);
}
pub fn draw_subimage(&self, img: &Image, x: f32, y: f32, sx: f32, sy: f32, sw: f32, sh: f32) {
self.draw_scaled_subimage(img, sx, sy, sw, sh, x, y, sw, sh);
}
pub fn draw_scaled_image(&self, img: &Image, dx: f32, dy: f32, dw: f32, dh: f32) {
self.draw_scaled_subimage(
img,
0.0,
0.0,
img.width as f32,
img.height as f32,
dx,
dy,
dw,
dh,
);
}
pub fn draw_scaled_subimage(
&self,
image: &Image,
sx: f32,
sy: f32,
sw: f32,
sh: f32,
dx: f32,
dy: f32,
dw: f32,
dh: f32,
) {
let mut props = self.props.borrow_mut();
props.coloredPainter.end();
props.textPainter.end();
unimplemented!()
}
pub fn draw_rect(
&self,
x: f32,
y: f32,
width: f32,
height: f32,
strength: f32,
) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.textPainter.end();
unimplemented!()
}
pub fn fill_rect(&self, x: f32, y: f32, width: f32, height: f32) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.textPainter.end();
unimplemented!()
}
pub fn draw_string(&self, text: &str, x: f32, y: f32) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.coloredPainter.end();
let opacity = match props.opacities.last() {
Some(opacity) => *opacity,
None => 1.0,
};
let color = props.color;
props.textPainter.drawString(
text, x, y, opacity, color,
);
}
pub fn draw_characters(&self, text: Vec<i32>, start: i32, length: i32, x: f32, y: f32) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.coloredPainter.end();
unimplemented!()
}
pub fn draw_line(&self, x1: f32, y1: f32, x2: f32, y2: f32, strength: f32 ) {
let mut props = self.props.borrow_mut();
props.imagePainter.end();
props.textPainter.end();
unimplemented!()
}
pub fn draw_video(&self, video: Video, x: f32, y: f32, width: f32, height: f32) {
unimplemented!()
}
pub fn fill_triangle(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) {
unimplemented!()
}
pub fn get_color(&self) -> Color {
let props = self.props.borrow_mut();
props.color
}
pub fn set_color(&self, color: Color) {
let mut props = self.props.borrow_mut();
props.color = color;
}
fn get_font(&self) -> Font {
unimplemented!()
}
fn set_font(&self, font: Font) {
unimplemented!()
}
fn get_font_size(&self) -> f32 {
let props = self.props.borrow_mut();
props.fontsize
}
fn set_font_size(&self, value: f32) {
let mut props = self.props.borrow_mut();
props.fontsize = value;
props.textPainter.fontsize = value;
}
#[inline]
fn get_transformation(&self) -> cgmath::Matrix3<f32> {
unimplemented!()
}
#[inline]
fn set_transformation(&self, transformation: cgmath::Matrix3<f32>) -> cgmath::Matrix3<f32> {
unimplemented!()
}
#[inline]
pub fn push_transformation(&self, trans: cgmath::Matrix3<f32>) {
unimplemented!()
}
pub fn pop_transformation(&self) -> cgmath::Matrix3<f32> {
unimplemented!()
}
pub fn scale(&self, x: f32, y: f32) {
unimplemented!()
}
#[inline]
fn translation(&self, tx: f32, ty: f32) -> cgmath::Matrix3<f32> {
unimplemented!()
}
pub fn translate(&self, tx: f32, ty: f32) {
unimplemented!()
}
pub fn push_translation(&self, tx: f32, ty: f32) {
unimplemented!()
}
#[inline]
fn rotation(&self, angle: f32, centerx: f32, centery: f32) -> cgmath::Matrix3<f32> {
unimplemented!()
}
pub fn rotate(&self, angle: f32, centerx: f32, centery: f32) {
unimplemented!()
}
pub fn push_rotation(&self, angle: f32, centerx: f32, centery: f32) {
unimplemented!()
}
pub fn push_opacity(&self, opacity: f32) {
let mut props = self.props.borrow_mut();
props.opacities.push(opacity);
}
pub fn pop_opacity(&self) -> f32 {
let mut props = self.props.borrow_mut();
let ret = props.opacities.pop().unwrap();
ret
}
pub fn get_opacity(&self) -> f32 {
let props = self.props.borrow();
*props.opacities.last().unwrap()
}
pub fn set_opacity(&self, opacity: f32) {
let mut props = self.props.borrow_mut();
let index = props.opacities.len() - 1;
props.opacities[index] = opacity;
}
pub fn scissor(&self, x: i32, y: i32, width: i32, height: i32) {}
pub fn disable_scissor(&self) {}
fn set_pipeline(&self, pipeline: Pipeline) {}
fn set_projection(&self) {
let mut props = self.props.borrow_mut();
let width = props.canvas.width as f32;
let height = props.canvas.height as f32;
let projectionMatrix: Matrix4<f32> = cgmath::ortho(0.0, width, 0.0, height, 0.0, 1000.0);
props.projectionMatrix = projectionMatrix;
props.imagePainter.setProjection(projectionMatrix);
props.coloredPainter.setProjection(projectionMatrix);
props.textPainter.setProjection(projectionMatrix);
}
}