Skip to content

Commit

Permalink
change the render context function inputs to doubles, version 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
LabyStudio committed Feb 23, 2021
1 parent 0e36b42 commit 916de40
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -26,7 +26,7 @@ You can exit the application by right-clicking the tray icon and selecting "Exit

```groovy
dependencies {
implementation 'com.github.LabyStudio:desktopmodules:2.2'
implementation 'com.github.LabyStudio:desktopmodules:2.3'
}
allprojects {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'de.labystudio'
version '2.2'
version '2.3'

compileJava {
sourceCompatibility = '1.8'
Expand Down
Expand Up @@ -23,7 +23,7 @@ public interface IRenderContext {
* @param bottom Bottom edge position relative to the module position
* @param color Color of the outline
*/
void drawOutline(int left, int top, int right, int bottom, Color color);
void drawOutline(double left, double top, double right, double bottom, Color color);

/**
* Fill a rectangle using LEFT, TOP, RIGHT and BOTTOM coordinates
Expand All @@ -34,7 +34,7 @@ public interface IRenderContext {
* @param bottom Bottom edge position relative to the module position
* @param color Color of the rectangle
*/
void drawRect(int left, int top, int right, int bottom, Color color);
void drawRect(double left, double top, double right, double bottom, Color color);

/**
* Fill a rectangle using X, Y, WIDTH and HEIGHT
Expand All @@ -45,7 +45,7 @@ public interface IRenderContext {
* @param height Height of the rectangle
* @param color
*/
void drawRectWH(int x, int y, int width, int height, Color color);
void drawRectWH(double x, double y, double width, double height, Color color);

/**
* Draw gradient rectangle
Expand All @@ -61,7 +61,7 @@ public interface IRenderContext {
* @param toX X to-color position relative to the module position
* @param toY Y to-color position relative to the module position
*/
void drawGradientRect(int left, int top, int right, int bottom, Color from, int fromX, int fromY, Color to, int toX, int toY);
void drawGradientRect(double left, double top, double right, double bottom, Color from, double fromX, double fromY, Color to, double toX, double toY);

/**
* Draw a string at given position with given settings
Expand All @@ -73,7 +73,7 @@ public interface IRenderContext {
* @param effect Text effect option
* @param color Text color option
*/
void drawString(String text, float x, float y, StringAlignment alignment, StringEffect effect, Color color, Font font);
void drawString(String text, double x, double y, StringAlignment alignment, StringEffect effect, Color color, Font font);

/**
* Get the string width of the given text with the given font style
Expand All @@ -91,7 +91,7 @@ public interface IRenderContext {
* @param x X position relative to the module position
* @param y Y position relative to the module position
*/
void drawImage(BufferedImage image, int x, int y);
void drawImage(BufferedImage image, double x, double y);


/**
Expand All @@ -103,7 +103,7 @@ public interface IRenderContext {
* @param width Image width
* @param height Image height
*/
void drawImage(BufferedImage image, int x, int y, int width, int height);
void drawImage(BufferedImage image, double x, double y, double width, double height);

/**
* Translate render context by given offset
Expand Down Expand Up @@ -131,6 +131,7 @@ public interface IRenderContext {

/**
* Change the alpha composite of the renderer
*
* @param alpha value from 0.0 to 1.0
*/
void setAlpha(float alpha);
Expand Down
Expand Up @@ -6,6 +6,7 @@
import de.labystudio.desktopmodules.core.renderer.font.StringEffect;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
Expand All @@ -31,36 +32,36 @@ public void updateGraphics(Graphics2D graphics) {
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}

@Override
public void drawOutline(int left, int top, int right, int bottom, Color color) {
public void drawOutline(double left, double top, double right, double bottom, Color color) {
this.graphics.setColor(color);
this.graphics.drawRect(left, top, right - left, bottom - top);
this.graphics.draw(new Rectangle2D.Double(left, top, right, bottom));
}

@Override
public void drawRect(int left, int top, int right, int bottom, Color color) {
this.graphics.setColor(color);
this.graphics.fillRect(left, top, right - left, bottom - top);
public void drawRect(double left, double top, double right, double bottom, Color color) {
drawRectWH(left, top, right - left, bottom - top, color);
}

@Override
public void drawRectWH(int x, int y, int width, int height, Color color) {
public void drawRectWH(double x, double y, double width, double height, Color color) {
this.graphics.setColor(color);
this.graphics.fillRect(x, y, width, height);
this.graphics.fill(new Rectangle2D.Double(x, y, width, height));
}

@Override
public void drawGradientRect(int left, int top, int right, int bottom, Color from, int fromX, int fromY, Color to, int toX, int toY) {
public void drawGradientRect(double left, double top, double right, double bottom, Color from, double fromX, double fromY, Color to, double toX, double toY) {
this.graphics.setPaint(new GradientPaint(
new Point2D.Double(fromX, fromY), from,
new Point2D.Double(toX, toY), to));
this.graphics.fill(new Rectangle2D.Double(left, top, right - left, bottom - top));
}

@Override
public void drawString(String text, float x, float y, StringAlignment alignment, StringEffect effect, Color color, Font font) {
public void drawString(String text, double x, double y, StringAlignment alignment, StringEffect effect, Color color, Font font) {
setFont(font);

FontMetrics fontMetrics = this.graphics.getFontMetrics();
Expand All @@ -71,12 +72,12 @@ public void drawString(String text, float x, float y, StringAlignment alignment,
// Draw effects
if (effect == StringEffect.SHADOW) {
this.graphics.setColor(Color.BLACK);
this.graphics.drawString(text, x - xOffset + 1, y + 1);
this.graphics.drawString(text, (float) x - xOffset + 1, (float) y + 1);
}

// Draw text
this.graphics.setColor(color);
this.graphics.drawString(text, x - xOffset, y);
this.graphics.drawString(text, (float) x - xOffset, (float) y);
}

@Override
Expand All @@ -86,13 +87,16 @@ public int getStringWidth(String text, Font font) {
}

@Override
public void drawImage(BufferedImage image, int x, int y) {
this.graphics.drawImage(image, x, y, null);
public void drawImage(BufferedImage image, double x, double y) {
drawImage(image, x, y, image.getWidth(), image.getHeight());
}

@Override
public void drawImage(BufferedImage image, int x, int y, int width, int height) {
this.graphics.drawImage(image, x, y, width, height, null, null);
public void drawImage(BufferedImage image, double x, double y, double width, double height) {
AffineTransform transform = new AffineTransform();
transform.translate(x, y);
transform.scale(width / image.getWidth(), height / image.getHeight());
this.graphics.drawImage(image, transform, null);
}

@Override
Expand Down

0 comments on commit 916de40

Please sign in to comment.