summaryrefslogtreecommitdiff
path: root/src/aftereffects/OpenColorIO_AE_UI.cpp
blob: b5634bfbcac7264d6c3c416919e1daf0b24081c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
/*
Copyright (c) 2003-2012 Sony Pictures Imageworks Inc., et al.
All Rights Reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of Sony Pictures Imageworks nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include "OpenColorIO_AE.h"

#include "OpenColorIO_AE_Context.h"
#include "OpenColorIO_AE_Dialogs.h"

#include "DrawbotBot.h"



// UI drawing constants

#define LEFT_MARGIN         5
#define TOP_MARGIN          5
#define RIGHT_MARGIN        50

#define FILE_LABEL_WIDTH    35

#define FIELD_HEIGHT        22

#define FIELD_TEXT_INDENT_H 10
#define FIELD_TEXT_INDENT_V 4

#define BUTTONS_INDENT_H    (LEFT_MARGIN + 70)

#define BUTTONS_GAP_V       20
#define BUTTONS_GAP_H       30

#define BUTTON_HEIGHT       20
#define BUTTON_WIDTH        80

#define BUTTON_TEXT_INDENT_V 2

#define MENUS_INDENT_H      0

#define MENUS_GAP_V         20

#define MENU_LABEL_WIDTH    100
#define MENU_LABEL_SPACE    5

#define MENU_WIDTH          150
#define MENU_HEIGHT         20

#define MENU_TEXT_INDENT_H  10
#define MENU_TEXT_INDENT_V  2

#define MENU_ARROW_WIDTH    14
#define MENU_ARROW_HEIGHT   7

#define MENU_ARROW_SPACE_H  8
#define MENU_ARROW_SPACE_V  7

#define MENU_SHADOW_OFFSET  3

#define MENU_SPACE_V        20

#define TEXT_COLOR      PF_App_Color_TEXT_DISABLED



typedef enum {
    REGION_NONE=0,
    REGION_CONFIG_MENU,
    REGION_PATH,
    REGION_CONVERT_BUTTON,
    REGION_DISPLAY_BUTTON,
    REGION_EXPORT_BUTTON,
    REGION_MENU1,
    REGION_MENU2,
    REGION_MENU3
} UIRegion;


static UIRegion WhichRegion(PF_Point ui_point, bool menus, bool third_menu)
{
    int field_top = TOP_MARGIN;
    int field_bottom = field_top + FIELD_HEIGHT;
    
    if(ui_point.v >= field_top && ui_point.v <= field_bottom)
    {
        int menu_left = LEFT_MARGIN + MENUS_INDENT_H + MENU_LABEL_WIDTH;
        int menu_right = menu_left + MENU_WIDTH;
        
        if(ui_point.h >= menu_left && ui_point.h <= menu_right)
        {
            return REGION_CONFIG_MENU;
        }
        else
        {
            int field_left = MENUS_INDENT_H + MENU_LABEL_WIDTH + MENU_LABEL_SPACE +
                                MENU_WIDTH + FIELD_TEXT_INDENT_H;
            
            if(ui_point.h >= field_left)
                return REGION_PATH;
        }
    }
    else
    {
        int buttons_top = field_bottom + BUTTONS_GAP_V;
        int buttons_bottom = buttons_top + BUTTON_HEIGHT;
        
        if(ui_point.v >= buttons_top && ui_point.v <= buttons_bottom)
        {
            int convert_left = BUTTONS_INDENT_H;
            int convert_right = convert_left + BUTTON_WIDTH;
            int display_left = convert_right + BUTTONS_GAP_H;
            int display_right = display_left + BUTTON_WIDTH;
            int export_left = display_right + BUTTONS_GAP_H;
            int export_right = export_left + BUTTON_WIDTH;
            
            if(ui_point.h >= convert_left && ui_point.h <= convert_right)
                return REGION_CONVERT_BUTTON;
            else if(ui_point.h >= display_left && ui_point.h <= display_right)
                return REGION_DISPLAY_BUTTON;
            else if(ui_point.h >= export_left && ui_point.h <= export_right)
                return REGION_EXPORT_BUTTON;
        }
        else if(menus)
        {
            int menu_left = LEFT_MARGIN + MENUS_INDENT_H + MENU_LABEL_WIDTH;
            int menu_right = menu_left + MENU_WIDTH;
        
            if(ui_point.h >= menu_left && ui_point.h <= menu_right)
            {
                int menu1_top = buttons_bottom + MENUS_GAP_V;
                int menu1_bottom = menu1_top + MENU_HEIGHT;
                int menu2_top = menu1_bottom + MENU_SPACE_V;
                int menu2_bottom = menu2_top + MENU_HEIGHT;
                int menu3_top = menu2_bottom + MENU_SPACE_V;
                int menu3_bottom = menu3_top + MENU_HEIGHT;
                
                if(ui_point.v >= menu1_top && ui_point.v <= menu1_bottom)
                    return REGION_MENU1;
                else if(ui_point.v >= menu2_top && ui_point.v <= menu2_bottom)
                    return REGION_MENU2;
                else if(third_menu && ui_point.v >= menu3_top && ui_point.v <= menu3_bottom)
                    return REGION_MENU3;
            }
        }
    }
    
    return REGION_NONE;
}


static void DrawMenu(DrawbotBot &bot, const char *label, const char *item)
{
    DRAWBOT_PointF32 original = bot.Pos();
    
    float text_height = bot.FontSize();
    
    bot.Move(MENU_LABEL_WIDTH, MENU_TEXT_INDENT_V + text_height);
    
    bot.SetColor(TEXT_COLOR);
    bot.DrawString(label, kDRAWBOT_TextAlignment_Right);
    
    bot.Move(MENU_LABEL_SPACE, -(MENU_TEXT_INDENT_V + text_height));
    
    DRAWBOT_PointF32 menu_corner = bot.Pos();
    
    bot.Move(MENU_SHADOW_OFFSET, MENU_SHADOW_OFFSET);
    bot.SetColor(PF_App_Color_BLACK, 0.3f);
    bot.PaintRect(MENU_WIDTH, MENU_HEIGHT);
    bot.MoveTo(menu_corner);
    
    bot.SetColor(PF_App_Color_SHADOW);
    bot.PaintRect(MENU_WIDTH, MENU_HEIGHT);
    
    bot.SetColor(PF_App_Color_HILITE);
    bot.DrawRect(MENU_WIDTH, MENU_HEIGHT);
    
    bot.Move(MENU_TEXT_INDENT_H, MENU_TEXT_INDENT_V + text_height);
    
    bot.SetColor(TEXT_COLOR);
    bot.DrawString(item,
                    kDRAWBOT_TextAlignment_Left,
                    kDRAWBOT_TextTruncation_EndEllipsis,
                    MENU_WIDTH - MENU_TEXT_INDENT_H - MENU_TEXT_INDENT_H -
                        MENU_ARROW_WIDTH - MENU_ARROW_SPACE_H - MENU_ARROW_SPACE_H);
    
    bot.MoveTo(menu_corner.x + MENU_WIDTH - MENU_ARROW_SPACE_H - MENU_ARROW_WIDTH,
                menu_corner.y + MENU_ARROW_SPACE_V);
    
    bot.SetColor(PF_App_Color_LIGHT_TINGE);
    bot.PaintTriangle(MENU_ARROW_WIDTH, MENU_ARROW_HEIGHT);
    
    bot.MoveTo(original);
}


static void DrawButton(DrawbotBot &bot, const char *label, int width, bool pressed)
{
    DRAWBOT_PointF32 original = bot.Pos();
    
    float text_height = bot.FontSize();
    
    
    PF_App_ColorType button_color = (pressed ? PF_App_Color_BUTTON_PRESSED_FILL : PF_App_Color_BUTTON_FILL);
    PF_App_ColorType button_hilite = (pressed ? PF_App_Color_BLACK : PF_App_Color_HILITE);
    PF_App_ColorType button_lowlite = (pressed ? PF_App_Color_HILITE : PF_App_Color_BLACK);
    
    
    bot.SetColor(button_color);
    bot.PaintRect(width, BUTTON_HEIGHT);
    
    float brush_size = (pressed ? 1.f : 0.5f);
    
    bot.SetColor(button_hilite);
    bot.MoveTo(original.x + 1, original.y + BUTTON_HEIGHT - 1);
    
    bot.DrawLineTo(original.x + 1, original.y + 1, brush_size);
    bot.DrawLineTo(original.x + width - 1, original.y + 1, brush_size);
    
    bot.MoveTo(original); // annoying corner pixel
    bot.SetColor(button_hilite, 0.3f);
    bot.PaintRect(1, 1);


    brush_size = (pressed ? 0.5f : 1.f);
    
    bot.SetColor(button_lowlite);
    bot.MoveTo(original.x + 1, original.y + BUTTON_HEIGHT - 1);
    
    bot.DrawLineTo(original.x + width - 1, original.y + BUTTON_HEIGHT - 1, brush_size);
    bot.DrawLineTo(original.x + width - 1, original.y + 2, brush_size);
    
    bot.MoveTo(original.x + width - 1, original.y + BUTTON_HEIGHT - 1); // corner
    bot.SetColor(button_lowlite, 0.3f);
    bot.PaintRect(1, 1);
    
    
    bot.MoveTo(original.x + (width / 2), original.y + text_height + BUTTON_TEXT_INDENT_V);
    
    if(pressed)
        bot.Move(2, 2);
    
    bot.SetColor(TEXT_COLOR);
    bot.DrawString(label, kDRAWBOT_TextAlignment_Center);
    
    bot.MoveTo(original);
}


static PF_Err DrawEvent(  
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra)
{
    PF_Err          err     =   PF_Err_NONE;
    

    if(!(event_extra->evt_in_flags & PF_EI_DONT_DRAW) &&
        params[OCIO_DATA]->u.arb_d.value != NULL)
    {
        if(event_extra->effect_win.area == PF_EA_CONTROL)
        {
            ArbitraryData *arb_data = (ArbitraryData *)PF_LOCK_HANDLE(params[OCIO_DATA]->u.arb_d.value);
            SequenceData *seq_data = (SequenceData *)PF_LOCK_HANDLE(in_data->sequence_data);
        
            DrawbotBot bot(in_data->pica_basicP, event_extra->contextH, in_data->appl_id);
            
            
            int panel_left = event_extra->effect_win.current_frame.left;
            int panel_top = event_extra->effect_win.current_frame.top;
            int panel_width = event_extra->effect_win.current_frame.right;
            int panel_height = event_extra->effect_win.current_frame.bottom;
            float text_height = bot.FontSize();
            
            if(in_data->appl_id != 'FXTC')
            {
                // for Premiere we need to paint the background first
                bot.SetColor(PF_App_Color_PANEL_BACKGROUND);
                bot.MoveTo(panel_left, panel_top);
                bot.PaintRect(panel_width, panel_height);
            }
            
            
            // configuration menu
            bot.MoveTo(panel_left + MENUS_INDENT_H, panel_top + TOP_MARGIN);
            
            std::string config_menu_text = arb_data->path;
            
            if(arb_data->source == OCIO_SOURCE_NONE)
            {
                config_menu_text = "(none)";
            }
            if(arb_data->source == OCIO_SOURCE_ENVIRONMENT)
            {
                config_menu_text = "$OCIO";
            }
            else if(arb_data->source == OCIO_SOURCE_CUSTOM)
            {
                config_menu_text = (arb_data->action == OCIO_ACTION_LUT ? "LUT" : "Custom");
            }
            
            DrawMenu(bot, "Configuration:", config_menu_text.c_str());
            
            
            if(arb_data->source == OCIO_SOURCE_CUSTOM ||
                arb_data->source == OCIO_SOURCE_ENVIRONMENT)
            {
                // path text field
                int field_left = panel_left + MENUS_INDENT_H + MENU_LABEL_WIDTH +
                                    MENU_LABEL_SPACE + MENU_WIDTH + FIELD_TEXT_INDENT_H;
                
                bot.MoveTo(field_left, panel_top + TOP_MARGIN);
                
                int field_width = MAX(panel_width - field_left + panel_left - RIGHT_MARGIN, 60);
                
                bot.SetColor(PF_App_Color_SHADOW);
                bot.PaintRect(field_width, FIELD_HEIGHT);
                bot.SetColor(PF_App_Color_BLACK);
                bot.DrawRect(field_width, FIELD_HEIGHT);

                bot.Move(FIELD_TEXT_INDENT_H, FIELD_TEXT_INDENT_V + text_height);
                
                bot.SetColor(TEXT_COLOR);
                
                std::string file_string = "(none)";
                
                if(arb_data->source == OCIO_SOURCE_ENVIRONMENT)
                {
                    char *file = std::getenv("OCIO");
                    
                    if(file)
                        file_string = file;
                }
                else
                {
                    file_string = (seq_data->status == STATUS_USING_RELATIVE ?
                                        arb_data->relative_path : arb_data->path);
                }
                
                                    
                bot.DrawString(file_string.c_str(),
                                kDRAWBOT_TextAlignment_Default,
                                kDRAWBOT_TextTruncation_PathEllipsis,
                                field_width - (2 * FIELD_TEXT_INDENT_H));
            }
            
            
            if(seq_data->status == STATUS_FILE_MISSING)
            {
                bot.MoveTo(panel_left + MENU_LABEL_WIDTH + MENU_LABEL_SPACE,
                            panel_top + MENU_HEIGHT + BUTTONS_GAP_V + BUTTON_HEIGHT + BUTTONS_GAP_V);
                
                bot.SetColor(PF_App_Color_RED);
                bot.PaintRect(200, 50);
                
                bot.Move(100, 25 + (bot.FontSize() / 2));
                bot.SetColor(PF_App_Color_WHITE);
                
                if(arb_data->source == OCIO_SOURCE_ENVIRONMENT)
                    bot.DrawString("$OCIO NOT SET", kDRAWBOT_TextAlignment_Center);
                else
                    bot.DrawString("FILE MISSING", kDRAWBOT_TextAlignment_Center);
            }
            else
            {
                // buttons
                int field_bottom = panel_top + TOP_MARGIN + FIELD_HEIGHT;
                int buttons_top = field_bottom + BUTTONS_GAP_V;
                
                // GPU alert
                if(seq_data->gpu_err != GPU_ERR_NONE)
                {
                    bot.MoveTo(panel_left + MENU_LABEL_WIDTH + MENU_LABEL_SPACE,
                                field_bottom + bot.FontSize() + BUTTON_TEXT_INDENT_V);
                    
                    if(seq_data->gpu_err == GPU_ERR_INSUFFICIENT)
                    {
                        bot.DrawString("GPU Insufficient");
                    }
                    else if(seq_data->gpu_err == GPU_ERR_RENDER_ERR)
                    {
                        bot.DrawString("GPU Render Error");
                    }
                }
                
            #ifndef NDEBUG
                // Premiere color space (only for debugging purposes)
                if(in_data->appl_id == 'PrMr' && seq_data->prem_status != PREMIERE_UNKNOWN)
                {
                    bot.MoveTo(panel_left + MENU_LABEL_WIDTH + MENU_LABEL_SPACE + 200,
                                field_bottom + bot.FontSize() + BUTTON_TEXT_INDENT_V);
                    
                    bot.SetColor(PF_App_Color_WHITE);
                    
                    if(seq_data->prem_status == PREMIERE_LINEAR)
                    {
                        bot.DrawString("Linear Float");
                    }
                    else if(seq_data->prem_status == PREMIERE_NON_LINEAR)
                    {
                        bot.DrawString("Non-Linear Float");
                    }
                }
            #endif
                
                // Export button
                if(arb_data->action != OCIO_ACTION_NONE)
                {
                    bot.MoveTo(panel_left + BUTTONS_INDENT_H + (2 * (BUTTON_WIDTH + BUTTONS_GAP_H)), buttons_top);
                    
                    DrawButton(bot, "Export...", BUTTON_WIDTH, false);
                }
                
                if(arb_data->action == OCIO_ACTION_LUT)
                {
                    // Invert button
                    bot.MoveTo(panel_left + BUTTONS_INDENT_H, buttons_top);
                    
                    DrawButton(bot, "Invert", BUTTON_WIDTH, arb_data->invert);
                    
                    // interpolation menu
                    int buttons_bottom = buttons_top + BUTTON_HEIGHT;
                    
                    bot.MoveTo(panel_left + MENUS_INDENT_H, buttons_bottom + MENUS_GAP_V);
                    
                    const char *txt =   arb_data->interpolation == OCIO_INTERP_NEAREST ? "Nearest Neighbor" :
                                        arb_data->interpolation == OCIO_INTERP_LINEAR ? "Linear" :
                                        arb_data->interpolation == OCIO_INTERP_TETRAHEDRAL ? "Tetrahedral" :
                                        arb_data->interpolation == OCIO_INTERP_BEST ? "Best" :
                                        "Unknown";
                    
                    DrawMenu(bot, "Interpolation:", txt);
                }
                else if(arb_data->action == OCIO_ACTION_CONVERT ||
                        arb_data->action == OCIO_ACTION_DISPLAY)
                {
                    // Convert/Display buttons
                    bot.MoveTo(panel_left + BUTTONS_INDENT_H, buttons_top);
                    
                    DrawButton(bot, "Convert", BUTTON_WIDTH,
                                arb_data->action == OCIO_ACTION_CONVERT);
                    
                    bot.Move(BUTTON_WIDTH + BUTTONS_GAP_H);
                    
                    DrawButton(bot, "Display", BUTTON_WIDTH,
                                arb_data->action == OCIO_ACTION_DISPLAY);
                    
                    
                    // menus
                    int buttons_bottom = buttons_top + BUTTON_HEIGHT;
                    
                    bot.MoveTo(panel_left + MENUS_INDENT_H, buttons_bottom + MENUS_GAP_V);
                    
                    if(arb_data->action == OCIO_ACTION_CONVERT)
                    {
                        DrawMenu(bot, "Input Space:", arb_data->input);
                        
                        bot.Move(0, MENU_HEIGHT + MENU_SPACE_V);
                        
                        DrawMenu(bot, "Output Space:", arb_data->output);
                    }
                    else if(arb_data->action == OCIO_ACTION_DISPLAY)
                    {
                        // color space transformations
                        DrawMenu(bot, "Input Space:", arb_data->input);
                        
                        bot.Move(0, MENU_HEIGHT + MENU_SPACE_V);
                        
                        DrawMenu(bot, "Transform:", arb_data->transform);
                        
                        bot.Move(0, MENU_HEIGHT + MENU_SPACE_V);
                        
                        DrawMenu(bot, "Device:", arb_data->device);
                    }
                }
            }
            
            
            event_extra->evt_out_flags = PF_EO_HANDLED_EVENT;

            PF_UNLOCK_HANDLE(params[OCIO_DATA]->u.arb_d.value);
            PF_UNLOCK_HANDLE(in_data->sequence_data);
        }
    }

    return err;
}


std::string GetProjectDir(PF_InData *in_data)
{
    if(in_data->appl_id == 'PrMr')
        return std::string("");
    
    AEGP_SuiteHandler suites(in_data->pica_basicP);

    AEGP_ProjectH projH = NULL;
    suites.ProjSuite5()->AEGP_GetProjectByIndex(0, &projH);

    AEGP_MemHandle pathH = NULL;
    suites.ProjSuite5()->AEGP_GetProjectPath(projH, &pathH);

    if(pathH)
    {
        std::string proj_dir;
        
        A_UTF16Char *path = NULL;
        suites.MemorySuite1()->AEGP_LockMemHandle(pathH, (void **)&path);

        if(path)
        {
            // poor-man's unicode copy
            char c_path[AEGP_MAX_PATH_SIZE];

            char *c = c_path;
            A_UTF16Char *s = path;

            do{
                *c++ = *s;
            }while(*s++ != '\0');

#ifdef WIN_ENV
#define PATH_DELIMITER  '\\'
#else
#define PATH_DELIMITER  '/'
#endif

            std::string proj_path(c_path);
            
            if(proj_path.find_last_of(PATH_DELIMITER) != std::string::npos)
            {
                proj_dir = proj_path.substr(0, proj_path.find_last_of(PATH_DELIMITER));
            }
        }
        
        suites.MemorySuite1()->AEGP_FreeMemHandle(pathH);
        
        return proj_dir;
    }

    return std::string("");
}


static int FindInVec(const std::vector<std::string> &vec, const std::string val)
{
    for(int i=0; i < vec.size(); i++)
    {
        if(vec[i] == val)
            return i;
    }
    
    return -1;
}


static void DoClickPath(
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra,
    ArbitraryData   *arb_data,
    SequenceData    *seq_data)
{
    ExtensionMap extensions;
    
    for(int i=0; i < OCIO::FileTransform::getNumFormats(); i++)
    {
        const char *extension = OCIO::FileTransform::getFormatExtensionByIndex(i);
        const char *format = OCIO::FileTransform::getFormatNameByIndex(i);
    
        extensions[ extension ] = format;
    }
    
    extensions[ "ocio" ] = "OCIO Format";
    

    void *hwndOwner = NULL;

#ifdef WIN_ENV
    PF_GET_PLATFORM_DATA(PF_PlatData_MAIN_WND, &hwndOwner);
#endif

    char c_path[ARB_PATH_LEN + 1] = { '\0' };
    
    bool result = OpenFile(c_path, ARB_PATH_LEN, extensions, hwndOwner);
    
    
    if(result)
    {
        Path path(c_path, GetProjectDir(in_data));
        
        OpenColorIO_AE_Context *new_context = new OpenColorIO_AE_Context(path.full_path(),
                                                                    OCIO_SOURCE_CUSTOM);
        
        if(new_context == NULL)
            throw OCIO::Exception("WTF?");
            
        
        if(seq_data->context)
        {
            delete seq_data->context;
        }
        
        seq_data->context = new_context;
        
        arb_data->source = seq_data->source = OCIO_SOURCE_CUSTOM;
        
        strncpy(arb_data->path, path.full_path().c_str(), ARB_PATH_LEN);
        strncpy(arb_data->relative_path, path.relative_path(false).c_str(), ARB_PATH_LEN);
        
        strncpy(seq_data->path, arb_data->path, ARB_PATH_LEN);
        strncpy(seq_data->relative_path, arb_data->relative_path, ARB_PATH_LEN);
        
        
        // try to retain settings if it looks like the same situation,
        // possibly fixing a moved path
        if(OCIO_ACTION_NONE == arb_data->action ||
            (OCIO_ACTION_LUT == new_context->getAction() && OCIO_ACTION_LUT != arb_data->action) ||
            (OCIO_ACTION_LUT != new_context->getAction() && OCIO_ACTION_LUT == arb_data->action) ||
            (OCIO_ACTION_LUT != new_context->getAction() &&
               (-1 == FindInVec(new_context->getInputs(), arb_data->input) ||
                -1 == FindInVec(new_context->getInputs(), arb_data->output) ||
                -1 == FindInVec(new_context->getTransforms(), arb_data->transform) ||
                -1 == FindInVec(new_context->getDevices(), arb_data->device) ) ) )
        {
            // Configuration is different, so initialize defaults
            arb_data->action = seq_data->context->getAction();
            
            if(arb_data->action == OCIO_ACTION_LUT)
            {
                arb_data->invert = FALSE;
                arb_data->interpolation = OCIO_INTERP_LINEAR;
            }
            else
            {
                strncpy(arb_data->input, seq_data->context->getInput().c_str(), ARB_SPACE_LEN);
                strncpy(arb_data->output, seq_data->context->getOutput().c_str(), ARB_SPACE_LEN);
                strncpy(arb_data->transform, seq_data->context->getTransform().c_str(), ARB_SPACE_LEN);
                strncpy(arb_data->device, seq_data->context->getDevice().c_str(), ARB_SPACE_LEN);
            }
        }
        else
        {
            // Configuration is the same, retain current settings
            if(arb_data->action == OCIO_ACTION_LUT)
            {
                seq_data->context->setupLUT(arb_data->invert, arb_data->interpolation);
            }
            else if(arb_data->action == OCIO_ACTION_CONVERT)
            {
                seq_data->context->setupConvert(arb_data->input, arb_data->output);
            }
            else if(arb_data->action == OCIO_ACTION_DISPLAY)
            {
                seq_data->context->setupDisplay(arb_data->input, arb_data->transform, arb_data->device);
            }
        }
        
        params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
        
        seq_data->status = STATUS_USING_ABSOLUTE;
    }
}


static void DoClickConfig(
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra,
    ArbitraryData   *arb_data,
    SequenceData    *seq_data)
{
    void *hwndOwner = NULL;

#ifdef WIN_ENV
    PF_GET_PLATFORM_DATA(PF_PlatData_MAIN_WND, &hwndOwner);
#endif

    ConfigVec configs;
    GetStdConfigs(configs);
    
    if(configs.size() == 0)
        configs.push_back("(nada)"); // menu makes a gray entry that says "No configs in $PATH"
    
    
    MenuVec menu_items;
    int selected = 0;
    
    menu_items.push_back("$OCIO"); // menu will gray this out if $OCIO is not defined
    
    menu_items.push_back("(-"); // this tells the menu to make a seperator
    
    for(ConfigVec::const_iterator i = configs.begin(); i != configs.end(); ++i)
    {
        menu_items.push_back( *i );
        
        if(arb_data->source == OCIO_SOURCE_STANDARD && arb_data->path == *i)
        {
            selected = menu_items.size() - 1;
        }
    }
    
    menu_items.push_back("(-");
    
    menu_items.push_back("Custom...");
    
    int custom_choice = menu_items.size() - 1;
    
    if(arb_data->source == OCIO_SOURCE_CUSTOM)
    {
        selected = -1;
    }
    
    
    int choice = PopUpMenu(menu_items, selected, hwndOwner);
    
    
    if(choice == custom_choice)
    {
        // custom is the same as clicking the path
        DoClickPath(in_data, out_data, params, output, event_extra, arb_data, seq_data);
    }
    else if(choice != selected)
    {
        OpenColorIO_AE_Context *new_context = NULL;
        
        if(choice == 0)
        {
            // $OCIO
            char *file = std::getenv("OCIO");
            
            if(file)
            {
                Path path(file, GetProjectDir(in_data));
                
                new_context = new OpenColorIO_AE_Context(path.full_path(),
                                                            OCIO_SOURCE_ENVIRONMENT);
                
                arb_data->source = seq_data->source = OCIO_SOURCE_ENVIRONMENT;
                
                strncpy(arb_data->path, path.full_path().c_str(), ARB_PATH_LEN);
                strncpy(arb_data->relative_path, path.relative_path(false).c_str(), ARB_PATH_LEN);
            }
            else
                throw OCIO::Exception("No $OCIO environment variable defined."); 
        }
        else
        {
            // standard configs
            std::string config = configs[choice - 2];
            
            std::string path = GetStdConfigPath(config);
            
            if( !path.empty() )
            {
                new_context = new OpenColorIO_AE_Context(config, OCIO_SOURCE_STANDARD);
                
                arb_data->source = seq_data->source = OCIO_SOURCE_STANDARD;
                
                strncpy(arb_data->path, config.c_str(), ARB_PATH_LEN);
                strncpy(arb_data->relative_path, path.c_str(), ARB_PATH_LEN);
            }
            else
                throw OCIO::Exception("Problem loading OCIO configuration."); 
        }
        
        
        if(new_context)
        {
            if(seq_data->context)
            {
                delete seq_data->context;
            }
            
            seq_data->context = new_context;
            
            
            strncpy(seq_data->path, arb_data->path, ARB_PATH_LEN);
            strncpy(seq_data->relative_path, arb_data->relative_path, ARB_PATH_LEN);
            
            // try to retain settings if it looks like the same situation,
            // possibly fixing a moved path
            if(OCIO_ACTION_NONE == arb_data->action ||
                (OCIO_ACTION_LUT == new_context->getAction() && OCIO_ACTION_LUT != arb_data->action) ||
                (OCIO_ACTION_LUT != new_context->getAction() && OCIO_ACTION_LUT == arb_data->action) ||
                (OCIO_ACTION_LUT != new_context->getAction() &&
                   (-1 == FindInVec(new_context->getInputs(), arb_data->input) ||
                    -1 == FindInVec(new_context->getInputs(), arb_data->output) ||
                    -1 == FindInVec(new_context->getTransforms(), arb_data->transform) ||
                    -1 == FindInVec(new_context->getDevices(), arb_data->device) ) ) )
            {
                // Configuration is different, so initialize defaults
                arb_data->action = seq_data->context->getAction();
                
                if(arb_data->action == OCIO_ACTION_LUT)
                {
                    arb_data->invert = FALSE;
                    arb_data->interpolation = OCIO_INTERP_LINEAR;
                }
                else
                {
                    strncpy(arb_data->input, seq_data->context->getInput().c_str(), ARB_SPACE_LEN);
                    strncpy(arb_data->output, seq_data->context->getOutput().c_str(), ARB_SPACE_LEN);
                    strncpy(arb_data->transform, seq_data->context->getTransform().c_str(), ARB_SPACE_LEN);
                    strncpy(arb_data->device, seq_data->context->getDevice().c_str(), ARB_SPACE_LEN);
                }
            }
            else
            {
                // Configuration is the same, retain current settings
                if(arb_data->action == OCIO_ACTION_LUT)
                {
                    seq_data->context->setupLUT(arb_data->invert, arb_data->interpolation);
                }
                else if(arb_data->action == OCIO_ACTION_CONVERT)
                {
                    seq_data->context->setupConvert(arb_data->input, arb_data->output);
                }
                else if(arb_data->action == OCIO_ACTION_DISPLAY)
                {
                    seq_data->context->setupDisplay(arb_data->input, arb_data->transform, arb_data->device);
                }
            }
            
            params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
            
            seq_data->status = STATUS_OK;
        }
    }
}


static void DoClickConvertDisplay(
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra,
    ArbitraryData   *arb_data,
    SequenceData    *seq_data,
    UIRegion        reg )
{
    if(arb_data->action == OCIO_ACTION_LUT)
    {
        if(reg == REGION_CONVERT_BUTTON) // i.e. Invert
        {
            // doing it this way so that any exceptions thrown by setupLUT
            // because the LUT can't be inverted are thrown before
            // I actually chenge the ArbData setting
            seq_data->context->setupLUT(!arb_data->invert, arb_data->interpolation);
            
            arb_data->invert = !arb_data->invert;
        
            params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
        }
    }
    else if(arb_data->action == OCIO_ACTION_CONVERT || arb_data->action == OCIO_ACTION_DISPLAY)
    {
        if(reg == REGION_CONVERT_BUTTON && arb_data->action != OCIO_ACTION_CONVERT)
        {
            arb_data->action = OCIO_ACTION_CONVERT;
            
            seq_data->context->setupConvert(arb_data->input, arb_data->output);
        
            params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
        }
        else if(reg == REGION_DISPLAY_BUTTON && arb_data->action != OCIO_ACTION_DISPLAY)
        {
            arb_data->action = OCIO_ACTION_DISPLAY;
            
            seq_data->context->setupDisplay(arb_data->input, arb_data->transform, arb_data->device);
            
            params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
        }
    }
}


static void DoClickExport(
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra,
    ArbitraryData   *arb_data,
    SequenceData    *seq_data,
    UIRegion        reg )
{
    ExtensionMap extensions;
    
    for(int i=0; i < OCIO::Baker::getNumFormats(); ++i)
    {
        const char *extension = OCIO::Baker::getFormatExtensionByIndex(i);
        const char *format = OCIO::Baker::getFormatNameByIndex(i);
        
        extensions[ extension ] = format;
    }
    
    extensions[ "icc" ] = "ICC Profile";
    
    
    void *hwndOwner = NULL;

#ifdef WIN_ENV
    PF_GET_PLATFORM_DATA(PF_PlatData_MAIN_WND, &hwndOwner);
#endif

    char path[256] = { '\0' };
    
    bool result = SaveFile(path, 255, extensions, hwndOwner);
    
    
    if(result)
    {
        std::string the_path(path);
        std::string the_extension = the_path.substr( the_path.find_last_of('.') + 1 );
        
        bool do_export = true;
        
        std::string monitor_icc_path;
        
        if(the_extension == "icc")
        {
            char monitor_path[256] = {'\0'};
        
            do_export = GetMonitorProfile(monitor_path, 255, hwndOwner);
        
            if(monitor_path[0] != '\0')
                monitor_icc_path = monitor_path;
        }
        
        if(do_export)
            seq_data->context->ExportLUT(the_path, monitor_icc_path);
    }
}


static void DoClickMenus(
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra,
    ArbitraryData   *arb_data,
    SequenceData    *seq_data,
    UIRegion        reg )
{
    if(seq_data->context != NULL && arb_data->action == seq_data->context->getAction())
    {
        MenuVec menu_items;
        int selected_item;
        
        if(arb_data->action == OCIO_ACTION_LUT)
        {
            if(reg == REGION_MENU1)
            {
                menu_items.push_back("Nearest Neighbor");
                menu_items.push_back("Linear");
                menu_items.push_back("Tetrahedral");
                menu_items.push_back("(-");
                menu_items.push_back("Best");
                
                selected_item = arb_data->interpolation == OCIO_INTERP_NEAREST ? 0 :
                                arb_data->interpolation == OCIO_INTERP_LINEAR ? 1 :
                                arb_data->interpolation == OCIO_INTERP_TETRAHEDRAL ? 2 :
                                arb_data->interpolation == OCIO_INTERP_BEST ? 4 :
                                -1;
            }
        }
        else if(arb_data->action == OCIO_ACTION_CONVERT)
        {
            menu_items = seq_data->context->getInputs();
            
            if(reg == REGION_MENU1)
            {
                selected_item = FindInVec(menu_items, arb_data->input);
            }
            else
            {
                selected_item = FindInVec(menu_items, arb_data->output);
            }
        }
        else if(arb_data->action == OCIO_ACTION_DISPLAY)
        {
            if(reg == REGION_MENU1)
            {
                menu_items = seq_data->context->getInputs();
                
                selected_item = FindInVec(menu_items, arb_data->input);
            }
            else if(reg == REGION_MENU2)
            {
                menu_items = seq_data->context->getTransforms();
                
                selected_item = FindInVec(menu_items, arb_data->transform);
            }
            else if(reg == REGION_MENU3)
            {
                menu_items = seq_data->context->getDevices();
                
                selected_item = FindInVec(menu_items, arb_data->device);
            }
        }
        
        
        
        void *hwndOwner = NULL;

    #ifdef WIN_ENV
        PF_GET_PLATFORM_DATA(PF_PlatData_MAIN_WND, &hwndOwner);
    #endif

        int result = PopUpMenu(menu_items, selected_item, hwndOwner);
        
        
        if(result != selected_item)
        {
            std::string color_space = menu_items[ result ];
            
            if(arb_data->action == OCIO_ACTION_LUT)
            {
                if(reg == REGION_MENU1)
                {
                    arb_data->interpolation =   result == 0 ? OCIO_INTERP_NEAREST :
                                                result == 2 ? OCIO_INTERP_TETRAHEDRAL :
                                                result == 4 ? OCIO_INTERP_BEST :
                                                OCIO_INTERP_LINEAR;
                                            
                    seq_data->context->setupLUT(arb_data->invert, arb_data->interpolation);
                }
            }
            else if(arb_data->action == OCIO_ACTION_CONVERT)
            {
                if(reg == REGION_MENU1)
                {
                    strncpy(arb_data->input, color_space.c_str(), ARB_SPACE_LEN);
                }
                else if(reg == REGION_MENU2)
                {
                    strncpy(arb_data->output, color_space.c_str(), ARB_SPACE_LEN);
                }
                
                seq_data->context->setupConvert(arb_data->input, arb_data->output);
            }
            else if(arb_data->action == OCIO_ACTION_DISPLAY)
            {
                if(reg == REGION_MENU1)
                {
                    strncpy(arb_data->input, color_space.c_str(), ARB_SPACE_LEN);
                }
                else if(reg == REGION_MENU2)
                {
                    strncpy(arb_data->transform, color_space.c_str(), ARB_SPACE_LEN);
                }
                else if(reg == REGION_MENU3)
                {
                    strncpy(arb_data->device, color_space.c_str(), ARB_SPACE_LEN);
                }
                
                seq_data->context->setupDisplay(arb_data->input, arb_data->transform, arb_data->device);
            }
                    
            params[OCIO_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
        }
    }
}


static PF_Err DoClick( 
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *event_extra )
{
    PF_Err          err     =   PF_Err_NONE;
    
    ArbitraryData *arb_data = (ArbitraryData *)PF_LOCK_HANDLE(params[OCIO_DATA]->u.arb_d.value);
    SequenceData *seq_data = (SequenceData *)PF_LOCK_HANDLE(in_data->sequence_data);
    
    
    if(event_extra->effect_win.area == PF_EA_CONTROL)
    {
        bool menus_visible = (arb_data->action != OCIO_ACTION_NONE);
        bool third_menu = (arb_data->action == OCIO_ACTION_DISPLAY);
        
        PF_Point local_point;
        
        local_point.h = event_extra->u.do_click.screen_point.h - event_extra->effect_win.current_frame.left;
        local_point.v = event_extra->u.do_click.screen_point.v - event_extra->effect_win.current_frame.top;
        
        UIRegion reg = WhichRegion(local_point, menus_visible, third_menu);
        
        if(reg != REGION_NONE)
        {
            try
            {
                if(reg == REGION_CONFIG_MENU)
                {
                    DoClickConfig(in_data, out_data, params, output,
                                    event_extra, arb_data, seq_data);
                }
                else if(reg == REGION_PATH)
                {
                    if(arb_data->source == OCIO_SOURCE_CUSTOM)
                    {
                        DoClickPath(in_data, out_data, params, output,
                                        event_extra, arb_data, seq_data);
                    }
                }
                else if(arb_data->action != OCIO_ACTION_NONE &&
                        seq_data->status != STATUS_FILE_MISSING)
                {
                    if(seq_data->context == NULL)
                    {
                        seq_data->context = new OpenColorIO_AE_Context(arb_data,
                                                                GetProjectDir(in_data) );
                    }
                        
                    if(reg == REGION_CONVERT_BUTTON || reg == REGION_DISPLAY_BUTTON)
                    {
                        DoClickConvertDisplay(in_data, out_data, params, output,
                                                event_extra, arb_data, seq_data, reg);
                    }
                    else if(reg == REGION_EXPORT_BUTTON)
                    {
                        DoClickExport(in_data, out_data, params, output,
                                        event_extra, arb_data, seq_data, reg);
                    }
                    else // must be a menu then
                    {
                        DoClickMenus(in_data, out_data, params, output,
                                        event_extra, arb_data, seq_data, reg);
                    }
                }
            }
            catch(std::exception &e)
            {
                if(in_data->appl_id == 'FXTC')
                {
                    PF_SPRINTF(out_data->return_msg, e.what());
                    
                    out_data->out_flags |= PF_OutFlag_DISPLAY_ERROR_MESSAGE;
                }
                else
                {
                    void *hwndOwner = NULL;

                #ifdef WIN_ENV
                    PF_GET_PLATFORM_DATA(PF_PlatData_MAIN_WND, &hwndOwner);
                #endif

                    ErrorMessage(e.what(), hwndOwner);
                }
            }
            catch(...)
            {
                PF_SPRINTF(out_data->return_msg, "Unknown error");
                
                out_data->out_flags |= PF_OutFlag_DISPLAY_ERROR_MESSAGE;
            }
        }
    }
    
    
    PF_UNLOCK_HANDLE(params[OCIO_DATA]->u.arb_d.value);
    PF_UNLOCK_HANDLE(in_data->sequence_data);
    
    event_extra->evt_out_flags = PF_EO_HANDLED_EVENT;
    
    return err;
}


PF_Err HandleEvent ( 
    PF_InData       *in_data,
    PF_OutData      *out_data,
    PF_ParamDef     *params[],
    PF_LayerDef     *output,
    PF_EventExtra   *extra )
{
    PF_Err      err     = PF_Err_NONE;
    
    extra->evt_out_flags = 0;
    
    if(!err) 
    {
        switch(extra->e_type) 
        {
            case PF_Event_DRAW:
                err = DrawEvent(in_data, out_data, params, output, extra);
                break;
            
            case PF_Event_DO_CLICK:
                err = DoClick(in_data, out_data, params, output, extra);
                break;
        }
    }
    
    return err;
}