@@ -8,6 +8,7 @@ use graphene::Quad;
8
8
use glam:: { DAffine2 , DVec2 } ;
9
9
use serde:: { Deserialize , Serialize } ;
10
10
11
+ use crate :: input:: keyboard:: Key ;
11
12
use crate :: input:: { mouse:: ViewportPosition , InputPreprocessor } ;
12
13
use crate :: tool:: { DocumentToolData , Fsm , ToolActionHandlerData } ;
13
14
use crate :: {
@@ -25,7 +26,7 @@ pub struct Select {
25
26
#[ impl_message( Message , ToolMessage , Select ) ]
26
27
#[ derive( PartialEq , Clone , Debug , Serialize , Deserialize , Hash ) ]
27
28
pub enum SelectMessage {
28
- DragStart ,
29
+ DragStart { add_to_selection : Key } ,
29
30
DragStop ,
30
31
MouseMove ,
31
32
Abort ,
@@ -136,7 +137,7 @@ impl Fsm for SelectToolFsmState {
136
137
responses. push_back ( response) ;
137
138
self
138
139
}
139
- ( Ready , DragStart ) => {
140
+ ( Ready , DragStart { add_to_selection } ) => {
140
141
data. drag_start = input. mouse . position ;
141
142
data. drag_current = input. mouse . position ;
142
143
let mut selected: Vec < _ > = document. selected_layers ( ) . cloned ( ) . collect ( ) ;
@@ -146,7 +147,7 @@ impl Fsm for SelectToolFsmState {
146
147
if selected. is_empty ( ) {
147
148
if let Some ( layer) = intersection. last ( ) {
148
149
selected. push ( layer. clone ( ) ) ;
149
- responses. push_back ( DocumentMessage :: SelectLayers ( selected. clone ( ) ) . into ( ) ) ;
150
+ responses. push_back ( DocumentMessage :: SetSelectedLayers ( selected. clone ( ) ) . into ( ) ) ;
150
151
}
151
152
}
152
153
// If the user clicks on a layer that is in their current selection, go into the dragging mode.
@@ -155,7 +156,9 @@ impl Fsm for SelectToolFsmState {
155
156
data. layers_dragging = selected;
156
157
Dragging
157
158
} else {
158
- responses. push_back ( DocumentMessage :: DeselectAllLayers . into ( ) ) ;
159
+ if !input. keyboard . get ( add_to_selection as usize ) {
160
+ responses. push_back ( DocumentMessage :: DeselectAllLayers . into ( ) ) ;
161
+ }
159
162
data. drag_box_id = Some ( add_boundnig_box ( responses) ) ;
160
163
DrawingBox
161
164
}
@@ -176,8 +179,9 @@ impl Fsm for SelectToolFsmState {
176
179
}
177
180
( DrawingBox , MouseMove ) => {
178
181
data. drag_current = input. mouse . position ;
179
- let start = data. drag_start ;
180
- let size = data. drag_current - start;
182
+ let half_pixel_offset = DVec2 :: new ( 0.5 , 0.5 ) ;
183
+ let start = data. drag_start + half_pixel_offset;
184
+ let size = data. drag_current - start + half_pixel_offset;
181
185
182
186
responses. push_back (
183
187
Operation :: SetLayerTransformInViewport {
@@ -191,14 +195,14 @@ impl Fsm for SelectToolFsmState {
191
195
( Dragging , DragStop ) => Ready ,
192
196
( DrawingBox , DragStop ) => {
193
197
let quad = data. selection_quad ( ) ;
194
- responses. push_back ( DocumentMessage :: SelectLayers ( document. document . intersects_quad_root ( quad) ) . into ( ) ) ;
198
+ responses. push_back ( DocumentMessage :: AddSelectedLayers ( document. document . intersects_quad_root ( quad) ) . into ( ) ) ;
195
199
responses. push_back (
196
200
Operation :: DeleteLayer {
197
201
path : data. drag_box_id . take ( ) . unwrap ( ) ,
198
202
}
199
203
. into ( ) ,
200
204
) ;
201
- data. drag_box_id = None ;
205
+ data. drag_box_id = None ;
202
206
Ready
203
207
}
204
208
( _, Abort ) => {
0 commit comments