GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/ruby.c: attach effects methods to the image class. (blur, glow, 
 shadow.)
 * shoes/effects.c: new home for image effects.
why (author)
Mon Aug 11 22:57:11 -0700 2008
commit  070e27362b145f2a9660056e88247bf3e2d27eea
tree    15bf8d4e7d9c85ebba0210d6d54a051b38c419be
parent  33e363d65e3811eb9ad8852ea3a8803f0574bf23
...
1
2
3
4
 
5
6
7
...
1
2
3
 
4
5
6
7
0
@@ -1,7 +1,7 @@
0
 # shoes - abstract windowing for gtk, osx, and win32
0
 # by why the lucky stiff, released to you under the MIT license
0
 
0
-SRC = shoes/app.c shoes/canvas.c shoes/image.c shoes/internal.c shoes/ruby.c shoes/world.c shoes/native/gtk.c shoes/http/curl.c
0
+SRC = shoes/app.c shoes/canvas.c shoes/effects.c shoes/image.c shoes/internal.c shoes/ruby.c shoes/world.c shoes/native/gtk.c shoes/http/curl.c
0
 OBJ = ${SRC:.c=.o}
0
 
0
 PREFIX = /usr/local
...
17
18
19
 
 
 
 
 
 
 
20
21
22
...
435
436
437
438
439
440
441
442
443
 
444
445
446
...
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
...
17
18
19
20
21
22
23
24
25
26
27
28
29
...
442
443
444
 
 
 
 
 
 
445
446
447
448
...
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
0
@@ -17,6 +17,13 @@
0
 #define SETUP_BASIC() \
0
   shoes_basic *basic; \
0
   Data_Get_Struct(self, shoes_basic, basic);
0
+#define SETUP_IMAGE() \
0
+ shoes_place place; \
0
+ GET_STRUCT(image, image); \
0
+ shoes_image_ensure_dup(image); \
0
+ shoes_place_exact(&place, attr, 0, 0); \
0
+ if (NIL_P(attr)) attr = image->attr; \
0
+ else if (!NIL_P(image->attr)) attr = rb_funcall(image->attr, s_merge, 1, attr);
0
 
0
 const double SHOES_PIM2 = 6.28318530717958647693;
0
 const double SHOES_PI = 3.14159265358979323846;
0
@@ -435,12 +442,7 @@ shoes_add_shape(VALUE self, ID name, VALUE attr)
0
 {
0
   if (rb_obj_is_kind_of(self, cImage))
0
   {
0
- shoes_place place;
0
- GET_STRUCT(image, image);
0
- shoes_image_ensure_dup(image);
0
- shoes_place_exact(&place, attr, 0, 0);
0
- if (NIL_P(attr)) attr = image->attr;
0
- else if (!NIL_P(image->attr)) rb_funcall(attr, s_update, 1, image->attr);
0
+ SETUP_IMAGE();
0
     shoes_shape_sketch(image->cr, name, &place, NULL, attr);
0
     return self;
0
   }
0
@@ -485,73 +487,39 @@ shoes_canvas_star(int argc, VALUE *argv, VALUE self)
0
 }
0
 
0
 VALUE
0
-shoes_canvas_blur(int argc, VALUE *argv, VALUE self)
0
+shoes_add_effect(VALUE self, ID name, VALUE attr)
0
 {
0
- VALUE x, y, fx, attr;
0
- SETUP();
0
-
0
- rb_scan_args(argc, argv, "02", &x, &y);
0
- if (NIL_P(y)) y = x;
0
-
0
- if (rb_obj_is_kind_of(x, rb_cHash))
0
- attr = x;
0
- else
0
+ if (rb_obj_is_kind_of(self, cImage))
0
   {
0
- attr = rb_hash_new();
0
- if (!NIL_P(x)) rb_hash_aset(attr, ID2SYM(s_width), x);
0
- if (!NIL_P(y)) rb_hash_aset(attr, ID2SYM(s_height), y);
0
+ shoes_effect_filter filter = shoes_effect_for_type(name);
0
+ SETUP_IMAGE();
0
+ filter(image->cr, attr, &place);
0
+ return self;
0
   }
0
 
0
- fx = shoes_effect_new(cBlur, attr, self);
0
- shoes_add_ele(canvas, fx);
0
- return fx;
0
+ SETUP();
0
+ return shoes_add_ele(canvas, shoes_effect_new(name, attr, self));
0
 }
