23
23
import com .bobrust .gui .comp .JRandomPanel ;
24
24
import com .bobrust .gui .comp .JStyledButton ;
25
25
import com .bobrust .gui .comp .JStyledToggleButton ;
26
+ import com .bobrust .gui .dialog .BobRustDrawDialog ;
27
+ import com .bobrust .gui .dialog .BobRustMonitorPicker ;
26
28
import com .bobrust .lang .RustTranslator ;
27
29
import com .bobrust .lang .RustUI ;
28
30
import com .bobrust .lang .RustUI .Type ;
@@ -101,100 +103,64 @@ public class BobRustOverlay extends JPanel {
101
103
public void mousePressed (MouseEvent e ) {
102
104
isToolbarArea = e .getX () < 137 - RECTANGLE_SELECTION_SIZE ;
103
105
if (isToolbarArea ) {
104
- // If the point is in the action panel we should not compute anything
105
106
return ;
106
107
}
107
108
108
109
originPoint = new Point (e .getPoint ());
109
110
if (originPoint .x < 137 ) {
110
111
originPoint .x = 137 ;
111
112
}
112
- if (action == OverlayType .SELECT_CANVAS_REGION ) rectangle = canvasRegion ;
113
- if (action == OverlayType .SELECT_IMAGE_REGION ) rectangle = imageRegion ;
114
113
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 ());
153
116
}
154
117
118
+ @ Override
155
119
public void mouseMoved (MouseEvent e ) {
156
120
if (isToolbarArea ) {
157
121
return ;
158
122
}
159
123
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
+ }
162
137
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 );
196
163
}
197
- default -> {}
198
164
}
199
165
}
200
166
@@ -364,7 +330,7 @@ public void windowClosing(WindowEvent e) {
364
330
});
365
331
366
332
btnMaximize = new JStyledButton (RustUI .getString (Type .ACTION_MAKEFULLSCREEN_ON ));
367
- btnMaximize .setMaximumSize (new Dimension ( 120 , 24 ) );
333
+ btnMaximize .setMaximumSize (buttonSize );
368
334
btnMaximize .addActionListener (this ::changeFullscreen );
369
335
actionPanel .add (btnMaximize );
370
336
actionPanel .add (btnSelectMonitor );
@@ -397,7 +363,7 @@ public void windowClosing(WindowEvent e) {
397
363
labels .add (lblRegions );
398
364
399
365
btnHideRegions = new JStyledToggleButton (RustUI .getString (Type .ACTION_SHOWREGIONS_ON ));
400
- btnHideRegions .setMaximumSize (new Dimension ( 120 , 24 ) );
366
+ btnHideRegions .setMaximumSize (buttonSize );
401
367
btnHideRegions .setSelected (true );
402
368
btnHideRegions .addActionListener ((event ) -> setHideRegions (btnHideRegions .isSelected ()));
403
369
regionsPanel .add (btnHideRegions );
@@ -455,7 +421,7 @@ public void windowClosing(WindowEvent e) {
455
421
previewPanel .add (btnPauseGenerate );
456
422
457
423
btnResetGenerate = new JStyledButton (RustUI .getString (Type .ACTION_RESETGENERATE_BUTTON ));
458
- btnResetGenerate .setMaximumSize (new Dimension ( 120 , 24 ) );
424
+ btnResetGenerate .setMaximumSize (buttonSize );
459
425
btnResetGenerate .setEnabled (false );
460
426
btnResetGenerate .addActionListener ((event ) -> resetGeneration ());
461
427
previewPanel .add (btnResetGenerate );
@@ -490,7 +456,7 @@ public void windowClosing(WindowEvent e) {
490
456
labels .add (lblPaintImage );
491
457
492
458
btnDrawImage = new JStyledButton (RustUI .getString (Type .ACTION_DRAWIMAGE_BUTTON ));
493
- btnDrawImage .setMaximumSize (new Dimension ( 120 , 24 ) );
459
+ btnDrawImage .setMaximumSize (buttonSize );
494
460
btnDrawImage .setEnabled (false );
495
461
btnDrawImage .addActionListener ((event ) -> {
496
462
drawDialog .openDialog (btnDrawImage .getLocationOnScreen ());
@@ -518,17 +484,17 @@ public void windowClosing(WindowEvent e) {
518
484
labels .add (lblHelp );
519
485
520
486
JStyledButton btnGithubIssue = new JStyledButton (RustUI .getString (Type .ACTION_REPORTISSUE_BUTTON ));
521
- btnGithubIssue .setMaximumSize (new Dimension ( 120 , 24 ) );
487
+ btnGithubIssue .setMaximumSize (buttonSize );
522
488
btnGithubIssue .addActionListener ((event ) -> UrlUtils .openIssueUrl ());
523
489
actionPanel .add (btnGithubIssue );
524
490
525
491
JStyledButton btnDonate = new JStyledButton (RustUI .getString (Type .ACTION_DONATE_BUTTON ));
526
- btnDonate .setMaximumSize (new Dimension ( 120 , 24 ) );
492
+ btnDonate .setMaximumSize (buttonSize );
527
493
btnDonate .addActionListener ((event ) -> UrlUtils .openDonationUrl ());
528
494
actionPanel .add (btnDonate );
529
495
530
496
JStyledButton btnAbout = new JStyledButton (RustUI .getString (Type .ACTION_ABOUT_BUTTON ));
531
- btnAbout .setMaximumSize (new Dimension ( 120 , 24 ) );
497
+ btnAbout .setMaximumSize (buttonSize );
532
498
btnAbout .addActionListener ((event ) -> {
533
499
String message = "Created by HardCoded & Sekwah41\n " +
534
500
"\n " +
@@ -623,7 +589,7 @@ private void resetGeneration() {
623
589
}
624
590
}
625
591
626
- protected void setHideRegions (boolean enable ) {
592
+ public void setHideRegions (boolean enable ) {
627
593
if (enable ) {
628
594
btnHideRegions .setText (RustUI .getString (Type .ACTION_SHOWREGIONS_ON ));
629
595
} else {
@@ -649,11 +615,11 @@ private void setPauseGeneration(boolean enable) {
649
615
}
650
616
651
617
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 ());
654
620
655
621
for (JLabel label : labels ) {
656
- label .setForeground (gui .getLabelColor ());
622
+ label .setForeground (gui .getEditorLabelColor ());
657
623
}
658
624
659
625
generationLabel .setLocation ((topBarPanel .getWidth () - generationLabel .getWidth ()) / 2 , generationLabel .getY ());
@@ -677,13 +643,13 @@ public Rectangle getScreenLocation() {
677
643
return monitorPicker .getMonitor ().getBounds ();
678
644
}
679
645
680
- protected void setEstimatedGenerationLabel (int index , int maxShapes ) {
646
+ public void setEstimatedGenerationLabel (int index , int maxShapes ) {
681
647
generationLabel .setText ("%d/%d shapes generated" .formatted (index , maxShapes ));
682
648
long time = (long )(index * 1.1 * (ESTIMATE_DELAY_OFFSET + 1000.0 / (double )gui .getSettingsClickInterval ()));
683
649
generationInfo .setText ("Estimated %s" .formatted (RustTranslator .getTimeMinutesMessage (time )));
684
650
}
685
651
686
- protected void setExactGenerationLabel (long time ) {
652
+ public void setExactGenerationLabel (long time ) {
687
653
generationInfo .setText ("Time %s" .formatted (RustTranslator .getTimeMinutesMessage (time )));
688
654
}
689
655
@@ -742,7 +708,7 @@ private void changeFullscreen(ActionEvent event) {
742
708
dialog .setVisible (true );
743
709
}
744
710
745
- protected BorstData getBorstData () {
711
+ public BorstData getBorstData () {
746
712
return lastData ;
747
713
}
748
714
@@ -754,7 +720,7 @@ public void onBorstCallback(BorstData data) {
754
720
repaint ();
755
721
756
722
if (data .isDone ()) {
757
- btnPauseGenerate .setText ("Pause Generate" );
723
+ btnPauseGenerate .setText (RustUI . getString ( Type . ACTION_PAUSEGENERATE_ON ) );
758
724
}
759
725
}
760
726
@@ -840,38 +806,43 @@ protected void paintComponent(Graphics gr) {
840
806
}
841
807
}
842
808
843
- // TODO: Find a better way to draw these than crashing the application. xd
844
- try {
809
+
810
+ {
845
811
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
+ }
872
845
}
873
- } catch (Exception e ) {
874
-
875
846
}
876
847
}
877
848
}
0 commit comments