Class: SDL2::Window
- Inherits:
-
Object
- Object
- SDL2::Window
- Defined in:
- ext/sdl2_ext/video.c,
ext/sdl2_ext/video.c
Overview
This class represents a window.
If you want to create graphical application using Ruby/SDL, first you need to create a window.
All of methods/class methods are available only after initializing video subsystem by init.
Defined Under Namespace
Modules: Flags
Constant Summary collapse
- POS_CENTERED =
Indicate that you don’t care what the window position is
INT2NUM(SDL_WINDOWPOS_CENTERED)
- POS_UNDEFINED =
Indicate that the window position should be centered
INT2NUM(SDL_WINDOWPOS_UNDEFINED)
Class Method Summary collapse
-
.all_windows ⇒ Hash<Integer => SDL2::Window>
Get all windows under SDL.
-
.create(title, x, y, w, h, flags) ⇒ SDL2::Window
Create a window with the specified position (x,y), dimensions (w,h) and flags.
-
.find_by_id(id) ⇒ SDL2::Window?
Get the window from ID.
Instance Method Summary collapse
-
#bordered ⇒ Boolean
Return true if the window is bordered.
-
#bordered=(bordered) ⇒ bordered
Set the border state of the window.
-
#brightness ⇒ Float
Get the brightness (gamma correction) of the window.
-
#brightness=(brightness) ⇒ brightness
Set the brightness (gamma correction) of the window.
-
#create_renderer(index, flags) ⇒ SDL2::Renderer
Create a 2D rendering context for a window.
-
#debug_info ⇒ Hash
(GC) debug information.
-
#destroy ⇒ void
Destroy window.
-
#destroy? ⇒ Boolean
Return true if the window is already destroyed.
-
#display ⇒ SDL2::Display
Get the display associated with the window.
-
#display_mode ⇒ SDL2::Window::Mode
Get information about the window.
-
#flags ⇒ Integer
Get the Window flag masks of the window.
-
#fullscreen_mode ⇒ Integer
Get the fullscreen stete of the window.
-
#fullscreen_mode=(flag) ⇒ flag
Set the fullscreen state of the window.
-
#gamma_ramp ⇒ Array<Array<Integer>>
Get the gamma ramp for a window.
-
#gl_drawable_size ⇒ [Integer, Integer]
Get the size of the drawable region.
-
#gl_swap ⇒ nil
Swap the OpenGL buffers for the window, if double buffering is supported.
-
#hide ⇒ nil
Hide the window.
-
#icon=(icon) ⇒ icon
Set the window icon.
-
#input_is_grabbed=(grabbed) ⇒ grabbed
Set the window’s input grab mode.
-
#input_is_grabbed? ⇒ Boolean
Return true if the input is grabbed to the window.
-
#inspect ⇒ String
Inspection string.
-
#maximize ⇒ nil
Maximize the window.
-
#maximum_size ⇒ Integer
Get the maximum size of the window’s client area.
-
#maximum_size=(size) ⇒ size
Set the maximum size of the window’s client area.
-
#minimize ⇒ nil
Minimize the window.
-
#minimum_size ⇒ Integer
Get the minimum size of the window’s client area.
-
#minimum_size=(size) ⇒ size
Set the minimum size of the window’s client area.
-
#position ⇒ Integer
Get the position of the window.
-
#position=(xy) ⇒ size
Set the position of the window.
-
#raise ⇒ nil
Raise the window above other windows and set the input focus.
-
#renderer ⇒ SDL2::Renderer?
Return the renderer associate with the window.
-
#restore ⇒ nil
Restore the size and position of a minimized or maixmized window.
-
#show ⇒ nil
Show the window.
-
#size ⇒ [Integer, Integer]
Get the size of the window.
-
#size=(size) ⇒ size
Set the size of the window.
-
#surface ⇒ SDL2::Surface
Get the window surface.
-
#title ⇒ String
Get the title of the window.
-
#title=(title) ⇒ title
Set the title of the window.
-
#update ⇒ nil
Copy window surface to the screen.
-
#window_id ⇒ Integer
Get the numeric ID of the window.
Class Method Details
.all_windows ⇒ Hash<Integer => SDL2::Window>
Get all windows under SDL.
375 376 377 378 |
# File 'ext/sdl2_ext/video.c', line 375
static VALUE Window_s_all_windows(VALUE self)
{
return rb_hash_dup(hash_windowid_to_window);
}
|
.create(title, x, y, w, h, flags) ⇒ SDL2::Window
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'ext/sdl2_ext/video.c', line 352
static VALUE Window_s_create(VALUE self, VALUE title, VALUE x, VALUE y, VALUE w, VALUE h,
VALUE flags)
{
SDL_Window* window;
VALUE win;
title = rb_str_export_to_enc(title, rb_utf8_encoding());
window = SDL_CreateWindow(StringValueCStr(title),
NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h),
NUM2UINT(flags));
if (window == NULL)
HANDLE_ERROR(-1);
win = Window_new(window);
rb_hash_aset(hash_windowid_to_window, UINT2NUM(SDL_GetWindowID(window)), win);
return win;
}
|
.find_by_id(id) ⇒ SDL2::Window?
389 390 391 392 |
# File 'ext/sdl2_ext/video.c', line 389
static VALUE Window_s_find_by_id(VALUE self, VALUE id)
{
return rb_hash_aref(hash_windowid_to_window, id);
}
|
Instance Method Details
#bordered ⇒ Boolean
Return true if the window is bordered
737 738 739 740 |
# File 'ext/sdl2_ext/video.c', line 737
static VALUE Window_bordered(VALUE self)
{
return INT2BOOL(!(SDL_GetWindowFlags(Get_SDL_Window(self)) & SDL_WINDOW_BORDERLESS));
}
|
#bordered=(bordered) ⇒ bordered
753 754 755 756 757 |
# File 'ext/sdl2_ext/video.c', line 753
static VALUE Window_set_bordered(VALUE self, VALUE bordered)
{
SDL_SetWindowBordered(Get_SDL_Window(self), RTEST(bordered));
return bordered;
}
|
#brightness ⇒ Float
Get the brightness (gamma correction) of the window.
492 493 494 495 |
# File 'ext/sdl2_ext/video.c', line 492
static VALUE Window_brightness(VALUE self)
{
return DBL2NUM(SDL_GetWindowBrightness(Get_SDL_Window(self)));
}
|
#brightness=(brightness) ⇒ brightness
507 508 509 510 511 |
# File 'ext/sdl2_ext/video.c', line 507
static VALUE Window_set_brightness(VALUE self, VALUE brightness)
{
HANDLE_ERROR(SDL_SetWindowBrightness(Get_SDL_Window(self), NUM2DBL(brightness)));
return brightness;
}
|
#create_renderer(index, flags) ⇒ SDL2::Renderer
427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'ext/sdl2_ext/video.c', line 427
static VALUE Window_create_renderer(VALUE self, VALUE index, VALUE flags)
{
SDL_Renderer* sdl_renderer;
VALUE renderer;
sdl_renderer = SDL_CreateRenderer(Get_SDL_Window(self), NUM2INT(index), NUM2UINT(flags));
if (sdl_renderer == NULL)
HANDLE_ERROR(-1);
renderer = Renderer_new(sdl_renderer, Get_Window(self));
rb_iv_set(self, "renderer", renderer);
return renderer;
}
|
#debug_info ⇒ Hash
Returns (GC) debug information.
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
# File 'ext/sdl2_ext/video.c', line 948
static VALUE Window_debug_info(VALUE self)
{
Window* w = Get_Window(self);
VALUE info = rb_hash_new();
int num_active_renderers = 0;
int i;
rb_hash_aset(info, rb_str_new2("destroy?"), INT2BOOL(w->window == NULL));
rb_hash_aset(info, rb_str_new2("max_renderers"), INT2NUM(w->max_renderers));
rb_hash_aset(info, rb_str_new2("num_renderers"), INT2NUM(w->num_renderers));
for (i=0; i<w->num_renderers; ++i)
if (w->renderers[i]->renderer)
++num_active_renderers;
rb_hash_aset(info, rb_str_new2("num_active_renderers"), INT2NUM(num_active_renderers));
return info;
}
|
#destroy ⇒ void
408 409 410 411 412 413 414 415 |
# File 'ext/sdl2_ext/video.c', line 408
static VALUE Window_destroy(VALUE self)
{
Window* w = Get_Window(self);
Window_destroy_internal(w);
SDL_DestroyWindow(w->window);
w->window = NULL;
return Qnil;
}
|
#destroy? ⇒ Boolean
Return true if the window is already destroyed.
#display ⇒ SDL2::Display
Get the display associated with the window.
480 481 482 483 484 |
# File 'ext/sdl2_ext/video.c', line 480
static VALUE Window_display(VALUE self)
{
int display_index = HANDLE_ERROR(SDL_GetWindowDisplayIndex(Get_SDL_Window(self)));
return Display_new(display_index);
}
|
#display_mode ⇒ SDL2::Window::Mode
Get information about the window.
468 469 470 471 472 473 |
# File 'ext/sdl2_ext/video.c', line 468
static VALUE Window_display_mode(VALUE self)
{
SDL_DisplayMode mode;
HANDLE_ERROR(SDL_GetWindowDisplayMode(Get_SDL_Window(self), &mode));
return DisplayMode_new(&mode);
}
|
#flags ⇒ Integer
Get the Window flag masks of the window.
519 520 521 522 |
# File 'ext/sdl2_ext/video.c', line 519
static VALUE Window_flags(VALUE self)
{
return UINT2NUM(SDL_GetWindowFlags(Get_SDL_Window(self)));
}
|
#fullscreen_mode ⇒ Integer
Get the fullscreen stete of the window
887 888 889 890 891 |
# File 'ext/sdl2_ext/video.c', line 887
static VALUE Window_fullscreen_mode(VALUE self)
{
Uint32 flags = SDL_GetWindowFlags(Get_SDL_Window(self));
return UINT2NUM(flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_FULLSCREEN_DESKTOP));
}
|
#fullscreen_mode=(flag) ⇒ flag
904 905 906 907 908 |
# File 'ext/sdl2_ext/video.c', line 904
static VALUE Window_set_fullscreen_mode(VALUE self, VALUE flags)
{
HANDLE_ERROR(SDL_SetWindowFullscreen(Get_SDL_Window(self), NUM2UINT(flags)));
return flags;
}
|
#gamma_ramp ⇒ Array<Array<Integer>>
Get the gamma ramp for a window
541 542 543 544 545 546 547 548 549 |
# File 'ext/sdl2_ext/video.c', line 541
static VALUE Window_gamma_ramp(VALUE self)
{
Uint16 r[256], g[256], b[256];
HANDLE_ERROR(SDL_GetWindowGammaRamp(Get_SDL_Window(self), r, g, b));
return rb_ary_new3(3,
gamma_table_to_Array(r),
gamma_table_to_Array(g),
gamma_table_to_Array(b));
}
|
#gl_drawable_size ⇒ [Integer, Integer]
Get the size of the drawable region.
916 917 918 919 920 921 |
# File 'ext/sdl2_ext/video.c', line 916
static VALUE Window_gl_drawable_size(VALUE self)
{
int w, h;
SDL_GL_GetDrawableSize(Get_SDL_Window(self), &w, &h);
return rb_ary_new3(2, INT2NUM(w), INT2NUM(h));
}
|
#gl_swap ⇒ nil
Swap the OpenGL buffers for the window, if double buffering is supported.
930 931 932 933 934 |
# File 'ext/sdl2_ext/video.c', line 930
static VALUE Window_gl_swap(VALUE self)
{
SDL_GL_SwapWindow(Get_SDL_Window(self));
return Qnil;
}
|
#hide ⇒ nil
Hide the window.
826 827 828 829 |
# File 'ext/sdl2_ext/video.c', line 826
static VALUE Window_hide(VALUE self)
{
SDL_HideWindow(Get_SDL_Window(self)); return Qnil;
};
|
#icon=(icon) ⇒ icon
559 560 561 562 563 |
# File 'ext/sdl2_ext/video.c', line 559
static VALUE Window_set_icon(VALUE self, VALUE icon)
{
SDL_SetWindowIcon(Get_SDL_Window(self), Get_SDL_Surface(icon));
return icon;
}
|
#input_is_grabbed=(grabbed) ⇒ grabbed
584 585 586 587 588 |
# File 'ext/sdl2_ext/video.c', line 584
static VALUE Window_set_input_is_grabbed(VALUE self, VALUE grabbed)
{
SDL_SetWindowGrab(Get_SDL_Window(self), RTEST(grabbed));
return grabbed;
}
|
#input_is_grabbed? ⇒ Boolean
Return true if the input is grabbed to the window.
570 571 572 573 |
# File 'ext/sdl2_ext/video.c', line 570
static VALUE Window_input_is_grabbed_p(VALUE self)
{
return INT2BOOL(SDL_GetWindowGrab(Get_SDL_Window(self)));
}
|
#inspect ⇒ String
Returns inspection string.
937 938 939 940 941 942 943 944 945 |
# File 'ext/sdl2_ext/video.c', line 937
static VALUE Window_inspect(VALUE self)
{
Window* w = Get_Window(self);
if (w->window)
return rb_sprintf("<%s:%p window_id=%d>",
rb_obj_classname(self), (void*)self, SDL_GetWindowID(w->window));
else
return rb_sprintf("<%s:%p (destroyed)>", rb_obj_classname(self), (void*)self);
}
|
#maximize ⇒ nil
Maximize the window.
838 839 840 841 |
# File 'ext/sdl2_ext/video.c', line 838
static VALUE Window_maximize(VALUE self)
{
SDL_MaximizeWindow(Get_SDL_Window(self)); return Qnil;
};
|
#maximum_size ⇒ Integer
Get the maximum size of the window’s client area.
613 614 615 616 |
# File 'ext/sdl2_ext/video.c', line 613
static VALUE Window_maximum_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowMaximumSize, self);
}
|
#maximum_size=(size) ⇒ size
629 630 631 632 |
# File 'ext/sdl2_ext/video.c', line 629
static VALUE Window_set_maximum_size(VALUE self, VALUE max_size)
{
return Window_set_int_int(SDL_SetWindowMaximumSize, self, max_size);
}
|
#minimize ⇒ nil
Minimize the window.
850 851 852 853 |
# File 'ext/sdl2_ext/video.c', line 850
static VALUE Window_minimize(VALUE self)
{
SDL_MinimizeWindow(Get_SDL_Window(self)); return Qnil;
};
|
#minimum_size ⇒ Integer
Get the minimum size of the window’s client area.
641 642 643 644 |
# File 'ext/sdl2_ext/video.c', line 641
static VALUE Window_minimum_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowMinimumSize, self);
}
|
#minimum_size=(size) ⇒ size
657 658 659 660 |
# File 'ext/sdl2_ext/video.c', line 657
static VALUE Window_set_minimum_size(VALUE self, VALUE min_size)
{
return Window_set_int_int(SDL_SetWindowMinimumSize, self, min_size);
}
|
#position ⇒ Integer
Get the position of the window.
669 670 671 672 |
# File 'ext/sdl2_ext/video.c', line 669
static VALUE Window_position(VALUE self)
{
return Window_get_int_int(SDL_GetWindowPosition, self);
}
|
#position=(xy) ⇒ size
686 687 688 689 |
# File 'ext/sdl2_ext/video.c', line 686
static VALUE Window_set_position(VALUE self, VALUE xy)
{
return Window_set_int_int(SDL_SetWindowPosition, self, xy);
}
|
#raise ⇒ nil
Raise the window above other windows and set the input focus.
860 861 862 863 |
# File 'ext/sdl2_ext/video.c', line 860
static VALUE Window_raise(VALUE self)
{
SDL_RaiseWindow(Get_SDL_Window(self)); return Qnil;
};
|
#renderer ⇒ SDL2::Renderer?
448 449 450 451 |
# File 'ext/sdl2_ext/video.c', line 448
static VALUE Window_renderer(VALUE self)
{
return rb_iv_get(self, "renderer");
}
|
#restore ⇒ nil
Restore the size and position of a minimized or maixmized window.
872 873 874 875 |
# File 'ext/sdl2_ext/video.c', line 872
static VALUE Window_restore(VALUE self)
{
SDL_RestoreWindow(Get_SDL_Window(self)); return Qnil;
};
|
#show ⇒ nil
Show the window.
815 816 817 818 |
# File 'ext/sdl2_ext/video.c', line 815
static VALUE Window_show(VALUE self)
{
SDL_ShowWindow(Get_SDL_Window(self)); return Qnil;
};
|
#size ⇒ [Integer, Integer]
Get the size of the window.
698 699 700 701 |
# File 'ext/sdl2_ext/video.c', line 698
static VALUE Window_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowSize, self);
}
|
#size=(size) ⇒ size
713 714 715 716 |
# File 'ext/sdl2_ext/video.c', line 713
static VALUE Window_set_size(VALUE self, VALUE size)
{
return Window_set_int_int(SDL_SetWindowSize, self, size);
}
|
#surface ⇒ SDL2::Surface
782 783 784 785 786 787 788 789 790 791 |
# File 'ext/sdl2_ext/video.c', line 782
static VALUE Window_surface(VALUE self)
{
SDL_Surface *surface = SDL_GetWindowSurface(Get_SDL_Window(self));
if(surface == NULL) {
SDL_ERROR();
return Qnil;
} else {
return Surface_new(surface);
}
}
|
#title ⇒ String
Get the title of the window
725 726 727 728 |
# File 'ext/sdl2_ext/video.c', line 725
static VALUE Window_title(VALUE self)
{
return utf8str_new_cstr(SDL_GetWindowTitle(Get_SDL_Window(self)));
}
|
#title=(title) ⇒ title
768 769 770 771 772 773 |
# File 'ext/sdl2_ext/video.c', line 768
static VALUE Window_set_title(VALUE self, VALUE title)
{
title = rb_str_export_to_enc(title, rb_utf8_encoding());
SDL_SetWindowTitle(Get_SDL_Window(self), StringValueCStr(title));
return Qnil;
}
|
#update ⇒ nil
800 801 802 803 804 |
# File 'ext/sdl2_ext/video.c', line 800
static VALUE Window_update(VALUE self)
{
HANDLE_ERROR(SDL_UpdateWindowSurface(Get_SDL_Window(self)));
return Qnil;
}
|
#window_id ⇒ Integer
Get the numeric ID of the window.
458 459 460 461 |
# File 'ext/sdl2_ext/video.c', line 458
static VALUE Window_window_id(VALUE self)
{
return UINT2NUM(SDL_GetWindowID(Get_SDL_Window(self)));
}
|