[Jrisk-cvs] SF.net SVN: domination-code:[2728] Domination/swingUI/src/net/yura
Brought to you by:
yuranet
|
From: <yu...@us...> - 2026-02-11 13:49:20
|
Revision: 2728
http://sourceforge.net/p/domination/code/2728
Author: yuranet
Date: 2026-02-11 13:49:17 +0000 (Wed, 11 Feb 2026)
Log Message:
-----------
fix for black and dark colors for text in dashboard
Modified Paths:
--------------
Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java
Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
Domination/swingUI/src/net/yura/swing/GraphicsUtil.java
Modified: Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java 2026-02-10 22:58:18 UTC (rev 2727)
+++ Domination/swingUI/src/net/yura/domination/guishared/PicturePanel.java 2026-02-11 13:49:17 UTC (rev 2728)
@@ -7,6 +7,7 @@
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
@@ -64,6 +65,7 @@
private String strCountry;
private RescaleOp HighLight;
+ private Font circleFont;
/**
* Creates an Picture Panel
@@ -84,6 +86,7 @@
setPreferredSize(size);
setMinimumSize(size);
+ setBackground(Color.BLACK);
}
protected void processMouseEvent(MouseEvent e) {
@@ -126,7 +129,7 @@
RiskGame game = myrisk.getGame();
BALL_SIZE = game.getCircleSize();
- setFont( new java.awt.Font("Arial", java.awt.Font.PLAIN, (BALL_SIZE+2)/2 ) );
+ circleFont = new java.awt.Font("Arial", java.awt.Font.PLAIN, (BALL_SIZE+2)/2 );
original = O;
cc=NO_COUNTRY;
c1=NO_COUNTRY;
@@ -247,10 +250,10 @@
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-
+
// draw the dashbard
g.setFont(getFont());
- RiskUIUtil.drawDashboard(g, myrisk.getGame(), drawImageX > 0);
+ RiskUIUtil.drawDashboard(g2, myrisk.getGame(), drawImageX > 0);
g2.translate(drawImageX, getDrawImageY(s));
g2.scale(s,s);
@@ -284,11 +287,13 @@
drawArmies(g2);
+ g2.scale(1.0 / s, 1.0 / s);
+
if (cc != NO_COUNTRY) {
int offset = 5;
- TextLayout tl = new TextLayout( this.strCountry + " "+ myrisk.getCountryName( cc ) , g2.getFont() , g2.getFontRenderContext() );
+ TextLayout tl = new TextLayout(this.strCountry + " " + myrisk.getCountryName(cc), getFont(), g2.getFontRenderContext());
int w = (int)tl.getAdvance();
int h = (int)tl.getAscent() + (int)tl.getDescent();
@@ -308,11 +313,11 @@
}
private int getDrawImageX(double ratio) {
- return (int) (getWidth()-( getMapWidth() *ratio) )/2;
+ return (int) ((getWidth()-( getMapWidth() *ratio) ) / 1.2);
}
private int getDrawImageY(double ratio) {
- return (int) (getHeight()-( getMapHeight() *ratio) )/2;
+ return (int) ((getHeight()-( getMapHeight() *ratio) ) / 1.2);
}
private double getScale() {
@@ -393,14 +398,13 @@
}
}
}
-
+
+ g2.setFont(circleFont);
+
Country t;
for (int c=0; c< v.length ; c++) {
-
t = v[c];
- g2.setFont( getFont() );
-
if ( t.getOwner() != null ) {
int x,y;
@@ -444,7 +448,7 @@
g2.setColor(textColor);
Color outlineColor = Color.WHITE.equals(textColor) ? Color.BLACK : Color.WHITE;
- GraphicsUtil.drawStringWithOutline(g2, new TextLayout(noa, g2.getFont(), g2.getFontRenderContext()), textX, textY, outlineColor);
+ GraphicsUtil.drawStringWithOutline(g2, new TextLayout(noa, circleFont, g2.getFontRenderContext()), textX, textY, outlineColor);
}
if (capital != null) {
Modified: Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java
===================================================================
--- Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2026-02-10 22:58:18 UTC (rev 2727)
+++ Domination/swingUI/src/net/yura/domination/guishared/RiskUIUtil.java 2026-02-11 13:49:17 UTC (rev 2728)
@@ -11,7 +11,7 @@
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
-import java.awt.Graphics;
+import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
@@ -1630,7 +1630,7 @@
/**
* @see net.yura.domination.mobile.flashgui.GameWindow
*/
- public static void drawDashboard(Graphics g, RiskGame game, boolean wrap) {
+ public static void drawDashboard(Graphics2D g, RiskGame game, boolean wrap) {
FontMetrics font = g.getFontMetrics();
List<Player> players = game.getPlayers();
@@ -1660,8 +1660,16 @@
g.drawString(arrow, x - font.stringWidth(arrow), y);
}
g.setColor(new Color(p.getColor()));
+ boolean isLightText = ColorUtil.isColorLight(p.getColor());
+
for (int col = 0; col < data[row].length; col++) {
- g.drawString(data[row][col], x, y);
+ if (isLightText) {
+ g.drawString(data[row][col], x, y);
+ }
+ else {
+ GraphicsUtil.drawStringWithOutline(g, data[row][col], x, y, Color.WHITE);
+ }
+
if (wrap && col == 0) {
x += lineHeight + font.stringWidth(" "); // player emoji width + space
y += lineHeight;
Modified: Domination/swingUI/src/net/yura/swing/GraphicsUtil.java
===================================================================
--- Domination/swingUI/src/net/yura/swing/GraphicsUtil.java 2026-02-10 22:58:18 UTC (rev 2727)
+++ Domination/swingUI/src/net/yura/swing/GraphicsUtil.java 2026-02-11 13:49:17 UTC (rev 2728)
@@ -29,6 +29,7 @@
import java.awt.image.ImageProducer;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
+import java.text.BreakIterator;
import java.util.List;
import javax.swing.plaf.basic.BasicGraphicsUtils;
@@ -197,6 +198,81 @@
g2.fill(outline);
}
+ public static void drawStringWithOutline(Graphics2D g2, String text, int x, int y, Color outlineColor) {
+ FontRenderContext frc = g2.getFontRenderContext();
+ BreakIterator it = BreakIterator.getCharacterInstance();
+ it.setText(text);
+
+ float penX = x;
+ StringBuilder buffer = new StringBuilder();
+
+ int start = it.first();
+ for (int end = it.next(); end != BreakIterator.DONE; start = end, end = it.next()) {
+
+ String cluster = text.substring(start, end);
+
+ if (isEmojiCluster(cluster)) {
+ // flush text buffer
+ if (buffer.length() > 0) {
+ TextLayout layout = new TextLayout(buffer.toString(), g2.getFont(), frc);
+ drawStringWithOutline(g2, layout, penX, y, outlineColor);
+ penX += layout.getAdvance();
+ buffer.setLength(0);
+ }
+
+ // draw emoji cluster
+ g2.drawString(cluster, penX, y);
+
+ FontMetrics fm = g2.getFontMetrics();
+ penX += fm.stringWidth(cluster);
+ }
+ else {
+ buffer.append(cluster);
+ }
+ }
+
+ // flush remaining text
+ if (buffer.length() > 0) {
+ TextLayout layout = new TextLayout(buffer.toString(), g2.getFont(), frc);
+ drawStringWithOutline(g2, layout, penX, y, outlineColor);
+ }
+ }
+
+ /**
+ * WARNING!!! code generated by AI, may not be correct!
+ */
+ private static boolean isEmojiCluster(String cluster) {
+ if (cluster == null || cluster.length() == 0) return false;
+
+ for (int i = 0; i < cluster.length(); ) {
+ char c1 = cluster.charAt(i);
+ int cp = c1;
+ if (Character.isHighSurrogate(c1) && i + 1 < cluster.length()) {
+ char c2 = cluster.charAt(i + 1);
+ if (Character.isLowSurrogate(c2)) {
+ cp = Character.toCodePoint(c1, c2);
+ }
+ }
+
+ if ((cp >= 0x1F300 && cp <= 0x1F5FF) || // Misc Symbols & Pictographs
+ (cp >= 0x1F600 && cp <= 0x1F64F) || // Emoticons
+ (cp >= 0x1F680 && cp <= 0x1F6FF) || // Transport & Map
+ (cp >= 0x1F900 && cp <= 0x1F9FF) || // Supplemental Symbols
+ (cp >= 0x1FA70 && cp <= 0x1FAFF) || // Extended-A
+ (cp >= 0x1F1E6 && cp <= 0x1F1FF) || // Regional indicators
+ cp == 0x200D || // ZWJ
+ cp == 0xFE0F // VS16
+ ) {
+ return true;
+ }
+
+ i += ((cp >= 0x10000) ? 2 : 1);
+ }
+
+ return false;
+ }
+
+
private static double getDisplayDensity() {
try {
return ((Double)Class.forName("javax.microedition.midlet.ApplicationManager")
|