Skip to content

Commit

Permalink
drop drawColor as it is hard to define semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
regb committed Sep 22, 2024
1 parent 9516f01 commit 65e4302
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 50 deletions.
28 changes: 0 additions & 28 deletions core/src/main/scala/sgl/GraphicsProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,34 +426,6 @@ trait GraphicsProvider extends GraphicsHelpersComponent {
*/
def drawCircle(x: Float, y: Float, radius: Float, paint: Paint): Unit = drawOval(x, y, 2*radius, 2*radius, paint)

/** Fill the canvas (restricted to the clip) with a color.
*
* This is a convenient way to fill the canvas with a color, it could
* instead be done by drawing a large rectangle, but it is potentially
* more efficient depending on the implementation.
*
* This always fills the visible area of the canvas. If the canvas
* origin is translated to the center of the screen, and we then call
* drawColor, the screen will be drawn from (-x,y) to (+x,+y), which
* will visually cover the entire screen. This also holds through a
* rotation of the canvas, the drawColor will still fill the entire
* space from top left to bottom right. You can think of it as drawing a
* rectangle from (0, 0) to (Window.width, Window.height) without any of
* the canvas transformations applied. However, it will respect clipped
* area, and it will not draw outside the clip.
*
* Note that it is unspecified if the color is drawn in the infinite
* canvas space, or only in the visible area. If you draw the color at
* some point, and then translate the canvas after that, the newly
* visible pixels might or might not be colored with the color.
*/
def drawColor(color: Color): Unit

// def clearRect(x: Float, y: Float, width: Float, height: Float): Unit
/** Clear the canvas by writing its background color */
// def clear(): Unit = clearRect(0, 0, width, height)


def drawString(str: String, x: Float, y: Float, paint: Paint): Unit
//TODO: provide alignment option
def drawText(text: TextLayout, x: Float, y: Float): Unit
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/sgl/proxy/ProxyGraphicsProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ trait ProxyGraphicsProvider extends GraphicsProvider {
override def drawLine(x1: Float, y1: Float, x2: Float, y2: Float, paint: Paint): Unit = canvas.drawLine(x1, y1, x2, y2, paint.paint)
override def drawRect(x: Float, y: Float, width: Float, height: Float, paint: Paint): Unit = canvas.drawRect(x, y, width, height, paint.paint)
override def drawOval(x: Float, y: Float, width: Float, height: Float, paint: Paint): Unit = canvas.drawOval(x,y,width, height, paint.paint)
override def drawColor(color: Color): Unit = canvas.drawColor(color)
override def drawString(str: String, x: Float, y: Float, paint: Paint): Unit = canvas.drawString(str,x,y,paint.paint)
override def drawText(text: TextLayout, x: Float, y: Float): Unit = canvas.drawText(text.textLayout, x, y)
override def renderText(text: String, width: Int, paint: Paint): TextLayout = ProxyTextLayout(canvas.renderText(text, width, paint.paint))
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/sgl/scene/ui/Popup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ trait PopupsComponent extends ButtonsComponent {
}

override def render(canvas: Canvas): Unit = {
val backgroundFont = Graphics.defaultPaint.withColor(backgroundColor)
if(active) {
canvas.drawColor(backgroundColor)
canvas.drawRect(0, 0, Window.width.toFloat, Window.height.toFloat, backgroundFont)
inner.render(canvas)
}
}
Expand Down
18 changes: 0 additions & 18 deletions desktop-awt/src/main/scala/sgl/awt/AWTGraphicsProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,6 @@ trait AWTGraphicsProvider extends GraphicsProvider {
text.draw(graphics, x, y)
}

override def drawColor(color: Color): Unit = {
val oldTransform = graphics.getTransform
graphics.setTransform(new java.awt.geom.AffineTransform)

graphics.setColor(color)
rect.setRect(0, 0, Window.width.toFloat, Window.height.toFloat)
graphics.fill(rect)

graphics.setTransform(oldTransform)
}


//override def clearRect(x: Float, y: Float, width: Float, height: Float): Unit = {
// graphics.setColor(Color.Black)
// rect.setRect(x, y, width, height)
// graphics.fill(rect)
//}

override def renderText(text: String, width: Int, paint: Paint): TextLayout = {
graphics.setColor(paint.color)
graphics.setFont(paint.font.f)
Expand Down
2 changes: 1 addition & 1 deletion examples/board/core/src/main/scala/MainScreen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ trait ScreensComponent {
override def update(dt: Long): Unit = { }

override def render(canvas: Graphics.Canvas): Unit = {
canvas.drawColor(Graphics.Color.Red)
canvas.drawRect(0, 0, Window.width, Window.height, Graphics.defaultPaint.withColor(Graphics.Color.Blue))
viewport.withViewport(canvas) {
for(i <- 0 until 100) {
for(j <- 0 until 100) {
Expand Down
2 changes: 1 addition & 1 deletion examples/menu/core/src/main/scala/MainScreen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait ScreensComponent {
}

override def render(canvas: Graphics.Canvas): Unit = {
canvas.drawColor(Graphics.Color.Black)
canvas.drawRect(0, 0, Window.width.toFloat, Window.height.toFloat, Graphics.defaultPaint.withColor(Graphics.Color.Black))
scene.render(canvas)
}

Expand Down

0 comments on commit 65e4302

Please sign in to comment.