source: libcaca/trunk/ruby/caca-display.c @ 2015

Last change on this file since 2015 was 2015, checked in by Pascal Terjan, 13 years ago
  • Add Caca and Caca::Display
  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/*
2 *  libcaca Ruby bindings
3 *  Copyright (c) 2007 Pascal Terjan <pterjan@linuxfr.org>
4 *
5 *  This library is free software. It comes without any warranty, to
6 *  the extent permitted by applicable law. You can redistribute it
7 *  and/or modify it under the terms of the Do What The Fuck You Want
8 *  To Public License, Version 2, as published by Sam Hocevar. See
9 *  http://sam.zoy.org/wtfpl/COPYING for more details.
10 */
11
12#include <ruby.h>
13#include <caca.h>
14#include <errno.h>
15#include "cucul-canvas.h"
16#include "common.h"
17
18VALUE cDisplay;
19
20void display_free(void *display)
21{
22    caca_free_display((caca_display_t *)display);
23}
24
25static VALUE display_alloc(VALUE klass)
26{
27    VALUE obj;
28    obj = Data_Wrap_Struct(klass, 0, display_free, NULL);   
29    return obj;
30}
31
32static VALUE display_initialize(VALUE self, VALUE cv)
33{
34    caca_display_t *display;
35   
36    if(CLASS_OF(cv) != cCanvas)
37    {
38        rb_raise(rb_eArgError, "Argument is not a Cucul::Canvas");
39    }
40
41    display = caca_create_display(DATA_PTR(cv));
42    if(display == NULL)
43    {
44        rb_raise(rb_eRuntimeError, strerror(errno));
45    }
46
47    _SELF = display;
48
49    return self;
50}
51
52static VALUE display_refresh(VALUE self)
53{
54    caca_refresh_display(_SELF);
55    return self;
56}
57
58static VALUE set_time(VALUE self, VALUE t)
59{
60    caca_set_display_time(_SELF, UINT2NUM(t));
61    return t;
62}
63
64static VALUE set_time2(VALUE self, VALUE t)
65{
66    set_time(self, t);
67    return self;
68}
69
70static VALUE get_time(VALUE self)
71{
72    return NUM2UINT(caca_get_display_time(_SELF));
73}
74
75static VALUE get_width(VALUE self)
76{
77    return NUM2UINT(caca_get_display_width(_SELF));
78}
79
80static VALUE get_height(VALUE self)
81{
82    return NUM2UINT(caca_get_display_height(_SELF));
83}
84
85static VALUE set_title(VALUE self, VALUE t)
86{
87    if(caca_set_display_title(_SELF, StringValuePtr(t))<0)
88    {
89        rb_raise(rb_eRuntimeError, strerror(errno));
90    }
91    return t;
92}
93
94static VALUE set_title2(VALUE self, VALUE t)
95{
96    set_title(self, t);
97    return self;
98}
99
100void Init_caca_display(VALUE mCaca)
101{
102    cDisplay = rb_define_class_under(mCaca, "Display", rb_cObject);
103    rb_define_alloc_func(cDisplay, display_alloc);
104
105    rb_define_method(cDisplay, "initialize", display_initialize, 1);
106    rb_define_method(cDisplay, "refresh", display_refresh, 0);
107    rb_define_method(cDisplay, "time=", set_time, 1);
108    rb_define_method(cDisplay, "set_time", set_time2, 1);
109    rb_define_method(cDisplay, "time", get_time, 0);
110    rb_define_method(cDisplay, "width", get_width, 0);
111    rb_define_method(cDisplay, "height", get_height, 0);
112    rb_define_method(cDisplay, "title=", set_title, 1);
113    rb_define_method(cDisplay, "set_title", set_title2, 1);
114}
Note: See TracBrowser for help on using the repository browser.