Skip to content

Commit cdcc1b7

Browse files
authored
Responsive layout improvements (#119)
* Work in progress * Replace brackets with parantheses * Introduce fit + align modes * Project update * Fix positioning when using "game" coordinate system * Mouse input fixes * Normalize input in the component * Use view matrix * Update documentation * Update plugins and content
1 parent 79903b3 commit cdcc1b7

37 files changed

+607
-970
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ builtins
1717
/bundle*
1818
bob.jar
1919
/defold-rive/lib/**/ext.settings
20-
/.editor_settings
20+
/.editor_settings
21+
*.keystore*
22+
manifest.*

defold-rive/api/rive.script_api

+10
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,13 @@
235235
type: string
236236
desc: (OPTIONAL) If specified, the text run will be set in the specified nested artboard
237237

238+
#*****************************************************************************************************
239+
240+
- name: get_projection_matrix
241+
type: function
242+
desc: Get an orthographic projection matrix that can be used to project regular Defold components into the same coordinate space as the rive model when using the 'fullscreen' coordinate space.
243+
244+
return:
245+
- name: matrix
246+
type: vmath.matrix4
247+
desc: The projection matrix

defold-rive/commonsrc/rive_ddf.proto

+39-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ option java_outer_classname = "Rive";
99

1010
message RiveSceneDesc
1111
{
12-
required string scene = 1 [(resource)=true];
13-
optional string atlas = 2 [(resource)=true];
12+
required string scene = 1 [(resource)=true];
13+
optional string atlas = 2 [(resource)=true];
1414
}
1515

1616
message RiveModelDesc
@@ -23,6 +23,39 @@ message RiveModelDesc
2323
BLEND_MODE_SCREEN = 4 [(displayName) = "Screen"];
2424
}
2525

26+
// Matches rive::Fit (see layout.hpp)
27+
enum Fit
28+
{
29+
FIT_FILL = 0 [(displayName) = "Fill"];
30+
FIT_CONTAIN = 1 [(displayName) = "Contain"];
31+
FIT_COVER = 2 [(displayName) = "Cover"];
32+
FIT_FIT_WIDTH = 3 [(displayName) = "Fit Width"];
33+
FIT_FIT_HEIGHT = 4 [(displayName) = "Fit Height"];
34+
FIT_NONE = 5 [(displayName) = "None"];
35+
FIT_SCALE_DOWN = 6 [(displayName) = "ScaleDown"];
36+
FIT_LAYOUT = 7 [(displayName) = "Layout"];
37+
}
38+
39+
// Matches rive::Alignment (see layout.hpp)
40+
enum Alignment
41+
{
42+
ALIGNMENT_TOP_LEFT = 0 [(displayName) = "Top Left"];
43+
ALIGNMENT_TOP_CENTER = 1 [(displayName) = "Top Center"];
44+
ALIGNMENT_TOP_RIGHT = 2 [(displayName) = "Top Right"];
45+
ALIGNMENT_CENTER_LEFT = 3 [(displayName) = "Center Left"];
46+
ALIGNMENT_CENTER = 4 [(displayName) = "Center"];
47+
ALIGNMENT_CENTER_RIGHT = 5 [(displayName) = "Center Right"];
48+
ALIGNMENT_BOTTOM_LEFT = 6 [(displayName) = "Bottom Left"];
49+
ALIGNMENT_BOTTOM_CENTER = 7 [(displayName) = "Bottom Center"];
50+
ALIGNMENT_BOTTOM_RIGHT = 8 [(displayName) = "Bottom Right"];
51+
}
52+
53+
enum CoordinateSystem
54+
{
55+
COORDINATE_SYSTEM_FULLSCREEN = 0 [(displayName) = "Fullscreen"];
56+
COORDINATE_SYSTEM_RIVE = 1 [(displayName) = "Rive"];
57+
}
58+
2659
required string scene = 1 [(resource)=true];
2760
required string default_animation = 2;
2861
optional string material = 3 [(resource)=true, default="/defold-rive/assets/rivemodel.material"];
@@ -31,6 +64,10 @@ message RiveModelDesc
3164
optional bool create_go_bones = 6 [default=false];
3265
optional string artboard = 7;
3366

