-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more shapes to display package
- Loading branch information
1 parent
0b938fc
commit efedc85
Showing
20 changed files
with
286 additions
and
35 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
4 changes: 1 addition & 3 deletions
4
...lin/dev/vexide/hydrozoa/clawbotkt/Main.kt → ...exide/hydrozoa/examples/clawbotkt/Main.kt
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
2 changes: 1 addition & 1 deletion
2
...in/dev/vexide/hydrozoa/clawbotkt/Robot.kt → ...xide/hydrozoa/examples/clawbotkt/Robot.kt
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
2 changes: 1 addition & 1 deletion
2
...ava/dev/vexide/hydrozoa/clawbot/Main.java → ...exide/hydrozoa/examples/clawbot/Main.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
2 changes: 1 addition & 1 deletion
2
...va/dev/vexide/hydrozoa/clawbot/Robot.java → ...xide/hydrozoa/examples/clawbot/Robot.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
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,13 @@ | ||
plugins { | ||
kotlin("jvm") version "1.9.20" | ||
id("dev.vexide.hydrozoa") | ||
} | ||
|
||
kotlin { | ||
jvmToolchain(21) | ||
} | ||
|
||
hydrozoa { | ||
entrypoint = "dev.vexide.hydrozoa.examples.screen.MainKt" | ||
runtime = rootProject.layout.projectDirectory.file("hydrozoa.bin") | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/screen/src/main/kotlin/dev/vexide/hydrozoa/examples/screen/Main.kt
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,20 @@ | ||
package dev.vexide.hydrozoa.examples.screen | ||
|
||
import dev.vexide.hydrozoa.CompetitionRobot | ||
import dev.vexide.hydrozoa.CompetitionRuntime | ||
import dev.vexide.hydrozoa.Peripherals | ||
import dev.vexide.hydrozoa.display.Rect | ||
import dev.vexide.hydrozoa.display.Rgb | ||
import dev.vexide.hydrozoa.display.Text | ||
|
||
fun main() { | ||
val peripherals = Peripherals.take().orElseThrow() | ||
val display = peripherals.takeDisplay() | ||
|
||
val rect = Rect(20, 20, 100, 100) | ||
display.fill(rect, Rgb.fromInteger(0xFFFFFF)) | ||
display.stroke(rect, Rgb.fromInteger(0xFF00FF)) | ||
|
||
val text = Text("Nice to see you!", 80, 80) | ||
display.write(text, Rgb.fromInteger(0x00FFFF), Rgb.fromInteger(0x000000)) | ||
} |
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
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.vexide.hydrozoa.display; | ||
|
||
import dev.vexide.hydrozoa.sdk.VexSdk; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record Circle(int x, int y, int radius) implements Shape { | ||
public Circle { | ||
if (radius < 0) { | ||
throw new IllegalArgumentException(String.format("Radius must be positive or zero, not `%d`", radius)); | ||
} | ||
} | ||
|
||
@Override | ||
public void draw(@NotNull Display screen, @NotNull Rgb color, boolean fill) { | ||
VexSdk.Display.vexDisplayForegroundColor(color.toInteger()); | ||
if (fill) { | ||
VexSdk.Display.vexDisplayCircleFill(x, y + Display.HEADER_HEIGHT, radius); | ||
} else { | ||
VexSdk.Display.vexDisplayCircleDraw(x, y + Display.HEADER_HEIGHT, radius); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,53 @@ | ||
package dev.vexide.hydrozoa.display; | ||
|
||
import dev.vexide.hydrozoa.Peripherals; | ||
import dev.vexide.hydrozoa.sdk.VexSdk; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class Display { | ||
public Display(Peripherals.Key ignoredKey) { | ||
public static final int HEADER_HEIGHT = 32; | ||
|
||
public Display(@NotNull Peripherals.Key ignoredKey) { | ||
} | ||
|
||
private @NotNull RenderMode renderMode = RenderMode.Immediate; | ||
|
||
public void setRenderMode(@NotNull RenderMode renderMode) { | ||
switch (renderMode) { | ||
case Immediate -> VexSdk.Display.vexDisplayDoubleBufferDisable(); | ||
case DoubleBuffered -> VexSdk.Display.vexDisplayRender(false, false); | ||
} | ||
this.renderMode = renderMode; | ||
} | ||
|
||
public @NotNull RenderMode getRenderMode() { | ||
return renderMode; | ||
} | ||
|
||
public void render() { | ||
if (renderMode == RenderMode.DoubleBuffered) { | ||
VexSdk.Display.vexDisplayRender(false, false); | ||
} | ||
} | ||
|
||
public void draw(@NotNull Shape shape, @NotNull Rgb color, boolean fill) { | ||
shape.draw(this, color, fill); | ||
} | ||
|
||
public void fill(@NotNull Shape shape, @NotNull Rgb color) { | ||
shape.draw(this, color, true); | ||
} | ||
|
||
public void stroke(@NotNull Shape shape, @NotNull Rgb color) { | ||
shape.draw(this, color, false); | ||
} | ||
|
||
public void write(@NotNull Text text, @NotNull Rgb fgColor, @NotNull Rgb bgColor) { | ||
text.draw(this, fgColor, bgColor); | ||
} | ||
|
||
public void fill(@NotNull Fillable shape, @NotNull Rgb color) { | ||
shape.fill(this, color); | ||
public enum RenderMode { | ||
Immediate, | ||
DoubleBuffered | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.vexide.hydrozoa.display; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface Shape { | ||
void draw(@NotNull Display screen, @NotNull Rgb color, boolean fill); | ||
} |
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,92 @@ | ||
package dev.vexide.hydrozoa.display; | ||
|
||
import dev.vexide.hydrozoa.sdk.VexSdk; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record Text(@NotNull String text, @NotNull Size size, int x, int y, HAlign hAlign, VAlign vAlign) { | ||
public Text(@NotNull String text, @NotNull Size size, int x, int y) { | ||
this(text, size, x, y, HAlign.Left, VAlign.Top); | ||
} | ||
|
||
public Text(@NotNull String text, int x, int y) { | ||
this(text, Size.Medium, x, y, HAlign.Left, VAlign.Top); | ||
} | ||
|
||
public @NotNull Text withSize(@NotNull Size size) { | ||
return new Text(text, size, x, y, hAlign, vAlign); | ||
} | ||
|
||
public @NotNull Text withAlignment(@NotNull HAlign hAlign, @NotNull VAlign vAlign) { | ||
return new Text(text, size, x, y, hAlign, vAlign); | ||
} | ||
|
||
private void configureTextMeasuring() { | ||
switch (size) { | ||
case Small -> VexSdk.Display.vexDisplaySmallStringAt(0, 0, ""); | ||
case Medium -> VexSdk.Display.vexDisplayStringAt(0, 0, ""); | ||
case Large -> VexSdk.Display.vexDisplayBigStringAt(0, 0, ""); | ||
} | ||
} | ||
|
||
/** | ||
* Get the height of the rendered text | ||
* @return the height of the text, in pixels | ||
*/ | ||
@Contract(pure = true) | ||
public int height() { | ||
configureTextMeasuring(); | ||
return VexSdk.Display.vexDisplayStringHeightGet(text); | ||
} | ||
|
||
/** | ||
* Get the width of the rendered text | ||
* @return the width of the text, in pixels | ||
*/ | ||
@Contract(pure = true) | ||
public int width() { | ||
configureTextMeasuring(); | ||
return VexSdk.Display.vexDisplayStringWidthGet(text); | ||
} | ||
|
||
public void draw(@NotNull Display display, @NotNull Rgb fgColor, @NotNull Rgb bgColor) { | ||
VexSdk.Display.vexDisplayForegroundColor(fgColor.toInteger()); | ||
VexSdk.Display.vexDisplayBackgroundColor(bgColor.toInteger()); | ||
|
||
var x = switch (hAlign) { | ||
case Left -> this.x; | ||
case Center -> this.x - width() / 2; | ||
case Right -> this.x - width(); | ||
}; | ||
|
||
var y = switch (vAlign) { | ||
case Top -> this.y; | ||
case Center -> this.y - height() / 2; | ||
case Bottom -> this.y - height(); | ||
} + Display.HEADER_HEIGHT; | ||
|
||
switch (size) { | ||
case Small -> VexSdk.Display.vexDisplaySmallStringAt(x, y, text); | ||
case Medium -> VexSdk.Display.vexDisplayStringAt(x, y, text); | ||
case Large -> VexSdk.Display.vexDisplayBigStringAt(x, y, text); | ||
} | ||
} | ||
|
||
public enum Size { | ||
Small, | ||
Medium, | ||
Large | ||
} | ||
|
||
public enum HAlign { | ||
Left, | ||
Center, | ||
Right | ||
} | ||
|
||
public enum VAlign { | ||
Top, | ||
Center, | ||
Bottom | ||
} | ||
} |
Oops, something went wrong.