Class: SDL2::Window
- Inherits:
-
Object
- Object
- SDL2::Window
- Defined in:
- video.c,
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
- 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)
-
+ (Hash<Integer => SDL2::Window>) all_windows
Get all windows under SDL.
-
+ (SDL2::Window) create(title, x, y, w, h, flags)
Create a window with the specified position (x,y), dimensions (w,h) and flags.
-
+ (SDL2::Window?) find_by_id(id)
Get the window from ID.
Instance Method Summary (collapse)
-
- (Boolean) bordered
Return true if the window is bordered.
-
- (bordered) bordered=(bordered)
Set the border state of the window.
-
- (Float) brightness
Get the brightness (gamma correction) of the window.
-
- (brightness) brightness=(brightness)
Set the brightness (gamma correction) of the window.
-
- (SDL2::Renderer) create_renderer(index, flags)
Create a 2D rendering context for a window.
-
- (Hash) debug_info
(GC) debug information.
-
- (void) destroy
Destroy window.
-
- (Boolean) destroy?
Return true if the window is already destroyed.
-
- (SDL2::Display) display
Get the display associated with the window.
-
- (SDL2::Window::Mode) display_mode
Get information about the window.
-
- (Integer) flags
Get the Window flag masks of the window.
-
- (Integer) fullscreen_mode
Get the fullscreen stete of the window.
-
- (flag) fullscreen_mode=(flag)
Set the fullscreen state of the window.
-
- (Array<Array<Integer>>) gamma_ramp
Get the gamma ramp for a window.
- - (Object) gl_drawable_size
-
- (nil) gl_swap
Swap the OpenGL buffers for the window, if double buffering is supported.
-
- (nil) hide
Hide the window.
-
- (icon) icon=(icon)
Set the window icon.
-
- (grabbed) input_is_grabbed=(grabbed)
Set the window's input grab mode.
-
- (Boolean) input_is_grabbed?
Return true if the input is grabbed to the window.
-
- (String) inspect
Inspection string.
-
- (nil) maximize
Maximize the window.
-
- (Integer) maximum_size
Get the maximum size of the window's client area.
-
- (size) maximum_size=(size)
Set the maximum size of the window's client area.
-
- (nil) minimize
Minimize the window.
-
- (Integer) minimum_size
Get the minimum size of the window's client area.
-
- (size) minimum_size=(size)
Set the minimum size of the window's client area.
-
- (Integer) position
Get the position of the window.
-
- (size) position=(xy)
Set the position of the window.
-
- (nil) raise
Raise the window above other windows and set the input focus.
-
- (SDL2::Renderer?) renderer
Return the renderer associate with the window.
-
- (nil) restore
Restore the size and position of a minimized or maixmized window.
-
- (nil) show
Show the window.
-
- ([Integer, Integer]) size
Get the size of the window.
-
- (size) size=(size)
Set the size of the window.
-
- (String) title
Get the title of the window.
-
- (title) title=(title)
Set the title of the window.
-
- (Integer) window_id
Get the numeric ID of the window.
Class Method Details
+ (Hash<Integer => SDL2::Window>) all_windows
Get all windows under SDL.
388 389 390 391 |
# File 'video.c', line 388
static VALUE Window_s_all_windows(VALUE self)
{
return rb_hash_dup(hash_windowid_to_window);
}
|
+ (SDL2::Window) create(title, x, y, w, h, flags)
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'video.c', line 365
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;
}
|
+ (SDL2::Window?) find_by_id(id)
402 403 404 405 |
# File 'video.c', line 402
static VALUE Window_s_find_by_id(VALUE self, VALUE id)
{
return rb_hash_aref(hash_windowid_to_window, id);
}
|
Instance Method Details
- (Boolean) bordered
Return true if the window is bordered
747 748 749 750 |
# File 'video.c', line 747
static VALUE Window_bordered(VALUE self)
{
return INT2BOOL(!(SDL_GetWindowFlags(Get_SDL_Window(self)) & SDL_WINDOW_BORDERLESS));
}
|
- (bordered) bordered=(bordered)
763 764 765 766 767 |
# File 'video.c', line 763
static VALUE Window_set_bordered(VALUE self, VALUE bordered)
{
SDL_SetWindowBordered(Get_SDL_Window(self), RTEST(bordered));
return bordered;
}
|
- (Float) brightness
Get the brightness (gamma correction) of the window.
502 503 504 505 |
# File 'video.c', line 502
static VALUE Window_brightness(VALUE self)
{
return DBL2NUM(SDL_GetWindowBrightness(Get_SDL_Window(self)));
}
|
- (brightness) brightness=(brightness)
517 518 519 520 521 |
# File 'video.c', line 517
static VALUE Window_set_brightness(VALUE self, VALUE brightness)
{
HANDLE_ERROR(SDL_SetWindowBrightness(Get_SDL_Window(self), NUM2DBL(brightness)));
return brightness;
}
|
- (SDL2::Renderer) create_renderer(index, flags)
437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'video.c', line 437
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;
}
|
- (Hash) debug_info
Returns (GC) debug information
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'video.c', line 928
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;
}
|
- (void) destroy
421 422 423 424 425 |
# File 'video.c', line 421
static VALUE Window_destroy(VALUE self)
{
Window_destroy_internal(Get_Window(self));
return Qnil;
}
|
- (Boolean) destroy?
Return true if the window is already destroyed.
- (SDL2::Display) display
Get the display associated with the window.
490 491 492 493 494 |
# File 'video.c', line 490
static VALUE Window_display(VALUE self)
{
int display_index = HANDLE_ERROR(SDL_GetWindowDisplayIndex(Get_SDL_Window(self)));
return Display_new(display_index);
}
|
- (SDL2::Window::Mode) display_mode
Get information about the window.
478 479 480 481 482 483 |
# File 'video.c', line 478
static VALUE Window_display_mode(VALUE self)
{
SDL_DisplayMode mode;
HANDLE_ERROR(SDL_GetWindowDisplayMode(Get_SDL_Window(self), &mode));
return DisplayMode_new(&mode);
}
|
- (Integer) flags
Get the Window flag masks of the window.
529 530 531 532 |
# File 'video.c', line 529
static VALUE Window_flags(VALUE self)
{
return UINT2NUM(SDL_GetWindowFlags(Get_SDL_Window(self)));
}
|
- (Integer) fullscreen_mode
Get the fullscreen stete of the window
866 867 868 869 870 |
# File 'video.c', line 866
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));
}
|
- (flag) fullscreen_mode=(flag)
883 884 885 886 887 |
# File 'video.c', line 883
static VALUE Window_set_fullscreen_mode(VALUE self, VALUE flags)
{
HANDLE_ERROR(SDL_SetWindowFullscreen(Get_SDL_Window(self), NUM2UINT(flags)));
return flags;
}
|
- (Array<Array<Integer>>) gamma_ramp
Get the gamma ramp for a window
551 552 553 554 555 556 557 558 559 |
# File 'video.c', line 551
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));
}
|
- (Object) gl_drawable_size
896 897 898 899 900 901 |
# File 'video.c', line 896
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));
}
|
- (nil) gl_swap
Swap the OpenGL buffers for the window, if double buffering is supported.
910 911 912 913 914 |
# File 'video.c', line 910
static VALUE Window_gl_swap(VALUE self)
{
SDL_GL_SwapWindow(Get_SDL_Window(self));
return Qnil;
}
|
- (nil) hide
Hide the window.
805 806 807 808 |
# File 'video.c', line 805
static VALUE Window_hide(VALUE self)
{
SDL_HideWindow(Get_SDL_Window(self)); return Qnil;
};
|
- (icon) icon=(icon)
569 570 571 572 573 |
# File 'video.c', line 569
static VALUE Window_set_icon(VALUE self, VALUE icon)
{
SDL_SetWindowIcon(Get_SDL_Window(self), Get_SDL_Surface(icon));
return icon;
}
|
- (grabbed) input_is_grabbed=(grabbed)
594 595 596 597 598 |
# File 'video.c', line 594
static VALUE Window_set_input_is_grabbed(VALUE self, VALUE grabbed)
{
SDL_SetWindowGrab(Get_SDL_Window(self), RTEST(grabbed));
return grabbed;
}
|
- (Boolean) input_is_grabbed?
Return true if the input is grabbed to the window.
580 581 582 583 |
# File 'video.c', line 580
static VALUE Window_input_is_grabbed_p(VALUE self)
{
return INT2BOOL(SDL_GetWindowGrab(Get_SDL_Window(self)));
}
|
- (String) inspect
Returns inspection string
917 918 919 920 921 922 923 924 925 |
# File 'video.c', line 917
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);
}
|
- (nil) maximize
Maximize the window.
817 818 819 820 |
# File 'video.c', line 817
static VALUE Window_maximize(VALUE self)
{
SDL_MaximizeWindow(Get_SDL_Window(self)); return Qnil;
};
|
- (Integer) maximum_size
Get the maximum size of the window's client area.
623 624 625 626 |
# File 'video.c', line 623
static VALUE Window_maximum_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowMaximumSize, self);
}
|
- (size) maximum_size=(size)
639 640 641 642 |
# File 'video.c', line 639
static VALUE Window_set_maximum_size(VALUE self, VALUE max_size)
{
return Window_set_int_int(SDL_SetWindowMaximumSize, self, max_size);
}
|
- (nil) minimize
Minimize the window.
829 830 831 832 |
# File 'video.c', line 829
static VALUE Window_minimize(VALUE self)
{
SDL_MinimizeWindow(Get_SDL_Window(self)); return Qnil;
};
|
- (Integer) minimum_size
Get the minimum size of the window's client area.
651 652 653 654 |
# File 'video.c', line 651
static VALUE Window_minimum_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowMinimumSize, self);
}
|
- (size) minimum_size=(size)
667 668 669 670 |
# File 'video.c', line 667
static VALUE Window_set_minimum_size(VALUE self, VALUE min_size)
{
return Window_set_int_int(SDL_SetWindowMinimumSize, self, min_size);
}
|
- (Integer) position
Get the position of the window.
679 680 681 682 |
# File 'video.c', line 679
static VALUE Window_position(VALUE self)
{
return Window_get_int_int(SDL_GetWindowPosition, self);
}
|
- (size) position=(xy)
696 697 698 699 |
# File 'video.c', line 696
static VALUE Window_set_position(VALUE self, VALUE xy)
{
return Window_set_int_int(SDL_SetWindowPosition, self, xy);
}
|
- (nil) raise
Raise the window above other windows and set the input focus.
839 840 841 842 |
# File 'video.c', line 839
static VALUE Window_raise(VALUE self)
{
SDL_RaiseWindow(Get_SDL_Window(self)); return Qnil;
};
|
- (SDL2::Renderer?) renderer
458 459 460 461 |
# File 'video.c', line 458
static VALUE Window_renderer(VALUE self)
{
return rb_iv_get(self, "renderer");
}
|
- (nil) restore
Restore the size and position of a minimized or maixmized window.
851 852 853 854 |
# File 'video.c', line 851
static VALUE Window_restore(VALUE self)
{
SDL_RestoreWindow(Get_SDL_Window(self)); return Qnil;
};
|
- (nil) show
Show the window.
794 795 796 797 |
# File 'video.c', line 794
static VALUE Window_show(VALUE self)
{
SDL_ShowWindow(Get_SDL_Window(self)); return Qnil;
};
|
- ([Integer, Integer]) size
Get the size of the window.
708 709 710 711 |
# File 'video.c', line 708
static VALUE Window_size(VALUE self)
{
return Window_get_int_int(SDL_GetWindowSize, self);
}
|
- (size) size=(size)
723 724 725 726 |
# File 'video.c', line 723
static VALUE Window_set_size(VALUE self, VALUE size)
{
return Window_set_int_int(SDL_SetWindowSize, self, size);
}
|
- (String) title
Get the title of the window
735 736 737 738 |
# File 'video.c', line 735
static VALUE Window_title(VALUE self)
{
return utf8str_new_cstr(SDL_GetWindowTitle(Get_SDL_Window(self)));
}
|
- (title) title=(title)
778 779 780 781 782 783 |
# File 'video.c', line 778
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;
}
|
- (Integer) window_id
Get the numeric ID of the window.
468 469 470 471 |
# File 'video.c', line 468
static VALUE Window_window_id(VALUE self)
{
return UINT2NUM(SDL_GetWindowID(Get_SDL_Window(self)));
}
|