Anim Editor: added FoeFlip property, Space to play, S to swap sides, P to show/hide property lines for selected particle

This commit is contained in:
Maruno17
2024-04-18 22:35:15 +01:00
parent 15033d6114
commit 4480def33c
23 changed files with 264 additions and 161 deletions

View File

@@ -24,6 +24,8 @@ class UIControls::BaseControl < BitmapSprite
invalidate
end
#-----------------------------------------------------------------------------
def width
return self.bitmap.width
end
@@ -32,6 +34,8 @@ class UIControls::BaseControl < BitmapSprite
return self.bitmap.height
end
#-----------------------------------------------------------------------------
def mouse_pos
mouse_coords = Mouse.getMousePos
return nil, nil if !mouse_coords
@@ -40,10 +44,6 @@ class UIControls::BaseControl < BitmapSprite
return ret_x, ret_y
end
def set_interactive_rects
@interactions = {}
end
def mouse_in_control?
return false if !@interactions || @interactions.empty?
mouse_x, mouse_y = mouse_pos
@@ -51,8 +51,6 @@ class UIControls::BaseControl < BitmapSprite
return @interactions.any? { |area, rect| rect.contains?(mouse_x, mouse_y) }
end
#-----------------------------------------------------------------------------
def disabled?
return @disabled
end
@@ -102,6 +100,12 @@ class UIControls::BaseControl < BitmapSprite
#-----------------------------------------------------------------------------
def set_interactive_rects
@interactions = {}
end
#-----------------------------------------------------------------------------
def draw_text(this_bitmap, text_x, text_y, this_text)
text_size = this_bitmap.text_size(this_text)
this_bitmap.draw_text(text_x, text_y, text_size.width, text_size.height, this_text, 0)

View File

@@ -10,6 +10,8 @@ class UIControls::Label < UIControls::BaseControl
@header = false
end
#-----------------------------------------------------------------------------
def text=(value)
@text = value
refresh
@@ -24,6 +26,8 @@ class UIControls::Label < UIControls::BaseControl
return self.bitmap.text_size(@text).width
end
#-----------------------------------------------------------------------------
def refresh
super
if @header

View File

@@ -6,21 +6,24 @@ class UIControls::Checkbox < UIControls::BaseControl
CHECKBOX_WIDTH = 40
CHECKBOX_HEIGHT = 24
CHECKBOX_FILL_SIZE = CHECKBOX_HEIGHT - 4
UNCHECKED_COLOR = Color.gray
CHECKED_COLOR = Color.new(48, 192, 48) # Darkish green
UNCHECKED_COLOR = Color.gray
CHECKED_COLOR = Color.new(48, 192, 48) # Darkish green
def initialize(width, height, viewport, value = false)
super(width, height, viewport)
@value = value
end
#-----------------------------------------------------------------------------
def value=(new_value)
return if @value == new_value
@value = new_value
invalidate
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@checkbox_rect = Rect.new(CHECKBOX_X, (height - CHECKBOX_HEIGHT) / 2,
CHECKBOX_WIDTH, CHECKBOX_HEIGHT)

View File

@@ -20,6 +20,8 @@ class UIControls::TextBox < UIControls::BaseControl
@blacklist = []
end
#-----------------------------------------------------------------------------
def value
return @value.dup
end
@@ -60,36 +62,6 @@ class UIControls::TextBox < UIControls::BaseControl
invalidate
end
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:text_box => @text_box_rect
}
end
#-----------------------------------------------------------------------------
def disabled?
val = (@value.respond_to?("strip!")) ? @value.strip : @value
return true if @blacklist.include?(val)
return super
end
def busy?
return @cursor_pos >= 0 if @captured_area == :text_box
return super
end
def reset_interaction
@cursor_pos = -1
@display_pos = 0
@cursor_timer = nil
@initial_value = nil
Input.text_input = false
invalidate
end
#-----------------------------------------------------------------------------
def get_cursor_index_from_mouse_position
@@ -107,6 +79,36 @@ class UIControls::TextBox < UIControls::BaseControl
return @value.to_s.length
end
def disabled?
val = (@value.respond_to?("strip!")) ? @value.strip : @value
return true if @blacklist.include?(val)
return super
end
def busy?
return @cursor_pos >= 0 if @captured_area == :text_box
return super
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:text_box => @text_box_rect
}
end
def reset_interaction
@cursor_pos = -1
@display_pos = 0
@cursor_timer = nil
@initial_value = nil
Input.text_input = false
invalidate
end
def reset_display_pos
box_width = @text_box_rect.width - (TEXT_BOX_PADDING * 2)
char_widths = []