0
 
0
 VALUE
0
-shoes_canvas_glow(int argc, VALUE *argv, VALUE self)
0
+shoes_canvas_blur(int argc, VALUE *argv, VALUE self)
0
 {
0
- VALUE x, y, fx, attr;
0
- SETUP();
0
-
0
- rb_scan_args(argc, argv, "02", &x, &y);
0
- if (NIL_P(y)) y = x;
0
-
0
- if (rb_obj_is_kind_of(x, rb_cHash))
0
- attr = x;
0
- else
0
- {
0
- attr = rb_hash_new();
0
- if (!NIL_P(x)) rb_hash_aset(attr, ID2SYM(s_width), x);
0
- if (!NIL_P(y)) rb_hash_aset(attr, ID2SYM(s_height), y);
0
- }
0
+ VALUE attr = shoes_shape_attr(argc, argv, 2, s_width, s_height);
0
+ return shoes_add_effect(self, s_blur, attr);
0
+}
0
 
0
- fx = shoes_effect_new(cGlow, attr, self);
0
- shoes_add_ele(canvas, fx);
0
- return fx;
0
+VALUE
0
+shoes_canvas_glow(int argc, VALUE *argv, VALUE self)
0
+{
0
+ VALUE attr = shoes_shape_attr(argc, argv, 2, s_width, s_height);
0
+ return shoes_add_effect(self, s_glow, attr);
0
 }
0
 
0
 VALUE
0
 shoes_canvas_shadow(int argc, VALUE *argv, VALUE self)
0
 {
0
- VALUE dist, x, y, fx, attr;
0
- SETUP();
0
-
0
- rb_scan_args(argc, argv, "03", &dist, &x, &y);
0
- if (NIL_P(y)) y = x;
0
-
0
- if (rb_obj_is_kind_of(x, rb_cHash))
0
- attr = x;
0
- else
0
- {
0
- attr = rb_hash_new();
0
- if (!NIL_P(dist)) rb_hash_aset(attr, ID2SYM(s_distance), dist);
0
- if (!NIL_P(x)) rb_hash_aset(attr, ID2SYM(s_width), x);
0
- if (!NIL_P(y)) rb_hash_aset(attr, ID2SYM(s_height), y);
0
- }
0
-
0
- fx = shoes_effect_new(cShadow, attr, self);
0
- shoes_add_ele(canvas, fx);
0
- return fx;
0
+ VALUE attr = shoes_shape_attr(argc, argv, 2, s_distance, s_width, s_height);
0
+ return shoes_add_effect(self, s_shadow, attr);
0
 }
0
 
0
 #define MARKUP_BLOCK(klass) \
...
65
66
67
 
 
68
69
70
...
241
242
243
244
 
245
246
247
248
249
250
 
251
252
253
...
500
501
502
503
 
 
504
505
506
...
65
66
67
68
69
70
71
72
...
243
244
245
 
246
247
248
249
250
 
251
252
253
254
255
...
502
503
504
 
505
506
507
508
509
0
@@ -65,6 +65,8 @@ typedef struct {
0
     blk; \
0
     rb_ary_pop(app->nesting); \
0
   }
0
+#define PATTERN_DIM(self_t, x) (self_t->cached != NULL ? self_t->cached->x : 1)
0
+#define PATTERN(self_t) (self_t->cached != NULL ? self_t->cached->pattern : self_t->pattern)
0
 #define ABSX(place) ((place).flags & FLAG_ABSX)
0
 #define ABSY(place) ((place).flags & FLAG_ABSY)
0
 #define POS(place) ((place).flags & FLAG_POSITION)
0
@@ -241,13 +243,13 @@ typedef struct {
0
   SHOES_TIMER_REF ref;
0
 } shoes_timer;
0
 
