Created
May 21, 2019 07:23
-
-
Save crlf0710/1d6983aa74b3f43be11b87c97660167f to your computer and use it in GitHub Desktop.
Graphics2D.rs draft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written by CrLF0710<crlf0710@gmail.com> | |
// Licensed with MIT OR Apache-2.0 | |
trait GraphicsSolution { | |
} | |
trait GraphicsContextBuilder<T: GraphicsSolution> { | |
type ImmediateContext: GraphicsContext; | |
type RetainedRasterContext: GraphicsContext; | |
type RetainedVectorContext: GraphicsContext; | |
fn create_immediate_context(&mut self) -> Self::ImmediateContext; | |
fn create_retained_raster_context(&self) -> Self::RetainedRasterContext; | |
fn create_retained_vector_context(&self) -> Self::RetainedVectorContext; | |
} | |
trait GraphicsContext { | |
type Coord; | |
type SignedLength; | |
type Coefficient; | |
type ClippableShape; | |
type FillableShape; | |
type FillableColor; | |
type TransferableSurface; | |
type ComplexGraphics; | |
fn save_transform_and_clipping(&mut self); | |
fn restore_transform_and_clipping(&mut self); | |
fn append_transform(&mut self, transform: Transform<Self>); | |
fn append_clipping(&mut self, clipping: Self::ClippableShape); | |
fn draw_fallback_graphics(&mut self, graphics: FallbackGraphics<Self>); | |
fn draw_filling_graphics(&mut self, graphics: FillingGraphics<Self>); | |
fn draw_transfer_graphics(&mut self, graphics: TransferGraphics<Self>); | |
fn draw_complex_graphics(&mut self, graphics: ComplexGraphics<Self>); | |
} | |
struct Transform<T: GraphicsContext + ?Sized> { | |
coeffs: [T::Coefficient; 4], | |
coords: [T::Coord; 2], | |
} | |
struct Point<T: GraphicsContext + ?Sized> { | |
coords: [T::Coord; 2] | |
} | |
enum SimpleLineExtent<T: GraphicsContext + ?Sized> { | |
Horz(T::SignedLength), | |
Vert(T::SignedLength), | |
} | |
struct SimpleLine<T: GraphicsContext + ?Sized> { | |
anchor: Point<T>, | |
extent: SimpleLineExtent<T>, | |
} | |
struct SimpleRectExtent<T: GraphicsContext + ?Sized> { | |
width: T::SignedLength, | |
height: T::SignedLength, | |
} | |
struct SimpleRect<T: GraphicsContext + ?Sized> { | |
anchor: Point<T>, | |
extent: SimpleRectExtent<T>, | |
} | |
enum FallbackGraphics<T: GraphicsContext + ?Sized> { | |
FallbackPoint(Point<T>, T::FillableColor), | |
FallbackLine(SimpleLine<T>, T::FillableColor), | |
FallbackRect(SimpleRect<T>, T::FillableColor), | |
FallbackEverywhere(T::FillableColor), | |
} | |
struct FillingGraphics<T: GraphicsContext + ?Sized> { | |
shape: T::FillableShape, | |
color: T::FillableColor | |
} | |
struct TransferGraphics<'a, T: GraphicsContext + ?Sized> { | |
rect: SimpleRect<T>, | |
surface: &'a T::TransferableSurface, | |
} | |
struct ComplexGraphics<'a, T: GraphicsContext + ?Sized> { | |
graphics: &'a T::ComplexGraphics, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment