()
| 800 | } |
| 801 | |
| 802 | func (button *Button) Update() { |
| 803 | |
| 804 | mousePos := globals.Mouse.Position() |
| 805 | |
| 806 | if button.WorldSpace { |
| 807 | mousePos = globals.Mouse.WorldPosition() |
| 808 | } |
| 809 | |
| 810 | alphaTarget := float32(1) |
| 811 | lineTarget := float32(1) |
| 812 | |
| 813 | buttonRect := button.Rectangle() |
| 814 | |
| 815 | if mousePos.Inside(buttonRect) && !button.Disabled && (globals.Mouse.CurrentCursor == CursorNormal || globals.State == StateCardLink) { |
| 816 | |
| 817 | if globals.Mouse.Button(sdl.BUTTON_LEFT).Pressed() && (globals.State == StateNeutral || globals.State == StateCardLink || globals.State == StateContextMenu || globals.State == StateMapEditing || globals.State == StateTextEditing) { |
| 818 | if button.OnPressed != nil { |
| 819 | |
| 820 | PlayUISound(UISoundTypeTap) |
| 821 | |
| 822 | globals.Mouse.Button(sdl.BUTTON_LEFT).Consume() |
| 823 | button.OnPressed() |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | } else if button.FadeOnInactive { |
| 828 | alphaTarget = 0.7 |
| 829 | lineTarget = 0 |
| 830 | } |
| 831 | |
| 832 | if button.Disabled { |
| 833 | alphaTarget = 0.3 |
| 834 | } |
| 835 | |
| 836 | button.Label.Alpha += ((alphaTarget - button.Label.Alpha) * 0.1) |
| 837 | button.LineWidth += (lineTarget - button.LineWidth) * 0.2 |
| 838 | |
| 839 | if len(button.Label.Text) > 0 { |
| 840 | button.Label.Update() |
| 841 | } |
| 842 | |
| 843 | } |
| 844 | |
| 845 | func (button *Button) Draw() { |
| 846 |
nothing calls this directly
no test coverage detected