3
3
4
4
import cn .hutool .core .swing .ScreenUtil ;
5
5
import cn .hutool .log .StaticLog ;
6
- import com .luooqi .ocr .MainFm ;
7
6
import com .luooqi .ocr .model .CaptureInfo ;
8
7
import com .luooqi .ocr .utils .CommUtils ;
8
+ import com .luooqi .ocr .windows .MainForm ;
9
9
import javafx .animation .AnimationTimer ;
10
10
import javafx .application .Platform ;
11
11
import javafx .embed .swing .SwingFXUtils ;
@@ -180,8 +180,7 @@ public ScreenCapture(Stage mainStage) {
180
180
181
181
mainCanvas .setOnMouseDragged (m -> {
182
182
if (m .getButton () == MouseButton .PRIMARY ) {
183
- if (m .getScreenX () >= CaptureInfo .ScreenMinX &&
184
- m .getScreenX () <= CaptureInfo .ScreenMaxX ) {
183
+ if (m .getScreenX () >= CaptureInfo .ScreenMinX && m .getScreenX () <= CaptureInfo .ScreenMaxX ) {
185
184
data .mouseXNow = (int ) m .getX ();
186
185
} else if (m .getScreenX () > CaptureInfo .ScreenMaxX ) {
187
186
data .mouseXNow = CaptureInfo .ScreenWidth ;
@@ -311,8 +310,7 @@ private void addKeyHandlers() {
311
310
}
312
311
});
313
312
314
- data .anyPressed .addListener ((obs , wasPressed , isNowPressed ) ->
315
- {
313
+ data .anyPressed .addListener ((obs , wasPressed , isNowPressed ) -> {
316
314
if (isNowPressed ) {
317
315
yPressedAnimation .start ();
318
316
} else {
@@ -370,15 +368,17 @@ private void repaintCanvas() {
370
368
: data .mouseYNow // UP
371
369
;
372
370
373
- gc .strokeRect (data .rectUpperLeftX - 1.00 , data .rectUpperLeftY - 1.00 , data .rectWidth + 2.00 , data .rectHeight + 2.00 );
371
+ gc .strokeRect (data .rectUpperLeftX - 1.00 , data .rectUpperLeftY - 1.00 , data .rectWidth + 2.00 ,
372
+ data .rectHeight + 2.00 );
374
373
gc .clearRect (data .rectUpperLeftX , data .rectUpperLeftY , data .rectWidth , data .rectHeight );
375
374
376
375
// draw the text
377
376
if (!data .hideExtraFeatures .getValue () && (data .rectWidth > 0 || data .rectHeight > 0 )) {
378
377
double middle = data .rectUpperLeftX + data .rectWidth / 2.00 ;
379
378
gc .setLineWidth (1 );
380
379
gc .setFill (Color .FIREBRICK );
381
- gc .fillRect (middle - 77 , data .rectUpperLeftY < 50 ? data .rectUpperLeftY + 2 : data .rectUpperLeftY - 18.00 , 100 , 18 );
380
+ gc .fillRect (middle - 77 , data .rectUpperLeftY < 50 ? data .rectUpperLeftY + 2 : data .rectUpperLeftY - 18.00 , 100 ,
381
+ 18 );
382
382
gc .setFill (Color .WHITE );
383
383
gc .fillText (data .rectWidth + " * " + data .rectHeight , middle - 77 + 9 ,
384
384
data .rectUpperLeftY < 50 ? data .rectUpperLeftY + 17.00 : data .rectUpperLeftY - 4.00 );
@@ -398,16 +398,16 @@ private void selectWholeScreen() {
398
398
399
399
public void prepareForCapture () {
400
400
isSnapping = true ;
401
- MainFm .stage .setOpacity (0.0f );
401
+ MainForm .stage .setOpacity (0.0f );
402
402
Platform .runLater (() -> {
403
- Rectangle rectangle = CommUtils .getDisplayScreen (MainFm .stage );
403
+ Rectangle rectangle = CommUtils .getDisplayScreen (MainForm .stage );
404
404
data .reset ();
405
405
CaptureInfo .ScreenMinX = rectangle .x ;
406
406
CaptureInfo .ScreenMaxX = rectangle .x + rectangle .width ;
407
407
CaptureInfo .ScreenWidth = rectangle .width ;
408
408
CaptureInfo .ScreenHeight = rectangle .height ;
409
409
BufferedImage bufferedImage = ScreenUtil .captureScreen (rectangle );
410
- //bufferedImage = Scalr.resize(bufferedImage, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, CaptureInfo.ScreenWidth * 2, CaptureInfo.ScreenHeight * 2);
410
+ // bufferedImage = Scalr.resize(bufferedImage, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, CaptureInfo.ScreenWidth * 2, CaptureInfo.ScreenHeight * 2);
411
411
WritableImage fxImage = SwingFXUtils .toFXImage (bufferedImage , null );
412
412
deActivateAllKeys ();
413
413
scene .setRoot (new Pane ());
@@ -417,9 +417,9 @@ public void prepareForCapture() {
417
417
mainCanvas .setHeight (CaptureInfo .ScreenHeight );
418
418
mainCanvas .setCursor (Cursor .CROSSHAIR );
419
419
initGraphContent ();
420
- rootPane .setBackground (new Background (new BackgroundImage (fxImage ,
421
- BackgroundRepeat .NO_REPEAT , BackgroundRepeat . NO_REPEAT ,
422
- BackgroundPosition . CENTER , new BackgroundSize (CaptureInfo .ScreenWidth , CaptureInfo .ScreenHeight , false , false , true , true ))));
420
+ rootPane .setBackground (new Background (new BackgroundImage (fxImage , BackgroundRepeat . NO_REPEAT ,
421
+ BackgroundRepeat .NO_REPEAT , BackgroundPosition . CENTER ,
422
+ new BackgroundSize (CaptureInfo .ScreenWidth , CaptureInfo .ScreenHeight , false , false , true , true ))));
423
423
repaintCanvas ();
424
424
stage .setScene (scene );
425
425
stage .setFullScreenExitHint ("" );
@@ -438,19 +438,21 @@ private void prepareImage() {
438
438
BufferedImage image ;
439
439
try {
440
440
mainCanvas .setDisable (true );
441
- image = new Robot ().createScreenCapture (new Rectangle (data .rectUpperLeftX + CaptureInfo .ScreenMinX , data .rectUpperLeftY + (int ) CommUtils .getCrtScreen (stage ).getVisualBounds ().getMinY (), data .rectWidth , data .rectHeight ));
441
+ image = new Robot ().createScreenCapture (new Rectangle (data .rectUpperLeftX + CaptureInfo .ScreenMinX ,
442
+ data .rectUpperLeftY + (int ) CommUtils .getCrtScreen (stage ).getVisualBounds ().getMinY (), data .rectWidth ,
443
+ data .rectHeight ));
442
444
} catch (AWTException ex ) {
443
445
StaticLog .error (ex );
444
446
return ;
445
447
} finally {
446
448
mainCanvas .setDisable (false );
447
- MainFm .restore (false );
449
+ MainForm .restore (false );
448
450
}
449
- MainFm .doOcr (image );
451
+ MainForm .doOcr (image );
450
452
}
451
453
452
454
public void cancelSnap () {
453
455
deActivateAllKeys ();
454
- MainFm .restore (true );
456
+ MainForm .restore (true );
455
457
}
456
458
}
0 commit comments