Skip to content

Commit 73ed016

Browse files
committed
PhotoPicker plugin implementation
1 parent 676d1de commit 73ed016

File tree

9 files changed

+618
-3
lines changed

9 files changed

+618
-3
lines changed

SConstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'arm
2424
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
2525
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
2626
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
27-
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore']))
27+
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker']))
2828
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.3', '4.0']))
2929

3030
# Updates the environment with the option variables.

plugins/photo_picker/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Godot PhotoPicker plugin
2+
3+
Example:
4+
5+
```
6+
var _picker = null
7+
8+
func _image_picked(image):
9+
var texture = ImageTexture.new()
10+
texture.create_from_image(image)
11+
icon.texture = texture
12+
13+
func _permission_updated(target, status):
14+
match (target):
15+
apns.PERMISSION_TARGET_PHOTO_LIBRARY:
16+
print("photo library")
17+
apns.PERMISSION_TARGET_CAMERA:
18+
print("camera")
19+
20+
match (status):
21+
apns.PERMISSION_STATUS_UNKNOWN:
22+
print("unknown")
23+
apns.PERMISSION_STATUS_ALLOWED:
24+
print("allowed")
25+
apns.PERMISSION_STATUS_DENIED:
26+
print("denied")
27+
28+
func _on_Button_button_down():
29+
apns.present(apns.SOURCE_SAVED_PHOTOS_ALBUM);
30+
apns.present(apns.SOURCE_CAMERA_REAR);
31+
apns.present(apns.SOURCE_CAMERA_FRONT);
32+
33+
print(apns.permission_status(apns.PERMISSION_TARGET_CAMERA))
34+
print(apns.permission_status(apns.PERMISSION_TARGET_PHOTO_LIBRARY))
35+
36+
apns.request_permission(apns.PERMISSION_TARGET_CAMERA)
37+
apns.request_permission(apns.PERMISSION_TARGET_PHOTO_LIBRARY)
38+
39+
...
40+
41+
func _ready():
42+
if Engine.has_singleton("PhotoPicker"):
43+
_picker = Engine.get_singleton("PhotoPicker")
44+
_picker.connect("image_picked", self, "_image_picked")
45+
_picker.connect("permission_updated", self, "_permission_updated")
46+
print("registering photo picker")
47+
else:
48+
print("no photo picker")
49+
```
50+
51+
## Enum
52+
53+
Type: `PhotoPickerSourceType`
54+
Values: `SOURCE_PHOTO_LIBRARY`, `SOURCE_CAMERA_FRONT`, `SOURCE_CAMERA_REAR`, `SOURCE_SAVED_PHOTOS_ALBUM`
55+
56+
Type: `PhotoPickerPermissionTarget`
57+
Values: `PERMISSION_TARGET_PHOTO_LIBRARY`, `PERMISSION_TARGET_CAMERA`
58+
59+
Type: `PhotoPickerPermissionStatus`
60+
Values: `PERMISSION_STATUS_UNKNOWN`, `PERMISSION_STATUS_ALLOWED`, `PERMISSION_STATUS_DENIED`
61+
62+
## Methods
63+
64+
`permission_status(PhotoPickerPermissionTarget target): PhotoPickerPermissionStatus` - Returns a permissions status for specific photo picker target.
65+
`request_permission(PhotoPickerPermissionTarget target)` - Performs a permission request for photo picker permission target if needed.
66+
`present(PhotoPickerSourceType source)` - Presents a photo picker with specific source type that allows to select an image or take a picture from camera.
67+
68+
## Properties
69+
70+
## Signals
71+
72+
`image_picked(Ref<Image> image)` - Called whenever user selects an image from a library or takes a photo.
73+
`permission_updated(PhotoPickerPermissionTarget image)` - Called when user changes permission status after `request_permission` is called.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[config]
2+
name="PhotoPicker"
3+
binary="photo_picker.xcframework"
4+
5+
initialization="godot_photopicker_init"
6+
deinitialization="godot_photopicker_deinit"
7+
8+
[dependencies]
9+
linked=[]
10+
embedded=[]
11+
system=[]
12+
13+
capabilities=[]
14+
15+
files=[]
16+
17+
[plist]
18+
NSPhotoLibraryUsageDescription:string_input="Photo Library usage description"
19+
NSCameraUsageDescription:string_input="Camera usage description"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*************************************************************************/
2+
/* photo_picker.h */
3+
/*************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/*************************************************************************/
8+
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
9+
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/*************************************************************************/
30+
31+
#ifndef PHOTO_PICKER_H
32+
#define PHOTO_PICKER_H
33+
34+
#include "core/version.h"
35+
36+
#include "core/image.h"
37+
#include "core/object.h"
38+
39+
#ifdef __OBJC__
40+
@class GodotPhotoPicker;
41+
#else
42+
typedef void GodotPhotoPicker;
43+
#endif
44+
45+
class PhotoPicker : public Object {
46+
GDCLASS(PhotoPicker, Object);
47+
48+
static void _bind_methods();
49+
50+
GodotPhotoPicker *godot_photo_picker;
51+
52+
public:
53+
enum PhotoPickerSourceType {
54+
SOURCE_PHOTO_LIBRARY = 1 << 0,
55+
SOURCE_CAMERA_FRONT = 1 << 1,
56+
SOURCE_CAMERA_REAR = 1 << 2,
57+
SOURCE_SAVED_PHOTOS_ALBUM = 1 << 3,
58+
};
59+
60+
enum PhotoPickerPermissionTarget {
61+
PERMISSION_TARGET_PHOTO_LIBRARY = 1 << 0,
62+
PERMISSION_TARGET_CAMERA = 1 << 1,
63+
};
64+
65+
enum PhotoPickerPermissionStatus {
66+
PERMISSION_STATUS_UNKNOWN = 1 << 0,
67+
PERMISSION_STATUS_ALLOWED = 1 << 1,
68+
PERMISSION_STATUS_DENIED = 1 << 2,
69+
};
70+
71+
static PhotoPicker *get_singleton();
72+
73+
void present(PhotoPickerSourceType source);
74+
void request_permission(PhotoPickerPermissionTarget target);
75+
PhotoPickerPermissionStatus permission_status(PhotoPickerPermissionTarget target);
76+
77+
void select_image(Ref<Image> image);
78+
void update_permission_status(PhotoPicker::PhotoPickerPermissionTarget target, PhotoPicker::PhotoPickerPermissionStatus status);
79+
80+
PhotoPicker();
81+
~PhotoPicker();
82+
};
83+
84+
VARIANT_ENUM_CAST(PhotoPicker::PhotoPickerSourceType)
85+
VARIANT_ENUM_CAST(PhotoPicker::PhotoPickerPermissionTarget)
86+
VARIANT_ENUM_CAST(PhotoPicker::PhotoPickerPermissionStatus)
87+
88+
#endif

0 commit comments

Comments
 (0)