0
-typedef void (*shoes_effect_filter)(cairo_t *, void *);
0
+typedef void (*shoes_effect_filter)(cairo_t *, VALUE attr, shoes_place *);
0
 
0
 typedef struct {
0
   VALUE parent;
0
   VALUE attr;
0
- shoes_effect_filter filter;
0
   shoes_place place;
0
+ shoes_effect_filter filter;
0
 } shoes_effect;
0
 
0
 typedef struct {
0
@@ -500,7 +502,8 @@ VALUE shoes_image_motion(VALUE, int, int, char *);
0
 VALUE shoes_image_send_click(VALUE, int, int, int);
0
 void shoes_image_send_release(VALUE, int, int, int);
0
 
0
-VALUE shoes_effect_new(VALUE, VALUE, VALUE);
0
+shoes_effect_filter shoes_effect_for_type(ID);
0
+VALUE shoes_effect_new(ID, VALUE, VALUE);
0
 VALUE shoes_effect_alloc(VALUE);
0
 VALUE shoes_effect_draw(VALUE, VALUE, VALUE);
0
 
...
10
11
12
 
13
14
15
 
16
17
18
19
 
20
21
22
...
296
297
298
299
300
 
 
301
302
303
...
522
523
524
525
526
527
528
529
530
...
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
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
...
1341
1342
1343
 
 
 
 
 
 
 
 
 
 
 
 
1344
1345
 
1346
1347
1348
1349
 
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
 
1360
1361
1362
...
1377
1378
1379
1380
1381
1382
1383
 
 
1384
1385
1386
...
4183
4184
4185
 
4186
4187
4188
...
4269
4270
4271
 
 
 
4272
4273
4274
...
4405
4406
4407
 
 
 
4408
4409
4410
...
4438
4439
4440
4441
4442
4443
4444
4445
4446
...
10
11
12
13
14
15
 
16
17
18
19
 
20
21
22
23
...
297
298
299
 
 
300
301
302
303
304
...
523
524
525
 
 
 
526
527
528
...
1025
1026
1027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1028
1029
1030
...
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
...
1139
1140
1141
 
 
 
 
1142
1143
1144
1145
1146
...
3943
3944
3945
3946
3947
3948
3949
...
4030
4031
4032
4033
4034
4035
4036
4037
4038
...
4169
4170
4171
4172
4173
4174
4175
4176
4177
...
4205
4206
4207
 
 
 
4208
4209
4210
0
@@ -10,13 +10,14 @@
0
 #include "shoes/native.h"
0
 #include "shoes/version.h"
0
 #include "shoes/http.h"
0
+#include "shoes/effects.h"
0
 #include <math.h>
0
 
0
-VALUE cShoes, cApp, cDialog, cShoesWindow, cMouse, cCanvas, cFlow, cStack, cMask, cWidget, cShape, cImage, cEffect, cBlur, cShadow, cGlow, cVideo, cTimerBase, cTimer, cEvery, cAnim, cPattern, cBorder, cBackground, cTextBlock, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cTextClass, cSpan, cDel, cStrong, cSub, cSup, cCode, cEm, cIns, cLinkUrl, cNative, cButton, cCheck, cRadio, cEditLine, cEditBox, cListBox, cProgress, cColor, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
0
+VALUE cShoes, cApp, cDialog, cShoesWindow, cMouse, cCanvas, cFlow, cStack, cMask, cWidget, cShape, cImage, cEffect, cVideo, cTimerBase, cTimer, cEvery, cAnim, cPattern, cBorder, cBackground, cTextBlock, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cTextClass, cSpan, cDel, cStrong, cSub, cSup, cCode, cEm, cIns, cLinkUrl, cNative, cButton, cCheck, cRadio, cEditLine, cEditBox, cListBox, cProgress, cColor, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
0
 VALUE eVlcError, eImageError, eInvMode, eNotImpl;
0
 VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE, reLF;
0
 VALUE symAltQuest, symAltSlash, symAltDot;
0
-ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_arrow, s_autoplay, s_begin, s_body, s_call, s_center, s_change, s_checked, s_checked_q, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_headers, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_method, s_motion, s_path, s_port, s_progress, s_release, s_request_uri, s_save, s_wheel, s_stroke, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_rect, s_oval, s_line, s_star;
0
+ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_merge, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_arrow, s_autoplay, s_begin, s_body, s_call, s_center, s_change, s_checked, s_checked_q, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_headers, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_method, s_motion, s_path, s_port, s_progress, s_release, s_request_uri, s_save, s_wheel, s_stroke, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_blur, s_glow, s_shadow, s_rect, s_oval, s_line, s_star;
0
 
0
 //
0
 // Mauricio's instance_eval hack (he bested my cloaker back in 06 Jun 2006)
0
@@ -296,8 +297,8 @@ shoes_place_exact(shoes_place *place, VALUE attr, int ox, int oy)
0
   place->dx = ATTR2(int, attr, displace_left, 0);
0
   place->dy = ATTR2(int, attr, displace_top, 0);
0
   place->flags = FLAG_ABSX | FLAG_ABSY;
0
- place->ix = place->x = NUM2INT(ATTR(attr, left)) + ox;
0
- place->iy = place->y = NUM2INT(ATTR(attr, top)) + oy;
0
+ place->ix = place->x = ATTR2(int, attr, left, 0) + ox;
0
+ place->iy = place->y = ATTR2(int, attr, top, 0) + oy;
0
   r = ATTR2(int, attr, radius, 0) * 2;
0
   place->iw = place->w = ATTR2(int, attr, width, r);
0
   place->ih = place->h = ATTR2(int, attr, height, place->w);
0
@@ -522,9 +523,6 @@ shoes_control_show_ref(SHOES_CONTROL_REF ref)
0
     canvas->cy = canvas->endy; \
0
   }
