diff --git a/api/align.md b/api/align.md index 95e2583..7c2766e 100644 --- a/api/align.md +++ b/api/align.md @@ -8,6 +8,8 @@ element in this enum might vary in the future. E.g. ```lua +local left = Align.LEFT +local top = Align.TOP local leftBottom = Align.LEFT | Align.BOTTOM local rightTop = Align.RIGHT | Align.TOP ``` diff --git a/api/app.md b/api/app.md index fcab5e1..db0a236 100644 --- a/api/app.md +++ b/api/app.md @@ -130,6 +130,77 @@ This is a table with parameters specified as [`gui.xml`](https://github.com/aseprite/aseprite/blob/main/data/gui.xml) file. +## app.clipboard + +Check the [app.clipboard](app_clipboard.md#appclipboard) documentation. + +## app.command + +Check the [app.command](app_command.md#appcommand) documentation. + +## app.preferences + +Check the [app.preferences](app_preferences.md#apppreferences) documentation. + +## app.fs + +Check the [app.fs](app_fs.md#appfs) documentation. + +## app.theme + +Check the [app.theme](app_theme.md#apptheme) documentation. + +## app.os + +Check the [app.os](app_os.md#appos) documentation. + +## app.uiScale + +``` +local scale = app.uiScale +``` + +Returns the [UI Elements Scaling](https://www.aseprite.org/docs/preferences/) +value specified in *Edit > Preferences* as an scale factor (1 for 100%, 2 for 200%, etc.) + +## app.events + +Returns the [`Events`](events.md#events) object to associate functions +that can act like listeners of specific `app` events. E.g. + +```lua +app.events:on('sitechange', + function() + print('Now we are located in other sprite, layer, or frame') + end) +``` + +Available events for `app`: + +* `'sitechange'`: When the user selects other sprite, layer, or frame. +* `'beforesitechange'`: Before the user switches to other sprite, layer, or frame. +* `'fgcolorchange'`: When the [Foreground color](https://www.aseprite.org/docs/color-bar/#foreground-color) in the color bar is changed. +* `'bgcolorchange'`: When the [Background color](https://www.aseprite.org/docs/color-bar/#background-color) in the color bar is changed. +* `'beforecommand'`: Before executing any command in the program. +* `'aftercommand'`: After executing any command in the program. + +The `'beforecommand'` and `'aftercommand'` events receive an `ev` +argument with the name of the command (`ev.name`) and the params +(`ev.params`). `'beforecommand'` includes a `ev.stopPropagation()` +function to cancel the event, e.g. in case that you've handled the +event in a custom way. + +E.g. This code catches the *Edit > Cut* command and convert it to a *Copy*: +```lua +app.events:on('beforecommand', + function(ev) + if ev.name == "Cut" then + app.command.Copy() -- call Copy command + ev.stopPropagation() -- and cancel the Cut + end + end) +``` + ## app.alert() ```lua @@ -228,39 +299,6 @@ app.transaction( end) ``` -## app.clipboard - -Check the [app.clipboard](app_clipboard.md#appclipboard) documentation. - -## app.command - -Check the [app.command](app_command.md#appcommand) documentation. - -## app.preferences - -Check the [app.preferences](app_preferences.md#apppreferences) documentation. - -## app.fs - -Check the [app.fs](app_fs.md#appfs) documentation. - -## app.theme - -Check the [app.theme](app_theme.md#apptheme) documentation. - -## app.os - -Check the [app.os](app_os.md#appos) documentation. - -## app.uiScale - -``` -local scale = app.uiScale -``` - -Returns the [UI Elements Scaling](https://www.aseprite.org/docs/preferences/) -value specified in *Edit > Preferences* as an scale factor (1 for 100%, 2 for 200%, etc.) - ## app.refresh() ```lua @@ -338,44 +376,6 @@ Simulates an user stroke in the canvas using the given tool. * `layer`: The [layer](layer.md#layer) where we want to use the tool/draw with the tool (by default [app.layer](app.md#applayer)) * `frame`: The [frame](frame.md#frame) where to draw (by default [app.frame](app.md#appframe)) -## app.events - -Returns the [`Events`](events.md#events) object to associate functions -that can act like listeners of specific `app` events. E.g. - -```lua -app.events:on('sitechange', - function() - print('Now we are located in other sprite, layer, or frame') - end) -``` - -Available events for `app`: - -* `'sitechange'`: When the user selects other sprite, layer, or frame. -* `'beforesitechange'`: Before the user switches to other sprite, layer, or frame. -* `'fgcolorchange'`: When the [Foreground color](https://www.aseprite.org/docs/color-bar/#foreground-color) in the color bar is changed. -* `'bgcolorchange'`: When the [Background color](https://www.aseprite.org/docs/color-bar/#background-color) in the color bar is changed. -* `'beforecommand'`: Before executing any command in the program. -* `'aftercommand'`: After executing any command in the program. - -The `'beforecommand'` and `'aftercommand'` events receive an `ev` -argument with the name of the command (`ev.name`) and the params -(`ev.params`). `'beforecommand'` includes a `ev.stopPropagation()` -function to cancel the event, e.g. in case that you've handled the -event in a custom way. - -E.g. This code catches the *Edit > Cut* command and convert it to a *Copy*: -```lua -app.events:on('beforecommand', - function(ev) - if ev.name == "Cut" then - app.command.Copy() -- call Copy command - ev.stopPropagation() -- and cancel the Cut - end - end) -``` - # Deprecated Names The following fields were replaced with new alternatives (generally diff --git a/api/app_clipboard.md b/api/app_clipboard.md index 9a4a78f..036b324 100644 --- a/api/app_clipboard.md +++ b/api/app_clipboard.md @@ -20,7 +20,9 @@ Gets or sets the clipboard text. Returns `nil` if there is no text. local image = app.clipboard.image ``` -Gets or sets the clipboard [image](image.md#image). Returns `nil` if there is no image. +Gets or sets the clipboard [image](image.md#image). Returns `nil` if there is no image. It is recommended to set/get the value once when needed, as the operation may not always be available immediately (in some instances it may take a few milliseconds, see [#5341](https://github.com/aseprite/aseprite/issues/5341#issuecomment-3176395116)). + +Additionally, when calling a method on an image from the clipboard image, the image should be saved to a variable first, instead of calling the method directly on the property (this will not work: `app.clipboard.image:clear()`, see [#5341](https://github.com/aseprite/aseprite/issues/5341#issuecomment-3176395116)) ## app.clipboard.content diff --git a/api/app_preferences.md b/api/app_preferences.md index 1e046b8..7496a58 100644 --- a/api/app_preferences.md +++ b/api/app_preferences.md @@ -5,10 +5,11 @@ local value = app.preferences.section.option app.preferences.section.option = newValue ``` -Gets or sets the given preference `option` in the given `section`. You -can find valid `section` and `option` names in the +Gets or sets the given preference `option` in the given `section`. + +You can find valid `section` and `option` names in the [pref.xml](https://github.com/aseprite/aseprite/blob/main/data/pref.xml) -file. +file; each `option` corresponds to a preference in the [preferences menu](https://www.aseprite.org/docs/preferences#preferences). ## app.preferences.tool() diff --git a/api/dialog.md b/api/dialog.md index 551a003..8f5f399 100644 --- a/api/dialog.md +++ b/api/dialog.md @@ -64,6 +64,7 @@ Where: local dlg = Dialog() local dlg = Dialog(string) local dlg = Dialog{ title=string, + autofit=align, notitlebar=false, resizeable=false, parent=otherDialog, @@ -86,9 +87,63 @@ kind of title bar (the dialog must be closed with a button inside it). `{ resizeable=false }` disables the user from resizing the dialog. +`{ autofit=align }` sets how the dialog will align when shown. See [Dialog.autofit](#dialogautofit). + Returns `nil` if there is no UI available, i.e. [app.isUIAvailable is `false`](app.md#appisuiavailable). +## Dialog.data + +```lua +local dlg = Dialog() +local data = dlg.data +dlg.data = data +``` + +Gets/sets a table with one field for each widget with a given `id`. +For each different kind of widget the field is of a different type: + +* [button](#dialogbutton)/[check](#dialogcheck)/[radio](#dialogradio): + The field is a boolean (true or + false) if the button is selected or was used to close the dialog. +* [entry](#dialogentry)/[label](#dialoglabel): A string of text. +* [slider](#dialogslider): An integer. +* [number](#dialognumber): An intenger or a + number depending on the number of decimals of the number field. +* [combobox](#dialogcombobox): A string with the + selected item. +* [color](#dialogcolor): A [Color](color.md#color). +* [shades](#dialogshades): A table with an array of [Color](color.md#color)s when `mode="sort"` + +## Dialog.bounds + +```lua +local dlg = Dialog() +local bounds = dlg.bounds +dlg.bounds = Rectangle(x, y, bounds.width, bounds.height) +``` + +Gets or sets the position and size (a [rectangle](rectangle.md#rectangle)) of +the dialog. This can be useful to align several dialog that must be +shown in the same *xy*-position. + +## Dialog.autofit + +```lua +local autofit = dlg.autofit +dlg.autofit = autofit +``` + +Gets or sets the dialog autofit, as an [Align](align.md#align) object. The setting will only visually take effect on the dialog after a [`Dialog:modify()`](#dialogmodify). When set, the dialog window will resize itself, anchoring at the specified value (eg. when autofitting with `Align.LEFT | Align.TOP`, the dialog bounds will shrink to the minimum size anchored at the top left of the dialog). + +## Dialog.sizeHint + +```lua +local sizeHint = dlg.sizeHint +``` + +Gets the minimum size (without cutoff) of the dialog window, as a [Size](size.md#Size). + ## Dialog:button() ```lua @@ -170,41 +225,6 @@ Creates a combo box/drop-down list. * `options`: Indicates a list of available options in the combobox. * `option`: Indicates the default selected option in the combobox (one of the `options`). -## Dialog.data - -```lua -local dlg = Dialog() -local data = dlg.data -dlg.data = data -``` - -Gets/sets a table with one field for each widget with a given `id`. -For each different kind of widget the field is of a different type: - -* [button](#dialogbutton)/[check](#dialogcheck)/[radio](#dialogradio): - The field is a boolean (true or - false) if the button is selected or was used to close the dialog. -* [entry](#dialogentry)/[label](#dialoglabel): A string of text. -* [slider](#dialogslider): An integer. -* [number](#dialognumber): An intenger or a - number depending on the number of decimals of the number field. -* [combobox](#dialogcombobox): A string with the - selected item. -* [color](#dialogcolor): A [Color](color.md#color). -* [shades](#dialogshades): A table with an array of [Color](color.md#color)s when `mode="sort"` - -## Dialog.bounds - -```lua -local dlg = Dialog() -local bounds = dlg.bounds -dlg.bounds = Rectangle(x, y, bounds.width, bounds.height) -``` - -Gets or sets the position and size (a [rectangle](rectangle.md#rectangle)) of -the dialog. This might be useful to align several dialog that must be -shown in the same *xy*-position. - ## Dialog:entry() ```lua @@ -252,7 +272,7 @@ local dlg = Dialog() dlg:modify{ title = "New Dialog Title" } ``` -Using the `dialog:modify` with a parameter `title` changes the dialog title. +Using the `dialog:modify` with a parameter `title` changes the dialog title. ## Dialog:newrow() @@ -453,29 +473,29 @@ Marks the end of both the last tab and the group of tabs to which it belongs. ```lua local dlg = Dialog() dlg:file{ id=string, - label=string, title=string, + filename=string, + basepath=string, open=boolean, save=boolean, - filename=string | { string1,string2,string3... }, + entry=boolean, filetypes={ string1,string2,string3... }, onchange=function } ``` Creates a text entry field + a button to select one file to open or save, possibilities: -* `open=true`: shows a dialog to open an existent file (this is the default mode). -* `save=true`: shows a dialog to select an existent file to overwrite or a new file to save. +* `open`: When true, shows a dialog to open an existing file (set to true by default). +* `save`: When true, shows a dialog to select an existing file to overwrite or a new file to save. -Arguments (table fields): +Other arguments: -* `load`: True if you want to show a dialog to the user to select an existent file to load/read. -* `save`: True if you want to show a dialog to the user to select a new file to save/write content. * `filename`: String of the selected filename to open or save. +* `title`: The title of the file select menu. * `filetypes`: Array of possible file types/extensions that the user can select. * `entry`: Show an entry field to edit the filename manually (false by default). -* `focus`: Focus this field by default. -* `onchange`: Function to be called when the filename is changed. +* `basepath`: The base path of the directory. Use [app.fs.joinPath()](app_fs.md#appfsjoinpath) for paths. +* `onchange`: Function to be called when the filename/path is changed. ## Dialog:canvas() @@ -520,10 +540,10 @@ will be displayed the same at any UI scale. This property is enabled by default you don't need it you must explicitly set it to false. ```lua -dlg:modify{ id=canvasId, mouseCursor=newMouseCursor } +dlg:modify{ id=canvasId, mousecursor=newMouseCursor } ``` -Additionally, when using `Dialog:modify()`, the canvas `mouseCursor` property can be set to a [MouseCursor](mousecursor.md) value, changing the mouse cursor type. +Additionally, when using `Dialog:modify()`, the canvas `mousecursor` property can be set to a [MouseCursor](mousecursor.md) value, changing the mouse cursor type. ## Dialog:repaint() diff --git a/api/mousecursor.md b/api/mousecursor.md index 76d18ce..ad5af35 100644 --- a/api/mousecursor.md +++ b/api/mousecursor.md @@ -3,41 +3,77 @@ Mouse cursor that can be set in a [canvas widget](dialog.md#dialogcanvas) using: ```lua -dialog:modify{ id=canvasId, mouseCursor=newMouseCursor } +dialog:modify{ id=canvasId, mousecursor=newMouseCursor } ``` ## MouseCursor.NONE +![MouseCursor.NONE image (blank image)](mousecursor/none.png) + ## MouseCursor.ARROW +![MouseCursor.ARROW image](mousecursor/arrow.png) + ## MouseCursor.CROSSHAIR +![MouseCursor.CROSSHAIR image](mousecursor/crosshair.png) + ## MouseCursor.POINTER +![MouseCursor.POINTER image](mousecursor/pointer.png) + ## MouseCursor.NOT_ALLOWED +![MouseCursor.NOT_ALLOWED image](mousecursor/not_allowed.png) + ## MouseCursor.GRAB +![MouseCursor.GRAB image](mousecursor/grab.png) + ## MouseCursor.GRABBING +![MouseCursor.GRABBING image](mousecursor/grab.png) + ## MouseCursor.MOVE +![MouseCursor.MOVE image ](mousecursor/move.png) + ## MouseCursor.NS_RESIZE +![MouseCursor.NS_RESIZE image](mousecursor/n_resize.png) + ## MouseCursor.WE_RESIZE +![MouseCursor.WE_RESIZE image](mousecursor/w_resize.png) + ## MouseCursor.N_RESIZE +![MouseCursor.N_RESIZE image](mousecursor/n_resize.png) + ## MouseCursor.NE_RESIZE +![MouseCursor.NE_RESIZE image](mousecursor/ne_resize.png) + ## MouseCursor.E_RESIZE +![MouseCursor.E_RESIZE image](mousecursor/w_resize.png) + ## MouseCursor.SE_RESIZE +![MouseCursor.SE_RESIZE image](mousecursor/se_resize.png) + ## MouseCursor.S_RESIZE +![MouseCursor.S_RESIZE image](mousecursor/n_resize.png) + ## MouseCursor.SW_RESIZE +![MouseCursor.SW_RESIZE image](mousecursor/ne_resize.png) + ## MouseCursor.W_RESIZE +![MouseCursor.W_RESIZE image](mousecursor/w_resize.png) + ## MouseCursor.NW_RESIZE + +![MouseCursor.NW_RESIZE image](mousecursor/se_resize.png) diff --git a/api/mousecursor/arrow.png b/api/mousecursor/arrow.png new file mode 100644 index 0000000..12628d3 Binary files /dev/null and b/api/mousecursor/arrow.png differ diff --git a/api/mousecursor/crosshair.png b/api/mousecursor/crosshair.png new file mode 100644 index 0000000..5e94764 Binary files /dev/null and b/api/mousecursor/crosshair.png differ diff --git a/api/mousecursor/grab.png b/api/mousecursor/grab.png new file mode 100644 index 0000000..0c24807 Binary files /dev/null and b/api/mousecursor/grab.png differ diff --git a/api/mousecursor/move.png b/api/mousecursor/move.png new file mode 100644 index 0000000..29a9004 Binary files /dev/null and b/api/mousecursor/move.png differ diff --git a/api/mousecursor/n_resize.png b/api/mousecursor/n_resize.png new file mode 100644 index 0000000..fb2df42 Binary files /dev/null and b/api/mousecursor/n_resize.png differ diff --git a/api/mousecursor/ne_resize.png b/api/mousecursor/ne_resize.png new file mode 100644 index 0000000..038a2f8 Binary files /dev/null and b/api/mousecursor/ne_resize.png differ diff --git a/api/mousecursor/none.png b/api/mousecursor/none.png new file mode 100644 index 0000000..7244b37 Binary files /dev/null and b/api/mousecursor/none.png differ diff --git a/api/mousecursor/not_allowed.png b/api/mousecursor/not_allowed.png new file mode 100644 index 0000000..8879519 Binary files /dev/null and b/api/mousecursor/not_allowed.png differ diff --git a/api/mousecursor/pointer.png b/api/mousecursor/pointer.png new file mode 100644 index 0000000..94d7f1a Binary files /dev/null and b/api/mousecursor/pointer.png differ diff --git a/api/mousecursor/se_resize.png b/api/mousecursor/se_resize.png new file mode 100644 index 0000000..f8e4d73 Binary files /dev/null and b/api/mousecursor/se_resize.png differ diff --git a/api/mousecursor/w_resize.png b/api/mousecursor/w_resize.png new file mode 100644 index 0000000..a995a9b Binary files /dev/null and b/api/mousecursor/w_resize.png differ