View File

@@ -7,12 +7,11 @@ class UIControls::NumberSlider < UIControls::BaseControl
PLUS_MINUS_SIZE = 16
SLIDER_PADDING = 6 # Gap between sides of interactive area for slider and drawn slider bar
MINUS_X = 0
SLIDER_X = MINUS_X + PLUS_MINUS_SIZE + SLIDER_PADDING
SLIDER_LENGTH = 128
PLUS_X = SLIDER_X + SLIDER_LENGTH + SLIDER_PADDING
VALUE_X = PLUS_X + PLUS_MINUS_SIZE + 5
MINUS_X = 0
SLIDER_X = MINUS_X + PLUS_MINUS_SIZE + SLIDER_PADDING
SLIDER_LENGTH = 128
PLUS_X = SLIDER_X + SLIDER_LENGTH + SLIDER_PADDING
VALUE_X = PLUS_X + PLUS_MINUS_SIZE + 5
def initialize(width, height, viewport, min_value, max_value, value)
super(width, height, viewport)
@@ -21,6 +20,8 @@ class UIControls::NumberSlider < UIControls::BaseControl
self.value = value
end
#-----------------------------------------------------------------------------
def value=(new_value)
old_val = @value
@value = new_value.to_i.clamp(self.min_value, self.max_value)
@@ -41,6 +42,8 @@ class UIControls::NumberSlider < UIControls::BaseControl
self.invalidate
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@slider_rect = Rect.new(SLIDER_X - SLIDER_PADDING, (self.height - PLUS_MINUS_SIZE) / 2, SLIDER_LENGTH + (SLIDER_PADDING * 2), PLUS_MINUS_SIZE)
@minus_rect = Rect.new(MINUS_X, (self.height - PLUS_MINUS_SIZE) / 2, PLUS_MINUS_SIZE, PLUS_MINUS_SIZE)

View File

@@ -7,7 +7,6 @@ class UIControls::NumberTextBox < UIControls::TextBox
PLUS_MINUS_SIZE = 16
CONTROL_PADDING = 2 # Gap between buttons and text box
MINUS_X = 0
TEXT_BOX_X = MINUS_X + PLUS_MINUS_SIZE + CONTROL_PADDING
TEXT_BOX_WIDTH = 64
@@ -21,6 +20,8 @@ class UIControls::NumberTextBox < UIControls::TextBox
self.value = value
end
#-----------------------------------------------------------------------------
def value=(new_value)
old_val = @value.to_i
@value = new_value.to_i.clamp(self.min_value, self.max_value)
@@ -49,6 +50,8 @@ class UIControls::NumberTextBox < UIControls::TextBox
invalidate
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT)
@@ -61,8 +64,6 @@ class UIControls::NumberTextBox < UIControls::TextBox
}
end
#-----------------------------------------------------------------------------
def reset_interaction
super
self.value = @value # Turn value back into a number and clamp it

View File

