Module: Rug

Defined in:
ext/rug.c

Defined Under Namespace

Modules: Key, Mouse Classes: Conf, Layer

Class Method Summary collapse

Class Method Details

.conf(*args) ⇒ Object

add to main module



47
48
49
50
51
52
53
54
55
56
57
# File 'ext/rug_conf.c', line 47

static VALUE RugConfFunc(int argc, VALUE * argv, VALUE class){
  // we keep track of the RugConf block and instance_eval it within
  // a RugConf object
  if (rb_block_given_p()){
    VALUE confFunc;
    rb_scan_args(argc, argv, "0&", &confFunc);
    VALUE confObj = rb_funcall(cRugConf, rb_intern("new"), 0);
    rb_funcall(block_converter, rb_intern("call"), 3, confObj, rb_str_new2("instance_eval"), confFunc);
  }
  return Qnil;
}

.draw(*args) ⇒ Object



27
28
29
30
31
32
33
34
# File 'ext/rug.c', line 27

static VALUE RugDraw(int argc, VALUE * argv, VALUE class){
  if (rb_block_given_p()){
    VALUE func;
    rb_scan_args(argc, argv, "0&", &func);
    drawFunc = func;
  }
  return Qnil;
}

.keydown(*args) ⇒ Object



15
16
17
18
19
20
# File 'ext/rug_events.c', line 15

static VALUE SetKeyDown(int argc, VALUE * argv, VALUE self){
  VALUE keydown;
  rb_scan_args(argc, argv, "0&", &keydown);
  RugEvents.KeyDown = keydown;
  return Qnil;
}

.keyup(*args) ⇒ Object



9
10
11
12
13
14
# File 'ext/rug_events.c', line 9

static VALUE SetKeyUp(int argc, VALUE * argv, VALUE self){
  VALUE keyup;
  rb_scan_args(argc, argv, "0&", &keyup);
  RugEvents.KeyUp = keyup;
  return Qnil;
}

.load(*args) ⇒ Object

main Rug actions



18
19
20
21
22
23
24
25
# File 'ext/rug.c', line 18

static VALUE RugLoad(int argc, VALUE * argv, VALUE class){
  if (rb_block_given_p()){
    VALUE func;
    rb_scan_args(argc, argv, "0&", &func);
    loadFunc = func;
  }
  return Qnil;
}

.mousedown(*args) ⇒ Object



27
28
29
30
31
32
# File 'ext/rug_events.c', line 27

static VALUE SetMouseDown(int argc, VALUE * argv, VALUE self){
  VALUE mousedown;
  rb_scan_args(argc, argv, "0&", &mousedown);
  RugEvents.MouseDown = mousedown;
  return Qnil;
}

.mousemove(*args) ⇒ Object



21
22
23
24
25
26
# File 'ext/rug_events.c', line 21

static VALUE SetMouseMove(int argc, VALUE * argv, VALUE self){
  VALUE mousemove;
  rb_scan_args(argc, argv, "0&", &mousemove);
  RugEvents.MouseMove = mousemove;
  return Qnil;
}

.mousemoveoffset(*args) ⇒ Object



39
40
41
42
43
44
# File 'ext/rug_events.c', line 39

static VALUE SetMouseMoveOffset(int argc, VALUE * argv, VALUE self){
  VALUE func;
  rb_scan_args(argc, argv, "0&", &func);
  RugEvents.MouseMoveOffset = func;
  return Qnil;
}

.mouseup(*args) ⇒ Object



33
34
35
36
37
38
# File 'ext/rug_events.c', line 33

static VALUE SetMouseUp(int argc, VALUE * argv, VALUE self){
  VALUE mouseup;
  rb_scan_args(argc, argv, "0&", &mouseup);
  RugEvents.MouseUp = mouseup;
  return Qnil;
}

.show_cursor=(show) ⇒ Object

some basic options



93
94
95
# File 'ext/rug.c', line 93

VALUE RugShowCursor(VALUE class, VALUE show){
  SDL_ShowCursor(TYPE(show) == T_TRUE);
}

.startObject



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
# File 'ext/rug.c', line 45

static VALUE RugStart(VALUE class){
  SDL_Init(SDL_INIT_VIDEO);
  atexit(SDL_Quit);

  SDL_Event ev;
  int lastDraw = 0;

  int frameGap = RugConf.frameGap;

  mainWnd = DoConf();

  if (loadFunc != Qnil){
    rb_funcall(loadFunc, rb_intern("call"), 0);
  }

  // TODO: make background configurable
  Uint32 black = SDL_MapRGB(mainWnd->format, 0, 0, 0);

  while (1){
    if (SDL_PollEvent(&ev)){
      if (!HandleEvent(ev)){
        break;
      }
    }

    int now = SDL_GetTicks();
    if (lastDraw + frameGap < now){
      // update
      if (updateFunc != Qnil){
        rb_funcall(updateFunc, rb_intern("call"), 1, INT2NUM(now - lastDraw));
      }

      // render
      SDL_FillRect(mainWnd, NULL, black);

      if (drawFunc != Qnil){
        rb_funcall(drawFunc, rb_intern("call"), 0);
      }
      SDL_UpdateRect(mainWnd, 0, 0, 0, 0);
      lastDraw = now;
    }

    SDL_Delay(1);
  }

  return Qnil;
}

.update(*args) ⇒ Object



36
37
38
39
40
41
42
43
# File 'ext/rug.c', line 36

static VALUE RugUpdate(int argc, VALUE * argv, VALUE class){
  if (rb_block_given_p()){
    VALUE func;
    rb_scan_args(argc, argv, "0&", &func);
    updateFunc = func;
  }
  return Qnil;
}