Class: Bitmap
- Inherits:
-
Object
- Object
- Bitmap
- Defined in:
- lib/bitmap.rb
Overview
The bitmap class. Bitmaps are expressions of so-called graphics. Sprites (Sprite) and other objects must be used to display bitmaps on the screen.
Instance Attribute Summary collapse
-
#font ⇒ Font
Gets the font used to draw a string with the #draw_text method.
-
#height ⇒ Object
readonly
Gets the bitmap height.
-
#rect ⇒ Rect
readonly
Gets the bitmap rectangle.
-
#width ⇒ Object
readonly
Gets the bitmap width.
Instance Method Summary collapse
-
#blt(x, y, src_bitmap, src_rect, opacity = 255) ⇒ Object
Performs a block transfer from the src_bitmap box src_rect to the specified bitmap coordinates (x, y).
-
#clear ⇒ Object
Clears the entire bitmap.
-
#dispose ⇒ Object
Frees the bitmap.
-
#disposed? ⇒ true, false
true if the bitmap has been freed.
-
#draw_text(*args) ⇒ Object
Draws a string str in the bitmap box (x, y, width, height) or rect (Rect).
-
#fill_rect(*args) ⇒ Object
Fills the bitmap box (x, y, width, height) or rect (Rect) with color (Color).
-
#get_pixel(x, y) ⇒ Object
Gets the Color at the specified pixel (x, y).
-
#hue_change(hue) ⇒ Object
Changes the bitmap’s hue within 360 degrees of displacement.
-
#intialize(*args) ⇒ Object
A new instance of Bitmap.
-
#set_pixel(x, y, color) ⇒ Object
Sets the specified pixel (x, y) to the specified Color.
-
#stretch_blt(dest_rect, src_bitmap, src_rect, opacity = 255) ⇒ Object
Performs a block transfer from the src_bitmap box src_rect to the specified bitmap box dest_rect (Rect).
-
#text_size(str) ⇒ Rect
The box used when drawing a string str with the draw_text method.
Instance Attribute Details
#font ⇒ Font
Gets the font used to draw a string with the #draw_text method.
7 8 9 |
# File 'lib/bitmap.rb', line 7 def font @font end |
#height ⇒ Object (readonly)
Gets the bitmap height.
13 14 15 |
# File 'lib/bitmap.rb', line 13 def height @height end |
#rect ⇒ Rect (readonly)
Gets the bitmap rectangle.
17 18 19 |
# File 'lib/bitmap.rb', line 17 def rect @rect end |
#width ⇒ Object (readonly)
Gets the bitmap width.
10 11 12 |
# File 'lib/bitmap.rb', line 10 def width @width end |
Instance Method Details
#blt(x, y, src_bitmap, src_rect, opacity = 255) ⇒ Object
Performs a block transfer from the src_bitmap box src_rect to the specified bitmap coordinates (x, y). Opacity can be set from 0 to 255.
56 57 58 |
# File 'lib/bitmap.rb', line 56 def blt(x, y, src_bitmap, src_rect, opacity = 255) raise "not implemented" end |
#clear ⇒ Object
Clears the entire bitmap.
79 80 81 |
# File 'lib/bitmap.rb', line 79 def clear raise "not implemented" end |
#dispose ⇒ Object
Frees the bitmap. If the bitmap has already been freed, does nothing.
37 38 39 40 41 |
# File 'lib/bitmap.rb', line 37 def dispose raise "not implemented" @disposed = true end |
#disposed? ⇒ true, false
Returns true if the bitmap has been freed.
44 45 46 |
# File 'lib/bitmap.rb', line 44 def disposed? @disposed end |
#draw_text(x, y, width, height, str[, align]) ⇒ Object #draw_text(rect, str[, align]) ⇒ Object
Draws a string str in the bitmap box (x, y, width, height) or rect (Rect).
If the text length exceeds the box’s width, the text width will automatically be reduced by up to 60 percent.
Horizontal text is left-aligned by default; set align to 1 to center the text and to 2 to right-align it. Vertical text is always centered.
As this process is time-consuming, redrawing the text with every frame is not recommended.
109 110 111 |
# File 'lib/bitmap.rb', line 109 def draw_text(*args) raise "not implemented" end |
#fill_rect(x, y, width, height, color) ⇒ Object #fill_rect(rect, color) ⇒ Object
Fills the bitmap box (x, y, width, height) or rect (Rect) with color (Color).
74 75 76 |
# File 'lib/bitmap.rb', line 74 def fill_rect(*args) raise "not implemented" end |
#get_pixel(x, y) ⇒ Object
Gets the Color at the specified pixel (x, y).
84 85 86 |
# File 'lib/bitmap.rb', line 84 def get_pixel(x, y) raise "not implemented" end |
#hue_change(hue) ⇒ Object
Changes the bitmap’s hue within 360 degrees of displacement. This process is time-consuming. Furthermore, due to conversion errors, repeated hue changes may result in color loss.
95 96 97 |
# File 'lib/bitmap.rb', line 95 def hue_change(hue) raise "not implemented" end |
#initialize(filename) ⇒ Bitmap #initialize(width, height) ⇒ Bitmap
A new instance of Bitmap.
27 28 29 30 31 32 33 34 |
# File 'lib/bitmap.rb', line 27 def intialize(*args) if args.size == 1 load_file args[0] elsif args.size == 2 @width = args[0] @height = args[1] end end |
#set_pixel(x, y, color) ⇒ Object
Sets the specified pixel (x, y) to the specified Color.
89 90 91 |
# File 'lib/bitmap.rb', line 89 def set_pixel(x, y, color) raise "not implemented" end |
#stretch_blt(dest_rect, src_bitmap, src_rect, opacity = 255) ⇒ Object
Performs a block transfer from the src_bitmap box src_rect to the specified bitmap box dest_rect (Rect). opacity can be set from 0 to 255.
67 68 69 |
# File 'lib/bitmap.rb', line 67 def stretch_blt(dest_rect, src_bitmap, src_rect, opacity = 255) raise "not implemented" end |
#text_size(str) ⇒ Rect
Returns the box used when drawing a string str with the draw_text method. Does not include the angled portions of italicized text.
115 116 117 |
# File 'lib/bitmap.rb', line 115 def text_size(str) raise "not implemented" end |