0
 
0
-#define PATTERN_DIM(self_t, x) (self_t->cached != NULL ? self_t->cached->x : 1)
0
-#define PATTERN(self_t) (self_t->cached != NULL ? self_t->cached->pattern : self_t->pattern)
0
-
0
 #define PATTERN_SCALE(self_t, place, sw) \
0
   if (self_t->cached == NULL) \
0
   { \
0
@@ -1027,249 +1025,6 @@ shoes_image_size(VALUE self)
0
   return rb_ary_new3(2, INT2NUM(self_t->cached->width), INT2NUM(self_t->cached->height));
0
 }
0
 
0
-static unsigned char *
0
-box_run(unsigned int size)
0
-{
0
- int i;
0
- unsigned char *tmp = SHOE_ALLOC_N(unsigned char, size * 256);
0
- for (i = 0; i < 256; i++)
0
- memset(tmp + i * size, i, size);
0
- return tmp;
0
-}
0
-
0
-#define BOX_H 1
0
-#define BOX_V 2
0
-
0
-static void
0
-box_blur(unsigned char *in, unsigned char *out,
0
- int stride, shoes_place place,
0
- unsigned int edge1, unsigned int edge2,
0
- const unsigned char *run, int dir)
0
-{
0
- int i, j1, j2, l, l2, l3, l4, lx, c1, c2, c3, c4, start;
0
- int boxSize = edge1 + edge2 + 1;
0
- if (dir == BOX_H)
0
- {
0
- c1 = place.y;
0
- c2 = place.y + place.h;
0
- c3 = place.x;
0
- c4 = place.x + place.w;
0
- }
0
- else
0
- {
0
- c1 = place.x;
0
- c2 = place.x + place.w;
0
- c3 = place.y;
0
- c4 = place.y + place.h;
0
- }
0
-
0
- start = c3 - edge1;
0
- for (j1 = c1; j1 < c2; j1++) {
0
- unsigned int sums[4] = {0, 0, 0, 0};
0
- if (dir == BOX_H)
0
- l = stride * j1;
0
- else
0
- lx = j1 << 2;
0
- for (i = 0; i < boxSize; i++) {
0
- int pos = start + i;
0
- pos = max(pos, c3);
0
- pos = min(pos, c4 - 1);
0
- if (dir == BOX_V)
0
- l = stride * pos + lx;
0
- sums[0] += in[l];
0
- sums[1] += in[l + 1];
0
- sums[2] += in[l + 2];
0
- sums[3] += in[l + 3];
0
- }
0
- for (j2 = c3; j2 < c4; j2++) {
0
- if (dir == BOX_H)
0
- l2 = l + (j2 << 2);
0
- else
0
- l2 = stride * j2 + lx;
0
- out[l2] = run[sums[0]];
0
- out[l2 + 1] = run[sums[1]];
0
- out[l2 + 2] = run[sums[2]];
0
- out[l2 + 3] = run[sums[3]];
0
-
0
- int tmp = j2 - edge1;
0
- int last = max(tmp, c3);
0
- int next = min(tmp + boxSize, c4 - 1);
0
- if (dir == BOX_H)
0
- {
0
- l3 = l + (next << 2);
0
- l4 = l + (last << 2);
0
- }
0
- else
0
- {
0
- l3 = stride * next + lx;
0
- l4 = stride * last + lx;
0
- }
0
-
0
- sums[0] += in[l3] - in[l4];
0
- sums[1] += in[l3 + 1] - in[l4 + 1];
0
- sums[2] += in[l3 + 2] - in[l4 + 2];
0
- sums[3] += in[l3 + 3] - in[l4 + 3];
0
- }
0
- }
0
-}
0
-
0
-#define RAW_FILTER_START(self_t) \
0
- int width, height, stride; \
0
- guchar *out; \
0
- static const cairo_user_data_key_t key; \
0
- cairo_surface_t *source = cairo_get_target(cr); \
0
- cairo_surface_t *target; \
0
- unsigned char *in = cairo_image_surface_get_data(source); \
0
- \
0
- self_t->place.x = self_t->place.y = 0; \
0
- self_t->place.w = width = cairo_image_surface_get_width(source); \
0
- self_t->place.h = height = cairo_image_surface_get_height(source); \
0
- stride = cairo_image_surface_get_stride(source); \
0
- \
0
- out = (guchar *)g_malloc(4 * width * height); \
0
- target = cairo_image_surface_create_for_data((unsigned char *)out, \
0
- CAIRO_FORMAT_ARGB32, \
0
- width, height, 4 * width); \
0
- cairo_surface_set_user_data(target, &key, out, (cairo_destroy_func_t)g_free); \
0
- unsigned int len = 4 * width * height
0
-
0
-#define RAW_FILTER_END(self_t) \
0
- cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); \
0
- cairo_paint(cr); \
0
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER); \
0
- cairo_set_source_surface(cr, target, 0, 0); \
0
- cairo_paint(cr); \
0
- cairo_surface_destroy(target);
0
-
0
-void
0
-shoes_gaussian_blur_filter(cairo_t *cr, void *data)
0
-{
0
- shoes_effect *fx = (shoes_effect *)data;
0
- RAW_FILTER_START(fx);
0
- float blur_d = ATTR2(dbl, fx->attr, radius, 2.);
0
- float blur_x = ATTR2(dbl, fx->attr, width, blur_d);
0
- float blur_y = ATTR2(dbl, fx->attr, height, blur_d);
0
-
0
- if (blur_x < 0 || blur_y < 0)
0
- return;
0
-
0
- if (blur_x == 0 || blur_y == 0)
0
- memset(out, 0, len);
0
-
0
- unsigned int dX, dY;
0
- dX = (unsigned int) floor(blur_x * 3*sqrt(2*SHOES_PI)/4 + 0.5);
0
- dY = (unsigned int) floor(blur_y * 3*sqrt(2*SHOES_PI)/4 + 0.5);
0
-
0
- unsigned char *tmp = SHOE_ALLOC_N(unsigned char, len);
0
-
0
- if (dX & 1) {
0
- unsigned char *run = box_run(2 * (dX / 2) + 1);
0
- box_blur(in, tmp, stride, fx->place, dX/2, dX/2, run, BOX_H);
0
- box_blur(tmp, out, stride, fx->place, dX/2, dX/2, run, BOX_H);
0
- box_blur(out, tmp, stride, fx->place, dX/2, dX/2, run, BOX_H);
0
- SHOE_FREE(run);
0
- } else {
0
- if (dX == 0) {
0
- memcpy(tmp, in, len);
0
- } else {
0
- unsigned char *run1 = box_run(2 * (dX / 2) + 1);
0
- unsigned char *run2 = box_run(2 * (dX / 2));
0
- box_blur(in, tmp, stride, fx->place, dX/2, dX/2 - 1, run2, BOX_H);
0
- box_blur(tmp, out, stride, fx->place, dX/2 - 1, dX/2, run2, BOX_H);
0
- box_blur(out, tmp, stride, fx->place, dX/2, dX/2, run1, BOX_H);
0
- SHOE_FREE(run1);
0
- SHOE_FREE(run2);
0
- }
0
- }
0
-
0
- if (dY & 1) {
0
- unsigned char *run = box_run(2 * (dY / 2) + 1);
0
- box_blur(tmp, out, stride, fx->place, dY/2, dY/2, run, BOX_V);
0
- box_blur(out, tmp, stride, fx->place, dY/2, dY/2, run, BOX_V);
0
- box_blur(tmp, out, stride, fx->place, dY/2, dY/2, run, BOX_V);
0
- SHOE_FREE(run);
0
- } else {
0
- if (dY == 0) {
0
- memcpy(out, tmp, len);
0
- } else {
0
- unsigned char *run1 = box_run(2 * (dY / 2) + 1);
0
- unsigned char *run2 = box_run(2 * (dY / 2));
0
- box_blur(tmp, out, stride, fx->place, dY/2, dY/2 - 1, run2, BOX_V);
0
- box_blur(out, tmp, stride, fx->place, dY/2 - 1, dY/2, run2, BOX_V);
0
- box_blur(tmp, out, stride, fx->place, dY/2, dY/2, run1, BOX_V);
0
- SHOE_FREE(run1);
0
- SHOE_FREE(run2);
0
- }
0
- }
0
-
0
- SHOE_FREE(tmp);
0
- RAW_FILTER_END(fx);
0
-}
0
-
0
-static void
0
-shoes_layer_blur_filter(cairo_t *cr, void *data, cairo_operator_t blur_op,
0
- cairo_operator_t merge_op, int distance)
0
-{
0
- VALUE bg;
0
- shoes_canvas *canvas;
0
- shoes_effect *fx = (shoes_effect *)data;
0
- cairo_surface_t *source = cairo_get_target(cr);
0
- int width = cairo_image_surface_get_width(source);
0
- int height = cairo_image_surface_get_height(source);
0
- VALUE fill = ATTR(fx->attr, fill);
0
- Data_Get_Struct(fx->parent, shoes_canvas, canvas);
0
-
0
- cairo_surface_t *target = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
0
- cairo_t *cr2 = cairo_create(target);
0
- cairo_set_source_surface(cr2, source, distance, distance);
0
- cairo_paint(cr2);
0
- cairo_set_operator(cr2, blur_op);
0
- bg = ATTR(canvas->attr, fill);
0
- if (NIL_P(bg))
0
- cairo_set_source_rgb(cr2, 0., 0., 0.);
0
- else if (rb_obj_is_kind_of(bg, cColor))
0
- {
0
- shoes_color *color;
0
- Data_Get_Struct(bg, shoes_color, color);
0
- cairo_set_source_rgba(cr, color->r / 255., color->g / 255., color->b / 255., color->a / 255.);
0
- }
0
- else
0
- {
0
- shoes_pattern *pattern;
0
- Data_Get_Struct(bg, shoes_pattern, pattern);
0
- cairo_set_source(cr2, PATTERN(pattern));
0
- }
0
- cairo_rectangle(cr2, 0, 0, width, height);
0
- cairo_paint(cr2);
0
- shoes_gaussian_blur_filter(cr2, data);
0
- cairo_set_operator(cr, merge_op);
0
- cairo_set_source_surface(cr, target, 0, 0);
0
- cairo_paint(cr);
0
- cairo_destroy(cr2);
0
-}
0
-
0
-void
0
-shoes_shadow_filter(cairo_t *cr, void *data)
0
-{
0
- shoes_effect *fx = (shoes_effect *)data;
0
- int distance = ATTR2(int, fx->attr, distance, 4);
0
- shoes_layer_blur_filter(cr, data, CAIRO_OPERATOR_IN, CAIRO_OPERATOR_DEST_OVER, distance);
0
-}
0
-
0
-void
0
-shoes_glow_filter(cairo_t *cr, void *data)
0
-{
0
- shoes_effect *fx = (shoes_effect *)data;
0
- cairo_operator_t blur_op = CAIRO_OPERATOR_IN;
0
- cairo_operator_t merge_op = CAIRO_OPERATOR_DEST_OVER;
0
- if (RTEST(ATTR(fx->attr, inner)))
0
- {
0
- blur_op = CAIRO_OPERATOR_OUT;
0
- merge_op = CAIRO_OPERATOR_ATOP;
0
- }
0
- shoes_layer_blur_filter(cr, data, blur_op, merge_op, 0);
0
-}
0
-
0
 VALUE
