Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Text Tester
- # By Mithran
- # change the options at the top of the script to test various text drawing
- # situations
- # while in the tester:
- # q/w add/subtract string width
- # a/s add/subtract buffer width
- # Enter: Center bitmap
- # left/right scroll bitmap left/right, hold ctrl for faster scroll
- Font.default_name = "Verdana" # for comparison to VX
- Font.default_size = 20 # for comparison to VX
- #Font.default_outline = true
- #Font.default_italic = true
- #Font.default_shadow = true
- #Font.default_bold = true
- class Scene_DrawTextTest < Scene_Base
- ON = true # change to false to disable this text tester
- TEST_TEXT = "The quick brown fox jumps over the lazy dog, and lands in a fox trap?!"
- "The green area is the rect given by Bitmap#text_size." +
- " And this is just an extra optional line that can be added to the above to demonstrate the error."
- # the green area is the rect given by Bitmap#text_size for the above string,
- # and the text is drawn to this rect
- # by definition, the text should be of approximately the same size as the rect
- # and should not shift if alignment is changed, but neither is true
- # if you make the above string really long (as in, for horizonally scrolling text)
- # the draw text will collapse over itself (uncomment the plus to see)
- ALIGN = 0# text_size issue is really ovbious when aligned left
- # but try center with longer text, to show text drawing over itself for no reason
- # to make matters worse, it doesnt even properly center when this happens
- BUFFER = 0 # how much wider the bitmap is than the text drawn to it
- def start
- @text = TEST_TEXT
- create_sprite
- end
- def create_sprite
- @sprite = Sprite_Base.new
- @buffer = BUFFER
- @align = ALIGN
- create_bitmap
- center_sprite(@sprite)
- end
- def create_bitmap
- rect = Cache.empty_bitmap.text_size(@text)
- rect.width += @buffer
- @sprite.bitmap = Bitmap.new(rect.width, rect.height)
- @sprite.bitmap.fill_rect(rect, Color.new(0, 128, 0))
- @sprite.bitmap.draw_text(rect, @text, @align)
- end
- def update
- super
- @sprite.update
- if Input.press?(:ALT)
- @align = 0 if Input.trigger?(:LEFT)
- @align = 1 if Input.trigger?(:DOWN)
- @align = 2 if Input.trigger?(:RIGHT)
- elsif Input.press?(:RIGHT)
- @sprite.ox -= 1
- @sprite.ox -= 3 if Input.press?(:CTRL)
- elsif Input.press?(:LEFT)
- @sprite.ox += 1
- @sprite.ox += 3 if Input.press?(:CTRL)
- elsif Input.repeat?(:R)
- @text += (rand(90) + 32).chr
- @sprite.bitmap.dispose
- create_bitmap
- elsif Input.repeat?(:L)
- @text.chop!
- @sprite.bitmap.dispose
- create_bitmap
- elsif Input.repeat?(:X)
- @buffer -= 1
- @buffer -= 3 if Input.press?(:CTRL)
- @sprite.bitmap.dispose
- create_bitmap
- elsif Input.repeat?(:Y)
- @buffer += 1
- @buffer += 3 if Input.press?(:CTRL)
- @sprite.bitmap.dispose
- create_bitmap
- elsif Input.trigger?(:F5)
- msgbox_p( "Buffer Ratio: #{(@buffer / Cache.empty_bitmap.text_size(@text).width.to_f) + 1}" )
- elsif Input.trigger?(:F6)
- msgbox_p "Bitmap Width: #{@sprite.bitmap.width}"
- end
- center_sprite(@sprite) if Input.trigger?(:C)
- SceneManager.exit if Input.trigger?(:B)
- end
- def center_sprite(sprite)
- sprite.ox = sprite.bitmap.width / 2
- sprite.oy = sprite.bitmap.height / 2
- sprite.x = Graphics.width / 2
- sprite.y = Graphics.height / 2
- end
- def terminate
- destroy_sprite
- end
- def destroy_sprite
- @sprite.bitmap.dispose
- @sprite.dispose
- end
- end
- module SceneManager
- if Scene_DrawTextTest::ON
- def self.first_scene_class
- Scene_DrawTextTest
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement