-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a DebugRenderer to render debugging shapes
This could be refined, but for now is sufficient to render the two shapes supported by ZoneRenderer. It also renders using a transformed graphics context rather than transforming the shapes when they are set. Some liberties were taken with the renderer vs the existing behaviour: 1. The renderer supports any number of shapes and just cycles through a palette. 2. The shapes are rendered with an opaque border but a translucent fill so they don't complete obscure what is behind them.
- Loading branch information
1 parent
3a78657
commit a91e9e6
Showing
2 changed files
with
71 additions
and
49 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/net/rptools/maptool/client/ui/zone/renderer/DebugRenderer.java
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,64 @@ | ||
/* | ||
* This software Copyright by the RPTools.net development team, and | ||
* licensed under the Affero GPL Version 3 or, at your option, any later | ||
* version. | ||
* | ||
* MapTool Source Code is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License * along with this source Code. If not, please visit | ||
* <http://www.gnu.org/licenses/> and specifically the Affero license | ||
* text at <http://www.gnu.org/licenses/agpl.html>. | ||
*/ | ||
package net.rptools.maptool.client.ui.zone.renderer; | ||
|
||
import com.google.common.collect.Iterators; | ||
import java.awt.AlphaComposite; | ||
import java.awt.BasicStroke; | ||
import java.awt.Color; | ||
import java.awt.Graphics2D; | ||
import java.awt.Shape; | ||
|
||
public class DebugRenderer { | ||
private final RenderHelper renderHelper; | ||
private final Color[] palette; | ||
|
||
public DebugRenderer(RenderHelper renderHelper) { | ||
this.renderHelper = renderHelper; | ||
palette = new Color[] {Color.red, Color.green, Color.blue}; | ||
} | ||
|
||
public void renderShapes(Graphics2D g2d, Iterable<Shape> shapes) { | ||
renderHelper.render(g2d, worldG -> renderWorld(worldG, shapes)); | ||
} | ||
|
||
private void renderWorld(Graphics2D worldG, Iterable<Shape> shapes) { | ||
worldG.setComposite(AlphaComposite.SrcOver); | ||
// Keep the line a consistent thickness | ||
worldG.setStroke(new BasicStroke(1 / (float) worldG.getTransform().getScaleX())); | ||
|
||
var paletteIterator = Iterators.cycle(palette); | ||
for (final var shape : shapes) { | ||
final var color = paletteIterator.next(); | ||
|
||
if (shape == null) { | ||
continue; | ||
} | ||
|
||
var fillColor = color.darker(); | ||
fillColor = | ||
new Color( | ||
fillColor.getRed(), | ||
fillColor.getGreen(), | ||
fillColor.getBlue(), | ||
fillColor.getAlpha() / 3); | ||
worldG.setColor(fillColor); | ||
worldG.fill(shape); | ||
|
||
worldG.setColor(color); | ||
worldG.draw(shape); | ||
} | ||
} | ||
} |
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