Skip to content

Commit b7af544

Browse files
authored
Merge pull request #17 from Bob-Rust/feature/update-all
Feature/update all
2 parents 427ae8f + 9b0de15 commit b7af544

25 files changed

+851
-140
lines changed

build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ project.ext {
2020
majorVersion = '0'
2121
minorVersion = '1'
2222
}
23+
2324
version = "${majorVersion}.${minorVersion}.${getBuildId()}"
2425
group = "Bob-Rust-Java"
2526
description = "Bob-Rust-Java"
2627
java.sourceCompatibility = JavaVersion.VERSION_16
2728

29+
// Make sure our project knows it's own version
30+
writeVersion()
31+
2832
application {
2933
mainClass = 'com.bobrust.main.Main'
3034
}
@@ -81,6 +85,13 @@ def incrementBuildId() {
8185
}
8286
}
8387

88+
def writeVersion() {
89+
def versionFile = file('src/main/resources/version')
90+
FileOutputStream stream = new FileOutputStream(versionFile)
91+
stream.write("$version".getBytes())
92+
stream.close()
93+
}
94+
8495
def getBuildId() {
8596
def versionPropsFile = file('version.properties')
8697
if (versionPropsFile.canRead()) {

src/main/java/com/bobrust/generator/BorstUtils.java

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,70 @@ public class BorstUtils {
55
public static final int[] SIZES = { 1, 2, 4, 6, 10, 13 };
66

77
public static final BorstColor[] COLORS = {
8-
new BorstColor(46, 204, 112),
9-
new BorstColor(22, 161, 132),
10-
new BorstColor(52, 153, 218),
11-
new BorstColor(241, 195, 16),
12-
new BorstColor(143, 69, 173),
13-
new BorstColor(153, 163, 162),
14-
new BorstColor(52, 73, 93),
15-
new BorstColor(46, 158, 135),
16-
new BorstColor(30, 224, 24),
17-
new BorstColor(176, 122, 195),
18-
new BorstColor(231, 127, 33),
19-
new BorstColor(236, 240, 241),
20-
new BorstColor(38, 174, 96),
21-
new BorstColor(33, 203, 241),
22-
new BorstColor(126, 77, 41),
23-
new BorstColor(239, 68, 49),
24-
new BorstColor(74, 212, 188),
25-
new BorstColor(69, 48, 33),
26-
new BorstColor(49, 49, 49),
27-
new BorstColor(1, 2, 1)
8+
new BorstColor(0, 0, 0),
9+
new BorstColor(52, 33, 21),
10+
new BorstColor(52, 45, 21),
11+
new BorstColor(46, 51, 21),
12+
new BorstColor(33, 51, 21),
13+
new BorstColor(21, 51, 21),
14+
new BorstColor(21, 51, 33),
15+
new BorstColor(21, 51, 46),
16+
new BorstColor(21, 45, 52),
17+
new BorstColor(21, 33, 52),
18+
new BorstColor(21, 20, 52),
19+
new BorstColor(33, 20, 52),
20+
new BorstColor(46, 20, 52),
21+
new BorstColor(52, 20, 46),
22+
new BorstColor(52, 20, 33),
23+
new BorstColor(52, 20, 21),
24+
new BorstColor(115, 116, 115),
25+
new BorstColor(102, 65, 41),
26+
new BorstColor(102, 90, 41),
27+
new BorstColor(90, 102, 41),
28+
new BorstColor(66, 102, 41),
29+
new BorstColor(41, 102, 41),
30+
new BorstColor(41, 102, 66),
31+
new BorstColor(41, 102, 90),
32+
new BorstColor(41, 90, 102),
33+
new BorstColor(41, 65, 102),
34+
new BorstColor(41, 41, 102),
35+
new BorstColor(66, 41, 102),
36+
new BorstColor(90, 41, 102),
37+
new BorstColor(102, 41, 90),
38+
new BorstColor(102, 41, 66),
39+
new BorstColor(102, 41, 41),
40+
new BorstColor(192, 192, 192),
41+
new BorstColor(255, 134, 52),
42+
new BorstColor(255, 215, 52),
43+
new BorstColor(214, 255, 52),
44+
new BorstColor(132, 255, 52),
45+
new BorstColor(52, 255, 52),
46+
new BorstColor(52, 255, 132),
47+
new BorstColor(52, 255, 214),
48+
new BorstColor(52, 215, 255),
49+
new BorstColor(52, 134, 255),
50+
new BorstColor(52, 51, 255),
51+
new BorstColor(132, 51, 255),
52+
new BorstColor(214, 51, 255),
53+
new BorstColor(255, 51, 214),
54+
new BorstColor(255, 51, 132),
55+
new BorstColor(255, 51, 52),
56+
new BorstColor(255, 255, 255),
57+
new BorstColor(255, 178, 126),
58+
new BorstColor(255, 230, 126),
59+
new BorstColor(231, 255, 126),
60+
new BorstColor(178, 255, 126),
61+
new BorstColor(129, 255, 126),
62+
new BorstColor(126, 255, 178),
63+
new BorstColor(126, 255, 228),
64+
new BorstColor(126, 230, 255),
65+
new BorstColor(126, 178, 255),
66+
new BorstColor(129, 127, 255),
67+
new BorstColor(178, 127, 255),
68+
new BorstColor(231, 127, 255),
69+
new BorstColor(255, 127, 228),
70+
new BorstColor(255, 127, 178),
71+
new BorstColor(255, 127, 126),
2872
};
2973

3074
// Precomputed lookup tables
@@ -54,15 +98,19 @@ public static BorstColor getClosestColor(int color) {
5498
}
5599

56100
public static int getClosestColorIndex(int color) {
57-
int current_diff = 0;
101+
double current_diff = 0;
58102
int result = 0;
59103

60104
int b_r = (color >> 16) & 0xff;
61105
int b_g = (color >> 8) & 0xff;
62106
int b_b = (color ) & 0xff;
63107
for(int i = 0, len = COLORS.length; i < len; i++) {
64108
BorstColor a = COLORS[i];
65-
int diff = (a.r - b_r) * (a.r - b_r) + (a.g - b_g) * (a.g - b_g) + (a.b - b_b) * (a.b - b_b);
109+
// Weighted
110+
double rd = (a.r - b_r);
111+
double gd = (a.g - b_g);
112+
double bd = (a.b - b_b);
113+
double diff = rd * rd + gd * gd + bd * bd;
66114

67115
if(i == 0 || current_diff > diff) {
68116
current_diff = diff;

src/main/java/com/bobrust/generator/sorter/BorstSorter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ private static Blob[] sort0(Piece[] array, int size) {
198198
// Takes 36 ms for 60000 shapes
199199
private static IntList[][] create_cache(Piece[] array) {
200200
// 6 sizes * 20 colors
201-
IntList[] list_all = new IntList[6 * 20];
202-
IntList[] list_either = new IntList[6 * 20];
201+
final int colorLen = BorstUtils.COLORS.length;
202+
final int sizeLen = BorstUtils.SIZES.length;
203+
IntList[] list_all = new IntList[sizeLen * colorLen];
204+
IntList[] list_either = new IntList[sizeLen * colorLen];
203205

204206
for(Piece piece : array) {
205207
if(piece == null) continue;
@@ -217,8 +219,6 @@ private static IntList[][] create_cache(Piece[] array) {
217219
}
218220

219221
/* either */ {
220-
final int colorLen = BorstUtils.COLORS.length;
221-
final int sizeLen = BorstUtils.SIZES.length;
222222

223223
for(int i = 0; i < colorLen; i++) {
224224
// Colors is the X axis and has the upper value

src/main/java/com/bobrust/gui/BobRustDesktopOverlay.java

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public void selectMonitor() {
279279

280280
Rectangle bounds = gc.getBounds();
281281
String idString = gc.getDevice().getIDstring();
282+
updateTopBar();
282283
LOGGER.info("Selected Monitor: { id: '{}', x: {}, y: {}, width: {}, height: {} }", idString, bounds.x, bounds.y, bounds.width, bounds.height);
283284
}
284285

@@ -307,7 +308,9 @@ public void openImage() {
307308
if(file != null) {
308309
try {
309310
BufferedImage selectedImage = ImageIO.read(file);
310-
selectedImage = RustImageUtil.applyFilters(selectedImage);
311+
if (gui.getSettingsUseICCConversion() == 1) {
312+
selectedImage = RustImageUtil.applyFilters(selectedImage);
313+
}
311314

312315
LOGGER.info("Loaded image '{}'", file);
313316
image = selectedImage;
@@ -322,42 +325,53 @@ public void openImage() {
322325
}
323326
}
324327

325-
public void startGeneration() {
326-
if(!gui.borstGenerator.isRunning()) {
327-
Rectangle rect = canvasRegion.createIntersection(imageRegion).getBounds();
328+
public boolean canPerformGenerate() {
329+
Rectangle rect = canvasRegion.createIntersection(imageRegion).getBounds();
330+
return !rect.isEmpty();
331+
}
332+
333+
public boolean startGeneration() {
334+
if(gui.borstGenerator.isRunning()) {
335+
return false;
336+
}
337+
338+
Rectangle rect = canvasRegion.createIntersection(imageRegion).getBounds();
328339

329-
if(!rect.isEmpty()) {
330-
Sign signType = gui.getSettingsSign();
331-
Color bgColor = gui.getSettingsBackgroundCalculated();
332-
333-
BufferedImage scaled;
334-
scaled = RustImageUtil.getScaledInstance(
335-
image,
336-
canvasRegion,
337-
imageRegion,
338-
signType.width,
339-
signType.height,
340-
bgColor,
341-
gui.getSettingsScaling()
342-
);
343-
344-
// Apply the ICC cmyk lut filter
340+
if(!rect.isEmpty()) {
341+
Sign signType = gui.getSettingsSign();
342+
Color bgColor = gui.getSettingsBackgroundCalculated();
343+
344+
BufferedImage scaled;
345+
scaled = RustImageUtil.getScaledInstance(
346+
image,
347+
canvasRegion,
348+
imageRegion,
349+
signType.width,
350+
signType.height,
351+
bgColor,
352+
gui.getSettingsScaling()
353+
);
354+
355+
// Apply the ICC cmyk lut filter
356+
if (gui.getSettingsUseICCConversion() == 1) {
345357
scaled = RustImageUtil.applyFilters(scaled);
346-
347-
BorstSettings settings = gui.getBorstSettings();
348-
settings.Background = bgColor.getRGB();
349-
settings.DirectImage = scaled;
350-
updateEditor();
351-
if(gui.borstGenerator.start()) {
352-
shapeRender.createCanvas(scaled.getWidth(), scaled.getHeight(), bgColor.getRGB());
353-
354-
action = OverlayType.GENERATE_IMAGE;
355-
actionBarPanel.updateButtons();
356-
}
357358
}
358359

359-
repaint();
360+
BorstSettings settings = gui.getBorstSettings();
361+
settings.Background = bgColor.getRGB();
362+
settings.DirectImage = scaled;
363+
updateEditor();
364+
365+
if(gui.borstGenerator.start()) {
366+
shapeRender.createCanvas(scaled.getWidth(), scaled.getHeight(), bgColor.getRGB());
367+
368+
action = OverlayType.GENERATE_IMAGE;
369+
actionBarPanel.updateButtons();
370+
}
360371
}
372+
373+
repaint();
374+
return !rect.isEmpty();
361375
}
362376

363377
public void resetGeneration() {
@@ -408,6 +422,10 @@ public Rectangle getScreenLocation() {
408422
return monitorPicker.getMonitor().getBounds();
409423
}
410424

425+
public GraphicsConfiguration getMonitorConfiguration() {
426+
return monitorPicker.getMonitor();
427+
}
428+
411429
public void setEstimatedGenerationLabel(int index, int maxShapes) {
412430
topBarPanel.setEstimatedGenerationLabel(index, maxShapes);
413431
}
@@ -420,6 +438,14 @@ public void setRemainingTime(int index, int maxShapes, long timeLeft) {
420438
topBarPanel.setRemainingTime(index, maxShapes, timeLeft);
421439
}
422440

441+
private void updateTopBar() {
442+
int borderSize = isFullscreen ? BORDER_SIZE:0;
443+
444+
actionBarPanel.setBounds(borderSize, borderSize, actionBarPanel.getWidth(), dialog.getHeight() - BORDER_SIZE * 2);
445+
actionBarPanel.updateButtons();
446+
topBarPanel.setBounds((dialog.getWidth() - 440) / 2, isFullscreen ? BORDER_SIZE:-50, 440, 40);
447+
}
448+
423449
public void toggleFullscreen() {
424450
isFullscreen = !isFullscreen;
425451

@@ -437,12 +463,7 @@ public void toggleFullscreen() {
437463
dialog.setBounds(gc.getBounds());
438464
}
439465

440-
int borderSize = isFullscreen ? BORDER_SIZE:0;
441-
442-
actionBarPanel.setBounds(borderSize, borderSize, actionBarPanel.getWidth(), dialog.getHeight() - BORDER_SIZE * 2);
443-
actionBarPanel.updateButtons();
444-
topBarPanel.setBounds((dialog.getWidth() - 440) / 2, isFullscreen ? BORDER_SIZE:-50, 440, 40);
445-
466+
updateTopBar();
446467
updateEditor();
447468
dialog.setAlwaysOnTop(isFullscreen);
448469
dialog.setVisible(true);
@@ -502,7 +523,10 @@ protected void paintComponent(Graphics gr) {
502523
|| (actionBarPanel.btnSelectImageRegion.isSelected()
503524
|| actionBarPanel.btnSelectCanvasRegion.isSelected())) {
504525
// TODO: Cache this color.
526+
// g.setColor(Color.black);
527+
// g.fillRect(0, 0, getWidth() - 150, getHeight());
505528
g.setColor(new Color(0x30000000, true));
529+
// g.clearRect(0, 0, getWidth() - 150, getHeight());
506530
g.fillRect(0, 0, getWidth() - 150, getHeight());
507531

508532
// Draw region outline
@@ -573,7 +597,7 @@ protected void paintComponent(Graphics gr) {
573597
for(Map.Entry<BorstColor, Point> entry : map.entrySet()) {
574598
Point point = entry.getValue();
575599
Point sc = new Point(point.x - screen.x, point.y - screen.y);
576-
g.drawOval(sc.x - 15, sc.y - 15, 30, 29);
600+
g.drawOval(sc.x - 15, sc.y - 7, 30, 15);
577601
}
578602

579603
// TODO: Find a better way to draw these than crashing the application. xd

src/main/java/com/bobrust/gui/OverlayActionPanel.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ public void updateButtons() {
235235
btnSelectImageRegion.setEnabled(defaultAction && hasImage || action == OverlayType.SELECT_IMAGE_REGION);
236236

237237
btnOpenImage.setEnabled(defaultAction);
238-
btnStartGenerate.setEnabled(isFullscreen && hasImage);
238+
boolean hasRegion = btnSelectCanvasRegion.isSelected() || btnSelectImageRegion.isSelected();
239+
btnStartGenerate.setEnabled(isFullscreen && hasImage && desktopOverlay.canPerformGenerate() && !hasRegion);
239240
btnDrawImage.setEnabled(isFullscreen && isGeneratorRunning);
240241
}
241242

@@ -279,6 +280,17 @@ private void performStartGeneration(ActionEvent event) {
279280
);
280281

281282
if(!desktopOverlay.isGeneratorRunning()) {
283+
// Fix canvas region bug
284+
if (btnSelectCanvasRegion.isSelected()) {
285+
btnSelectCanvasRegion.setSelected(false);
286+
desktopOverlay.startSelectCanvasRegion(false);
287+
}
288+
289+
if (btnSelectImageRegion.isSelected()) {
290+
btnSelectImageRegion.setSelected(false);
291+
desktopOverlay.startSelectImageRegion(false);
292+
}
293+
282294
desktopOverlay.startGeneration();
283295
} else {
284296
desktopOverlay.resetGeneration();
@@ -295,6 +307,7 @@ private void performCloseApplication(ActionEvent event) {
295307
RustUI.getString(Type.ACTION_CLOSEDIALOG_TITLE),
296308
JOptionPane.YES_NO_OPTION
297309
);
310+
298311
if(dialogResult == JOptionPane.YES_OPTION) {
299312
System.exit(0);
300313
}
@@ -309,17 +322,10 @@ private void performOpenDonateUrl(ActionEvent event) {
309322
}
310323

311324
private void performShowAboutDialog(ActionEvent event) {
312-
String message =
313-
"Created by HardCoded & Sekwah41\n" +
314-
"\n" +
315-
"HardCoded\n" +
316-
"- Design\n" +
317-
"- Sorting algorithm\n" +
318-
"- Optimized generation\n" +
319-
"\n" +
320-
"Sekwah41\n" +
321-
"- Initial generation";
322-
323-
JOptionPane.showMessageDialog(dialog, message, "About me", JOptionPane.INFORMATION_MESSAGE);
325+
JOptionPane.showMessageDialog(dialog,
326+
RustUI.getString(Type.ACTION_ABOUTME_MESSAGE),
327+
RustUI.getString(Type.ACTION_ABOUTME_TITLE),
328+
JOptionPane.INFORMATION_MESSAGE
329+
);
324330
}
325331
}

0 commit comments

Comments
 (0)