createRect method
Implementation
CanvasRects createRect(Size size, Vector3 position, Color color, int i, int currentRect, {int j = 0, SelectedType type = SelectedType.rect}){
size *= camera.zoom;
Vector3 newPosition = Vector3.copy(position)..scale(camera.zoom);
newPosition.applyMatrix4(camera.lookAtMatrix);
Rect rect = Rect.fromLTWH(newPosition.x, newPosition.y, size.width, size.height);
double area = size.width*size.height;
bool isAllowed = false;
bool isDifferent = true;
if(objectTappedOn.isNotEmpty && isControlPressed){
if(objectTappedOn[0].type == SelectedType.image && objectTappedOn[0].type == type){
isAllowed = true;
}
else if(objectTappedOn[0].type == SelectedType.rect && objectTappedOn[0].type == type && objectTappedOn[0].animation == i){
isAllowed = true;
}
}
else if(objectTappedOn.isEmpty){
isAllowed = true;
}
if(objectTappedOn.isNotEmpty){
for(int k = 0; k < objectTappedOn.length;k++){
if(objectTappedOn[k].type == type && objectTappedOn[k].animation == i && objectTappedOn[k].frame == j){
isDifferent = false;
color = Colors.green;
break;
}
}
}
logger?.verbose(type == selectableType);
if(tapLocation != null && rect.contains(tapLocation!) && isDifferent && type == selectableType){
isClicked = true;
if(currentSize == null){
currentSize = area;
objectTappedOn.add(SelectedObjects(type: type,frame: j,animation: i, toColor: currentRect));
}
else if(currentSize! > area || isAllowed){
currentSize = area;
if(objectTappedOn.length == 1 && !isAllowed){
objectTappedOn[0] = SelectedObjects(type: type,frame: j,animation: i, toColor: currentRect);
}
else if(isAllowed){
objectTappedOn.add(SelectedObjects(type: type,frame: j,animation: i, toColor: currentRect));
}
}
color = Colors.green;
}
return CanvasRects(rect: rect, color: color, name: (j+1).toString(), type: type);
}