16
16
17
17
#include "kino_layer.h"
18
18
19
+ #include <stdint.h> // For uintptr_t
20
+
19
21
#include "applib/applib_malloc.auto.h"
20
22
#include "applib/graphics/graphics.h"
21
23
24
+ static GColor prv_invert_bw_color (GColor color ) {
25
+ if (gcolor_equal (color , GColorBlack )) {
26
+ return GColorWhite ;
27
+ } else if (gcolor_equal (color , GColorWhite )) {
28
+ return GColorBlack ;
29
+ }
30
+ return color ;
31
+ }
32
+
33
+ static void prv_invert_pdc_colors (GDrawCommandProcessor * processor , GDrawCommand * processed_command ,
34
+ size_t processed_command_max_size , const GDrawCommandList * list ,
35
+ const GDrawCommand * command ) {
36
+ gdraw_command_set_stroke_color (
37
+ processed_command ,
38
+ prv_invert_bw_color (gdraw_command_get_stroke_color ((GDrawCommand * )command )));
39
+ gdraw_command_set_fill_color (
40
+ processed_command ,
41
+ prv_invert_bw_color (gdraw_command_get_fill_color ((GDrawCommand * )command )));
42
+ }
43
+
44
+ GDrawCommandProcessor prv_gdraw_inv_processor = {
45
+ .command = prv_invert_pdc_colors ,
46
+ };
47
+
48
+ KinoReelProcessor PRV_INVERT_COLORS_PROCESSOR = {.draw_command_processor = & prv_gdraw_inv_processor };
49
+
22
50
static void prv_update_proc (Layer * layer , GContext * ctx ) {
23
51
KinoLayer * kino_layer = (KinoLayer * )layer ;
24
52
@@ -35,7 +63,9 @@ static void prv_update_proc(Layer *layer, GContext *ctx) {
35
63
}
36
64
37
65
const GRect reel_bounds = kino_layer_get_reel_bounds (kino_layer );
38
- kino_player_draw (& kino_layer -> player , ctx , reel_bounds .origin );
66
+
67
+ KinoReelProcessor processor = kino_layer -> invert_colors ? PRV_INVERT_COLORS_PROCESSOR : (KinoReelProcessor ){};
68
+ kino_player_draw_processed (& kino_layer -> player , ctx , reel_bounds .origin , & processor );
39
69
}
40
70
41
71
//////////////////////
@@ -66,10 +96,12 @@ void kino_layer_init(KinoLayer *kino_layer, const GRect *frame) {
66
96
// init kino layer
67
97
kino_layer -> background_color = GColorClear ;
68
98
// init kino player
69
- kino_player_set_callbacks (& kino_layer -> player , (KinoPlayerCallbacks ){
70
- .frame_did_change = prv_player_frame_did_change ,
71
- .did_stop = prv_player_did_stop ,
72
- }, kino_layer );
99
+ kino_player_set_callbacks (& kino_layer -> player ,
100
+ (KinoPlayerCallbacks ){
101
+ .frame_did_change = prv_player_frame_did_change ,
102
+ .did_stop = prv_player_did_stop ,
103
+ },
104
+ kino_layer );
73
105
}
74
106
75
107
void kino_layer_deinit (KinoLayer * kino_layer ) {
@@ -107,22 +139,26 @@ void kino_layer_set_reel(KinoLayer *kino_layer, KinoReel *reel, bool take_owners
107
139
kino_player_set_reel (& kino_layer -> player , reel , take_ownership );
108
140
}
109
141
142
+ void kino_layer_set_invert_colors (KinoLayer * kino_layer , bool invert ) {
143
+ // Store the invert flag in the LSB of the context pointer
144
+ kino_layer -> invert_colors = invert ;
145
+ }
146
+
110
147
void kino_layer_set_reel_with_resource (KinoLayer * kino_layer , uint32_t resource_id ) {
111
148
kino_player_set_reel_with_resource (& kino_layer -> player , resource_id );
112
149
}
113
150
114
151
void kino_layer_set_reel_with_resource_system (KinoLayer * kino_layer , ResAppNum app_num ,
115
- uint32_t resource_id ) {
152
+ uint32_t resource_id , bool invert ) {
153
+ kino_layer_set_invert_colors (kino_layer , invert );
116
154
kino_player_set_reel_with_resource_system (& kino_layer -> player , app_num , resource_id );
117
155
}
118
156
119
157
KinoReel * kino_layer_get_reel (KinoLayer * kino_layer ) {
120
158
return kino_player_get_reel (& kino_layer -> player );
121
159
}
122
160
123
- KinoPlayer * kino_layer_get_player (KinoLayer * kino_layer ) {
124
- return & kino_layer -> player ;
125
- }
161
+ KinoPlayer * kino_layer_get_player (KinoLayer * kino_layer ) { return & kino_layer -> player ; }
126
162
127
163
void kino_layer_set_alignment (KinoLayer * kino_layer , GAlign alignment ) {
128
164
kino_layer -> alignment = alignment ;
@@ -134,9 +170,7 @@ void kino_layer_set_background_color(KinoLayer *kino_layer, GColor color) {
134
170
layer_mark_dirty (& kino_layer -> layer );
135
171
}
136
172
137
- void kino_layer_play (KinoLayer * kino_layer ) {
138
- kino_player_play (& kino_layer -> player );
139
- }
173
+ void kino_layer_play (KinoLayer * kino_layer ) { kino_player_play (& kino_layer -> player ); }
140
174
141
175
void kino_layer_play_section (KinoLayer * kino_layer , uint32_t from_position , uint32_t to_position ) {
142
176
kino_player_play_section (& kino_layer -> player , from_position , to_position );
@@ -146,27 +180,21 @@ ImmutableAnimation *kino_layer_create_play_animation(KinoLayer *kino_layer) {
146
180
return kino_player_create_play_animation (& kino_layer -> player );
147
181
}
148
182
149
- ImmutableAnimation * kino_layer_create_play_section_animation (
150
- KinoLayer * kino_layer , uint32_t from_position , uint32_t to_position ) {
151
- return kino_player_create_play_section_animation ( & kino_layer -> player , from_position ,
152
- to_position );
183
+ ImmutableAnimation * kino_layer_create_play_section_animation (KinoLayer * kino_layer ,
184
+ uint32_t from_position ,
185
+ uint32_t to_position ) {
186
+ return kino_player_create_play_section_animation ( & kino_layer -> player , from_position , to_position );
153
187
}
154
188
155
- void kino_layer_pause (KinoLayer * kino_layer ) {
156
- kino_player_pause (& kino_layer -> player );
157
- }
189
+ void kino_layer_pause (KinoLayer * kino_layer ) { kino_player_pause (& kino_layer -> player ); }
158
190
159
- void kino_layer_rewind (KinoLayer * kino_layer ) {
160
- kino_player_rewind (& kino_layer -> player );
161
- }
191
+ void kino_layer_rewind (KinoLayer * kino_layer ) { kino_player_rewind (& kino_layer -> player ); }
162
192
163
193
GColor kino_layer_get_background_color (KinoLayer * kino_layer ) {
164
194
return kino_layer -> background_color ;
165
195
}
166
196
167
- GAlign kino_layer_get_alignment (KinoLayer * kino_layer ) {
168
- return kino_layer -> alignment ;
169
- }
197
+ GAlign kino_layer_get_alignment (KinoLayer * kino_layer ) { return kino_layer -> alignment ; }
170
198
171
199
GRect kino_layer_get_reel_bounds (KinoLayer * kino_layer ) {
172
200
KinoPlayer * player = kino_layer_get_player (kino_layer );
0 commit comments