0
 shoes_image_motion(VALUE self, int x, int y, char *touch)
0
 {
0
@@ -1341,22 +1096,29 @@ shoes_effect_free(shoes_effect *fx)
0
   RUBY_CRITICAL(free(fx));
0
 }
0
 
0
+shoes_effect_filter
0
+shoes_effect_for_type(ID name)
0
+{
0
+ if (name == s_blur)
0
+ return &shoes_gaussian_blur_filter;
0
+ else if (name == s_shadow)
0
+ return &shoes_shadow_filter;
0
+ else if (name == s_glow)
0
+ return &shoes_glow_filter;
0
+ return NULL;
0
+}
0
+
0
 VALUE
0
-shoes_effect_new(VALUE klass, VALUE attr, VALUE parent)
0
+shoes_effect_new(ID name, VALUE attr, VALUE parent)
0
 {
0
   shoes_effect *fx;
0
   shoes_canvas *canvas;
0
- VALUE obj = shoes_effect_alloc(klass);
0
+ VALUE obj = shoes_effect_alloc(cEffect);
0
   Data_Get_Struct(obj, shoes_effect, fx);
0
   Data_Get_Struct(parent, shoes_canvas, canvas);
0
   fx->parent = parent;
0
   fx->attr = attr;
0
- if (klass == cBlur)
0
- fx->filter = &shoes_gaussian_blur_filter;
0
- else if (klass == cShadow)
0
- fx->filter = &shoes_shadow_filter;
0
- else if (klass == cGlow)
0
- fx->filter = &shoes_glow_filter;
0
+ fx->filter = shoes_effect_for_type(name);
0
   return obj;
0
 }
