this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

render a checkboard for transparent assets

+58 -5
+47 -5
src/main/java/app/pane/AssetsPanel.java
··· 9 9 import java.awt.Graphics; 10 10 import java.awt.Graphics2D; 11 11 import java.awt.Image; 12 + import java.awt.Rectangle; 12 13 import java.awt.RenderingHints; 14 + import java.awt.TexturePaint; 15 + import java.awt.image.BufferedImage; 13 16 import java.awt.event.MouseAdapter; 14 17 import java.awt.event.MouseEvent; 15 18 import java.io.File; 16 19 import java.io.IOException; 17 20 import java.nio.file.FileSystems; 18 - import java.nio.file.Path; 19 21 import java.nio.file.StandardWatchEventKinds; 20 22 import java.nio.file.WatchEvent; 21 23 import java.nio.file.WatchKey; ··· 214 216 215 217 private JPanel createSubdirItem(String name) 216 218 { 217 - JPanel panel = createItem(name, ThemedIcon.FOLDER_OPEN_24, () -> { 219 + JPanel panel = createItem(name, ThemedIcon.FOLDER_OPEN_24, null, () -> { 218 220 navigateTo(currentPath + name + "/"); 219 221 }); 220 222 return panel; ··· 222 224 223 225 private JPanel createAssetItem(AssetHandle asset) 224 226 { 225 - JPanel panel = createItem(asset.getAssetName(), ThemedIcon.PACKAGE_24, () -> { 227 + JPanel panel = createItem(asset.getAssetName(), ThemedIcon.PACKAGE_24, asset, () -> { 226 228 openAsset(asset); 227 229 }); 228 230 ··· 261 263 return panel; 262 264 } 263 265 264 - private JPanel createItem(String name, Icon defaultIcon, Runnable onDoubleClick) 266 + private JPanel createItem(String name, Icon defaultIcon, AssetHandle asset, Runnable onDoubleClick) 265 267 { 266 268 JPanel panel = createItemPanel(); 267 269 268 - JLabel icon = new JLabel(defaultIcon); 270 + boolean checkerboard = asset != null && asset.thumbnailHasCheckerboard(); 271 + JLabel icon = checkerboard ? new JLabel(defaultIcon) { 272 + @Override 273 + protected void paintComponent(Graphics g) 274 + { 275 + if (getIcon() != null) 276 + paintCheckerboard((Graphics2D) g, this); 277 + super.paintComponent(g); 278 + } 279 + } : new JLabel(defaultIcon); 269 280 icon.setHorizontalAlignment(JLabel.CENTER); 270 281 icon.setVerticalAlignment(JLabel.CENTER); 271 282 ··· 328 339 panel.setPreferredSize(new Dimension(ITEM_SIZE, ITEM_SIZE)); 329 340 panel.setOpaque(false); 330 341 return panel; 342 + } 343 + 344 + private static void paintCheckerboard(Graphics2D g2, JLabel label) 345 + { 346 + Icon icon = label.getIcon(); 347 + int iconW = icon.getIconWidth(); 348 + int iconH = icon.getIconHeight(); 349 + int x = (label.getWidth() - iconW) / 2; 350 + int y = (label.getHeight() - iconH) / 2; 351 + 352 + Color panelBg = UIManager.getColor("Panel.background"); 353 + boolean dark = panelBg != null && luminance(panelBg) < 0.5f; 354 + Color c1 = dark ? new Color(0x3C3C3C) : new Color(0xCCCCCC); 355 + Color c2 = dark ? new Color(0x2C2C2C) : new Color(0xFFFFFF); 356 + int cs = 4; 357 + var tile = new BufferedImage(cs * 2, cs * 2, BufferedImage.TYPE_INT_RGB); 358 + Graphics2D tg = tile.createGraphics(); 359 + tg.setColor(c1); 360 + tg.fillRect(0, 0, cs, cs); 361 + tg.fillRect(cs, cs, cs, cs); 362 + tg.setColor(c2); 363 + tg.fillRect(cs, 0, cs, cs); 364 + tg.fillRect(0, cs, cs, cs); 365 + tg.dispose(); 366 + g2.setPaint(new TexturePaint(tile, new Rectangle(x, y, cs * 2, cs * 2))); 367 + g2.fillRect(x, y, iconW, iconH); 368 + } 369 + 370 + private static float luminance(Color c) 371 + { 372 + return (0.299f * c.getRed() + 0.587f * c.getGreen() + 0.114f * c.getBlue()) / 255f; 331 373 } 332 374 333 375 private void openAsset(AssetHandle asset)
+6
src/main/java/assets/AssetHandle.java
··· 49 49 return null; 50 50 } 51 51 52 + /** Whether to paint a checkerboard behind the thumbnail for transparency. */ 53 + public boolean thumbnailHasCheckerboard() 54 + { 55 + return true; 56 + } 57 + 52 58 /** Override in subclasses to provide a high-resolution thumbnail image. */ 53 59 protected Image loadThumbnail() 54 60 {
+5
src/main/java/assets/ui/MapAsset.java
··· 84 84 } 85 85 86 86 @Override 87 + public boolean thumbnailHasCheckerboard() { 88 + return false; 89 + } 90 + 91 + @Override 87 92 protected Image loadThumbnail() 88 93 { 89 94 File thumbFile = new File(PROJ_THUMBNAIL + assetPath + ".png");