User Tools

Site Tools


en:tutorials:display:clipboard

This is an old revision of the document!


The Clipboard

Orx now supports clipboards! We can demonstrate this by allowing the user to paste in some text, and have the text replace a text object. First there's a little setup.

Start by using init to create a default project.

Next, define the Control-V key which is the usual for paste, except in the case of Mac OS X:

[MainInput]
KEY_ESCAPE  = Quit
KEY_LCTRL   = Paste
KEY_V       = Paste
CombineList = Paste

To make it more interesting, let's change the default object into a text object which we will update with text from the clipboard.

Change the [Object] in the config to be a text object:

[Object]
Graphic         = TextGraphic
Pivot           = center
Scale           = 1
Position        = (-90, -30, 0)
 
[TextGraphic]
Text = Sentence
 
[Sentence]
String = "Paste into this window."

Set the object variable and the top of the code:

orxOBJECT *object;

Then assign to the object variable in the init() function:

object = orxObject_CreateFromConfig("Object");

Compile and run, and you'll have a window with a text object like this:

In the Run() function (or an update function), check for the Control and V keys, call a get from the clipboard, and send the output to the text object:

if (orxInput_HasBeenActivated("Paste")){
 
	const orxSTRING clipboardText = orxSystem_GetClipboard();
	orxObject_SetTextString(object, clipboardText);
 
}

Compile and run. Go to a text editor and copy some text with Control-C into the system clipboard.

Come back to the Orx game window and press Control-V. The object will take the text from your clipboard. Nice!

If you attempt copy and paste a file, a bitmap, or any other non-textual information into Orx, the clipboard will contain orxNULL.

You can also send copied text back into the clipboard. First, set up the keybinding:

[MainInput]
KEY_ESCAPE  = Quit
KEY_LCTRL   = Copy # Paste
KEY_C       = Copy
KEY_V       = Paste
CombineList = Copy # Paste

In the Run() function (or an update function), set the clipboard text with:

if (orxInput_HasBeenActivated("Copy")){
 
	const orxSTRING clipboardText = "Hello from Orx.";
	orxSystem_SetClipboard(clipboardText);
 
}

Compile and run. Press Control-C to set the clipboard with the “Hello from Orx.” text. Now paste into a text editor to get the text from the clipboard:

You can also work with the clipboard in the Orx Console. Go to a text editor and copy some text. Go back your Orx application and open the console. Enter:

Clipboard.Get

: Hello from outside of Orx

From here you can set the clipboard text with:

Clipboard.Set “Hello from Orx”

: true

Note that quotes are needed when there is whitespace in the text.

Now paste the text into a text editor.

en/tutorials/display/clipboard.1597843393.txt.gz · Last modified: 2020/08/19 06:23 (5 years ago) by sausage