diff --git a/src/azure-c.cpp b/src/azure-c.cpp index 24d9722..97acb88 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -721,10 +721,11 @@ AzCloneRadialGradientPattern(AzRadialGradientPatternRef aPattern) { } extern "C" AzSurfacePatternRef -AzCreateSurfacePattern(AzSourceSurfaceRef aSurface) { +AzCreateSurfacePattern(AzSourceSurfaceRef aSurface, AzExtendMode aExtendMode) { gfx::SourceSurface *gfxSourceSurface = reinterpret_cast(aSurface); + gfx::ExtendMode gfxExtendMode = static_cast(aExtendMode); gfx::SurfacePattern* gfxSurfacePattern = new - gfx::SurfacePattern(gfxSourceSurface, gfx::ExtendMode::REPEAT); + gfx::SurfacePattern(gfxSourceSurface, gfxExtendMode); return gfxSurfacePattern; } diff --git a/src/azure-c.h b/src/azure-c.h index 36fd1a9..c189662 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -462,7 +462,7 @@ AzRadialGradientPatternRef AzCreateRadialGradientPattern(const AzPoint *aCenter1 AzRadialGradientPatternRef AzCloneRadialGradientPattern(AzRadialGradientPatternRef aPattern); -AzSurfacePatternRef AzCreateSurfacePattern(AzSourceSurfaceRef aSurface); +AzSurfacePatternRef AzCreateSurfacePattern(AzSourceSurfaceRef aSurface, AzExtendMode aExtendMode); AzSurfacePatternRef AzCloneSurfacePattern(AzSurfacePatternRef aPattern); diff --git a/src/azure.rs b/src/azure.rs index b93bb3a..8816485 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -553,7 +553,7 @@ pub fn AzCreateRadialGradientPattern(aCenter1: *const AzPoint, pub fn AzCloneRadialGradientPattern(aPattern: AzRadialGradientPatternRef) -> AzRadialGradientPatternRef; -pub fn AzCreateSurfacePattern(aSurface: AzSourceSurfaceRef) +pub fn AzCreateSurfacePattern(aSurface: AzSourceSurfaceRef, aExtendMode: AzExtendMode) -> AzSurfacePatternRef; pub fn AzCloneSurfacePattern(aPattern: AzSurfacePatternRef) diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 26b7c0d..638fd24 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -547,11 +547,14 @@ impl DrawTarget { } } - pub fn fill(&self, path: &Path, pattern: &ColorPattern, draw_options: &DrawOptions) { + pub fn fill(&self, + path: &Path, + pattern: PatternRef, + draw_options: &DrawOptions) { unsafe { AzDrawTargetFill(self.azure_draw_target, path.azure_path, - pattern.azure_color_pattern, + pattern.as_azure_pattern(), &mut draw_options.as_azure_draw_options()); } } @@ -578,13 +581,13 @@ impl DrawTarget { pub fn stroke(&self, path: &Path, - pattern: &ColorPattern, + pattern: PatternRef, stroke_options: &StrokeOptions, draw_options: &DrawOptions) { unsafe { AzDrawTargetStroke(self.azure_draw_target, path.azure_path, - pattern.azure_color_pattern, + pattern.as_azure_pattern(), &stroke_options.as_azure_stroke_options(), &draw_options.as_azure_draw_options()); } @@ -608,13 +611,13 @@ impl DrawTarget { pub fn stroke_rect(&self, rect: &Rect, - pattern: &ColorPattern, + pattern: PatternRef, stroke_options: &StrokeOptions, draw_options: &DrawOptions) { unsafe { AzDrawTargetStrokeRect(self.azure_draw_target, &mut rect.as_azure_rect(), - pattern.azure_color_pattern, + pattern.as_azure_pattern(), &mut stroke_options.as_azure_stroke_options(), &mut draw_options.as_azure_draw_options()); } @@ -1099,6 +1102,8 @@ impl Drop for PathBuilder { pub struct LinearGradientPattern { pub azure_linear_gradient_pattern: AzLinearGradientPatternRef, + pub begin: Point2D, + pub end: Point2D, } impl Drop for LinearGradientPattern { @@ -1115,6 +1120,8 @@ impl Clone for LinearGradientPattern { LinearGradientPattern { azure_linear_gradient_pattern: AzCloneLinearGradientPattern(self.azure_linear_gradient_pattern), + begin: self.begin, + end: self.end, } } } @@ -1133,9 +1140,15 @@ impl LinearGradientPattern { mem::transmute::<_,*const AzPoint>(end), stops.azure_gradient_stops, mem::transmute::<_,*const AzMatrix>(matrix)), + begin: *begin, + end: *end, } } } + + pub fn is_zero_size(&self) -> bool { + self.begin == self.end + } } pub struct RadialGradientPattern { @@ -1213,10 +1226,16 @@ impl Clone for SurfacePattern { impl SurfacePattern { pub fn new(surface: AzSourceSurfaceRef, repeat_x: bool, repeat_y: bool) -> SurfacePattern { + let mode = if !repeat_x && !repeat_y { + ExtendMode::Clamp + } else { + ExtendMode::Repeat + }; + unsafe { SurfacePattern { azure_surface_pattern: - AzCreateSurfacePattern(surface), + AzCreateSurfacePattern(surface, mode.as_azure_extend_mode()), repeat_x: repeat_x, repeat_y: repeat_y, }