67+
optional CoordinateSystem coordinate_system = 8 [default = COORDINATE_SYSTEM_FULLSCREEN];
68+
optional Fit artboard_fit = 9 [default = FIT_NONE];
69+
optional Alignment artboard_alignment = 10 [default = ALIGNMENT_CENTER];
70+
3471
// E.g. various per-instance tesselation options
3572
//optional float tesselation_option1 = 4 [default = 0.0];
3673
}

defold-rive/editor/src/rive.clj

+22-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
(def rive-scene-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveSceneDesc"))
4343
(def rive-model-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveModelDesc"))
4444
(def blend-mode-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveModelDesc$BlendMode"))
45+
(def coordinate-system-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveModelDesc$CoordinateSystem"))
46+
(def artboard-fit-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveModelDesc$Fit"))
47+
(def artboard-alignment-pb-class (workspace/load-class! "com.dynamo.rive.proto.Rive$RiveModelDesc$Alignment"))
4548

4649
(def rive-file-icon "/defold-rive/editor/resources/icons/32/Icons_17-Rive-file.png")
4750
(def rive-scene-icon "/defold-rive/editor/resources/icons/32/Icons_16-Rive-scene.png")
@@ -95,7 +98,10 @@
9598
default-animation :default-animation
9699
default-state-machine :default-state-machine
97100
blend-mode :blend-mode
98-
create-go-bones :create-go-bones))))
101+
create-go-bones :create-go-bones
102+
coordinate-system :coordinate-system
103+
artboard-fit :artboard-fit
104+
artboard-alignment :artboard-alignment))))
99105

100106
(g/defnk produce-transform [position rotation scale]
101107
(math/->mat4-non-uniform (Vector3d. (double-array position))
@@ -605,7 +611,7 @@
605611
(dynamic error (g/fnk [_node-id atlas]
606612
(validate-scene-atlas _node-id atlas))))
607613

608-
; This property isn't visible, but here to allow us to preview the .spinescene
614+
; This property isn't visible, but here to allow us to preview the .rivescene
609615
(property material resource/Resource ; Default assigned in load-fn.
610616
(value (gu/passthrough material-resource))
611617
(set (fn [evaluation-context self old-value new-value]
@@ -667,15 +673,18 @@
667673
; .rivemodel (The "instance" file)
668674
;
669675

670-
(g/defnk produce-rivemodel-save-value [rive-scene-resource artboard default-animation default-state-machine material-resource blend-mode create-go-bones]
676+
(g/defnk produce-rivemodel-save-value [rive-scene-resource artboard default-animation default-state-machine material-resource blend-mode create-go-bones coordinate-system artboard-fit artboard-alignment]
671677
(protobuf/make-map-without-defaults rive-model-pb-class
672678
:scene (resource/resource->proj-path rive-scene-resource)
673679
:material (resource/resource->proj-path material-resource)
674680
:artboard artboard
675681
:default-animation default-animation
676682
:default-state-machine default-state-machine
677683
:blend-mode blend-mode
678-
:create-go-bones create-go-bones))
684+
:create-go-bones create-go-bones
685+
:coordinate-system coordinate-system
686+
:artboard-fit artboard-fit
687+
:artboard-alignment artboard-alignment))
679688

680689
(defn- validate-model-artboard [node-id rive-scene rive-artboards artboard]
681690
(when (and rive-scene (not-empty artboard))
@@ -788,6 +797,15 @@
788797
(dynamic edit-type (g/fnk [rive-anim-ids] (properties/->choicebox (cons "" rive-anim-ids)))))
789798
(property create-go-bones g/Bool (default (protobuf/default rive-model-pb-class :create-go-bones)))
790799

800+
(property coordinate-system g/Any (default (protobuf/default rive-model-pb-class :coordinate-system))
801+
(dynamic edit-type (g/constantly (properties/->pb-choicebox coordinate-system-pb-class))))
802+
803+
(property artboard-fit g/Any (default (protobuf/default rive-model-pb-class :artboard-fit))
804+
(dynamic edit-type (g/constantly (properties/->pb-choicebox artboard-fit-pb-class))))
805+
806+
(property artboard-alignment g/Any (default (protobuf/default rive-model-pb-class :artboard-alignment))
807+
(dynamic edit-type (g/constantly (properties/->pb-choicebox artboard-alignment-pb-class))))
808+
791809
(input dep-build-targets g/Any :array)
792810
(input rive-file-handle g/Any)
793811
(input rive-scene-resource resource/Resource)

0 commit comments

Comments
 (0)