-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves screen capture API to accept configuration
Also allows for capturing multiple images at once, and scaling
- Loading branch information
Showing
8 changed files
with
417 additions
and
192 deletions.
There are no files selected for viewing
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
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
194 changes: 194 additions & 0 deletions
194
indigo/indigo/src/main/scala/indigo/platform/renderer/ScreenCaptureConfig.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
package indigo.platform.renderer | ||
|
||
import indigo.shared.ImageType | ||
import indigo.shared.collections.Batch | ||
import indigo.shared.datatypes.BindingKey | ||
import indigo.shared.datatypes.Rectangle | ||
import indigo.shared.datatypes.Vector2 | ||
|
||
/** Configuration for a screen capture | ||
* | ||
* @param name | ||
* The optional name of the capture | ||
* @param croppingRect | ||
* The rectangle to crop the capture to | ||
* @param scale | ||
* The scale to apply to the capture | ||
* @param excludeLayers | ||
* The layers to exclude from the capture | ||
* @param imageType | ||
* The type of image to capture | ||
*/ | ||
final case class ScreenCaptureConfig( | ||
name: Option[String], | ||
croppingRect: Option[Rectangle], | ||
scale: Option[Vector2], | ||
excludeLayers: Batch[BindingKey], | ||
imageType: ImageType | ||
) { | ||
|
||
/** Set the name of the capture | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
def withName(name: String): ScreenCaptureConfig = | ||
this.copy(name = Some(name)) | ||
|
||
/** Set the cropping rectangle of the capture | ||
* | ||
* @param rect | ||
* @return | ||
*/ | ||
def withCrop(rect: Rectangle): ScreenCaptureConfig = | ||
this.copy(croppingRect = Some(rect)) | ||
|
||
/** Set the scale of the capture | ||
* | ||
* @param scale | ||
* @return | ||
*/ | ||
def withScale(scale: Double): ScreenCaptureConfig = | ||
withScale(Vector2(scale, scale)) | ||
|
||
/** Set the scale of the capture | ||
* | ||
* @param scale | ||
* @return | ||
*/ | ||
def withScale(scale: Vector2): ScreenCaptureConfig = | ||
this.copy(scale = Some(scale)) | ||
|
||
/** Set the image type of the capture | ||
* | ||
* @param imageType | ||
* @return | ||
*/ | ||
def withImageType(imageType: ImageType): ScreenCaptureConfig = | ||
this.copy(imageType = imageType) | ||
|
||
/** Set the layers to exclude from the capture | ||
* | ||
* @param excludeLayers | ||
* @return | ||
*/ | ||
def withExcludeLayers(excludeLayers: Batch[BindingKey]): ScreenCaptureConfig = | ||
this.copy(excludeLayers = excludeLayers) | ||
|
||
/** Add a layer to exclude from the capture | ||
* | ||
* @param excludeLayer | ||
* @return | ||
*/ | ||
def addExcludeLayer(excludeLayer: BindingKey): ScreenCaptureConfig = | ||
this.copy(excludeLayers = excludeLayers :+ excludeLayer) | ||
|
||
/** Add layers to exclude from the capture | ||
* | ||
* @param excludeLayers | ||
* @return | ||
*/ | ||
def addExcludeLayers(excludeLayers: Batch[BindingKey]): ScreenCaptureConfig = | ||
this.copy(excludeLayers = this.excludeLayers ++ excludeLayers) | ||
} | ||
|
||
object ScreenCaptureConfig { | ||
|
||
/** Default configuration | ||
*/ | ||
val default: ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, None, None, Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
def apply(name: String): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), None, None, Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name and cropping rectangle | ||
* | ||
* @param name | ||
* @param croppingRect | ||
* @return | ||
*/ | ||
def apply(name: String, croppingRect: Rectangle): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), Some(croppingRect), None, Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name and scale | ||
* | ||
* @param name | ||
* @param scale | ||
* @return | ||
*/ | ||
def apply(name: String, scale: Double): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), None, Some(Vector2(scale, scale)), Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name and scale | ||
* | ||
* @param name | ||
* @param scale | ||
* @return | ||
*/ | ||
def apply(name: String, scale: Vector2): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), None, Some(scale), Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name and excluded layers | ||
* | ||
* @param name | ||
* @param excludeLayers | ||
* @return | ||
*/ | ||
def apply(name: String, excludeLayers: Batch[BindingKey]): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), None, None, excludeLayers, ImageType.WEBP) | ||
|
||
/** Create a configuration with a name and image type | ||
* | ||
* @param name | ||
* @param imageType | ||
* @return | ||
*/ | ||
def apply(name: String, imageType: ImageType): ScreenCaptureConfig = | ||
ScreenCaptureConfig(Some(name), None, None, Batch.empty, imageType) | ||
|
||
/** Create a configuration with a cropping rectangle | ||
* | ||
* @param croppingRect | ||
* @return | ||
*/ | ||
def apply(croppingRect: Rectangle): ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, Some(croppingRect), None, Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a scale | ||
* | ||
* @param scale | ||
* @return | ||
*/ | ||
def apply(scale: Double): ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, None, Some(Vector2(scale, scale)), Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with a scale | ||
* | ||
* @param scale | ||
* @return | ||
*/ | ||
def apply(scale: Vector2): ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, None, Some(scale), Batch.empty, ImageType.WEBP) | ||
|
||
/** Create a configuration with excluded layers | ||
* | ||
* @param excludeLayers | ||
* @return | ||
*/ | ||
def apply(excludeLayers: Batch[BindingKey]): ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, None, None, excludeLayers, ImageType.WEBP) | ||
|
||
/** Create a configuration with an image type | ||
* | ||
* @param imageType | ||
* @return | ||
*/ | ||
def apply(imageType: ImageType): ScreenCaptureConfig = | ||
ScreenCaptureConfig(None, None, None, Batch.empty, imageType) | ||
} |
Oops, something went wrong.