@@ -16,21 +16,12 @@ class UIControls::Button < UIControls::BaseControl
@highlight = false
end
#-----------------------------------------------------------------------------
def set_fixed_size
@fixed_size = true
end
def set_interactive_rects
@interactions&.clear
button_width = (@fixed_size) ? width - (BUTTON_X * 2) : self.bitmap.text_size(@text).width + (BUTTON_PADDING * 2)
button_height = (@fixed_size) ? height - (2 * BUTTON_Y) : BUTTON_HEIGHT
button_height = [button_height, height - (2 * BUTTON_Y)].min
@button_rect = Rect.new(BUTTON_X, (height - button_height) / 2, button_width, button_height)
@interactions = {
:button => @button_rect
}
end
def set_text(val)
return if @text == val
@text = val
@@ -38,6 +29,8 @@ class UIControls::Button < UIControls::BaseControl
invalidate
end
#-----------------------------------------------------------------------------
def disabled?
return highlighted? || super
end
@@ -70,6 +63,19 @@ class UIControls::Button < UIControls::BaseControl
#-----------------------------------------------------------------------------
def set_interactive_rects
@interactions&.clear
button_width = (@fixed_size) ? width - (BUTTON_X * 2) : self.bitmap.text_size(@text).width + (BUTTON_PADDING * 2)
button_height = (@fixed_size) ? height - (2 * BUTTON_Y) : BUTTON_HEIGHT
button_height = [button_height, height - (2 * BUTTON_Y)].min
@button_rect = Rect.new(BUTTON_X, (height - button_height) / 2, button_width, button_height)
@interactions = {
:button => @button_rect
}
end
#-----------------------------------------------------------------------------
def refresh
super
if highlighted?

View File

@@ -12,6 +12,8 @@ class UIControls::BitmapButton < UIControls::Button
@disabled_bitmap = disabled_bitmap
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@interactions&.clear
@button_rect = Rect.new(0, 0, width, height)

View File

@@ -2,11 +2,10 @@
#
#===============================================================================
class UIControls::List < UIControls::BaseControl
BORDER_THICKNESS = 2
ROW_HEIGHT = 24
TEXT_PADDING_X = 4
TEXT_OFFSET_Y = 3
BORDER_THICKNESS = 2
ROW_HEIGHT = 24
TEXT_PADDING_X = 4
TEXT_OFFSET_Y = 3
SELECTED_ROW_COLOR = Color.new(216, 192, 32) # Dark yellow
def initialize(width, height, viewport, values = [])
@@ -30,6 +29,8 @@ class UIControls::List < UIControls::BaseControl
super
end
#-----------------------------------------------------------------------------
def x=(new_val)
super(new_val)
@scrollbar.x = new_val + width - UIControls::Scrollbar::SLIDER_WIDTH - BORDER_THICKNESS
@@ -64,6 +65,17 @@ class UIControls::List < UIControls::BaseControl
invalidate
end
# Returns the ID of the selected row.
def value
return nil if @selected < 0
if @values.is_a?(Array)
return (@values[@selected].is_a?(Array)) ? @values[@selected][0] : @selected
elsif @values.is_a?(Hash)
return @values.keys[@selected]
end
return nil
end
def top_row=(val)
old_val = @top_row
@top_row = val
@@ -81,16 +93,7 @@ class UIControls::List < UIControls::BaseControl
invalidate
end
# Returns the ID of the selected row.
def value
return nil if @selected < 0
if @values.is_a?(Array)
return (@values[@selected].is_a?(Array)) ? @values[@selected][0] : @selected
elsif @values.is_a?(Hash)
return @values.keys[@selected]
end
return nil
end
#-----------------------------------------------------------------------------
def mouse_in_control?
mouse_x, mouse_y = mouse_pos
@@ -100,6 +103,12 @@ class UIControls::List < UIControls::BaseControl
return false
end
def busy?
return !@captured_area.nil?
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@interactions = {}
@values.length.times do |i|
@@ -112,12 +121,6 @@ class UIControls::List < UIControls::BaseControl
#-----------------------------------------------------------------------------
def busy?
return !@captured_area.nil?
end
#-----------------------------------------------------------------------------
def draw_area_highlight
# If a row is captured, it will automatically be selected and the selection
# colour will be drawn over the highlight. There's no point drawing a

