Skip to content

Commit

Permalink
Updates clipping calculations for screen capture
Browse files Browse the repository at this point in the history
  • Loading branch information
hobnob committed Oct 16, 2024
1 parent 3bbcd52 commit 6fa99c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import org.scalajs.dom.WebGLRenderingContext._
import org.scalajs.dom.WebGLUniformLocation
import org.scalajs.dom.html

import scala.scalajs.js.typedarray.Float32Array
import java.util.Base64
import scala.scalajs.js.typedarray.Float32Array

final class RendererWebGL1(
config: RendererConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,17 @@ final class RendererWebGL2(
_prevGameRuntime
)

println(s"magnification: ${cNc.magnification}, config magnification: ${config.magnification}")
ctx2d.drawImage(
cNc.canvas,
clippingRect.x,
clippingRect.y,
clippingRect.width,
clippingRect.height,
clippingRect.x * cNc.magnification,
clippingRect.y * cNc.magnification,
clippingRect.width * cNc.magnification,
clippingRect.height * cNc.magnification,
0,
0,
clippingRect.width,
clippingRect.height
clippingRect.width * cNc.magnification,
clippingRect.height * cNc.magnification
)
val dataUrl = canvas.toDataURL(imageType.toString())
canvas.remove()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ object CaptureScreenScene extends Scene[SandboxStartupData, SandboxGameModel, Sa
type SceneModel = SandboxGameModel
type SceneViewModel = SandboxViewModel

val uiKey = BindingKey("ui")
val defaultKey = BindingKey("default")
val dudeCloneId = CloneId("Dude")
val uiKey = BindingKey("ui")
val defaultKey = BindingKey("default")
val dudeCloneId = CloneId("Dude")
val clippingRect = Rectangle(25, 25, 150, 100)

def eventFilters: EventFilters =
EventFilters.Restricted
Expand All @@ -48,6 +49,7 @@ object CaptureScreenScene extends Scene[SandboxStartupData, SandboxGameModel, Sa
case MouseEvent.Click(x, y) if x >= 250 && x <= 266 && y >= 165 && y <= 181 =>
// Open a window with the captured image
println(context.captureScreen(Batch(uiKey)).getDataUrl)
println(context.captureScreen(clippingRect).getDataUrl)
Outcome(model)
case _ => Outcome(model)
}
Expand All @@ -68,7 +70,7 @@ object CaptureScreenScene extends Scene[SandboxStartupData, SandboxGameModel, Sa
SceneUpdateFragment(
uiKey -> Layer(
Graphic(Rectangle(0, 0, 16, 16), Material.Bitmap(SandboxAssets.cameraIcon)).moveTo(250, 165),
Shape.Box(Rectangle(0, 0, 150, 100), Fill.None, Stroke(1, RGBA.SlateGray)).moveTo(25, 25)
Shape.Box(clippingRect, Fill.None, Stroke(1, RGBA.SlateGray))
),
defaultKey -> Layer(gameLayer(model, viewModel))
)
Expand Down

0 comments on commit 6fa99c9

Please sign in to comment.