note description: "A mode (width, height, refresh rate, etc.) of a GAME_DISPLAY (screen)" author: "Louis Marchand" date: "Thu, 02 Apr 2015 02:40:10 +0000" revision: "2.0" class GAME_DISPLAY_MODE inherit GAME_SDL_ANY redefine out, is_equal end MEMORY_STRUCTURE rename make as make_structure export {NONE} make_structure, make_by_pointer {GAME_SDL_ANY} item redefine out, is_equal end create make, make_with_refresh_rate create {GAME_SDL_ANY} own_from_pointer, shared_from_pointer feature {NONE} -- Initialization make (a_width, a_height: INTEGER_32) -- Initialization for Current using only a_width and a_height. require display_mode_make_width_valid: a_width > 0 display_mode_make_height_valid: a_height > 0 do make_with_refresh_rate (a_width, a_height, 0) end make_with_refresh_rate (a_width, a_height, a_refresh_rate: INTEGER_32) -- Initialization for Current using a_width, a_height and a_refresh_rate. require display_mode_make_refresh_rate_valid: a_refresh_rate >= 0 display_mode_make_width_valid: a_width > 0 display_mode_make_height_valid: a_height > 0 do make_structure set_pixel_format (create {GAME_PIXEL_FORMAT}) set_width (a_width) set_height (a_height) set_refresh_rate (a_refresh_rate) end shared_from_pointer (a_mode: POINTER) -- Initialization for Current using a_mode pointer. -- Note that the a_mode will not be free by Current. require display_mode_own_pointer_not_null: not a_mode.is_default_pointer do make_by_pointer (a_mode) ensure display_mode_own_internal_pointer_not_null: not item.is_default_pointer end own_from_pointer (a_mode: POINTER) -- Initialization for Current using a_mode pointer. -- Note that the a_mode pointer is owned by Current. The client does not have to free it. require display_mode_own_pointer_not_null: not a_mode.is_default_pointer do create internal_item create managed_pointer.own_from_pointer (a_mode, structure_size) shared := False end make_from_pointer (a_mode: POINTER) -- Initialization for Current using a copy of the internal mode pointed by a_mode pointer. -- Note that the a_mode will not be free by Current. require display_mode_own_pointer_not_null: not a_mode.is_default_pointer do make_with_refresh_rate ({GAME_SDL_EXTERNAL}.get_display_mode_struct_w (a_mode), {GAME_SDL_EXTERNAL}.get_display_mode_struct_h (a_mode), {GAME_SDL_EXTERNAL}.get_display_mode_struct_refresh_rate (a_mode)) set_pixel_format (create {GAME_PIXEL_FORMAT_READABLE}.make_from_flags ({GAME_SDL_EXTERNAL}.get_display_mode_struct_format (a_mode))) end feature -- Access width: INTEGER_32 assign set_width -- The width of Current require pointer_exists: exists do Result := {GAME_SDL_EXTERNAL}.get_display_mode_struct_w (item) ensure display_mode_width_not_changed: width = old width display_mode_height_not_changed: height = old height display_mode_refresh_rate_not_changed: refresh_rate = old refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end set_width (a_width: INTEGER_32) -- Assign width with the value of a_width. require pointer_exists: exists do {GAME_SDL_EXTERNAL}.set_display_mode_struct_w (item, a_width) ensure display_mode_width_changed: width = a_width display_mode_height_not_changed: height = old height display_mode_refresh_rate_not_changed: refresh_rate = old refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end height: INTEGER_32 assign set_height -- The height of `Current require pointer_exists: exists do Result := {GAME_SDL_EXTERNAL}.get_display_mode_struct_h (item) ensure display_mode_width_not_changed: width = old width display_mode_height_not_changed: height = old height display_mode_refresh_rate_not_changed: refresh_rate = old refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end set_height (a_height: INTEGER_32) -- Assign height with the value of a_height. require pointer_exists: exists do {GAME_SDL_EXTERNAL}.set_display_mode_struct_h (item, a_height) ensure display_mode_width_not_changed: width = old width display_mode_height_changed: height = a_height display_mode_refresh_rate_not_changed: refresh_rate = old refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end refresh_rate: INTEGER_32 assign set_refresh_rate -- The frame_rate of Current require pointer_exists: exists do Result := {GAME_SDL_EXTERNAL}.get_display_mode_struct_refresh_rate (item) ensure display_mode_width_not_changed: width = old width display_mode_height_not_changed: height = old height display_mode_refresh_rate_not_changed: refresh_rate = old refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end set_refresh_rate (a_refresh_rate: INTEGER_32) -- Assign refresh_rate with the value of a_refresh_rate. require pointer_exists: exists do {GAME_SDL_EXTERNAL}.set_display_mode_struct_refresh_rate (item, a_refresh_rate) ensure display_mode_width_not_changed: width = old width display_mode_height_not_changed: height = old height display_mode_refresh_rate_changed: refresh_rate = a_refresh_rate display_mode_pixel_format_not_changed: pixel_format ~ old pixel_format end pixel_format: GAME_PIXEL_FORMAT_READABLE assign set_pixel_format -- The internal format of the pixel representation in memory. require pointer_exists: exists do create Result.make_from_flags ({GAME_SDL_EXTERNAL}.get_display_mode_struct_format (item)) end set_pixel_format (a_pixel_format: like pixel_format) -- Assign the pixel_format of the pixel representation in memory to the value of a_pixel_format. require pointer_exists: exists do {GAME_SDL_EXTERNAL}.set_display_mode_struct_format (item, pixel_format.internal_index) end out: STRING_8 -- New string containing terse printable representation -- of current object require else pointer_exists: exists do if exists then Result := width.out + "x" + height.out + ", " + refresh_rate.out + "Hz, Format:" + pixel_format.out else Result := "" end end is_equal (a_other: like Current): BOOLEAN -- Is other attached to an object considered -- equal to current object? require else pointer_exists: exists do if exists then Result := (width = a_other.width) and (height = a_other.height) and (refresh_rate = a_other.refresh_rate) and (pixel_format ~ a_other.pixel_format) else Result := not a_other.exists end end feature -- Implementation structure_size: INTEGER_32 -- Size to allocate (in bytes). do Result := {GAME_SDL_EXTERNAL}.c_sizeof_sdl_display_mode end end -- class GAME_DISPLAY_MODE
Generated by ISE EiffelStudio