View File

@@ -26,23 +26,17 @@ class UIControls::DropdownList < UIControls::BaseControl
super
end
def value=(new_value)
return if @value == new_value
@value = new_value
invalidate
end
#-----------------------------------------------------------------------------
def values=(new_vals)
@options = new_vals
@dropdown_menu.values = @options if @dropdown_menu
end
def set_interactive_rects
@button_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:button => @button_rect
}
def value=(new_value)
return if @value == new_value
@value = new_value
invalidate
end
#-----------------------------------------------------------------------------
@@ -54,6 +48,14 @@ class UIControls::DropdownList < UIControls::BaseControl
#-----------------------------------------------------------------------------
def set_interactive_rects
@button_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:button => @button_rect
}
end
def make_dropdown_menu
menu_height = (UIControls::List::ROW_HEIGHT * [@options.length, @max_rows].min) + (UIControls::List::BORDER_THICKNESS * 2)
# Draw menu's background

View File

@@ -26,21 +26,13 @@ class UIControls::TextBoxDropdownList < UIControls::TextBox
super
end
#-----------------------------------------------------------------------------
def values=(new_vals)
@options = new_vals
@dropdown_menu.values = @options if @dropdown_menu
end
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2) - BUTTON_WIDTH].min, TEXT_BOX_HEIGHT)
@button_rect = Rect.new(BUTTON_X, @text_box_rect.y, BUTTON_WIDTH, BUTTON_HEIGHT)
@interactions = {
:text_box => @text_box_rect,
:button => @button_rect
}
end
#-----------------------------------------------------------------------------
def busy?
@@ -50,6 +42,16 @@ class UIControls::TextBoxDropdownList < UIControls::TextBox
#-----------------------------------------------------------------------------
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[@box_width, width - (TEXT_BOX_X * 2) - BUTTON_WIDTH].min, TEXT_BOX_HEIGHT)
@button_rect = Rect.new(BUTTON_X, @text_box_rect.y, BUTTON_WIDTH, BUTTON_HEIGHT)
@interactions = {
:text_box => @text_box_rect,
:button => @button_rect
}
end
def make_dropdown_menu
menu_height = (UIControls::List::ROW_HEIGHT * [@options.length, @max_rows].min) + (UIControls::List::BORDER_THICKNESS * 2)
# Draw menu's background

View File

@@ -2,6 +2,8 @@
#
#===============================================================================
class UIControls::Scrollbar < UIControls::BaseControl
attr_reader :slider_top
SLIDER_WIDTH = 16
WIDTH_PADDING = 0
SCROLL_DISTANCE = 16
@@ -9,8 +11,6 @@ class UIControls::Scrollbar < UIControls::BaseControl
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
super(size, SLIDER_WIDTH, viewport)
@@ -28,18 +28,7 @@ class UIControls::Scrollbar < UIControls::BaseControl
self.visible = @always_visible
end
def position
return 0 if @range <= @tray_size
return (@range - @tray_size) * @slider_top / (@tray_size - @slider_size)
end
def minimum?
return @slider_top <= 0
end
def maximum?
return @slider_top >= @tray_size - @slider_size
end
#-----------------------------------------------------------------------------
# Range is the total size of the large area that the scrollbar is able to
# show part of.
@@ -68,6 +57,21 @@ class UIControls::Scrollbar < UIControls::BaseControl
invalidate if @slider_top != old_val
end
def position
return 0 if @range <= @tray_size
return (@range - @tray_size) * @slider_top / (@tray_size - @slider_size)
end
def minimum?
return @slider_top <= 0
end
def maximum?
return @slider_top >= @tray_size - @slider_size
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@interactions = {}
if @horizontal