https://github.com/traunin/debug-graphics-2d
Graphics2D debugger
https://github.com/traunin/debug-graphics-2d
debugging graphics2d java
Last synced: 4 months ago
JSON representation
Graphics2D debugger
- Host: GitHub
- URL: https://github.com/traunin/debug-graphics-2d
- Owner: Traunin
- License: mit
- Created: 2024-09-12T18:00:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-29T19:05:06.000Z (over 1 year ago)
- Last Synced: 2025-04-16T19:23:35.671Z (about 1 year ago)
- Topics: debugging, graphics2d, java
- Language: Java
- Homepage:
- Size: 36.1 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DebugGraphics2D
The following library is a superset of Java's Graphics2D class which allows users to display markers at primitives' control points for debugging purposes.
## Download
If you don't want to build the library yourself, you can download the jar file from the releases tab.
## Building
### Manually
Prerequisites:
- JDK (preferably 21 or newer)
- `javac` and `jar` in PATH
- `git` (to clone the repository, not necessary)
Clone the repository:
```sh
git clone https://github.com/traunin/debug-graphics-2d
```
Or download the code manually and extract it in the current folder.
Go into the folder:
```sh
cd debug-graphics-2d
```
Run:
```sh
javac -d bin src/com/github/traunin/debug_graphics_2d/*.java
jar cf DebugGraphics2D.jar -C bin .
```
The jar file is generated in the root folder of the repository.
### IntelliJ IDEA
Alternatively, if you are using IntelliJ IDEA:
1. Go to "File > Project Structure > Artifacts".
2. Click on the plus icon.
3. Select "JAR > From modules with dependencies".
4. Go to "Build > Build Artifacts".
5. Your jar file is now in the out/artifacts directory.
## Importing
### Gradle
In the `app` directory create the `lib` folder (or name as you wish) at the same level as the build file and the `src` folder. Place the jar file in that directory.
Then, modify the corresponding build file:
`build.gradle`:
```groovy
dependencies {
# other dependencies above
implementation files('lib/DebugGraphics2D.jar')
}
```
`build.gradle.kts`:
```kts
dependencies {
// other dependencies above
implementation(files("lib/DebugGraphics2D.jar"))
}
```
And rebuild the project. The package should be available for import.
## Usage
```java
// get the object
// import the library
import com.github.traunin.debug_graphics_2d.DebugGraphics2D;
// get any graphics instance from JFrame, JPanel, etc.
final Graphics g;
// create from graphics2d instance
final DebugGraphics2D g2d = new DebugGraphics2D((Graphics2D) g);
// debug parameters
// enable or disable debugging (no new markers will be recorded if disabled)
// enabled by default
g2d.enableDebugging();
g2d.disableDebugging();
// set marker color and/or size
g2d.setDebugColor(Color.YELLOW);
g2d.setDebugMarkerSize(4); // prefer even size
// draw
// works the same as standard graphics2d instance
// but will draw the corners of the drawn primitives
g2d.fillOval(50, 50, 100, 100);
// works with transforms
g2d.translate(50, 50);
// works with general path
g2d.fill(somePath);
// deferring markers
// start drawing markers on the top layer
g2d.startDeferringMarkers();
// draw something
g2d.fillRect(10, 10, 20, 20);
// draw all of the deferred markers on the top layer
// (if debugging was enabled)
g2d.drawDeferredMarkers();
```