Ignore:
Timestamp:
Sep 27, 2008, 4:11:36 PM (12 years ago)
Author:
Sam Hocevar
Message:

Continuing the libcucul-libcaca merge.

Location:
libcaca/trunk/ruby
Files:
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/Makefile.am

    r2821 r2822  
    3131EXTRA_DIST = ruby.dox \
    3232             ruby-caca.dox \
    33              ruby-cucul.dox \
    3433             lib/caca.rb \
    3534             t/tc_canvas.rb \
  • libcaca/trunk/ruby/README

    r2033 r2822  
    1 This a Ruby binding for libcucul and libcaca.
     1This a Ruby binding for libcaca.
    22
    3 You can play with it by doing require 'caca' or require 'cucul' and looking at
    4 the Cucul and Caca modules, or maybe read the documentation :)
     3You can play with it by doing require 'caca' and looking at
     4the Caca module, or maybe read the documentation :)
  • libcaca/trunk/ruby/caca-canvas.c

    r2821 r2822  
    212212    if(CLASS_OF(src) != cCanvas)
    213213    {
    214         rb_raise(rb_eArgError, "src is not a Cucul::Canvas");
     214        rb_raise(rb_eArgError, "src is not a Caca::Canvas");
    215215    }
    216216    Data_Get_Struct(src, caca_canvas_t, csrc);
     
    220220        if(CLASS_OF(mask) != cCanvas)
    221221        {
    222             rb_raise(rb_eArgError, "mask is not a Cucul::Canvas");
     222            rb_raise(rb_eArgError, "mask is not a Caca::Canvas");
    223223        }
    224224        Data_Get_Struct(mask, caca_canvas_t, cmask);
     
    448448{
    449449    if(CLASS_OF(d) != cDither)
    450         rb_raise(rb_eArgError, "d is not a Cucul::Dither");
     450        rb_raise(rb_eArgError, "d is not a Caca::Dither");
    451451    Check_Type(pixels, T_STRING);
    452452
     
    518518    if(CLASS_OF(font) != cFont)
    519519    {
    520         rb_raise(rb_eArgError, "First argument is not a Cucul::Font");
     520        rb_raise(rb_eArgError, "First argument is not a Caca::Font");
    521521    }
    522522
     
    571571/****/
    572572
    573 void Init_caca_canvas(VALUE mCucul)
    574 {
    575     cCanvas = rb_define_class_under(mCucul, "Canvas", rb_cObject);
     573void Init_caca_canvas(VALUE mCaca)
     574{
     575    cCanvas = rb_define_class_under(mCaca, "Canvas", rb_cObject);
    576576    rb_define_alloc_func(cCanvas, canvas_alloc);
    577577
  • libcaca/trunk/ruby/caca-display.c

    r2821 r2822  
    4646        if(CLASS_OF(arg2) == cCanvas)
    4747        {
    48             rb_raise(rb_eArgError, "Only one argument can be a Cucul::Canvas");
     48            rb_raise(rb_eArgError, "Only one argument can be a Caca::Canvas");
    4949        }
    5050    }
  • libcaca/trunk/ruby/caca-dither.c

    r2821 r2822  
    180180get_set_str_from_list(algorithm)
    181181
    182 void Init_caca_dither(VALUE mCucul)
    183 {
    184     cDither = rb_define_class_under(mCucul, "Dither", rb_cObject);
     182void Init_caca_dither(VALUE mCaca)
     183{
     184    cDither = rb_define_class_under(mCaca, "Dither", rb_cObject);
    185185    rb_define_alloc_func(cDither, dither_alloc);
    186186
  • libcaca/trunk/ruby/caca-font.c

    r2821 r2822  
    8686}
    8787
    88 void Init_caca_font(VALUE mCucul)
     88void Init_caca_font(VALUE mCaca)
    8989{
    90     cFont = rb_define_class_under(mCucul, "Font", rb_cObject);
     90    cFont = rb_define_class_under(mCaca, "Font", rb_cObject);
    9191    rb_define_alloc_func(cFont, font_alloc);
    9292
  • libcaca/trunk/ruby/lib/caca.rb

    r2093 r2822  
    1 require 'cucul'
    21require 'caca.so'
    32
  • libcaca/trunk/ruby/ruby-caca.dox

    r2093 r2822  
    1 /* $Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
     1/*$Id$ */ /** \page libcaca-ruby-api Libcaca Ruby API
    22
    3 The classes available for libcaca are :
     3Theclasses available for libcaca are :
    44
    5 \li \b Caca::Display
    6 \li \b Caca::Event
    7 \li \b Caca::Event::Key
    8 \li \b Caca::Event::Key::Press
    9 \li \b Caca::Event::Key::Release
    10 \li \b Caca::Event::Mouse
    11 \li \b Caca::Event::Mouse::Press
    12 \li \b Caca::Event::Mouse::Release
    13 \li \b Caca::Event::Mouse::Motion
    14 \li \b Caca::Event::Resize
    15 \li \b Caca::Event::Quit
     5\li\b Caca::Canvas : functions that have a caca_canvas_t* as first argument
     6\li\b Caca::Dither : functions that have a caca_dither_t* as first argument
     7\li\b Caca::Font : functions that have a caca_font_t* as first argument
     8(The constructor can currently only accept the name of a builtin font)
     9\li\b Caca::Display
     10\li\b Caca::Event
     11\li\b Caca::Event::Key
     12\li\b Caca::Event::Key::Press
     13\li\b Caca::Event::Key::Release
     14\li\b Caca::Event::Mouse
     15\li\b Caca::Event::Mouse::Press
     16\li\b Caca::Event::Mouse::Release
     17\li\b Caca::Event::Mouse::Motion
     18\li\b Caca::Event::Resize
     19\li\b Caca::Event::Quit
     20
     21Thecharacter set conversion functions are not available yet in the binding.
    1622
    1723\code
    18 $ irb -rcaca
    19 irb(main):001:0> class Object
    20 irb(main):002:1>   def Object.my_instance_methods
    21 irb(main):003:2>     instance_methods.sort - ancestors[1].instance_methods
    22 irb(main):004:2>   end
    23 irb(main):005:1>   def Object.my_methods
    24 irb(main):006:2>     methods.sort - ancestors[1].methods
    25 irb(main):007:2>   end
    26 irb(main):008:1> end
     24$irb -rcaca
     25irb(main):001:0>class Object
     26irb(main):002:1>def Object.my_instance_methods
     27irb(main):003:2>instance_methods.sort - ancestors[1].instance_methods
     28irb(main):004:2>end
     29irb(main):005:1>def Object.my_methods
     30irb(main):006:2>methods.sort - ancestors[1].methods
     31irb(main):007:2>end
     32irb(main):008:1>end
    2733\endcode
    2834
    2935\code
    30 irb(main):009:0> Caca.my_methods
    31 => ["version"]
     36irb(main):009:0>Caca.constants
     37=>["BROWN", "BOLD", "GREEN", "LIGHTMAGENTA", "LIGHTBLUE", "BLINK",
     38"MAGENTA","DEFAULT", "TRANSPARENT", "BLUE", "LIGHTRED", "DARKGRAY",
     39"UNDERLINE","RED", "WHITE", "BLACK", "LIGHTCYAN", "LIGHTGRAY",
     40"ITALICS","CYAN", "YELLOW", "LIGHTGREEN", "Canvas", "Dither", "Font"]
    3241\endcode
    3342
    3443\code
    35 irb(main):010:0> Caca::Display.my_instance_methods
    36 => ["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
    37 "set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"]
     44irb(main):010:0>Caca.my_methods
     45=>["version"]
    3846\endcode
    3947
    4048\code
    41 irb(main):011:0> Caca::Event.constants
    42 => ["Key", "Quit", "TYPE", "Mouse", "Resize"]
     49irb(main):011:0>Caca::Canvas.my_methods
     50=>["export_list", "import_list"]
    4351\endcode
    4452
    4553\code
    46 irb(main):012:0> Caca::Event.my_instance_methods
    47 => ["quit?"]
     54irb(main):012:0>Caca::Canvas.my_instance_methods
     55=>["attr=", "blit", "clear", "create_frame", "cursor_x", "cursor_y",
     56"dither_bitmap","draw_box", "draw_circle", "draw_cp437_box", "draw_ellipse",
     57"draw_line","draw_polyline", "draw_thin_box", "draw_thin_ellipse",
     58"draw_thin_line","draw_thin_polyline", "draw_thin_triangle",
     59"draw_triangle","export_memory", "fill_box", "fill_ellipse",
     60"fill_triangle","flip", "flop", "frame=", "frame_count", "frame_name",
     61"frame_name=","free_frame", "get_attr", "get_char", "gotoxy",
     62"handle_x","handle_y", "height", "height=", "import_file",
     63"import_memory","invert", "printf", "put_attr", "put_char", "put_str",
     64"rotate_180","rotate_left", "rotate_right", "set_attr",
     65"set_boundaries","set_color_ansi", "set_color_argb", "set_frame",
     66"set_frame_name","set_handle", "set_height", "set_size", "set_width",
     67"stretch_left","stretch_right", "width", "width="]
    4868\endcode
    4969
    5070\code
    51 irb(main):013:0> Caca::Event::Key.my_instance_methods
    52 => ["ch", "utf32", "utf8"]
     71irb(main):013:0>Caca::Font.my_methods
     72=>["list"]
    5373\endcode
    5474
    5575\code
    56 irb(main):014:0> Caca::Event::Mouse.my_instance_methods
    57 => ["button", "x", "y"]
     76irb(main):014:0>Caca::Font.my_instance_methods
     77=>["blocks", "height", "width"]
    5878\endcode
    5979
    6080\code
    61 irb(main):015:0> Caca::Event::Resize.my_instance_methods
    62 => ["w", "h"]
     81irb(main):015:0>Caca::Dither.my_instance_methods
     82=>["algorithm=", "algorithm_list", "antialias=", "antialias_list",
     83"brightness=","charset=", "charset_list", "color=", "color_list",
     84"contrast=","gamma=", "palette=", "set_algorithm", "set_antialias",
     85"set_brightness","set_charset", "set_color", "set_contrast",
     86"set_gamma","set_palette"]
    6387\endcode
    6488
    65 \section Samples
     89\code
     90irb(main):010:0>Caca::Display.my_instance_methods
     91=>["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
     92"set_mouse","set_time", "set_title", "time", "time=", "title=", "width"]
     93\endcode
    6694
    6795\code
    68 require 'caca'
    69 c = Cucul::Canvas.new(20,10)
    70 c.put_str(2, 3, "plop!")
    71 c.draw_thin_polyline([[0,0], [0,2], [5,2], [0,0]])
    72 d = Caca::Display.new(c)
    73 d.title = "Test !"
     96irb(main):011:0>Caca::Event.constants
     97=>["Key", "Quit", "TYPE", "Mouse", "Resize"]
     98\endcode
     99
     100\code
     101irb(main):012:0>Caca::Event.my_instance_methods
     102=>["quit?"]
     103\endcode
     104
     105\code
     106irb(main):013:0>Caca::Event::Key.my_instance_methods
     107=>["ch", "utf32", "utf8"]
     108\endcode
     109
     110\code
     111irb(main):014:0>Caca::Event::Mouse.my_instance_methods
     112=>["button", "x", "y"]
     113\endcode
     114
     115\code
     116irb(main):015:0>Caca::Event::Resize.my_instance_methods
     117=>["w", "h"]
     118\endcode
     119
     120\sectionSamples
     121
     122\code
     123$ruby -rcaca -e 'c=Caca::Canvas.new(6, 3).fill_box(0,0,2,2,"#"[0]);
     124c2=Caca::Canvas.new(1,1).put_str(0,0,"x"); c.blit(1,1,c2); puts
     125c.export_memory("irc")'
     126###
     127#x#
     128###
     129\endcode
     130
     131\code
     132$ruby -e 'puts Caca::Canvas.new(6,3).draw_thin_polyline([[0,0], [0,2],
     133[5,2],[0,0]]).export_memory("irc")'
     134-.
     135|`. 
     136----`-
     137\endcode
     138
     139\code
     140$ruby -rcaca -e 'p Caca::Canvas.export_list'
     141[["caca","native libcaca format"], ["ansi", "ANSI"], ["utf8", "UTF-8
     142withANSI escape codes"], ["utf8cr", "UTF-8 with ANSI escape codes and
     143MS-DOS\\r"], ["html", "HTML"], ["html3", "backwards-compatible HTML"],
     144["irc","IRC with mIRC colours"], ["ps", "PostScript document"], ["svg",
     145"SVGvector image"], ["tga", "TGA image"]]
     146\endcode
     147
     148\code
     149$ruby -rcaca -e 'p Caca::Font.list'
     150["Monospace9", "Monospace Bold 12"]
     151\endcode
     152
     153\code
     154require'caca'
     155c= Caca::Canvas.new(20,10)
     156c.put_str(2,3, "plop!")
     157c.draw_thin_polyline([[0,0],[0,2], [5,2], [0,0]])
     158d= Caca::Display.new(c)
     159d.title= "Test !"
    74160d.refresh
    75161
    76 # Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
    77 module Caca
    78         class Event::Key
    79                 def quit?
    80                         "qQ^[".split('').member?(@ch.chr)
    81                 end
    82         end
     162#Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
     163moduleCaca
     164class Event::Key
     165def quit?
     166"qQ^[".split('').member?(@ch.chr)
     167end
     168end
    83169end
    84170
    85 while((e = d.get_event(Caca::Event, -1)) && ! e.quit?)
    86     p e
    87     d.refresh
     171while((e= d.get_event(Caca::Event, -1)) && ! e.quit?)
     172p e
     173d.refresh
    88174end
    89175\endcode
  • libcaca/trunk/ruby/t/tc_canvas.rb

    r2004 r2822  
    11require 'test/unit'
    2 require 'cucul'
     2require 'caca'
    33
    44class TC_Canvas < Test::Unit::TestCase
    55    def setup
    6         @c = Cucul::Canvas.new(3, 3)
     6        @c = Caca::Canvas.new(3, 3)
    77    end
    88    def test_create
    9         c = Cucul::Canvas.new(3, 3)
     9        c = Caca::Canvas.new(3, 3)
    1010        assert_not_nil(c, 'Canvas creation failed')
    1111        assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas')
     
    4646    end
    4747    def test_render
    48         c = Cucul::Canvas.new(4,4)
     48        c = Caca::Canvas.new(4,4)
    4949        c.put_str(0,0,"plop")
    50         f = Cucul::Font.new(Cucul::Font.list[0])
     50        f = Caca::Font.new(Caca::Font.list[0])
    5151        assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4))
    5252    end
    5353    def test_fail_render
    54         c = Cucul::Canvas.new(4,4)
     54        c = Caca::Canvas.new(4,4)
    5555        assert_raise(ArgumentError) {
    5656            c.render(nil, c.width, c.height, c.width*4)
  • libcaca/trunk/ruby/t/tc_display.rb

    r2298 r2822  
    1515        driver = Caca::Display.driver_list[0]
    1616        assert_raise(ArgumentError){Caca::Display.new(driver, driver)}
    17         c = Cucul::Canvas.new(3, 3)
     17        c = Caca::Canvas.new(3, 3)
    1818        assert_raise(ArgumentError){Caca::Display.new(c, c)}
    1919    end
    2020    def test_create_from_canvas
    21         c = Cucul::Canvas.new(3, 3)
     21        c = Caca::Canvas.new(3, 3)
    2222        d = Caca::Display.new(c)
    2323        assert_not_nil(d, 'Display creation failed')
     
    2525    end
    2626    def test_set_title
    27         c = Cucul::Canvas.new(3, 3)
     27        c = Caca::Canvas.new(3, 3)
    2828        d = Caca::Display.new(c)
    2929        d.title = "Test !"
  • libcaca/trunk/ruby/t/tc_dither.rb

    r2008 r2822  
    11require 'test/unit'
    2 require 'cucul'
     2require 'caca'
    33
    44class TC_Canvas < Test::Unit::TestCase
    55    def test_create
    66        assert_nothing_raised {
    7             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     7            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    88        }
    99    end
    1010    def test_fail_create
    1111        assert_raise(RuntimeError) {
    12             d = Cucul::Dither.new(-1, 32, 32, 32, 0, 0, 0, 0)
     12            d = Caca::Dither.new(-1, 32, 32, 32, 0, 0, 0, 0)
    1313        }
    1414    end
    1515    def test_set_palette
    1616        assert_nothing_raised {
    17             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     17            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    1818            d.palette=[[0xfff, 0xfff, 0xfff, 0xfff]]*256
    1919        }
     
    2121    def test_fail_set_palette
    2222        assert_raise(ArgumentError) {
    23             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     23            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    2424            d.palette=[]
    2525        }
     
    2727    def test_fail_set_palette2
    2828        assert_raise(RuntimeError) {
    29             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     29            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    3030            d.palette=[[0xffff, 0, 0, 0]]*256
    3131        }
     
    3333    def test_set_brightness
    3434        assert_nothing_raised {
    35             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     35            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    3636            d.brightness=0.5
    3737        }
     
    3939    def test_set_gamma
    4040        assert_nothing_raised {
    41             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     41            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    4242            d.gamma=0.5
    4343        }
     
    4545    def test_set_contrast
    4646        assert_nothing_raised {
    47             d = Cucul::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
     47            d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0)
    4848            d.contrast=0.5
    4949        }
  • libcaca/trunk/ruby/t/tc_font.rb

    r1995 r2822  
    11require 'test/unit'
    2 require 'cucul'
     2require 'caca'
    33
    44class TC_Canvas < Test::Unit::TestCase
    55    def test_list
    6         assert_not_nil(Cucul::Font.list)
     6        assert_not_nil(Caca::Font.list)
    77    end
    88    def test_load
    9         Cucul::Font.list.each{|f|
    10                 font = Cucul::Font.new(f)
     9        Caca::Font.list.each{|f|
     10                font = Caca::Font.new(f)
    1111                assert_not_nil(font)
    1212                assert_not_nil(font.width)
     
    1717    def test_fail_load
    1818        assert_raise(RuntimeError) {
    19                 Cucul::Font.new("This font should not exist")
     19                Caca::Font.new("This font should not exist")
    2020        }
    2121    end
  • libcaca/trunk/ruby/t/tc_frame.rb

    r1949 r2822  
    11require 'test/unit'
    2 require 'cucul'
     2require 'caca'
    33
    44class TC_Frame < Test::Unit::TestCase
    55        def setup
    6                 @c = Cucul::Canvas.new(3, 3)
     6                @c = Caca::Canvas.new(3, 3)
    77        end
    88        def test_create
Note: See TracChangeset for help on using the changeset viewer.