From 0de3e6b0be415ba6faa7bbc47cc70da3a688836d Mon Sep 17 00:00:00 2001 From: Vovanium Date: Wed, 9 Aug 2023 19:13:20 +0300 Subject: [PATCH] + Stencil Renderables and small refactoring --- source/base/video-colors.ads | 10 +++++- .../base/video-renderables-color-stencil.ads | 4 +++ .../base/video-renderables-generic_sprite.ads | 14 --------- source/base/video-renderables-image.ads | 3 +- source/base/video-renderables.ads | 27 ++++++++++++++++ source/base/video-stencils.ads | 31 +++++++++++++++++++ 6 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 source/base/video-renderables-color-stencil.ads delete mode 100644 source/base/video-renderables-generic_sprite.ads create mode 100644 source/base/video-stencils.ads diff --git a/source/base/video-colors.ads b/source/base/video-colors.ads index f55bbb9..d7639d1 100644 --- a/source/base/video-colors.ads +++ b/source/base/video-colors.ads @@ -10,6 +10,11 @@ package Video.Colors with Pure is -- Universal definition for color component (like R, G, B channels or Alpha) -- defined to cover the best color resolution required (e. g. 8 bit in true color systems) + subtype Opacity is Color_Component; + + Opaque : constant Opacity; + Transparent : constant Opacity; + subtype Color_Component_1_Bit is Integer range 0 .. 1; subtype Color_Component_4_Bit is Integer range 0 .. 2**4 - 1; subtype Color_Component_5_Bit is Integer range 0 .. 2**5 - 1; @@ -43,7 +48,7 @@ package Video.Colors with Pure is R : Color_Component; G : Color_Component; B : Color_Component; - A : Color_Component := From_8_Bit (2**Color_Component_Bits - 1); + A : Opacity := From_8_Bit (2**Color_Component_Bits - 1); end record; function RGB_8 ( @@ -61,4 +66,7 @@ package Video.Colors with Pure is private type Color_Component is range 0 .. 2**Color_Component_Bits - 1; + Opaque : constant Opacity := Color_Component'Last; + Transparent : constant Opacity := Color_Component'First; + end Video.Colors; \ No newline at end of file diff --git a/source/base/video-renderables-color-stencil.ads b/source/base/video-renderables-color-stencil.ads new file mode 100644 index 0000000..a1eb5ff --- /dev/null +++ b/source/base/video-renderables-color-stencil.ads @@ -0,0 +1,4 @@ +with Video.Stencils; + +package Video.Renderables.Color.Stencil +is new Renderables.Color.Generic_Stencil (Stencil_Type => Video.Stencils.Stencil'Class); diff --git a/source/base/video-renderables-generic_sprite.ads b/source/base/video-renderables-generic_sprite.ads deleted file mode 100644 index 040d787..0000000 --- a/source/base/video-renderables-generic_sprite.ads +++ /dev/null @@ -1,14 +0,0 @@ --- --- Base interface for rendering image (sprite) to image (renderable) --- -generic - type Sprite (<>) is limited private; -package Video.Renderables.Generic_Sprite is - type Sprite_Renderable is limited interface and Root_Renderable; - - procedure Paste ( - Target : in out Sprite_Renderable; - A : Integer_Geometry.Point; - Source : Sprite) is abstract; - -end Video.Renderables.Generic_Sprite; diff --git a/source/base/video-renderables-image.ads b/source/base/video-renderables-image.ads index 505b5ea..fb9df1a 100644 --- a/source/base/video-renderables-image.ads +++ b/source/base/video-renderables-image.ads @@ -1,4 +1,3 @@ with Video.Images; -with Video.Renderables.Generic_Sprite; -package Video.Renderables.Image is new Video.Renderables.Generic_Sprite (Images.Image'Class); +package Video.Renderables.Image is new Video.Renderables.Generic_Image (Images.Image'Class); diff --git a/source/base/video-renderables.ads b/source/base/video-renderables.ads index 903b543..3e4af1e 100644 --- a/source/base/video-renderables.ads +++ b/source/base/video-renderables.ads @@ -61,6 +61,33 @@ package Video.Renderables with Pure is Bounds : in Box; Paint : in Paint_Type) is abstract; + generic + type Stencil_Type (<>) is limited private; + package Generic_Stencil is + type Stencil_Renderable is limited interface and Root_Renderable; + + procedure Fill ( + Target : in out Stencil_Renderable; + A : in Point; + Shape : in Stencil_Type; + Paint : in Paint_Type) is abstract; + end Generic_Stencil; + end Paint_Renderables; + -- + -- Base interface for rendering image (sprite) to image (renderable) + -- + generic + type Image_Type (<>) is limited private; + package Generic_Image is + type Image_Renderable is limited interface and Root_Renderable; + + procedure Paste ( + Target : in out Image_Renderable; + A : Integer_Geometry.Point; + Source : Image_Type) is abstract; + + end Generic_Image; + end Video.Renderables; diff --git a/source/base/video-stencils.ads b/source/base/video-stencils.ads new file mode 100644 index 0000000..7907e02 --- /dev/null +++ b/source/base/video-stencils.ads @@ -0,0 +1,31 @@ +with Video.Integer_Geometry, Video.Colors; +use Video.Integer_Geometry, Video.Colors; + +package Video.Stencils is + + type Stencil is interface; + + function Bounding_Box ( + Source : Stencil) + return Box is abstract; + -- Stencil bounds in native (whatever it means) resolution + + function Pixel ( + Source : Stencil; + A : Point) + return Opacity is abstract; + + type Raster_Stencil is interface and Stencil; + + generic + type Pixel_Type is private; + package Generic_Raster is + type Stencil is interface and Raster_Stencil; + + function Pixel ( + Source : Stencil; + A : Point) + return Pixel_Type is abstract; + end Generic_Raster; + +end Video.Stencils; \ No newline at end of file