Skip to content

Commit 9ee2e8e

Browse files
committed
add layer alpha interface to ios and andriod fix format
1 parent 7e2564a commit 9ee2e8e

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

android/libpag/src/main/java/org/libpag/PAGLayer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public Matrix getTotalMatrix() {
178178
*/
179179
public native void setAlpha(float value);
180180

181+
/**
182+
* Returns the current alpha of the layer if previously set.
183+
*/
184+
public native float alpha();
185+
181186
private native void nativeRelease();
182187

183188
protected long nativeContext;

src/platform/android/JPAGLayer.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,21 @@ PAG_API void Java_org_libpag_PAGLayer_setExcludedFromTimeline(JNIEnv* env, jobje
298298
pagLayer->setExcludedFromTimeline(value);
299299
}
300300

301-
PAG_API void Java_org_libpag_PAGLayer_setAlpha(JNIEnv* env, jobject thiz,
302-
jfloat value){
301+
PAG_API void Java_org_libpag_PAGLayer_setAlpha(JNIEnv* env, jobject thiz, jfloat value) {
303302
auto pagLayer = GetPAGLayer(env, thiz);
304-
if(pagLayer == nullptr){
303+
if (pagLayer == nullptr) {
305304
return;
306305
}
307306

308307
pagLayer->setAlpha(value);
309308
}
309+
310+
PAG_API jfloat Java_org_libpag_PAGLayer_alpha(JNIEnv* env, jobject thiz) {
311+
auto pagLayer = GetPAGLayer(env, thiz);
312+
if (pagLayer == nullptr) {
313+
return 0.0f;
314+
}
315+
316+
return pagLayer->alpha();
317+
}
310318
}

src/platform/cocoa/PAGLayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,9 @@ PAG_API @interface PAGLayer : NSObject
171171
*/
172172
- (void)setAlpha:(float)value;
173173

174+
/**
175+
* Returns the current alpha of the layer if previously set.
176+
*/
177+
- (float)alpha;
178+
174179
@end

src/platform/cocoa/PAGLayer.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ - (void)setExcludedFromTimeline:(BOOL)value {
133133
[(PAGLayerImpl*)_impl setExcludedFromTimeline:value];
134134
}
135135

136-
- (void)setAlpha:(float)value{
136+
- (void)setAlpha:(float)value {
137137
[(PAGLayerImpl*)_impl setAlpha:value];
138138
}
139139

140+
- (float)alpha {
141+
return [(PAGLayerImpl*)_impl alpha];
142+
}
143+
140144
- (void)dealloc {
141145
[_impl release];
142146
[super dealloc];

src/platform/cocoa/private/PAGLayerImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@
7474

7575
- (void)setAlpha:(float)value;
7676

77+
- (float)alpha;
78+
7779
@end

src/platform/cocoa/private/PAGLayerImpl.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,8 @@ - (void)setAlpha:(float)value {
258258
_pagLayer->setAlpha(value);
259259
}
260260

261+
- (float)alpha {
262+
return _pagLayer->alpha();
263+
}
264+
261265
@end

0 commit comments

Comments
 (0)