Skip to content

Commit

Permalink
Added a method to Rubygame::Screen to get screen resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Paul Weber committed Oct 18, 2008
1 parent 5caef26 commit ca67dfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ext/rubygame/rubygame_screen.c
Expand Up @@ -32,6 +32,8 @@ VALUE cScreen;
VALUE rbgm_screen_setmode(int, VALUE*, VALUE);
VALUE rbgm_screen_getsurface(VALUE);

VALUE rbgm_screen_getresolution(VALUE);

VALUE rbgm_screen_getcaption(VALUE);
VALUE rbgm_screen_setcaption(VALUE, VALUE);

Expand Down Expand Up @@ -150,6 +152,22 @@ VALUE rbgm_screen_getsurface(VALUE module)
return Data_Wrap_Struct( cScreen,0,0,surface );
}


VALUE rbgm_screen_getresolution(VALUE module)
{
VALUE array;
const SDL_VideoInfo* hw;
hw = SDL_GetVideoInfo();
if(hw==NULL)
{
rb_raise(eSDLError,"Couldn't get video info: %s",SDL_GetError());
}
array = rb_ary_new();
rb_ary_push(array, INT2NUM(hw->current_w));
rb_ary_push(array, INT2NUM(hw->current_h));
return array;
}

/* Screen methods: */

/* call-seq:
Expand Down Expand Up @@ -423,6 +441,7 @@ void Rubygame_Init_Screen()
rb_define_alias(rb_singleton_class(cScreen),"set_mode","new");
rb_define_alias(rb_singleton_class(cScreen),"instance","new");
rb_define_singleton_method(cScreen,"get_surface",rbgm_screen_getsurface, 0);
rb_define_singleton_method(cScreen,"get_resolution",rbgm_screen_getresolution, 0);

/* These are inherited from Surface, but should not be called on Screen */
rb_undef_method(cScreen,"set_alpha");
Expand Down
2 changes: 2 additions & 0 deletions ext/rubygame/rubygame_screen.h
Expand Up @@ -28,6 +28,8 @@ extern VALUE cScreen;
extern VALUE rbgm_screen_setmode(int, VALUE*, VALUE);
extern VALUE rbgm_screen_getsurface(VALUE);

extern VALUE rbgm_screen_getresolution(VALUE);

extern VALUE rbgm_screen_getcaption(VALUE);
extern VALUE rbgm_screen_setcaption(VALUE, VALUE);

Expand Down

0 comments on commit ca67dfa

Please sign in to comment.