Fleshing out animation editor's code

This commit is contained in:
Maruno17
2023-10-23 22:36:43 +01:00
parent 7031698d85
commit 340983e765
14 changed files with 810 additions and 282 deletions

View File

@@ -10,7 +10,7 @@ class UIControls::BaseControl < BitmapSprite
# attr_accessor :disabled # TODO: Make use of this.
TEXT_COLOR = Color.black
TEXT_SIZE = 18 # Default is 22 if size isn't explicitly set
TEXT_SIZE = 18 # Default is 22 if size isn't explicitly set
HOVER_COLOR = Color.cyan # For clickable area when hovering over it
CAPTURE_COLOR = Color.pink # For area you clicked in but aren't hovering over

View File

@@ -5,7 +5,7 @@ class UIControls::Label < UIControls::BaseControl
attr_reader :label
LABEL_END_X = 80
TEXT_OFFSET_Y = 7
TEXT_OFFSET_Y = 5
def initialize(width, height, viewport, label)
super(width, height, viewport)

View File

@@ -10,7 +10,7 @@ class UIControls::TextBox < UIControls::BaseControl
TEXT_BOX_WIDTH = 172
TEXT_BOX_HEIGHT = 24
TEXT_BOX_PADDING = 4 # Gap between sides of text box and text
TEXT_OFFSET_Y = 7
TEXT_OFFSET_Y = 5
def initialize(width, height, viewport, value = "")
super(width, height, viewport)
@@ -201,6 +201,7 @@ class UIControls::TextBox < UIControls::BaseControl
@cursor_timer = System.uptime
invalidate
else
@value.strip! if @value.respond_to?("strip!")
set_changed if @initial_value && @value != @initial_value
reset_interaction
end
@@ -220,6 +221,7 @@ class UIControls::TextBox < UIControls::BaseControl
end
# Released mouse button outside of text box, or initially clicked outside of
# text box; end interaction with this control
@value.strip! if @value.respond_to?("strip!")
set_changed if @initial_value && @value != @initial_value
reset_interaction
super # Make this control not busy again
@@ -247,6 +249,7 @@ class UIControls::TextBox < UIControls::BaseControl
# Return/Escape to end text input (Escape undoes the change)
if Input.triggerex?(:RETURN) || Input.repeatex?(:RETURN) ||
Input.triggerex?(:KP_ENTER) || Input.repeatex?(:KP_ENTER)
@value.strip! if @value.respond_to?("strip!")
set_changed if @initial_value && @value != @initial_value
reset_interaction
@captured_area = nil

View File

@@ -13,7 +13,7 @@ class UIControls::Slider < UIControls::BaseControl
SLIDER_LENGTH = 128
PLUS_X = SLIDER_X + SLIDER_LENGTH + SLIDER_PADDING
VALUE_X = PLUS_X + PLUS_MINUS_SIZE + 5
TEXT_OFFSET_Y = 7
TEXT_OFFSET_Y = 5
# TODO: Is there a better knob design than a big black rectangle? I'd rather
# it not be a different colour.

View File

@@ -7,9 +7,9 @@
# through a line? Nah.
#===============================================================================
class UIControls::List < UIControls::BaseControl
LIST_X = 0
LIST_Y = 0
ROW_HEIGHT = 24
LIST_X = 0
LIST_Y = 0
ROW_HEIGHT = 24
TEXT_PADDING_X = 4
TEXT_OFFSET_Y = 3

View File

@@ -4,11 +4,14 @@
# seem to be any lag at the moment with a tall scrollbar.
#===============================================================================
class UIControls::Scrollbar < UIControls::BaseControl
SLIDER_WIDTH = 16
WIDTH_PADDING = 0
TRAY_COLOR = Color.white
SLIDER_COLOR = Color.black
GRAB_COLOR = HOVER_COLOR # Cyan
SLIDER_WIDTH = 16
WIDTH_PADDING = 0
SCROLL_DISTANCE = 16
TRAY_COLOR = Color.white
SLIDER_COLOR = Color.black
GRAB_COLOR = HOVER_COLOR # Cyan
attr_reader :slider_top
def initialize(x, y, size, viewport, horizontal = false, always_visible = false)
if horizontal
@@ -138,6 +141,16 @@ class UIControls::Scrollbar < UIControls::BaseControl
self.slider_top = @slider_top + ((@tray_size - @slider_size) / 4.0).ceil
end
end
else
mouse_x, mouse_y = mouse_pos
if mouse_x && mouse_y && @interactions[:slider_tray].contains?(mouse_x, mouse_y)
wheel_v = Input.scroll_v
if wheel_v > 0 # Scroll up
self.slider_top -= SCROLL_DISTANCE
elsif wheel_v < 0 # Scroll down
self.slider_top += SCROLL_DISTANCE
end
end
end
end
end