Implement API squeleton
Some adjustements done to the API to ease implementation
This commit is contained in:
parent
282534c969
commit
60d79e7d85
95
src/canvas.rs
Normal file
95
src/canvas.rs
Normal file
@ -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<Pixel>)
|
||||||
|
-> Rc<RefCell<Texture>>
|
||||||
|
{
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_texture_from_file(&mut self,
|
||||||
|
_pos: Position,
|
||||||
|
_file: &'static str,
|
||||||
|
_background: Option<Pixel>)
|
||||||
|
-> Rc<RefCell<Texture>>
|
||||||
|
{
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--Output functions--
|
||||||
|
pub fn draw<S: Sprite>(&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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
src/io.rs
Normal file
19
src/io.rs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
|
||||||
15
src/shape.rs
Normal file
15
src/shape.rs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
|
||||||
145
src/sprite.rs
Normal file
145
src/sprite.rs
Normal file
@ -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<f32>,
|
||||||
|
size: Size,
|
||||||
|
texture: Rc<RefCell<Texture>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextureSprite {
|
||||||
|
|
||||||
|
pub fn set_texture(&mut self, _texture: Rc<RefCell<Texture>>, _offset: Option<Position>) {
|
||||||
|
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<f32>,
|
||||||
|
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<f32>,
|
||||||
|
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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
25
src/texture.rs
Normal file
25
src/texture.rs
Normal file
@ -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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
48
src/utils.rs
Normal file
48
src/utils.rs
Normal file
@ -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};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user