diff --git a/src/main/resources/ocelot/desktop/colorscheme.txt b/src/main/resources/ocelot/desktop/colorscheme.txt index afeea4d..be0868d 100644 --- a/src/main/resources/ocelot/desktop/colorscheme.txt +++ b/src/main/resources/ocelot/desktop/colorscheme.txt @@ -58,10 +58,13 @@ TextInputForeground = #333333 TextInputBorderError = #aa8888 TextInputBorderErrorFocused = #cc6666 -ButtonBackground = #aaaaaa -ButtonBorder = #888888 -ButtonForeground = #333333 -ButtonConfirm = #336633 +ButtonBackground = #aaaaaa +ButtonBorder = #888888 +ButtonForeground = #333333 +ButtonBackgroundDisabled = #333333 +ButtonBorderDisabled = #666666 +ButtonForegroundDisabled = #888888 +ButtonConfirm = #336633 BottomDrawerBorder = #888888 diff --git a/src/main/scala/ocelot/desktop/ui/widget/Button.scala b/src/main/scala/ocelot/desktop/ui/widget/Button.scala index 350ad7e..ee5dd38 100644 --- a/src/main/scala/ocelot/desktop/ui/widget/Button.scala +++ b/src/main/scala/ocelot/desktop/ui/widget/Button.scala @@ -11,26 +11,40 @@ import ocelot.desktop.util.DrawUtils class Button extends Widget with ClickHandler with ClickSoundSource { def text: String = "" + def onClick(): Unit = {} + def enabled: Boolean = true + override def receiveMouseEvents: Boolean = true eventHandlers += { - case ClickEvent(MouseEvent.Button.Left, _) => + case ClickEvent(MouseEvent.Button.Left, _) if enabled => onClick() clickSoundSource.play() } override def minimumSize: Size2D = Size2D(24 + text.length * 8, 24) + override def maximumSize: Size2D = minimumSize override def draw(g: Graphics): Unit = { - g.rect(bounds, ColorScheme("ButtonBackground")) - DrawUtils.ring(g, position.x, position.y, width, height, 2, ColorScheme("ButtonBorder")) + val (background, border, foreground) = if (enabled) ( + ColorScheme("ButtonBackground"), + ColorScheme("ButtonBorder"), + ColorScheme("ButtonForeground") + ) else ( + ColorScheme("ButtonBackgroundDisabled"), + ColorScheme("ButtonBorderDisabled"), + ColorScheme("ButtonForegroundDisabled") + ) + + g.rect(bounds, background) + DrawUtils.ring(g, position.x, position.y, width, height, 2, border) g.background = Color.Transparent - g.foreground = ColorScheme("ButtonForeground") + g.foreground = foreground val textWidth = text.iterator.map(g.font.charWidth(_)).sum g.text(position.x + ((width - textWidth) / 2).round, position.y + 4, text) } diff --git a/src/main/scala/ocelot/desktop/ui/widget/ChangeSimulationSpeedDialog.scala b/src/main/scala/ocelot/desktop/ui/widget/ChangeSimulationSpeedDialog.scala index dbbe63a..d81f630 100644 --- a/src/main/scala/ocelot/desktop/ui/widget/ChangeSimulationSpeedDialog.scala +++ b/src/main/scala/ocelot/desktop/ui/widget/ChangeSimulationSpeedDialog.scala @@ -91,10 +91,10 @@ class ChangeSimulationSpeedDialog() extends ModalDialog { override def onClick(): Unit = close() }, Padding2D(right = 8)) - // TODO: disable the button if tickInterval.isEmpty children :+= new Button { override def text: String = "Apply" override def onClick(): Unit = confirm() + override def enabled: Boolean = tickInterval.nonEmpty } } }, Padding2D.equal(16))