mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Add hover animation to icon buttons
This commit is contained in:
parent
7a255ec631
commit
73d41071ee
@ -91,25 +91,17 @@ class DiskEditWindow(item: DiskItem) extends PanelWindow {
|
|||||||
model = IconButton.ReadOnlyModel(isColorSelected),
|
model = IconButton.ReadOnlyModel(isColorSelected),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
private val backgroundAnimation = new ColorAnimation(targetBackgroundColor, IconButton.AnimationSpeed)
|
|
||||||
private val borderAnimation = new ColorAnimation(targetBorderColor, IconButton.AnimationSpeed)
|
private val borderAnimation = new ColorAnimation(targetBorderColor, IconButton.AnimationSpeed)
|
||||||
|
|
||||||
private def targetBackgroundColor: Color =
|
|
||||||
if (isColorSelected) ColorScheme("FloppyIconButtonBackgroundSelected")
|
|
||||||
else ColorScheme("ButtonBackground")
|
|
||||||
|
|
||||||
private def targetBorderColor: Color =
|
private def targetBorderColor: Color =
|
||||||
if (isColorSelected) ColorScheme("FloppyIconButtonBorderSelected")
|
if (isColorSelected) ColorScheme("FloppyIconButtonBorderSelected")
|
||||||
else ColorScheme("ButtonBorder")
|
else ColorScheme("ButtonBorder")
|
||||||
|
|
||||||
override protected def updateAnimationTargets(): Unit = {
|
override protected def updateAnimationTargets(): Unit = {
|
||||||
super.updateAnimationTargets()
|
super.updateAnimationTargets()
|
||||||
backgroundAnimation.goto(targetBackgroundColor)
|
|
||||||
borderAnimation.goto(targetBorderColor)
|
borderAnimation.goto(targetBorderColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def backgroundColor: Color = backgroundAnimation.color
|
|
||||||
|
|
||||||
override def borderColor: Color = borderAnimation.color
|
override def borderColor: Color = borderAnimation.color
|
||||||
|
|
||||||
override def onPressed(): Unit = {
|
override def onPressed(): Unit = {
|
||||||
@ -120,7 +112,6 @@ class DiskEditWindow(item: DiskItem) extends PanelWindow {
|
|||||||
|
|
||||||
override def update(): Unit = {
|
override def update(): Unit = {
|
||||||
super.update()
|
super.update()
|
||||||
backgroundAnimation.update()
|
|
||||||
borderAnimation.update()
|
borderAnimation.update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,11 +8,12 @@ import ocelot.desktop.graphics.Graphics
|
|||||||
import ocelot.desktop.ui.event.handlers.{ClickHandler, HoverHandler}
|
import ocelot.desktop.ui.event.handlers.{ClickHandler, HoverHandler}
|
||||||
import ocelot.desktop.ui.event.{HoverEvent, MouseEvent}
|
import ocelot.desktop.ui.event.{HoverEvent, MouseEvent}
|
||||||
import ocelot.desktop.ui.widget.IconButton.{AnimationSpeed, Mode}
|
import ocelot.desktop.ui.widget.IconButton.{AnimationSpeed, Mode}
|
||||||
|
import ocelot.desktop.ui.widget.`trait`.HoverAnimation
|
||||||
import ocelot.desktop.ui.widget.tooltip.LabelTooltip
|
import ocelot.desktop.ui.widget.tooltip.LabelTooltip
|
||||||
import ocelot.desktop.util.animation.{ColorAnimation, ValueAnimation}
|
import ocelot.desktop.util.animation.{ColorAnimation, ValueAnimation}
|
||||||
import ocelot.desktop.util.{DrawUtils, Spritesheet}
|
import ocelot.desktop.util.{DrawUtils, Spritesheet}
|
||||||
|
|
||||||
class IconButton(
|
class IconButton (
|
||||||
releasedIcon: String,
|
releasedIcon: String,
|
||||||
pressedIcon: String,
|
pressedIcon: String,
|
||||||
releasedColor: Color = Color.White,
|
releasedColor: Color = Color.White,
|
||||||
@ -26,8 +27,9 @@ class IconButton(
|
|||||||
) extends Widget
|
) extends Widget
|
||||||
with ClickHandler
|
with ClickHandler
|
||||||
with HoverHandler
|
with HoverHandler
|
||||||
with ClickSoundSource {
|
with HoverAnimation
|
||||||
|
with ClickSoundSource
|
||||||
|
{
|
||||||
override def receiveMouseEvents = true
|
override def receiveMouseEvents = true
|
||||||
|
|
||||||
private var prevModelValue = model.pressed
|
private var prevModelValue = model.pressed
|
||||||
@ -96,12 +98,11 @@ class IconButton(
|
|||||||
|
|
||||||
private val labelTooltip = tooltip.map(label => new LabelTooltip(label))
|
private val labelTooltip = tooltip.map(label => new LabelTooltip(label))
|
||||||
|
|
||||||
def backgroundColor: Color = ColorScheme("ButtonBackground")
|
|
||||||
def borderColor: Color = ColorScheme("ButtonBorder")
|
def borderColor: Color = ColorScheme("ButtonBorder")
|
||||||
|
|
||||||
override def draw(g: Graphics): Unit = {
|
override def draw(g: Graphics): Unit = {
|
||||||
if (drawBackground) {
|
if (drawBackground) {
|
||||||
g.rect(bounds, backgroundColor)
|
g.rect(bounds, hoverAnimation.color)
|
||||||
DrawUtils.ring(g, position.x, position.y, width, height, 2, borderColor)
|
DrawUtils.ring(g, position.x, position.y, width, height, 2, borderColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user