/
ming.c
3157 lines (2410 loc) · 82.5 KB
/
ming.c
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
/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2002 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| http://www.php.net/license/2_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: dave@opaque.net |
+----------------------------------------------------------------------+
*/
#include <stdio.h>
#include <math.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ming.h"
#include "ext/standard/info.h"
#include "ext/standard/file.h"
#include "ext/standard/fsock.h"
#if HAVE_MING
static zend_function_entry ming_functions[] = {
PHP_FALIAS(ming_setcubicthreshold, ming_setCubicThreshold, NULL)
PHP_FALIAS(ming_setscale, ming_setScale, NULL)
PHP_FALIAS(ming_useswfversion, ming_useSWFVersion, NULL)
PHP_FALIAS(swfbutton_keypress, swfbutton_keypress, NULL)
{ NULL, NULL, NULL }
};
static SWFMovie getMovie(zval *id TSRMLS_DC);
static SWFFill getFill(zval *id TSRMLS_DC);
static SWFGradient getGradient(zval *id TSRMLS_DC);
static SWFBitmap getBitmap(zval *id TSRMLS_DC);
static SWFShape getShape(zval *id TSRMLS_DC);
static SWFFont getFont(zval *id TSRMLS_DC);
static SWFText getText(zval *id TSRMLS_DC);
static SWFTextField getTextField(zval *id TSRMLS_DC);
static SWFDisplayItem getDisplayItem(zval *id TSRMLS_DC);
static SWFButton getButton(zval *id TSRMLS_DC);
static SWFAction getAction(zval *id TSRMLS_DC);
static SWFMorph getMorph(zval *id TSRMLS_DC);
static SWFMovieClip getSprite(zval *id TSRMLS_DC);
PHP_FUNCTION(ming_setCubicThreshold)
{
zval **num;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long_ex(num);
Ming_setCubicThreshold(Z_LVAL_PP(num));
}
PHP_FUNCTION(ming_setScale)
{
zval **num;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(num);
Ming_setScale(Z_DVAL_PP(num));
}
PHP_FUNCTION(ming_useSWFVersion)
{
zval **num;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long_ex(num);
Ming_useSWFVersion(Z_LVAL_PP(num));
}
static int le_swfmoviep;
static int le_swfshapep;
static int le_swffillp;
static int le_swfgradientp;
static int le_swfbitmapp;
static int le_swffontp;
static int le_swftextp;
static int le_swftextfieldp;
static int le_swfdisplayitemp;
static int le_swfbuttonp;
static int le_swfactionp;
static int le_swfmorphp;
static int le_swfspritep;
static int le_swfinputp;
static int le_fopen;
static int le_socket;
static int le_popen;
zend_class_entry movie_class_entry;
zend_class_entry shape_class_entry;
zend_class_entry fill_class_entry;
zend_class_entry gradient_class_entry;
zend_class_entry bitmap_class_entry;
zend_class_entry font_class_entry;
zend_class_entry text_class_entry;
zend_class_entry textfield_class_entry;
zend_class_entry displayitem_class_entry;
zend_class_entry button_class_entry;
zend_class_entry action_class_entry;
zend_class_entry morph_class_entry;
zend_class_entry sprite_class_entry;
/* {{{ internal function SWFgetProperty
*/
static void *SWFgetProperty(zval *id, char *name, int namelen, int proptype TSRMLS_DC)
{
zval **tmp;
int id_to_find;
void *property;
int type;
if(id)
{
if(zend_hash_find(Z_OBJPROP_P(id), name, namelen+1, (void **)&tmp) == FAILURE)
{
php_error(E_WARNING, "unable to find property %s", name);
return NULL;
}
id_to_find = Z_LVAL_PP(tmp);
}
else
return NULL;
property = zend_list_find(id_to_find, &type);
if (!property || type != proptype)
{
php_error(E_WARNING, "unable to find identifier (%d)", id_to_find);
return NULL;
}
return property;
}
/* }}} */
/* {{{ SWFCharacter - not a real class */
/* {{{ internal function SWFCharacter getCharacter(zval *id)
Returns the SWFCharacter contained in zval *id */
SWFCharacter getCharacter(zval *id TSRMLS_DC)
{
if(Z_OBJCE_P(id) == &shape_class_entry)
return (SWFCharacter)getShape(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &font_class_entry)
return (SWFCharacter)getFont(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &text_class_entry)
return (SWFCharacter)getText(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &textfield_class_entry)
return (SWFCharacter)getTextField(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &button_class_entry)
return (SWFCharacter)getButton(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &morph_class_entry)
return (SWFCharacter)getMorph(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &sprite_class_entry)
return (SWFCharacter)getSprite(id TSRMLS_CC);
else if(Z_OBJCE_P(id) == &bitmap_class_entry)
return (SWFCharacter)getBitmap(id TSRMLS_CC);
else
php_error(E_ERROR, "called object is not an SWFCharacter");
return NULL;
}
/* }}} */
/* }}} */
/* {{{ getInput - utility func for making an SWFInput from an fopened resource */
static void destroy_SWFInput_resource(zend_rsrc_list_entry *resource)
{
destroySWFInput((SWFInput)resource->ptr);
}
#define SOCKBUF_INCREMENT 10240
/* turn a socket into an SWFInput by copying everything to a buffer. */
/* not pretty, but it works */
static SWFInput newSWFInput_sock(int socket)
{
char *buffer = NULL;
int l, offset = 0, alloced = 0;
do
{
if(offset <= alloced)
{
alloced += SOCKBUF_INCREMENT;
buffer = realloc(buffer, alloced);
}
l = SOCK_FREAD(buffer+offset, SOCKBUF_INCREMENT, socket);
offset += l;
}
while(l > 0);
return newSWFInput_allocedBuffer(buffer, offset);
}
static SWFInput getInput(zval **zfile TSRMLS_DC)
{
FILE *file;
int type;
SWFInput input;
file = (FILE *) zend_fetch_resource(zfile TSRMLS_CC, -1, "File-Handle", &type, 3, php_file_le_fopen(), php_file_le_popen(), php_file_le_socket());
if(type == le_socket)
input = newSWFInput_sock(*(int *)file);
else
{
input = newSWFInput_file(file);
zend_list_addref(Z_LVAL_PP(zfile));
}
zend_list_addref(zend_list_insert(input, le_swfinputp));
return input;
}
/* }}} */
/* {{{ SWFAction */
static zend_function_entry swfaction_functions[] = {
PHP_FALIAS(swfaction, swfaction_init, NULL)
{ NULL, NULL, NULL }
};
/* {{{ proto object swfaction_init(string)
Returns a new SWFAction object, compiling the given script */
PHP_FUNCTION(swfaction_init)
{
SWFAction action;
zval **script;
int ret;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &script) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_string_ex(script);
action = compileSWFActionCode(Z_STRVAL_PP(script));
if(!action)
php_error(E_ERROR, "Couldn't compile actionscript.");
ret = zend_list_insert(action, le_swfactionp);
object_init_ex(getThis(), &action_class_entry);
add_property_resource(getThis(), "action", ret);
zend_list_addref(ret);
}
/* no destructor for SWFAction, it's not a character */
/* }}} */
/* {{{ internal function getAction
Returns the SWFAction object contained in zval *id */
static SWFAction getAction(zval *id TSRMLS_DC)
{
void *action = SWFgetProperty(id, "action", 6, le_swfactionp TSRMLS_CC);
if(!action)
php_error(E_ERROR, "called object is not an SWFAction!");
return (SWFAction)action;
}
/* }}} */
/* }}} */
/* {{{ SWFBitmap */
static zend_function_entry swfbitmap_functions[] = {
PHP_FALIAS(swfbitmap, swfbitmap_init, NULL)
PHP_FALIAS(getwidth, swfbitmap_getWidth, NULL)
PHP_FALIAS(getheight, swfbitmap_getHeight, NULL)
{ NULL, NULL, NULL }
};
/* {{{ proto class swfbitmap_init(file [, maskfile])
Returns a new SWFBitmap object from jpg (with optional mask) or dbl file */
PHP_FUNCTION(swfbitmap_init)
{
zval **zfile, **zmask = NULL;
SWFBitmap bitmap;
SWFInput input, maskinput;
int ret;
if(ZEND_NUM_ARGS() == 1)
{
if(zend_get_parameters_ex(1, &zfile) == FAILURE)
WRONG_PARAM_COUNT;
}
else if(ZEND_NUM_ARGS() == 2)
{
if(zend_get_parameters_ex(2, &zfile, &zmask) == FAILURE)
WRONG_PARAM_COUNT;
}
else
WRONG_PARAM_COUNT;
if(Z_TYPE_PP(zfile) != IS_RESOURCE)
{
convert_to_string_ex(zfile);
input = newSWFInput_buffer(Z_STRVAL_PP(zfile), Z_STRLEN_PP(zfile));
zend_list_addref(zend_list_insert(input, le_swfinputp));
}
else
input = getInput(zfile TSRMLS_CC);
if(zmask != NULL)
{
if(Z_TYPE_PP(zmask) != IS_RESOURCE)
{
convert_to_string_ex(zmask);
maskinput = newSWFInput_buffer(Z_STRVAL_PP(zmask), Z_STRLEN_PP(zmask));
zend_list_addref(zend_list_insert(maskinput, le_swfinputp));
}
else
maskinput = getInput(zmask TSRMLS_CC);
bitmap = newSWFJpegWithAlpha_fromInput(input, maskinput);
}
else
bitmap = newSWFBitmap_fromInput(input);
ret = zend_list_insert(bitmap, le_swfbitmapp);
object_init_ex(getThis(), &bitmap_class_entry);
add_property_resource(getThis(), "bitmap", ret);
zend_list_addref(ret);
}
static void destroy_SWFBitmap_resource(zend_rsrc_list_entry *resource TSRMLS_DC)
{
destroySWFBitmap((SWFBitmap)resource->ptr);
}
/* }}} */
/* {{{ internal function getBitmap
Returns the SWFBitmap object contained in zval *id */
static SWFBitmap getBitmap(zval *id TSRMLS_DC)
{
void *bitmap = SWFgetProperty(id, "bitmap", 6, le_swfbitmapp TSRMLS_CC);
if(!bitmap)
php_error(E_ERROR, "called object is not an SWFBitmap!");
return (SWFBitmap)bitmap;
}
/* }}} */
/* {{{ proto void swfbitmap_getWidth(void)
Returns the width of this bitmap */
PHP_FUNCTION(swfbitmap_getWidth)
{
if(ZEND_NUM_ARGS() != 0)
WRONG_PARAM_COUNT;
RETURN_DOUBLE(SWFBitmap_getWidth(getBitmap(getThis() TSRMLS_CC)));
}
/* }}} */
/* {{{ proto void swfbitmap_getHeight(void)
Returns the height of this bitmap */
PHP_FUNCTION(swfbitmap_getHeight)
{
if(ZEND_NUM_ARGS() != 0)
WRONG_PARAM_COUNT;
RETURN_DOUBLE(SWFBitmap_getHeight(getBitmap(getThis() TSRMLS_CC)));
}
/* }}} */
/* }}} */
/* {{{ SWFButton */
static zend_function_entry swfbutton_functions[] = {
PHP_FALIAS(swfbutton, swfbutton_init, NULL)
PHP_FALIAS(sethit, swfbutton_setHit, NULL)
PHP_FALIAS(setover, swfbutton_setOver, NULL)
PHP_FALIAS(setup, swfbutton_setUp, NULL)
PHP_FALIAS(setdown, swfbutton_setDown, NULL)
PHP_FALIAS(setaction, swfbutton_setAction, NULL)
PHP_FALIAS(addshape, swfbutton_addShape, NULL)
PHP_FALIAS(addaction, swfbutton_addAction, NULL)
{ NULL, NULL, NULL }
};
/* {{{ proto object swfbutton_init(void)
Returns a new SWFButton object */
PHP_FUNCTION(swfbutton_init)
{
SWFButton button = newSWFButton();
int ret = zend_list_insert(button, le_swfbuttonp);
object_init_ex(getThis(), &button_class_entry);
add_property_resource(getThis(), "button", ret);
zend_list_addref(ret);
}
static void destroy_SWFButton_resource(zend_rsrc_list_entry *resource TSRMLS_DC)
{
destroySWFButton((SWFButton)resource->ptr);
}
/* }}} */
/* {{{ internal function getButton
Returns the SWFButton object contained in zval *id */
static SWFButton getButton(zval *id TSRMLS_DC)
{
void *button = SWFgetProperty(id, "button", 6, le_swfbuttonp TSRMLS_CC);
if(!button)
php_error(E_ERROR, "called object is not an SWFButton!");
return (SWFButton)button;
}
/* }}} */
/* {{{ proto void swfbutton_setHit(SWFCharacter)
Sets the character for this button's hit test state */
PHP_FUNCTION(swfbutton_setHit)
{
zval **zchar;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFCharacter character;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zchar) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zchar);
character = getCharacter(*zchar TSRMLS_CC);
SWFButton_addShape(button, character, SWFBUTTONRECORD_HITSTATE);
}
/* }}} */
/* {{{ proto void swfbutton_setOver(SWFCharacter)
Sets the character for this button's over state */
PHP_FUNCTION(swfbutton_setOver)
{
zval **zchar;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFCharacter character;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zchar) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zchar);
character = getCharacter(*zchar TSRMLS_CC);
SWFButton_addShape(button, character, SWFBUTTONRECORD_OVERSTATE);
}
/* }}} */
/* {{{ proto void swfbutton_setUp(SWFCharacter)
Sets the character for this button's up state */
PHP_FUNCTION(swfbutton_setUp)
{
zval **zchar;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFCharacter character;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zchar) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zchar);
character = getCharacter(*zchar TSRMLS_CC);
SWFButton_addShape(button, character, SWFBUTTONRECORD_UPSTATE);
}
/* }}} */
/* {{{ proto void swfbutton_setDown(SWFCharacter)
Sets the character for this button's down state */
PHP_FUNCTION(swfbutton_setDown)
{
zval **zchar;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFCharacter character;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zchar) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zchar);
character = getCharacter(*zchar TSRMLS_CC);
SWFButton_addShape(button, character, SWFBUTTONRECORD_DOWNSTATE);
}
/* }}} */
/* {{{ proto void swfbutton_addShape(SWFCharacter character, int flags)
Sets the character to display for the condition described in flags */
PHP_FUNCTION(swfbutton_addShape)
{
zval **zchar, **flags;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFCharacter character;
if(ZEND_NUM_ARGS() != 2 ||
zend_get_parameters_ex(2, &zchar, &flags) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zchar);
character = getCharacter(*zchar TSRMLS_CC);
convert_to_long_ex(flags);
SWFButton_addShape(button, character, Z_LVAL_PP(flags));
}
/* }}} */
/* {{{ proto void swfbutton_setAction(SWFAction)
Sets the action to perform when button is pressed */
PHP_FUNCTION(swfbutton_setAction)
{
zval **zaction;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFAction action;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zaction) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zaction);
action = getAction(*zaction TSRMLS_CC);
SWFButton_addAction(button, action, SWFBUTTON_OVERDOWNTOOVERUP);
}
/* }}} */
/* {{{ proto void swfbutton_addAction(SWFAction action, int flags)
Sets the action to perform when conditions described in flags is met */
PHP_FUNCTION(swfbutton_addAction)
{
zval **zaction, **flags;
SWFButton button = getButton(getThis() TSRMLS_CC);
SWFAction action;
if(ZEND_NUM_ARGS() != 2 ||
zend_get_parameters_ex(2, &zaction, &flags) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zaction);
action = getAction(*zaction TSRMLS_CC);
convert_to_long_ex(flags);
SWFButton_addAction(button, action, Z_LVAL_PP(flags));
}
/* }}} */
/* {{{ proto int swfbutton_keypress(string str)
Returns the action flag for keyPress(char) */
PHP_FUNCTION(swfbutton_keypress)
{
zval **key;
char c;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &key) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_string_ex(key);
if(Z_STRLEN_PP(key) > 1)
php_error(E_ERROR, "SWFBUTTON_KEYPRESS expects only one character!");
c = Z_STRVAL_PP(key)[0];
RETURN_LONG((c&0x7f)<<9);
}
/* }}} */
/* }}} */
/* {{{ SWFDisplayitem */
static zend_function_entry swfdisplayitem_functions[] = {
PHP_FALIAS(moveto, swfdisplayitem_moveTo, NULL)
PHP_FALIAS(move, swfdisplayitem_move, NULL)
PHP_FALIAS(scaleto, swfdisplayitem_scaleTo, NULL)
PHP_FALIAS(scale, swfdisplayitem_scale, NULL)
PHP_FALIAS(rotateto, swfdisplayitem_rotateTo, NULL)
PHP_FALIAS(rotate, swfdisplayitem_rotate, NULL)
PHP_FALIAS(skewxto, swfdisplayitem_skewXTo, NULL)
PHP_FALIAS(skewx, swfdisplayitem_skewX, NULL)
PHP_FALIAS(skewyto, swfdisplayitem_skewYTo, NULL)
PHP_FALIAS(skewy, swfdisplayitem_skewY, NULL)
PHP_FALIAS(setmatrix, swfdisplayitem_setMatrix, NULL)
PHP_FALIAS(setdepth, swfdisplayitem_setDepth, NULL)
PHP_FALIAS(setratio, swfdisplayitem_setRatio, NULL)
PHP_FALIAS(addcolor, swfdisplayitem_addColor, NULL)
PHP_FALIAS(multcolor, swfdisplayitem_multColor, NULL)
PHP_FALIAS(setname, swfdisplayitem_setName, NULL)
PHP_FALIAS(addaction, swfdisplayitem_addAction, NULL)
{ NULL, NULL, NULL }
};
/* {{{ internal function getDisplayItem
Returns the SWFDisplayItem contained in zval *id */
static SWFDisplayItem getDisplayItem(zval *id TSRMLS_DC)
{
void *item = SWFgetProperty(id, "displayitem", 11, le_swfdisplayitemp TSRMLS_CC);
if(!item)
php_error(E_ERROR, "called object is not an SWFDisplayItem!");
return (SWFDisplayItem)item;
}
/* }}} */
/* {{{ proto void swfdisplayitem_moveTo(int x, int y)
Moves this SWFDisplayItem to movie coordinates (x, y) */
PHP_FUNCTION(swfdisplayitem_moveTo)
{
zval **x, **y;
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
convert_to_double_ex(y);
SWFDisplayItem_moveTo(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(x), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_move(int dx, int dy)
Displaces this SWFDisplayItem by (dx, dy) in movie coordinates */
PHP_FUNCTION(swfdisplayitem_move)
{
zval **x, **y;
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
convert_to_double_ex(y);
SWFDisplayItem_move(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(x), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_scaleTo(float xScale [, float yScale])
Scales this SWFDisplayItem by xScale in the x direction, yScale in the y, or both to xScale if only one arg */
PHP_FUNCTION(swfdisplayitem_scaleTo)
{
zval **x, **y;
if(ZEND_NUM_ARGS() == 1)
{
if(zend_get_parameters_ex(1, &x) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
SWFDisplayItem_scaleTo(getDisplayItem(getThis() TSRMLS_CC),
Z_DVAL_PP(x), Z_DVAL_PP(x));
}
else if(ZEND_NUM_ARGS() == 2)
{
if(zend_get_parameters_ex(2, &x, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
convert_to_double_ex(y);
SWFDisplayItem_scaleTo(getDisplayItem(getThis() TSRMLS_CC),
Z_DVAL_PP(x), Z_DVAL_PP(y));
}
else
WRONG_PARAM_COUNT;
}
/* }}} */
/* {{{ proto void swfdisplayitem_scale(float xScale, float yScale)
Multiplies this SWFDisplayItem's current x scale by xScale, its y scale by yScale */
PHP_FUNCTION(swfdisplayitem_scale)
{
zval **x, **y;
if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &x, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
convert_to_double_ex(y);
SWFDisplayItem_scale(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(x), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_rotateTo(float degrees)
Rotates this SWFDisplayItem the given (clockwise) degrees from its original orientation */
PHP_FUNCTION(swfdisplayitem_rotateTo)
{
zval **degrees;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, °rees) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(degrees);
SWFDisplayItem_rotateTo(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(degrees));
}
/* }}} */
/* {{{ proto void swfdisplayitem_rotate(float degrees)
Rotates this SWFDisplayItem the given (clockwise) degrees from its current orientation */
PHP_FUNCTION(swfdisplayitem_rotate)
{
zval **degrees;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, °rees) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(degrees);
SWFDisplayItem_rotate(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(degrees));
}
/* }}} */
/* {{{ proto void swfdisplayitem_skewXTo(float xSkew)
Sets this SWFDisplayItem's x skew value to xSkew */
PHP_FUNCTION(swfdisplayitem_skewXTo)
{
zval **x;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &x) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
SWFDisplayItem_skewXTo(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(x));
}
/* }}} */
/* {{{ proto void swfdisplayitem_skewX(float xSkew)
Adds xSkew to this SWFDisplayItem's x skew value */
PHP_FUNCTION(swfdisplayitem_skewX)
{
zval **x;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &x) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(x);
SWFDisplayItem_skewX(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(x));
}
/* }}} */
/* {{{ proto void swfdisplayitem_skewYTo(float ySkew)
Sets this SWFDisplayItem's y skew value to ySkew */
PHP_FUNCTION(swfdisplayitem_skewYTo)
{
zval **y;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(y);
SWFDisplayItem_skewYTo(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_skewY(float ySkew)
Adds ySkew to this SWFDisplayItem's y skew value */
PHP_FUNCTION(swfdisplayitem_skewY)
{
zval **y;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(y);
SWFDisplayItem_skewY(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_setMatrix(float a, float b, float c, float d, float x, float y)
Sets the item's transform matrix */
PHP_FUNCTION(swfdisplayitem_setMatrix)
{
zval **a, **b, **c, **d, **x, **y;
if(ZEND_NUM_ARGS() != 6 ||
zend_get_parameters_ex(6, &a, &b, &c, &d, &x, &y) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(a);
convert_to_double_ex(b);
convert_to_double_ex(c);
convert_to_double_ex(d);
convert_to_double_ex(x);
convert_to_double_ex(y);
SWFDisplayItem_setMatrix(getDisplayItem(getThis() TSRMLS_CC),
Z_DVAL_PP(a), Z_DVAL_PP(b), Z_DVAL_PP(c),
Z_DVAL_PP(d), Z_DVAL_PP(x), Z_DVAL_PP(y));
}
/* }}} */
/* {{{ proto void swfdisplayitem_setDepth(int depth)
Sets this SWFDisplayItem's z-depth to depth. Items with higher depth values are drawn on top of those with lower values */
PHP_FUNCTION(swfdisplayitem_setDepth)
{
zval **depth;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &depth) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long_ex(depth);
SWFDisplayItem_setDepth(getDisplayItem(getThis() TSRMLS_CC), Z_LVAL_PP(depth));
}
/* }}} */
/* {{{ proto void swfdisplayitem_setRatio(float ratio)
Sets this SWFDisplayItem's ratio to ratio. Obviously only does anything if displayitem was created from an SWFMorph */
PHP_FUNCTION(swfdisplayitem_setRatio)
{
zval **ratio;
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &ratio) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(ratio);
SWFDisplayItem_setRatio(getDisplayItem(getThis() TSRMLS_CC), Z_DVAL_PP(ratio));
}
/* }}} */
/* {{{ proto void swfdisplayitem_addColor(int r, int g, int b [, int a])
Sets the add color part of this SWFDisplayItem's CXform to (r, g, b [, a]), a defaults to 0 */
PHP_FUNCTION(swfdisplayitem_addColor)
{
zval **r, **g, **b, **za;
int a = 0;
if(ZEND_NUM_ARGS() == 4)
{
if(zend_get_parameters_ex(4, &r, &g, &b, &za) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long_ex(za);
a = Z_LVAL_PP(za);
}
else if(ZEND_NUM_ARGS() == 3)
{
if(zend_get_parameters_ex(3, &r, &g, &b) == FAILURE)
WRONG_PARAM_COUNT;
}
else
WRONG_PARAM_COUNT;
convert_to_long_ex(r);
convert_to_long_ex(g);
convert_to_long_ex(b);
SWFDisplayItem_setColorAdd(getDisplayItem(getThis() TSRMLS_CC),
Z_LVAL_PP(r), Z_LVAL_PP(g), Z_LVAL_PP(b), a);
}
/* }}} */
/* {{{ proto void swfdisplayitem_multColor(float r, float g, float b [, float a])
Sets the multiply color part of this SWFDisplayItem's CXform to (r, g, b [, a]),
a defaults to 1.0 */
PHP_FUNCTION(swfdisplayitem_multColor)
{
zval **r, **g, **b, **za;
float a = 1.0;
if(ZEND_NUM_ARGS() == 4)
{
if(zend_get_parameters_ex(4, &r, &g, &b, &za) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_double_ex(za);
a = Z_DVAL_PP(za);
}
else if(ZEND_NUM_ARGS() == 3)
{
if(zend_get_parameters_ex(3, &r, &g, &b) == FAILURE)
WRONG_PARAM_COUNT;
}
else
WRONG_PARAM_COUNT;
convert_to_double_ex(r);
convert_to_double_ex(g);
convert_to_double_ex(b);
SWFDisplayItem_setColorMult(getDisplayItem(getThis() TSRMLS_CC),
Z_DVAL_PP(r), Z_DVAL_PP(g), Z_DVAL_PP(b), a);
}
/* }}} */
/* {{{ proto void swfdisplayitem_setName(string name)
Sets this SWFDisplayItem's name to name */
PHP_FUNCTION(swfdisplayitem_setName)
{
zval **name;
SWFDisplayItem item = getDisplayItem(getThis() TSRMLS_CC);
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &name) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_string_ex(name);
SWFDisplayItem_setName(item, Z_STRVAL_PP(name));
}
/* }}} */
/* {{{ proto void swfdisplayitem_addAction(SWFAction action, int flags)
Adds this SWFAction to the given SWFSprite instance */
PHP_FUNCTION(swfdisplayitem_addAction)
{
zval **zaction, **flags;
SWFAction action;
SWFDisplayItem item = getDisplayItem(getThis() TSRMLS_CC);
if(ZEND_NUM_ARGS() != 2 ||
zend_get_parameters_ex(2, &zaction, &flags) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_object_ex(zaction);
convert_to_long_ex(flags);
action = (SWFBlock)getAction(*zaction TSRMLS_CC);
SWFDisplayItem_addAction(item, action, Z_LVAL_PP(flags));
}
/* }}} */
/* }}} */
/* {{{ SWFFill */
static zend_function_entry swffill_functions[] = {
PHP_FALIAS(swffill, swffill_init, NULL)
PHP_FALIAS(moveto, swffill_moveTo, NULL)