71 Commits

Author SHA1 Message Date
46bd385675 feat!: Support secondary taps (right click) on new callbacks system (#3741)
Support secondary taps (right click) on new callbacks system.

In order to follow through with our [event system
migration](https://docs.google.com/document/d/1nBUup9QCPioVwWL1zs79z1hWF882tAYfNywFMdye2Qc),
we need to make sure the new system is equipped to support all use
cases; also changes the existing TapCallbacks to be primary-only.

I noticed that we don't support "secondary taps" (i.e. right clicks), so
I am adding this. I honestly really dislike the fact that this is
considered a completely different event from the left click, instead of
just a property on the click event. But I kept this structure to
replicate what Flutter does, so this is more familiar for users. I think
that is worth the slight verbosity of having yet another detector. Also,
it plays well this way with Flutter because that underlying events are a
bit different (for example, the secondary ones don't support `pointId`).

Note: this is a slight breaking change because the existing detector
works for BOTH left and right click, but there is NO WAY of
distinguishing them because the `buttons` property is not propagated in
the Flutter end (massive oversight I believe - might put a PR later).
Since this provides the secondary as a solution, it also removes
secondary clicks from triggering the primary. I think this is more
versatile than having tap detector=`(primary OR secondary)` and
secondary=`(secondary only)`.

I don't think this should affect basically any users because (1) desktop
only and (2) this acceptance of right clicks was probably a bug anyway
(for example, on the example it would rotate the square and also open
the context menu, which is jarring).

However I am happy to add an option or pursue a different approach, I
believe this is the best path forward, IMO.
2025-10-06 11:11:31 -04:00
b79fee0ae2 chore: Update min Dart constraint to 3.8 (#3676)
Update min Dart constraint to 3.8, which will enable us to use the
fancier collection literals.

This requires bumping the min Flutter version as well:

<img width="1892" height="1122" alt="image"
src="https://github.com/user-attachments/assets/7c7b07fc-4d96-4987-824d-9a7133ecfb85"
/>
2025-08-10 12:42:31 -04:00
a882261b63 fix: Deprecate HasGameRef in favor of HasGameReference (#3559)
This deprecates `HasGameRef` and suggests users to use
`HasGameReference` instead.
2025-04-14 18:45:17 +00:00
978ad31b42 refactor: Fix lint issues from latest flutter release (#3390)
Updates to use the new color method `withValues`.

---------

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
2024-12-13 22:40:54 +01:00
06f5a4b4a8 chore: Update cicd.yml file on flame_3d to match main, rollback color changes (#3378)
Update cicd.yml file on flame_3d to match main.

Since we finally updated main, we should require no difference
whatsoever on this file anymore.

This will require downgrading all the color changes, which is fine. This
should never have been a part of flame_3d to begin with.

Files were "untouched" by checking out the exact version as they are in
main right now (will need to rebase flame_3d to main later). I had to
add a couple more files because the files on main had dependencies on
changes that are not yet rebased on flame_3d. These extra diffs should
disappear when I do the final rebase.
2024-12-11 14:26:29 -05:00
27e4dcb65a chore: Update usages of Dart UI Color to not use deprecated fields and methods [flame_3d] (#3297)
Update usages of Dart UI Color to not use deprecated fields and methods.
On latest main of Flutter these will cause lint errors, [as can be seen
here](https://github.com/flame-engine/flame/actions/runs/10814047130/job/29999530293?pr=3282).

Note: I will update the `flame_3d`-specific violations on a followup.
2024-12-11 14:26:29 -05:00
b283b82f6c refactor: Modernize switch; use switch-expressions and no break; (#3133)
Replaces the switch cases that can be replaces with switch expressions
and removes `break;` where it isn't needed.

https://dart.dev/language/branches#switch-statements
2024-04-18 23:41:08 +02:00
12841d6471 docs: Update RawKeyEvent references to KeyEvent (#3052) (#3053)
This PR fixes #3052 and updates deprecated type references in docs from
`RawKeyEvent` to `KeyEvent`.

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
2024-03-06 14:40:54 +01:00
330862c98e fix!: Migrate from RawKeyEvent to KeyEvent (#3002)
First pass at migrating from `RawKeyEvent` and `RawKeyboard`
to `KeyEvent` and `HardwareKeyboard`.

Context:
https://docs.flutter.dev/release/breaking-changes/key-event-migration
2024-02-15 23:10:51 +01:00
e27818d872 fix: Set margins of JoystickComponent properly (#3019)
The margins of the `JoystickComponent` weren't set properly, this PR
fixes that.
2024-02-05 11:02:02 +00:00
d12e45444e docs: Remove references to Tappable and Draggable (#2912)
We still had some references to `Tappable` and `Draggable`, this PR
removes them and removes a superfluous test for `TapCallbacks`.

---------

Co-authored-by: jonathan <sharyari@gmail.com>
2023-12-09 16:09:45 +01:00
63994ebcd8 fix!: Add DisplacementEvent to fix delta coordinate transformations for drag events (#2871)
This adds `DisplacementEvent` to fix delta coordinate transformations
for drag events, to be used instead of `PositionEvent`.
Drag Events now expose the start and end position, as well as the delta,
correctly transformed by the camera and zoom.
This also ensures that drag events, once starts, do not get lost if the
drag update leaves the component bounds.



* if you are using `DragUpdateEvent` events, the `devicePosition`,
`canvasPosition`, `localPosition`, and `delta` are deprecated as they
are unclear.
* use `xStartPosition` to get the position at the start of the drag
event ("from")
* use `xEndPosition` to get the position at the end of the drag event
("to")
* if you want the delta, use `localDelta`. it now already considers the
camera zoom. no need to manually account for that
* now you keep receiving drag events for the same component even if the
mouse leaves the component (breaking)

---------

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2023-11-30 16:40:26 +01:00
f42d0e73be docs: Fix naming of drag- and tap-callbacks examples (#2873)
Fix naming of drag- and tap-callbacks examples
2023-11-26 17:55:35 +00:00
37f7b12f57 fix: Use world on tap_callbacks_example (#2875)
Use world on tap_callbacks_example. We should just standardize all
examples to use the world unless there is a reason not to, in order to
avoid confusing users.
2023-11-26 17:32:59 +00:00
39edc70206 docs: Fix Hover Callbacks so the tap used in the example respects the zoom (#2874)
Fix Hover Callbacks so the tap used in the example respects the zoom.

The example happens to use a tap event to create new squares. However,
since the tap event is bound to the Game instead of the World, had it
had any zoom applied (which it didn't), or any other camera transform,
the squares would have been created on the wrong place. This sends a bad
example to new users and can cause confusion.
2023-11-26 18:26:00 +01:00
5b67b8f14a fix: Remove deprecations for 1.10.0 (#2809)
Removed deprecations for 1.10.0 and fixes some small unreleased regressions found when going through the examples.
2023-10-11 15:57:25 +02:00
97fff0ed2b feat: Add advanced button component (#2742)
New button with support for multiple states:
<img width="278" alt="image"
src="https://github.com/flame-engine/flame/assets/18004353/041c1105-8991-4976-b1a2-0553c149ec4e">
2023-10-10 21:43:28 +02:00
152fbb61db docs: Fix examples for v1.9.0 (#2757)
Fixed up some examples that needed fixing before releasing v1.9.0
2023-09-21 19:24:40 +00:00
9c1e1c3098 chore: Remove deprecations for v1.9.0 (#2749)
Removes everything that was marked as deprecated and that should be
removed for v1.9.0.
2023-09-19 16:47:41 +02:00
7c2f400076 feat!: Add CameraComponent to FlameGame (#2740)
This PR adds the `CameraComponent` and a `World` by default to the
FlameGame.
2023-09-18 21:06:37 +02:00
7a3d5126a5 feat!: Move Forge2DGame to use CameraComponent (#2728)
This enables flame_forge2d to work with the CameraComponent and the new event system.
2023-09-16 08:08:29 +00:00
d460b846c2 feat: Add HoverCallbacks (#2706)
This creates HoverCallbacks (and PointerMoveCallbacks) to replicate the Hoverables behaviour in the new camera and event system.
2023-09-10 14:49:52 -04:00
4b420b7952 refactor!: Rename (Text) Elements, Nodes and Styles for clarity, add docs (#2700)
This occurred to me after a discussion on the [new FCS component
PR](https://github.com/flame-engine/flame/pull/2694#discussion_r1312450113).
As per usual, @spydon has opened my eyes to the ultimate truth:

We should rename loads of files, and it shall affect almost no one.

The idea is to (1) add a "Text" prefix to all text-rendering-related
classes and (2) rename the existing `Text*` to `InlineText*` (which is
what they are).

This PR is a bit big, but the changes should hopefully be simple to
review, and can be broken down into:

* Add a proper base class for the node inheritance chain, call it
TextNode (while working on Flame Markdown I realized the value this will
have to me)
* Rename the old TextNode to InlineTextNode
* Rename DocumentNode to DocumentRoot because it is not a node
* Rename Element to TextElement
* Rename the old TextElement to InlineTextElement
* Rename Style to FlameTextStyle (note: we could consider dropping the
Flame here)
* Rename the old FlameTextStyle to InlineTextStyle
* Update the docs accordingly
* Add some more diagrams and explanations to the docs, following the new
nomenclature
* I also updated our "internal" imports to use the text module to make
life so much easier (this could arguably be done in a separate PR, but I
honestly think it's easier to review together, please lmk if you prefer
me to split).

These are all breaking changes but likely won't actually affect most
users (see below).

While this is breaking, it should hopefully not affect most users,
because these are all infrastructure classes that most people aren't
using directly. If you are using the FCS components, or the renderers
`TextPaint` or `SpriteFontRenderer` directly, this should have zero
effect to you.

If you are using the Nodes, Stlyes or Elements directly, or have a
custom TextRenderer, see below.

Migrating should be a simple matter of renaming your type references:

* from TextNode to InlineTextNode
* from TextElement to InlineTextElement
* from Element to TextElement
* from FlameTextStyle to InlineTextStyle
* from Style to FlameTextStyle

Make sure to do it in the appropriate order not to cause any
double-replace issues.

If you are importing via the module `package:flame/text.dart`, which we
highly encourage, you should not have to change any import statements
whatsoever.
2023-09-02 12:59:59 -04:00
a1cb9a06ad refactor!: Kill TextRenderer, Long Live TextRenderer (#2683)
This will:

    kill the TextRenderer inheritance chain
    incorporate the functionality of the base TextRenderer in the base TextFormatter
    rename TextFormatter to TextRenderer and appropriate references

That is because both essentially do the same job; encompass the style (or "how") information about how to render text, but using two slightly different interfaces. While that could allow for more flexibility, it is a faux choice that needlessly complicates the pipeline. By having a single interface to comply with, we still allow for custom renders while at the same time making all the code downstream simpler to use and understand.
2023-08-27 21:47:01 +02:00
1a64443cca refactor!: Make TextElement more usable on its own (#2679)
This is part of my ongoing effort to simplify the text rendering
pipeline.
My ultimate goal is to:
* get rid of renders
* rename formatters to renderers
* make the interface complies to both
All details are specified here:
https://github.com/flame-engine/flame/pull/2663

As a first step to break down that huge PR, this makes a small change to
TextElements to make them more useful

This PR will:
### rename render -> draw

draw becomes the "internal", underlying impl, raw method, that just
draws the element w/ any custom options

### add a new render method that takes in more options

this does not need to be extended by every impl.
this is for end users and accepts parameters like position and anchor to
be more in line with the renderer interface

This is technically a breaking change but should have no effect for
users, unless you are creating your own custom `TextElement`s. In that
case, to migrate:

* rename your `render` method to `draw`
2023-08-26 12:10:03 -04:00
10e4109c81 refactor: Fix lint issues across the codebase - Part 2 (#2677)
Fix a handful of lint issues across the codebase, identified using DCM.
Nothing controversial, I expect; slowly getting these out of the way so
we can focus on discussing bigger things.
2023-08-25 18:15:17 +00:00
e852064e49 fix: Viewport should recieve events before the world (#2630)
The viewport should receive events before the world, otherwise all huds will get the events after the world components, if there are any world components underneath them.
2023-08-07 11:57:21 +00:00
b3efb612cb feat: ComponentKey API (#2566)
Adds a new key api on FCS, which will allow users to get a component from the tree, without needing to iterate over all the children or a parent descendants.
2023-06-20 09:36:15 -03:00
2d45d2be39 chore: Remove 1.8.0 deprecations (#2538)
Removes all the deprecated methods before 1.8.0 release.
2023-05-22 19:01:55 +02:00
87b8a067f3 refactor!: Move CameraComponent and events out of experimental (#2505)
This moves the CameraComponent and the new event system out of experimental since this now is the recommended way of handling things.
2023-04-19 09:55:32 +02:00
dbda37b81a refactor: Add new lint rules (#2477)
This PR adds the following lint rules to our list:

```
always_put_required_named_parameters_first
avoid_multiple_declarations_per_line
avoid_positional_boolean_parameters
avoid_returning_null_for_void
avoid_returning_this
avoid_unnecessary_containers
enable_null_safety
library_private_types_in_public_api
no_leading_underscores_for_library_prefixes
no_leading_underscores_for_local_identifiers
prefer_null_aware_method_calls
tighten_type_of_initializing_formals
unnecessary_late
use_setters_to_change_properties
```

And these rules were considered, and some changes were made according to
them as a clean-up, but in many places they didn't make sense
(`prefer_asserts_with_message` I would have included, but there were too
many places that needed to be changes):

```
collection_methods_unrelated_type
prefer_asserts_with_message
avoid_renaming_method_parameters
```
2023-04-13 19:42:00 +00:00
de630a1c3a feat: Add isDragged in DragCallbacks mixin (#2472)
Adding a isDragged state for DragCallbacks mixin. This was available in the Draggable mixin.
2023-04-07 13:39:28 +02:00
b5bdf4ec17 feat!: The HasTappableComponents mixin is no longer needed (#2450)
This PR is the second in a series of refactors that aim to simplify event handling in Flame. The approach is as follows:

    Added the MultiTapDispatcher component, which contains the logic that used to be within the HasTappableComponents mixin. This component is internal; it mounts to a FlameGame directly, and ensures that it is a singleton.
    Whenever any TapCallbacks component is added to a game, it automatically adds the MultiTapDispatcher component (unless there is already one), which in turn registers a tap gesture detector with GestureDetectorBuilder and rebuilds the game widget.

The end result is that now in order to make a component tappable you only need to add the TapCallbacks mixin to that component, everything else will be handled by the framework.

Consequently, the HasTappableComponents mixin is now empty and marked as deprecated.
2023-04-02 16:52:57 +00:00
b5f79d1ce4 feat: Add DoubleTapCallbacks that receives double-tap events. (#2327)
As-is
As mentioned in #2321, the user needs to propagate double-tap events to the component tree using DoubleTapDetector & propagateToChildren until now.

To-be
Any components that are mixed into the DoubleTapCallbacks receive double-tap-related events.
Same as DragCallbacks, there is no need to add mixin to the game like HasDoubleTapCallbaks as before.
2023-02-10 19:29:36 +01:00
95b1fc0fbc feat: Added HardwareKeyboardDetector (#2257)
This creates a new component HardwareKeyboardDetector, which is a more advanced version of the KeyboardEvents mixin:

    HardwareKeyboardDetector is a component instead of a mixin, which means it can be added/removed by the user at any point;
    multiple such detectors can be attached to a game - for example, in a 2-player game one component may be paying attention to arrow keys, while another to WASD keys;
    the new component uses Flutter's HardwareKeyboard interface, bypassing the need for a Focus widget;
    the component keeps the ordered list of keys that are currently being pressed, which is helpful for games where this order is important;
    there is the ability to temporarily pause the reception of key events using keyEventsPaused property.
2023-01-27 21:57:42 +00:00
475b226911 docs: Fixed broken example links (#2030) 2022-10-06 10:15:32 +02:00
5bdb2a1ec8 docs: Improve keyboard input examples (#1907)
This PR updates the live keyboard examples to correctly handle multiple key inputs. This was discovered in #847.
2022-09-15 08:13:05 +02:00
b401c5485c docs: fix broken link for Keyboard Input Component (#1854) 2022-08-20 21:32:42 +00:00
8384a51d65 docs: Simplify draggable example (#1754)
The draggable example was overly complicated so I simplified it.
2022-06-27 14:57:58 -03:00
2a41d0d683 feat: Move to Flutter 3.0.0 and Dart 2.17.0 (#1713)
This upgrades all packages to Flutter 3.0.0 and fixes all analyze issues that came from that.
2022-06-08 06:04:40 +00:00
f55b2e0dc0 feat: Callbacks in HudButtonComponent constructor and ViewportMargin mixin to avoid code duplication (#1685)
Created a mixin to handle the margin to the viewport, mostly to remove the code duplication in ButtonComponent and HudButtonComponent, but it can also be useful in other cases when you don't want to wrap your component in HudMarginComponent.

Once the new camera system is in place this will of course have to be replaced.
2022-06-04 17:00:12 +02:00
c887c3616e feat: adding KeyboardListenerComponent (#1594) 2022-05-23 06:32:10 +00:00
821d01c3fa fix!: Game.mouseCursor and Game.overlays can now be safely set during onLoad (#1498) 2022-05-20 21:49:29 +02:00
843ddc3624 refactor: Move to package imports (#1625)
* refactor: Move to package imports

* Fix local imports

* Removed unused imports
2022-05-15 15:04:35 +00:00
295468f03c feat: Add Transform2D.setFrom and Transform2D.clone (#1495) 2022-03-27 21:48:26 +00:00
4c3960c341 feat: Possibility to mark gesture events as handled (#1465) 2022-03-19 18:07:06 +01:00
dfeafdd6f3 fix: Fix collision detection comments and typo (#1422)
* Fix collision detection comments and typo

* Update packages/flame/lib/src/collisions/collision_callbacks.dart

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

* Update doc/flame/collision_detection.md

Co-authored-by: Pasha Stetsenko <stpasha@google.com>

Co-authored-by: Pasha Stetsenko <stpasha@google.com>
2022-03-08 14:38:21 +01:00
29dd09ca92 feat(collision detection)!: Use a broadphase to make collision detection more efficient (#1252) 2022-03-07 09:08:32 +01:00
05f7a4c3d6 refactor: Remove Loadable, optional onLoads (#1333) 2022-01-24 23:23:12 +01:00
27adda17b7 fix!: Remove pointerId from Draggable callbacks (#1313)
Since pointerId is already handled by the handle* methods we don't have to expose it in the onDrag* methods, this conforms with the standard set in Tappable.
2022-01-18 23:22:10 +01:00