Skip to content

Commit 04d268f

Browse files
committed
use stop button color
1 parent acfeb6b commit 04d268f

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ public abstract class PGL {
352352

353353
protected boolean presentMode = false;
354354
protected boolean showStopButton = true;
355-
protected int stopButtonColor;
356355
public float presentX;
357356
public float presentY;
358-
protected IntBuffer closeBtnTex;
359-
protected int closeBtnWidth = 28;
360-
protected int closeBtnHeight = 12;
361-
protected int closeBtnX = 21; // The position of the close button is relative to the
362-
protected int closeBtnY = 21; // lower left corner
363-
protected static int[] closeBtnPix = {
357+
protected IntBuffer closeButtonTex;
358+
protected int stopButtonColor;
359+
protected int stopButtonWidth = 28;
360+
protected int stopButtonHeight = 12;
361+
protected int stopButtonX = 21; // The position of the close button is relative to the
362+
protected int closeButtonY = 21; // lower left corner
363+
protected static int[] closeButtonPix = {
364364
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
365365
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
366366
0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, -1,
@@ -626,8 +626,8 @@ public float presentY() {
626626

627627
public boolean insideStopButton(float x, float y) {
628628
if (!showStopButton) return false;
629-
return closeBtnX < x && x < closeBtnX + closeBtnWidth &&
630-
-(closeBtnY + closeBtnHeight) < y && y < -closeBtnY;
629+
return stopButtonX < x && x < stopButtonX + stopButtonWidth &&
630+
-(closeButtonY + stopButtonHeight) < y && y < -closeButtonY;
631631
}
632632

633633

@@ -732,23 +732,41 @@ protected void endRender(int windowColor) {
732732
clear(COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT);
733733

734734
if (showStopButton) {
735-
if (closeBtnTex == null) {
736-
closeBtnTex = allocateIntBuffer(1);
737-
genTextures(1, closeBtnTex);
738-
bindTexture(TEXTURE_2D, closeBtnTex.get(0));
735+
if (closeButtonTex == null) {
736+
closeButtonTex = allocateIntBuffer(1);
737+
genTextures(1, closeButtonTex);
738+
bindTexture(TEXTURE_2D, closeButtonTex.get(0));
739739
texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, NEAREST);
740740
texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, NEAREST);
741741
texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
742742
texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
743-
texImage2D(TEXTURE_2D, 0, RGBA, closeBtnWidth, closeBtnHeight, 0, RGBA, UNSIGNED_BYTE, null);
744-
IntBuffer buf = allocateIntBuffer(closeBtnPix);
745-
copyToTexture(TEXTURE_2D, RGBA, closeBtnTex.get(0), 0, 0, closeBtnWidth, closeBtnHeight, buf);
743+
texImage2D(TEXTURE_2D, 0, RGBA, stopButtonWidth, stopButtonHeight, 0, RGBA, UNSIGNED_BYTE, null);
744+
745+
int[] color = new int[closeButtonPix.length];
746+
PApplet.arrayCopy(closeButtonPix, color);
747+
748+
749+
// Multiply the texture by the button color
750+
float ba = ((stopButtonColor >> 24) & 0xFF) / 255f;
751+
float br = ((stopButtonColor >> 16) & 0xFF) / 255f;
752+
float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
753+
float bb = ((stopButtonColor >> 0) & 0xFF) / 255f;
754+
for (int i = 0; i < color.length; i++) {
755+
int c = closeButtonPix[i];
756+
int a = (int)(ba * ((c >> 24) & 0xFF));
757+
int r = (int)(br * ((c >> 16) & 0xFF));
758+
int g = (int)(bg * ((c >> 8) & 0xFF));
759+
int b = (int)(bb * ((c >> 0) & 0xFF));
760+
color[i] = javaToNativeARGB((a << 24) | (r << 16) | (g << 8) | b);
761+
}
762+
IntBuffer buf = allocateIntBuffer(color);
763+
copyToTexture(TEXTURE_2D, RGBA, closeButtonTex.get(0), 0, 0, stopButtonWidth, stopButtonHeight, buf);
746764
bindTexture(TEXTURE_2D, 0);
747765
}
748-
drawTexture(TEXTURE_2D, closeBtnTex.get(0), closeBtnWidth, closeBtnHeight,
749-
0, 0, closeBtnX + closeBtnWidth, closeBtnY + closeBtnHeight,
750-
0, closeBtnHeight, closeBtnWidth, 0,
751-
closeBtnX, closeBtnY, closeBtnX + closeBtnWidth, closeBtnY + closeBtnHeight);
766+
drawTexture(TEXTURE_2D, closeButtonTex.get(0), stopButtonWidth, stopButtonHeight,
767+
0, 0, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight,
768+
0, stopButtonHeight, stopButtonWidth, 0,
769+
stopButtonX, closeButtonY, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight);
752770
}
753771
} else {
754772
clearDepth(1);

0 commit comments

Comments
 (0)