mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-18 22:02:34 +00:00
Removed use of the clipboard gem since Gosu now supports this natively! Added :static option for Text to render text using Gosu::Image.from_text/markup which results in nicer looking text, improvements to EditLine to display the caret in the correct place (doesn't position properly if :text_static is true)
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
module CyberarmEngine
|
||||
class Element
|
||||
class EditLine < Button
|
||||
class TextInput < Gosu::TextInput
|
||||
def filter=(filter)
|
||||
@filter = filter
|
||||
end
|
||||
|
||||
def filter(text_in)
|
||||
if @filter
|
||||
@filter.call(text_in)
|
||||
else
|
||||
text_in
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(text, options = {}, block = nil)
|
||||
@filter = options.delete(:filter)
|
||||
super(text, options, block)
|
||||
@@ -14,18 +28,11 @@ module CyberarmEngine
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
@show_caret = true
|
||||
|
||||
@text_input = Gosu::TextInput.new
|
||||
@text_input = TextInput.new
|
||||
@text_input.filter = @filter
|
||||
@text_input.text = text
|
||||
@last_text_value = text
|
||||
|
||||
if @filter && @filter.respond_to?(:call)
|
||||
@text_input.instance_variable_set(:@filter, @filter)
|
||||
|
||||
def @text_input.filter(text_in)
|
||||
@filter.call(text_in)
|
||||
end
|
||||
end
|
||||
|
||||
@offset_x = 0
|
||||
@offset_y = 0
|
||||
|
||||
@@ -98,20 +105,20 @@ module CyberarmEngine
|
||||
@text_input.caret_pos = @text_input.text.length
|
||||
|
||||
when Gosu::KB_C
|
||||
if @text_input.selection_start < @text_input.caret_pos
|
||||
Clipboard.copy(@text_input.text[@text_input.selection_start...@text_input.caret_pos])
|
||||
else
|
||||
Clipboard.copy(@text_input.text[@text_input.caret_pos...@text_input.selection_start])
|
||||
end
|
||||
Gosu.clipboard = if @text_input.selection_start < @text_input.caret_pos
|
||||
@text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
||||
else
|
||||
@text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
||||
end
|
||||
|
||||
when Gosu::KB_X
|
||||
chars = @text_input.text.chars
|
||||
|
||||
if @text_input.selection_start < @text_input.caret_pos
|
||||
Clipboard.copy(@text_input.text[@text_input.selection_start...@text_input.caret_pos])
|
||||
Gosu.clipboard = @text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
||||
chars.slice!(@text_input.selection_start, @text_input.caret_pos)
|
||||
else
|
||||
Clipboard.copy(@text_input.text[@text_input.caret_pos...@text_input.selection_start])
|
||||
Gosu.clipboard = @text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
||||
chars.slice!(@text_input.caret_pos, @text_input.selection_start)
|
||||
end
|
||||
|
||||
@@ -119,10 +126,9 @@ module CyberarmEngine
|
||||
|
||||
when Gosu::KB_V
|
||||
if instance_of?(EditLine) # EditLine assumes a single line of text
|
||||
@text_input.text = @text_input.text.insert(@text_input.caret_pos,
|
||||
Clipboard.paste.encode("UTF-8").gsub("\n", ""))
|
||||
@text_input.insert_text(Gosu.clipboard.encode("UTF-8").gsub("\n", ""))
|
||||
else
|
||||
@text_input.text = @text_input.text.insert(@text_input.caret_pos, Clipboard.paste.encode("UTF-8"))
|
||||
@text_input.insert_text(Gosu.clipboard.encode("UTF-8"))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -180,7 +186,7 @@ module CyberarmEngine
|
||||
if @type == :password
|
||||
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length)
|
||||
else
|
||||
@text.x + @text.width(@text_input.text[0...@text_input.send(method)])
|
||||
@text.x + @text.width(@text_input.text[0...@text_input.send(method)]) - @style.border_thickness_left
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ module CyberarmEngine
|
||||
@text = Text.new(
|
||||
text, font: @options[:font], z: @z, color: @options[:color],
|
||||
size: @options[:text_size], shadow: @options[:text_shadow],
|
||||
static: @options[:text_static],
|
||||
shadow_size: @options[:text_shadow_size],
|
||||
shadow_color: @options[:text_shadow_color],
|
||||
border: @options[:text_border],
|
||||
@@ -64,6 +65,10 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
if is_a?(Button)
|
||||
@text.y = @y + height / 2 - @text.height / 2
|
||||
end
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user