Skip to content
Browse files

Extracting Shoes::Color into Ruby.

  • Loading branch information...
1 parent 72f1449 commit 3513e8576c1d8e403c5ee81c8c40b66b432b2103 @steveklabnik steveklabnik committed
Showing with 329 additions and 478 deletions.
  1. +2 −0 lib/shoes.rb
  2. +247 −0 lib/shoes/color.rb
  3. +1 −1 req/sqlite3/ext/sqlite3/mkmf.log
  4. +11 −2 shoes/canvas.c
  5. +0 −15 shoes/canvas.h
  6. +1 −0 shoes/effects.c
  7. +14 −2 shoes/native/cocoa.m
  8. +18 −3 shoes/native/gtk.c
  9. +18 −4 shoes/native/windows.c
  10. +16 −449 shoes/ruby.c
  11. +1 −2 shoes/ruby.h
View
2 lib/shoes.rb
@@ -552,3 +552,5 @@ def #{methc}(*a, &b)
def window(*a, &b)
Shoes.app(*a, &b)
end
+
+require_relative 'shoes/color'
View
247 lib/shoes/color.rb
@@ -0,0 +1,247 @@
+class Shoes::Types::Color
+ attr_accessor :r, :g, :b, :a
+
+ def initialize(r_or_color, g, b, a=255)
+ @r = r
+ @g = g
+ @b = b
+ @a = a
+ end
+
+ def self.rgb(r, g, b, a=255)
+ new(r, g, b, a)
+ end
+
+ # parses out a color
+ def self.parse(source)
+ end
+
+ include Comparable
+
+ def <=>(other)
+ alert("fffuuu")
+ return nil unless other.kind_if?(Color)
+
+ alert("zomg!")
+ if r == other.r and g == other.g and b == other.b
+ return 0
+ else
+ v1 = r + g + b
+ v2 = other.r + other.g + other.b
+ return 0 if v1 == v2
+ return 1 if v1 > v2
+ return -1
+ end
+ end
+
+ def red
+ r
+ end
+
+ def green
+ g
+ end
+
+ def blue
+ b
+ end
+
+ def alpha
+ a
+ end
+
+ def black?
+ r + g + b == 0
+ end
+
+ def dark?
+ r + g + b < 255
+ end
+
+ def light?
+ r + g + b > 510
+ end
+
+ def opaque?
+ a == 255
+ end
+
+ def transparent?
+ a == 0
+ end
+
+ def white?
+ r + g + b == 765
+ end
+
+ def invert
+ new(255 - r, 255 - g, 255 - b, 255)
+ end
+
+ def to_s
+ if a == 255
+ "rgb(%s, %s, %s)" % [r, g, b]
+ else
+ "rgb(%s, %s, %s, %0.1f)" % [r, g, b, a / 255.0]
+ end
+ end
+
+ def to_pattern
+ pattern(self)
+ end
+
+ def inspect
+ to_s
+ end
+end
+
+module Kernel
+ def rgb(r, g, b, a=255)
+ Shoes::Color.rgb(r, g, b, a)
+ end
+ def gray(num)
+ Shoes::Color.new(num, num, num, 255)
+ end
+end
+
+aliceblue = Shoes::Color.new(240, 248, 255)
+antiquewhite = Shoes::Color.new(250, 235, 215)
+aqua = Shoes::Color.new(0, 255, 255)
+aquamarine = Shoes::Color.new(127, 255, 212)
+azure = Shoes::Color.new(240, 255, 255)
+beige = Shoes::Color.new(245, 245, 220)
+bisque = Shoes::Color.new(255, 228, 196)
+black = Shoes::Color.new(0, 0, 0)
+blanchedalmond = Shoes::Color.new(255, 235, 205)
+blue = Shoes::Color.new(0, 0, 255)
+blueviolet = Shoes::Color.new(138, 43, 226)
+brown = Shoes::Color.new(165, 42, 42)
+burlywood = Shoes::Color.new(222, 184, 135)
+cadetblue = Shoes::Color.new(95, 158, 160)
+chartreuse = Shoes::Color.new(127, 255, 0)
+chocolate = Shoes::Color.new(210, 105, 30)
+coral = Shoes::Color.new(255, 127, 80)
+cornflowerblue = Shoes::Color.new(100, 149, 237)
+cornsilk = Shoes::Color.new(255, 248, 220)
+crimson = Shoes::Color.new(220, 20, 60)
+cyan = Shoes::Color.new(0, 255, 255)
+darkblue = Shoes::Color.new(0, 0, 139)
+darkcyan = Shoes::Color.new(0, 139, 139)
+darkgoldenrod = Shoes::Color.new(184, 134, 11)
+darkgray = Shoes::Color.new(169, 169, 169)
+darkgreen = Shoes::Color.new(0, 100, 0)
+darkkhaki = Shoes::Color.new(189, 183, 107)
+darkmagenta = Shoes::Color.new(139, 0, 139)
+darkolivegreen = Shoes::Color.new(85, 107, 47)
+darkorange = Shoes::Color.new(255, 140, 0)
+darkorchid = Shoes::Color.new(153, 50, 204)
+darkred = Shoes::Color.new(139, 0, 0)
+darksalmon = Shoes::Color.new(233, 150, 122)
+darkseagreen = Shoes::Color.new(143, 188, 143)
+darkslateblue = Shoes::Color.new(72, 61, 139)
+darkslategray = Shoes::Color.new(47, 79, 79)
+darkturquoise = Shoes::Color.new(0, 206, 209)
+darkviolet = Shoes::Color.new(148, 0, 211)
+deeppink = Shoes::Color.new(255, 20, 147)
+deepskyblue = Shoes::Color.new(0, 191, 255)
+dimgray = Shoes::Color.new(105, 105, 105)
+dodgerblue = Shoes::Color.new(30, 144, 255)
+firebrick = Shoes::Color.new(178, 34, 34)
+floralwhite = Shoes::Color.new(255, 250, 240)
+forestgreen = Shoes::Color.new(34, 139, 34)
+fuchsia = Shoes::Color.new(255, 0, 255)
+gainsboro = Shoes::Color.new(220, 220, 220)
+ghostwhite = Shoes::Color.new(248, 248, 255)
+gold = Shoes::Color.new(255, 215, 0)
+goldenrod = Shoes::Color.new(218, 165, 32)
+gray = Shoes::Color.new(128, 128, 128)
+green = Shoes::Color.new(0, 128, 0)
+greenyellow = Shoes::Color.new(173, 255, 47)
+honeydew = Shoes::Color.new(240, 255, 240)
+hotpink = Shoes::Color.new(255, 105, 180)
+indianred = Shoes::Color.new(205, 92, 92)
+indigo = Shoes::Color.new(75, 0, 130)
+ivory = Shoes::Color.new(255, 255, 240)
+khaki = Shoes::Color.new(240, 230, 140)
+lavender = Shoes::Color.new(230, 230, 250)
+lavenderblush = Shoes::Color.new(255, 240, 245)
+lawngreen = Shoes::Color.new(124, 252, 0)
+lemonchiffon = Shoes::Color.new(255, 250, 205)
+lightblue = Shoes::Color.new(173, 216, 230)
+lightcoral = Shoes::Color.new(240, 128, 128)
+lightcyan = Shoes::Color.new(224, 255, 255)
+lightgoldenrodyellow = Shoes::Color.new(250, 250, 210)
+lightgreen = Shoes::Color.new(144, 238, 144)
+lightgrey = Shoes::Color.new(211, 211, 211)
+lightpink = Shoes::Color.new(255, 182, 193)
+lightsalmon = Shoes::Color.new(255, 160, 122)
+lightseagreen = Shoes::Color.new(32, 178, 170)
+lightskyblue = Shoes::Color.new(135, 206, 250)
+lightslategray = Shoes::Color.new(119, 136, 153)
+lightsteelblue = Shoes::Color.new(176, 196, 222)
+lightyellow = Shoes::Color.new(255, 255, 224)
+lime = Shoes::Color.new(0, 255, 0)
+limegreen = Shoes::Color.new(50, 205, 50)
+linen = Shoes::Color.new(250, 240, 230)
+magenta = Shoes::Color.new(255, 0, 255)
+maroon = Shoes::Color.new(128, 0, 0)
+mediumaquamarine = Shoes::Color.new(102, 205, 170)
+mediumblue = Shoes::Color.new(0, 0, 205)
+mediumorchid = Shoes::Color.new(186, 85, 211)
+mediumpurple = Shoes::Color.new(147, 112, 219)
+mediumseagreen = Shoes::Color.new(60, 179, 113)
+mediumslateblue = Shoes::Color.new(123, 104, 238)
+mediumspringgreen = Shoes::Color.new(0, 250, 154)
+mediumturquoise = Shoes::Color.new(72, 209, 204)
+mediumvioletred = Shoes::Color.new(199, 21, 133)
+midnightblue = Shoes::Color.new(25, 25, 112)
+mintcream = Shoes::Color.new(245, 255, 250)
+mistyrose = Shoes::Color.new(255, 228, 225)
+moccasin = Shoes::Color.new(255, 228, 181)
+navajowhite = Shoes::Color.new(255, 222, 173)
+navy = Shoes::Color.new(0, 0, 128)
+oldlace = Shoes::Color.new(253, 245, 230)
+olive = Shoes::Color.new(128, 128, 0)
+olivedrab = Shoes::Color.new(107, 142, 35)
+orange = Shoes::Color.new(255, 165, 0)
+orangered = Shoes::Color.new(255, 69, 0)
+orchid = Shoes::Color.new(218, 112, 214)
+palegoldenrod = Shoes::Color.new(238, 232, 170)
+palegreen = Shoes::Color.new(152, 251, 152)
+paleturquoise = Shoes::Color.new(175, 238, 238)
+palevioletred = Shoes::Color.new(219, 112, 147)
+papayawhip = Shoes::Color.new(255, 239, 213)
+peachpuff = Shoes::Color.new(255, 218, 185)
+peru = Shoes::Color.new(205, 133, 63)
+pink = Shoes::Color.new(255, 192, 203)
+plum = Shoes::Color.new(221, 160, 221)
+powderblue = Shoes::Color.new(176, 224, 230)
+purple = Shoes::Color.new(128, 0, 128)
+red = Shoes::Color.new(255, 0, 0)
+rosybrown = Shoes::Color.new(188, 143, 143)
+royalblue = Shoes::Color.new(65, 105, 225)
+saddlebrown = Shoes::Color.new(139, 69, 19)
+salmon = Shoes::Color.new(250, 128, 114)
+sandybrown = Shoes::Color.new(244, 164, 96)
+seagreen = Shoes::Color.new(46, 139, 87)
+seashell = Shoes::Color.new(255, 245, 238)
+sienna = Shoes::Color.new(160, 82, 45)
+silver = Shoes::Color.new(192, 192, 192)
+skyblue = Shoes::Color.new(135, 206, 235)
+slateblue = Shoes::Color.new(106, 90, 205)
+slategray = Shoes::Color.new(112, 128, 144)
+snow = Shoes::Color.new(255, 250, 250)
+springgreen = Shoes::Color.new(0, 255, 127)
+steelblue = Shoes::Color.new(70, 130, 180)
+tan = Shoes::Color.new(210, 180, 140)
+teal = Shoes::Color.new(0, 128, 128)
+thistle = Shoes::Color.new(216, 191, 216)
+tomato = Shoes::Color.new(255, 99, 71)
+turquoise = Shoes::Color.new(64, 224, 208)
+violet = Shoes::Color.new(238, 130, 238)
+wheat = Shoes::Color.new(245, 222, 179)
+white = Shoes::Color.new(255, 255, 255)
+whitesmoke = Shoes::Color.new(245, 245, 245)
+yellow = Shoes::Color.new(255, 255, 0)
+yellowgreen = Shoes::Color.new(154, 205, 50)
+
View
2 req/sqlite3/ext/sqlite3/mkmf.log
@@ -87,7 +87,7 @@ conftest.c:5: warning: implicit declaration of function ‘sqlite3_column_databa
ld: warning: directory not found for option '-L/opt/local/lib'
Undefined symbols for architecture x86_64:
"_sqlite3_column_database_name", referenced from:
- _t in cc60aeKV.o
+ _t in cca7PYCB.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
checked program was:
View
13 shoes/canvas.c
@@ -10,6 +10,8 @@
#include "shoes/native.h"
#include "shoes/http.h"
+extern VALUE cColor;
+
#define SETUP() \
shoes_canvas *canvas; \
cairo_t *cr; \
@@ -353,8 +355,13 @@ shoes_canvas_clear(VALUE self)
canvas->attr = rb_hash_new();
ATTRSET(canvas->attr, cap, Qnil);
ATTRSET(canvas->attr, strokewidth, rb_float_new(1.));
- ATTRSET(canvas->attr, stroke, shoes_color_new(0, 0, 0, 0xFF));
- ATTRSET(canvas->attr, fill, shoes_color_new(0, 0, 0, 0xFF));
+ VALUE *colors[4];
+ colors[0] = 0;
+ colors[1] = 0;
+ colors[2] = 0;
+ colors[3] = 0xFF;
+ ATTRSET(canvas->attr, stroke, rb_class_new_instance(4, colors, cColor));
+ ATTRSET(canvas->attr, fill, rb_class_new_instance(4, colors, cColor));
canvas->parent = Qnil;
canvas->stl = 0;
canvas->stt = 0;
@@ -415,6 +422,7 @@ shoes_canvas_stroke(int argc, VALUE *argv, VALUE self)
{
VALUE pat;
SETUP_BASIC();
+ VALUE cColor = rb_const_get(rb_cObject, rb_intern("Shoes::Color"));
if (argc == 1 && rb_respond_to(argv[0], s_to_pattern))
pat = argv[0];
else
@@ -462,6 +470,7 @@ shoes_canvas_fill(int argc, VALUE *argv, VALUE self)
{
VALUE pat;
SETUP_BASIC();
+ VALUE cColor = rb_const_get(rb_cObject, rb_intern("Shoes::Color"));
if (argc == 1 && rb_respond_to(argv[0], s_to_pattern))
pat = argv[0];
else
View
15 shoes/canvas.h
@@ -571,22 +571,7 @@ VALUE shoes_timer_start(VALUE);
VALUE shoes_timer_stop(VALUE);
void shoes_timer_call(VALUE);
-void shoes_color_mark(shoes_color *);
-VALUE shoes_color_new(int, int, int, int);
-VALUE shoes_color_alloc(VALUE);
-VALUE shoes_color_rgb(int, VALUE *, VALUE);
-VALUE shoes_color_gray(int, VALUE *, VALUE);
cairo_pattern_t *shoes_color_pattern(VALUE);
-void shoes_color_grad_stop(cairo_pattern_t *, double, VALUE);
-VALUE shoes_color_args(int, VALUE *, VALUE);
-VALUE shoes_color_parse(VALUE, VALUE);
-VALUE shoes_color_is_black(VALUE);
-VALUE shoes_color_is_dark(VALUE);
-VALUE shoes_color_is_light(VALUE);
-VALUE shoes_color_is_white(VALUE);
-VALUE shoes_color_invert(VALUE);
-VALUE shoes_color_to_s(VALUE);
-VALUE shoes_color_to_pattern(VALUE);
VALUE shoes_color_gradient(int, VALUE *, VALUE);
void shoes_link_mark(shoes_link *);
View
1 shoes/effects.c
@@ -199,6 +199,7 @@ shoes_layer_blur_filter(cairo_t *cr, VALUE attr, shoes_place *place,
cairo_set_source_surface(cr2, source, distance, distance);
cairo_paint(cr2);
cairo_set_operator(cr2, blur_op);
+ VALUE cColor = rb_const_get(rb_cObject, rb_intern("Shoes::Color"));
if (NIL_P(fill))
cairo_set_source_rgb(cr2, 0., 0., 0.);
else if (rb_obj_is_kind_of(fill, cColor))
View
16 shoes/native/cocoa.m
@@ -10,6 +10,8 @@
#include "shoes/internal.h"
#include "shoes/http.h"
+extern VALUE cColor;
+
#define HEIGHT_PAD 6
#define INIT NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
@@ -1394,7 +1396,12 @@ void shoes_cairo_destroy(shoes_canvas *canvas)
// getRed: &r green: &g blue: &b alpha: &a];
// RELEASE;
// return shoes_color_new((int)(r * 255), (int)(g * 255), (int)(b * 255), (int)(a * 255));
- return shoes_color_new(255, 255, 255, 255);
+ VALUE *colors[4];
+ colors[0] = 255;
+ colors[1] = 255;
+ colors[2] = 255;
+ colors[3] = 255;
+ return rb_class_new_instance(4, colors, cColor);
}
VALUE
@@ -1495,7 +1502,12 @@ void shoes_cairo_destroy(shoes_canvas *canvas)
title = shoes_native_to_s(title);
if (GetColor(where, RSTRING_PTR(title), &colwh, &_color))
{
- color = shoes_color_new(_color.red/256, _color.green/256, _color.blue/256, SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = _color.red/256;
+ colors[1] = _color.green/256;
+ colors[2] = _color.blue/256;
+ colors[3] = 0xFF;
+ color = rb_class_new_instance(4, colors, cColor);
}
return color;
}
View
21 shoes/native/gtk.c
@@ -1090,7 +1090,12 @@ shoes_native_window_color(shoes_app *app)
{
GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(APP_WINDOW(app)));
GdkColor bg = style->bg[GTK_STATE_NORMAL];
- return shoes_color_new(bg.red / 257, bg.green / 257, bg.blue / 257 , SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = _color.red/256;
+ colors[1] = _color.green/256;
+ colors[2] = _color.blue/256;
+ colors[3] = 0xFF;
+ return rb_class_new_instance(4, colors, cColor);
}
VALUE
@@ -1098,7 +1103,12 @@ shoes_native_dialog_color(shoes_app *app)
{
GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(APP_WINDOW(app)));
GdkColor bg = style->bg[GTK_STATE_NORMAL];
- return shoes_color_new(bg.red / 257, bg.green / 257, bg.blue / 257 , SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = _color.red/257;
+ colors[1] = _color.green/257;
+ colors[2] = _color.blue/257;
+ colors[3] = 0xFF;
+ return rb_class_new_instance(4, colors, cColor);
}
VALUE
@@ -1178,7 +1188,12 @@ shoes_dialog_color(VALUE self, VALUE title)
gtk_color_selection_get_current_color(
GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel),
&_color);
- color = shoes_color_new(_color.red/256, _color.green/256, _color.blue/256, SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = _color.red/256;
+ colors[1] = _color.green/256;
+ colors[2] = _color.blue/256;
+ colors[3] = 0xFF;
+ color = rb_class_new_instance(4, colors, cColor);
}
gtk_widget_destroy(dialog);
return color;
View
22 shoes/native/windows.c
@@ -2102,14 +2102,24 @@ VALUE
shoes_native_window_color(shoes_app *app)
{
DWORD winc = GetSysColor(COLOR_WINDOW);
- return shoes_color_new(GetRValue(winc), GetGValue(winc), GetBValue(winc), SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = GetRValue(winc);
+ colors[1] = GetGValue(winc);
+ colors[2] = GetBValue(winc);
+ colors[3] = 255;
+ return rb_class_new_instance(4, colors, cColor);
}
VALUE
shoes_native_dialog_color(shoes_app *app)
{
DWORD winc = GetSysColor(COLOR_3DFACE);
- return shoes_color_new(GetRValue(winc), GetGValue(winc), GetBValue(winc), SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = GetRValue(winc);
+ colors[1] = GetGValue(winc);
+ colors[2] = GetBValue(winc);
+ colors[3] = 255;
+ return rb_class_new_instance(4, colors, cColor);
}
LPWSTR win32_dialog_label = NULL;
@@ -2229,8 +2239,12 @@ shoes_dialog_color(VALUE self, VALUE title)
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&cc)) {
- color = shoes_color_new(GetRValue(cc.rgbResult), GetGValue(cc.rgbResult), GetBValue(cc.rgbResult),
- SHOES_COLOR_OPAQUE);
+ VALUE *colors[4];
+ colors[0] = GetRValue(cc.rgbResult);
+ colors[1] = GetGValue(cc.rgbResult);
+ colors[2] = GetBValue(cc.rgbResult);
+ colors[3] = 255;
+ color = rb_class_new_instance(4, colors, cColor);
}
return color;
}
View
465 shoes/ruby.c
@@ -593,8 +593,7 @@ shoes_is_element_p(VALUE ele, unsigned char any)
dmark == shoes_pattern_mark || dmark == shoes_textblock_mark ||
dmark == shoes_control_mark ||
(any && (dmark == shoes_http_mark || dmark == shoes_timer_mark ||
- dmark == shoes_color_mark || dmark == shoes_link_mark ||
- dmark == shoes_text_mark))
+ dmark == shoes_link_mark || dmark == shoes_text_mark))
);
}
@@ -1211,7 +1210,7 @@ shoes_image_get_pixel(VALUE self, VALUE _x, VALUE _y)
GET_STRUCT(image, image);
unsigned char *pixels = shoes_image_surface_get_pixel(image->cached, x, y);
if (pixels != NULL)
- color = shoes_color_new(pixels[2], pixels[1], pixels[0], pixels[3]);
+ color = rb_class_new_instance(4, pixels, cColor);
return color;
}
@@ -1225,7 +1224,7 @@ shoes_image_set_pixel(VALUE self, VALUE _x, VALUE _y, VALUE col)
if (pixels != NULL)
{
if (TYPE(col) == T_STRING)
- col = shoes_color_parse(cColor, col);
+ col = rb_funcall(cColor, rb_intern("parse"), col);
if (rb_obj_is_kind_of(col, cColor))
{
shoes_color *color;
@@ -1456,9 +1455,9 @@ shoes_pattern_gradient(shoes_pattern *pattern, VALUE r1, VALUE r2, VALUE attr)
double edge = (fabs(dx) + fabs(dy)) * 0.5;
if (rb_obj_is_kind_of(r1, rb_cString))
- r1 = shoes_color_parse(cColor, r1);
+ r1 = rb_funcall(cColor, rb_intern("parse"), r1);
if (rb_obj_is_kind_of(r2, rb_cString))
- r2 = shoes_color_parse(cColor, r2);
+ r2 = rb_funcall(cColor, rb_intern("parse"), r2);
VALUE radius = ATTR(attr, radius);
if (!NIL_P(radius))
@@ -1496,7 +1495,7 @@ shoes_pattern_set_fill(VALUE self, VALUE source)
{
if (!rb_obj_is_kind_of(source, cColor))
{
- VALUE rgb = shoes_color_parse(cColor, source);
+ VALUE rgb = rb_funcall(cColor, rb_intern("parse"), source);
if (!NIL_P(rgb)) source = rgb;
}
@@ -1559,6 +1558,7 @@ shoes_pattern_method(VALUE klass, VALUE source)
return shoes_pattern_new(cPattern, source, Qnil, Qnil);
}
+
VALUE
shoes_pattern_alloc(VALUE klass)
{
@@ -1656,57 +1656,6 @@ shoes_subpattern_new(VALUE klass, VALUE pat, VALUE parent)
return obj;
}
-//
-// Shoes::Color
-//
-void
-shoes_color_mark(shoes_color *color)
-{
-}
-
-static void
-shoes_color_free(shoes_color *color)
-{
- RUBY_CRITICAL(free(color));
-}
-
-VALUE
-shoes_color_new(int r, int g, int b, int a)
-{
- shoes_color *color;
- VALUE obj = shoes_color_alloc(cColor);
- Data_Get_Struct(obj, shoes_color, color);
- color->r = r;
- color->g = g;
- color->b = b;
- color->a = a;
- return obj;
-}
-
-VALUE
-shoes_color_alloc(VALUE klass)
-{
- VALUE obj;
- shoes_color *color = SHOE_ALLOC(shoes_color);
- SHOE_MEMZERO(color, shoes_color, 1);
- obj = Data_Wrap_Struct(klass, shoes_color_mark, shoes_color_free, color);
- color->a = SHOES_COLOR_OPAQUE;
- color->on = TRUE;
- return obj;
-}
-
-VALUE
-shoes_color_rgb(int argc, VALUE *argv, VALUE self)
-{
- int a;
- VALUE _r, _g, _b, _a;
- rb_scan_args(argc, argv, "31", &_r, &_g, &_b, &_a);
-
- a = SHOES_COLOR_OPAQUE;
- if (!NIL_P(_a)) a = NUM2RGBINT(_a);
- return shoes_color_new(NUM2RGBINT(_r), NUM2RGBINT(_g), NUM2RGBINT(_b), a);
-}
-
VALUE
shoes_color_gradient(int argc, VALUE *argv, VALUE self)
{
@@ -1723,20 +1672,6 @@ shoes_color_gradient(int argc, VALUE *argv, VALUE self)
return obj;
}
-VALUE
-shoes_color_gray(int argc, VALUE *argv, VALUE self)
-{
- VALUE _g, _a;
- int g, a;
- rb_scan_args(argc, argv, "02", &_g, &_a);
-
- a = SHOES_COLOR_OPAQUE;
- g = 128;
- if (!NIL_P(_g)) g = NUM2RGBINT(_g);
- if (!NIL_P(_a)) a = NUM2RGBINT(_a);
- return shoes_color_new(g, g, g, a);
-}
-
cairo_pattern_t *
shoes_color_pattern(VALUE self)
{
@@ -1758,215 +1693,6 @@ shoes_color_grad_stop(cairo_pattern_t *pattern, double stop, VALUE self)
}
VALUE
-shoes_color_args(int argc, VALUE *argv, VALUE self)
-{
- VALUE _r, _g, _b, _a, _color;
- argc = rb_scan_args(argc, argv, "13", &_r, &_g, &_b, &_a);
-
- if (argc == 1 && rb_obj_is_kind_of(_r, cColor))
- _color = _r;
- else if (argc == 1 && rb_obj_is_kind_of(_r, rb_cString))
- _color = shoes_color_parse(cColor, _r);
- else if (argc == 1 || argc == 2)
- _color = shoes_color_gray(argc, argv, cColor);
- else
- _color = shoes_color_rgb(argc, argv, cColor);
-
- return _color;
-}
-
-#define NEW_COLOR(v, o) \
- shoes_color *v; \
- VALUE o = shoes_color_alloc(cColor); \
- Data_Get_Struct(o, shoes_color, v)
-
-VALUE
-shoes_color_parse(VALUE self, VALUE source)
-{
- VALUE reg;
-
- reg = rb_funcall(source, s_match, 1, reHEX3_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = NUM2INT(rb_str2inum(rb_reg_nth_match(1, reg), 16)) * 17;
- color->g = NUM2INT(rb_str2inum(rb_reg_nth_match(2, reg), 16)) * 17;
- color->b = NUM2INT(rb_str2inum(rb_reg_nth_match(3, reg), 16)) * 17;
- return obj;
- }
-
- reg = rb_funcall(source, s_match, 1, reHEX_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = NUM2INT(rb_str2inum(rb_reg_nth_match(1, reg), 16));
- color->g = NUM2INT(rb_str2inum(rb_reg_nth_match(2, reg), 16));
- color->b = NUM2INT(rb_str2inum(rb_reg_nth_match(3, reg), 16));
- return obj;
- }
-
- reg = rb_funcall(source, s_match, 1, reRGB_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg)));
- color->g = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg)));
- color->b = NUM2INT(rb_Integer(rb_reg_nth_match(3, reg)));
- return obj;
- }
-
- reg = rb_funcall(source, s_match, 1, reRGBA_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg)));
- color->g = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg)));
- color->b = NUM2INT(rb_Integer(rb_reg_nth_match(3, reg)));
- color->a = NUM2INT(rb_Integer(rb_reg_nth_match(4, reg)));
- return obj;
- }
-
- reg = rb_funcall(source, s_match, 1, reGRAY_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = color->g = color->b = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg)));
- return obj;
- }
-
- reg = rb_funcall(source, s_match, 1, reGRAYA_SOURCE);
- if (!NIL_P(reg))
- {
- NEW_COLOR(color, obj);
- color->r = color->g = color->b = NUM2INT(rb_Integer(rb_reg_nth_match(1, reg)));
- color->a = NUM2INT(rb_Integer(rb_reg_nth_match(2, reg)));
- return obj;
- }
-
- return Qnil;
-}
-
-VALUE
-shoes_color_spaceship(VALUE self, VALUE c2)
-{
- int v1, v2;
- shoes_color *color2;
- GET_STRUCT(color, color);
- if (!rb_obj_is_kind_of(c2, cColor)) return Qnil;
- Data_Get_Struct(c2, shoes_color, color2);
- if ((color->r == color2->r) && (color->g == color2->g) && (color->b == color2->b))
- {
- return INT2FIX(0);
- } else
- {
- v1 = color->r + color->g + color->b;
- v2 = color2->r + color2->g + color2->b;
- if (v1 > v2) return INT2FIX(1);
- else return INT2FIX(-1);
- }
-}
-
-VALUE
-shoes_color_get_red(VALUE self)
-{
- GET_STRUCT(color, color);
- return INT2NUM(color->r);
-}
-
-VALUE
-shoes_color_get_green(VALUE self)
-{
- GET_STRUCT(color, color);
- return INT2NUM(color->g);
-}
-
-VALUE
-shoes_color_get_blue(VALUE self)
-{
- GET_STRUCT(color, color);
- return INT2NUM(color->b);
-}
-
-VALUE
-shoes_color_get_alpha(VALUE self)
-{
- GET_STRUCT(color, color);
- return INT2NUM(color->a);
-}
-
-VALUE
-shoes_color_is_black(VALUE self)
-{
- GET_STRUCT(color, color);
- return (color->r + color->g + color->b == 0) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_is_dark(VALUE self)
-{
- GET_STRUCT(color, color);
- return ((int)color->r + (int)color->g + (int)color->b < SHOES_COLOR_DARK) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_is_light(VALUE self)
-{
- GET_STRUCT(color, color);
- return ((int)color->r + (int)color->g + (int)color->b > SHOES_COLOR_LIGHT) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_is_opaque(VALUE self)
-{
- GET_STRUCT(color, color);
- return (color->a == SHOES_COLOR_OPAQUE) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_is_transparent(VALUE self)
-{
- GET_STRUCT(color, color);
- return (color->a == SHOES_COLOR_TRANSPARENT) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_is_white(VALUE self)
-{
- GET_STRUCT(color, color);
- return (color->r + color->g + color->b == 765) ? Qtrue : Qfalse;
-}
-
-VALUE
-shoes_color_invert(VALUE self)
-{
- GET_STRUCT(color, color);
- NEW_COLOR(color2, obj);
- color2->r = 255 - color->r; color2->g = 255 - color->g; color2->b = 255 - color->b;
- return obj;
-}
-
-VALUE
-shoes_color_to_s(VALUE self)
-{
- GET_STRUCT(color, color);
-
- VALUE ary = rb_ary_new3(4,
- INT2NUM(color->r), INT2NUM(color->g), INT2NUM(color->b),
- rb_float_new((color->a * 1.) / 255.));
-
- if (color->a == 255)
- return rb_funcall(rb_str_new2("rgb(%d, %d, %d)"), s_perc, 1, ary);
- else
- return rb_funcall(rb_str_new2("rgb(%d, %d, %d, %0.1f)"), s_perc, 1, ary);
-}
-
-VALUE
-shoes_color_to_pattern(VALUE self)
-{
- return shoes_pattern_method(cPattern, self);
-}
-
-VALUE
shoes_color_method_missing(int argc, VALUE *argv, VALUE self)
{
VALUE alpha;
@@ -1986,7 +1712,12 @@ shoes_color_method_missing(int argc, VALUE *argv, VALUE self)
{
shoes_color *color;
Data_Get_Struct(c, shoes_color, color);
- c = shoes_color_new(color->r, color->g, color->b, NUM2RGBINT(alpha));
+ VALUE *colors[4];
+ colors[0] = color->r;
+ colors[1] = color->g;
+ colors[2] = color->b;
+ colors[3] = NUM2RGBINT(alpha);
+ c = rb_class_new_instance(4, colors, cColor);
}
return c;
@@ -2428,7 +2159,7 @@ shoes_textblock_send_release(VALUE self, int button, int x, int y)
if (!NIL_P(str)) \
{ \
if (TYPE(str) == T_STRING) \
- str = shoes_color_parse(cColor, str); \
+ str = rb_funcall(cColor, rb_intern("parse"), str); \
if (rb_obj_is_kind_of(str, cColor)) \
{ \
shoes_color *color; \
@@ -4444,8 +4175,6 @@ shoes_ruby_init()
//
// Shoes Kernel methods
//
- rb_define_method(rb_mKernel, "rgb", CASTHOOK(shoes_color_rgb), -1);
- rb_define_method(rb_mKernel, "gray", CASTHOOK(shoes_color_gray), -1);
rb_define_method(rb_mKernel, "gradient", CASTHOOK(shoes_color_gradient), -1);
rb_define_method(rb_mKernel, "pattern", CASTHOOK(shoes_pattern_method), 1);
rb_define_method(rb_mKernel, "quit", CASTHOOK(shoes_app_quit), 0);
@@ -4726,30 +4455,6 @@ shoes_ruby_init()
cEvery = rb_define_class_under(cTypes, "Every", cTimerBase);
cTimer = rb_define_class_under(cTypes, "Timer", cTimerBase);
- cColor = rb_define_class_under(cTypes, "Color", rb_cObject);
- rb_define_alloc_func(cColor, shoes_color_alloc);
- rb_define_method(rb_mKernel, "rgb", CASTHOOK(shoes_color_rgb), -1);
- rb_define_method(rb_mKernel, "gray", CASTHOOK(shoes_color_gray), -1);
- rb_define_singleton_method(cColor, "rgb", CASTHOOK(shoes_color_rgb), -1);
- rb_define_singleton_method(cColor, "gray", CASTHOOK(shoes_color_gray), -1);
- rb_define_singleton_method(cColor, "parse", CASTHOOK(shoes_color_parse), 1);
- rb_include_module(cColor, rb_mComparable);
- rb_define_method(cColor, "<=>", CASTHOOK(shoes_color_spaceship), 1);
- rb_define_method(cColor, "red", CASTHOOK(shoes_color_get_red), 0);
- rb_define_method(cColor, "green", CASTHOOK(shoes_color_get_green), 0);
- rb_define_method(cColor, "blue", CASTHOOK(shoes_color_get_blue), 0);
- rb_define_method(cColor, "alpha", CASTHOOK(shoes_color_get_alpha), 0);
- rb_define_method(cColor, "black?", CASTHOOK(shoes_color_is_black), 0);
- rb_define_method(cColor, "dark?", CASTHOOK(shoes_color_is_dark), 0);
- rb_define_method(cColor, "inspect", CASTHOOK(shoes_color_to_s), 0);
- rb_define_method(cColor, "invert", CASTHOOK(shoes_color_invert), 0);
- rb_define_method(cColor, "light?", CASTHOOK(shoes_color_is_light), 0);
- rb_define_method(cColor, "opaque?", CASTHOOK(shoes_color_is_opaque), 0);
- rb_define_method(cColor, "to_s", CASTHOOK(shoes_color_to_s), 0);
- rb_define_method(cColor, "to_pattern", CASTHOOK(shoes_color_to_pattern), 0);
- rb_define_method(cColor, "transparent?", CASTHOOK(shoes_color_is_transparent), 0);
- rb_define_method(cColor, "white?", CASTHOOK(shoes_color_is_white), 0);
-
cDownload = rb_define_class_under(cTypes, "Download", rb_cObject);
rb_define_alloc_func(cDownload, shoes_http_alloc);
rb_define_method(cDownload, "abort", CASTHOOK(shoes_http_abort), 0);
@@ -4775,146 +4480,8 @@ shoes_ruby_init()
rb_const_set(cTypes, rb_intern("ALL_NAMED_COLORS"), rb_hash_new());
cColors = rb_const_get(cTypes, rb_intern("ALL_NAMED_COLORS"));
rb_const_set(cTypes, rb_intern("COLORS"), cColors);
- DEF_COLOR(aliceblue, 240, 248, 255);
- DEF_COLOR(antiquewhite, 250, 235, 215);
- DEF_COLOR(aqua, 0, 255, 255);
- DEF_COLOR(aquamarine, 127, 255, 212);
- DEF_COLOR(azure, 240, 255, 255);
- DEF_COLOR(beige, 245, 245, 220);
- DEF_COLOR(bisque, 255, 228, 196);
- DEF_COLOR(black, 0, 0, 0);
- DEF_COLOR(blanchedalmond, 255, 235, 205);
- DEF_COLOR(blue, 0, 0, 255);
- DEF_COLOR(blueviolet, 138, 43, 226);
- DEF_COLOR(brown, 165, 42, 42);
- DEF_COLOR(burlywood, 222, 184, 135);
- DEF_COLOR(cadetblue, 95, 158, 160);
- DEF_COLOR(chartreuse, 127, 255, 0);
- DEF_COLOR(chocolate, 210, 105, 30);
- DEF_COLOR(coral, 255, 127, 80);
- DEF_COLOR(cornflowerblue, 100, 149, 237);
- DEF_COLOR(cornsilk, 255, 248, 220);
- DEF_COLOR(crimson, 220, 20, 60);
- DEF_COLOR(cyan, 0, 255, 255);
- DEF_COLOR(darkblue, 0, 0, 139);
- DEF_COLOR(darkcyan, 0, 139, 139);
- DEF_COLOR(darkgoldenrod, 184, 134, 11);
- DEF_COLOR(darkgray, 169, 169, 169);
- DEF_COLOR(darkgreen, 0, 100, 0);
- DEF_COLOR(darkkhaki, 189, 183, 107);
- DEF_COLOR(darkmagenta, 139, 0, 139);
- DEF_COLOR(darkolivegreen, 85, 107, 47);
- DEF_COLOR(darkorange, 255, 140, 0);
- DEF_COLOR(darkorchid, 153, 50, 204);
- DEF_COLOR(darkred, 139, 0, 0);
- DEF_COLOR(darksalmon, 233, 150, 122);
- DEF_COLOR(darkseagreen, 143, 188, 143);
- DEF_COLOR(darkslateblue, 72, 61, 139);
- DEF_COLOR(darkslategray, 47, 79, 79);
- DEF_COLOR(darkturquoise, 0, 206, 209);
- DEF_COLOR(darkviolet, 148, 0, 211);
- DEF_COLOR(deeppink, 255, 20, 147);
- DEF_COLOR(deepskyblue, 0, 191, 255);
- DEF_COLOR(dimgray, 105, 105, 105);
- DEF_COLOR(dodgerblue, 30, 144, 255);
- DEF_COLOR(firebrick, 178, 34, 34);
- DEF_COLOR(floralwhite, 255, 250, 240);
- DEF_COLOR(forestgreen, 34, 139, 34);
- DEF_COLOR(fuchsia, 255, 0, 255);
- DEF_COLOR(gainsboro, 220, 220, 220);
- DEF_COLOR(ghostwhite, 248, 248, 255);
- DEF_COLOR(gold, 255, 215, 0);
- DEF_COLOR(goldenrod, 218, 165, 32);
- DEF_COLOR(gray, 128, 128, 128);
- DEF_COLOR(green, 0, 128, 0);
- DEF_COLOR(greenyellow, 173, 255, 47);
- DEF_COLOR(honeydew, 240, 255, 240);
- DEF_COLOR(hotpink, 255, 105, 180);
- DEF_COLOR(indianred, 205, 92, 92);
- DEF_COLOR(indigo, 75, 0, 130);
- DEF_COLOR(ivory, 255, 255, 240);
- DEF_COLOR(khaki, 240, 230, 140);
- DEF_COLOR(lavender, 230, 230, 250);
- DEF_COLOR(lavenderblush, 255, 240, 245);
- DEF_COLOR(lawngreen, 124, 252, 0);
- DEF_COLOR(lemonchiffon, 255, 250, 205);
- DEF_COLOR(lightblue, 173, 216, 230);
- DEF_COLOR(lightcoral, 240, 128, 128);
- DEF_COLOR(lightcyan, 224, 255, 255);
- DEF_COLOR(lightgoldenrodyellow, 250, 250, 210);
- DEF_COLOR(lightgreen, 144, 238, 144);
- DEF_COLOR(lightgrey, 211, 211, 211);
- DEF_COLOR(lightpink, 255, 182, 193);
- DEF_COLOR(lightsalmon, 255, 160, 122);
- DEF_COLOR(lightseagreen, 32, 178, 170);
- DEF_COLOR(lightskyblue, 135, 206, 250);
- DEF_COLOR(lightslategray, 119, 136, 153);
- DEF_COLOR(lightsteelblue, 176, 196, 222);
- DEF_COLOR(lightyellow, 255, 255, 224);
- DEF_COLOR(lime, 0, 255, 0);
- DEF_COLOR(limegreen, 50, 205, 50);
- DEF_COLOR(linen, 250, 240, 230);
- DEF_COLOR(magenta, 255, 0, 255);
- DEF_COLOR(maroon, 128, 0, 0);
- DEF_COLOR(mediumaquamarine, 102, 205, 170);
- DEF_COLOR(mediumblue, 0, 0, 205);
- DEF_COLOR(mediumorchid, 186, 85, 211);
- DEF_COLOR(mediumpurple, 147, 112, 219);
- DEF_COLOR(mediumseagreen, 60, 179, 113);
- DEF_COLOR(mediumslateblue, 123, 104, 238);
- DEF_COLOR(mediumspringgreen, 0, 250, 154);
- DEF_COLOR(mediumturquoise, 72, 209, 204);
- DEF_COLOR(mediumvioletred, 199, 21, 133);
- DEF_COLOR(midnightblue, 25, 25, 112);
- DEF_COLOR(mintcream, 245, 255, 250);
- DEF_COLOR(mistyrose, 255, 228, 225);
- DEF_COLOR(moccasin, 255, 228, 181);
- DEF_COLOR(navajowhite, 255, 222, 173);
- DEF_COLOR(navy, 0, 0, 128);
- DEF_COLOR(oldlace, 253, 245, 230);
- DEF_COLOR(olive, 128, 128, 0);
- DEF_COLOR(olivedrab, 107, 142, 35);
- DEF_COLOR(orange, 255, 165, 0);
- DEF_COLOR(orangered, 255, 69, 0);
- DEF_COLOR(orchid, 218, 112, 214);
- DEF_COLOR(palegoldenrod, 238, 232, 170);
- DEF_COLOR(palegreen, 152, 251, 152);
- DEF_COLOR(paleturquoise, 175, 238, 238);
- DEF_COLOR(palevioletred, 219, 112, 147);
- DEF_COLOR(papayawhip, 255, 239, 213);
- DEF_COLOR(peachpuff, 255, 218, 185);
- DEF_COLOR(peru, 205, 133, 63);
- DEF_COLOR(pink, 255, 192, 203);
- DEF_COLOR(plum, 221, 160, 221);
- DEF_COLOR(powderblue, 176, 224, 230);
- DEF_COLOR(purple, 128, 0, 128);
- DEF_COLOR(red, 255, 0, 0);
- DEF_COLOR(rosybrown, 188, 143, 143);
- DEF_COLOR(royalblue, 65, 105, 225);
- DEF_COLOR(saddlebrown, 139, 69, 19);
- DEF_COLOR(salmon, 250, 128, 114);
- DEF_COLOR(sandybrown, 244, 164, 96);
- DEF_COLOR(seagreen, 46, 139, 87);
- DEF_COLOR(seashell, 255, 245, 238);
- DEF_COLOR(sienna, 160, 82, 45);
- DEF_COLOR(silver, 192, 192, 192);
- DEF_COLOR(skyblue, 135, 206, 235);
- DEF_COLOR(slateblue, 106, 90, 205);
- DEF_COLOR(slategray, 112, 128, 144);
- DEF_COLOR(snow, 255, 250, 250);
- DEF_COLOR(springgreen, 0, 255, 127);
- DEF_COLOR(steelblue, 70, 130, 180);
- DEF_COLOR(tan, 210, 180, 140);
- DEF_COLOR(teal, 0, 128, 128);
- DEF_COLOR(thistle, 216, 191, 216);
- DEF_COLOR(tomato, 255, 99, 71);
- DEF_COLOR(turquoise, 64, 224, 208);
- DEF_COLOR(violet, 238, 130, 238);
- DEF_COLOR(wheat, 245, 222, 179);
- DEF_COLOR(white, 255, 255, 255);
- DEF_COLOR(whitesmoke, 245, 245, 245);
- DEF_COLOR(yellow, 255, 255, 0);
- DEF_COLOR(yellowgreen, 154, 205, 50);
+
+ cColor = rb_const_get(cTypes, rb_intern("Color"));
cLinkUrl = rb_define_class_under(cTypes, "LinkUrl", rb_cObject);
View
3 shoes/ruby.h
@@ -77,7 +77,7 @@ static inline void flip_endian(unsigned char* x, int length) {
#undef s_host
-extern VALUE cShoes, cApp, cDialog, cTypes, 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, cSlider, cCheck, cRadio, cColor, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
+extern VALUE cShoes, cApp, cDialog, cTypes, 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, cSlider, cCheck, cRadio, cDownload, cResponse, cColors, cLink, cLinkHover, ssNestSlot;
extern VALUE aMsgList;
extern VALUE eInvMode, eNotImpl, eImageError;
extern VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE, reLF;
@@ -120,7 +120,6 @@ void shoes_ruby_init(void);
return SHOES_QUIT;
#define NUM2RGBINT(x) (rb_obj_is_kind_of(x, rb_cFloat) ? ROUND(NUM2DBL(x) * 255) : NUM2INT(x))
-#define DEF_COLOR(name, r, g, b) rb_hash_aset(cColors, ID2SYM(rb_intern("" # name)), shoes_color_new(r, g, b, 255))
#define GET_STRUCT(ele, var) \
shoes_##ele *var; \
Data_Get_Struct(self, shoes_##ele, var)

0 comments on commit 3513e85

Please sign in to comment.
Something went wrong with that request. Please try again.