forked from UltimateBoomer/Resolution-Control
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add _N suffix to additional screenshots taken within 1 second
- Loading branch information
1 parent
72ec866
commit fefa4ce
Showing
5 changed files
with
64 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/main/java/io/github/ultimateboomer/resolutioncontrol/util/RCMathUtil.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/main/java/io/github/ultimateboomer/resolutioncontrol/util/RCUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github.ultimateboomer.resolutioncontrol.util; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.text.DateFormat; | ||
import java.text.NumberFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public final class RCUtil { | ||
private static final String[] UNITS = "KMGTPE".split(""); | ||
private static final NumberFormat FORMAT = NumberFormat.getNumberInstance(); | ||
|
||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss"); | ||
|
||
/** | ||
* Format number with metric conversion (K, M, G etc) | ||
*/ | ||
public static String formatMetric(long n) { | ||
if (n < 1000) { | ||
return n + " "; | ||
} | ||
|
||
int log10 = (int) Math.log10(n); | ||
int decimalPlace = (int) Math.pow(10, 2 - log10 % 3); | ||
int displayDigits = (int) (n / Math.pow(10, log10 - 2)); | ||
|
||
float result = (float) displayDigits / decimalPlace; | ||
return String.format("%s %s", FORMAT.format(result), UNITS[log10 / 3 - 1]); | ||
} | ||
|
||
public static File getScreenshotFilename(File directory) { | ||
String string = DATE_FORMAT.format(new Date()); | ||
int i = 1; | ||
|
||
while (true) { | ||
File file = new File(directory, string + (i == 1 ? "" : "_" + i) + ".png"); | ||
if (!file.exists()) { | ||
try { | ||
file.createNewFile(); | ||
} catch (IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
return file; | ||
} | ||
|
||
++i; | ||
} | ||
} | ||
} |