Skip to content

Commit afb2bb9

Browse files
authored
Merge pull request #12 from Bob-Rust/graphics-update
style: Updated graphics
2 parents 8140ed1 + a9a39ec commit afb2bb9

13 files changed

+281
-301
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bobrust.generator.sorter;
22

33
import java.util.*;
4+
import java.util.stream.IntStream;
45

56
import com.bobrust.generator.BorstUtils;
67

@@ -137,9 +138,7 @@ private static Blob[] sort0(Piece[] array) {
137138

138139
// Takes 4600 ms for 60000 shapes
139140
// Use the quad tree to efficiently calculate the collisions
140-
List<Integer> indexList = new ArrayList<>(array.length);
141-
for(int i = 1, len = array.length; i < len; i++) indexList.add(i);
142-
indexList.parallelStream().forEach((i) -> {
141+
IntStream.range(1, array.length).parallel().forEach((i) -> {
143142
// Worst case senario O(N^2) if every circle is in the same position
144143
map[i] = get_intersections(array[i], array, tree);
145144
map[i].reverse();

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

Lines changed: 93 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.bobrust.gui.comp.JRandomPanel;
2424
import com.bobrust.gui.comp.JStyledButton;
2525
import com.bobrust.gui.comp.JStyledToggleButton;
26+
import com.bobrust.gui.dialog.BobRustDrawDialog;
27+
import com.bobrust.gui.dialog.BobRustMonitorPicker;
2628
import com.bobrust.lang.RustTranslator;
2729
import com.bobrust.lang.RustUI;
2830
import com.bobrust.lang.RustUI.Type;
@@ -101,100 +103,64 @@ public class BobRustOverlay extends JPanel {
101103
public void mousePressed(MouseEvent e) {
102104
isToolbarArea = e.getX() < 137 - RECTANGLE_SELECTION_SIZE;
103105
if(isToolbarArea) {
104-
// If the point is in the action panel we should not compute anything
105106
return;
106107
}
107108

108109
originPoint = new Point(e.getPoint());
109110
if(originPoint.x < 137) {
110111
originPoint.x = 137;
111112
}
112-
if(action == OverlayType.SELECT_CANVAS_REGION) rectangle = canvasRegion;
113-
if(action == OverlayType.SELECT_IMAGE_REGION) rectangle = imageRegion;
114113

115-
switch(action) {
116-
case SELECT_CANVAS_REGION, SELECT_IMAGE_REGION -> {
117-
// Keep a copy of the original.
118-
original.setBounds(rectangle);
119-
120-
Rectangle larger = new Rectangle(rectangle);
121-
larger.setBounds(
122-
rectangle.x - RECTANGLE_SELECTION_SIZE,
123-
rectangle.y - RECTANGLE_SELECTION_SIZE,
124-
rectangle.x + rectangle.width + RECTANGLE_SELECTION_SIZE * 2,
125-
rectangle.y + rectangle.height + RECTANGLE_SELECTION_SIZE * 2
126-
);
127-
128-
Point mouse = e.getPoint();
129-
130-
if(!larger.contains(mouse)) {
131-
resizeOption = ResizeOption.ALL;
132-
} else {
133-
boolean top = Math.abs(rectangle.y - mouse.y) < RECTANGLE_SELECTION_SIZE;
134-
boolean right = Math.abs(rectangle.x + rectangle.width - mouse.x) < RECTANGLE_SELECTION_SIZE;
135-
boolean bottom = Math.abs(rectangle.y + rectangle.height - mouse.y) < RECTANGLE_SELECTION_SIZE;
136-
boolean left = Math.abs(rectangle.x - mouse.x) < RECTANGLE_SELECTION_SIZE;
137-
138-
if(top) {
139-
resizeOption = right ? ResizeOption.TOP_RIGHT:(left ? ResizeOption.TOP_LEFT:ResizeOption.TOP);
140-
} else if(bottom) {
141-
resizeOption = right ? ResizeOption.BOTTOM_RIGHT:(left ? ResizeOption.BOTTOM_LEFT:ResizeOption.BOTTOM);
142-
} else {
143-
resizeOption = right ? ResizeOption.RIGHT:(left ? ResizeOption.LEFT:ResizeOption.ALL);
144-
}
145-
}
146-
147-
modifyRectangle(e.getPoint());
148-
}
149-
default -> {
150-
151-
}
152-
}
114+
updateResizeOption(e.getPoint());
115+
modifyRectangle(e.getPoint());
153116
}
154117

118+
@Override
155119
public void mouseMoved(MouseEvent e) {
156120
if(isToolbarArea) {
157121
return;
158122
}
159123

160-
if(action == OverlayType.SELECT_CANVAS_REGION) rectangle = canvasRegion;
161-
if(action == OverlayType.SELECT_IMAGE_REGION) rectangle = imageRegion;
124+
updateResizeOption(e.getPoint());
125+
repaint();
126+
}
127+
128+
private void updateResizeOption(Point mouse) {
129+
if(action == OverlayType.SELECT_CANVAS_REGION) {
130+
rectangle = canvasRegion;
131+
} else if(action == OverlayType.SELECT_IMAGE_REGION) {
132+
rectangle = imageRegion;
133+
} else {
134+
// Return if the action was not canvas or image.
135+
return;
136+
}
162137

163-
switch(action) {
164-
case SELECT_CANVAS_REGION, SELECT_IMAGE_REGION -> {
165-
// Keep a copy of the original.
166-
original.setBounds(rectangle);
167-
168-
Point mouse = e.getPoint();
169-
170-
Rectangle larger = new Rectangle(rectangle);
171-
larger.setBounds(
172-
rectangle.x - RECTANGLE_SELECTION_SIZE,
173-
rectangle.y - RECTANGLE_SELECTION_SIZE,
174-
rectangle.width + RECTANGLE_SELECTION_SIZE * 2,
175-
rectangle.height + RECTANGLE_SELECTION_SIZE * 2
176-
);
177-
178-
if(!larger.contains(mouse)) {
179-
resizeOption = ResizeOption.ALL;
180-
} else {
181-
boolean top = Math.abs(rectangle.y - mouse.y) < RECTANGLE_SELECTION_SIZE;
182-
boolean right = Math.abs(rectangle.x + rectangle.width - mouse.x) < RECTANGLE_SELECTION_SIZE;
183-
boolean bottom = Math.abs(rectangle.y + rectangle.height - mouse.y) < RECTANGLE_SELECTION_SIZE;
184-
boolean left = Math.abs(rectangle.x - mouse.x) < RECTANGLE_SELECTION_SIZE;
185-
186-
if(top) {
187-
resizeOption = right ? ResizeOption.TOP_RIGHT:(left ? ResizeOption.TOP_LEFT:ResizeOption.TOP);
188-
} else if(bottom) {
189-
resizeOption = right ? ResizeOption.BOTTOM_RIGHT:(left ? ResizeOption.BOTTOM_LEFT:ResizeOption.BOTTOM);
190-
} else {
191-
resizeOption = right ? ResizeOption.RIGHT:(left ? ResizeOption.LEFT:ResizeOption.ALL);
192-
}
193-
}
194-
195-
repaint();
138+
// Keep a copy of the original.
139+
original.setBounds(rectangle);
140+
141+
Rectangle larger = new Rectangle(rectangle);
142+
larger.setBounds(
143+
rectangle.x - RECTANGLE_SELECTION_SIZE,
144+
rectangle.y - RECTANGLE_SELECTION_SIZE,
145+
rectangle.width + RECTANGLE_SELECTION_SIZE * 2,
146+
rectangle.height + RECTANGLE_SELECTION_SIZE * 2
147+
);
148+
149+
if(!larger.contains(mouse)) {
150+
resizeOption = ResizeOption.ALL;
151+
} else {
152+
boolean top = Math.abs(rectangle.y - mouse.y) < RECTANGLE_SELECTION_SIZE;
153+
boolean right = Math.abs(rectangle.x + rectangle.width - mouse.x) < RECTANGLE_SELECTION_SIZE;
154+
boolean bottom = Math.abs(rectangle.y + rectangle.height - mouse.y) < RECTANGLE_SELECTION_SIZE;
155+
boolean left = Math.abs(rectangle.x - mouse.x) < RECTANGLE_SELECTION_SIZE;
156+
157+
if(top) {
158+
resizeOption = right ? ResizeOption.TOP_RIGHT:(left ? ResizeOption.TOP_LEFT:ResizeOption.TOP);
159+
} else if(bottom) {
160+
resizeOption = right ? ResizeOption.BOTTOM_RIGHT:(left ? ResizeOption.BOTTOM_LEFT:ResizeOption.BOTTOM);
161+
} else {
162+
resizeOption = right ? ResizeOption.RIGHT:(left ? ResizeOption.LEFT:ResizeOption.ALL);
196163
}
197-
default -> {}
198164
}
199165
}
200166

@@ -364,7 +330,7 @@ public void windowClosing(WindowEvent e) {
364330
});
365331

366332
btnMaximize = new JStyledButton(RustUI.getString(Type.ACTION_MAKEFULLSCREEN_ON));
367-
btnMaximize.setMaximumSize(new Dimension(120, 24));
333+
btnMaximize.setMaximumSize(buttonSize);
368334
btnMaximize.addActionListener(this::changeFullscreen);
369335
actionPanel.add(btnMaximize);
370336
actionPanel.add(btnSelectMonitor);
@@ -397,7 +363,7 @@ public void windowClosing(WindowEvent e) {
397363
labels.add(lblRegions);
398364

399365
btnHideRegions = new JStyledToggleButton(RustUI.getString(Type.ACTION_SHOWREGIONS_ON));
400-
btnHideRegions.setMaximumSize(new Dimension(120, 24));
366+
btnHideRegions.setMaximumSize(buttonSize);
401367
btnHideRegions.setSelected(true);
402368
btnHideRegions.addActionListener((event) -> setHideRegions(btnHideRegions.isSelected()));
403369
regionsPanel.add(btnHideRegions);
@@ -455,7 +421,7 @@ public void windowClosing(WindowEvent e) {
455421
previewPanel.add(btnPauseGenerate);
456422

457423
btnResetGenerate = new JStyledButton(RustUI.getString(Type.ACTION_RESETGENERATE_BUTTON));
458-
btnResetGenerate.setMaximumSize(new Dimension(120, 24));
424+
btnResetGenerate.setMaximumSize(buttonSize);
459425
btnResetGenerate.setEnabled(false);
460426
btnResetGenerate.addActionListener((event) -> resetGeneration());
461427
previewPanel.add(btnResetGenerate);
@@ -490,7 +456,7 @@ public void windowClosing(WindowEvent e) {
490456
labels.add(lblPaintImage);
491457

492458
btnDrawImage = new JStyledButton(RustUI.getString(Type.ACTION_DRAWIMAGE_BUTTON));
493-
btnDrawImage.setMaximumSize(new Dimension(120, 24));
459+
btnDrawImage.setMaximumSize(buttonSize);
494460
btnDrawImage.setEnabled(false);
495461
btnDrawImage.addActionListener((event) -> {
496462
drawDialog.openDialog(btnDrawImage.getLocationOnScreen());
@@ -518,17 +484,17 @@ public void windowClosing(WindowEvent e) {
518484
labels.add(lblHelp);
519485

520486
JStyledButton btnGithubIssue = new JStyledButton(RustUI.getString(Type.ACTION_REPORTISSUE_BUTTON));
521-
btnGithubIssue.setMaximumSize(new Dimension(120, 24));
487+
btnGithubIssue.setMaximumSize(buttonSize);
522488
btnGithubIssue.addActionListener((event) -> UrlUtils.openIssueUrl());
523489
actionPanel.add(btnGithubIssue);
524490

525491
JStyledButton btnDonate = new JStyledButton(RustUI.getString(Type.ACTION_DONATE_BUTTON));
526-
btnDonate.setMaximumSize(new Dimension(120, 24));
492+
btnDonate.setMaximumSize(buttonSize);
527493
btnDonate.addActionListener((event) -> UrlUtils.openDonationUrl());
528494
actionPanel.add(btnDonate);
529495

530496
JStyledButton btnAbout = new JStyledButton(RustUI.getString(Type.ACTION_ABOUT_BUTTON));
531-
btnAbout.setMaximumSize(new Dimension(120, 24));
497+
btnAbout.setMaximumSize(buttonSize);
532498
btnAbout.addActionListener((event) -> {
533499
String message = "Created by HardCoded & Sekwah41\n" +
534500
"\n" +
@@ -623,7 +589,7 @@ private void resetGeneration() {
623589
}
624590
}
625591

626-
protected void setHideRegions(boolean enable) {
592+
public void setHideRegions(boolean enable) {
627593
if(enable) {
628594
btnHideRegions.setText(RustUI.getString(Type.ACTION_SHOWREGIONS_ON));
629595
} else {
@@ -649,11 +615,11 @@ private void setPauseGeneration(boolean enable) {
649615
}
650616

651617
public void updateEditor() {
652-
setBorder(isFullscreen ? new LineBorder(gui.getBorderColor(), BORDER_SIZE):null);
653-
actionPanel.setBackground(gui.getToolbarColor());
618+
setBorder(isFullscreen ? new LineBorder(gui.getEditorBorderColor(), BORDER_SIZE):null);
619+
actionPanel.setBackground(gui.getEditorToolbarColor());
654620

655621
for(JLabel label : labels) {
656-
label.setForeground(gui.getLabelColor());
622+
label.setForeground(gui.getEditorLabelColor());
657623
}
658624

659625
generationLabel.setLocation((topBarPanel.getWidth() - generationLabel.getWidth()) / 2, generationLabel.getY());
@@ -677,13 +643,13 @@ public Rectangle getScreenLocation() {
677643
return monitorPicker.getMonitor().getBounds();
678644
}
679645

680-
protected void setEstimatedGenerationLabel(int index, int maxShapes) {
646+
public void setEstimatedGenerationLabel(int index, int maxShapes) {
681647
generationLabel.setText("%d/%d shapes generated".formatted(index, maxShapes));
682648
long time = (long)(index * 1.1 * (ESTIMATE_DELAY_OFFSET + 1000.0 / (double)gui.getSettingsClickInterval()));
683649
generationInfo.setText("Estimated %s".formatted(RustTranslator.getTimeMinutesMessage(time)));
684650
}
685651

686-
protected void setExactGenerationLabel(long time) {
652+
public void setExactGenerationLabel(long time) {
687653
generationInfo.setText("Time %s".formatted(RustTranslator.getTimeMinutesMessage(time)));
688654
}
689655

@@ -742,7 +708,7 @@ private void changeFullscreen(ActionEvent event) {
742708
dialog.setVisible(true);
743709
}
744710

745-
protected BorstData getBorstData() {
711+
public BorstData getBorstData() {
746712
return lastData;
747713
}
748714

@@ -754,7 +720,7 @@ public void onBorstCallback(BorstData data) {
754720
repaint();
755721

756722
if(data.isDone()) {
757-
btnPauseGenerate.setText("Pause Generate");
723+
btnPauseGenerate.setText(RustUI.getString(Type.ACTION_PAUSEGENERATE_ON));
758724
}
759725
}
760726

@@ -840,38 +806,43 @@ protected void paintComponent(Graphics gr) {
840806
}
841807
}
842808

843-
// TODO: Find a better way to draw these than crashing the application. xd
844-
try {
809+
810+
{
845811
BobRustPalette palette = drawDialog.getPalette();
846-
Map<BorstColor, Point> map = palette.getColorMap();
847-
848-
g.setColor(Color.white);
849-
Point screen = dialog.getLocationOnScreen();
850-
for(Map.Entry<BorstColor, Point> entry : map.entrySet()) {
851-
Point point = entry.getValue();
852-
Point sc = new Point(point.x - screen.x, point.y - screen.y);
853-
g.drawOval(sc.x - 15, sc.y - 15, 30, 29);
854-
}
855-
856-
for(int i = 0; i < 6; i++) {
857-
Point point = palette.getAlphaButton(i);
858-
Point sc = new Point(point.x - screen.x, point.y - screen.y);
859-
g.drawOval(sc.x - 10, sc.y - 10, 20, 20);
860-
}
861-
862-
for(int i = 0; i < 6; i++) {
863-
Point point = palette.getSizeButton(i);
864-
Point sc = new Point(point.x - screen.x, point.y - screen.y);
865-
g.drawOval(sc.x - 10, sc.y - 10, 20, 20);
866-
}
867-
868-
for(int i = 0; i < 4; i++) {
869-
Point point = palette.getShapeButton(i);
870-
Point sc = new Point(point.x - screen.x, point.y - screen.y);
871-
g.drawOval(sc.x - 15, sc.y - 15, 30, 29);
812+
if(palette.hasPalette()) {
813+
Map<BorstColor, Point> map = palette.getColorMap();
814+
815+
g.setColor(Color.white);
816+
Point screen = dialog.getLocationOnScreen();
817+
for(Map.Entry<BorstColor, Point> entry : map.entrySet()) {
818+
Point point = entry.getValue();
819+
Point sc = new Point(point.x - screen.x, point.y - screen.y);
820+
g.drawOval(sc.x - 15, sc.y - 15, 30, 29);
821+
}
822+
823+
// TODO: Find a better way to draw these than crashing the application. xd
824+
try {
825+
for(int i = 0; i < 6; i++) {
826+
Point point = palette.getAlphaButton(i);
827+
Point sc = new Point(point.x - screen.x, point.y - screen.y);
828+
g.drawOval(sc.x - 10, sc.y - 10, 20, 20);
829+
}
830+
831+
for(int i = 0; i < 6; i++) {
832+
Point point = palette.getSizeButton(i);
833+
Point sc = new Point(point.x - screen.x, point.y - screen.y);
834+
g.drawOval(sc.x - 10, sc.y - 10, 20, 20);
835+
}
836+
837+
for(int i = 0; i < 4; i++) {
838+
Point point = palette.getShapeButton(i);
839+
Point sc = new Point(point.x - screen.x, point.y - screen.y);
840+
g.drawOval(sc.x - 15, sc.y - 15, 30, 29);
841+
}
842+
} catch(Exception e) {
843+
e.printStackTrace();
844+
}
872845
}
873-
} catch(Exception e) {
874-
875846
}
876847
}
877848
}

0 commit comments

Comments
 (0)