Commit Graph

92 Commits

Author SHA1 Message Date
Christian Kaiser 0ccf9dcc4f [lua] Add app.tip (#5316 / #5348) 2025-08-26 09:00:40 -03:00
Christian Kaiser 7331398203 Add app.clipboard Lua API 2025-01-08 12:35:20 -03:00
David Capello 09538f9a1a clang-format all files 2024-12-16 14:52:19 -03:00
Gaspar Capello 0f7cac0f0c [lua] Add get/set the foreground/background tile (fix #4403)
It's now possible to get/set the selected foreground/background tile
index. Example of use:

  app.fgTile = 1    -- the primary tile is '1'
  print(app.fgTile) -- this will show '1'
  app.fgTile = 0    -- the primery tile is 'no tile'
  print(app.fgTile) -- this will show '0'
  app.bgTile = 2    -- the secondary tile is '2'
2024-09-16 16:19:29 -03:00
David Capello 9429d915ae [lua] Fix default color/bgColor params in app.useTool()
We can select the default color or tile from preferences depending if
we're going to paint pixels or tiles

Fixes a confusing logic from 4a91d150af
where the bg color was obtained from preferences only when the fg
color type (rgb/gray/index/hsv/tile/etc.) was equal to the bg color
type from the preferences (rgb/gray/index/hsv/tile/etc.).
2024-09-03 19:25:19 -03:00
Gaspar Capello 4a91d150af Fix transparent color is possible on opaque sprites (fix #4370)
To reproduce the error before this fix on RGBA/Grayscale Color Mode:
- New 100x100 RGBA/Grayscale opaque sprite (white background).
- Draw something with some gray color in the palette.
- Keep the selected gray color as primary color.
- Configure as secondary color the mask color (#000000 alpha=0).
- Pick 'eraser' tool and erase over the gray color with right click.
- Result: The sprite doesn't look more opaque, which is wrong. Also,
  if we export this sprite, the transparent parts will turn black.

A similar problem occurs in Indexed Color Mode, but getting a
transparent color in a Background sprite is inevitable if the color of
a palette entry is transparent or semi-transparent, since the index
must be set as is. This could be fixed in the future at the
render stage, however, this could lead to other perceived
inconsistencies. For now it'll be left as is.

Original issue description:
Downloaded PNG in RGB mode fails to support transparency: erase
uses secondary color and export PNG replaces transparent color
with black

Added tests for 'eraser' in 'Replace Color Mode'
To make the eraser work in 'Replace Color Mode' within the tests,
was implemented the possibility of using the right button in
the creation of the point vector.

During testing with UI available it was observed that the 'bg' color
was copied from the 'fg'. Changed this to be compatible with the way
the default value of 'fg' is assigned when it is not specified.
This last modification resulted in errors during 'tilemap.lua' due to
incompatibility of the type of 'bg' color. This was corrected
considering the color type of 'fg' color.
Furthermore, it was found that the command 'app.range.tiles = { 1 }'
did not finish assigning the tile picks to the activeSite,
then 'assert(1, #app.range.tiles)' was failing. This was fixed too.
2024-09-03 19:08:15 -03:00
David Capello bf0a47545c Remove #if/endif ENABLE_UI conditional directives (fix #4619)
This was originated for #1279 (CLI-only Aseprite) which can be
achieved with LAF_BACKEND=none anyway.

In this way we simplify the development process, and checking for the
availability of the GUI can be done in run-time through App::isGui()
or Context::isUIAvailable().
2024-09-02 23:16:26 -03:00
David Capello d3562b140c A Tx now will always try to lock the document if possible (#2430)
With re-entrant RWLocks we can try to lock the document on each
transaction/command/modification. This fixes several problems running
scripts that weren't locking the sprite in an app.transaction() call.
2023-12-27 11:05:15 -03:00
David Capello 8722c8ec16 Lock document in Tx() ctor (part of #2430)
This already fixes a lot of possible problems that can happen when a
script is running and modifying some part of a sprite that is being
backed up in a background thread.

We still need some work to being able to lock a sprite two or more
times in the same thread to write it. E.g. an app.transaction() should
lock the sprite for write access, but the script transaction function
could call a command, and that command could use a ContextWriter to
lock the sprite again. At the moment this is not possible because we
need a re-entrant RWLock implementation.
2023-12-27 11:05:15 -03:00
David Capello a2d8a080f5 [lua] Create app.window to access new main window properties (#3927)
We moved the app.width/heigth to app.window.width/height and
app.events.on('resize', ...) to app.window.events.on('resize', ...).
2023-07-18 17:54:57 -03:00
lampysprites 7ee866643b [lua] Add width and height properties to app 2023-07-18 15:50:22 -03:00
David Capello ccc57800a8 [lua] Add support to use app.sprite = nil 2023-05-18 13:20:10 -03:00
David Capello d7af7f4312 [lua] Add new app.editor object (fix aseprite/Attachment-System#104) 2023-04-19 19:10:28 -03:00
David Capello 622b02294a [lua] Add short field names (fix #3815, fix #3816) 2023-04-19 13:48:15 -03:00
David Capello 0dbcdc8159 [lua] Add app.uiScale property 2023-03-20 18:26:44 -03:00
David Capello f536327fc1 Add app.transaction(string, function) overload
In this way we can specify the transaction/undo-redo label from a
script.
2023-01-17 15:39:16 -03:00
David Capello 3d9021d717 [lua] Add app.theme.dimension/color.id to access theme values 2022-12-16 10:55:11 -03:00
David Capello 8f44b521b6 Merge branch 'main' into beta 2022-06-10 10:31:13 -03:00
David Capello 71d885d2a0 Replace base::clamp -> std::clamp as now we use C++17 2022-06-09 19:05:48 -03:00
David Capello 8b5133b4c0 [lua] Fix context used in App.useTool() 2022-02-11 10:41:56 -03:00
David Capello 0c1e08138e [lua] Fix crash using app.useTool() when the active editor is in MovingPixelsState (fix #2933)
More information in https://github.com/aseprite/aseprite/pull/3166
2022-02-11 10:19:32 -03:00
David Capello 6e726025ee Merge branch 'main' into beta 2022-01-05 20:16:13 -03:00
lampysprites 3035d00283 [lua] Show errors that happen inside App.transaction 2021-12-12 19:20:12 +07:00
David Capello db44eeb269 Merge branch 'main' into beta 2021-10-12 10:45:33 -03:00
David Capello b9241e6d91 Refactor ask_access() with ResourceType argument 2021-10-07 19:34:40 -03:00
David Capello cd342f5630 [lua] Add events handling with Sprite.events & App.events
Added a new Events object with :on() and :off() methods to start or
stop listening to a specific event respectively. This also allows to
add several callbacks for the same event.

Replaced the temporal Site.onChange & Sprite.onChange implementations.

Related to several issues (enable more possibilities for): #138, #1403, #1949, #2965, #2980
2021-10-07 18:56:39 -03:00
David Capello ecbd845aae Merge branch 'main' into beta 2021-04-22 14:02:36 -03:00
David Capello d7a1c71df0 lua: Add support for selection tools in app.useTool()
Fix https://github.com/aseprite/api/issues/37
2021-04-22 13:51:56 -03:00
David Capello c19ac7a45c Move the cancel flag from ToolLoop to ToolLoopManager 2020-09-01 12:13:24 -03:00
David Capello d8f6c666de Merge branch 'beta' into tilemap-editor 2020-07-30 16:49:17 -03:00
David Capello 7a534b0a4e [lua] Add Sprite{ fromFile="...", oneFrame=true } to load just one frame 2020-07-28 17:41:01 -03:00
David Capello 27e2a287bf [lua] Add possibility to draw tiles w/app.useTool{ tilemapMode=TilemapMode.TILES... } 2020-07-14 17:27:40 -03:00
David Capello a10efb187b Merge branch 'master' into tilemap-editor 2020-06-01 16:21:32 -03:00
David Capello 7a74aef1a7 [lua] Use the correct "controller" when "tool" param is specified in app.useTool()
Fix regression introduced in 1ec502d242
2020-05-28 12:01:34 -03:00
David Capello 1ec502d242 Add "ink" parameter to app.useTool() + minor needed refactors 2020-05-20 17:15:30 -03:00
David Capello b922cfcc10 Refactor ToolLoop creation w/ToolLoopParams to add more options to app.useTool()
This will be used to add more testing capabilities to app.useTool()
2020-05-19 20:11:47 -03:00
David Capello a80af2b304 Merge branch 'master' into tilemap-editor 2020-05-18 20:24:22 -03:00
David Capello c99a566635 Refactor velocity sensor with tools::VelocitySensor class 2020-04-24 11:19:35 -03:00
David Capello 79f9e28ce8 Added pen pressure sensitivity (fix #710)
- Added support to detect eraser tip on Linux (#610)
- Related to #139
- Still needs works for gradients and better brush interpolations
  between stroke points
- Requested several times, e.g. https://community.aseprite.org/t/1077
  https://community.aseprite.org/t/1881, steam forum, etc.
2020-04-21 22:27:49 -03:00
David Capello 7319309630 Merge branch 'master' into tilemap-editor 2020-03-17 00:25:24 -03:00
David Capello a0882ba443 Move PACKAGE/VERSION, etc. to new ver-lib
* As we moved the VERSION macro to a .c file, we don't have to
  recompile the whole project when we change the version number.
* Removed the version number from gui.xml
* Removed the invalid first menu item that might appear in the root
  menu when the gui.xml version is outdated in debug mode.
2020-03-16 10:31:32 -03:00
David Capello 26139c4ae2 Add tilemap layers (#977)
This is the first commit with a simple tilemap editor. Still buggy but
functional in several ways. Several changes were made:

* NewLayer command can receive a tilemap=true to create a new tilemap
  layer
* New ToggleTilesMode command added to switch between the palette and
  the tileset in the ColorBar (the ColorBar was expanded to show
  colors or tilesets with a generic AbstractPaletteViewAdapter)
* All commands to create new layers were moved to Layer >
  New... submenu
* There are a new tileset chunk to save tilesets in .aseprite files,
  and a new kind of cels to save tilemaps
* Added doc::LayerTilemap, doc::Tileset, etc. and several other types
  to handle tilesets/tilemaps in the doc layer.
* Added doc::Grid class with grid specifications that indicates how a
  tilemap <-> tileset must be drawn
* Added and expanded cel operations to work with tilemaps and
  conversions between regular LayerImage cels <-> LayerTilemap cels
  (e.g. copy cels in the timeline between layer types)
2020-02-17 09:06:00 -03:00
David Capello 66864beb77 lua: Fix crash calling app.refresh() from a script using -b -script from CLI 2020-02-05 12:18:12 -03:00
David Capello 1c8b8051a8 Rename FrameTag -> Tag 2019-10-01 14:55:08 -03:00
David Capello 35aaa18ee3 [lua] Add app.range.colors + Move/CopyColors commands
Closes: https://community.aseprite.org/t/2512
2019-08-10 14:37:18 -03:00
David Capello 57d5fcba68 lua: Don't include -x64 in app.version 2019-05-27 23:53:57 -03:00
David Capello 23f00d87f6 lua: Add error if we specify and invalid tool in app.useTool() 2019-04-25 16:33:49 -03:00
David Capello ad1a0af752 lua: Add a way to set/get the default app palette (and well-known palettes from resources) 2019-04-24 19:08:25 -03:00
David Capello d35251d431 lua: Add Version() class 2019-04-21 00:04:49 -03:00
David Capello 8a821c83fd lua: Add Brush class and app.useTool{ brush } parameter 2019-04-18 22:33:48 -03:00