| Author | DaveJarvis <email> |
|---|---|
| Date | 2020-07-19 21:04:50 GMT-0700 |
| Commit | d4dc956880ab3e74594eed2d733f2a37994ec639 |
| Parent | 897e2e5 |
| /** | ||
| - * Available space on the image for drawing. This | ||
| + * Available space on the image for drawing. | ||
| */ | ||
| private final Insets mInsets; |
| private final static String DIR_IMAGES_MOUSE = DIR_IMAGES + "/mouse"; | ||
| + private final static Map<HardwareSwitch, String> FILE_NAME_PREFIXES = Map.of( | ||
| + KEY_ALT, "medium", | ||
| + KEY_CTRL, "medium", | ||
| + KEY_SHIFT, "long", | ||
| + KEY_REGULAR, "short" | ||
| + ); | ||
| + | ||
| private final static SvgRasterizer sRasterizer = new SvgRasterizer(); | ||
| mouseStates.put( state( MOUSE, FALSE.toString() ), mouseImage( "0" ) ); | ||
| mSwitches.put( MOUSE, mouseStates ); | ||
| - | ||
| - final var fileNamePrefixes = Map.of( | ||
| - KEY_ALT, "medium", | ||
| - KEY_CTRL, "medium", | ||
| - KEY_SHIFT, "long", | ||
| - KEY_REGULAR, "short" | ||
| - ); | ||
| for( final var key : HardwareSwitch.keyboardKeys() ) { | ||
| - final var hardwareComponent = createHardwareComponent(); | ||
| final var stateNameOn = key == KEY_REGULAR ? ANY_KEY : TRUE.toString(); | ||
| final var stateOn = state( key, stateNameOn ); | ||
| final var stateOff = state( key, FALSE.toString() ); | ||
| - final var imageDn = keyDnImage( fileNamePrefixes.get( key ) ); | ||
| - final var imageUp = keyUpImage( fileNamePrefixes.get( key ) ); | ||
| + final var imageDn = keyDnImage( FILE_NAME_PREFIXES.get( key ) ); | ||
| + final var imageUp = keyUpImage( FILE_NAME_PREFIXES.get( key ) ); | ||
| + final var scale = imageDn.getValue(); | ||
| + | ||
| + final var insets = KeyCapInsets.scale( scale ); | ||
| + final var hardwareComponent = createHardwareComponent( insets ); | ||
| hardwareComponent.put( stateOn, imageDn.getKey() ); | ||
| private HardwareComponent<HardwareState, Image> createHardwareComponent() { | ||
| return new HardwareComponent<>(); | ||
| + } | ||
| + | ||
| + private HardwareComponent<HardwareState, Image> createHardwareComponent( | ||
| + final Insets insets ) { | ||
| + return new HardwareComponent<>( insets ); | ||
| } | ||
| * keyboard modifier keys, not mouse buttons. | ||
| * | ||
| - * @param modifiers A set of bits that indicate what modifier keys are | ||
| - * pressed. | ||
| + * @param modifiers Bit set that indicates what modifier keys are pressed. | ||
| * @return {@code true} if this switch's modifier bit is set in the | ||
| * given {@code modifiers} value. | ||
| return mName; | ||
| } | ||
| - | ||
| } | ||
| package com.whitemagicsoftware.kmcaster; | ||
| +import com.whitemagicsoftware.kmcaster.ui.DimensionTuple; | ||
| + | ||
| import java.awt.*; | ||
| -import java.util.Map; | ||
| /** | ||
| * Scales the image insets and padding. | ||
| */ | ||
| - public static Insets scaleInsets( final Map.Entry<Dimension, Dimension> factor ) { | ||
| - final var srcDim = factor.getKey(); | ||
| - final var dstDim = factor.getValue(); | ||
| - final var wRatio = srcDim.getWidth() / dstDim.getWidth(); | ||
| - final var hRatio = srcDim.getHeight() / dstDim.getHeight(); | ||
| - | ||
| - return scale( wRatio, hRatio ); | ||
| - } | ||
| + public static Insets scale( final DimensionTuple factor ) { | ||
| + final var wRatio = factor.getWidthRatio(); | ||
| + final var hRatio = factor.getHeightRatio(); | ||
| - private static Insets scale( final double wScale, final double hScale ) { | ||
| return new Insets( | ||
| - (int) (INSET_TOTAL.top * hScale), | ||
| - (int) (INSET_TOTAL.left * wScale), | ||
| - (int) (INSET_TOTAL.bottom * hScale), | ||
| - (int) (INSET_TOTAL.right * wScale) ); | ||
| + (int) (INSET_TOTAL.top * hRatio), | ||
| + (int) (INSET_TOTAL.left * wRatio), | ||
| + (int) (INSET_TOTAL.bottom * hRatio), | ||
| + (int) (INSET_TOTAL.right * wRatio) ); | ||
| } | ||
| } | ||
| /** | ||
| - * Delegates construction to this class. | ||
| - * | ||
| - * @param w The width, cast to an integer. | ||
| - * @param h The height, cast to an integer. | ||
| - */ | ||
| - @SuppressWarnings("unused") | ||
| - public ScalableDimension( final double w, final double h ) { | ||
| - this( (int) w, (int) h ); | ||
| - } | ||
| - | ||
| - /** | ||
| * Scales the given source {@link Dimension} to the destination | ||
| * {@link Dimension}, maintaining the aspect ratio with respect to | ||
| // Scale both dimensions with respect to the best fit ratio. | ||
| - return new ScalableDimension( (int) (srcWidth * ratio), | ||
| - (int) (srcHeight * ratio) ); | ||
| + return new Dimension( (int) (srcWidth * ratio), (int) (srcHeight * ratio) ); | ||
| } | ||
| } | ||
| Delta | 30 lines added, 41 lines removed, 11-line decrease |
|---|