0
 
0
@@ -1377,10 +1139,8 @@ shoes_effect_draw(VALUE self, VALUE c, VALUE actual)
0
 {
0
   SETUP(shoes_effect, REL_TILE, canvas->width, canvas->height);
0
 
0
- if (RTEST(actual))
0
- {
0
- self_t->filter(canvas->cr, (void *)self_t);
0
- }
0
+ if (RTEST(actual) && self_t->filter != NULL)
0
+ self_t->filter(canvas->cr, self_t->attr, &self_t->place);
0
 
0
   self_t->place = place;
0
   return self;
0
@@ -4183,6 +3943,7 @@ shoes_ruby_init()
0
   s_gsub = rb_intern("gsub");
0
   s_keys = rb_intern("keys");
0
   s_update = rb_intern("update");
0
+ s_merge = rb_intern("merge");
0
   s_new = rb_intern("new");
0
   s_URI = rb_intern("URI");
0
 
0
@@ -4269,6 +4030,9 @@ shoes_ruby_init()
0
   s_margin_bottom = rb_intern("margin_bottom");
0
   s_radius = rb_intern("radius");
0
   s_secret = rb_intern("secret");
0
+ s_blur = rb_intern("blur");
0
+ s_glow = rb_intern("glow");
0
+ s_shadow = rb_intern("shadow");
0
   s_rect = rb_intern("rect");
0
   s_oval = rb_intern("oval");
0
   s_line = rb_intern("line");
0
@@ -4405,6 +4169,9 @@ shoes_ruby_init()
0
   rb_define_method(cImage, "oval", CASTHOOK(shoes_canvas_oval), -1);
0
   rb_define_method(cImage, "rect", CASTHOOK(shoes_canvas_rect), -1);
0
   rb_define_method(cImage, "star", CASTHOOK(shoes_canvas_star), -1);
0
+ rb_define_method(cImage, "blur", CASTHOOK(shoes_canvas_blur), -1);
0
+ rb_define_method(cImage, "glow", CASTHOOK(shoes_canvas_glow), -1);
0
+ rb_define_method(cImage, "shadow", CASTHOOK(shoes_canvas_shadow), -1);
0
   rb_define_method(cImage, "path", CASTHOOK(shoes_image_get_path), 0);
0
   rb_define_method(cImage, "path=", CASTHOOK(shoes_image_set_path), 1);
0
   rb_define_method(cImage, "app", CASTHOOK(shoes_canvas_get_app), 0);
0
@@ -4438,9 +4205,6 @@ shoes_ruby_init()
0
   rb_define_alloc_func(cEffect, shoes_effect_alloc);
0
   rb_define_method(cEffect, "draw", CASTHOOK(shoes_effect_draw), 2);
0
   rb_define_method(cEffect, "remove", CASTHOOK(shoes_basic_remove), 0);
0
- cBlur = rb_define_class_under(cShoes, "Blur", cEffect);
0
- cShadow = rb_define_class_under(cShoes, "Shadow", cEffect);
0
- cGlow = rb_define_class_under(cShoes, "Glow", cEffect);
0
 
0
 #ifdef VIDEO
0
   cVideo = rb_define_class_under(cShoes, "Video", rb_cObject);
...
69
70
71
72
 
73
74
75
76
77
 
78
79
80
...
69
70
71
 
72
73
74
75
76
 
77
78
79
80
0
@@ -69,12 +69,12 @@ static inline void flip_endian(unsigned char* x, int length) {
0
 
0
 #undef s_host
0
 
0
-extern VALUE cShoes, cApp, cDialog, cShoesWindow, cMouse, cCanvas, cFlow, cStack, cMask, cNative, cShape, cVideo, cImage, cEffect, cBlur, cShadow, cGlow, cEvery, cTimer, cAnim, cPattern, cBorder, cBackground, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cLinkText, cTextBlock, cTextClass, cSpan, cStrong, cSub, cSup, cCode, cDel, cEm, cIns, cButton, cEditLine, cEditBox, cListBox, cProgress, cCheck, cRadio, cColor, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
0
+extern VALUE cShoes, cApp, cDialog, cShoesWindow, cMouse, cCanvas, cFlow, cStack, cMask, cNative, cShape, cVideo, cImage, cEffect, cEvery, cTimer, cAnim, cPattern, cBorder, cBackground, cPara, cBanner, cTitle, cSubtitle, cTagline, cCaption, cInscription, cLinkText, cTextBlock, cTextClass, cSpan, cStrong, cSub, cSup, cCode, cDel, cEm, cIns, cButton, cEditLine, cEditBox, cListBox, cProgress, cCheck, cRadio, cColor, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
0
 extern VALUE aMsgList;
0
 extern VALUE eInvMode, eNotImpl, eImageError;
0
 extern VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE, reLF;
0
 extern VALUE symAltQuest, symAltSlash, symAltDot;
0
-extern ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_arrow, s_autoplay, s_begin, s_call, s_center, s_change, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_motion, s_path, s_port, s_progress, s_release, s_request_uri, s_save, s_wheel, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_stroke, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_rect, s_oval, s_line, s_star;
0
+extern ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_merge, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_arrow, s_autoplay, s_begin, s_call, s_center, s_change, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_motion, s_path, s_port, s_progress, s_release, s_request_uri, s_save, s_wheel, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_stroke, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_blur, s_glow, s_shadow, s_rect, s_oval, s_line, s_star;
0
 extern VALUE instance_eval_proc;
0
 
0
 VALUE mfp_instance_eval(VALUE, VALUE);

Comments

    No one has commented yet.