diff --git a/src/canvas.rs b/src/canvas.rs new file mode 100644 index 0000000..ab401e7 --- /dev/null +++ b/src/canvas.rs @@ -0,0 +1,95 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +use crate::{ + io::{Key, Scroll}, + sprite::{Sprite, TextureSprite, TextSprite, ShapeSprite}, + texture::Texture, + utils::{Size, Pixel, Position}, +}; + +use std::{ + rc::Rc, + cell::RefCell, +}; + +//--Canvas struct----------------------------------------------------------------------------------- +pub struct Canvas {} + +impl Canvas { + + //--Create functions-- + pub fn create_texture_sprite(&mut self, _size: Size, _scale: f32) -> TextureSprite { + unimplemented!(); + } + + pub fn create_text_sprite(&mut self, _size: Size, _scale: f32) -> TextSprite { + unimplemented!(); + } + + pub fn create_shape_sprite(&mut self) -> ShapeSprite { + unimplemented!(); + } + + pub fn create_texture(&mut self, _size: Size, _background: Option) + -> Rc> + { + unimplemented!(); + } + + pub fn create_texture_from_file(&mut self, + _pos: Position, + _file: &'static str, + _background: Option) + -> Rc> + { + unimplemented!(); + } + + //--Output functions-- + pub fn draw(&mut self, _sprite: S) { + unimplemented!(); + } + + pub fn set_clear_color(&mut self, _color: Pixel) { + unimplemented!(); + } + + pub fn clear(&mut self) { + unimplemented!(); + } + + //--Input functions-- + pub fn close_requested(&self) -> bool { + unimplemented!(); + } + + pub fn key_pressed(&self, _key: Key) -> bool { + unimplemented!(); + } + + pub fn key_released(&self, _key: Key) -> bool { + unimplemented!(); + } + + pub fn get_key_presses(&self) -> Key { + unimplemented!(); + } + + pub fn get_key_releases(&self) -> Key { + unimplemented!(); + } + + pub fn get_mouse_position(&self) -> Position { + unimplemented!(); + } + + pub fn get_mouse_scroll(&self) -> Scroll { + unimplemented!(); + } + + pub fn update(&mut self) { + unimplemented!(); + } +} + diff --git a/src/io.rs b/src/io.rs new file mode 100644 index 0000000..fb5d940 --- /dev/null +++ b/src/io.rs @@ -0,0 +1,19 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +use bitflags::bitflags; + +//--Key enum---------------------------------------------------------------------------------------- +bitflags! { + pub struct Key: u128 { + const A = 0x1 << 0; + const B = 0x1 << 1; + } +} + +//--Scroll struct----------------------------------------------------------------------------------- +pub struct Scroll { + x: f32, + y: f32, +} + diff --git a/src/shape.rs b/src/shape.rs new file mode 100644 index 0000000..1e1c761 --- /dev/null +++ b/src/shape.rs @@ -0,0 +1,15 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +use crate::utils::Size; + +//--Shape trait------------------------------------------------------------------------------------- +pub enum Shape { + Rectangle (Rectangle), +} + +//--Rectangle struct-------------------------------------------------------------------------------- +pub struct Rectangle { + pub size: Size, +} + diff --git a/src/sprite.rs b/src/sprite.rs new file mode 100644 index 0000000..2c81cca --- /dev/null +++ b/src/sprite.rs @@ -0,0 +1,145 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +use crate::{ + shape::Shape, + texture::Texture, + utils::{Pixel, Position, Size}, +}; + +use cgmath::Matrix4; + +use std::{ + rc::Rc, + cell::RefCell, + slice::{Iter, IterMut}, +}; + +//--Sprite trait------------------------------------------------------------------------------------ +pub trait Sprite { + + fn set_position(&mut self, pos: Position); + fn set_rotation(&mut self, rot: f32); + fn set_alpha(&mut self, alpha: u8); + fn set_scale(&mut self, scale: f32); +} + +//--TextureSprite struct---------------------------------------------------------------------------- +pub struct TextureSprite { + matrix: Matrix4, + size: Size, + texture: Rc>, +} + +impl TextureSprite { + + pub fn set_texture(&mut self, _texture: Rc>, _offset: Option) { + unimplemented!(); + } + + pub fn set_pixel(&mut self, _pos: Position, _pix: Pixel) { + unimplemented!(); + } + + pub fn iter(&self) -> Iter<'_, Pixel> { + unimplemented!(); + } + + pub fn iter_mut(&mut self) -> IterMut<'_, Pixel> { + unimplemented!(); + } +} + +impl Sprite for TextureSprite { + + fn set_position(&mut self, _pos: Position) { + unimplemented!(); + } + + fn set_rotation(&mut self, _rot: f32) { + unimplemented!(); + } + + fn set_alpha(&mut self, _alpha: u8) { + unimplemented!(); + } + + fn set_scale(&mut self, _scale: f32) { + unimplemented!(); + } +} + +//--TextSprite struct------------------------------------------------------------------------------- +pub struct TextSprite { + matrix: Matrix4, + size: Size, + text: &'static str, //TODO: temporary +} + +impl TextSprite { + + pub fn set_text(&mut self, _text: &'static str) { + unimplemented!(); + } + + pub fn set_color(&mut self, _color: Pixel) { + unimplemented!(); + } +} + +impl Sprite for TextSprite { + + fn set_position(&mut self, _pos: Position) { + unimplemented!(); + } + + fn set_rotation(&mut self, _rot: f32) { + unimplemented!(); + } + + fn set_alpha(&mut self, _alpha: u8) { + unimplemented!(); + } + + fn set_scale(&mut self, _scale: f32) { + unimplemented!(); + } +} + +//--ShapeSprite struct------------------------------------------------------------------------------- +pub struct ShapeSprite { + matrix: Matrix4, + size: Size, + shape: Shape, +} + +impl ShapeSprite { + + pub fn set_shape(&mut self, _shape: Shape) { + unimplemented!(); + } + + pub fn set_color(&mut self, _color: Pixel) { + unimplemented!(); + } +} + +impl Sprite for ShapeSprite { + + fn set_position(&mut self, _pos: Position) { + unimplemented!(); + } + + fn set_rotation(&mut self, _rot: f32) { + unimplemented!(); + } + + fn set_alpha(&mut self, _alpha: u8) { + unimplemented!(); + } + + fn set_scale(&mut self, _scale: f32) { + unimplemented!(); + } +} + diff --git a/src/texture.rs b/src/texture.rs new file mode 100644 index 0000000..9b0256a --- /dev/null +++ b/src/texture.rs @@ -0,0 +1,25 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +use crate::utils::{Pixel, Position}; + +use std::slice::{Iter, IterMut}; + +//--Texture struct---------------------------------------------------------------------------------- +pub struct Texture {} + +impl Texture { + + pub fn set_pixel(&mut self, _pos: Position, _pix: Pixel) { + unimplemented!(); + } + + pub fn iter(&self) -> Iter<'_, Pixel> { + unimplemented!(); + } + + pub fn iter_mut(&mut self) -> IterMut<'_, Pixel> { + unimplemented!(); + } +} + diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..d9e10ac --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,48 @@ +#[allow(unused_imports)] +use log::{debug, error, info, trace, warn}; + +//--Position struct--------------------------------------------------------------------------------- +pub struct Position { + pub x: u32, + pub y: u32, +} + +//--Size struct------------------------------------------------------------------------------------- +pub struct Size { + pub w: u32, + pub h: u32, +} + +//--Pixel struct------------------------------------------------------------------------------------ +#[derive(Copy, Clone)] +struct Rgba { + r: u8, + g: u8, + b: u8, + a: u8, +} + +pub union Pixel { + flat: u32, + rgba: Rgba, +} + +impl Pixel { + + pub fn rgb(r: u8, g: u8, b: u8) -> Pixel { + Pixel { + rgba: Rgba{r, g, b, a: 255}, + } + } +} + +//--Color values------------------------------------------------------------------------------------ +#[non_exhaustive] +pub struct Color; + +impl Color { + pub const WHITE: Pixel = Pixel {flat: 0x000000ff}; + pub const BLACK: Pixel = Pixel {flat: 0xffffffff}; +} + +