Canvas widgets: Difference between revisions

Jump to navigation Jump to search
Line 174: Line 174:
BTW: There is already a property to toggle the mouse cursor via setprop, so this could also be wrapped in gui.nas, obviously being able to use a canvas texture as the cursor would prove the point that "everything is a canvas" in the design.
BTW: There is already a property to toggle the mouse cursor via setprop, so this could also be wrapped in gui.nas, obviously being able to use a canvas texture as the cursor would prove the point that "everything is a canvas" in the design.
=== Multiplatform Clipboard Support (native Copy/Paste) {{Pending}} ===
=== Multiplatform Clipboard Support (native Copy/Paste) {{Pending}} ===
{{Progressbar|60}}
{{Progressbar|70}}
 
** X11 (For full support we will need to somehow hook into the X11 event queue):
*** http://www.jwz.org/doc/x-cut-and-paste.html
*** http://www.edwardrosten.com/code/x11.html
*** http://michael.toren.net/mirrors/doc/X-copy+paste.txt
*** https://github.com/kfish/xsel/blob/master/xsel.c
*** http://xclip.svn.sourceforge.net/viewvc/xclip/trunk/xclib.c?revision=82&view=markup
*** http://stackoverflow.com/questions/10570315/c-x11-clipboard-selection-transfer-does-not-work
 


Needs to be individually implemented for each supported window manager environment (Windows, OSX, X11):
Needs to be individually implemented for each supported window manager environment (Windows, OSX, X11):
* X11: [https://gitorious.org/~tomprogs/fg/toms-flightgear/blobs/clipboard/src/Scripting/ClipboardX11.cxx Scripting/ClipboardX11.cxx] {{Pending}}
* X11: [https://gitorious.org/fg/flightgear/blobs/next/src/Scripting/ClipboardX11.cxx Scripting/ClipboardX11.cxx] {{Done}}
* Windows: [https://gitorious.org/~tomprogs/fg/toms-flightgear/blobs/clipboard/src/Scripting/ClipboardWindows.cxx Scripting/ClipboardWindows.cxx] {{Done}}
* Windows: [https://gitorious.org/fg/flightgear/blobs/next/src/Scripting/ClipboardWindows.cxx Scripting/ClipboardWindows.cxx] {{Done}}
* OSX: To be based on: [https://gitorious.org/~tomprogs/fg/toms-flightgear/blobs/clipboard/src/Scripting/ClipboardFallback.cxx Scripting/ClipboardFallback.cxx] {{Not done}}
* OSX: To be based on: [https://gitorious.org/fg/flightgear/blobs/next/src/Scripting/ClipboardFallback.cxx Scripting/ClipboardFallback.cxx] {{Not done}}
 
A basic implementation is available which is not complete and needs some testing: https://gitorious.org/fg/toms-flightgear/commits/clipboard


* '''Hooray''': "Also, copy/paste usually involves getting a bounding box for the area and retrieving the text in that area (drawing a rectangle and inverting the font color)"
* '''Hooray''': "Also, copy/paste usually involves getting a bounding box for the area and retrieving the text in that area (drawing a rectangle and inverting the font color)"
Line 199: Line 188:
* f_getClipboardText() {{Done}}
* f_getClipboardText() {{Done}}


==== Nasal API ====
In Nasal space, there exists a "clipboard" hash which can be used to access the clipboard. There are two types of clipboards supported:
In Nasal space, there exists a "clipboard" hash which can be used to access the clipboard. There are two types of clipboards supported:


* CLIPBOARD: Standard clipboard like on almost everything operating system
* CLIPBOARD: Standard clipboard like on almost everything operating system
* SELECTION/PRIMARY: Primary X Selection like found on X11 based systems. On non-X11 platform this clipboard is only accessible from inside FlightGear.
* SELECTION: Primary X Selection like found on X11 based systems. On non-X11 platform this clipboard is only accessible from inside FlightGear.


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
clipboard.setText(text, type = "CLIPBOARD");
# Setting/getting the contents of the given type of clipboard. If
clipboard.getText(type = "CLIPBOARD");
# no type is specified it defaults to the standard clipboard.
# The return value indicates whether the operation completed
# successfully.
clipboard.setText: func(text, type = clipboard.CLIPBOARD) : bool
clipboard.getText: func(type = clipboard.CLIPBOARD)       : bool
</syntaxhighlight>


Some examples of using the clipboard:
<syntaxhighlight lang="php">
print("Clipboard contains: ", clipboard.getText() );
print("Clipboard contains: ", clipboard.getText() );
print("Selection contains: ", clipboard.getText("SELECTION") );
print("Selection contains: ", clipboard.getText(clipboard.SELECTION) );


if( !clipboard.setText("test") )
if( !clipboard.setText("test") )
   print("Failed to write to clipboard");
   print("Failed to write to clipboard");
if( !clipboard.setText("test-selection", "SELECTION") )
if( !clipboard.setText("test-selection", clipboard.SELECTION) )
   print("Failed to write to selection");
   print("Failed to write to selection");
</syntaxhighlight>
</syntaxhighlight>
166

edits

Navigation menu