Module: SFML::Clipboard
- Defined in:
- lib/sfml/window/clipboard.rb
Overview
The system clipboard. UTF-8 in, UTF-8 out — even when the OS stores
it as wide chars, we go through CSFML's *UnicodeString variants
and convert in Ruby so non-ASCII text round-trips losslessly.
SFML::Clipboard.text #=> "whatever was last copied"
SFML::Clipboard.text = "пример"
Useful inside text-input UIs (Ctrl+C / Ctrl+V handlers) and for quick "copy that error message" buttons in tools.
Class Method Summary collapse
-
.text ⇒ Object
Returns the text.
-
.text=(value) ⇒ Object
Set the text.
Class Method Details
.text ⇒ Object
Returns the text.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sfml/window/clipboard.rb', line 15 def text ptr = C::Window.sfClipboard_getUnicodeString return "" if ptr.null? codepoints = [] offset = 0 loop do cp = ptr.get_uint32(offset) break if cp.zero? codepoints << cp offset += 4 end codepoints.pack("U*") end |
.text=(value) ⇒ Object
Set the text.
31 32 33 34 35 36 37 38 |
# File 'lib/sfml/window/clipboard.rb', line 31 def text=(value) str = value.to_s.encode("UTF-8") cps = str.unpack("U*") buf = FFI::MemoryPointer.new(:uint32, cps.length + 1) buf.write_array_of_uint32(cps + [0]) C::Window.sfClipboard_setUnicodeString(buf) str end |