Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/kmcaster.git
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
final var switchState = new HardwareSwitchState(
hwSwitch, hwState, switchValue );
+
+ // Clear the text before redrawing to prevent discord between the
+ // label colour and the hardware switch's background.
+ if( switchState.isSwitchState( SWITCH_RELEASED ) ) {
+ getHardwareComponent( switchState ).removeAll();
+ }
+
updateSwitchState( switchState );
final var keyValue = state.getValue();
final var keyColour = KEY_COLOURS.get( state.getHardwareState() );
-
- if( state.isSwitchState( SWITCH_RELEASED ) ) {
- container.removeAll();
- }
if( state.isModifier() ) {
src/main/com/whitemagicsoftware/kmcaster/HardwareImages.java
import static com.whitemagicsoftware.kmcaster.HardwareSwitch.*;
import static com.whitemagicsoftware.kmcaster.exceptions.Rethrowable.rethrow;
+import static com.whitemagicsoftware.kmcaster.ui.Constants.APP_DIMENSIONS;
import static java.lang.String.format;
HardwareComponent<HardwareSwitchState, Image>
> mSwitches = new HashMap<>();
-
- /**
- * Images are scaled to these dimensions, maintaining aspect ratio. The
- * height constrains the width, so as long as the width is sufficiently
- * large, the application's window will adjust to fit.
- */
- private final Dimension mDimension = new Dimension( 1024, 90 );
public HardwareImages() {
try {
final var diagram = sRasterizer.loadDiagram( resource );
- final var scale = sRasterizer.calculateScale( diagram, mDimension );
- final var image = sRasterizer.rasterize( diagram, mDimension );
+ final var scale = sRasterizer.calculateScale( diagram, APP_DIMENSIONS );
+ final var image = sRasterizer.rasterize( diagram, APP_DIMENSIONS );
return new Pair<>( image, scale );
src/main/com/whitemagicsoftware/kmcaster/HardwareState.java
*/
SWITCH_PRESSED,
+
/**
* Defines when a hardware switch is up.
src/main/com/whitemagicsoftware/kmcaster/HardwareSwitch.java
}
+ // This could be thrown when a mouse button is pressed that does not have
+ // a visual representation.
throw new NoSuchElementException( name );
}
src/main/com/whitemagicsoftware/kmcaster/KmCaster.java
initWindowFrame();
initWindowContents();
- initListeners();
pack();
+ initListeners();
setVisible( true );
}
addNativeKeyListener( keyboardListener );
keyboardListener.addPropertyChangeListener( listener );
+ keyboardListener.initModifiers();
}
src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java
}
+ /**
+ * Unused. Key up and key down are tracked separately from a typed key.
+ *
+ * @param e Ignored.
+ */
@Override
public void nativeKeyTyped( final NativeKeyEvent e ) {
+ }
+
+ /**
+ * Sets the initial state of the modifiers.
+ */
+ public void initModifiers() {
+ for( final var key : mSwitches.keySet() ) {
+ final var state = mSwitches.get( key );
+
+ // By default, the keys are all "false", so fire fake events indicating
+ // that has one has just transitioned to "false". This will cause the
+ // GUI to repaint with the text label affixed to each key, drawn in the
+ // released state. This happens before the frame is set to visible.
+ tryFire( key, !state, state );
+ }
}
src/main/com/whitemagicsoftware/kmcaster/listeners/MouseListener.java
}
+ /**
+ * Unused.
+ *
+ * @param e Ignored.
+ */
public void nativeMouseClicked( final NativeMouseEvent e ) {
-// System.out.println( "Clicked # Times: " + e.getClickCount() );
-// System.out.println( "Button clicked: " + e.getButton() );
}
+ /**
+ * Unused.
+ *
+ * @param e Ignored.
+ */
public void nativeMouseMoved( final NativeMouseEvent e ) {
-// System.out.println( "Mouse Moved: " + e.getX() + ", " + e.getY() );
}
+ /**
+ * Unused.
+ *
+ * @param e Ignored.
+ */
public void nativeMouseDragged( final NativeMouseEvent e ) {
-// System.out.println( "Mouse Dragged: " + e.getX() + ", " + e.getY() );
}
}
src/main/com/whitemagicsoftware/kmcaster/ui/Constants.java
*/
public class Constants {
+ /**
+ * Use with {@code setOpaque( false )}.
+ */
public static final Color TRANSPARENT = new Color( 0, 0, 0, 0 );
+
+ /**
+ * Partially see-through.
+ */
public static final Color TRANSLUCENT = new Color( .2f, .2f, .2f, 0.5f );
+
+ /**
+ * Application dimensions in pixels. Images are scaled to these dimensions,
+ * maintaining aspect ratio. The height constrains the width, so as long as
+ * the width is sufficiently large, the application's window will adjust to
+ * fit.
+ */
+ public static final Dimension APP_DIMENSIONS = new Dimension( 1024, 90 );
/**
* Default insets, has no padding.
*/
- public final static Insets INSETS_EMPTY =
- new Insets( 0, 0, 0, 0 );
+ public final static Insets INSETS_EMPTY = new Insets( 0, 0, 0, 0 );
/**

Initialize modifier keys in the released state

Author DaveJarvis <email>
Date 2020-07-22 00:33:28 GMT-0700
Commit f9402e12b6236b93b99387778d7e4b11bda6fb05
Parent a18d2dc
Delta 66 lines added, 20 lines removed, 46-line increase