OSL ‐ Drawing Cursor - Mistium/Origin-OS GitHub Wiki

About

The cursor in this context, refers to the position where the next graphics command will draw a ui element for example


Goto

The first parameter is the x-coordinate. It represents the horizontal position of the cursor. The second parameter is the y-coordinate. It represents the vertical position of the cursor. For example, in the settings.osl script, the goto command is used to set the location for drawing the system settings options:

goto -150 -70

In this line, -150 is the x-coordinate and -70 is the y-coordinate. This moves the drawing cursor to the left and down from the center of the screen.

The goto command is often used before drawing commands like square, circle, text, etc. to specify where these elements should be drawn on the screen. For example:

goto 0 0
square 210 40 10 : c#111

In these lines, the goto command moves the drawing cursor to the center of the screen, and the square command draws a square at that location.


Change_x and Change_y

The change_x and change_y commands in OSL (Origin Scripting Language) are used to move the drawing cursor relative to its current position.

change_x moves the cursor horizontally by the specified amount. A positive value moves the cursor to the right, and a negative value moves it to the left.

change_y moves the cursor vertically by the specified amount. A positive value moves the cursor down, and a negative value moves it up.

change_x sidebar_width - 145

In this line, sidebar_width - 145 is the amount by which the cursor is moved. If sidebar_width is greater than 145, the cursor will move to the right; if sidebar_width is less than 145, the cursor will move to the left.

Similarly, the change_y command is used to move the cursor vertically:

change_y -50

In this line, -50 is the amount by which the cursor is moved. Since this is a negative value, the cursor will move up.

These commands are often used to adjust the position of the cursor when drawing multiple elements in a row or column. For example, you might use change_x to move the cursor to the right after drawing each element in a row, or change_y to move the cursor down after drawing each element in a column.


Loc

// This is a little bit more of an advanced but necessary command for osl programming

The loc command adjusts the cursor position relative to the dimensions of the current frame. It takes four parameters, a, b, c, and d, to calculate the new cursor position. This command is equivalent to the following sequence:

goto frame_width * -1 / a + c frame_height / b + d

Here's a breakdown of the parameters:

  • a: Adjusts the horizontal position of the cursor.
  • b: Adjusts the vertical position of the cursor.
  • c: Additional factor for horizontal adjustment.
  • d: Additional factor for vertical adjustment.

For instance, the following loc command:

loc 2 3 1 2

is equivalent to:

goto frame_width * -1 / 2 + 1 frame_height / 3 + 2

This moves the cursor to a position calculated based on the frame's dimensions and the specified parameters. The loc command is particularly useful for precise cursor positioning within the frame, offering flexibility in layout adjustments.

These cursor positioning commands provide control over the cursor's movement in a graphical environment, enabling you to specify absolute and relative positions on the screen.

Screenshot 2024-03-14 at 23 27 27

Set X and Y Coordinates

The set_x and set_y commands in originOS v4.2.4 or later allow precise control over the cursor's position.

Set X Coordinate

The set_x command adjusts the horizontal position of the cursor to the specified value.

Example:

set_x 50

In this example, the x-coordinate of the cursor is set to 50.

Set Y Coordinate

The set_y command adjusts the vertical position of the cursor to the specified value.

Example:

set_y 75

Here, the y-coordinate of the cursor is set to 75.

These commands offer a straightforward way to set specific coordinates for the cursor in originOS scripts. They are particularly useful for precise control over the cursor's position, enabling developers to fine-tune the placement of elements on the screen. These commands are supported in originOS v4.2.4 or later.